pdf-4.0.379.worker.mjs 1.8 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ // The require scope
  23. /******/ var __webpack_require__ = {};
  24. /******/
  25. /************************************************************************/
  26. /******/ /* webpack/runtime/define property getters */
  27. /******/ (() => {
  28. /******/ // define getter functions for harmony exports
  29. /******/ __webpack_require__.d = (exports, definition) => {
  30. /******/ for(var key in definition) {
  31. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  32. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  33. /******/ }
  34. /******/ }
  35. /******/ };
  36. /******/ })();
  37. /******/
  38. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  39. /******/ (() => {
  40. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  41. /******/ })();
  42. /******/
  43. /************************************************************************/
  44. var __webpack_exports__ = globalThis.pdfjsWorker = {};
  45. // EXPORTS
  46. __webpack_require__.d(__webpack_exports__, {
  47. WorkerMessageHandler: () => (/* reexport */ WorkerMessageHandler)
  48. });
  49. ;// CONCATENATED MODULE: ./src/shared/util.js
  50. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  51. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  52. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  53. const MAX_IMAGE_SIZE_TO_CACHE = 10e6;
  54. const LINE_FACTOR = 1.35;
  55. const LINE_DESCENT_FACTOR = 0.35;
  56. const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
  57. const RenderingIntentFlag = {
  58. ANY: 0x01,
  59. DISPLAY: 0x02,
  60. PRINT: 0x04,
  61. SAVE: 0x08,
  62. ANNOTATIONS_FORMS: 0x10,
  63. ANNOTATIONS_STORAGE: 0x20,
  64. ANNOTATIONS_DISABLE: 0x40,
  65. OPLIST: 0x100
  66. };
  67. const AnnotationMode = {
  68. DISABLE: 0,
  69. ENABLE: 1,
  70. ENABLE_FORMS: 2,
  71. ENABLE_STORAGE: 3
  72. };
  73. const AnnotationEditorPrefix = "pdfjs_internal_editor_";
  74. const AnnotationEditorType = {
  75. DISABLE: -1,
  76. NONE: 0,
  77. FREETEXT: 3,
  78. HIGHLIGHT: 9,
  79. STAMP: 13,
  80. INK: 15
  81. };
  82. const AnnotationEditorParamsType = {
  83. RESIZE: 1,
  84. CREATE: 2,
  85. FREETEXT_SIZE: 11,
  86. FREETEXT_COLOR: 12,
  87. FREETEXT_OPACITY: 13,
  88. INK_COLOR: 21,
  89. INK_THICKNESS: 22,
  90. INK_OPACITY: 23,
  91. HIGHLIGHT_COLOR: 31,
  92. HIGHLIGHT_DEFAULT_COLOR: 32
  93. };
  94. const PermissionFlag = {
  95. PRINT: 0x04,
  96. MODIFY_CONTENTS: 0x08,
  97. COPY: 0x10,
  98. MODIFY_ANNOTATIONS: 0x20,
  99. FILL_INTERACTIVE_FORMS: 0x100,
  100. COPY_FOR_ACCESSIBILITY: 0x200,
  101. ASSEMBLE: 0x400,
  102. PRINT_HIGH_QUALITY: 0x800
  103. };
  104. const TextRenderingMode = {
  105. FILL: 0,
  106. STROKE: 1,
  107. FILL_STROKE: 2,
  108. INVISIBLE: 3,
  109. FILL_ADD_TO_PATH: 4,
  110. STROKE_ADD_TO_PATH: 5,
  111. FILL_STROKE_ADD_TO_PATH: 6,
  112. ADD_TO_PATH: 7,
  113. FILL_STROKE_MASK: 3,
  114. ADD_TO_PATH_FLAG: 4
  115. };
  116. const ImageKind = {
  117. GRAYSCALE_1BPP: 1,
  118. RGB_24BPP: 2,
  119. RGBA_32BPP: 3
  120. };
  121. const AnnotationType = {
  122. TEXT: 1,
  123. LINK: 2,
  124. FREETEXT: 3,
  125. LINE: 4,
  126. SQUARE: 5,
  127. CIRCLE: 6,
  128. POLYGON: 7,
  129. POLYLINE: 8,
  130. HIGHLIGHT: 9,
  131. UNDERLINE: 10,
  132. SQUIGGLY: 11,
  133. STRIKEOUT: 12,
  134. STAMP: 13,
  135. CARET: 14,
  136. INK: 15,
  137. POPUP: 16,
  138. FILEATTACHMENT: 17,
  139. SOUND: 18,
  140. MOVIE: 19,
  141. WIDGET: 20,
  142. SCREEN: 21,
  143. PRINTERMARK: 22,
  144. TRAPNET: 23,
  145. WATERMARK: 24,
  146. THREED: 25,
  147. REDACT: 26
  148. };
  149. const AnnotationReplyType = {
  150. GROUP: "Group",
  151. REPLY: "R"
  152. };
  153. const AnnotationFlag = {
  154. INVISIBLE: 0x01,
  155. HIDDEN: 0x02,
  156. PRINT: 0x04,
  157. NOZOOM: 0x08,
  158. NOROTATE: 0x10,
  159. NOVIEW: 0x20,
  160. READONLY: 0x40,
  161. LOCKED: 0x80,
  162. TOGGLENOVIEW: 0x100,
  163. LOCKEDCONTENTS: 0x200
  164. };
  165. const AnnotationFieldFlag = {
  166. READONLY: 0x0000001,
  167. REQUIRED: 0x0000002,
  168. NOEXPORT: 0x0000004,
  169. MULTILINE: 0x0001000,
  170. PASSWORD: 0x0002000,
  171. NOTOGGLETOOFF: 0x0004000,
  172. RADIO: 0x0008000,
  173. PUSHBUTTON: 0x0010000,
  174. COMBO: 0x0020000,
  175. EDIT: 0x0040000,
  176. SORT: 0x0080000,
  177. FILESELECT: 0x0100000,
  178. MULTISELECT: 0x0200000,
  179. DONOTSPELLCHECK: 0x0400000,
  180. DONOTSCROLL: 0x0800000,
  181. COMB: 0x1000000,
  182. RICHTEXT: 0x2000000,
  183. RADIOSINUNISON: 0x2000000,
  184. COMMITONSELCHANGE: 0x4000000
  185. };
  186. const AnnotationBorderStyleType = {
  187. SOLID: 1,
  188. DASHED: 2,
  189. BEVELED: 3,
  190. INSET: 4,
  191. UNDERLINE: 5
  192. };
  193. const AnnotationActionEventType = {
  194. E: "Mouse Enter",
  195. X: "Mouse Exit",
  196. D: "Mouse Down",
  197. U: "Mouse Up",
  198. Fo: "Focus",
  199. Bl: "Blur",
  200. PO: "PageOpen",
  201. PC: "PageClose",
  202. PV: "PageVisible",
  203. PI: "PageInvisible",
  204. K: "Keystroke",
  205. F: "Format",
  206. V: "Validate",
  207. C: "Calculate"
  208. };
  209. const DocumentActionEventType = {
  210. WC: "WillClose",
  211. WS: "WillSave",
  212. DS: "DidSave",
  213. WP: "WillPrint",
  214. DP: "DidPrint"
  215. };
  216. const PageActionEventType = {
  217. O: "PageOpen",
  218. C: "PageClose"
  219. };
  220. const VerbosityLevel = {
  221. ERRORS: 0,
  222. WARNINGS: 1,
  223. INFOS: 5
  224. };
  225. const CMapCompressionType = {
  226. NONE: 0,
  227. BINARY: 1
  228. };
  229. const OPS = {
  230. dependency: 1,
  231. setLineWidth: 2,
  232. setLineCap: 3,
  233. setLineJoin: 4,
  234. setMiterLimit: 5,
  235. setDash: 6,
  236. setRenderingIntent: 7,
  237. setFlatness: 8,
  238. setGState: 9,
  239. save: 10,
  240. restore: 11,
  241. transform: 12,
  242. moveTo: 13,
  243. lineTo: 14,
  244. curveTo: 15,
  245. curveTo2: 16,
  246. curveTo3: 17,
  247. closePath: 18,
  248. rectangle: 19,
  249. stroke: 20,
  250. closeStroke: 21,
  251. fill: 22,
  252. eoFill: 23,
  253. fillStroke: 24,
  254. eoFillStroke: 25,
  255. closeFillStroke: 26,
  256. closeEOFillStroke: 27,
  257. endPath: 28,
  258. clip: 29,
  259. eoClip: 30,
  260. beginText: 31,
  261. endText: 32,
  262. setCharSpacing: 33,
  263. setWordSpacing: 34,
  264. setHScale: 35,
  265. setLeading: 36,
  266. setFont: 37,
  267. setTextRenderingMode: 38,
  268. setTextRise: 39,
  269. moveText: 40,
  270. setLeadingMoveText: 41,
  271. setTextMatrix: 42,
  272. nextLine: 43,
  273. showText: 44,
  274. showSpacedText: 45,
  275. nextLineShowText: 46,
  276. nextLineSetSpacingShowText: 47,
  277. setCharWidth: 48,
  278. setCharWidthAndBounds: 49,
  279. setStrokeColorSpace: 50,
  280. setFillColorSpace: 51,
  281. setStrokeColor: 52,
  282. setStrokeColorN: 53,
  283. setFillColor: 54,
  284. setFillColorN: 55,
  285. setStrokeGray: 56,
  286. setFillGray: 57,
  287. setStrokeRGBColor: 58,
  288. setFillRGBColor: 59,
  289. setStrokeCMYKColor: 60,
  290. setFillCMYKColor: 61,
  291. shadingFill: 62,
  292. beginInlineImage: 63,
  293. beginImageData: 64,
  294. endInlineImage: 65,
  295. paintXObject: 66,
  296. markPoint: 67,
  297. markPointProps: 68,
  298. beginMarkedContent: 69,
  299. beginMarkedContentProps: 70,
  300. endMarkedContent: 71,
  301. beginCompat: 72,
  302. endCompat: 73,
  303. paintFormXObjectBegin: 74,
  304. paintFormXObjectEnd: 75,
  305. beginGroup: 76,
  306. endGroup: 77,
  307. beginAnnotation: 80,
  308. endAnnotation: 81,
  309. paintImageMaskXObject: 83,
  310. paintImageMaskXObjectGroup: 84,
  311. paintImageXObject: 85,
  312. paintInlineImageXObject: 86,
  313. paintInlineImageXObjectGroup: 87,
  314. paintImageXObjectRepeat: 88,
  315. paintImageMaskXObjectRepeat: 89,
  316. paintSolidColorImageMask: 90,
  317. constructPath: 91
  318. };
  319. const PasswordResponses = {
  320. NEED_PASSWORD: 1,
  321. INCORRECT_PASSWORD: 2
  322. };
  323. let verbosity = VerbosityLevel.WARNINGS;
  324. function setVerbosityLevel(level) {
  325. if (Number.isInteger(level)) {
  326. verbosity = level;
  327. }
  328. }
  329. function getVerbosityLevel() {
  330. return verbosity;
  331. }
  332. function info(msg) {
  333. if (verbosity >= VerbosityLevel.INFOS) {
  334. console.log(`Info: ${msg}`);
  335. }
  336. }
  337. function warn(msg) {
  338. if (verbosity >= VerbosityLevel.WARNINGS) {
  339. console.log(`Warning: ${msg}`);
  340. }
  341. }
  342. function unreachable(msg) {
  343. throw new Error(msg);
  344. }
  345. function assert(cond, msg) {
  346. if (!cond) {
  347. unreachable(msg);
  348. }
  349. }
  350. function _isValidProtocol(url) {
  351. switch (url?.protocol) {
  352. case "http:":
  353. case "https:":
  354. case "ftp:":
  355. case "mailto:":
  356. case "tel:":
  357. return true;
  358. default:
  359. return false;
  360. }
  361. }
  362. function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
  363. if (!url) {
  364. return null;
  365. }
  366. try {
  367. if (options && typeof url === "string") {
  368. if (options.addDefaultProtocol && url.startsWith("www.")) {
  369. const dots = url.match(/\./g);
  370. if (dots?.length >= 2) {
  371. url = `http://${url}`;
  372. }
  373. }
  374. if (options.tryConvertEncoding) {
  375. try {
  376. url = stringToUTF8String(url);
  377. } catch {}
  378. }
  379. }
  380. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  381. if (_isValidProtocol(absoluteUrl)) {
  382. return absoluteUrl;
  383. }
  384. } catch {}
  385. return null;
  386. }
  387. function shadow(obj, prop, value, nonSerializable = false) {
  388. Object.defineProperty(obj, prop, {
  389. value,
  390. enumerable: !nonSerializable,
  391. configurable: true,
  392. writable: false
  393. });
  394. return value;
  395. }
  396. const BaseException = function BaseExceptionClosure() {
  397. function BaseException(message, name) {
  398. if (this.constructor === BaseException) {
  399. unreachable("Cannot initialize BaseException.");
  400. }
  401. this.message = message;
  402. this.name = name;
  403. }
  404. BaseException.prototype = new Error();
  405. BaseException.constructor = BaseException;
  406. return BaseException;
  407. }();
  408. class PasswordException extends BaseException {
  409. constructor(msg, code) {
  410. super(msg, "PasswordException");
  411. this.code = code;
  412. }
  413. }
  414. class UnknownErrorException extends BaseException {
  415. constructor(msg, details) {
  416. super(msg, "UnknownErrorException");
  417. this.details = details;
  418. }
  419. }
  420. class InvalidPDFException extends BaseException {
  421. constructor(msg) {
  422. super(msg, "InvalidPDFException");
  423. }
  424. }
  425. class MissingPDFException extends BaseException {
  426. constructor(msg) {
  427. super(msg, "MissingPDFException");
  428. }
  429. }
  430. class UnexpectedResponseException extends BaseException {
  431. constructor(msg, status) {
  432. super(msg, "UnexpectedResponseException");
  433. this.status = status;
  434. }
  435. }
  436. class FormatError extends BaseException {
  437. constructor(msg) {
  438. super(msg, "FormatError");
  439. }
  440. }
  441. class AbortException extends BaseException {
  442. constructor(msg) {
  443. super(msg, "AbortException");
  444. }
  445. }
  446. function bytesToString(bytes) {
  447. if (typeof bytes !== "object" || bytes?.length === undefined) {
  448. unreachable("Invalid argument for bytesToString");
  449. }
  450. const length = bytes.length;
  451. const MAX_ARGUMENT_COUNT = 8192;
  452. if (length < MAX_ARGUMENT_COUNT) {
  453. return String.fromCharCode.apply(null, bytes);
  454. }
  455. const strBuf = [];
  456. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  457. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  458. const chunk = bytes.subarray(i, chunkEnd);
  459. strBuf.push(String.fromCharCode.apply(null, chunk));
  460. }
  461. return strBuf.join("");
  462. }
  463. function stringToBytes(str) {
  464. if (typeof str !== "string") {
  465. unreachable("Invalid argument for stringToBytes");
  466. }
  467. const length = str.length;
  468. const bytes = new Uint8Array(length);
  469. for (let i = 0; i < length; ++i) {
  470. bytes[i] = str.charCodeAt(i) & 0xff;
  471. }
  472. return bytes;
  473. }
  474. function string32(value) {
  475. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  476. }
  477. function objectSize(obj) {
  478. return Object.keys(obj).length;
  479. }
  480. function objectFromMap(map) {
  481. const obj = Object.create(null);
  482. for (const [key, value] of map) {
  483. obj[key] = value;
  484. }
  485. return obj;
  486. }
  487. function isLittleEndian() {
  488. const buffer8 = new Uint8Array(4);
  489. buffer8[0] = 1;
  490. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  491. return view32[0] === 1;
  492. }
  493. function isEvalSupported() {
  494. try {
  495. new Function("");
  496. return true;
  497. } catch {
  498. return false;
  499. }
  500. }
  501. class FeatureTest {
  502. static get isLittleEndian() {
  503. return shadow(this, "isLittleEndian", isLittleEndian());
  504. }
  505. static get isEvalSupported() {
  506. return shadow(this, "isEvalSupported", isEvalSupported());
  507. }
  508. static get isOffscreenCanvasSupported() {
  509. return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
  510. }
  511. static get platform() {
  512. if (typeof navigator !== "undefined" && typeof navigator?.platform === "string") {
  513. return shadow(this, "platform", {
  514. isMac: navigator.platform.includes("Mac")
  515. });
  516. }
  517. return shadow(this, "platform", {
  518. isMac: false
  519. });
  520. }
  521. static get isCSSRoundSupported() {
  522. return shadow(this, "isCSSRoundSupported", globalThis.CSS?.supports?.("width: round(1.5px, 1px)"));
  523. }
  524. }
  525. const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
  526. class Util {
  527. static makeHexColor(r, g, b) {
  528. return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
  529. }
  530. static scaleMinMax(transform, minMax) {
  531. let temp;
  532. if (transform[0]) {
  533. if (transform[0] < 0) {
  534. temp = minMax[0];
  535. minMax[0] = minMax[1];
  536. minMax[1] = temp;
  537. }
  538. minMax[0] *= transform[0];
  539. minMax[1] *= transform[0];
  540. if (transform[3] < 0) {
  541. temp = minMax[2];
  542. minMax[2] = minMax[3];
  543. minMax[3] = temp;
  544. }
  545. minMax[2] *= transform[3];
  546. minMax[3] *= transform[3];
  547. } else {
  548. temp = minMax[0];
  549. minMax[0] = minMax[2];
  550. minMax[2] = temp;
  551. temp = minMax[1];
  552. minMax[1] = minMax[3];
  553. minMax[3] = temp;
  554. if (transform[1] < 0) {
  555. temp = minMax[2];
  556. minMax[2] = minMax[3];
  557. minMax[3] = temp;
  558. }
  559. minMax[2] *= transform[1];
  560. minMax[3] *= transform[1];
  561. if (transform[2] < 0) {
  562. temp = minMax[0];
  563. minMax[0] = minMax[1];
  564. minMax[1] = temp;
  565. }
  566. minMax[0] *= transform[2];
  567. minMax[1] *= transform[2];
  568. }
  569. minMax[0] += transform[4];
  570. minMax[1] += transform[4];
  571. minMax[2] += transform[5];
  572. minMax[3] += transform[5];
  573. }
  574. static transform(m1, m2) {
  575. return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
  576. }
  577. static applyTransform(p, m) {
  578. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  579. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  580. return [xt, yt];
  581. }
  582. static applyInverseTransform(p, m) {
  583. const d = m[0] * m[3] - m[1] * m[2];
  584. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  585. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  586. return [xt, yt];
  587. }
  588. static getAxialAlignedBoundingBox(r, m) {
  589. const p1 = this.applyTransform(r, m);
  590. const p2 = this.applyTransform(r.slice(2, 4), m);
  591. const p3 = this.applyTransform([r[0], r[3]], m);
  592. const p4 = this.applyTransform([r[2], r[1]], m);
  593. return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
  594. }
  595. static inverseTransform(m) {
  596. const d = m[0] * m[3] - m[1] * m[2];
  597. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  598. }
  599. static singularValueDecompose2dScale(m) {
  600. const transpose = [m[0], m[2], m[1], m[3]];
  601. const a = m[0] * transpose[0] + m[1] * transpose[2];
  602. const b = m[0] * transpose[1] + m[1] * transpose[3];
  603. const c = m[2] * transpose[0] + m[3] * transpose[2];
  604. const d = m[2] * transpose[1] + m[3] * transpose[3];
  605. const first = (a + d) / 2;
  606. const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
  607. const sx = first + second || 1;
  608. const sy = first - second || 1;
  609. return [Math.sqrt(sx), Math.sqrt(sy)];
  610. }
  611. static normalizeRect(rect) {
  612. const r = rect.slice(0);
  613. if (rect[0] > rect[2]) {
  614. r[0] = rect[2];
  615. r[2] = rect[0];
  616. }
  617. if (rect[1] > rect[3]) {
  618. r[1] = rect[3];
  619. r[3] = rect[1];
  620. }
  621. return r;
  622. }
  623. static intersect(rect1, rect2) {
  624. const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
  625. const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
  626. if (xLow > xHigh) {
  627. return null;
  628. }
  629. const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
  630. const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
  631. if (yLow > yHigh) {
  632. return null;
  633. }
  634. return [xLow, yLow, xHigh, yHigh];
  635. }
  636. static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
  637. const tvalues = [],
  638. bounds = [[], []];
  639. let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
  640. for (let i = 0; i < 2; ++i) {
  641. if (i === 0) {
  642. b = 6 * x0 - 12 * x1 + 6 * x2;
  643. a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
  644. c = 3 * x1 - 3 * x0;
  645. } else {
  646. b = 6 * y0 - 12 * y1 + 6 * y2;
  647. a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
  648. c = 3 * y1 - 3 * y0;
  649. }
  650. if (Math.abs(a) < 1e-12) {
  651. if (Math.abs(b) < 1e-12) {
  652. continue;
  653. }
  654. t = -c / b;
  655. if (0 < t && t < 1) {
  656. tvalues.push(t);
  657. }
  658. continue;
  659. }
  660. b2ac = b * b - 4 * c * a;
  661. sqrtb2ac = Math.sqrt(b2ac);
  662. if (b2ac < 0) {
  663. continue;
  664. }
  665. t1 = (-b + sqrtb2ac) / (2 * a);
  666. if (0 < t1 && t1 < 1) {
  667. tvalues.push(t1);
  668. }
  669. t2 = (-b - sqrtb2ac) / (2 * a);
  670. if (0 < t2 && t2 < 1) {
  671. tvalues.push(t2);
  672. }
  673. }
  674. let j = tvalues.length,
  675. mt;
  676. const jlen = j;
  677. while (j--) {
  678. t = tvalues[j];
  679. mt = 1 - t;
  680. bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
  681. bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
  682. }
  683. bounds[0][jlen] = x0;
  684. bounds[1][jlen] = y0;
  685. bounds[0][jlen + 1] = x3;
  686. bounds[1][jlen + 1] = y3;
  687. bounds[0].length = bounds[1].length = jlen + 2;
  688. return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
  689. }
  690. }
  691. const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
  692. function stringToPDFString(str) {
  693. if (str[0] >= "\xEF") {
  694. let encoding;
  695. if (str[0] === "\xFE" && str[1] === "\xFF") {
  696. encoding = "utf-16be";
  697. if (str.length % 2 === 1) {
  698. str = str.slice(0, -1);
  699. }
  700. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  701. encoding = "utf-16le";
  702. if (str.length % 2 === 1) {
  703. str = str.slice(0, -1);
  704. }
  705. } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
  706. encoding = "utf-8";
  707. }
  708. if (encoding) {
  709. try {
  710. const decoder = new TextDecoder(encoding, {
  711. fatal: true
  712. });
  713. const buffer = stringToBytes(str);
  714. const decoded = decoder.decode(buffer);
  715. if (!decoded.includes("\x1b")) {
  716. return decoded;
  717. }
  718. return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
  719. } catch (ex) {
  720. warn(`stringToPDFString: "${ex}".`);
  721. }
  722. }
  723. }
  724. const strBuf = [];
  725. for (let i = 0, ii = str.length; i < ii; i++) {
  726. const charCode = str.charCodeAt(i);
  727. if (charCode === 0x1b) {
  728. while (++i < ii && str.charCodeAt(i) !== 0x1b) {}
  729. continue;
  730. }
  731. const code = PDFStringTranslateTable[charCode];
  732. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  733. }
  734. return strBuf.join("");
  735. }
  736. function stringToUTF8String(str) {
  737. return decodeURIComponent(escape(str));
  738. }
  739. function utf8StringToString(str) {
  740. return unescape(encodeURIComponent(str));
  741. }
  742. function isArrayBuffer(v) {
  743. return typeof v === "object" && v?.byteLength !== undefined;
  744. }
  745. function isArrayEqual(arr1, arr2) {
  746. if (arr1.length !== arr2.length) {
  747. return false;
  748. }
  749. for (let i = 0, ii = arr1.length; i < ii; i++) {
  750. if (arr1[i] !== arr2[i]) {
  751. return false;
  752. }
  753. }
  754. return true;
  755. }
  756. function getModificationDate(date = new Date()) {
  757. const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
  758. return buffer.join("");
  759. }
  760. class PromiseCapability {
  761. #settled = false;
  762. constructor() {
  763. this.promise = new Promise((resolve, reject) => {
  764. this.resolve = data => {
  765. this.#settled = true;
  766. resolve(data);
  767. };
  768. this.reject = reason => {
  769. this.#settled = true;
  770. reject(reason);
  771. };
  772. });
  773. }
  774. get settled() {
  775. return this.#settled;
  776. }
  777. }
  778. let NormalizeRegex = null;
  779. let NormalizationMap = null;
  780. function normalizeUnicode(str) {
  781. if (!NormalizeRegex) {
  782. NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu;
  783. NormalizationMap = new Map([["ſt", "ſt"]]);
  784. }
  785. return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
  786. return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
  787. });
  788. }
  789. function getUuid() {
  790. if (typeof crypto !== "undefined" && typeof crypto?.randomUUID === "function") {
  791. return crypto.randomUUID();
  792. }
  793. const buf = new Uint8Array(32);
  794. if (typeof crypto !== "undefined" && typeof crypto?.getRandomValues === "function") {
  795. crypto.getRandomValues(buf);
  796. } else {
  797. for (let i = 0; i < 32; i++) {
  798. buf[i] = Math.floor(Math.random() * 255);
  799. }
  800. }
  801. return bytesToString(buf);
  802. }
  803. const AnnotationPrefix = "pdfjs_internal_id_";
  804. ;// CONCATENATED MODULE: ./src/core/primitives.js
  805. const CIRCULAR_REF = Symbol("CIRCULAR_REF");
  806. const EOF = Symbol("EOF");
  807. let CmdCache = Object.create(null);
  808. let NameCache = Object.create(null);
  809. let RefCache = Object.create(null);
  810. function clearPrimitiveCaches() {
  811. CmdCache = Object.create(null);
  812. NameCache = Object.create(null);
  813. RefCache = Object.create(null);
  814. }
  815. class Name {
  816. constructor(name) {
  817. this.name = name;
  818. }
  819. static get(name) {
  820. return NameCache[name] ||= new Name(name);
  821. }
  822. }
  823. class Cmd {
  824. constructor(cmd) {
  825. this.cmd = cmd;
  826. }
  827. static get(cmd) {
  828. return CmdCache[cmd] ||= new Cmd(cmd);
  829. }
  830. }
  831. const nonSerializable = function nonSerializableClosure() {
  832. return nonSerializable;
  833. };
  834. class Dict {
  835. constructor(xref = null) {
  836. this._map = Object.create(null);
  837. this.xref = xref;
  838. this.objId = null;
  839. this.suppressEncryption = false;
  840. this.__nonSerializable__ = nonSerializable;
  841. }
  842. assignXref(newXref) {
  843. this.xref = newXref;
  844. }
  845. get size() {
  846. return Object.keys(this._map).length;
  847. }
  848. get(key1, key2, key3) {
  849. let value = this._map[key1];
  850. if (value === undefined && key2 !== undefined) {
  851. value = this._map[key2];
  852. if (value === undefined && key3 !== undefined) {
  853. value = this._map[key3];
  854. }
  855. }
  856. if (value instanceof Ref && this.xref) {
  857. return this.xref.fetch(value, this.suppressEncryption);
  858. }
  859. return value;
  860. }
  861. async getAsync(key1, key2, key3) {
  862. let value = this._map[key1];
  863. if (value === undefined && key2 !== undefined) {
  864. value = this._map[key2];
  865. if (value === undefined && key3 !== undefined) {
  866. value = this._map[key3];
  867. }
  868. }
  869. if (value instanceof Ref && this.xref) {
  870. return this.xref.fetchAsync(value, this.suppressEncryption);
  871. }
  872. return value;
  873. }
  874. getArray(key1, key2, key3) {
  875. let value = this._map[key1];
  876. if (value === undefined && key2 !== undefined) {
  877. value = this._map[key2];
  878. if (value === undefined && key3 !== undefined) {
  879. value = this._map[key3];
  880. }
  881. }
  882. if (value instanceof Ref && this.xref) {
  883. value = this.xref.fetch(value, this.suppressEncryption);
  884. }
  885. if (Array.isArray(value)) {
  886. value = value.slice();
  887. for (let i = 0, ii = value.length; i < ii; i++) {
  888. if (value[i] instanceof Ref && this.xref) {
  889. value[i] = this.xref.fetch(value[i], this.suppressEncryption);
  890. }
  891. }
  892. }
  893. return value;
  894. }
  895. getRaw(key) {
  896. return this._map[key];
  897. }
  898. getKeys() {
  899. return Object.keys(this._map);
  900. }
  901. getRawValues() {
  902. return Object.values(this._map);
  903. }
  904. set(key, value) {
  905. this._map[key] = value;
  906. }
  907. has(key) {
  908. return this._map[key] !== undefined;
  909. }
  910. forEach(callback) {
  911. for (const key in this._map) {
  912. callback(key, this.get(key));
  913. }
  914. }
  915. static get empty() {
  916. const emptyDict = new Dict(null);
  917. emptyDict.set = (key, value) => {
  918. unreachable("Should not call `set` on the empty dictionary.");
  919. };
  920. return shadow(this, "empty", emptyDict);
  921. }
  922. static merge({
  923. xref,
  924. dictArray,
  925. mergeSubDicts = false
  926. }) {
  927. const mergedDict = new Dict(xref),
  928. properties = new Map();
  929. for (const dict of dictArray) {
  930. if (!(dict instanceof Dict)) {
  931. continue;
  932. }
  933. for (const [key, value] of Object.entries(dict._map)) {
  934. let property = properties.get(key);
  935. if (property === undefined) {
  936. property = [];
  937. properties.set(key, property);
  938. } else if (!mergeSubDicts || !(value instanceof Dict)) {
  939. continue;
  940. }
  941. property.push(value);
  942. }
  943. }
  944. for (const [name, values] of properties) {
  945. if (values.length === 1 || !(values[0] instanceof Dict)) {
  946. mergedDict._map[name] = values[0];
  947. continue;
  948. }
  949. const subDict = new Dict(xref);
  950. for (const dict of values) {
  951. for (const [key, value] of Object.entries(dict._map)) {
  952. if (subDict._map[key] === undefined) {
  953. subDict._map[key] = value;
  954. }
  955. }
  956. }
  957. if (subDict.size > 0) {
  958. mergedDict._map[name] = subDict;
  959. }
  960. }
  961. properties.clear();
  962. return mergedDict.size > 0 ? mergedDict : Dict.empty;
  963. }
  964. clone() {
  965. const dict = new Dict(this.xref);
  966. for (const key of this.getKeys()) {
  967. dict.set(key, this.getRaw(key));
  968. }
  969. return dict;
  970. }
  971. }
  972. class Ref {
  973. constructor(num, gen) {
  974. this.num = num;
  975. this.gen = gen;
  976. }
  977. toString() {
  978. if (this.gen === 0) {
  979. return `${this.num}R`;
  980. }
  981. return `${this.num}R${this.gen}`;
  982. }
  983. static fromString(str) {
  984. const ref = RefCache[str];
  985. if (ref) {
  986. return ref;
  987. }
  988. const m = /^(\d+)R(\d*)$/.exec(str);
  989. if (!m || m[1] === "0") {
  990. return null;
  991. }
  992. return RefCache[str] = new Ref(parseInt(m[1]), !m[2] ? 0 : parseInt(m[2]));
  993. }
  994. static get(num, gen) {
  995. const key = gen === 0 ? `${num}R` : `${num}R${gen}`;
  996. return RefCache[key] ||= new Ref(num, gen);
  997. }
  998. }
  999. class RefSet {
  1000. constructor(parent = null) {
  1001. this._set = new Set(parent?._set);
  1002. }
  1003. has(ref) {
  1004. return this._set.has(ref.toString());
  1005. }
  1006. put(ref) {
  1007. this._set.add(ref.toString());
  1008. }
  1009. remove(ref) {
  1010. this._set.delete(ref.toString());
  1011. }
  1012. [Symbol.iterator]() {
  1013. return this._set.values();
  1014. }
  1015. clear() {
  1016. this._set.clear();
  1017. }
  1018. }
  1019. class RefSetCache {
  1020. constructor() {
  1021. this._map = new Map();
  1022. }
  1023. get size() {
  1024. return this._map.size;
  1025. }
  1026. get(ref) {
  1027. return this._map.get(ref.toString());
  1028. }
  1029. has(ref) {
  1030. return this._map.has(ref.toString());
  1031. }
  1032. put(ref, obj) {
  1033. this._map.set(ref.toString(), obj);
  1034. }
  1035. putAlias(ref, aliasRef) {
  1036. this._map.set(ref.toString(), this.get(aliasRef));
  1037. }
  1038. [Symbol.iterator]() {
  1039. return this._map.values();
  1040. }
  1041. clear() {
  1042. this._map.clear();
  1043. }
  1044. }
  1045. function isName(v, name) {
  1046. return v instanceof Name && (name === undefined || v.name === name);
  1047. }
  1048. function isCmd(v, cmd) {
  1049. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  1050. }
  1051. function isDict(v, type) {
  1052. return v instanceof Dict && (type === undefined || isName(v.get("Type"), type));
  1053. }
  1054. function isRefsEqual(v1, v2) {
  1055. return v1.num === v2.num && v1.gen === v2.gen;
  1056. }
  1057. ;// CONCATENATED MODULE: ./src/core/base_stream.js
  1058. class BaseStream {
  1059. constructor() {
  1060. if (this.constructor === BaseStream) {
  1061. unreachable("Cannot initialize BaseStream.");
  1062. }
  1063. }
  1064. get length() {
  1065. unreachable("Abstract getter `length` accessed");
  1066. }
  1067. get isEmpty() {
  1068. unreachable("Abstract getter `isEmpty` accessed");
  1069. }
  1070. get isDataLoaded() {
  1071. return shadow(this, "isDataLoaded", true);
  1072. }
  1073. getByte() {
  1074. unreachable("Abstract method `getByte` called");
  1075. }
  1076. getBytes(length) {
  1077. unreachable("Abstract method `getBytes` called");
  1078. }
  1079. peekByte() {
  1080. const peekedByte = this.getByte();
  1081. if (peekedByte !== -1) {
  1082. this.pos--;
  1083. }
  1084. return peekedByte;
  1085. }
  1086. peekBytes(length) {
  1087. const bytes = this.getBytes(length);
  1088. this.pos -= bytes.length;
  1089. return bytes;
  1090. }
  1091. getUint16() {
  1092. const b0 = this.getByte();
  1093. const b1 = this.getByte();
  1094. if (b0 === -1 || b1 === -1) {
  1095. return -1;
  1096. }
  1097. return (b0 << 8) + b1;
  1098. }
  1099. getInt32() {
  1100. const b0 = this.getByte();
  1101. const b1 = this.getByte();
  1102. const b2 = this.getByte();
  1103. const b3 = this.getByte();
  1104. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1105. }
  1106. getByteRange(begin, end) {
  1107. unreachable("Abstract method `getByteRange` called");
  1108. }
  1109. getString(length) {
  1110. return bytesToString(this.getBytes(length));
  1111. }
  1112. skip(n) {
  1113. this.pos += n || 1;
  1114. }
  1115. reset() {
  1116. unreachable("Abstract method `reset` called");
  1117. }
  1118. moveStart() {
  1119. unreachable("Abstract method `moveStart` called");
  1120. }
  1121. makeSubStream(start, length, dict = null) {
  1122. unreachable("Abstract method `makeSubStream` called");
  1123. }
  1124. getBaseStreams() {
  1125. return null;
  1126. }
  1127. }
  1128. ;// CONCATENATED MODULE: ./src/core/core_utils.js
  1129. const PDF_VERSION_REGEXP = /^[1-9]\.\d$/;
  1130. function getLookupTableFactory(initializer) {
  1131. let lookup;
  1132. return function () {
  1133. if (initializer) {
  1134. lookup = Object.create(null);
  1135. initializer(lookup);
  1136. initializer = null;
  1137. }
  1138. return lookup;
  1139. };
  1140. }
  1141. class MissingDataException extends BaseException {
  1142. constructor(begin, end) {
  1143. super(`Missing data [${begin}, ${end})`, "MissingDataException");
  1144. this.begin = begin;
  1145. this.end = end;
  1146. }
  1147. }
  1148. class ParserEOFException extends BaseException {
  1149. constructor(msg) {
  1150. super(msg, "ParserEOFException");
  1151. }
  1152. }
  1153. class XRefEntryException extends BaseException {
  1154. constructor(msg) {
  1155. super(msg, "XRefEntryException");
  1156. }
  1157. }
  1158. class XRefParseException extends BaseException {
  1159. constructor(msg) {
  1160. super(msg, "XRefParseException");
  1161. }
  1162. }
  1163. function arrayBuffersToBytes(arr) {
  1164. const length = arr.length;
  1165. if (length === 0) {
  1166. return new Uint8Array(0);
  1167. }
  1168. if (length === 1) {
  1169. return new Uint8Array(arr[0]);
  1170. }
  1171. let dataLength = 0;
  1172. for (let i = 0; i < length; i++) {
  1173. dataLength += arr[i].byteLength;
  1174. }
  1175. const data = new Uint8Array(dataLength);
  1176. let pos = 0;
  1177. for (let i = 0; i < length; i++) {
  1178. const item = new Uint8Array(arr[i]);
  1179. data.set(item, pos);
  1180. pos += item.byteLength;
  1181. }
  1182. return data;
  1183. }
  1184. function getInheritableProperty({
  1185. dict,
  1186. key,
  1187. getArray = false,
  1188. stopWhenFound = true
  1189. }) {
  1190. let values;
  1191. const visited = new RefSet();
  1192. while (dict instanceof Dict && !(dict.objId && visited.has(dict.objId))) {
  1193. if (dict.objId) {
  1194. visited.put(dict.objId);
  1195. }
  1196. const value = getArray ? dict.getArray(key) : dict.get(key);
  1197. if (value !== undefined) {
  1198. if (stopWhenFound) {
  1199. return value;
  1200. }
  1201. (values ||= []).push(value);
  1202. }
  1203. dict = dict.get("Parent");
  1204. }
  1205. return values;
  1206. }
  1207. const ROMAN_NUMBER_MAP = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
  1208. function toRomanNumerals(number, lowerCase = false) {
  1209. assert(Number.isInteger(number) && number > 0, "The number should be a positive integer.");
  1210. const romanBuf = [];
  1211. let pos;
  1212. while (number >= 1000) {
  1213. number -= 1000;
  1214. romanBuf.push("M");
  1215. }
  1216. pos = number / 100 | 0;
  1217. number %= 100;
  1218. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  1219. pos = number / 10 | 0;
  1220. number %= 10;
  1221. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  1222. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  1223. const romanStr = romanBuf.join("");
  1224. return lowerCase ? romanStr.toLowerCase() : romanStr;
  1225. }
  1226. function log2(x) {
  1227. if (x <= 0) {
  1228. return 0;
  1229. }
  1230. return Math.ceil(Math.log2(x));
  1231. }
  1232. function readInt8(data, offset) {
  1233. return data[offset] << 24 >> 24;
  1234. }
  1235. function readUint16(data, offset) {
  1236. return data[offset] << 8 | data[offset + 1];
  1237. }
  1238. function readUint32(data, offset) {
  1239. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  1240. }
  1241. function isWhiteSpace(ch) {
  1242. return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
  1243. }
  1244. function parseXFAPath(path) {
  1245. const positionPattern = /(.+)\[(\d+)\]$/;
  1246. return path.split(".").map(component => {
  1247. const m = component.match(positionPattern);
  1248. if (m) {
  1249. return {
  1250. name: m[1],
  1251. pos: parseInt(m[2], 10)
  1252. };
  1253. }
  1254. return {
  1255. name: component,
  1256. pos: 0
  1257. };
  1258. });
  1259. }
  1260. function escapePDFName(str) {
  1261. const buffer = [];
  1262. let start = 0;
  1263. for (let i = 0, ii = str.length; i < ii; i++) {
  1264. const char = str.charCodeAt(i);
  1265. if (char < 0x21 || char > 0x7e || char === 0x23 || char === 0x28 || char === 0x29 || char === 0x3c || char === 0x3e || char === 0x5b || char === 0x5d || char === 0x7b || char === 0x7d || char === 0x2f || char === 0x25) {
  1266. if (start < i) {
  1267. buffer.push(str.substring(start, i));
  1268. }
  1269. buffer.push(`#${char.toString(16)}`);
  1270. start = i + 1;
  1271. }
  1272. }
  1273. if (buffer.length === 0) {
  1274. return str;
  1275. }
  1276. if (start < str.length) {
  1277. buffer.push(str.substring(start, str.length));
  1278. }
  1279. return buffer.join("");
  1280. }
  1281. function escapeString(str) {
  1282. return str.replaceAll(/([()\\\n\r])/g, match => {
  1283. if (match === "\n") {
  1284. return "\\n";
  1285. } else if (match === "\r") {
  1286. return "\\r";
  1287. }
  1288. return `\\${match}`;
  1289. });
  1290. }
  1291. function _collectJS(entry, xref, list, parents) {
  1292. if (!entry) {
  1293. return;
  1294. }
  1295. let parent = null;
  1296. if (entry instanceof Ref) {
  1297. if (parents.has(entry)) {
  1298. return;
  1299. }
  1300. parent = entry;
  1301. parents.put(parent);
  1302. entry = xref.fetch(entry);
  1303. }
  1304. if (Array.isArray(entry)) {
  1305. for (const element of entry) {
  1306. _collectJS(element, xref, list, parents);
  1307. }
  1308. } else if (entry instanceof Dict) {
  1309. if (isName(entry.get("S"), "JavaScript")) {
  1310. const js = entry.get("JS");
  1311. let code;
  1312. if (js instanceof BaseStream) {
  1313. code = js.getString();
  1314. } else if (typeof js === "string") {
  1315. code = js;
  1316. }
  1317. code &&= stringToPDFString(code).replaceAll("\x00", "");
  1318. if (code) {
  1319. list.push(code);
  1320. }
  1321. }
  1322. _collectJS(entry.getRaw("Next"), xref, list, parents);
  1323. }
  1324. if (parent) {
  1325. parents.remove(parent);
  1326. }
  1327. }
  1328. function collectActions(xref, dict, eventType) {
  1329. const actions = Object.create(null);
  1330. const additionalActionsDicts = getInheritableProperty({
  1331. dict,
  1332. key: "AA",
  1333. stopWhenFound: false
  1334. });
  1335. if (additionalActionsDicts) {
  1336. for (let i = additionalActionsDicts.length - 1; i >= 0; i--) {
  1337. const additionalActions = additionalActionsDicts[i];
  1338. if (!(additionalActions instanceof Dict)) {
  1339. continue;
  1340. }
  1341. for (const key of additionalActions.getKeys()) {
  1342. const action = eventType[key];
  1343. if (!action) {
  1344. continue;
  1345. }
  1346. const actionDict = additionalActions.getRaw(key);
  1347. const parents = new RefSet();
  1348. const list = [];
  1349. _collectJS(actionDict, xref, list, parents);
  1350. if (list.length > 0) {
  1351. actions[action] = list;
  1352. }
  1353. }
  1354. }
  1355. }
  1356. if (dict.has("A")) {
  1357. const actionDict = dict.get("A");
  1358. const parents = new RefSet();
  1359. const list = [];
  1360. _collectJS(actionDict, xref, list, parents);
  1361. if (list.length > 0) {
  1362. actions.Action = list;
  1363. }
  1364. }
  1365. return objectSize(actions) > 0 ? actions : null;
  1366. }
  1367. const XMLEntities = {
  1368. 0x3c: "&lt;",
  1369. 0x3e: "&gt;",
  1370. 0x26: "&amp;",
  1371. 0x22: "&quot;",
  1372. 0x27: "&apos;"
  1373. };
  1374. function encodeToXmlString(str) {
  1375. const buffer = [];
  1376. let start = 0;
  1377. for (let i = 0, ii = str.length; i < ii; i++) {
  1378. const char = str.codePointAt(i);
  1379. if (0x20 <= char && char <= 0x7e) {
  1380. const entity = XMLEntities[char];
  1381. if (entity) {
  1382. if (start < i) {
  1383. buffer.push(str.substring(start, i));
  1384. }
  1385. buffer.push(entity);
  1386. start = i + 1;
  1387. }
  1388. } else {
  1389. if (start < i) {
  1390. buffer.push(str.substring(start, i));
  1391. }
  1392. buffer.push(`&#x${char.toString(16).toUpperCase()};`);
  1393. if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
  1394. i++;
  1395. }
  1396. start = i + 1;
  1397. }
  1398. }
  1399. if (buffer.length === 0) {
  1400. return str;
  1401. }
  1402. if (start < str.length) {
  1403. buffer.push(str.substring(start, str.length));
  1404. }
  1405. return buffer.join("");
  1406. }
  1407. function validateFontName(fontFamily, mustWarn = false) {
  1408. const m = /^("|').*("|')$/.exec(fontFamily);
  1409. if (m && m[1] === m[2]) {
  1410. const re = new RegExp(`[^\\\\]${m[1]}`);
  1411. if (re.test(fontFamily.slice(1, -1))) {
  1412. if (mustWarn) {
  1413. warn(`FontFamily contains unescaped ${m[1]}: ${fontFamily}.`);
  1414. }
  1415. return false;
  1416. }
  1417. } else {
  1418. for (const ident of fontFamily.split(/[ \t]+/)) {
  1419. if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
  1420. if (mustWarn) {
  1421. warn(`FontFamily contains invalid <custom-ident>: ${fontFamily}.`);
  1422. }
  1423. return false;
  1424. }
  1425. }
  1426. }
  1427. return true;
  1428. }
  1429. function validateCSSFont(cssFontInfo) {
  1430. const DEFAULT_CSS_FONT_OBLIQUE = "14";
  1431. const DEFAULT_CSS_FONT_WEIGHT = "400";
  1432. const CSS_FONT_WEIGHT_VALUES = new Set(["100", "200", "300", "400", "500", "600", "700", "800", "900", "1000", "normal", "bold", "bolder", "lighter"]);
  1433. const {
  1434. fontFamily,
  1435. fontWeight,
  1436. italicAngle
  1437. } = cssFontInfo;
  1438. if (!validateFontName(fontFamily, true)) {
  1439. return false;
  1440. }
  1441. const weight = fontWeight ? fontWeight.toString() : "";
  1442. cssFontInfo.fontWeight = CSS_FONT_WEIGHT_VALUES.has(weight) ? weight : DEFAULT_CSS_FONT_WEIGHT;
  1443. const angle = parseFloat(italicAngle);
  1444. cssFontInfo.italicAngle = isNaN(angle) || angle < -90 || angle > 90 ? DEFAULT_CSS_FONT_OBLIQUE : italicAngle.toString();
  1445. return true;
  1446. }
  1447. function recoverJsURL(str) {
  1448. const URL_OPEN_METHODS = ["app.launchURL", "window.open", "xfa.host.gotoURL"];
  1449. const regex = new RegExp("^\\s*(" + URL_OPEN_METHODS.join("|").replaceAll(".", "\\.") + ")\\((?:'|\")([^'\"]*)(?:'|\")(?:,\\s*(\\w+)\\)|\\))", "i");
  1450. const jsUrl = regex.exec(str);
  1451. if (jsUrl?.[2]) {
  1452. const url = jsUrl[2];
  1453. let newWindow = false;
  1454. if (jsUrl[3] === "true" && jsUrl[1] === "app.launchURL") {
  1455. newWindow = true;
  1456. }
  1457. return {
  1458. url,
  1459. newWindow
  1460. };
  1461. }
  1462. return null;
  1463. }
  1464. function numberToString(value) {
  1465. if (Number.isInteger(value)) {
  1466. return value.toString();
  1467. }
  1468. const roundedValue = Math.round(value * 100);
  1469. if (roundedValue % 100 === 0) {
  1470. return (roundedValue / 100).toString();
  1471. }
  1472. if (roundedValue % 10 === 0) {
  1473. return value.toFixed(1);
  1474. }
  1475. return value.toFixed(2);
  1476. }
  1477. function getNewAnnotationsMap(annotationStorage) {
  1478. if (!annotationStorage) {
  1479. return null;
  1480. }
  1481. const newAnnotationsByPage = new Map();
  1482. for (const [key, value] of annotationStorage) {
  1483. if (!key.startsWith(AnnotationEditorPrefix)) {
  1484. continue;
  1485. }
  1486. let annotations = newAnnotationsByPage.get(value.pageIndex);
  1487. if (!annotations) {
  1488. annotations = [];
  1489. newAnnotationsByPage.set(value.pageIndex, annotations);
  1490. }
  1491. annotations.push(value);
  1492. }
  1493. return newAnnotationsByPage.size > 0 ? newAnnotationsByPage : null;
  1494. }
  1495. function isAscii(str) {
  1496. return /^[\x00-\x7F]*$/.test(str);
  1497. }
  1498. function stringToUTF16HexString(str) {
  1499. const buf = [];
  1500. for (let i = 0, ii = str.length; i < ii; i++) {
  1501. const char = str.charCodeAt(i);
  1502. buf.push((char >> 8 & 0xff).toString(16).padStart(2, "0"), (char & 0xff).toString(16).padStart(2, "0"));
  1503. }
  1504. return buf.join("");
  1505. }
  1506. function stringToUTF16String(str, bigEndian = false) {
  1507. const buf = [];
  1508. if (bigEndian) {
  1509. buf.push("\xFE\xFF");
  1510. }
  1511. for (let i = 0, ii = str.length; i < ii; i++) {
  1512. const char = str.charCodeAt(i);
  1513. buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
  1514. }
  1515. return buf.join("");
  1516. }
  1517. function getRotationMatrix(rotation, width, height) {
  1518. switch (rotation) {
  1519. case 90:
  1520. return [0, 1, -1, 0, width, 0];
  1521. case 180:
  1522. return [-1, 0, 0, -1, width, height];
  1523. case 270:
  1524. return [0, -1, 1, 0, 0, height];
  1525. default:
  1526. throw new Error("Invalid rotation");
  1527. }
  1528. }
  1529. ;// CONCATENATED MODULE: ./src/core/stream.js
  1530. class Stream extends BaseStream {
  1531. constructor(arrayBuffer, start, length, dict) {
  1532. super();
  1533. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  1534. this.start = start || 0;
  1535. this.pos = this.start;
  1536. this.end = start + length || this.bytes.length;
  1537. this.dict = dict;
  1538. }
  1539. get length() {
  1540. return this.end - this.start;
  1541. }
  1542. get isEmpty() {
  1543. return this.length === 0;
  1544. }
  1545. getByte() {
  1546. if (this.pos >= this.end) {
  1547. return -1;
  1548. }
  1549. return this.bytes[this.pos++];
  1550. }
  1551. getBytes(length) {
  1552. const bytes = this.bytes;
  1553. const pos = this.pos;
  1554. const strEnd = this.end;
  1555. if (!length) {
  1556. return bytes.subarray(pos, strEnd);
  1557. }
  1558. let end = pos + length;
  1559. if (end > strEnd) {
  1560. end = strEnd;
  1561. }
  1562. this.pos = end;
  1563. return bytes.subarray(pos, end);
  1564. }
  1565. getByteRange(begin, end) {
  1566. if (begin < 0) {
  1567. begin = 0;
  1568. }
  1569. if (end > this.end) {
  1570. end = this.end;
  1571. }
  1572. return this.bytes.subarray(begin, end);
  1573. }
  1574. reset() {
  1575. this.pos = this.start;
  1576. }
  1577. moveStart() {
  1578. this.start = this.pos;
  1579. }
  1580. makeSubStream(start, length, dict = null) {
  1581. return new Stream(this.bytes.buffer, start, length, dict);
  1582. }
  1583. }
  1584. class StringStream extends Stream {
  1585. constructor(str) {
  1586. super(stringToBytes(str));
  1587. }
  1588. }
  1589. class NullStream extends Stream {
  1590. constructor() {
  1591. super(new Uint8Array(0));
  1592. }
  1593. }
  1594. ;// CONCATENATED MODULE: ./src/core/chunked_stream.js
  1595. class ChunkedStream extends Stream {
  1596. constructor(length, chunkSize, manager) {
  1597. super(new Uint8Array(length), 0, length, null);
  1598. this.chunkSize = chunkSize;
  1599. this._loadedChunks = new Set();
  1600. this.numChunks = Math.ceil(length / chunkSize);
  1601. this.manager = manager;
  1602. this.progressiveDataLength = 0;
  1603. this.lastSuccessfulEnsureByteChunk = -1;
  1604. }
  1605. getMissingChunks() {
  1606. const chunks = [];
  1607. for (let chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1608. if (!this._loadedChunks.has(chunk)) {
  1609. chunks.push(chunk);
  1610. }
  1611. }
  1612. return chunks;
  1613. }
  1614. get numChunksLoaded() {
  1615. return this._loadedChunks.size;
  1616. }
  1617. get isDataLoaded() {
  1618. return this.numChunksLoaded === this.numChunks;
  1619. }
  1620. onReceiveData(begin, chunk) {
  1621. const chunkSize = this.chunkSize;
  1622. if (begin % chunkSize !== 0) {
  1623. throw new Error(`Bad begin offset: ${begin}`);
  1624. }
  1625. const end = begin + chunk.byteLength;
  1626. if (end % chunkSize !== 0 && end !== this.bytes.length) {
  1627. throw new Error(`Bad end offset: ${end}`);
  1628. }
  1629. this.bytes.set(new Uint8Array(chunk), begin);
  1630. const beginChunk = Math.floor(begin / chunkSize);
  1631. const endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1632. for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1633. this._loadedChunks.add(curChunk);
  1634. }
  1635. }
  1636. onReceiveProgressiveData(data) {
  1637. let position = this.progressiveDataLength;
  1638. const beginChunk = Math.floor(position / this.chunkSize);
  1639. this.bytes.set(new Uint8Array(data), position);
  1640. position += data.byteLength;
  1641. this.progressiveDataLength = position;
  1642. const endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  1643. for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1644. this._loadedChunks.add(curChunk);
  1645. }
  1646. }
  1647. ensureByte(pos) {
  1648. if (pos < this.progressiveDataLength) {
  1649. return;
  1650. }
  1651. const chunk = Math.floor(pos / this.chunkSize);
  1652. if (chunk > this.numChunks) {
  1653. return;
  1654. }
  1655. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1656. return;
  1657. }
  1658. if (!this._loadedChunks.has(chunk)) {
  1659. throw new MissingDataException(pos, pos + 1);
  1660. }
  1661. this.lastSuccessfulEnsureByteChunk = chunk;
  1662. }
  1663. ensureRange(begin, end) {
  1664. if (begin >= end) {
  1665. return;
  1666. }
  1667. if (end <= this.progressiveDataLength) {
  1668. return;
  1669. }
  1670. const beginChunk = Math.floor(begin / this.chunkSize);
  1671. if (beginChunk > this.numChunks) {
  1672. return;
  1673. }
  1674. const endChunk = Math.min(Math.floor((end - 1) / this.chunkSize) + 1, this.numChunks);
  1675. for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
  1676. if (!this._loadedChunks.has(chunk)) {
  1677. throw new MissingDataException(begin, end);
  1678. }
  1679. }
  1680. }
  1681. nextEmptyChunk(beginChunk) {
  1682. const numChunks = this.numChunks;
  1683. for (let i = 0; i < numChunks; ++i) {
  1684. const chunk = (beginChunk + i) % numChunks;
  1685. if (!this._loadedChunks.has(chunk)) {
  1686. return chunk;
  1687. }
  1688. }
  1689. return null;
  1690. }
  1691. hasChunk(chunk) {
  1692. return this._loadedChunks.has(chunk);
  1693. }
  1694. getByte() {
  1695. const pos = this.pos;
  1696. if (pos >= this.end) {
  1697. return -1;
  1698. }
  1699. if (pos >= this.progressiveDataLength) {
  1700. this.ensureByte(pos);
  1701. }
  1702. return this.bytes[this.pos++];
  1703. }
  1704. getBytes(length) {
  1705. const bytes = this.bytes;
  1706. const pos = this.pos;
  1707. const strEnd = this.end;
  1708. if (!length) {
  1709. if (strEnd > this.progressiveDataLength) {
  1710. this.ensureRange(pos, strEnd);
  1711. }
  1712. return bytes.subarray(pos, strEnd);
  1713. }
  1714. let end = pos + length;
  1715. if (end > strEnd) {
  1716. end = strEnd;
  1717. }
  1718. if (end > this.progressiveDataLength) {
  1719. this.ensureRange(pos, end);
  1720. }
  1721. this.pos = end;
  1722. return bytes.subarray(pos, end);
  1723. }
  1724. getByteRange(begin, end) {
  1725. if (begin < 0) {
  1726. begin = 0;
  1727. }
  1728. if (end > this.end) {
  1729. end = this.end;
  1730. }
  1731. if (end > this.progressiveDataLength) {
  1732. this.ensureRange(begin, end);
  1733. }
  1734. return this.bytes.subarray(begin, end);
  1735. }
  1736. makeSubStream(start, length, dict = null) {
  1737. if (length) {
  1738. if (start + length > this.progressiveDataLength) {
  1739. this.ensureRange(start, start + length);
  1740. }
  1741. } else if (start >= this.progressiveDataLength) {
  1742. this.ensureByte(start);
  1743. }
  1744. function ChunkedStreamSubstream() {}
  1745. ChunkedStreamSubstream.prototype = Object.create(this);
  1746. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  1747. const chunkSize = this.chunkSize;
  1748. const beginChunk = Math.floor(this.start / chunkSize);
  1749. const endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1750. const missingChunks = [];
  1751. for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
  1752. if (!this._loadedChunks.has(chunk)) {
  1753. missingChunks.push(chunk);
  1754. }
  1755. }
  1756. return missingChunks;
  1757. };
  1758. Object.defineProperty(ChunkedStreamSubstream.prototype, "isDataLoaded", {
  1759. get() {
  1760. if (this.numChunksLoaded === this.numChunks) {
  1761. return true;
  1762. }
  1763. return this.getMissingChunks().length === 0;
  1764. },
  1765. configurable: true
  1766. });
  1767. const subStream = new ChunkedStreamSubstream();
  1768. subStream.pos = subStream.start = start;
  1769. subStream.end = start + length || this.end;
  1770. subStream.dict = dict;
  1771. return subStream;
  1772. }
  1773. getBaseStreams() {
  1774. return [this];
  1775. }
  1776. }
  1777. class ChunkedStreamManager {
  1778. constructor(pdfNetworkStream, args) {
  1779. this.length = args.length;
  1780. this.chunkSize = args.rangeChunkSize;
  1781. this.stream = new ChunkedStream(this.length, this.chunkSize, this);
  1782. this.pdfNetworkStream = pdfNetworkStream;
  1783. this.disableAutoFetch = args.disableAutoFetch;
  1784. this.msgHandler = args.msgHandler;
  1785. this.currRequestId = 0;
  1786. this._chunksNeededByRequest = new Map();
  1787. this._requestsByChunk = new Map();
  1788. this._promisesByRequest = new Map();
  1789. this.progressiveDataLength = 0;
  1790. this.aborted = false;
  1791. this._loadedStreamCapability = new PromiseCapability();
  1792. }
  1793. sendRequest(begin, end) {
  1794. const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  1795. if (!rangeReader.isStreamingSupported) {
  1796. rangeReader.onProgress = this.onProgress.bind(this);
  1797. }
  1798. let chunks = [],
  1799. loaded = 0;
  1800. return new Promise((resolve, reject) => {
  1801. const readChunk = ({
  1802. value,
  1803. done
  1804. }) => {
  1805. try {
  1806. if (done) {
  1807. const chunkData = arrayBuffersToBytes(chunks);
  1808. chunks = null;
  1809. resolve(chunkData);
  1810. return;
  1811. }
  1812. loaded += value.byteLength;
  1813. if (rangeReader.isStreamingSupported) {
  1814. this.onProgress({
  1815. loaded
  1816. });
  1817. }
  1818. chunks.push(value);
  1819. rangeReader.read().then(readChunk, reject);
  1820. } catch (e) {
  1821. reject(e);
  1822. }
  1823. };
  1824. rangeReader.read().then(readChunk, reject);
  1825. }).then(data => {
  1826. if (this.aborted) {
  1827. return;
  1828. }
  1829. this.onReceiveData({
  1830. chunk: data,
  1831. begin
  1832. });
  1833. });
  1834. }
  1835. requestAllChunks(noFetch = false) {
  1836. if (!noFetch) {
  1837. const missingChunks = this.stream.getMissingChunks();
  1838. this._requestChunks(missingChunks);
  1839. }
  1840. return this._loadedStreamCapability.promise;
  1841. }
  1842. _requestChunks(chunks) {
  1843. const requestId = this.currRequestId++;
  1844. const chunksNeeded = new Set();
  1845. this._chunksNeededByRequest.set(requestId, chunksNeeded);
  1846. for (const chunk of chunks) {
  1847. if (!this.stream.hasChunk(chunk)) {
  1848. chunksNeeded.add(chunk);
  1849. }
  1850. }
  1851. if (chunksNeeded.size === 0) {
  1852. return Promise.resolve();
  1853. }
  1854. const capability = new PromiseCapability();
  1855. this._promisesByRequest.set(requestId, capability);
  1856. const chunksToRequest = [];
  1857. for (const chunk of chunksNeeded) {
  1858. let requestIds = this._requestsByChunk.get(chunk);
  1859. if (!requestIds) {
  1860. requestIds = [];
  1861. this._requestsByChunk.set(chunk, requestIds);
  1862. chunksToRequest.push(chunk);
  1863. }
  1864. requestIds.push(requestId);
  1865. }
  1866. if (chunksToRequest.length > 0) {
  1867. const groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1868. for (const groupedChunk of groupedChunksToRequest) {
  1869. const begin = groupedChunk.beginChunk * this.chunkSize;
  1870. const end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1871. this.sendRequest(begin, end).catch(capability.reject);
  1872. }
  1873. }
  1874. return capability.promise.catch(reason => {
  1875. if (this.aborted) {
  1876. return;
  1877. }
  1878. throw reason;
  1879. });
  1880. }
  1881. getStream() {
  1882. return this.stream;
  1883. }
  1884. requestRange(begin, end) {
  1885. end = Math.min(end, this.length);
  1886. const beginChunk = this.getBeginChunk(begin);
  1887. const endChunk = this.getEndChunk(end);
  1888. const chunks = [];
  1889. for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
  1890. chunks.push(chunk);
  1891. }
  1892. return this._requestChunks(chunks);
  1893. }
  1894. requestRanges(ranges = []) {
  1895. const chunksToRequest = [];
  1896. for (const range of ranges) {
  1897. const beginChunk = this.getBeginChunk(range.begin);
  1898. const endChunk = this.getEndChunk(range.end);
  1899. for (let chunk = beginChunk; chunk < endChunk; ++chunk) {
  1900. if (!chunksToRequest.includes(chunk)) {
  1901. chunksToRequest.push(chunk);
  1902. }
  1903. }
  1904. }
  1905. chunksToRequest.sort(function (a, b) {
  1906. return a - b;
  1907. });
  1908. return this._requestChunks(chunksToRequest);
  1909. }
  1910. groupChunks(chunks) {
  1911. const groupedChunks = [];
  1912. let beginChunk = -1;
  1913. let prevChunk = -1;
  1914. for (let i = 0, ii = chunks.length; i < ii; ++i) {
  1915. const chunk = chunks[i];
  1916. if (beginChunk < 0) {
  1917. beginChunk = chunk;
  1918. }
  1919. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1920. groupedChunks.push({
  1921. beginChunk,
  1922. endChunk: prevChunk + 1
  1923. });
  1924. beginChunk = chunk;
  1925. }
  1926. if (i + 1 === chunks.length) {
  1927. groupedChunks.push({
  1928. beginChunk,
  1929. endChunk: chunk + 1
  1930. });
  1931. }
  1932. prevChunk = chunk;
  1933. }
  1934. return groupedChunks;
  1935. }
  1936. onProgress(args) {
  1937. this.msgHandler.send("DocProgress", {
  1938. loaded: this.stream.numChunksLoaded * this.chunkSize + args.loaded,
  1939. total: this.length
  1940. });
  1941. }
  1942. onReceiveData(args) {
  1943. const chunk = args.chunk;
  1944. const isProgressive = args.begin === undefined;
  1945. const begin = isProgressive ? this.progressiveDataLength : args.begin;
  1946. const end = begin + chunk.byteLength;
  1947. const beginChunk = Math.floor(begin / this.chunkSize);
  1948. const endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  1949. if (isProgressive) {
  1950. this.stream.onReceiveProgressiveData(chunk);
  1951. this.progressiveDataLength = end;
  1952. } else {
  1953. this.stream.onReceiveData(begin, chunk);
  1954. }
  1955. if (this.stream.isDataLoaded) {
  1956. this._loadedStreamCapability.resolve(this.stream);
  1957. }
  1958. const loadedRequests = [];
  1959. for (let curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1960. const requestIds = this._requestsByChunk.get(curChunk);
  1961. if (!requestIds) {
  1962. continue;
  1963. }
  1964. this._requestsByChunk.delete(curChunk);
  1965. for (const requestId of requestIds) {
  1966. const chunksNeeded = this._chunksNeededByRequest.get(requestId);
  1967. if (chunksNeeded.has(curChunk)) {
  1968. chunksNeeded.delete(curChunk);
  1969. }
  1970. if (chunksNeeded.size > 0) {
  1971. continue;
  1972. }
  1973. loadedRequests.push(requestId);
  1974. }
  1975. }
  1976. if (!this.disableAutoFetch && this._requestsByChunk.size === 0) {
  1977. let nextEmptyChunk;
  1978. if (this.stream.numChunksLoaded === 1) {
  1979. const lastChunk = this.stream.numChunks - 1;
  1980. if (!this.stream.hasChunk(lastChunk)) {
  1981. nextEmptyChunk = lastChunk;
  1982. }
  1983. } else {
  1984. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  1985. }
  1986. if (Number.isInteger(nextEmptyChunk)) {
  1987. this._requestChunks([nextEmptyChunk]);
  1988. }
  1989. }
  1990. for (const requestId of loadedRequests) {
  1991. const capability = this._promisesByRequest.get(requestId);
  1992. this._promisesByRequest.delete(requestId);
  1993. capability.resolve();
  1994. }
  1995. this.msgHandler.send("DocProgress", {
  1996. loaded: this.stream.numChunksLoaded * this.chunkSize,
  1997. total: this.length
  1998. });
  1999. }
  2000. onError(err) {
  2001. this._loadedStreamCapability.reject(err);
  2002. }
  2003. getBeginChunk(begin) {
  2004. return Math.floor(begin / this.chunkSize);
  2005. }
  2006. getEndChunk(end) {
  2007. return Math.floor((end - 1) / this.chunkSize) + 1;
  2008. }
  2009. abort(reason) {
  2010. this.aborted = true;
  2011. this.pdfNetworkStream?.cancelAllRequests(reason);
  2012. for (const capability of this._promisesByRequest.values()) {
  2013. capability.reject(reason);
  2014. }
  2015. }
  2016. }
  2017. ;// CONCATENATED MODULE: ./src/core/colorspace.js
  2018. function resizeRgbImage(src, dest, w1, h1, w2, h2, alpha01) {
  2019. const COMPONENTS = 3;
  2020. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  2021. const xRatio = w1 / w2;
  2022. const yRatio = h1 / h2;
  2023. let newIndex = 0,
  2024. oldIndex;
  2025. const xScaled = new Uint16Array(w2);
  2026. const w1Scanline = w1 * COMPONENTS;
  2027. for (let i = 0; i < w2; i++) {
  2028. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  2029. }
  2030. for (let i = 0; i < h2; i++) {
  2031. const py = Math.floor(i * yRatio) * w1Scanline;
  2032. for (let j = 0; j < w2; j++) {
  2033. oldIndex = py + xScaled[j];
  2034. dest[newIndex++] = src[oldIndex++];
  2035. dest[newIndex++] = src[oldIndex++];
  2036. dest[newIndex++] = src[oldIndex++];
  2037. newIndex += alpha01;
  2038. }
  2039. }
  2040. }
  2041. class ColorSpace {
  2042. constructor(name, numComps) {
  2043. if (this.constructor === ColorSpace) {
  2044. unreachable("Cannot initialize ColorSpace.");
  2045. }
  2046. this.name = name;
  2047. this.numComps = numComps;
  2048. }
  2049. getRgb(src, srcOffset) {
  2050. const rgb = new Uint8ClampedArray(3);
  2051. this.getRgbItem(src, srcOffset, rgb, 0);
  2052. return rgb;
  2053. }
  2054. getRgbItem(src, srcOffset, dest, destOffset) {
  2055. unreachable("Should not call ColorSpace.getRgbItem");
  2056. }
  2057. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2058. unreachable("Should not call ColorSpace.getRgbBuffer");
  2059. }
  2060. getOutputLength(inputLength, alpha01) {
  2061. unreachable("Should not call ColorSpace.getOutputLength");
  2062. }
  2063. isPassthrough(bits) {
  2064. return false;
  2065. }
  2066. isDefaultDecode(decodeMap, bpc) {
  2067. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  2068. }
  2069. fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  2070. const count = originalWidth * originalHeight;
  2071. let rgbBuf = null;
  2072. const numComponentColors = 1 << bpc;
  2073. const needsResizing = originalHeight !== height || originalWidth !== width;
  2074. if (this.isPassthrough(bpc)) {
  2075. rgbBuf = comps;
  2076. } else if (this.numComps === 1 && count > numComponentColors && this.name !== "DeviceGray" && this.name !== "DeviceRGB") {
  2077. const allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  2078. for (let i = 0; i < numComponentColors; i++) {
  2079. allColors[i] = i;
  2080. }
  2081. const colorMap = new Uint8ClampedArray(numComponentColors * 3);
  2082. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, 0);
  2083. if (!needsResizing) {
  2084. let destPos = 0;
  2085. for (let i = 0; i < count; ++i) {
  2086. const key = comps[i] * 3;
  2087. dest[destPos++] = colorMap[key];
  2088. dest[destPos++] = colorMap[key + 1];
  2089. dest[destPos++] = colorMap[key + 2];
  2090. destPos += alpha01;
  2091. }
  2092. } else {
  2093. rgbBuf = new Uint8Array(count * 3);
  2094. let rgbPos = 0;
  2095. for (let i = 0; i < count; ++i) {
  2096. const key = comps[i] * 3;
  2097. rgbBuf[rgbPos++] = colorMap[key];
  2098. rgbBuf[rgbPos++] = colorMap[key + 1];
  2099. rgbBuf[rgbPos++] = colorMap[key + 2];
  2100. }
  2101. }
  2102. } else if (!needsResizing) {
  2103. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  2104. } else {
  2105. rgbBuf = new Uint8ClampedArray(count * 3);
  2106. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, 0);
  2107. }
  2108. if (rgbBuf) {
  2109. if (needsResizing) {
  2110. resizeRgbImage(rgbBuf, dest, originalWidth, originalHeight, width, height, alpha01);
  2111. } else {
  2112. let destPos = 0,
  2113. rgbPos = 0;
  2114. for (let i = 0, ii = width * actualHeight; i < ii; i++) {
  2115. dest[destPos++] = rgbBuf[rgbPos++];
  2116. dest[destPos++] = rgbBuf[rgbPos++];
  2117. dest[destPos++] = rgbBuf[rgbPos++];
  2118. destPos += alpha01;
  2119. }
  2120. }
  2121. }
  2122. }
  2123. get usesZeroToOneRange() {
  2124. return shadow(this, "usesZeroToOneRange", true);
  2125. }
  2126. static _cache(cacheKey, xref, localColorSpaceCache, parsedColorSpace) {
  2127. if (!localColorSpaceCache) {
  2128. throw new Error('ColorSpace._cache - expected "localColorSpaceCache" argument.');
  2129. }
  2130. if (!parsedColorSpace) {
  2131. throw new Error('ColorSpace._cache - expected "parsedColorSpace" argument.');
  2132. }
  2133. let csName, csRef;
  2134. if (cacheKey instanceof Ref) {
  2135. csRef = cacheKey;
  2136. cacheKey = xref.fetch(cacheKey);
  2137. }
  2138. if (cacheKey instanceof Name) {
  2139. csName = cacheKey.name;
  2140. }
  2141. if (csName || csRef) {
  2142. localColorSpaceCache.set(csName, csRef, parsedColorSpace);
  2143. }
  2144. }
  2145. static getCached(cacheKey, xref, localColorSpaceCache) {
  2146. if (!localColorSpaceCache) {
  2147. throw new Error('ColorSpace.getCached - expected "localColorSpaceCache" argument.');
  2148. }
  2149. if (cacheKey instanceof Ref) {
  2150. const localColorSpace = localColorSpaceCache.getByRef(cacheKey);
  2151. if (localColorSpace) {
  2152. return localColorSpace;
  2153. }
  2154. try {
  2155. cacheKey = xref.fetch(cacheKey);
  2156. } catch (ex) {
  2157. if (ex instanceof MissingDataException) {
  2158. throw ex;
  2159. }
  2160. }
  2161. }
  2162. if (cacheKey instanceof Name) {
  2163. const localColorSpace = localColorSpaceCache.getByName(cacheKey.name);
  2164. if (localColorSpace) {
  2165. return localColorSpace;
  2166. }
  2167. }
  2168. return null;
  2169. }
  2170. static async parseAsync({
  2171. cs,
  2172. xref,
  2173. resources = null,
  2174. pdfFunctionFactory,
  2175. localColorSpaceCache
  2176. }) {
  2177. const parsedColorSpace = this._parse(cs, xref, resources, pdfFunctionFactory);
  2178. this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
  2179. return parsedColorSpace;
  2180. }
  2181. static parse({
  2182. cs,
  2183. xref,
  2184. resources = null,
  2185. pdfFunctionFactory,
  2186. localColorSpaceCache
  2187. }) {
  2188. const cachedColorSpace = this.getCached(cs, xref, localColorSpaceCache);
  2189. if (cachedColorSpace) {
  2190. return cachedColorSpace;
  2191. }
  2192. const parsedColorSpace = this._parse(cs, xref, resources, pdfFunctionFactory);
  2193. this._cache(cs, xref, localColorSpaceCache, parsedColorSpace);
  2194. return parsedColorSpace;
  2195. }
  2196. static _parse(cs, xref, resources = null, pdfFunctionFactory) {
  2197. cs = xref.fetchIfRef(cs);
  2198. if (cs instanceof Name) {
  2199. switch (cs.name) {
  2200. case "G":
  2201. case "DeviceGray":
  2202. return this.singletons.gray;
  2203. case "RGB":
  2204. case "DeviceRGB":
  2205. return this.singletons.rgb;
  2206. case "CMYK":
  2207. case "DeviceCMYK":
  2208. return this.singletons.cmyk;
  2209. case "Pattern":
  2210. return new PatternCS(null);
  2211. default:
  2212. if (resources instanceof Dict) {
  2213. const colorSpaces = resources.get("ColorSpace");
  2214. if (colorSpaces instanceof Dict) {
  2215. const resourcesCS = colorSpaces.get(cs.name);
  2216. if (resourcesCS) {
  2217. if (resourcesCS instanceof Name) {
  2218. return this._parse(resourcesCS, xref, resources, pdfFunctionFactory);
  2219. }
  2220. cs = resourcesCS;
  2221. break;
  2222. }
  2223. }
  2224. }
  2225. throw new FormatError(`Unrecognized ColorSpace: ${cs.name}`);
  2226. }
  2227. }
  2228. if (Array.isArray(cs)) {
  2229. const mode = xref.fetchIfRef(cs[0]).name;
  2230. let params, numComps, baseCS, whitePoint, blackPoint, gamma;
  2231. switch (mode) {
  2232. case "G":
  2233. case "DeviceGray":
  2234. return this.singletons.gray;
  2235. case "RGB":
  2236. case "DeviceRGB":
  2237. return this.singletons.rgb;
  2238. case "CMYK":
  2239. case "DeviceCMYK":
  2240. return this.singletons.cmyk;
  2241. case "CalGray":
  2242. params = xref.fetchIfRef(cs[1]);
  2243. whitePoint = params.getArray("WhitePoint");
  2244. blackPoint = params.getArray("BlackPoint");
  2245. gamma = params.get("Gamma");
  2246. return new CalGrayCS(whitePoint, blackPoint, gamma);
  2247. case "CalRGB":
  2248. params = xref.fetchIfRef(cs[1]);
  2249. whitePoint = params.getArray("WhitePoint");
  2250. blackPoint = params.getArray("BlackPoint");
  2251. gamma = params.getArray("Gamma");
  2252. const matrix = params.getArray("Matrix");
  2253. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  2254. case "ICCBased":
  2255. const stream = xref.fetchIfRef(cs[1]);
  2256. const dict = stream.dict;
  2257. numComps = dict.get("N");
  2258. const alt = dict.get("Alternate");
  2259. if (alt) {
  2260. const altCS = this._parse(alt, xref, resources, pdfFunctionFactory);
  2261. if (altCS.numComps === numComps) {
  2262. return altCS;
  2263. }
  2264. warn("ICCBased color space: Ignoring incorrect /Alternate entry.");
  2265. }
  2266. if (numComps === 1) {
  2267. return this.singletons.gray;
  2268. } else if (numComps === 3) {
  2269. return this.singletons.rgb;
  2270. } else if (numComps === 4) {
  2271. return this.singletons.cmyk;
  2272. }
  2273. break;
  2274. case "Pattern":
  2275. baseCS = cs[1] || null;
  2276. if (baseCS) {
  2277. baseCS = this._parse(baseCS, xref, resources, pdfFunctionFactory);
  2278. }
  2279. return new PatternCS(baseCS);
  2280. case "I":
  2281. case "Indexed":
  2282. baseCS = this._parse(cs[1], xref, resources, pdfFunctionFactory);
  2283. const hiVal = xref.fetchIfRef(cs[2]) + 1;
  2284. const lookup = xref.fetchIfRef(cs[3]);
  2285. return new IndexedCS(baseCS, hiVal, lookup);
  2286. case "Separation":
  2287. case "DeviceN":
  2288. const name = xref.fetchIfRef(cs[1]);
  2289. numComps = Array.isArray(name) ? name.length : 1;
  2290. baseCS = this._parse(cs[2], xref, resources, pdfFunctionFactory);
  2291. const tintFn = pdfFunctionFactory.create(cs[3]);
  2292. return new AlternateCS(numComps, baseCS, tintFn);
  2293. case "Lab":
  2294. params = xref.fetchIfRef(cs[1]);
  2295. whitePoint = params.getArray("WhitePoint");
  2296. blackPoint = params.getArray("BlackPoint");
  2297. const range = params.getArray("Range");
  2298. return new LabCS(whitePoint, blackPoint, range);
  2299. default:
  2300. throw new FormatError(`Unimplemented ColorSpace object: ${mode}`);
  2301. }
  2302. }
  2303. throw new FormatError(`Unrecognized ColorSpace object: ${cs}`);
  2304. }
  2305. static isDefaultDecode(decode, numComps) {
  2306. if (!Array.isArray(decode)) {
  2307. return true;
  2308. }
  2309. if (numComps * 2 !== decode.length) {
  2310. warn("The decode map is not the correct length");
  2311. return true;
  2312. }
  2313. for (let i = 0, ii = decode.length; i < ii; i += 2) {
  2314. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  2315. return false;
  2316. }
  2317. }
  2318. return true;
  2319. }
  2320. static get singletons() {
  2321. return shadow(this, "singletons", {
  2322. get gray() {
  2323. return shadow(this, "gray", new DeviceGrayCS());
  2324. },
  2325. get rgb() {
  2326. return shadow(this, "rgb", new DeviceRgbCS());
  2327. },
  2328. get cmyk() {
  2329. return shadow(this, "cmyk", new DeviceCmykCS());
  2330. }
  2331. });
  2332. }
  2333. }
  2334. class AlternateCS extends ColorSpace {
  2335. constructor(numComps, base, tintFn) {
  2336. super("Alternate", numComps);
  2337. this.base = base;
  2338. this.tintFn = tintFn;
  2339. this.tmpBuf = new Float32Array(base.numComps);
  2340. }
  2341. getRgbItem(src, srcOffset, dest, destOffset) {
  2342. const tmpBuf = this.tmpBuf;
  2343. this.tintFn(src, srcOffset, tmpBuf, 0);
  2344. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  2345. }
  2346. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2347. const tintFn = this.tintFn;
  2348. const base = this.base;
  2349. const scale = 1 / ((1 << bits) - 1);
  2350. const baseNumComps = base.numComps;
  2351. const usesZeroToOneRange = base.usesZeroToOneRange;
  2352. const isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  2353. let pos = isPassthrough ? destOffset : 0;
  2354. const baseBuf = isPassthrough ? dest : new Uint8ClampedArray(baseNumComps * count);
  2355. const numComps = this.numComps;
  2356. const scaled = new Float32Array(numComps);
  2357. const tinted = new Float32Array(baseNumComps);
  2358. let i, j;
  2359. for (i = 0; i < count; i++) {
  2360. for (j = 0; j < numComps; j++) {
  2361. scaled[j] = src[srcOffset++] * scale;
  2362. }
  2363. tintFn(scaled, 0, tinted, 0);
  2364. if (usesZeroToOneRange) {
  2365. for (j = 0; j < baseNumComps; j++) {
  2366. baseBuf[pos++] = tinted[j] * 255;
  2367. }
  2368. } else {
  2369. base.getRgbItem(tinted, 0, baseBuf, pos);
  2370. pos += baseNumComps;
  2371. }
  2372. }
  2373. if (!isPassthrough) {
  2374. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  2375. }
  2376. }
  2377. getOutputLength(inputLength, alpha01) {
  2378. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  2379. }
  2380. }
  2381. class PatternCS extends ColorSpace {
  2382. constructor(baseCS) {
  2383. super("Pattern", null);
  2384. this.base = baseCS;
  2385. }
  2386. isDefaultDecode(decodeMap, bpc) {
  2387. unreachable("Should not call PatternCS.isDefaultDecode");
  2388. }
  2389. }
  2390. class IndexedCS extends ColorSpace {
  2391. constructor(base, highVal, lookup) {
  2392. super("Indexed", 1);
  2393. this.base = base;
  2394. this.highVal = highVal;
  2395. const length = base.numComps * highVal;
  2396. this.lookup = new Uint8Array(length);
  2397. if (lookup instanceof BaseStream) {
  2398. const bytes = lookup.getBytes(length);
  2399. this.lookup.set(bytes);
  2400. } else if (typeof lookup === "string") {
  2401. for (let i = 0; i < length; ++i) {
  2402. this.lookup[i] = lookup.charCodeAt(i) & 0xff;
  2403. }
  2404. } else {
  2405. throw new FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`);
  2406. }
  2407. }
  2408. getRgbItem(src, srcOffset, dest, destOffset) {
  2409. const numComps = this.base.numComps;
  2410. const start = src[srcOffset] * numComps;
  2411. this.base.getRgbBuffer(this.lookup, start, 1, dest, destOffset, 8, 0);
  2412. }
  2413. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2414. const base = this.base;
  2415. const numComps = base.numComps;
  2416. const outputDelta = base.getOutputLength(numComps, alpha01);
  2417. const lookup = this.lookup;
  2418. for (let i = 0; i < count; ++i) {
  2419. const lookupPos = src[srcOffset++] * numComps;
  2420. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  2421. destOffset += outputDelta;
  2422. }
  2423. }
  2424. getOutputLength(inputLength, alpha01) {
  2425. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  2426. }
  2427. isDefaultDecode(decodeMap, bpc) {
  2428. if (!Array.isArray(decodeMap)) {
  2429. return true;
  2430. }
  2431. if (decodeMap.length !== 2) {
  2432. warn("Decode map length is not correct");
  2433. return true;
  2434. }
  2435. if (!Number.isInteger(bpc) || bpc < 1) {
  2436. warn("Bits per component is not correct");
  2437. return true;
  2438. }
  2439. return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
  2440. }
  2441. }
  2442. class DeviceGrayCS extends ColorSpace {
  2443. constructor() {
  2444. super("DeviceGray", 1);
  2445. }
  2446. getRgbItem(src, srcOffset, dest, destOffset) {
  2447. const c = src[srcOffset] * 255;
  2448. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  2449. }
  2450. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2451. const scale = 255 / ((1 << bits) - 1);
  2452. let j = srcOffset,
  2453. q = destOffset;
  2454. for (let i = 0; i < count; ++i) {
  2455. const c = scale * src[j++];
  2456. dest[q++] = c;
  2457. dest[q++] = c;
  2458. dest[q++] = c;
  2459. q += alpha01;
  2460. }
  2461. }
  2462. getOutputLength(inputLength, alpha01) {
  2463. return inputLength * (3 + alpha01);
  2464. }
  2465. }
  2466. class DeviceRgbCS extends ColorSpace {
  2467. constructor() {
  2468. super("DeviceRGB", 3);
  2469. }
  2470. getRgbItem(src, srcOffset, dest, destOffset) {
  2471. dest[destOffset] = src[srcOffset] * 255;
  2472. dest[destOffset + 1] = src[srcOffset + 1] * 255;
  2473. dest[destOffset + 2] = src[srcOffset + 2] * 255;
  2474. }
  2475. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2476. if (bits === 8 && alpha01 === 0) {
  2477. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  2478. return;
  2479. }
  2480. const scale = 255 / ((1 << bits) - 1);
  2481. let j = srcOffset,
  2482. q = destOffset;
  2483. for (let i = 0; i < count; ++i) {
  2484. dest[q++] = scale * src[j++];
  2485. dest[q++] = scale * src[j++];
  2486. dest[q++] = scale * src[j++];
  2487. q += alpha01;
  2488. }
  2489. }
  2490. getOutputLength(inputLength, alpha01) {
  2491. return inputLength * (3 + alpha01) / 3 | 0;
  2492. }
  2493. isPassthrough(bits) {
  2494. return bits === 8;
  2495. }
  2496. }
  2497. class DeviceCmykCS extends ColorSpace {
  2498. constructor() {
  2499. super("DeviceCMYK", 4);
  2500. }
  2501. #toRgb(src, srcOffset, srcScale, dest, destOffset) {
  2502. const c = src[srcOffset] * srcScale;
  2503. const m = src[srcOffset + 1] * srcScale;
  2504. const y = src[srcOffset + 2] * srcScale;
  2505. const k = src[srcOffset + 3] * srcScale;
  2506. dest[destOffset] = 255 + 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);
  2507. dest[destOffset + 1] = 255 + 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);
  2508. dest[destOffset + 2] = 255 + 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);
  2509. }
  2510. getRgbItem(src, srcOffset, dest, destOffset) {
  2511. this.#toRgb(src, srcOffset, 1, dest, destOffset);
  2512. }
  2513. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2514. const scale = 1 / ((1 << bits) - 1);
  2515. for (let i = 0; i < count; i++) {
  2516. this.#toRgb(src, srcOffset, scale, dest, destOffset);
  2517. srcOffset += 4;
  2518. destOffset += 3 + alpha01;
  2519. }
  2520. }
  2521. getOutputLength(inputLength, alpha01) {
  2522. return inputLength / 4 * (3 + alpha01) | 0;
  2523. }
  2524. }
  2525. class CalGrayCS extends ColorSpace {
  2526. constructor(whitePoint, blackPoint, gamma) {
  2527. super("CalGray", 1);
  2528. if (!whitePoint) {
  2529. throw new FormatError("WhitePoint missing - required for color space CalGray");
  2530. }
  2531. [this.XW, this.YW, this.ZW] = whitePoint;
  2532. [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
  2533. this.G = gamma || 1;
  2534. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  2535. throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);
  2536. }
  2537. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  2538. info(`Invalid BlackPoint for ${this.name}, falling back to default.`);
  2539. this.XB = this.YB = this.ZB = 0;
  2540. }
  2541. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  2542. warn(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ` + `ZB: ${this.ZB}, only default values are supported.`);
  2543. }
  2544. if (this.G < 1) {
  2545. info(`Invalid Gamma: ${this.G} for ${this.name}, falling back to default.`);
  2546. this.G = 1;
  2547. }
  2548. }
  2549. #toRgb(src, srcOffset, dest, destOffset, scale) {
  2550. const A = src[srcOffset] * scale;
  2551. const AG = A ** this.G;
  2552. const L = this.YW * AG;
  2553. const val = Math.max(295.8 * L ** 0.3333333333333333 - 40.8, 0);
  2554. dest[destOffset] = val;
  2555. dest[destOffset + 1] = val;
  2556. dest[destOffset + 2] = val;
  2557. }
  2558. getRgbItem(src, srcOffset, dest, destOffset) {
  2559. this.#toRgb(src, srcOffset, dest, destOffset, 1);
  2560. }
  2561. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2562. const scale = 1 / ((1 << bits) - 1);
  2563. for (let i = 0; i < count; ++i) {
  2564. this.#toRgb(src, srcOffset, dest, destOffset, scale);
  2565. srcOffset += 1;
  2566. destOffset += 3 + alpha01;
  2567. }
  2568. }
  2569. getOutputLength(inputLength, alpha01) {
  2570. return inputLength * (3 + alpha01);
  2571. }
  2572. }
  2573. class CalRGBCS extends ColorSpace {
  2574. static #BRADFORD_SCALE_MATRIX = new Float32Array([0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296]);
  2575. static #BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([0.9869929, -0.1470543, 0.1599627, 0.4323053, 0.5183603, 0.0492912, -0.0085287, 0.0400428, 0.9684867]);
  2576. static #SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([3.2404542, -1.5371385, -0.4985314, -0.9692660, 1.8760108, 0.0415560, 0.0556434, -0.2040259, 1.0572252]);
  2577. static #FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  2578. static #tempNormalizeMatrix = new Float32Array(3);
  2579. static #tempConvertMatrix1 = new Float32Array(3);
  2580. static #tempConvertMatrix2 = new Float32Array(3);
  2581. static #DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0;
  2582. constructor(whitePoint, blackPoint, gamma, matrix) {
  2583. super("CalRGB", 3);
  2584. if (!whitePoint) {
  2585. throw new FormatError("WhitePoint missing - required for color space CalRGB");
  2586. }
  2587. const [XW, YW, ZW] = this.whitePoint = whitePoint;
  2588. const [XB, YB, ZB] = this.blackPoint = blackPoint || new Float32Array(3);
  2589. [this.GR, this.GG, this.GB] = gamma || new Float32Array([1, 1, 1]);
  2590. [this.MXA, this.MYA, this.MZA, this.MXB, this.MYB, this.MZB, this.MXC, this.MYC, this.MZC] = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  2591. if (XW < 0 || ZW < 0 || YW !== 1) {
  2592. throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);
  2593. }
  2594. if (XB < 0 || YB < 0 || ZB < 0) {
  2595. info(`Invalid BlackPoint for ${this.name} [${XB}, ${YB}, ${ZB}], ` + "falling back to default.");
  2596. this.blackPoint = new Float32Array(3);
  2597. }
  2598. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  2599. info(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ` + `${this.name}, falling back to default.`);
  2600. this.GR = this.GG = this.GB = 1;
  2601. }
  2602. }
  2603. #matrixProduct(a, b, result) {
  2604. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  2605. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  2606. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  2607. }
  2608. #toFlat(sourceWhitePoint, LMS, result) {
  2609. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  2610. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  2611. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  2612. }
  2613. #toD65(sourceWhitePoint, LMS, result) {
  2614. const D65X = 0.95047;
  2615. const D65Y = 1;
  2616. const D65Z = 1.08883;
  2617. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  2618. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  2619. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  2620. }
  2621. #sRGBTransferFunction(color) {
  2622. if (color <= 0.0031308) {
  2623. return this.#adjustToRange(0, 1, 12.92 * color);
  2624. }
  2625. if (color >= 0.99554525) {
  2626. return 1;
  2627. }
  2628. return this.#adjustToRange(0, 1, (1 + 0.055) * color ** (1 / 2.4) - 0.055);
  2629. }
  2630. #adjustToRange(min, max, value) {
  2631. return Math.max(min, Math.min(max, value));
  2632. }
  2633. #decodeL(L) {
  2634. if (L < 0) {
  2635. return -this.#decodeL(-L);
  2636. }
  2637. if (L > 8.0) {
  2638. return ((L + 16) / 116) ** 3;
  2639. }
  2640. return L * CalRGBCS.#DECODE_L_CONSTANT;
  2641. }
  2642. #compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  2643. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  2644. result[0] = XYZ_Flat[0];
  2645. result[1] = XYZ_Flat[1];
  2646. result[2] = XYZ_Flat[2];
  2647. return;
  2648. }
  2649. const zeroDecodeL = this.#decodeL(0);
  2650. const X_DST = zeroDecodeL;
  2651. const X_SRC = this.#decodeL(sourceBlackPoint[0]);
  2652. const Y_DST = zeroDecodeL;
  2653. const Y_SRC = this.#decodeL(sourceBlackPoint[1]);
  2654. const Z_DST = zeroDecodeL;
  2655. const Z_SRC = this.#decodeL(sourceBlackPoint[2]);
  2656. const X_Scale = (1 - X_DST) / (1 - X_SRC);
  2657. const X_Offset = 1 - X_Scale;
  2658. const Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  2659. const Y_Offset = 1 - Y_Scale;
  2660. const Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  2661. const Z_Offset = 1 - Z_Scale;
  2662. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  2663. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  2664. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  2665. }
  2666. #normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  2667. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  2668. result[0] = XYZ_In[0];
  2669. result[1] = XYZ_In[1];
  2670. result[2] = XYZ_In[2];
  2671. return;
  2672. }
  2673. const LMS = result;
  2674. this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  2675. const LMS_Flat = CalRGBCS.#tempNormalizeMatrix;
  2676. this.#toFlat(sourceWhitePoint, LMS, LMS_Flat);
  2677. this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  2678. }
  2679. #normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  2680. const LMS = result;
  2681. this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  2682. const LMS_D65 = CalRGBCS.#tempNormalizeMatrix;
  2683. this.#toD65(sourceWhitePoint, LMS, LMS_D65);
  2684. this.#matrixProduct(CalRGBCS.#BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  2685. }
  2686. #toRgb(src, srcOffset, dest, destOffset, scale) {
  2687. const A = this.#adjustToRange(0, 1, src[srcOffset] * scale);
  2688. const B = this.#adjustToRange(0, 1, src[srcOffset + 1] * scale);
  2689. const C = this.#adjustToRange(0, 1, src[srcOffset + 2] * scale);
  2690. const AGR = A === 1 ? 1 : A ** this.GR;
  2691. const BGG = B === 1 ? 1 : B ** this.GG;
  2692. const CGB = C === 1 ? 1 : C ** this.GB;
  2693. const X = this.MXA * AGR + this.MXB * BGG + this.MXC * CGB;
  2694. const Y = this.MYA * AGR + this.MYB * BGG + this.MYC * CGB;
  2695. const Z = this.MZA * AGR + this.MZB * BGG + this.MZC * CGB;
  2696. const XYZ = CalRGBCS.#tempConvertMatrix1;
  2697. XYZ[0] = X;
  2698. XYZ[1] = Y;
  2699. XYZ[2] = Z;
  2700. const XYZ_Flat = CalRGBCS.#tempConvertMatrix2;
  2701. this.#normalizeWhitePointToFlat(this.whitePoint, XYZ, XYZ_Flat);
  2702. const XYZ_Black = CalRGBCS.#tempConvertMatrix1;
  2703. this.#compensateBlackPoint(this.blackPoint, XYZ_Flat, XYZ_Black);
  2704. const XYZ_D65 = CalRGBCS.#tempConvertMatrix2;
  2705. this.#normalizeWhitePointToD65(CalRGBCS.#FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  2706. const SRGB = CalRGBCS.#tempConvertMatrix1;
  2707. this.#matrixProduct(CalRGBCS.#SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  2708. dest[destOffset] = this.#sRGBTransferFunction(SRGB[0]) * 255;
  2709. dest[destOffset + 1] = this.#sRGBTransferFunction(SRGB[1]) * 255;
  2710. dest[destOffset + 2] = this.#sRGBTransferFunction(SRGB[2]) * 255;
  2711. }
  2712. getRgbItem(src, srcOffset, dest, destOffset) {
  2713. this.#toRgb(src, srcOffset, dest, destOffset, 1);
  2714. }
  2715. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2716. const scale = 1 / ((1 << bits) - 1);
  2717. for (let i = 0; i < count; ++i) {
  2718. this.#toRgb(src, srcOffset, dest, destOffset, scale);
  2719. srcOffset += 3;
  2720. destOffset += 3 + alpha01;
  2721. }
  2722. }
  2723. getOutputLength(inputLength, alpha01) {
  2724. return inputLength * (3 + alpha01) / 3 | 0;
  2725. }
  2726. }
  2727. class LabCS extends ColorSpace {
  2728. constructor(whitePoint, blackPoint, range) {
  2729. super("Lab", 3);
  2730. if (!whitePoint) {
  2731. throw new FormatError("WhitePoint missing - required for color space Lab");
  2732. }
  2733. [this.XW, this.YW, this.ZW] = whitePoint;
  2734. [this.amin, this.amax, this.bmin, this.bmax] = range || [-100, 100, -100, 100];
  2735. [this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
  2736. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  2737. throw new FormatError("Invalid WhitePoint components, no fallback available");
  2738. }
  2739. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  2740. info("Invalid BlackPoint, falling back to default");
  2741. this.XB = this.YB = this.ZB = 0;
  2742. }
  2743. if (this.amin > this.amax || this.bmin > this.bmax) {
  2744. info("Invalid Range, falling back to defaults");
  2745. this.amin = -100;
  2746. this.amax = 100;
  2747. this.bmin = -100;
  2748. this.bmax = 100;
  2749. }
  2750. }
  2751. #fn_g(x) {
  2752. return x >= 6 / 29 ? x ** 3 : 108 / 841 * (x - 4 / 29);
  2753. }
  2754. #decode(value, high1, low2, high2) {
  2755. return low2 + value * (high2 - low2) / high1;
  2756. }
  2757. #toRgb(src, srcOffset, maxVal, dest, destOffset) {
  2758. let Ls = src[srcOffset];
  2759. let as = src[srcOffset + 1];
  2760. let bs = src[srcOffset + 2];
  2761. if (maxVal !== false) {
  2762. Ls = this.#decode(Ls, maxVal, 0, 100);
  2763. as = this.#decode(as, maxVal, this.amin, this.amax);
  2764. bs = this.#decode(bs, maxVal, this.bmin, this.bmax);
  2765. }
  2766. if (as > this.amax) {
  2767. as = this.amax;
  2768. } else if (as < this.amin) {
  2769. as = this.amin;
  2770. }
  2771. if (bs > this.bmax) {
  2772. bs = this.bmax;
  2773. } else if (bs < this.bmin) {
  2774. bs = this.bmin;
  2775. }
  2776. const M = (Ls + 16) / 116;
  2777. const L = M + as / 500;
  2778. const N = M - bs / 200;
  2779. const X = this.XW * this.#fn_g(L);
  2780. const Y = this.YW * this.#fn_g(M);
  2781. const Z = this.ZW * this.#fn_g(N);
  2782. let r, g, b;
  2783. if (this.ZW < 1) {
  2784. r = X * 3.1339 + Y * -1.617 + Z * -0.4906;
  2785. g = X * -0.9785 + Y * 1.916 + Z * 0.0333;
  2786. b = X * 0.072 + Y * -0.229 + Z * 1.4057;
  2787. } else {
  2788. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  2789. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  2790. b = X * 0.0557 + Y * -0.204 + Z * 1.057;
  2791. }
  2792. dest[destOffset] = Math.sqrt(r) * 255;
  2793. dest[destOffset + 1] = Math.sqrt(g) * 255;
  2794. dest[destOffset + 2] = Math.sqrt(b) * 255;
  2795. }
  2796. getRgbItem(src, srcOffset, dest, destOffset) {
  2797. this.#toRgb(src, srcOffset, false, dest, destOffset);
  2798. }
  2799. getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  2800. const maxVal = (1 << bits) - 1;
  2801. for (let i = 0; i < count; i++) {
  2802. this.#toRgb(src, srcOffset, maxVal, dest, destOffset);
  2803. srcOffset += 3;
  2804. destOffset += 3 + alpha01;
  2805. }
  2806. }
  2807. getOutputLength(inputLength, alpha01) {
  2808. return inputLength * (3 + alpha01) / 3 | 0;
  2809. }
  2810. isDefaultDecode(decodeMap, bpc) {
  2811. return true;
  2812. }
  2813. get usesZeroToOneRange() {
  2814. return shadow(this, "usesZeroToOneRange", false);
  2815. }
  2816. }
  2817. ;// CONCATENATED MODULE: ./src/core/binary_cmap.js
  2818. function hexToInt(a, size) {
  2819. let n = 0;
  2820. for (let i = 0; i <= size; i++) {
  2821. n = n << 8 | a[i];
  2822. }
  2823. return n >>> 0;
  2824. }
  2825. function hexToStr(a, size) {
  2826. if (size === 1) {
  2827. return String.fromCharCode(a[0], a[1]);
  2828. }
  2829. if (size === 3) {
  2830. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  2831. }
  2832. return String.fromCharCode(...a.subarray(0, size + 1));
  2833. }
  2834. function addHex(a, b, size) {
  2835. let c = 0;
  2836. for (let i = size; i >= 0; i--) {
  2837. c += a[i] + b[i];
  2838. a[i] = c & 255;
  2839. c >>= 8;
  2840. }
  2841. }
  2842. function incHex(a, size) {
  2843. let c = 1;
  2844. for (let i = size; i >= 0 && c > 0; i--) {
  2845. c += a[i];
  2846. a[i] = c & 255;
  2847. c >>= 8;
  2848. }
  2849. }
  2850. const MAX_NUM_SIZE = 16;
  2851. const MAX_ENCODED_NUM_SIZE = 19;
  2852. class BinaryCMapStream {
  2853. constructor(data) {
  2854. this.buffer = data;
  2855. this.pos = 0;
  2856. this.end = data.length;
  2857. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  2858. }
  2859. readByte() {
  2860. if (this.pos >= this.end) {
  2861. return -1;
  2862. }
  2863. return this.buffer[this.pos++];
  2864. }
  2865. readNumber() {
  2866. let n = 0;
  2867. let last;
  2868. do {
  2869. const b = this.readByte();
  2870. if (b < 0) {
  2871. throw new FormatError("unexpected EOF in bcmap");
  2872. }
  2873. last = !(b & 0x80);
  2874. n = n << 7 | b & 0x7f;
  2875. } while (!last);
  2876. return n;
  2877. }
  2878. readSigned() {
  2879. const n = this.readNumber();
  2880. return n & 1 ? ~(n >>> 1) : n >>> 1;
  2881. }
  2882. readHex(num, size) {
  2883. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  2884. this.pos += size + 1;
  2885. }
  2886. readHexNumber(num, size) {
  2887. let last;
  2888. const stack = this.tmpBuf;
  2889. let sp = 0;
  2890. do {
  2891. const b = this.readByte();
  2892. if (b < 0) {
  2893. throw new FormatError("unexpected EOF in bcmap");
  2894. }
  2895. last = !(b & 0x80);
  2896. stack[sp++] = b & 0x7f;
  2897. } while (!last);
  2898. let i = size,
  2899. buffer = 0,
  2900. bufferSize = 0;
  2901. while (i >= 0) {
  2902. while (bufferSize < 8 && stack.length > 0) {
  2903. buffer |= stack[--sp] << bufferSize;
  2904. bufferSize += 7;
  2905. }
  2906. num[i] = buffer & 255;
  2907. i--;
  2908. buffer >>= 8;
  2909. bufferSize -= 8;
  2910. }
  2911. }
  2912. readHexSigned(num, size) {
  2913. this.readHexNumber(num, size);
  2914. const sign = num[size] & 1 ? 255 : 0;
  2915. let c = 0;
  2916. for (let i = 0; i <= size; i++) {
  2917. c = (c & 1) << 8 | num[i];
  2918. num[i] = c >> 1 ^ sign;
  2919. }
  2920. }
  2921. readString() {
  2922. const len = this.readNumber(),
  2923. buf = new Array(len);
  2924. for (let i = 0; i < len; i++) {
  2925. buf[i] = this.readNumber();
  2926. }
  2927. return String.fromCharCode(...buf);
  2928. }
  2929. }
  2930. class BinaryCMapReader {
  2931. async process(data, cMap, extend) {
  2932. const stream = new BinaryCMapStream(data);
  2933. const header = stream.readByte();
  2934. cMap.vertical = !!(header & 1);
  2935. let useCMap = null;
  2936. const start = new Uint8Array(MAX_NUM_SIZE);
  2937. const end = new Uint8Array(MAX_NUM_SIZE);
  2938. const char = new Uint8Array(MAX_NUM_SIZE);
  2939. const charCode = new Uint8Array(MAX_NUM_SIZE);
  2940. const tmp = new Uint8Array(MAX_NUM_SIZE);
  2941. let code;
  2942. let b;
  2943. while ((b = stream.readByte()) >= 0) {
  2944. const type = b >> 5;
  2945. if (type === 7) {
  2946. switch (b & 0x1f) {
  2947. case 0:
  2948. stream.readString();
  2949. break;
  2950. case 1:
  2951. useCMap = stream.readString();
  2952. break;
  2953. }
  2954. continue;
  2955. }
  2956. const sequence = !!(b & 0x10);
  2957. const dataSize = b & 15;
  2958. if (dataSize + 1 > MAX_NUM_SIZE) {
  2959. throw new Error("BinaryCMapReader.process: Invalid dataSize.");
  2960. }
  2961. const ucs2DataSize = 1;
  2962. const subitemsCount = stream.readNumber();
  2963. switch (type) {
  2964. case 0:
  2965. stream.readHex(start, dataSize);
  2966. stream.readHexNumber(end, dataSize);
  2967. addHex(end, start, dataSize);
  2968. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  2969. for (let i = 1; i < subitemsCount; i++) {
  2970. incHex(end, dataSize);
  2971. stream.readHexNumber(start, dataSize);
  2972. addHex(start, end, dataSize);
  2973. stream.readHexNumber(end, dataSize);
  2974. addHex(end, start, dataSize);
  2975. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  2976. }
  2977. break;
  2978. case 1:
  2979. stream.readHex(start, dataSize);
  2980. stream.readHexNumber(end, dataSize);
  2981. addHex(end, start, dataSize);
  2982. stream.readNumber();
  2983. for (let i = 1; i < subitemsCount; i++) {
  2984. incHex(end, dataSize);
  2985. stream.readHexNumber(start, dataSize);
  2986. addHex(start, end, dataSize);
  2987. stream.readHexNumber(end, dataSize);
  2988. addHex(end, start, dataSize);
  2989. stream.readNumber();
  2990. }
  2991. break;
  2992. case 2:
  2993. stream.readHex(char, dataSize);
  2994. code = stream.readNumber();
  2995. cMap.mapOne(hexToInt(char, dataSize), code);
  2996. for (let i = 1; i < subitemsCount; i++) {
  2997. incHex(char, dataSize);
  2998. if (!sequence) {
  2999. stream.readHexNumber(tmp, dataSize);
  3000. addHex(char, tmp, dataSize);
  3001. }
  3002. code = stream.readSigned() + (code + 1);
  3003. cMap.mapOne(hexToInt(char, dataSize), code);
  3004. }
  3005. break;
  3006. case 3:
  3007. stream.readHex(start, dataSize);
  3008. stream.readHexNumber(end, dataSize);
  3009. addHex(end, start, dataSize);
  3010. code = stream.readNumber();
  3011. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  3012. for (let i = 1; i < subitemsCount; i++) {
  3013. incHex(end, dataSize);
  3014. if (!sequence) {
  3015. stream.readHexNumber(start, dataSize);
  3016. addHex(start, end, dataSize);
  3017. } else {
  3018. start.set(end);
  3019. }
  3020. stream.readHexNumber(end, dataSize);
  3021. addHex(end, start, dataSize);
  3022. code = stream.readNumber();
  3023. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  3024. }
  3025. break;
  3026. case 4:
  3027. stream.readHex(char, ucs2DataSize);
  3028. stream.readHex(charCode, dataSize);
  3029. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  3030. for (let i = 1; i < subitemsCount; i++) {
  3031. incHex(char, ucs2DataSize);
  3032. if (!sequence) {
  3033. stream.readHexNumber(tmp, ucs2DataSize);
  3034. addHex(char, tmp, ucs2DataSize);
  3035. }
  3036. incHex(charCode, dataSize);
  3037. stream.readHexSigned(tmp, dataSize);
  3038. addHex(charCode, tmp, dataSize);
  3039. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  3040. }
  3041. break;
  3042. case 5:
  3043. stream.readHex(start, ucs2DataSize);
  3044. stream.readHexNumber(end, ucs2DataSize);
  3045. addHex(end, start, ucs2DataSize);
  3046. stream.readHex(charCode, dataSize);
  3047. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  3048. for (let i = 1; i < subitemsCount; i++) {
  3049. incHex(end, ucs2DataSize);
  3050. if (!sequence) {
  3051. stream.readHexNumber(start, ucs2DataSize);
  3052. addHex(start, end, ucs2DataSize);
  3053. } else {
  3054. start.set(end);
  3055. }
  3056. stream.readHexNumber(end, ucs2DataSize);
  3057. addHex(end, start, ucs2DataSize);
  3058. stream.readHex(charCode, dataSize);
  3059. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  3060. }
  3061. break;
  3062. default:
  3063. throw new Error(`BinaryCMapReader.process - unknown type: ${type}`);
  3064. }
  3065. }
  3066. if (useCMap) {
  3067. return extend(useCMap);
  3068. }
  3069. return cMap;
  3070. }
  3071. }
  3072. ;// CONCATENATED MODULE: ./src/core/decode_stream.js
  3073. const emptyBuffer = new Uint8Array(0);
  3074. class DecodeStream extends BaseStream {
  3075. constructor(maybeMinBufferLength) {
  3076. super();
  3077. this._rawMinBufferLength = maybeMinBufferLength || 0;
  3078. this.pos = 0;
  3079. this.bufferLength = 0;
  3080. this.eof = false;
  3081. this.buffer = emptyBuffer;
  3082. this.minBufferLength = 512;
  3083. if (maybeMinBufferLength) {
  3084. while (this.minBufferLength < maybeMinBufferLength) {
  3085. this.minBufferLength *= 2;
  3086. }
  3087. }
  3088. }
  3089. get isEmpty() {
  3090. while (!this.eof && this.bufferLength === 0) {
  3091. this.readBlock();
  3092. }
  3093. return this.bufferLength === 0;
  3094. }
  3095. ensureBuffer(requested) {
  3096. const buffer = this.buffer;
  3097. if (requested <= buffer.byteLength) {
  3098. return buffer;
  3099. }
  3100. let size = this.minBufferLength;
  3101. while (size < requested) {
  3102. size *= 2;
  3103. }
  3104. const buffer2 = new Uint8Array(size);
  3105. buffer2.set(buffer);
  3106. return this.buffer = buffer2;
  3107. }
  3108. getByte() {
  3109. const pos = this.pos;
  3110. while (this.bufferLength <= pos) {
  3111. if (this.eof) {
  3112. return -1;
  3113. }
  3114. this.readBlock();
  3115. }
  3116. return this.buffer[this.pos++];
  3117. }
  3118. getBytes(length) {
  3119. const pos = this.pos;
  3120. let end;
  3121. if (length) {
  3122. this.ensureBuffer(pos + length);
  3123. end = pos + length;
  3124. while (!this.eof && this.bufferLength < end) {
  3125. this.readBlock();
  3126. }
  3127. const bufEnd = this.bufferLength;
  3128. if (end > bufEnd) {
  3129. end = bufEnd;
  3130. }
  3131. } else {
  3132. while (!this.eof) {
  3133. this.readBlock();
  3134. }
  3135. end = this.bufferLength;
  3136. }
  3137. this.pos = end;
  3138. return this.buffer.subarray(pos, end);
  3139. }
  3140. reset() {
  3141. this.pos = 0;
  3142. }
  3143. makeSubStream(start, length, dict = null) {
  3144. if (length === undefined) {
  3145. while (!this.eof) {
  3146. this.readBlock();
  3147. }
  3148. } else {
  3149. const end = start + length;
  3150. while (this.bufferLength <= end && !this.eof) {
  3151. this.readBlock();
  3152. }
  3153. }
  3154. return new Stream(this.buffer, start, length, dict);
  3155. }
  3156. getBaseStreams() {
  3157. return this.str ? this.str.getBaseStreams() : null;
  3158. }
  3159. }
  3160. class StreamsSequenceStream extends DecodeStream {
  3161. constructor(streams, onError = null) {
  3162. let maybeLength = 0;
  3163. for (const stream of streams) {
  3164. maybeLength += stream instanceof DecodeStream ? stream._rawMinBufferLength : stream.length;
  3165. }
  3166. super(maybeLength);
  3167. this.streams = streams;
  3168. this._onError = onError;
  3169. }
  3170. readBlock() {
  3171. const streams = this.streams;
  3172. if (streams.length === 0) {
  3173. this.eof = true;
  3174. return;
  3175. }
  3176. const stream = streams.shift();
  3177. let chunk;
  3178. try {
  3179. chunk = stream.getBytes();
  3180. } catch (reason) {
  3181. if (this._onError) {
  3182. this._onError(reason, stream.dict?.objId);
  3183. return;
  3184. }
  3185. throw reason;
  3186. }
  3187. const bufferLength = this.bufferLength;
  3188. const newLength = bufferLength + chunk.length;
  3189. const buffer = this.ensureBuffer(newLength);
  3190. buffer.set(chunk, bufferLength);
  3191. this.bufferLength = newLength;
  3192. }
  3193. getBaseStreams() {
  3194. const baseStreamsBuf = [];
  3195. for (const stream of this.streams) {
  3196. const baseStreams = stream.getBaseStreams();
  3197. if (baseStreams) {
  3198. baseStreamsBuf.push(...baseStreams);
  3199. }
  3200. }
  3201. return baseStreamsBuf.length > 0 ? baseStreamsBuf : null;
  3202. }
  3203. }
  3204. ;// CONCATENATED MODULE: ./src/core/ascii_85_stream.js
  3205. class Ascii85Stream extends DecodeStream {
  3206. constructor(str, maybeLength) {
  3207. if (maybeLength) {
  3208. maybeLength *= 0.8;
  3209. }
  3210. super(maybeLength);
  3211. this.str = str;
  3212. this.dict = str.dict;
  3213. this.input = new Uint8Array(5);
  3214. }
  3215. readBlock() {
  3216. const TILDA_CHAR = 0x7e;
  3217. const Z_LOWER_CHAR = 0x7a;
  3218. const EOF = -1;
  3219. const str = this.str;
  3220. let c = str.getByte();
  3221. while (isWhiteSpace(c)) {
  3222. c = str.getByte();
  3223. }
  3224. if (c === EOF || c === TILDA_CHAR) {
  3225. this.eof = true;
  3226. return;
  3227. }
  3228. const bufferLength = this.bufferLength;
  3229. let buffer, i;
  3230. if (c === Z_LOWER_CHAR) {
  3231. buffer = this.ensureBuffer(bufferLength + 4);
  3232. for (i = 0; i < 4; ++i) {
  3233. buffer[bufferLength + i] = 0;
  3234. }
  3235. this.bufferLength += 4;
  3236. } else {
  3237. const input = this.input;
  3238. input[0] = c;
  3239. for (i = 1; i < 5; ++i) {
  3240. c = str.getByte();
  3241. while (isWhiteSpace(c)) {
  3242. c = str.getByte();
  3243. }
  3244. input[i] = c;
  3245. if (c === EOF || c === TILDA_CHAR) {
  3246. break;
  3247. }
  3248. }
  3249. buffer = this.ensureBuffer(bufferLength + i - 1);
  3250. this.bufferLength += i - 1;
  3251. if (i < 5) {
  3252. for (; i < 5; ++i) {
  3253. input[i] = 0x21 + 84;
  3254. }
  3255. this.eof = true;
  3256. }
  3257. let t = 0;
  3258. for (i = 0; i < 5; ++i) {
  3259. t = t * 85 + (input[i] - 0x21);
  3260. }
  3261. for (i = 3; i >= 0; --i) {
  3262. buffer[bufferLength + i] = t & 0xff;
  3263. t >>= 8;
  3264. }
  3265. }
  3266. }
  3267. }
  3268. ;// CONCATENATED MODULE: ./src/core/ascii_hex_stream.js
  3269. class AsciiHexStream extends DecodeStream {
  3270. constructor(str, maybeLength) {
  3271. if (maybeLength) {
  3272. maybeLength *= 0.5;
  3273. }
  3274. super(maybeLength);
  3275. this.str = str;
  3276. this.dict = str.dict;
  3277. this.firstDigit = -1;
  3278. }
  3279. readBlock() {
  3280. const UPSTREAM_BLOCK_SIZE = 8000;
  3281. const bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  3282. if (!bytes.length) {
  3283. this.eof = true;
  3284. return;
  3285. }
  3286. const maxDecodeLength = bytes.length + 1 >> 1;
  3287. const buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  3288. let bufferLength = this.bufferLength;
  3289. let firstDigit = this.firstDigit;
  3290. for (const ch of bytes) {
  3291. let digit;
  3292. if (ch >= 0x30 && ch <= 0x39) {
  3293. digit = ch & 0x0f;
  3294. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  3295. digit = (ch & 0x0f) + 9;
  3296. } else if (ch === 0x3e) {
  3297. this.eof = true;
  3298. break;
  3299. } else {
  3300. continue;
  3301. }
  3302. if (firstDigit < 0) {
  3303. firstDigit = digit;
  3304. } else {
  3305. buffer[bufferLength++] = firstDigit << 4 | digit;
  3306. firstDigit = -1;
  3307. }
  3308. }
  3309. if (firstDigit >= 0 && this.eof) {
  3310. buffer[bufferLength++] = firstDigit << 4;
  3311. firstDigit = -1;
  3312. }
  3313. this.firstDigit = firstDigit;
  3314. this.bufferLength = bufferLength;
  3315. }
  3316. }
  3317. ;// CONCATENATED MODULE: ./src/core/ccitt.js
  3318. const ccittEOL = -2;
  3319. const ccittEOF = -1;
  3320. const twoDimPass = 0;
  3321. const twoDimHoriz = 1;
  3322. const twoDimVert0 = 2;
  3323. const twoDimVertR1 = 3;
  3324. const twoDimVertL1 = 4;
  3325. const twoDimVertR2 = 5;
  3326. const twoDimVertL2 = 6;
  3327. const twoDimVertR3 = 7;
  3328. const twoDimVertL3 = 8;
  3329. const twoDimTable = [[-1, -1], [-1, -1], [7, twoDimVertL3], [7, twoDimVertR3], [6, twoDimVertL2], [6, twoDimVertL2], [6, twoDimVertR2], [6, twoDimVertR2], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [4, twoDimPass], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimHoriz], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertL1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [3, twoDimVertR1], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0], [1, twoDimVert0]];
  3330. const whiteTable1 = [[-1, -1], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [12, 1984], [12, 2048], [12, 2112], [12, 2176], [12, 2240], [12, 2304], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [12, 2368], [12, 2432], [12, 2496], [12, 2560]];
  3331. const whiteTable2 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [8, 29], [8, 29], [8, 30], [8, 30], [8, 45], [8, 45], [8, 46], [8, 46], [7, 22], [7, 22], [7, 22], [7, 22], [7, 23], [7, 23], [7, 23], [7, 23], [8, 47], [8, 47], [8, 48], [8, 48], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [6, 13], [7, 20], [7, 20], [7, 20], [7, 20], [8, 33], [8, 33], [8, 34], [8, 34], [8, 35], [8, 35], [8, 36], [8, 36], [8, 37], [8, 37], [8, 38], [8, 38], [7, 19], [7, 19], [7, 19], [7, 19], [8, 31], [8, 31], [8, 32], [8, 32], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 1], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [6, 12], [8, 53], [8, 53], [8, 54], [8, 54], [7, 26], [7, 26], [7, 26], [7, 26], [8, 39], [8, 39], [8, 40], [8, 40], [8, 41], [8, 41], [8, 42], [8, 42], [8, 43], [8, 43], [8, 44], [8, 44], [7, 21], [7, 21], [7, 21], [7, 21], [7, 28], [7, 28], [7, 28], [7, 28], [8, 61], [8, 61], [8, 62], [8, 62], [8, 63], [8, 63], [8, 0], [8, 0], [8, 320], [8, 320], [8, 384], [8, 384], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 10], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [5, 11], [7, 27], [7, 27], [7, 27], [7, 27], [8, 59], [8, 59], [8, 60], [8, 60], [9, 1472], [9, 1536], [9, 1600], [9, 1728], [7, 18], [7, 18], [7, 18], [7, 18], [7, 24], [7, 24], [7, 24], [7, 24], [8, 49], [8, 49], [8, 50], [8, 50], [8, 51], [8, 51], [8, 52], [8, 52], [7, 25], [7, 25], [7, 25], [7, 25], [8, 55], [8, 55], [8, 56], [8, 56], [8, 57], [8, 57], [8, 58], [8, 58], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 192], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [6, 1664], [8, 448], [8, 448], [8, 512], [8, 512], [9, 704], [9, 768], [8, 640], [8, 640], [8, 576], [8, 576], [9, 832], [9, 896], [9, 960], [9, 1024], [9, 1088], [9, 1152], [9, 1216], [9, 1280], [9, 1344], [9, 1408], [7, 256], [7, 256], [7, 256], [7, 256], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [4, 3], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 128], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 8], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [5, 9], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 16], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [6, 17], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 4], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [4, 5], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 14], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [6, 15], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [5, 64], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 6], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7], [4, 7]];
  3332. const blackTable1 = [[-1, -1], [-1, -1], [12, ccittEOL], [12, ccittEOL], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [-1, -1], [11, 1792], [11, 1792], [11, 1792], [11, 1792], [12, 1984], [12, 1984], [12, 2048], [12, 2048], [12, 2112], [12, 2112], [12, 2176], [12, 2176], [12, 2240], [12, 2240], [12, 2304], [12, 2304], [11, 1856], [11, 1856], [11, 1856], [11, 1856], [11, 1920], [11, 1920], [11, 1920], [11, 1920], [12, 2368], [12, 2368], [12, 2432], [12, 2432], [12, 2496], [12, 2496], [12, 2560], [12, 2560], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [10, 18], [12, 52], [12, 52], [13, 640], [13, 704], [13, 768], [13, 832], [12, 55], [12, 55], [12, 56], [12, 56], [13, 1280], [13, 1344], [13, 1408], [13, 1472], [12, 59], [12, 59], [12, 60], [12, 60], [13, 1536], [13, 1600], [11, 24], [11, 24], [11, 24], [11, 24], [11, 25], [11, 25], [11, 25], [11, 25], [13, 1664], [13, 1728], [12, 320], [12, 320], [12, 384], [12, 384], [12, 448], [12, 448], [13, 512], [13, 576], [12, 53], [12, 53], [12, 54], [12, 54], [13, 896], [13, 960], [13, 1024], [13, 1088], [13, 1152], [13, 1216], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64], [10, 64]];
  3333. const blackTable2 = [[8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [8, 13], [11, 23], [11, 23], [12, 50], [12, 51], [12, 44], [12, 45], [12, 46], [12, 47], [12, 57], [12, 58], [12, 61], [12, 256], [10, 16], [10, 16], [10, 16], [10, 16], [10, 17], [10, 17], [10, 17], [10, 17], [12, 48], [12, 49], [12, 62], [12, 63], [12, 30], [12, 31], [12, 32], [12, 33], [12, 40], [12, 41], [11, 22], [11, 22], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [8, 14], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 10], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [7, 11], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [9, 15], [12, 128], [12, 192], [12, 26], [12, 27], [12, 28], [12, 29], [11, 19], [11, 19], [11, 20], [11, 20], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [11, 21], [11, 21], [12, 42], [12, 43], [10, 0], [10, 0], [10, 0], [10, 0], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12], [7, 12]];
  3334. const blackTable3 = [[-1, -1], [-1, -1], [-1, -1], [-1, -1], [6, 9], [6, 8], [5, 7], [5, 7], [4, 6], [4, 6], [4, 6], [4, 6], [4, 5], [4, 5], [4, 5], [4, 5], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 1], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [3, 4], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]];
  3335. class CCITTFaxDecoder {
  3336. constructor(source, options = {}) {
  3337. if (!source || typeof source.next !== "function") {
  3338. throw new Error('CCITTFaxDecoder - invalid "source" parameter.');
  3339. }
  3340. this.source = source;
  3341. this.eof = false;
  3342. this.encoding = options.K || 0;
  3343. this.eoline = options.EndOfLine || false;
  3344. this.byteAlign = options.EncodedByteAlign || false;
  3345. this.columns = options.Columns || 1728;
  3346. this.rows = options.Rows || 0;
  3347. this.eoblock = options.EndOfBlock ?? true;
  3348. this.black = options.BlackIs1 || false;
  3349. this.codingLine = new Uint32Array(this.columns + 1);
  3350. this.refLine = new Uint32Array(this.columns + 2);
  3351. this.codingLine[0] = this.columns;
  3352. this.codingPos = 0;
  3353. this.row = 0;
  3354. this.nextLine2D = this.encoding < 0;
  3355. this.inputBits = 0;
  3356. this.inputBuf = 0;
  3357. this.outputBits = 0;
  3358. this.rowsDone = false;
  3359. let code1;
  3360. while ((code1 = this._lookBits(12)) === 0) {
  3361. this._eatBits(1);
  3362. }
  3363. if (code1 === 1) {
  3364. this._eatBits(12);
  3365. }
  3366. if (this.encoding > 0) {
  3367. this.nextLine2D = !this._lookBits(1);
  3368. this._eatBits(1);
  3369. }
  3370. }
  3371. readNextChar() {
  3372. if (this.eof) {
  3373. return -1;
  3374. }
  3375. const refLine = this.refLine;
  3376. const codingLine = this.codingLine;
  3377. const columns = this.columns;
  3378. let refPos, blackPixels, bits, i;
  3379. if (this.outputBits === 0) {
  3380. if (this.rowsDone) {
  3381. this.eof = true;
  3382. }
  3383. if (this.eof) {
  3384. return -1;
  3385. }
  3386. this.err = false;
  3387. let code1, code2, code3;
  3388. if (this.nextLine2D) {
  3389. for (i = 0; codingLine[i] < columns; ++i) {
  3390. refLine[i] = codingLine[i];
  3391. }
  3392. refLine[i++] = columns;
  3393. refLine[i] = columns;
  3394. codingLine[0] = 0;
  3395. this.codingPos = 0;
  3396. refPos = 0;
  3397. blackPixels = 0;
  3398. while (codingLine[this.codingPos] < columns) {
  3399. code1 = this._getTwoDimCode();
  3400. switch (code1) {
  3401. case twoDimPass:
  3402. this._addPixels(refLine[refPos + 1], blackPixels);
  3403. if (refLine[refPos + 1] < columns) {
  3404. refPos += 2;
  3405. }
  3406. break;
  3407. case twoDimHoriz:
  3408. code1 = code2 = 0;
  3409. if (blackPixels) {
  3410. do {
  3411. code1 += code3 = this._getBlackCode();
  3412. } while (code3 >= 64);
  3413. do {
  3414. code2 += code3 = this._getWhiteCode();
  3415. } while (code3 >= 64);
  3416. } else {
  3417. do {
  3418. code1 += code3 = this._getWhiteCode();
  3419. } while (code3 >= 64);
  3420. do {
  3421. code2 += code3 = this._getBlackCode();
  3422. } while (code3 >= 64);
  3423. }
  3424. this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
  3425. if (codingLine[this.codingPos] < columns) {
  3426. this._addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  3427. }
  3428. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3429. refPos += 2;
  3430. }
  3431. break;
  3432. case twoDimVertR3:
  3433. this._addPixels(refLine[refPos] + 3, blackPixels);
  3434. blackPixels ^= 1;
  3435. if (codingLine[this.codingPos] < columns) {
  3436. ++refPos;
  3437. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3438. refPos += 2;
  3439. }
  3440. }
  3441. break;
  3442. case twoDimVertR2:
  3443. this._addPixels(refLine[refPos] + 2, blackPixels);
  3444. blackPixels ^= 1;
  3445. if (codingLine[this.codingPos] < columns) {
  3446. ++refPos;
  3447. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3448. refPos += 2;
  3449. }
  3450. }
  3451. break;
  3452. case twoDimVertR1:
  3453. this._addPixels(refLine[refPos] + 1, blackPixels);
  3454. blackPixels ^= 1;
  3455. if (codingLine[this.codingPos] < columns) {
  3456. ++refPos;
  3457. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3458. refPos += 2;
  3459. }
  3460. }
  3461. break;
  3462. case twoDimVert0:
  3463. this._addPixels(refLine[refPos], blackPixels);
  3464. blackPixels ^= 1;
  3465. if (codingLine[this.codingPos] < columns) {
  3466. ++refPos;
  3467. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3468. refPos += 2;
  3469. }
  3470. }
  3471. break;
  3472. case twoDimVertL3:
  3473. this._addPixelsNeg(refLine[refPos] - 3, blackPixels);
  3474. blackPixels ^= 1;
  3475. if (codingLine[this.codingPos] < columns) {
  3476. if (refPos > 0) {
  3477. --refPos;
  3478. } else {
  3479. ++refPos;
  3480. }
  3481. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3482. refPos += 2;
  3483. }
  3484. }
  3485. break;
  3486. case twoDimVertL2:
  3487. this._addPixelsNeg(refLine[refPos] - 2, blackPixels);
  3488. blackPixels ^= 1;
  3489. if (codingLine[this.codingPos] < columns) {
  3490. if (refPos > 0) {
  3491. --refPos;
  3492. } else {
  3493. ++refPos;
  3494. }
  3495. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3496. refPos += 2;
  3497. }
  3498. }
  3499. break;
  3500. case twoDimVertL1:
  3501. this._addPixelsNeg(refLine[refPos] - 1, blackPixels);
  3502. blackPixels ^= 1;
  3503. if (codingLine[this.codingPos] < columns) {
  3504. if (refPos > 0) {
  3505. --refPos;
  3506. } else {
  3507. ++refPos;
  3508. }
  3509. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  3510. refPos += 2;
  3511. }
  3512. }
  3513. break;
  3514. case ccittEOF:
  3515. this._addPixels(columns, 0);
  3516. this.eof = true;
  3517. break;
  3518. default:
  3519. info("bad 2d code");
  3520. this._addPixels(columns, 0);
  3521. this.err = true;
  3522. }
  3523. }
  3524. } else {
  3525. codingLine[0] = 0;
  3526. this.codingPos = 0;
  3527. blackPixels = 0;
  3528. while (codingLine[this.codingPos] < columns) {
  3529. code1 = 0;
  3530. if (blackPixels) {
  3531. do {
  3532. code1 += code3 = this._getBlackCode();
  3533. } while (code3 >= 64);
  3534. } else {
  3535. do {
  3536. code1 += code3 = this._getWhiteCode();
  3537. } while (code3 >= 64);
  3538. }
  3539. this._addPixels(codingLine[this.codingPos] + code1, blackPixels);
  3540. blackPixels ^= 1;
  3541. }
  3542. }
  3543. let gotEOL = false;
  3544. if (this.byteAlign) {
  3545. this.inputBits &= ~7;
  3546. }
  3547. if (!this.eoblock && this.row === this.rows - 1) {
  3548. this.rowsDone = true;
  3549. } else {
  3550. code1 = this._lookBits(12);
  3551. if (this.eoline) {
  3552. while (code1 !== ccittEOF && code1 !== 1) {
  3553. this._eatBits(1);
  3554. code1 = this._lookBits(12);
  3555. }
  3556. } else {
  3557. while (code1 === 0) {
  3558. this._eatBits(1);
  3559. code1 = this._lookBits(12);
  3560. }
  3561. }
  3562. if (code1 === 1) {
  3563. this._eatBits(12);
  3564. gotEOL = true;
  3565. } else if (code1 === ccittEOF) {
  3566. this.eof = true;
  3567. }
  3568. }
  3569. if (!this.eof && this.encoding > 0 && !this.rowsDone) {
  3570. this.nextLine2D = !this._lookBits(1);
  3571. this._eatBits(1);
  3572. }
  3573. if (this.eoblock && gotEOL && this.byteAlign) {
  3574. code1 = this._lookBits(12);
  3575. if (code1 === 1) {
  3576. this._eatBits(12);
  3577. if (this.encoding > 0) {
  3578. this._lookBits(1);
  3579. this._eatBits(1);
  3580. }
  3581. if (this.encoding >= 0) {
  3582. for (i = 0; i < 4; ++i) {
  3583. code1 = this._lookBits(12);
  3584. if (code1 !== 1) {
  3585. info("bad rtc code: " + code1);
  3586. }
  3587. this._eatBits(12);
  3588. if (this.encoding > 0) {
  3589. this._lookBits(1);
  3590. this._eatBits(1);
  3591. }
  3592. }
  3593. }
  3594. this.eof = true;
  3595. }
  3596. } else if (this.err && this.eoline) {
  3597. while (true) {
  3598. code1 = this._lookBits(13);
  3599. if (code1 === ccittEOF) {
  3600. this.eof = true;
  3601. return -1;
  3602. }
  3603. if (code1 >> 1 === 1) {
  3604. break;
  3605. }
  3606. this._eatBits(1);
  3607. }
  3608. this._eatBits(12);
  3609. if (this.encoding > 0) {
  3610. this._eatBits(1);
  3611. this.nextLine2D = !(code1 & 1);
  3612. }
  3613. }
  3614. this.outputBits = codingLine[0] > 0 ? codingLine[this.codingPos = 0] : codingLine[this.codingPos = 1];
  3615. this.row++;
  3616. }
  3617. let c;
  3618. if (this.outputBits >= 8) {
  3619. c = this.codingPos & 1 ? 0 : 0xff;
  3620. this.outputBits -= 8;
  3621. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  3622. this.codingPos++;
  3623. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  3624. }
  3625. } else {
  3626. bits = 8;
  3627. c = 0;
  3628. do {
  3629. if (typeof this.outputBits !== "number") {
  3630. throw new FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.');
  3631. }
  3632. if (this.outputBits > bits) {
  3633. c <<= bits;
  3634. if (!(this.codingPos & 1)) {
  3635. c |= 0xff >> 8 - bits;
  3636. }
  3637. this.outputBits -= bits;
  3638. bits = 0;
  3639. } else {
  3640. c <<= this.outputBits;
  3641. if (!(this.codingPos & 1)) {
  3642. c |= 0xff >> 8 - this.outputBits;
  3643. }
  3644. bits -= this.outputBits;
  3645. this.outputBits = 0;
  3646. if (codingLine[this.codingPos] < columns) {
  3647. this.codingPos++;
  3648. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  3649. } else if (bits > 0) {
  3650. c <<= bits;
  3651. bits = 0;
  3652. }
  3653. }
  3654. } while (bits);
  3655. }
  3656. if (this.black) {
  3657. c ^= 0xff;
  3658. }
  3659. return c;
  3660. }
  3661. _addPixels(a1, blackPixels) {
  3662. const codingLine = this.codingLine;
  3663. let codingPos = this.codingPos;
  3664. if (a1 > codingLine[codingPos]) {
  3665. if (a1 > this.columns) {
  3666. info("row is wrong length");
  3667. this.err = true;
  3668. a1 = this.columns;
  3669. }
  3670. if (codingPos & 1 ^ blackPixels) {
  3671. ++codingPos;
  3672. }
  3673. codingLine[codingPos] = a1;
  3674. }
  3675. this.codingPos = codingPos;
  3676. }
  3677. _addPixelsNeg(a1, blackPixels) {
  3678. const codingLine = this.codingLine;
  3679. let codingPos = this.codingPos;
  3680. if (a1 > codingLine[codingPos]) {
  3681. if (a1 > this.columns) {
  3682. info("row is wrong length");
  3683. this.err = true;
  3684. a1 = this.columns;
  3685. }
  3686. if (codingPos & 1 ^ blackPixels) {
  3687. ++codingPos;
  3688. }
  3689. codingLine[codingPos] = a1;
  3690. } else if (a1 < codingLine[codingPos]) {
  3691. if (a1 < 0) {
  3692. info("invalid code");
  3693. this.err = true;
  3694. a1 = 0;
  3695. }
  3696. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  3697. --codingPos;
  3698. }
  3699. codingLine[codingPos] = a1;
  3700. }
  3701. this.codingPos = codingPos;
  3702. }
  3703. _findTableCode(start, end, table, limit) {
  3704. const limitValue = limit || 0;
  3705. for (let i = start; i <= end; ++i) {
  3706. let code = this._lookBits(i);
  3707. if (code === ccittEOF) {
  3708. return [true, 1, false];
  3709. }
  3710. if (i < end) {
  3711. code <<= end - i;
  3712. }
  3713. if (!limitValue || code >= limitValue) {
  3714. const p = table[code - limitValue];
  3715. if (p[0] === i) {
  3716. this._eatBits(i);
  3717. return [true, p[1], true];
  3718. }
  3719. }
  3720. }
  3721. return [false, 0, false];
  3722. }
  3723. _getTwoDimCode() {
  3724. let code = 0;
  3725. let p;
  3726. if (this.eoblock) {
  3727. code = this._lookBits(7);
  3728. p = twoDimTable[code];
  3729. if (p?.[0] > 0) {
  3730. this._eatBits(p[0]);
  3731. return p[1];
  3732. }
  3733. } else {
  3734. const result = this._findTableCode(1, 7, twoDimTable);
  3735. if (result[0] && result[2]) {
  3736. return result[1];
  3737. }
  3738. }
  3739. info("Bad two dim code");
  3740. return ccittEOF;
  3741. }
  3742. _getWhiteCode() {
  3743. let code = 0;
  3744. let p;
  3745. if (this.eoblock) {
  3746. code = this._lookBits(12);
  3747. if (code === ccittEOF) {
  3748. return 1;
  3749. }
  3750. p = code >> 5 === 0 ? whiteTable1[code] : whiteTable2[code >> 3];
  3751. if (p[0] > 0) {
  3752. this._eatBits(p[0]);
  3753. return p[1];
  3754. }
  3755. } else {
  3756. let result = this._findTableCode(1, 9, whiteTable2);
  3757. if (result[0]) {
  3758. return result[1];
  3759. }
  3760. result = this._findTableCode(11, 12, whiteTable1);
  3761. if (result[0]) {
  3762. return result[1];
  3763. }
  3764. }
  3765. info("bad white code");
  3766. this._eatBits(1);
  3767. return 1;
  3768. }
  3769. _getBlackCode() {
  3770. let code, p;
  3771. if (this.eoblock) {
  3772. code = this._lookBits(13);
  3773. if (code === ccittEOF) {
  3774. return 1;
  3775. }
  3776. if (code >> 7 === 0) {
  3777. p = blackTable1[code];
  3778. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  3779. p = blackTable2[(code >> 1) - 64];
  3780. } else {
  3781. p = blackTable3[code >> 7];
  3782. }
  3783. if (p[0] > 0) {
  3784. this._eatBits(p[0]);
  3785. return p[1];
  3786. }
  3787. } else {
  3788. let result = this._findTableCode(2, 6, blackTable3);
  3789. if (result[0]) {
  3790. return result[1];
  3791. }
  3792. result = this._findTableCode(7, 12, blackTable2, 64);
  3793. if (result[0]) {
  3794. return result[1];
  3795. }
  3796. result = this._findTableCode(10, 13, blackTable1);
  3797. if (result[0]) {
  3798. return result[1];
  3799. }
  3800. }
  3801. info("bad black code");
  3802. this._eatBits(1);
  3803. return 1;
  3804. }
  3805. _lookBits(n) {
  3806. let c;
  3807. while (this.inputBits < n) {
  3808. if ((c = this.source.next()) === -1) {
  3809. if (this.inputBits === 0) {
  3810. return ccittEOF;
  3811. }
  3812. return this.inputBuf << n - this.inputBits & 0xffff >> 16 - n;
  3813. }
  3814. this.inputBuf = this.inputBuf << 8 | c;
  3815. this.inputBits += 8;
  3816. }
  3817. return this.inputBuf >> this.inputBits - n & 0xffff >> 16 - n;
  3818. }
  3819. _eatBits(n) {
  3820. if ((this.inputBits -= n) < 0) {
  3821. this.inputBits = 0;
  3822. }
  3823. }
  3824. }
  3825. ;// CONCATENATED MODULE: ./src/core/ccitt_stream.js
  3826. class CCITTFaxStream extends DecodeStream {
  3827. constructor(str, maybeLength, params) {
  3828. super(maybeLength);
  3829. this.str = str;
  3830. this.dict = str.dict;
  3831. if (!(params instanceof Dict)) {
  3832. params = Dict.empty;
  3833. }
  3834. const source = {
  3835. next() {
  3836. return str.getByte();
  3837. }
  3838. };
  3839. this.ccittFaxDecoder = new CCITTFaxDecoder(source, {
  3840. K: params.get("K"),
  3841. EndOfLine: params.get("EndOfLine"),
  3842. EncodedByteAlign: params.get("EncodedByteAlign"),
  3843. Columns: params.get("Columns"),
  3844. Rows: params.get("Rows"),
  3845. EndOfBlock: params.get("EndOfBlock"),
  3846. BlackIs1: params.get("BlackIs1")
  3847. });
  3848. }
  3849. readBlock() {
  3850. while (!this.eof) {
  3851. const c = this.ccittFaxDecoder.readNextChar();
  3852. if (c === -1) {
  3853. this.eof = true;
  3854. return;
  3855. }
  3856. this.ensureBuffer(this.bufferLength + 1);
  3857. this.buffer[this.bufferLength++] = c;
  3858. }
  3859. }
  3860. }
  3861. ;// CONCATENATED MODULE: ./src/core/flate_stream.js
  3862. const codeLenCodeMap = new Int32Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
  3863. const lengthDecode = new Int32Array([0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a, 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f, 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073, 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102]);
  3864. const distDecode = new Int32Array([0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d, 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1, 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01, 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001]);
  3865. const fixedLitCodeTab = [new Int32Array([0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0, 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0, 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0, 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8, 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8, 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8, 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4, 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4, 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4, 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc, 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec, 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc, 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2, 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2, 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2, 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca, 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea, 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da, 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6, 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6, 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6, 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce, 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee, 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de, 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe, 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1, 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1, 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1, 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1, 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9, 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9, 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9, 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9, 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5, 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5, 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5, 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5, 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd, 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed, 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd, 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd, 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3, 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3, 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3, 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3, 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb, 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb, 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db, 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb, 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7, 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7, 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7, 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7, 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf, 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef, 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df, 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff]), 9];
  3866. const fixedDistCodeTab = [new Int32Array([0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c, 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000, 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d, 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000]), 5];
  3867. class FlateStream extends DecodeStream {
  3868. constructor(str, maybeLength) {
  3869. super(maybeLength);
  3870. this.str = str;
  3871. this.dict = str.dict;
  3872. const cmf = str.getByte();
  3873. const flg = str.getByte();
  3874. if (cmf === -1 || flg === -1) {
  3875. throw new FormatError(`Invalid header in flate stream: ${cmf}, ${flg}`);
  3876. }
  3877. if ((cmf & 0x0f) !== 0x08) {
  3878. throw new FormatError(`Unknown compression method in flate stream: ${cmf}, ${flg}`);
  3879. }
  3880. if (((cmf << 8) + flg) % 31 !== 0) {
  3881. throw new FormatError(`Bad FCHECK in flate stream: ${cmf}, ${flg}`);
  3882. }
  3883. if (flg & 0x20) {
  3884. throw new FormatError(`FDICT bit set in flate stream: ${cmf}, ${flg}`);
  3885. }
  3886. this.codeSize = 0;
  3887. this.codeBuf = 0;
  3888. }
  3889. getBits(bits) {
  3890. const str = this.str;
  3891. let codeSize = this.codeSize;
  3892. let codeBuf = this.codeBuf;
  3893. let b;
  3894. while (codeSize < bits) {
  3895. if ((b = str.getByte()) === -1) {
  3896. throw new FormatError("Bad encoding in flate stream");
  3897. }
  3898. codeBuf |= b << codeSize;
  3899. codeSize += 8;
  3900. }
  3901. b = codeBuf & (1 << bits) - 1;
  3902. this.codeBuf = codeBuf >> bits;
  3903. this.codeSize = codeSize -= bits;
  3904. return b;
  3905. }
  3906. getCode(table) {
  3907. const str = this.str;
  3908. const codes = table[0];
  3909. const maxLen = table[1];
  3910. let codeSize = this.codeSize;
  3911. let codeBuf = this.codeBuf;
  3912. let b;
  3913. while (codeSize < maxLen) {
  3914. if ((b = str.getByte()) === -1) {
  3915. break;
  3916. }
  3917. codeBuf |= b << codeSize;
  3918. codeSize += 8;
  3919. }
  3920. const code = codes[codeBuf & (1 << maxLen) - 1];
  3921. const codeLen = code >> 16;
  3922. const codeVal = code & 0xffff;
  3923. if (codeLen < 1 || codeSize < codeLen) {
  3924. throw new FormatError("Bad encoding in flate stream");
  3925. }
  3926. this.codeBuf = codeBuf >> codeLen;
  3927. this.codeSize = codeSize - codeLen;
  3928. return codeVal;
  3929. }
  3930. generateHuffmanTable(lengths) {
  3931. const n = lengths.length;
  3932. let maxLen = 0;
  3933. let i;
  3934. for (i = 0; i < n; ++i) {
  3935. if (lengths[i] > maxLen) {
  3936. maxLen = lengths[i];
  3937. }
  3938. }
  3939. const size = 1 << maxLen;
  3940. const codes = new Int32Array(size);
  3941. for (let len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  3942. for (let val = 0; val < n; ++val) {
  3943. if (lengths[val] === len) {
  3944. let code2 = 0;
  3945. let t = code;
  3946. for (i = 0; i < len; ++i) {
  3947. code2 = code2 << 1 | t & 1;
  3948. t >>= 1;
  3949. }
  3950. for (i = code2; i < size; i += skip) {
  3951. codes[i] = len << 16 | val;
  3952. }
  3953. ++code;
  3954. }
  3955. }
  3956. }
  3957. return [codes, maxLen];
  3958. }
  3959. #endsStreamOnError(err) {
  3960. info(err);
  3961. this.eof = true;
  3962. }
  3963. readBlock() {
  3964. let buffer, len;
  3965. const str = this.str;
  3966. let hdr = this.getBits(3);
  3967. if (hdr & 1) {
  3968. this.eof = true;
  3969. }
  3970. hdr >>= 1;
  3971. if (hdr === 0) {
  3972. let b;
  3973. if ((b = str.getByte()) === -1) {
  3974. this.#endsStreamOnError("Bad block header in flate stream");
  3975. return;
  3976. }
  3977. let blockLen = b;
  3978. if ((b = str.getByte()) === -1) {
  3979. this.#endsStreamOnError("Bad block header in flate stream");
  3980. return;
  3981. }
  3982. blockLen |= b << 8;
  3983. if ((b = str.getByte()) === -1) {
  3984. this.#endsStreamOnError("Bad block header in flate stream");
  3985. return;
  3986. }
  3987. let check = b;
  3988. if ((b = str.getByte()) === -1) {
  3989. this.#endsStreamOnError("Bad block header in flate stream");
  3990. return;
  3991. }
  3992. check |= b << 8;
  3993. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  3994. throw new FormatError("Bad uncompressed block length in flate stream");
  3995. }
  3996. this.codeBuf = 0;
  3997. this.codeSize = 0;
  3998. const bufferLength = this.bufferLength,
  3999. end = bufferLength + blockLen;
  4000. buffer = this.ensureBuffer(end);
  4001. this.bufferLength = end;
  4002. if (blockLen === 0) {
  4003. if (str.peekByte() === -1) {
  4004. this.eof = true;
  4005. }
  4006. } else {
  4007. const block = str.getBytes(blockLen);
  4008. buffer.set(block, bufferLength);
  4009. if (block.length < blockLen) {
  4010. this.eof = true;
  4011. }
  4012. }
  4013. return;
  4014. }
  4015. let litCodeTable;
  4016. let distCodeTable;
  4017. if (hdr === 1) {
  4018. litCodeTable = fixedLitCodeTab;
  4019. distCodeTable = fixedDistCodeTab;
  4020. } else if (hdr === 2) {
  4021. const numLitCodes = this.getBits(5) + 257;
  4022. const numDistCodes = this.getBits(5) + 1;
  4023. const numCodeLenCodes = this.getBits(4) + 4;
  4024. const codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  4025. let i;
  4026. for (i = 0; i < numCodeLenCodes; ++i) {
  4027. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  4028. }
  4029. const codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  4030. len = 0;
  4031. i = 0;
  4032. const codes = numLitCodes + numDistCodes;
  4033. const codeLengths = new Uint8Array(codes);
  4034. let bitsLength, bitsOffset, what;
  4035. while (i < codes) {
  4036. const code = this.getCode(codeLenCodeTab);
  4037. if (code === 16) {
  4038. bitsLength = 2;
  4039. bitsOffset = 3;
  4040. what = len;
  4041. } else if (code === 17) {
  4042. bitsLength = 3;
  4043. bitsOffset = 3;
  4044. what = len = 0;
  4045. } else if (code === 18) {
  4046. bitsLength = 7;
  4047. bitsOffset = 11;
  4048. what = len = 0;
  4049. } else {
  4050. codeLengths[i++] = len = code;
  4051. continue;
  4052. }
  4053. let repeatLength = this.getBits(bitsLength) + bitsOffset;
  4054. while (repeatLength-- > 0) {
  4055. codeLengths[i++] = what;
  4056. }
  4057. }
  4058. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  4059. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  4060. } else {
  4061. throw new FormatError("Unknown block type in flate stream");
  4062. }
  4063. buffer = this.buffer;
  4064. let limit = buffer ? buffer.length : 0;
  4065. let pos = this.bufferLength;
  4066. while (true) {
  4067. let code1 = this.getCode(litCodeTable);
  4068. if (code1 < 256) {
  4069. if (pos + 1 >= limit) {
  4070. buffer = this.ensureBuffer(pos + 1);
  4071. limit = buffer.length;
  4072. }
  4073. buffer[pos++] = code1;
  4074. continue;
  4075. }
  4076. if (code1 === 256) {
  4077. this.bufferLength = pos;
  4078. return;
  4079. }
  4080. code1 -= 257;
  4081. code1 = lengthDecode[code1];
  4082. let code2 = code1 >> 16;
  4083. if (code2 > 0) {
  4084. code2 = this.getBits(code2);
  4085. }
  4086. len = (code1 & 0xffff) + code2;
  4087. code1 = this.getCode(distCodeTable);
  4088. code1 = distDecode[code1];
  4089. code2 = code1 >> 16;
  4090. if (code2 > 0) {
  4091. code2 = this.getBits(code2);
  4092. }
  4093. const dist = (code1 & 0xffff) + code2;
  4094. if (pos + len >= limit) {
  4095. buffer = this.ensureBuffer(pos + len);
  4096. limit = buffer.length;
  4097. }
  4098. for (let k = 0; k < len; ++k, ++pos) {
  4099. buffer[pos] = buffer[pos - dist];
  4100. }
  4101. }
  4102. }
  4103. }
  4104. ;// CONCATENATED MODULE: ./src/core/arithmetic_decoder.js
  4105. const QeTable = [{
  4106. qe: 0x5601,
  4107. nmps: 1,
  4108. nlps: 1,
  4109. switchFlag: 1
  4110. }, {
  4111. qe: 0x3401,
  4112. nmps: 2,
  4113. nlps: 6,
  4114. switchFlag: 0
  4115. }, {
  4116. qe: 0x1801,
  4117. nmps: 3,
  4118. nlps: 9,
  4119. switchFlag: 0
  4120. }, {
  4121. qe: 0x0ac1,
  4122. nmps: 4,
  4123. nlps: 12,
  4124. switchFlag: 0
  4125. }, {
  4126. qe: 0x0521,
  4127. nmps: 5,
  4128. nlps: 29,
  4129. switchFlag: 0
  4130. }, {
  4131. qe: 0x0221,
  4132. nmps: 38,
  4133. nlps: 33,
  4134. switchFlag: 0
  4135. }, {
  4136. qe: 0x5601,
  4137. nmps: 7,
  4138. nlps: 6,
  4139. switchFlag: 1
  4140. }, {
  4141. qe: 0x5401,
  4142. nmps: 8,
  4143. nlps: 14,
  4144. switchFlag: 0
  4145. }, {
  4146. qe: 0x4801,
  4147. nmps: 9,
  4148. nlps: 14,
  4149. switchFlag: 0
  4150. }, {
  4151. qe: 0x3801,
  4152. nmps: 10,
  4153. nlps: 14,
  4154. switchFlag: 0
  4155. }, {
  4156. qe: 0x3001,
  4157. nmps: 11,
  4158. nlps: 17,
  4159. switchFlag: 0
  4160. }, {
  4161. qe: 0x2401,
  4162. nmps: 12,
  4163. nlps: 18,
  4164. switchFlag: 0
  4165. }, {
  4166. qe: 0x1c01,
  4167. nmps: 13,
  4168. nlps: 20,
  4169. switchFlag: 0
  4170. }, {
  4171. qe: 0x1601,
  4172. nmps: 29,
  4173. nlps: 21,
  4174. switchFlag: 0
  4175. }, {
  4176. qe: 0x5601,
  4177. nmps: 15,
  4178. nlps: 14,
  4179. switchFlag: 1
  4180. }, {
  4181. qe: 0x5401,
  4182. nmps: 16,
  4183. nlps: 14,
  4184. switchFlag: 0
  4185. }, {
  4186. qe: 0x5101,
  4187. nmps: 17,
  4188. nlps: 15,
  4189. switchFlag: 0
  4190. }, {
  4191. qe: 0x4801,
  4192. nmps: 18,
  4193. nlps: 16,
  4194. switchFlag: 0
  4195. }, {
  4196. qe: 0x3801,
  4197. nmps: 19,
  4198. nlps: 17,
  4199. switchFlag: 0
  4200. }, {
  4201. qe: 0x3401,
  4202. nmps: 20,
  4203. nlps: 18,
  4204. switchFlag: 0
  4205. }, {
  4206. qe: 0x3001,
  4207. nmps: 21,
  4208. nlps: 19,
  4209. switchFlag: 0
  4210. }, {
  4211. qe: 0x2801,
  4212. nmps: 22,
  4213. nlps: 19,
  4214. switchFlag: 0
  4215. }, {
  4216. qe: 0x2401,
  4217. nmps: 23,
  4218. nlps: 20,
  4219. switchFlag: 0
  4220. }, {
  4221. qe: 0x2201,
  4222. nmps: 24,
  4223. nlps: 21,
  4224. switchFlag: 0
  4225. }, {
  4226. qe: 0x1c01,
  4227. nmps: 25,
  4228. nlps: 22,
  4229. switchFlag: 0
  4230. }, {
  4231. qe: 0x1801,
  4232. nmps: 26,
  4233. nlps: 23,
  4234. switchFlag: 0
  4235. }, {
  4236. qe: 0x1601,
  4237. nmps: 27,
  4238. nlps: 24,
  4239. switchFlag: 0
  4240. }, {
  4241. qe: 0x1401,
  4242. nmps: 28,
  4243. nlps: 25,
  4244. switchFlag: 0
  4245. }, {
  4246. qe: 0x1201,
  4247. nmps: 29,
  4248. nlps: 26,
  4249. switchFlag: 0
  4250. }, {
  4251. qe: 0x1101,
  4252. nmps: 30,
  4253. nlps: 27,
  4254. switchFlag: 0
  4255. }, {
  4256. qe: 0x0ac1,
  4257. nmps: 31,
  4258. nlps: 28,
  4259. switchFlag: 0
  4260. }, {
  4261. qe: 0x09c1,
  4262. nmps: 32,
  4263. nlps: 29,
  4264. switchFlag: 0
  4265. }, {
  4266. qe: 0x08a1,
  4267. nmps: 33,
  4268. nlps: 30,
  4269. switchFlag: 0
  4270. }, {
  4271. qe: 0x0521,
  4272. nmps: 34,
  4273. nlps: 31,
  4274. switchFlag: 0
  4275. }, {
  4276. qe: 0x0441,
  4277. nmps: 35,
  4278. nlps: 32,
  4279. switchFlag: 0
  4280. }, {
  4281. qe: 0x02a1,
  4282. nmps: 36,
  4283. nlps: 33,
  4284. switchFlag: 0
  4285. }, {
  4286. qe: 0x0221,
  4287. nmps: 37,
  4288. nlps: 34,
  4289. switchFlag: 0
  4290. }, {
  4291. qe: 0x0141,
  4292. nmps: 38,
  4293. nlps: 35,
  4294. switchFlag: 0
  4295. }, {
  4296. qe: 0x0111,
  4297. nmps: 39,
  4298. nlps: 36,
  4299. switchFlag: 0
  4300. }, {
  4301. qe: 0x0085,
  4302. nmps: 40,
  4303. nlps: 37,
  4304. switchFlag: 0
  4305. }, {
  4306. qe: 0x0049,
  4307. nmps: 41,
  4308. nlps: 38,
  4309. switchFlag: 0
  4310. }, {
  4311. qe: 0x0025,
  4312. nmps: 42,
  4313. nlps: 39,
  4314. switchFlag: 0
  4315. }, {
  4316. qe: 0x0015,
  4317. nmps: 43,
  4318. nlps: 40,
  4319. switchFlag: 0
  4320. }, {
  4321. qe: 0x0009,
  4322. nmps: 44,
  4323. nlps: 41,
  4324. switchFlag: 0
  4325. }, {
  4326. qe: 0x0005,
  4327. nmps: 45,
  4328. nlps: 42,
  4329. switchFlag: 0
  4330. }, {
  4331. qe: 0x0001,
  4332. nmps: 45,
  4333. nlps: 43,
  4334. switchFlag: 0
  4335. }, {
  4336. qe: 0x5601,
  4337. nmps: 46,
  4338. nlps: 46,
  4339. switchFlag: 0
  4340. }];
  4341. class ArithmeticDecoder {
  4342. constructor(data, start, end) {
  4343. this.data = data;
  4344. this.bp = start;
  4345. this.dataEnd = end;
  4346. this.chigh = data[start];
  4347. this.clow = 0;
  4348. this.byteIn();
  4349. this.chigh = this.chigh << 7 & 0xffff | this.clow >> 9 & 0x7f;
  4350. this.clow = this.clow << 7 & 0xffff;
  4351. this.ct -= 7;
  4352. this.a = 0x8000;
  4353. }
  4354. byteIn() {
  4355. const data = this.data;
  4356. let bp = this.bp;
  4357. if (data[bp] === 0xff) {
  4358. if (data[bp + 1] > 0x8f) {
  4359. this.clow += 0xff00;
  4360. this.ct = 8;
  4361. } else {
  4362. bp++;
  4363. this.clow += data[bp] << 9;
  4364. this.ct = 7;
  4365. this.bp = bp;
  4366. }
  4367. } else {
  4368. bp++;
  4369. this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xff00;
  4370. this.ct = 8;
  4371. this.bp = bp;
  4372. }
  4373. if (this.clow > 0xffff) {
  4374. this.chigh += this.clow >> 16;
  4375. this.clow &= 0xffff;
  4376. }
  4377. }
  4378. readBit(contexts, pos) {
  4379. let cx_index = contexts[pos] >> 1,
  4380. cx_mps = contexts[pos] & 1;
  4381. const qeTableIcx = QeTable[cx_index];
  4382. const qeIcx = qeTableIcx.qe;
  4383. let d;
  4384. let a = this.a - qeIcx;
  4385. if (this.chigh < qeIcx) {
  4386. if (a < qeIcx) {
  4387. a = qeIcx;
  4388. d = cx_mps;
  4389. cx_index = qeTableIcx.nmps;
  4390. } else {
  4391. a = qeIcx;
  4392. d = 1 ^ cx_mps;
  4393. if (qeTableIcx.switchFlag === 1) {
  4394. cx_mps = d;
  4395. }
  4396. cx_index = qeTableIcx.nlps;
  4397. }
  4398. } else {
  4399. this.chigh -= qeIcx;
  4400. if ((a & 0x8000) !== 0) {
  4401. this.a = a;
  4402. return cx_mps;
  4403. }
  4404. if (a < qeIcx) {
  4405. d = 1 ^ cx_mps;
  4406. if (qeTableIcx.switchFlag === 1) {
  4407. cx_mps = d;
  4408. }
  4409. cx_index = qeTableIcx.nlps;
  4410. } else {
  4411. d = cx_mps;
  4412. cx_index = qeTableIcx.nmps;
  4413. }
  4414. }
  4415. do {
  4416. if (this.ct === 0) {
  4417. this.byteIn();
  4418. }
  4419. a <<= 1;
  4420. this.chigh = this.chigh << 1 & 0xffff | this.clow >> 15 & 1;
  4421. this.clow = this.clow << 1 & 0xffff;
  4422. this.ct--;
  4423. } while ((a & 0x8000) === 0);
  4424. this.a = a;
  4425. contexts[pos] = cx_index << 1 | cx_mps;
  4426. return d;
  4427. }
  4428. }
  4429. ;// CONCATENATED MODULE: ./src/core/jbig2.js
  4430. class Jbig2Error extends BaseException {
  4431. constructor(msg) {
  4432. super(`JBIG2 error: ${msg}`, "Jbig2Error");
  4433. }
  4434. }
  4435. class ContextCache {
  4436. getContexts(id) {
  4437. if (id in this) {
  4438. return this[id];
  4439. }
  4440. return this[id] = new Int8Array(1 << 16);
  4441. }
  4442. }
  4443. class DecodingContext {
  4444. constructor(data, start, end) {
  4445. this.data = data;
  4446. this.start = start;
  4447. this.end = end;
  4448. }
  4449. get decoder() {
  4450. const decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  4451. return shadow(this, "decoder", decoder);
  4452. }
  4453. get contextCache() {
  4454. const cache = new ContextCache();
  4455. return shadow(this, "contextCache", cache);
  4456. }
  4457. }
  4458. const MAX_INT_32 = 2 ** 31 - 1;
  4459. const MIN_INT_32 = -(2 ** 31);
  4460. function decodeInteger(contextCache, procedure, decoder) {
  4461. const contexts = contextCache.getContexts(procedure);
  4462. let prev = 1;
  4463. function readBits(length) {
  4464. let v = 0;
  4465. for (let i = 0; i < length; i++) {
  4466. const bit = decoder.readBit(contexts, prev);
  4467. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  4468. v = v << 1 | bit;
  4469. }
  4470. return v >>> 0;
  4471. }
  4472. const sign = readBits(1);
  4473. const 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);
  4474. let signedValue;
  4475. if (sign === 0) {
  4476. signedValue = value;
  4477. } else if (value > 0) {
  4478. signedValue = -value;
  4479. }
  4480. if (signedValue >= MIN_INT_32 && signedValue <= MAX_INT_32) {
  4481. return signedValue;
  4482. }
  4483. return null;
  4484. }
  4485. function decodeIAID(contextCache, decoder, codeLength) {
  4486. const contexts = contextCache.getContexts("IAID");
  4487. let prev = 1;
  4488. for (let i = 0; i < codeLength; i++) {
  4489. const bit = decoder.readBit(contexts, prev);
  4490. prev = prev << 1 | bit;
  4491. }
  4492. if (codeLength < 31) {
  4493. return prev & (1 << codeLength) - 1;
  4494. }
  4495. return prev & 0x7fffffff;
  4496. }
  4497. const SegmentTypes = ["SymbolDictionary", null, null, null, "IntermediateTextRegion", null, "ImmediateTextRegion", "ImmediateLosslessTextRegion", null, null, null, null, null, null, null, null, "PatternDictionary", null, null, null, "IntermediateHalftoneRegion", null, "ImmediateHalftoneRegion", "ImmediateLosslessHalftoneRegion", null, null, null, null, null, null, null, null, null, null, null, null, "IntermediateGenericRegion", null, "ImmediateGenericRegion", "ImmediateLosslessGenericRegion", "IntermediateGenericRefinementRegion", null, "ImmediateGenericRefinementRegion", "ImmediateLosslessGenericRefinementRegion", null, null, null, null, "PageInformation", "EndOfPage", "EndOfStripe", "EndOfFile", "Profiles", "Tables", null, null, null, null, null, null, null, null, "Extension"];
  4498. const CodingTemplates = [[{
  4499. x: -1,
  4500. y: -2
  4501. }, {
  4502. x: 0,
  4503. y: -2
  4504. }, {
  4505. x: 1,
  4506. y: -2
  4507. }, {
  4508. x: -2,
  4509. y: -1
  4510. }, {
  4511. x: -1,
  4512. y: -1
  4513. }, {
  4514. x: 0,
  4515. y: -1
  4516. }, {
  4517. x: 1,
  4518. y: -1
  4519. }, {
  4520. x: 2,
  4521. y: -1
  4522. }, {
  4523. x: -4,
  4524. y: 0
  4525. }, {
  4526. x: -3,
  4527. y: 0
  4528. }, {
  4529. x: -2,
  4530. y: 0
  4531. }, {
  4532. x: -1,
  4533. y: 0
  4534. }], [{
  4535. x: -1,
  4536. y: -2
  4537. }, {
  4538. x: 0,
  4539. y: -2
  4540. }, {
  4541. x: 1,
  4542. y: -2
  4543. }, {
  4544. x: 2,
  4545. y: -2
  4546. }, {
  4547. x: -2,
  4548. y: -1
  4549. }, {
  4550. x: -1,
  4551. y: -1
  4552. }, {
  4553. x: 0,
  4554. y: -1
  4555. }, {
  4556. x: 1,
  4557. y: -1
  4558. }, {
  4559. x: 2,
  4560. y: -1
  4561. }, {
  4562. x: -3,
  4563. y: 0
  4564. }, {
  4565. x: -2,
  4566. y: 0
  4567. }, {
  4568. x: -1,
  4569. y: 0
  4570. }], [{
  4571. x: -1,
  4572. y: -2
  4573. }, {
  4574. x: 0,
  4575. y: -2
  4576. }, {
  4577. x: 1,
  4578. y: -2
  4579. }, {
  4580. x: -2,
  4581. y: -1
  4582. }, {
  4583. x: -1,
  4584. y: -1
  4585. }, {
  4586. x: 0,
  4587. y: -1
  4588. }, {
  4589. x: 1,
  4590. y: -1
  4591. }, {
  4592. x: -2,
  4593. y: 0
  4594. }, {
  4595. x: -1,
  4596. y: 0
  4597. }], [{
  4598. x: -3,
  4599. y: -1
  4600. }, {
  4601. x: -2,
  4602. y: -1
  4603. }, {
  4604. x: -1,
  4605. y: -1
  4606. }, {
  4607. x: 0,
  4608. y: -1
  4609. }, {
  4610. x: 1,
  4611. y: -1
  4612. }, {
  4613. x: -4,
  4614. y: 0
  4615. }, {
  4616. x: -3,
  4617. y: 0
  4618. }, {
  4619. x: -2,
  4620. y: 0
  4621. }, {
  4622. x: -1,
  4623. y: 0
  4624. }]];
  4625. const RefinementTemplates = [{
  4626. coding: [{
  4627. x: 0,
  4628. y: -1
  4629. }, {
  4630. x: 1,
  4631. y: -1
  4632. }, {
  4633. x: -1,
  4634. y: 0
  4635. }],
  4636. reference: [{
  4637. x: 0,
  4638. y: -1
  4639. }, {
  4640. x: 1,
  4641. y: -1
  4642. }, {
  4643. x: -1,
  4644. y: 0
  4645. }, {
  4646. x: 0,
  4647. y: 0
  4648. }, {
  4649. x: 1,
  4650. y: 0
  4651. }, {
  4652. x: -1,
  4653. y: 1
  4654. }, {
  4655. x: 0,
  4656. y: 1
  4657. }, {
  4658. x: 1,
  4659. y: 1
  4660. }]
  4661. }, {
  4662. coding: [{
  4663. x: -1,
  4664. y: -1
  4665. }, {
  4666. x: 0,
  4667. y: -1
  4668. }, {
  4669. x: 1,
  4670. y: -1
  4671. }, {
  4672. x: -1,
  4673. y: 0
  4674. }],
  4675. reference: [{
  4676. x: 0,
  4677. y: -1
  4678. }, {
  4679. x: -1,
  4680. y: 0
  4681. }, {
  4682. x: 0,
  4683. y: 0
  4684. }, {
  4685. x: 1,
  4686. y: 0
  4687. }, {
  4688. x: 0,
  4689. y: 1
  4690. }, {
  4691. x: 1,
  4692. y: 1
  4693. }]
  4694. }];
  4695. const ReusedContexts = [0x9b25, 0x0795, 0x00e5, 0x0195];
  4696. const RefinementReusedContexts = [0x0020, 0x0008];
  4697. function decodeBitmapTemplate0(width, height, decodingContext) {
  4698. const decoder = decodingContext.decoder;
  4699. const contexts = decodingContext.contextCache.getContexts("GB");
  4700. const bitmap = [];
  4701. let contextLabel, i, j, pixel, row, row1, row2;
  4702. const OLD_PIXEL_MASK = 0x7bf7;
  4703. for (i = 0; i < height; i++) {
  4704. row = bitmap[i] = new Uint8Array(width);
  4705. row1 = i < 1 ? row : bitmap[i - 1];
  4706. row2 = i < 2 ? row : bitmap[i - 2];
  4707. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  4708. for (j = 0; j < width; j++) {
  4709. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  4710. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  4711. }
  4712. }
  4713. return bitmap;
  4714. }
  4715. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  4716. if (mmr) {
  4717. const input = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
  4718. return decodeMMRBitmap(input, width, height, false);
  4719. }
  4720. 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) {
  4721. return decodeBitmapTemplate0(width, height, decodingContext);
  4722. }
  4723. const useskip = !!skip;
  4724. const template = CodingTemplates[templateIndex].concat(at);
  4725. template.sort(function (a, b) {
  4726. return a.y - b.y || a.x - b.x;
  4727. });
  4728. const templateLength = template.length;
  4729. const templateX = new Int8Array(templateLength);
  4730. const templateY = new Int8Array(templateLength);
  4731. const changingTemplateEntries = [];
  4732. let reuseMask = 0,
  4733. minX = 0,
  4734. maxX = 0,
  4735. minY = 0;
  4736. let c, k;
  4737. for (k = 0; k < templateLength; k++) {
  4738. templateX[k] = template[k].x;
  4739. templateY[k] = template[k].y;
  4740. minX = Math.min(minX, template[k].x);
  4741. maxX = Math.max(maxX, template[k].x);
  4742. minY = Math.min(minY, template[k].y);
  4743. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  4744. reuseMask |= 1 << templateLength - 1 - k;
  4745. } else {
  4746. changingTemplateEntries.push(k);
  4747. }
  4748. }
  4749. const changingEntriesLength = changingTemplateEntries.length;
  4750. const changingTemplateX = new Int8Array(changingEntriesLength);
  4751. const changingTemplateY = new Int8Array(changingEntriesLength);
  4752. const changingTemplateBit = new Uint16Array(changingEntriesLength);
  4753. for (c = 0; c < changingEntriesLength; c++) {
  4754. k = changingTemplateEntries[c];
  4755. changingTemplateX[c] = template[k].x;
  4756. changingTemplateY[c] = template[k].y;
  4757. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  4758. }
  4759. const sbb_left = -minX;
  4760. const sbb_top = -minY;
  4761. const sbb_right = width - maxX;
  4762. const pseudoPixelContext = ReusedContexts[templateIndex];
  4763. let row = new Uint8Array(width);
  4764. const bitmap = [];
  4765. const decoder = decodingContext.decoder;
  4766. const contexts = decodingContext.contextCache.getContexts("GB");
  4767. let ltp = 0,
  4768. j,
  4769. i0,
  4770. j0,
  4771. contextLabel = 0,
  4772. bit,
  4773. shift;
  4774. for (let i = 0; i < height; i++) {
  4775. if (prediction) {
  4776. const sltp = decoder.readBit(contexts, pseudoPixelContext);
  4777. ltp ^= sltp;
  4778. if (ltp) {
  4779. bitmap.push(row);
  4780. continue;
  4781. }
  4782. }
  4783. row = new Uint8Array(row);
  4784. bitmap.push(row);
  4785. for (j = 0; j < width; j++) {
  4786. if (useskip && skip[i][j]) {
  4787. row[j] = 0;
  4788. continue;
  4789. }
  4790. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  4791. contextLabel = contextLabel << 1 & reuseMask;
  4792. for (k = 0; k < changingEntriesLength; k++) {
  4793. i0 = i + changingTemplateY[k];
  4794. j0 = j + changingTemplateX[k];
  4795. bit = bitmap[i0][j0];
  4796. if (bit) {
  4797. bit = changingTemplateBit[k];
  4798. contextLabel |= bit;
  4799. }
  4800. }
  4801. } else {
  4802. contextLabel = 0;
  4803. shift = templateLength - 1;
  4804. for (k = 0; k < templateLength; k++, shift--) {
  4805. j0 = j + templateX[k];
  4806. if (j0 >= 0 && j0 < width) {
  4807. i0 = i + templateY[k];
  4808. if (i0 >= 0) {
  4809. bit = bitmap[i0][j0];
  4810. if (bit) {
  4811. contextLabel |= bit << shift;
  4812. }
  4813. }
  4814. }
  4815. }
  4816. }
  4817. const pixel = decoder.readBit(contexts, contextLabel);
  4818. row[j] = pixel;
  4819. }
  4820. }
  4821. return bitmap;
  4822. }
  4823. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  4824. let codingTemplate = RefinementTemplates[templateIndex].coding;
  4825. if (templateIndex === 0) {
  4826. codingTemplate = codingTemplate.concat([at[0]]);
  4827. }
  4828. const codingTemplateLength = codingTemplate.length;
  4829. const codingTemplateX = new Int32Array(codingTemplateLength);
  4830. const codingTemplateY = new Int32Array(codingTemplateLength);
  4831. let k;
  4832. for (k = 0; k < codingTemplateLength; k++) {
  4833. codingTemplateX[k] = codingTemplate[k].x;
  4834. codingTemplateY[k] = codingTemplate[k].y;
  4835. }
  4836. let referenceTemplate = RefinementTemplates[templateIndex].reference;
  4837. if (templateIndex === 0) {
  4838. referenceTemplate = referenceTemplate.concat([at[1]]);
  4839. }
  4840. const referenceTemplateLength = referenceTemplate.length;
  4841. const referenceTemplateX = new Int32Array(referenceTemplateLength);
  4842. const referenceTemplateY = new Int32Array(referenceTemplateLength);
  4843. for (k = 0; k < referenceTemplateLength; k++) {
  4844. referenceTemplateX[k] = referenceTemplate[k].x;
  4845. referenceTemplateY[k] = referenceTemplate[k].y;
  4846. }
  4847. const referenceWidth = referenceBitmap[0].length;
  4848. const referenceHeight = referenceBitmap.length;
  4849. const pseudoPixelContext = RefinementReusedContexts[templateIndex];
  4850. const bitmap = [];
  4851. const decoder = decodingContext.decoder;
  4852. const contexts = decodingContext.contextCache.getContexts("GR");
  4853. let ltp = 0;
  4854. for (let i = 0; i < height; i++) {
  4855. if (prediction) {
  4856. const sltp = decoder.readBit(contexts, pseudoPixelContext);
  4857. ltp ^= sltp;
  4858. if (ltp) {
  4859. throw new Jbig2Error("prediction is not supported");
  4860. }
  4861. }
  4862. const row = new Uint8Array(width);
  4863. bitmap.push(row);
  4864. for (let j = 0; j < width; j++) {
  4865. let i0, j0;
  4866. let contextLabel = 0;
  4867. for (k = 0; k < codingTemplateLength; k++) {
  4868. i0 = i + codingTemplateY[k];
  4869. j0 = j + codingTemplateX[k];
  4870. if (i0 < 0 || j0 < 0 || j0 >= width) {
  4871. contextLabel <<= 1;
  4872. } else {
  4873. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  4874. }
  4875. }
  4876. for (k = 0; k < referenceTemplateLength; k++) {
  4877. i0 = i + referenceTemplateY[k] - offsetY;
  4878. j0 = j + referenceTemplateX[k] - offsetX;
  4879. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  4880. contextLabel <<= 1;
  4881. } else {
  4882. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  4883. }
  4884. }
  4885. const pixel = decoder.readBit(contexts, contextLabel);
  4886. row[j] = pixel;
  4887. }
  4888. }
  4889. return bitmap;
  4890. }
  4891. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext, huffmanInput) {
  4892. if (huffman && refinement) {
  4893. throw new Jbig2Error("symbol refinement with Huffman is not supported");
  4894. }
  4895. const newSymbols = [];
  4896. let currentHeight = 0;
  4897. let symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  4898. const decoder = decodingContext.decoder;
  4899. const contextCache = decodingContext.contextCache;
  4900. let tableB1, symbolWidths;
  4901. if (huffman) {
  4902. tableB1 = getStandardTable(1);
  4903. symbolWidths = [];
  4904. symbolCodeLength = Math.max(symbolCodeLength, 1);
  4905. }
  4906. while (newSymbols.length < numberOfNewSymbols) {
  4907. const deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, "IADH", decoder);
  4908. currentHeight += deltaHeight;
  4909. let currentWidth = 0,
  4910. totalWidth = 0;
  4911. const firstSymbol = huffman ? symbolWidths.length : 0;
  4912. while (true) {
  4913. const deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, "IADW", decoder);
  4914. if (deltaWidth === null) {
  4915. break;
  4916. }
  4917. currentWidth += deltaWidth;
  4918. totalWidth += currentWidth;
  4919. let bitmap;
  4920. if (refinement) {
  4921. const numberOfInstances = decodeInteger(contextCache, "IAAI", decoder);
  4922. if (numberOfInstances > 1) {
  4923. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);
  4924. } else {
  4925. const symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  4926. const rdx = decodeInteger(contextCache, "IARDX", decoder);
  4927. const rdy = decodeInteger(contextCache, "IARDY", decoder);
  4928. const symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  4929. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  4930. }
  4931. newSymbols.push(bitmap);
  4932. } else if (huffman) {
  4933. symbolWidths.push(currentWidth);
  4934. } else {
  4935. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  4936. newSymbols.push(bitmap);
  4937. }
  4938. }
  4939. if (huffman && !refinement) {
  4940. const bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);
  4941. huffmanInput.byteAlign();
  4942. let collectiveBitmap;
  4943. if (bitmapSize === 0) {
  4944. collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);
  4945. } else {
  4946. const originalEnd = huffmanInput.end;
  4947. const bitmapEnd = huffmanInput.position + bitmapSize;
  4948. huffmanInput.end = bitmapEnd;
  4949. collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false);
  4950. huffmanInput.end = originalEnd;
  4951. huffmanInput.position = bitmapEnd;
  4952. }
  4953. const numberOfSymbolsDecoded = symbolWidths.length;
  4954. if (firstSymbol === numberOfSymbolsDecoded - 1) {
  4955. newSymbols.push(collectiveBitmap);
  4956. } else {
  4957. let i,
  4958. y,
  4959. xMin = 0,
  4960. xMax,
  4961. bitmapWidth,
  4962. symbolBitmap;
  4963. for (i = firstSymbol; i < numberOfSymbolsDecoded; i++) {
  4964. bitmapWidth = symbolWidths[i];
  4965. xMax = xMin + bitmapWidth;
  4966. symbolBitmap = [];
  4967. for (y = 0; y < currentHeight; y++) {
  4968. symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
  4969. }
  4970. newSymbols.push(symbolBitmap);
  4971. xMin = xMax;
  4972. }
  4973. }
  4974. }
  4975. }
  4976. const exportedSymbols = [],
  4977. flags = [];
  4978. let currentFlag = false,
  4979. i,
  4980. ii;
  4981. const totalSymbolsLength = symbols.length + numberOfNewSymbols;
  4982. while (flags.length < totalSymbolsLength) {
  4983. let runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, "IAEX", decoder);
  4984. while (runLength--) {
  4985. flags.push(currentFlag);
  4986. }
  4987. currentFlag = !currentFlag;
  4988. }
  4989. for (i = 0, ii = symbols.length; i < ii; i++) {
  4990. if (flags[i]) {
  4991. exportedSymbols.push(symbols[i]);
  4992. }
  4993. }
  4994. for (let j = 0; j < numberOfNewSymbols; i++, j++) {
  4995. if (flags[i]) {
  4996. exportedSymbols.push(newSymbols[j]);
  4997. }
  4998. }
  4999. return exportedSymbols;
  5000. }
  5001. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {
  5002. if (huffman && refinement) {
  5003. throw new Jbig2Error("refinement with Huffman is not supported");
  5004. }
  5005. const bitmap = [];
  5006. let i, row;
  5007. for (i = 0; i < height; i++) {
  5008. row = new Uint8Array(width);
  5009. if (defaultPixelValue) {
  5010. for (let j = 0; j < width; j++) {
  5011. row[j] = defaultPixelValue;
  5012. }
  5013. }
  5014. bitmap.push(row);
  5015. }
  5016. const decoder = decodingContext.decoder;
  5017. const contextCache = decodingContext.contextCache;
  5018. let stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, "IADT", decoder);
  5019. let firstS = 0;
  5020. i = 0;
  5021. while (i < numberOfSymbolInstances) {
  5022. const deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, "IADT", decoder);
  5023. stripT += deltaT;
  5024. const deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, "IAFS", decoder);
  5025. firstS += deltaFirstS;
  5026. let currentS = firstS;
  5027. do {
  5028. let currentT = 0;
  5029. if (stripSize > 1) {
  5030. currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, "IAIT", decoder);
  5031. }
  5032. const t = stripSize * stripT + currentT;
  5033. const symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);
  5034. const applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, "IARI", decoder));
  5035. let symbolBitmap = inputSymbols[symbolId];
  5036. let symbolWidth = symbolBitmap[0].length;
  5037. let symbolHeight = symbolBitmap.length;
  5038. if (applyRefinement) {
  5039. const rdw = decodeInteger(contextCache, "IARDW", decoder);
  5040. const rdh = decodeInteger(contextCache, "IARDH", decoder);
  5041. const rdx = decodeInteger(contextCache, "IARDX", decoder);
  5042. const rdy = decodeInteger(contextCache, "IARDY", decoder);
  5043. symbolWidth += rdw;
  5044. symbolHeight += rdh;
  5045. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  5046. }
  5047. const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
  5048. const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
  5049. let s2, t2, symbolRow;
  5050. if (transposed) {
  5051. for (s2 = 0; s2 < symbolHeight; s2++) {
  5052. row = bitmap[offsetS + s2];
  5053. if (!row) {
  5054. continue;
  5055. }
  5056. symbolRow = symbolBitmap[s2];
  5057. const maxWidth = Math.min(width - offsetT, symbolWidth);
  5058. switch (combinationOperator) {
  5059. case 0:
  5060. for (t2 = 0; t2 < maxWidth; t2++) {
  5061. row[offsetT + t2] |= symbolRow[t2];
  5062. }
  5063. break;
  5064. case 2:
  5065. for (t2 = 0; t2 < maxWidth; t2++) {
  5066. row[offsetT + t2] ^= symbolRow[t2];
  5067. }
  5068. break;
  5069. default:
  5070. throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
  5071. }
  5072. }
  5073. currentS += symbolHeight - 1;
  5074. } else {
  5075. for (t2 = 0; t2 < symbolHeight; t2++) {
  5076. row = bitmap[offsetT + t2];
  5077. if (!row) {
  5078. continue;
  5079. }
  5080. symbolRow = symbolBitmap[t2];
  5081. switch (combinationOperator) {
  5082. case 0:
  5083. for (s2 = 0; s2 < symbolWidth; s2++) {
  5084. row[offsetS + s2] |= symbolRow[s2];
  5085. }
  5086. break;
  5087. case 2:
  5088. for (s2 = 0; s2 < symbolWidth; s2++) {
  5089. row[offsetS + s2] ^= symbolRow[s2];
  5090. }
  5091. break;
  5092. default:
  5093. throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
  5094. }
  5095. }
  5096. currentS += symbolWidth - 1;
  5097. }
  5098. i++;
  5099. const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder);
  5100. if (deltaS === null) {
  5101. break;
  5102. }
  5103. currentS += deltaS + dsOffset;
  5104. } while (true);
  5105. }
  5106. return bitmap;
  5107. }
  5108. function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {
  5109. const at = [];
  5110. if (!mmr) {
  5111. at.push({
  5112. x: -patternWidth,
  5113. y: 0
  5114. });
  5115. if (template === 0) {
  5116. at.push({
  5117. x: -3,
  5118. y: -1
  5119. }, {
  5120. x: 2,
  5121. y: -2
  5122. }, {
  5123. x: -2,
  5124. y: -2
  5125. });
  5126. }
  5127. }
  5128. const collectiveWidth = (maxPatternIndex + 1) * patternWidth;
  5129. const collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);
  5130. const patterns = [];
  5131. for (let i = 0; i <= maxPatternIndex; i++) {
  5132. const patternBitmap = [];
  5133. const xMin = patternWidth * i;
  5134. const xMax = xMin + patternWidth;
  5135. for (let y = 0; y < patternHeight; y++) {
  5136. patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));
  5137. }
  5138. patterns.push(patternBitmap);
  5139. }
  5140. return patterns;
  5141. }
  5142. function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {
  5143. const skip = null;
  5144. if (enableSkip) {
  5145. throw new Jbig2Error("skip is not supported");
  5146. }
  5147. if (combinationOperator !== 0) {
  5148. throw new Jbig2Error(`operator "${combinationOperator}" is not supported in halftone region`);
  5149. }
  5150. const regionBitmap = [];
  5151. let i, j, row;
  5152. for (i = 0; i < regionHeight; i++) {
  5153. row = new Uint8Array(regionWidth);
  5154. if (defaultPixelValue) {
  5155. for (j = 0; j < regionWidth; j++) {
  5156. row[j] = defaultPixelValue;
  5157. }
  5158. }
  5159. regionBitmap.push(row);
  5160. }
  5161. const numberOfPatterns = patterns.length;
  5162. const pattern0 = patterns[0];
  5163. const patternWidth = pattern0[0].length,
  5164. patternHeight = pattern0.length;
  5165. const bitsPerValue = log2(numberOfPatterns);
  5166. const at = [];
  5167. if (!mmr) {
  5168. at.push({
  5169. x: template <= 1 ? 3 : 2,
  5170. y: -1
  5171. });
  5172. if (template === 0) {
  5173. at.push({
  5174. x: -3,
  5175. y: -1
  5176. }, {
  5177. x: 2,
  5178. y: -2
  5179. }, {
  5180. x: -2,
  5181. y: -2
  5182. });
  5183. }
  5184. }
  5185. const grayScaleBitPlanes = [];
  5186. let mmrInput, bitmap;
  5187. if (mmr) {
  5188. mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);
  5189. }
  5190. for (i = bitsPerValue - 1; i >= 0; i--) {
  5191. if (mmr) {
  5192. bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);
  5193. } else {
  5194. bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);
  5195. }
  5196. grayScaleBitPlanes[i] = bitmap;
  5197. }
  5198. let mg, ng, bit, patternIndex, patternBitmap, x, y, patternRow, regionRow;
  5199. for (mg = 0; mg < gridHeight; mg++) {
  5200. for (ng = 0; ng < gridWidth; ng++) {
  5201. bit = 0;
  5202. patternIndex = 0;
  5203. for (j = bitsPerValue - 1; j >= 0; j--) {
  5204. bit ^= grayScaleBitPlanes[j][mg][ng];
  5205. patternIndex |= bit << j;
  5206. }
  5207. patternBitmap = patterns[patternIndex];
  5208. x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;
  5209. y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;
  5210. if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {
  5211. for (i = 0; i < patternHeight; i++) {
  5212. regionRow = regionBitmap[y + i];
  5213. patternRow = patternBitmap[i];
  5214. for (j = 0; j < patternWidth; j++) {
  5215. regionRow[x + j] |= patternRow[j];
  5216. }
  5217. }
  5218. } else {
  5219. let regionX, regionY;
  5220. for (i = 0; i < patternHeight; i++) {
  5221. regionY = y + i;
  5222. if (regionY < 0 || regionY >= regionHeight) {
  5223. continue;
  5224. }
  5225. regionRow = regionBitmap[regionY];
  5226. patternRow = patternBitmap[i];
  5227. for (j = 0; j < patternWidth; j++) {
  5228. regionX = x + j;
  5229. if (regionX >= 0 && regionX < regionWidth) {
  5230. regionRow[regionX] |= patternRow[j];
  5231. }
  5232. }
  5233. }
  5234. }
  5235. }
  5236. }
  5237. return regionBitmap;
  5238. }
  5239. function readSegmentHeader(data, start) {
  5240. const segmentHeader = {};
  5241. segmentHeader.number = readUint32(data, start);
  5242. const flags = data[start + 4];
  5243. const segmentType = flags & 0x3f;
  5244. if (!SegmentTypes[segmentType]) {
  5245. throw new Jbig2Error("invalid segment type: " + segmentType);
  5246. }
  5247. segmentHeader.type = segmentType;
  5248. segmentHeader.typeName = SegmentTypes[segmentType];
  5249. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  5250. const pageAssociationFieldSize = !!(flags & 0x40);
  5251. const referredFlags = data[start + 5];
  5252. let referredToCount = referredFlags >> 5 & 7;
  5253. const retainBits = [referredFlags & 31];
  5254. let position = start + 6;
  5255. if (referredFlags === 7) {
  5256. referredToCount = readUint32(data, position - 1) & 0x1fffffff;
  5257. position += 3;
  5258. let bytes = referredToCount + 7 >> 3;
  5259. retainBits[0] = data[position++];
  5260. while (--bytes > 0) {
  5261. retainBits.push(data[position++]);
  5262. }
  5263. } else if (referredFlags === 5 || referredFlags === 6) {
  5264. throw new Jbig2Error("invalid referred-to flags");
  5265. }
  5266. segmentHeader.retainBits = retainBits;
  5267. let referredToSegmentNumberSize = 4;
  5268. if (segmentHeader.number <= 256) {
  5269. referredToSegmentNumberSize = 1;
  5270. } else if (segmentHeader.number <= 65536) {
  5271. referredToSegmentNumberSize = 2;
  5272. }
  5273. const referredTo = [];
  5274. let i, ii;
  5275. for (i = 0; i < referredToCount; i++) {
  5276. let number;
  5277. if (referredToSegmentNumberSize === 1) {
  5278. number = data[position];
  5279. } else if (referredToSegmentNumberSize === 2) {
  5280. number = readUint16(data, position);
  5281. } else {
  5282. number = readUint32(data, position);
  5283. }
  5284. referredTo.push(number);
  5285. position += referredToSegmentNumberSize;
  5286. }
  5287. segmentHeader.referredTo = referredTo;
  5288. if (!pageAssociationFieldSize) {
  5289. segmentHeader.pageAssociation = data[position++];
  5290. } else {
  5291. segmentHeader.pageAssociation = readUint32(data, position);
  5292. position += 4;
  5293. }
  5294. segmentHeader.length = readUint32(data, position);
  5295. position += 4;
  5296. if (segmentHeader.length === 0xffffffff) {
  5297. if (segmentType === 38) {
  5298. const genericRegionInfo = readRegionSegmentInformation(data, position);
  5299. const genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  5300. const genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  5301. const searchPatternLength = 6;
  5302. const searchPattern = new Uint8Array(searchPatternLength);
  5303. if (!genericRegionMmr) {
  5304. searchPattern[0] = 0xff;
  5305. searchPattern[1] = 0xac;
  5306. }
  5307. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xff;
  5308. searchPattern[3] = genericRegionInfo.height >> 16 & 0xff;
  5309. searchPattern[4] = genericRegionInfo.height >> 8 & 0xff;
  5310. searchPattern[5] = genericRegionInfo.height & 0xff;
  5311. for (i = position, ii = data.length; i < ii; i++) {
  5312. let j = 0;
  5313. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  5314. j++;
  5315. }
  5316. if (j === searchPatternLength) {
  5317. segmentHeader.length = i + searchPatternLength;
  5318. break;
  5319. }
  5320. }
  5321. if (segmentHeader.length === 0xffffffff) {
  5322. throw new Jbig2Error("segment end was not found");
  5323. }
  5324. } else {
  5325. throw new Jbig2Error("invalid unknown segment length");
  5326. }
  5327. }
  5328. segmentHeader.headerEnd = position;
  5329. return segmentHeader;
  5330. }
  5331. function readSegments(header, data, start, end) {
  5332. const segments = [];
  5333. let position = start;
  5334. while (position < end) {
  5335. const segmentHeader = readSegmentHeader(data, position);
  5336. position = segmentHeader.headerEnd;
  5337. const segment = {
  5338. header: segmentHeader,
  5339. data
  5340. };
  5341. if (!header.randomAccess) {
  5342. segment.start = position;
  5343. position += segmentHeader.length;
  5344. segment.end = position;
  5345. }
  5346. segments.push(segment);
  5347. if (segmentHeader.type === 51) {
  5348. break;
  5349. }
  5350. }
  5351. if (header.randomAccess) {
  5352. for (let i = 0, ii = segments.length; i < ii; i++) {
  5353. segments[i].start = position;
  5354. position += segments[i].header.length;
  5355. segments[i].end = position;
  5356. }
  5357. }
  5358. return segments;
  5359. }
  5360. function readRegionSegmentInformation(data, start) {
  5361. return {
  5362. width: readUint32(data, start),
  5363. height: readUint32(data, start + 4),
  5364. x: readUint32(data, start + 8),
  5365. y: readUint32(data, start + 12),
  5366. combinationOperator: data[start + 16] & 7
  5367. };
  5368. }
  5369. const RegionSegmentInformationFieldLength = 17;
  5370. function processSegment(segment, visitor) {
  5371. const header = segment.header;
  5372. const data = segment.data,
  5373. end = segment.end;
  5374. let position = segment.start;
  5375. let args, at, i, atLength;
  5376. switch (header.type) {
  5377. case 0:
  5378. const dictionary = {};
  5379. const dictionaryFlags = readUint16(data, position);
  5380. dictionary.huffman = !!(dictionaryFlags & 1);
  5381. dictionary.refinement = !!(dictionaryFlags & 2);
  5382. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  5383. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  5384. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  5385. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  5386. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  5387. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  5388. dictionary.template = dictionaryFlags >> 10 & 3;
  5389. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  5390. position += 2;
  5391. if (!dictionary.huffman) {
  5392. atLength = dictionary.template === 0 ? 4 : 1;
  5393. at = [];
  5394. for (i = 0; i < atLength; i++) {
  5395. at.push({
  5396. x: readInt8(data, position),
  5397. y: readInt8(data, position + 1)
  5398. });
  5399. position += 2;
  5400. }
  5401. dictionary.at = at;
  5402. }
  5403. if (dictionary.refinement && !dictionary.refinementTemplate) {
  5404. at = [];
  5405. for (i = 0; i < 2; i++) {
  5406. at.push({
  5407. x: readInt8(data, position),
  5408. y: readInt8(data, position + 1)
  5409. });
  5410. position += 2;
  5411. }
  5412. dictionary.refinementAt = at;
  5413. }
  5414. dictionary.numberOfExportedSymbols = readUint32(data, position);
  5415. position += 4;
  5416. dictionary.numberOfNewSymbols = readUint32(data, position);
  5417. position += 4;
  5418. args = [dictionary, header.number, header.referredTo, data, position, end];
  5419. break;
  5420. case 6:
  5421. case 7:
  5422. const textRegion = {};
  5423. textRegion.info = readRegionSegmentInformation(data, position);
  5424. position += RegionSegmentInformationFieldLength;
  5425. const textRegionSegmentFlags = readUint16(data, position);
  5426. position += 2;
  5427. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  5428. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  5429. textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3;
  5430. textRegion.stripSize = 1 << textRegion.logStripSize;
  5431. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  5432. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  5433. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  5434. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  5435. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  5436. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  5437. if (textRegion.huffman) {
  5438. const textRegionHuffmanFlags = readUint16(data, position);
  5439. position += 2;
  5440. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  5441. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  5442. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  5443. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  5444. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  5445. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  5446. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  5447. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);
  5448. }
  5449. if (textRegion.refinement && !textRegion.refinementTemplate) {
  5450. at = [];
  5451. for (i = 0; i < 2; i++) {
  5452. at.push({
  5453. x: readInt8(data, position),
  5454. y: readInt8(data, position + 1)
  5455. });
  5456. position += 2;
  5457. }
  5458. textRegion.refinementAt = at;
  5459. }
  5460. textRegion.numberOfSymbolInstances = readUint32(data, position);
  5461. position += 4;
  5462. args = [textRegion, header.referredTo, data, position, end];
  5463. break;
  5464. case 16:
  5465. const patternDictionary = {};
  5466. const patternDictionaryFlags = data[position++];
  5467. patternDictionary.mmr = !!(patternDictionaryFlags & 1);
  5468. patternDictionary.template = patternDictionaryFlags >> 1 & 3;
  5469. patternDictionary.patternWidth = data[position++];
  5470. patternDictionary.patternHeight = data[position++];
  5471. patternDictionary.maxPatternIndex = readUint32(data, position);
  5472. position += 4;
  5473. args = [patternDictionary, header.number, data, position, end];
  5474. break;
  5475. case 22:
  5476. case 23:
  5477. const halftoneRegion = {};
  5478. halftoneRegion.info = readRegionSegmentInformation(data, position);
  5479. position += RegionSegmentInformationFieldLength;
  5480. const halftoneRegionFlags = data[position++];
  5481. halftoneRegion.mmr = !!(halftoneRegionFlags & 1);
  5482. halftoneRegion.template = halftoneRegionFlags >> 1 & 3;
  5483. halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8);
  5484. halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7;
  5485. halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1;
  5486. halftoneRegion.gridWidth = readUint32(data, position);
  5487. position += 4;
  5488. halftoneRegion.gridHeight = readUint32(data, position);
  5489. position += 4;
  5490. halftoneRegion.gridOffsetX = readUint32(data, position) & 0xffffffff;
  5491. position += 4;
  5492. halftoneRegion.gridOffsetY = readUint32(data, position) & 0xffffffff;
  5493. position += 4;
  5494. halftoneRegion.gridVectorX = readUint16(data, position);
  5495. position += 2;
  5496. halftoneRegion.gridVectorY = readUint16(data, position);
  5497. position += 2;
  5498. args = [halftoneRegion, header.referredTo, data, position, end];
  5499. break;
  5500. case 38:
  5501. case 39:
  5502. const genericRegion = {};
  5503. genericRegion.info = readRegionSegmentInformation(data, position);
  5504. position += RegionSegmentInformationFieldLength;
  5505. const genericRegionSegmentFlags = data[position++];
  5506. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  5507. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  5508. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  5509. if (!genericRegion.mmr) {
  5510. atLength = genericRegion.template === 0 ? 4 : 1;
  5511. at = [];
  5512. for (i = 0; i < atLength; i++) {
  5513. at.push({
  5514. x: readInt8(data, position),
  5515. y: readInt8(data, position + 1)
  5516. });
  5517. position += 2;
  5518. }
  5519. genericRegion.at = at;
  5520. }
  5521. args = [genericRegion, data, position, end];
  5522. break;
  5523. case 48:
  5524. const pageInfo = {
  5525. width: readUint32(data, position),
  5526. height: readUint32(data, position + 4),
  5527. resolutionX: readUint32(data, position + 8),
  5528. resolutionY: readUint32(data, position + 12)
  5529. };
  5530. if (pageInfo.height === 0xffffffff) {
  5531. delete pageInfo.height;
  5532. }
  5533. const pageSegmentFlags = data[position + 16];
  5534. readUint16(data, position + 17);
  5535. pageInfo.lossless = !!(pageSegmentFlags & 1);
  5536. pageInfo.refinement = !!(pageSegmentFlags & 2);
  5537. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  5538. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  5539. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  5540. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  5541. args = [pageInfo];
  5542. break;
  5543. case 49:
  5544. break;
  5545. case 50:
  5546. break;
  5547. case 51:
  5548. break;
  5549. case 53:
  5550. args = [header.number, data, position, end];
  5551. break;
  5552. case 62:
  5553. break;
  5554. default:
  5555. throw new Jbig2Error(`segment type ${header.typeName}(${header.type}) is not implemented`);
  5556. }
  5557. const callbackName = "on" + header.typeName;
  5558. if (callbackName in visitor) {
  5559. visitor[callbackName].apply(visitor, args);
  5560. }
  5561. }
  5562. function processSegments(segments, visitor) {
  5563. for (let i = 0, ii = segments.length; i < ii; i++) {
  5564. processSegment(segments[i], visitor);
  5565. }
  5566. }
  5567. function parseJbig2Chunks(chunks) {
  5568. const visitor = new SimpleSegmentVisitor();
  5569. for (let i = 0, ii = chunks.length; i < ii; i++) {
  5570. const chunk = chunks[i];
  5571. const segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  5572. processSegments(segments, visitor);
  5573. }
  5574. return visitor.buffer;
  5575. }
  5576. function parseJbig2(data) {
  5577. throw new Error("Not implemented: parseJbig2");
  5578. }
  5579. class SimpleSegmentVisitor {
  5580. onPageInformation(info) {
  5581. this.currentPageInfo = info;
  5582. const rowSize = info.width + 7 >> 3;
  5583. const buffer = new Uint8ClampedArray(rowSize * info.height);
  5584. if (info.defaultPixelValue) {
  5585. buffer.fill(0xff);
  5586. }
  5587. this.buffer = buffer;
  5588. }
  5589. drawBitmap(regionInfo, bitmap) {
  5590. const pageInfo = this.currentPageInfo;
  5591. const width = regionInfo.width,
  5592. height = regionInfo.height;
  5593. const rowSize = pageInfo.width + 7 >> 3;
  5594. const combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  5595. const buffer = this.buffer;
  5596. const mask0 = 128 >> (regionInfo.x & 7);
  5597. let offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  5598. let i, j, mask, offset;
  5599. switch (combinationOperator) {
  5600. case 0:
  5601. for (i = 0; i < height; i++) {
  5602. mask = mask0;
  5603. offset = offset0;
  5604. for (j = 0; j < width; j++) {
  5605. if (bitmap[i][j]) {
  5606. buffer[offset] |= mask;
  5607. }
  5608. mask >>= 1;
  5609. if (!mask) {
  5610. mask = 128;
  5611. offset++;
  5612. }
  5613. }
  5614. offset0 += rowSize;
  5615. }
  5616. break;
  5617. case 2:
  5618. for (i = 0; i < height; i++) {
  5619. mask = mask0;
  5620. offset = offset0;
  5621. for (j = 0; j < width; j++) {
  5622. if (bitmap[i][j]) {
  5623. buffer[offset] ^= mask;
  5624. }
  5625. mask >>= 1;
  5626. if (!mask) {
  5627. mask = 128;
  5628. offset++;
  5629. }
  5630. }
  5631. offset0 += rowSize;
  5632. }
  5633. break;
  5634. default:
  5635. throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
  5636. }
  5637. }
  5638. onImmediateGenericRegion(region, data, start, end) {
  5639. const regionInfo = region.info;
  5640. const decodingContext = new DecodingContext(data, start, end);
  5641. const bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  5642. this.drawBitmap(regionInfo, bitmap);
  5643. }
  5644. onImmediateLosslessGenericRegion() {
  5645. this.onImmediateGenericRegion(...arguments);
  5646. }
  5647. onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  5648. let huffmanTables, huffmanInput;
  5649. if (dictionary.huffman) {
  5650. huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);
  5651. huffmanInput = new Reader(data, start, end);
  5652. }
  5653. let symbols = this.symbols;
  5654. if (!symbols) {
  5655. this.symbols = symbols = {};
  5656. }
  5657. const inputSymbols = [];
  5658. for (const referredSegment of referredSegments) {
  5659. const referredSymbols = symbols[referredSegment];
  5660. if (referredSymbols) {
  5661. inputSymbols.push(...referredSymbols);
  5662. }
  5663. }
  5664. const decodingContext = new DecodingContext(data, start, end);
  5665. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);
  5666. }
  5667. onImmediateTextRegion(region, referredSegments, data, start, end) {
  5668. const regionInfo = region.info;
  5669. let huffmanTables, huffmanInput;
  5670. const symbols = this.symbols;
  5671. const inputSymbols = [];
  5672. for (const referredSegment of referredSegments) {
  5673. const referredSymbols = symbols[referredSegment];
  5674. if (referredSymbols) {
  5675. inputSymbols.push(...referredSymbols);
  5676. }
  5677. }
  5678. const symbolCodeLength = log2(inputSymbols.length);
  5679. if (region.huffman) {
  5680. huffmanInput = new Reader(data, start, end);
  5681. huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);
  5682. }
  5683. const decodingContext = new DecodingContext(data, start, end);
  5684. const 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, region.logStripSize, huffmanInput);
  5685. this.drawBitmap(regionInfo, bitmap);
  5686. }
  5687. onImmediateLosslessTextRegion() {
  5688. this.onImmediateTextRegion(...arguments);
  5689. }
  5690. onPatternDictionary(dictionary, currentSegment, data, start, end) {
  5691. let patterns = this.patterns;
  5692. if (!patterns) {
  5693. this.patterns = patterns = {};
  5694. }
  5695. const decodingContext = new DecodingContext(data, start, end);
  5696. patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);
  5697. }
  5698. onImmediateHalftoneRegion(region, referredSegments, data, start, end) {
  5699. const patterns = this.patterns[referredSegments[0]];
  5700. const regionInfo = region.info;
  5701. const decodingContext = new DecodingContext(data, start, end);
  5702. const bitmap = decodeHalftoneRegion(region.mmr, patterns, region.template, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.enableSkip, region.combinationOperator, region.gridWidth, region.gridHeight, region.gridOffsetX, region.gridOffsetY, region.gridVectorX, region.gridVectorY, decodingContext);
  5703. this.drawBitmap(regionInfo, bitmap);
  5704. }
  5705. onImmediateLosslessHalftoneRegion() {
  5706. this.onImmediateHalftoneRegion(...arguments);
  5707. }
  5708. onTables(currentSegment, data, start, end) {
  5709. let customTables = this.customTables;
  5710. if (!customTables) {
  5711. this.customTables = customTables = {};
  5712. }
  5713. customTables[currentSegment] = decodeTablesSegment(data, start, end);
  5714. }
  5715. }
  5716. class HuffmanLine {
  5717. constructor(lineData) {
  5718. if (lineData.length === 2) {
  5719. this.isOOB = true;
  5720. this.rangeLow = 0;
  5721. this.prefixLength = lineData[0];
  5722. this.rangeLength = 0;
  5723. this.prefixCode = lineData[1];
  5724. this.isLowerRange = false;
  5725. } else {
  5726. this.isOOB = false;
  5727. this.rangeLow = lineData[0];
  5728. this.prefixLength = lineData[1];
  5729. this.rangeLength = lineData[2];
  5730. this.prefixCode = lineData[3];
  5731. this.isLowerRange = lineData[4] === "lower";
  5732. }
  5733. }
  5734. }
  5735. class HuffmanTreeNode {
  5736. constructor(line) {
  5737. this.children = [];
  5738. if (line) {
  5739. this.isLeaf = true;
  5740. this.rangeLength = line.rangeLength;
  5741. this.rangeLow = line.rangeLow;
  5742. this.isLowerRange = line.isLowerRange;
  5743. this.isOOB = line.isOOB;
  5744. } else {
  5745. this.isLeaf = false;
  5746. }
  5747. }
  5748. buildTree(line, shift) {
  5749. const bit = line.prefixCode >> shift & 1;
  5750. if (shift <= 0) {
  5751. this.children[bit] = new HuffmanTreeNode(line);
  5752. } else {
  5753. let node = this.children[bit];
  5754. if (!node) {
  5755. this.children[bit] = node = new HuffmanTreeNode(null);
  5756. }
  5757. node.buildTree(line, shift - 1);
  5758. }
  5759. }
  5760. decodeNode(reader) {
  5761. if (this.isLeaf) {
  5762. if (this.isOOB) {
  5763. return null;
  5764. }
  5765. const htOffset = reader.readBits(this.rangeLength);
  5766. return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);
  5767. }
  5768. const node = this.children[reader.readBit()];
  5769. if (!node) {
  5770. throw new Jbig2Error("invalid Huffman data");
  5771. }
  5772. return node.decodeNode(reader);
  5773. }
  5774. }
  5775. class HuffmanTable {
  5776. constructor(lines, prefixCodesDone) {
  5777. if (!prefixCodesDone) {
  5778. this.assignPrefixCodes(lines);
  5779. }
  5780. this.rootNode = new HuffmanTreeNode(null);
  5781. for (let i = 0, ii = lines.length; i < ii; i++) {
  5782. const line = lines[i];
  5783. if (line.prefixLength > 0) {
  5784. this.rootNode.buildTree(line, line.prefixLength - 1);
  5785. }
  5786. }
  5787. }
  5788. decode(reader) {
  5789. return this.rootNode.decodeNode(reader);
  5790. }
  5791. assignPrefixCodes(lines) {
  5792. const linesLength = lines.length;
  5793. let prefixLengthMax = 0;
  5794. for (let i = 0; i < linesLength; i++) {
  5795. prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);
  5796. }
  5797. const histogram = new Uint32Array(prefixLengthMax + 1);
  5798. for (let i = 0; i < linesLength; i++) {
  5799. histogram[lines[i].prefixLength]++;
  5800. }
  5801. let currentLength = 1,
  5802. firstCode = 0,
  5803. currentCode,
  5804. currentTemp,
  5805. line;
  5806. histogram[0] = 0;
  5807. while (currentLength <= prefixLengthMax) {
  5808. firstCode = firstCode + histogram[currentLength - 1] << 1;
  5809. currentCode = firstCode;
  5810. currentTemp = 0;
  5811. while (currentTemp < linesLength) {
  5812. line = lines[currentTemp];
  5813. if (line.prefixLength === currentLength) {
  5814. line.prefixCode = currentCode;
  5815. currentCode++;
  5816. }
  5817. currentTemp++;
  5818. }
  5819. currentLength++;
  5820. }
  5821. }
  5822. }
  5823. function decodeTablesSegment(data, start, end) {
  5824. const flags = data[start];
  5825. const lowestValue = readUint32(data, start + 1) & 0xffffffff;
  5826. const highestValue = readUint32(data, start + 5) & 0xffffffff;
  5827. const reader = new Reader(data, start + 9, end);
  5828. const prefixSizeBits = (flags >> 1 & 7) + 1;
  5829. const rangeSizeBits = (flags >> 4 & 7) + 1;
  5830. const lines = [];
  5831. let prefixLength,
  5832. rangeLength,
  5833. currentRangeLow = lowestValue;
  5834. do {
  5835. prefixLength = reader.readBits(prefixSizeBits);
  5836. rangeLength = reader.readBits(rangeSizeBits);
  5837. lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));
  5838. currentRangeLow += 1 << rangeLength;
  5839. } while (currentRangeLow < highestValue);
  5840. prefixLength = reader.readBits(prefixSizeBits);
  5841. lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, "lower"]));
  5842. prefixLength = reader.readBits(prefixSizeBits);
  5843. lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));
  5844. if (flags & 1) {
  5845. prefixLength = reader.readBits(prefixSizeBits);
  5846. lines.push(new HuffmanLine([prefixLength, 0]));
  5847. }
  5848. return new HuffmanTable(lines, false);
  5849. }
  5850. const standardTablesCache = {};
  5851. function getStandardTable(number) {
  5852. let table = standardTablesCache[number];
  5853. if (table) {
  5854. return table;
  5855. }
  5856. let lines;
  5857. switch (number) {
  5858. case 1:
  5859. lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];
  5860. break;
  5861. case 2:
  5862. lines = [[0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [75, 6, 32, 0x3e], [6, 0x3f]];
  5863. break;
  5864. case 3:
  5865. lines = [[-256, 8, 8, 0xfe], [0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xe], [11, 5, 6, 0x1e], [-257, 8, 32, 0xff, "lower"], [75, 7, 32, 0x7e], [6, 0x3e]];
  5866. break;
  5867. case 4:
  5868. lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [76, 5, 32, 0x1f]];
  5869. break;
  5870. case 5:
  5871. lines = [[-255, 7, 8, 0x7e], [1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xe], [12, 5, 6, 0x1e], [-256, 7, 32, 0x7f, "lower"], [76, 6, 32, 0x3e]];
  5872. break;
  5873. case 6:
  5874. lines = [[-2048, 5, 10, 0x1c], [-1024, 4, 9, 0x8], [-512, 4, 8, 0x9], [-256, 4, 7, 0xa], [-128, 5, 6, 0x1d], [-64, 5, 5, 0x1e], [-32, 4, 5, 0xb], [0, 2, 7, 0x0], [128, 3, 7, 0x2], [256, 3, 8, 0x3], [512, 4, 9, 0xc], [1024, 4, 10, 0xd], [-2049, 6, 32, 0x3e, "lower"], [2048, 6, 32, 0x3f]];
  5875. break;
  5876. case 7:
  5877. lines = [[-1024, 4, 9, 0x8], [-512, 3, 8, 0x0], [-256, 4, 7, 0x9], [-128, 5, 6, 0x1a], [-64, 5, 5, 0x1b], [-32, 4, 5, 0xa], [0, 4, 5, 0xb], [32, 5, 5, 0x1c], [64, 5, 6, 0x1d], [128, 4, 7, 0xc], [256, 3, 8, 0x1], [512, 3, 9, 0x2], [1024, 3, 10, 0x3], [-1025, 5, 32, 0x1e, "lower"], [2048, 5, 32, 0x1f]];
  5878. break;
  5879. case 8:
  5880. lines = [[-15, 8, 3, 0xfc], [-7, 9, 1, 0x1fc], [-5, 8, 1, 0xfd], [-3, 9, 0, 0x1fd], [-2, 7, 0, 0x7c], [-1, 4, 0, 0xa], [0, 2, 1, 0x0], [2, 5, 0, 0x1a], [3, 6, 0, 0x3a], [4, 3, 4, 0x4], [20, 6, 1, 0x3b], [22, 4, 4, 0xb], [38, 4, 5, 0xc], [70, 5, 6, 0x1b], [134, 5, 7, 0x1c], [262, 6, 7, 0x3c], [390, 7, 8, 0x7d], [646, 6, 10, 0x3d], [-16, 9, 32, 0x1fe, "lower"], [1670, 9, 32, 0x1ff], [2, 0x1]];
  5881. break;
  5882. case 9:
  5883. lines = [[-31, 8, 4, 0xfc], [-15, 9, 2, 0x1fc], [-11, 8, 2, 0xfd], [-7, 9, 1, 0x1fd], [-5, 7, 1, 0x7c], [-3, 4, 1, 0xa], [-1, 3, 1, 0x2], [1, 3, 1, 0x3], [3, 5, 1, 0x1a], [5, 6, 1, 0x3a], [7, 3, 5, 0x4], [39, 6, 2, 0x3b], [43, 4, 5, 0xb], [75, 4, 6, 0xc], [139, 5, 7, 0x1b], [267, 5, 8, 0x1c], [523, 6, 8, 0x3c], [779, 7, 9, 0x7d], [1291, 6, 11, 0x3d], [-32, 9, 32, 0x1fe, "lower"], [3339, 9, 32, 0x1ff], [2, 0x0]];
  5884. break;
  5885. case 10:
  5886. lines = [[-21, 7, 4, 0x7a], [-5, 8, 0, 0xfc], [-4, 7, 0, 0x7b], [-3, 5, 0, 0x18], [-2, 2, 2, 0x0], [2, 5, 0, 0x19], [3, 6, 0, 0x36], [4, 7, 0, 0x7c], [5, 8, 0, 0xfd], [6, 2, 6, 0x1], [70, 5, 5, 0x1a], [102, 6, 5, 0x37], [134, 6, 6, 0x38], [198, 6, 7, 0x39], [326, 6, 8, 0x3a], [582, 6, 9, 0x3b], [1094, 6, 10, 0x3c], [2118, 7, 11, 0x7d], [-22, 8, 32, 0xfe, "lower"], [4166, 8, 32, 0xff], [2, 0x2]];
  5887. break;
  5888. case 11:
  5889. lines = [[1, 1, 0, 0x0], [2, 2, 1, 0x2], [4, 4, 0, 0xc], [5, 4, 1, 0xd], [7, 5, 1, 0x1c], [9, 5, 2, 0x1d], [13, 6, 2, 0x3c], [17, 7, 2, 0x7a], [21, 7, 3, 0x7b], [29, 7, 4, 0x7c], [45, 7, 5, 0x7d], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]];
  5890. break;
  5891. case 12:
  5892. lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 1, 0x6], [5, 5, 0, 0x1c], [6, 5, 1, 0x1d], [8, 6, 1, 0x3c], [10, 7, 0, 0x7a], [11, 7, 1, 0x7b], [13, 7, 2, 0x7c], [17, 7, 3, 0x7d], [25, 7, 4, 0x7e], [41, 8, 5, 0xfe], [73, 8, 32, 0xff]];
  5893. break;
  5894. case 13:
  5895. lines = [[1, 1, 0, 0x0], [2, 3, 0, 0x4], [3, 4, 0, 0xc], [4, 5, 0, 0x1c], [5, 4, 1, 0xd], [7, 3, 3, 0x5], [15, 6, 1, 0x3a], [17, 6, 2, 0x3b], [21, 6, 3, 0x3c], [29, 6, 4, 0x3d], [45, 6, 5, 0x3e], [77, 7, 6, 0x7e], [141, 7, 32, 0x7f]];
  5896. break;
  5897. case 14:
  5898. lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];
  5899. break;
  5900. case 15:
  5901. lines = [[-24, 7, 4, 0x7c], [-8, 6, 2, 0x3c], [-4, 5, 1, 0x1c], [-2, 4, 0, 0xc], [-1, 3, 0, 0x4], [0, 1, 0, 0x0], [1, 3, 0, 0x5], [2, 4, 0, 0xd], [3, 5, 1, 0x1d], [5, 6, 2, 0x3d], [9, 7, 4, 0x7d], [-25, 7, 32, 0x7e, "lower"], [25, 7, 32, 0x7f]];
  5902. break;
  5903. default:
  5904. throw new Jbig2Error(`standard table B.${number} does not exist`);
  5905. }
  5906. for (let i = 0, ii = lines.length; i < ii; i++) {
  5907. lines[i] = new HuffmanLine(lines[i]);
  5908. }
  5909. table = new HuffmanTable(lines, true);
  5910. standardTablesCache[number] = table;
  5911. return table;
  5912. }
  5913. class Reader {
  5914. constructor(data, start, end) {
  5915. this.data = data;
  5916. this.start = start;
  5917. this.end = end;
  5918. this.position = start;
  5919. this.shift = -1;
  5920. this.currentByte = 0;
  5921. }
  5922. readBit() {
  5923. if (this.shift < 0) {
  5924. if (this.position >= this.end) {
  5925. throw new Jbig2Error("end of data while reading bit");
  5926. }
  5927. this.currentByte = this.data[this.position++];
  5928. this.shift = 7;
  5929. }
  5930. const bit = this.currentByte >> this.shift & 1;
  5931. this.shift--;
  5932. return bit;
  5933. }
  5934. readBits(numBits) {
  5935. let result = 0,
  5936. i;
  5937. for (i = numBits - 1; i >= 0; i--) {
  5938. result |= this.readBit() << i;
  5939. }
  5940. return result;
  5941. }
  5942. byteAlign() {
  5943. this.shift = -1;
  5944. }
  5945. next() {
  5946. if (this.position >= this.end) {
  5947. return -1;
  5948. }
  5949. return this.data[this.position++];
  5950. }
  5951. }
  5952. function getCustomHuffmanTable(index, referredTo, customTables) {
  5953. let currentIndex = 0;
  5954. for (let i = 0, ii = referredTo.length; i < ii; i++) {
  5955. const table = customTables[referredTo[i]];
  5956. if (table) {
  5957. if (index === currentIndex) {
  5958. return table;
  5959. }
  5960. currentIndex++;
  5961. }
  5962. }
  5963. throw new Jbig2Error("can't find custom Huffman table");
  5964. }
  5965. function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {
  5966. const codes = [];
  5967. for (let i = 0; i <= 34; i++) {
  5968. const codeLength = reader.readBits(4);
  5969. codes.push(new HuffmanLine([i, codeLength, 0, 0]));
  5970. }
  5971. const runCodesTable = new HuffmanTable(codes, false);
  5972. codes.length = 0;
  5973. for (let i = 0; i < numberOfSymbols;) {
  5974. const codeLength = runCodesTable.decode(reader);
  5975. if (codeLength >= 32) {
  5976. let repeatedLength, numberOfRepeats, j;
  5977. switch (codeLength) {
  5978. case 32:
  5979. if (i === 0) {
  5980. throw new Jbig2Error("no previous value in symbol ID table");
  5981. }
  5982. numberOfRepeats = reader.readBits(2) + 3;
  5983. repeatedLength = codes[i - 1].prefixLength;
  5984. break;
  5985. case 33:
  5986. numberOfRepeats = reader.readBits(3) + 3;
  5987. repeatedLength = 0;
  5988. break;
  5989. case 34:
  5990. numberOfRepeats = reader.readBits(7) + 11;
  5991. repeatedLength = 0;
  5992. break;
  5993. default:
  5994. throw new Jbig2Error("invalid code length in symbol ID table");
  5995. }
  5996. for (j = 0; j < numberOfRepeats; j++) {
  5997. codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));
  5998. i++;
  5999. }
  6000. } else {
  6001. codes.push(new HuffmanLine([i, codeLength, 0, 0]));
  6002. i++;
  6003. }
  6004. }
  6005. reader.byteAlign();
  6006. const symbolIDTable = new HuffmanTable(codes, false);
  6007. let customIndex = 0,
  6008. tableFirstS,
  6009. tableDeltaS,
  6010. tableDeltaT;
  6011. switch (textRegion.huffmanFS) {
  6012. case 0:
  6013. case 1:
  6014. tableFirstS = getStandardTable(textRegion.huffmanFS + 6);
  6015. break;
  6016. case 3:
  6017. tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6018. customIndex++;
  6019. break;
  6020. default:
  6021. throw new Jbig2Error("invalid Huffman FS selector");
  6022. }
  6023. switch (textRegion.huffmanDS) {
  6024. case 0:
  6025. case 1:
  6026. case 2:
  6027. tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);
  6028. break;
  6029. case 3:
  6030. tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6031. customIndex++;
  6032. break;
  6033. default:
  6034. throw new Jbig2Error("invalid Huffman DS selector");
  6035. }
  6036. switch (textRegion.huffmanDT) {
  6037. case 0:
  6038. case 1:
  6039. case 2:
  6040. tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);
  6041. break;
  6042. case 3:
  6043. tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6044. customIndex++;
  6045. break;
  6046. default:
  6047. throw new Jbig2Error("invalid Huffman DT selector");
  6048. }
  6049. if (textRegion.refinement) {
  6050. throw new Jbig2Error("refinement with Huffman is not supported");
  6051. }
  6052. return {
  6053. symbolIDTable,
  6054. tableFirstS,
  6055. tableDeltaS,
  6056. tableDeltaT
  6057. };
  6058. }
  6059. function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {
  6060. let customIndex = 0,
  6061. tableDeltaHeight,
  6062. tableDeltaWidth;
  6063. switch (dictionary.huffmanDHSelector) {
  6064. case 0:
  6065. case 1:
  6066. tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);
  6067. break;
  6068. case 3:
  6069. tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6070. customIndex++;
  6071. break;
  6072. default:
  6073. throw new Jbig2Error("invalid Huffman DH selector");
  6074. }
  6075. switch (dictionary.huffmanDWSelector) {
  6076. case 0:
  6077. case 1:
  6078. tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);
  6079. break;
  6080. case 3:
  6081. tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6082. customIndex++;
  6083. break;
  6084. default:
  6085. throw new Jbig2Error("invalid Huffman DW selector");
  6086. }
  6087. let tableBitmapSize, tableAggregateInstances;
  6088. if (dictionary.bitmapSizeSelector) {
  6089. tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6090. customIndex++;
  6091. } else {
  6092. tableBitmapSize = getStandardTable(1);
  6093. }
  6094. if (dictionary.aggregationInstancesSelector) {
  6095. tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);
  6096. } else {
  6097. tableAggregateInstances = getStandardTable(1);
  6098. }
  6099. return {
  6100. tableDeltaHeight,
  6101. tableDeltaWidth,
  6102. tableBitmapSize,
  6103. tableAggregateInstances
  6104. };
  6105. }
  6106. function readUncompressedBitmap(reader, width, height) {
  6107. const bitmap = [];
  6108. for (let y = 0; y < height; y++) {
  6109. const row = new Uint8Array(width);
  6110. bitmap.push(row);
  6111. for (let x = 0; x < width; x++) {
  6112. row[x] = reader.readBit();
  6113. }
  6114. reader.byteAlign();
  6115. }
  6116. return bitmap;
  6117. }
  6118. function decodeMMRBitmap(input, width, height, endOfBlock) {
  6119. const params = {
  6120. K: -1,
  6121. Columns: width,
  6122. Rows: height,
  6123. BlackIs1: true,
  6124. EndOfBlock: endOfBlock
  6125. };
  6126. const decoder = new CCITTFaxDecoder(input, params);
  6127. const bitmap = [];
  6128. let currentByte,
  6129. eof = false;
  6130. for (let y = 0; y < height; y++) {
  6131. const row = new Uint8Array(width);
  6132. bitmap.push(row);
  6133. let shift = -1;
  6134. for (let x = 0; x < width; x++) {
  6135. if (shift < 0) {
  6136. currentByte = decoder.readNextChar();
  6137. if (currentByte === -1) {
  6138. currentByte = 0;
  6139. eof = true;
  6140. }
  6141. shift = 7;
  6142. }
  6143. row[x] = currentByte >> shift & 1;
  6144. shift--;
  6145. }
  6146. }
  6147. if (endOfBlock && !eof) {
  6148. const lookForEOFLimit = 5;
  6149. for (let i = 0; i < lookForEOFLimit; i++) {
  6150. if (decoder.readNextChar() === -1) {
  6151. break;
  6152. }
  6153. }
  6154. }
  6155. return bitmap;
  6156. }
  6157. class Jbig2Image {
  6158. parseChunks(chunks) {
  6159. return parseJbig2Chunks(chunks);
  6160. }
  6161. parse(data) {
  6162. throw new Error("Not implemented: Jbig2Image.parse");
  6163. }
  6164. }
  6165. ;// CONCATENATED MODULE: ./src/core/jbig2_stream.js
  6166. class Jbig2Stream extends DecodeStream {
  6167. constructor(stream, maybeLength, params) {
  6168. super(maybeLength);
  6169. this.stream = stream;
  6170. this.dict = stream.dict;
  6171. this.maybeLength = maybeLength;
  6172. this.params = params;
  6173. }
  6174. get bytes() {
  6175. return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
  6176. }
  6177. ensureBuffer(requested) {}
  6178. readBlock() {
  6179. if (this.eof) {
  6180. return;
  6181. }
  6182. const jbig2Image = new Jbig2Image();
  6183. const chunks = [];
  6184. if (this.params instanceof Dict) {
  6185. const globalsStream = this.params.get("JBIG2Globals");
  6186. if (globalsStream instanceof BaseStream) {
  6187. const globals = globalsStream.getBytes();
  6188. chunks.push({
  6189. data: globals,
  6190. start: 0,
  6191. end: globals.length
  6192. });
  6193. }
  6194. }
  6195. chunks.push({
  6196. data: this.bytes,
  6197. start: 0,
  6198. end: this.bytes.length
  6199. });
  6200. const data = jbig2Image.parseChunks(chunks);
  6201. const dataLength = data.length;
  6202. for (let i = 0; i < dataLength; i++) {
  6203. data[i] ^= 0xff;
  6204. }
  6205. this.buffer = data;
  6206. this.bufferLength = dataLength;
  6207. this.eof = true;
  6208. }
  6209. }
  6210. ;// CONCATENATED MODULE: ./src/shared/image_utils.js
  6211. function convertToRGBA(params) {
  6212. switch (params.kind) {
  6213. case ImageKind.GRAYSCALE_1BPP:
  6214. return convertBlackAndWhiteToRGBA(params);
  6215. case ImageKind.RGB_24BPP:
  6216. return convertRGBToRGBA(params);
  6217. }
  6218. return null;
  6219. }
  6220. function convertBlackAndWhiteToRGBA({
  6221. src,
  6222. srcPos = 0,
  6223. dest,
  6224. width,
  6225. height,
  6226. nonBlackColor = 0xffffffff,
  6227. inverseDecode = false
  6228. }) {
  6229. const black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
  6230. const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
  6231. const widthInSource = width >> 3;
  6232. const widthRemainder = width & 7;
  6233. const srcLength = src.length;
  6234. dest = new Uint32Array(dest.buffer);
  6235. let destPos = 0;
  6236. for (let i = 0; i < height; i++) {
  6237. for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
  6238. const elem = srcPos < srcLength ? src[srcPos] : 255;
  6239. dest[destPos++] = elem & 0b10000000 ? oneMapping : zeroMapping;
  6240. dest[destPos++] = elem & 0b1000000 ? oneMapping : zeroMapping;
  6241. dest[destPos++] = elem & 0b100000 ? oneMapping : zeroMapping;
  6242. dest[destPos++] = elem & 0b10000 ? oneMapping : zeroMapping;
  6243. dest[destPos++] = elem & 0b1000 ? oneMapping : zeroMapping;
  6244. dest[destPos++] = elem & 0b100 ? oneMapping : zeroMapping;
  6245. dest[destPos++] = elem & 0b10 ? oneMapping : zeroMapping;
  6246. dest[destPos++] = elem & 0b1 ? oneMapping : zeroMapping;
  6247. }
  6248. if (widthRemainder === 0) {
  6249. continue;
  6250. }
  6251. const elem = srcPos < srcLength ? src[srcPos++] : 255;
  6252. for (let j = 0; j < widthRemainder; j++) {
  6253. dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
  6254. }
  6255. }
  6256. return {
  6257. srcPos,
  6258. destPos
  6259. };
  6260. }
  6261. function convertRGBToRGBA({
  6262. src,
  6263. srcPos = 0,
  6264. dest,
  6265. destPos = 0,
  6266. width,
  6267. height
  6268. }) {
  6269. let i = 0;
  6270. const len32 = src.length >> 2;
  6271. const src32 = new Uint32Array(src.buffer, srcPos, len32);
  6272. if (FeatureTest.isLittleEndian) {
  6273. for (; i < len32 - 2; i += 3, destPos += 4) {
  6274. const s1 = src32[i];
  6275. const s2 = src32[i + 1];
  6276. const s3 = src32[i + 2];
  6277. dest[destPos] = s1 | 0xff000000;
  6278. dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 0xff000000;
  6279. dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 0xff000000;
  6280. dest[destPos + 3] = s3 >>> 8 | 0xff000000;
  6281. }
  6282. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  6283. dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 0xff000000;
  6284. }
  6285. } else {
  6286. for (; i < len32 - 2; i += 3, destPos += 4) {
  6287. const s1 = src32[i];
  6288. const s2 = src32[i + 1];
  6289. const s3 = src32[i + 2];
  6290. dest[destPos] = s1 | 0xff;
  6291. dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 0xff;
  6292. dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 0xff;
  6293. dest[destPos + 3] = s3 << 8 | 0xff;
  6294. }
  6295. for (let j = i * 4, jj = src.length; j < jj; j += 3) {
  6296. dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 0xff;
  6297. }
  6298. }
  6299. return {
  6300. srcPos,
  6301. destPos
  6302. };
  6303. }
  6304. function grayToRGBA(src, dest) {
  6305. if (FeatureTest.isLittleEndian) {
  6306. for (let i = 0, ii = src.length; i < ii; i++) {
  6307. dest[i] = src[i] * 0x10101 | 0xff000000;
  6308. }
  6309. } else {
  6310. for (let i = 0, ii = src.length; i < ii; i++) {
  6311. dest[i] = src[i] * 0x1010100 | 0x000000ff;
  6312. }
  6313. }
  6314. }
  6315. ;// CONCATENATED MODULE: ./src/core/jpg.js
  6316. class JpegError extends BaseException {
  6317. constructor(msg) {
  6318. super(`JPEG error: ${msg}`, "JpegError");
  6319. }
  6320. }
  6321. class DNLMarkerError extends BaseException {
  6322. constructor(message, scanLines) {
  6323. super(message, "DNLMarkerError");
  6324. this.scanLines = scanLines;
  6325. }
  6326. }
  6327. class EOIMarkerError extends BaseException {
  6328. constructor(msg) {
  6329. super(msg, "EOIMarkerError");
  6330. }
  6331. }
  6332. const dctZigZag = new Uint8Array([0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63]);
  6333. const dctCos1 = 4017;
  6334. const dctSin1 = 799;
  6335. const dctCos3 = 3406;
  6336. const dctSin3 = 2276;
  6337. const dctCos6 = 1567;
  6338. const dctSin6 = 3784;
  6339. const dctSqrt2 = 5793;
  6340. const dctSqrt1d2 = 2896;
  6341. function buildHuffmanTable(codeLengths, values) {
  6342. let k = 0,
  6343. i,
  6344. j,
  6345. length = 16;
  6346. while (length > 0 && !codeLengths[length - 1]) {
  6347. length--;
  6348. }
  6349. const code = [{
  6350. children: [],
  6351. index: 0
  6352. }];
  6353. let p = code[0],
  6354. q;
  6355. for (i = 0; i < length; i++) {
  6356. for (j = 0; j < codeLengths[i]; j++) {
  6357. p = code.pop();
  6358. p.children[p.index] = values[k];
  6359. while (p.index > 0) {
  6360. p = code.pop();
  6361. }
  6362. p.index++;
  6363. code.push(p);
  6364. while (code.length <= i) {
  6365. code.push(q = {
  6366. children: [],
  6367. index: 0
  6368. });
  6369. p.children[p.index] = q.children;
  6370. p = q;
  6371. }
  6372. k++;
  6373. }
  6374. if (i + 1 < length) {
  6375. code.push(q = {
  6376. children: [],
  6377. index: 0
  6378. });
  6379. p.children[p.index] = q.children;
  6380. p = q;
  6381. }
  6382. }
  6383. return code[0].children;
  6384. }
  6385. function getBlockBufferOffset(component, row, col) {
  6386. return 64 * ((component.blocksPerLine + 1) * row + col);
  6387. }
  6388. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive, parseDNLMarker = false) {
  6389. const mcusPerLine = frame.mcusPerLine;
  6390. const progressive = frame.progressive;
  6391. const startOffset = offset;
  6392. let bitsData = 0,
  6393. bitsCount = 0;
  6394. function readBit() {
  6395. if (bitsCount > 0) {
  6396. bitsCount--;
  6397. return bitsData >> bitsCount & 1;
  6398. }
  6399. bitsData = data[offset++];
  6400. if (bitsData === 0xff) {
  6401. const nextByte = data[offset++];
  6402. if (nextByte) {
  6403. if (nextByte === 0xdc && parseDNLMarker) {
  6404. offset += 2;
  6405. const scanLines = readUint16(data, offset);
  6406. offset += 2;
  6407. if (scanLines > 0 && scanLines !== frame.scanLines) {
  6408. throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data", scanLines);
  6409. }
  6410. } else if (nextByte === 0xd9) {
  6411. if (parseDNLMarker) {
  6412. const maybeScanLines = blockRow * (frame.precision === 8 ? 8 : 0);
  6413. if (maybeScanLines > 0 && Math.round(frame.scanLines / maybeScanLines) >= 5) {
  6414. throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, " + "possibly caused by incorrect `scanLines` parameter", maybeScanLines);
  6415. }
  6416. }
  6417. throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data");
  6418. }
  6419. throw new JpegError(`unexpected marker ${(bitsData << 8 | nextByte).toString(16)}`);
  6420. }
  6421. }
  6422. bitsCount = 7;
  6423. return bitsData >>> 7;
  6424. }
  6425. function decodeHuffman(tree) {
  6426. let node = tree;
  6427. while (true) {
  6428. node = node[readBit()];
  6429. switch (typeof node) {
  6430. case "number":
  6431. return node;
  6432. case "object":
  6433. continue;
  6434. }
  6435. throw new JpegError("invalid huffman sequence");
  6436. }
  6437. }
  6438. function receive(length) {
  6439. let n = 0;
  6440. while (length > 0) {
  6441. n = n << 1 | readBit();
  6442. length--;
  6443. }
  6444. return n;
  6445. }
  6446. function receiveAndExtend(length) {
  6447. if (length === 1) {
  6448. return readBit() === 1 ? 1 : -1;
  6449. }
  6450. const n = receive(length);
  6451. if (n >= 1 << length - 1) {
  6452. return n;
  6453. }
  6454. return n + (-1 << length) + 1;
  6455. }
  6456. function decodeBaseline(component, blockOffset) {
  6457. const t = decodeHuffman(component.huffmanTableDC);
  6458. const diff = t === 0 ? 0 : receiveAndExtend(t);
  6459. component.blockData[blockOffset] = component.pred += diff;
  6460. let k = 1;
  6461. while (k < 64) {
  6462. const rs = decodeHuffman(component.huffmanTableAC);
  6463. const s = rs & 15,
  6464. r = rs >> 4;
  6465. if (s === 0) {
  6466. if (r < 15) {
  6467. break;
  6468. }
  6469. k += 16;
  6470. continue;
  6471. }
  6472. k += r;
  6473. const z = dctZigZag[k];
  6474. component.blockData[blockOffset + z] = receiveAndExtend(s);
  6475. k++;
  6476. }
  6477. }
  6478. function decodeDCFirst(component, blockOffset) {
  6479. const t = decodeHuffman(component.huffmanTableDC);
  6480. const diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  6481. component.blockData[blockOffset] = component.pred += diff;
  6482. }
  6483. function decodeDCSuccessive(component, blockOffset) {
  6484. component.blockData[blockOffset] |= readBit() << successive;
  6485. }
  6486. let eobrun = 0;
  6487. function decodeACFirst(component, blockOffset) {
  6488. if (eobrun > 0) {
  6489. eobrun--;
  6490. return;
  6491. }
  6492. let k = spectralStart;
  6493. const e = spectralEnd;
  6494. while (k <= e) {
  6495. const rs = decodeHuffman(component.huffmanTableAC);
  6496. const s = rs & 15,
  6497. r = rs >> 4;
  6498. if (s === 0) {
  6499. if (r < 15) {
  6500. eobrun = receive(r) + (1 << r) - 1;
  6501. break;
  6502. }
  6503. k += 16;
  6504. continue;
  6505. }
  6506. k += r;
  6507. const z = dctZigZag[k];
  6508. component.blockData[blockOffset + z] = receiveAndExtend(s) * (1 << successive);
  6509. k++;
  6510. }
  6511. }
  6512. let successiveACState = 0,
  6513. successiveACNextValue;
  6514. function decodeACSuccessive(component, blockOffset) {
  6515. let k = spectralStart;
  6516. const e = spectralEnd;
  6517. let r = 0;
  6518. let s;
  6519. let rs;
  6520. while (k <= e) {
  6521. const offsetZ = blockOffset + dctZigZag[k];
  6522. const sign = component.blockData[offsetZ] < 0 ? -1 : 1;
  6523. switch (successiveACState) {
  6524. case 0:
  6525. rs = decodeHuffman(component.huffmanTableAC);
  6526. s = rs & 15;
  6527. r = rs >> 4;
  6528. if (s === 0) {
  6529. if (r < 15) {
  6530. eobrun = receive(r) + (1 << r);
  6531. successiveACState = 4;
  6532. } else {
  6533. r = 16;
  6534. successiveACState = 1;
  6535. }
  6536. } else {
  6537. if (s !== 1) {
  6538. throw new JpegError("invalid ACn encoding");
  6539. }
  6540. successiveACNextValue = receiveAndExtend(s);
  6541. successiveACState = r ? 2 : 3;
  6542. }
  6543. continue;
  6544. case 1:
  6545. case 2:
  6546. if (component.blockData[offsetZ]) {
  6547. component.blockData[offsetZ] += sign * (readBit() << successive);
  6548. } else {
  6549. r--;
  6550. if (r === 0) {
  6551. successiveACState = successiveACState === 2 ? 3 : 0;
  6552. }
  6553. }
  6554. break;
  6555. case 3:
  6556. if (component.blockData[offsetZ]) {
  6557. component.blockData[offsetZ] += sign * (readBit() << successive);
  6558. } else {
  6559. component.blockData[offsetZ] = successiveACNextValue << successive;
  6560. successiveACState = 0;
  6561. }
  6562. break;
  6563. case 4:
  6564. if (component.blockData[offsetZ]) {
  6565. component.blockData[offsetZ] += sign * (readBit() << successive);
  6566. }
  6567. break;
  6568. }
  6569. k++;
  6570. }
  6571. if (successiveACState === 4) {
  6572. eobrun--;
  6573. if (eobrun === 0) {
  6574. successiveACState = 0;
  6575. }
  6576. }
  6577. }
  6578. let blockRow = 0;
  6579. function decodeMcu(component, decode, mcu, row, col) {
  6580. const mcuRow = mcu / mcusPerLine | 0;
  6581. const mcuCol = mcu % mcusPerLine;
  6582. blockRow = mcuRow * component.v + row;
  6583. const blockCol = mcuCol * component.h + col;
  6584. const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
  6585. decode(component, blockOffset);
  6586. }
  6587. function decodeBlock(component, decode, mcu) {
  6588. blockRow = mcu / component.blocksPerLine | 0;
  6589. const blockCol = mcu % component.blocksPerLine;
  6590. const blockOffset = getBlockBufferOffset(component, blockRow, blockCol);
  6591. decode(component, blockOffset);
  6592. }
  6593. const componentsLength = components.length;
  6594. let component, i, j, k, n;
  6595. let decodeFn;
  6596. if (progressive) {
  6597. if (spectralStart === 0) {
  6598. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  6599. } else {
  6600. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  6601. }
  6602. } else {
  6603. decodeFn = decodeBaseline;
  6604. }
  6605. let mcu = 0,
  6606. fileMarker;
  6607. const mcuExpected = componentsLength === 1 ? components[0].blocksPerLine * components[0].blocksPerColumn : mcusPerLine * frame.mcusPerColumn;
  6608. let h, v;
  6609. while (mcu <= mcuExpected) {
  6610. const mcuToRead = resetInterval ? Math.min(mcuExpected - mcu, resetInterval) : mcuExpected;
  6611. if (mcuToRead > 0) {
  6612. for (i = 0; i < componentsLength; i++) {
  6613. components[i].pred = 0;
  6614. }
  6615. eobrun = 0;
  6616. if (componentsLength === 1) {
  6617. component = components[0];
  6618. for (n = 0; n < mcuToRead; n++) {
  6619. decodeBlock(component, decodeFn, mcu);
  6620. mcu++;
  6621. }
  6622. } else {
  6623. for (n = 0; n < mcuToRead; n++) {
  6624. for (i = 0; i < componentsLength; i++) {
  6625. component = components[i];
  6626. h = component.h;
  6627. v = component.v;
  6628. for (j = 0; j < v; j++) {
  6629. for (k = 0; k < h; k++) {
  6630. decodeMcu(component, decodeFn, mcu, j, k);
  6631. }
  6632. }
  6633. }
  6634. mcu++;
  6635. }
  6636. }
  6637. }
  6638. bitsCount = 0;
  6639. fileMarker = findNextFileMarker(data, offset);
  6640. if (!fileMarker) {
  6641. break;
  6642. }
  6643. if (fileMarker.invalid) {
  6644. const partialMsg = mcuToRead > 0 ? "unexpected" : "excessive";
  6645. warn(`decodeScan - ${partialMsg} MCU data, current marker is: ${fileMarker.invalid}`);
  6646. offset = fileMarker.offset;
  6647. }
  6648. if (fileMarker.marker >= 0xffd0 && fileMarker.marker <= 0xffd7) {
  6649. offset += 2;
  6650. } else {
  6651. break;
  6652. }
  6653. }
  6654. return offset - startOffset;
  6655. }
  6656. function quantizeAndInverse(component, blockBufferOffset, p) {
  6657. const qt = component.quantizationTable,
  6658. blockData = component.blockData;
  6659. let v0, v1, v2, v3, v4, v5, v6, v7;
  6660. let p0, p1, p2, p3, p4, p5, p6, p7;
  6661. let t;
  6662. if (!qt) {
  6663. throw new JpegError("missing required Quantization Table.");
  6664. }
  6665. for (let row = 0; row < 64; row += 8) {
  6666. p0 = blockData[blockBufferOffset + row];
  6667. p1 = blockData[blockBufferOffset + row + 1];
  6668. p2 = blockData[blockBufferOffset + row + 2];
  6669. p3 = blockData[blockBufferOffset + row + 3];
  6670. p4 = blockData[blockBufferOffset + row + 4];
  6671. p5 = blockData[blockBufferOffset + row + 5];
  6672. p6 = blockData[blockBufferOffset + row + 6];
  6673. p7 = blockData[blockBufferOffset + row + 7];
  6674. p0 *= qt[row];
  6675. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6676. t = dctSqrt2 * p0 + 512 >> 10;
  6677. p[row] = t;
  6678. p[row + 1] = t;
  6679. p[row + 2] = t;
  6680. p[row + 3] = t;
  6681. p[row + 4] = t;
  6682. p[row + 5] = t;
  6683. p[row + 6] = t;
  6684. p[row + 7] = t;
  6685. continue;
  6686. }
  6687. p1 *= qt[row + 1];
  6688. p2 *= qt[row + 2];
  6689. p3 *= qt[row + 3];
  6690. p4 *= qt[row + 4];
  6691. p5 *= qt[row + 5];
  6692. p6 *= qt[row + 6];
  6693. p7 *= qt[row + 7];
  6694. v0 = dctSqrt2 * p0 + 128 >> 8;
  6695. v1 = dctSqrt2 * p4 + 128 >> 8;
  6696. v2 = p2;
  6697. v3 = p6;
  6698. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  6699. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  6700. v5 = p3 << 4;
  6701. v6 = p5 << 4;
  6702. v0 = v0 + v1 + 1 >> 1;
  6703. v1 = v0 - v1;
  6704. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  6705. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  6706. v3 = t;
  6707. v4 = v4 + v6 + 1 >> 1;
  6708. v6 = v4 - v6;
  6709. v7 = v7 + v5 + 1 >> 1;
  6710. v5 = v7 - v5;
  6711. v0 = v0 + v3 + 1 >> 1;
  6712. v3 = v0 - v3;
  6713. v1 = v1 + v2 + 1 >> 1;
  6714. v2 = v1 - v2;
  6715. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  6716. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  6717. v7 = t;
  6718. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  6719. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  6720. v6 = t;
  6721. p[row] = v0 + v7;
  6722. p[row + 7] = v0 - v7;
  6723. p[row + 1] = v1 + v6;
  6724. p[row + 6] = v1 - v6;
  6725. p[row + 2] = v2 + v5;
  6726. p[row + 5] = v2 - v5;
  6727. p[row + 3] = v3 + v4;
  6728. p[row + 4] = v3 - v4;
  6729. }
  6730. for (let col = 0; col < 8; ++col) {
  6731. p0 = p[col];
  6732. p1 = p[col + 8];
  6733. p2 = p[col + 16];
  6734. p3 = p[col + 24];
  6735. p4 = p[col + 32];
  6736. p5 = p[col + 40];
  6737. p6 = p[col + 48];
  6738. p7 = p[col + 56];
  6739. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6740. t = dctSqrt2 * p0 + 8192 >> 14;
  6741. if (t < -2040) {
  6742. t = 0;
  6743. } else if (t >= 2024) {
  6744. t = 255;
  6745. } else {
  6746. t = t + 2056 >> 4;
  6747. }
  6748. blockData[blockBufferOffset + col] = t;
  6749. blockData[blockBufferOffset + col + 8] = t;
  6750. blockData[blockBufferOffset + col + 16] = t;
  6751. blockData[blockBufferOffset + col + 24] = t;
  6752. blockData[blockBufferOffset + col + 32] = t;
  6753. blockData[blockBufferOffset + col + 40] = t;
  6754. blockData[blockBufferOffset + col + 48] = t;
  6755. blockData[blockBufferOffset + col + 56] = t;
  6756. continue;
  6757. }
  6758. v0 = dctSqrt2 * p0 + 2048 >> 12;
  6759. v1 = dctSqrt2 * p4 + 2048 >> 12;
  6760. v2 = p2;
  6761. v3 = p6;
  6762. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  6763. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  6764. v5 = p3;
  6765. v6 = p5;
  6766. v0 = (v0 + v1 + 1 >> 1) + 4112;
  6767. v1 = v0 - v1;
  6768. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  6769. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  6770. v3 = t;
  6771. v4 = v4 + v6 + 1 >> 1;
  6772. v6 = v4 - v6;
  6773. v7 = v7 + v5 + 1 >> 1;
  6774. v5 = v7 - v5;
  6775. v0 = v0 + v3 + 1 >> 1;
  6776. v3 = v0 - v3;
  6777. v1 = v1 + v2 + 1 >> 1;
  6778. v2 = v1 - v2;
  6779. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  6780. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  6781. v7 = t;
  6782. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  6783. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  6784. v6 = t;
  6785. p0 = v0 + v7;
  6786. p7 = v0 - v7;
  6787. p1 = v1 + v6;
  6788. p6 = v1 - v6;
  6789. p2 = v2 + v5;
  6790. p5 = v2 - v5;
  6791. p3 = v3 + v4;
  6792. p4 = v3 - v4;
  6793. if (p0 < 16) {
  6794. p0 = 0;
  6795. } else if (p0 >= 4080) {
  6796. p0 = 255;
  6797. } else {
  6798. p0 >>= 4;
  6799. }
  6800. if (p1 < 16) {
  6801. p1 = 0;
  6802. } else if (p1 >= 4080) {
  6803. p1 = 255;
  6804. } else {
  6805. p1 >>= 4;
  6806. }
  6807. if (p2 < 16) {
  6808. p2 = 0;
  6809. } else if (p2 >= 4080) {
  6810. p2 = 255;
  6811. } else {
  6812. p2 >>= 4;
  6813. }
  6814. if (p3 < 16) {
  6815. p3 = 0;
  6816. } else if (p3 >= 4080) {
  6817. p3 = 255;
  6818. } else {
  6819. p3 >>= 4;
  6820. }
  6821. if (p4 < 16) {
  6822. p4 = 0;
  6823. } else if (p4 >= 4080) {
  6824. p4 = 255;
  6825. } else {
  6826. p4 >>= 4;
  6827. }
  6828. if (p5 < 16) {
  6829. p5 = 0;
  6830. } else if (p5 >= 4080) {
  6831. p5 = 255;
  6832. } else {
  6833. p5 >>= 4;
  6834. }
  6835. if (p6 < 16) {
  6836. p6 = 0;
  6837. } else if (p6 >= 4080) {
  6838. p6 = 255;
  6839. } else {
  6840. p6 >>= 4;
  6841. }
  6842. if (p7 < 16) {
  6843. p7 = 0;
  6844. } else if (p7 >= 4080) {
  6845. p7 = 255;
  6846. } else {
  6847. p7 >>= 4;
  6848. }
  6849. blockData[blockBufferOffset + col] = p0;
  6850. blockData[blockBufferOffset + col + 8] = p1;
  6851. blockData[blockBufferOffset + col + 16] = p2;
  6852. blockData[blockBufferOffset + col + 24] = p3;
  6853. blockData[blockBufferOffset + col + 32] = p4;
  6854. blockData[blockBufferOffset + col + 40] = p5;
  6855. blockData[blockBufferOffset + col + 48] = p6;
  6856. blockData[blockBufferOffset + col + 56] = p7;
  6857. }
  6858. }
  6859. function buildComponentData(frame, component) {
  6860. const blocksPerLine = component.blocksPerLine;
  6861. const blocksPerColumn = component.blocksPerColumn;
  6862. const computationBuffer = new Int16Array(64);
  6863. for (let blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  6864. for (let blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  6865. const offset = getBlockBufferOffset(component, blockRow, blockCol);
  6866. quantizeAndInverse(component, offset, computationBuffer);
  6867. }
  6868. }
  6869. return component.blockData;
  6870. }
  6871. function findNextFileMarker(data, currentPos, startPos = currentPos) {
  6872. const maxPos = data.length - 1;
  6873. let newPos = startPos < currentPos ? startPos : currentPos;
  6874. if (currentPos >= maxPos) {
  6875. return null;
  6876. }
  6877. const currentMarker = readUint16(data, currentPos);
  6878. if (currentMarker >= 0xffc0 && currentMarker <= 0xfffe) {
  6879. return {
  6880. invalid: null,
  6881. marker: currentMarker,
  6882. offset: currentPos
  6883. };
  6884. }
  6885. let newMarker = readUint16(data, newPos);
  6886. while (!(newMarker >= 0xffc0 && newMarker <= 0xfffe)) {
  6887. if (++newPos >= maxPos) {
  6888. return null;
  6889. }
  6890. newMarker = readUint16(data, newPos);
  6891. }
  6892. return {
  6893. invalid: currentMarker.toString(16),
  6894. marker: newMarker,
  6895. offset: newPos
  6896. };
  6897. }
  6898. class JpegImage {
  6899. constructor({
  6900. decodeTransform = null,
  6901. colorTransform = -1
  6902. } = {}) {
  6903. this._decodeTransform = decodeTransform;
  6904. this._colorTransform = colorTransform;
  6905. }
  6906. parse(data, {
  6907. dnlScanLines = null
  6908. } = {}) {
  6909. function readDataBlock() {
  6910. const length = readUint16(data, offset);
  6911. offset += 2;
  6912. let endOffset = offset + length - 2;
  6913. const fileMarker = findNextFileMarker(data, endOffset, offset);
  6914. if (fileMarker?.invalid) {
  6915. warn("readDataBlock - incorrect length, current marker is: " + fileMarker.invalid);
  6916. endOffset = fileMarker.offset;
  6917. }
  6918. const array = data.subarray(offset, endOffset);
  6919. offset += array.length;
  6920. return array;
  6921. }
  6922. function prepareComponents(frame) {
  6923. const mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  6924. const mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  6925. for (const component of frame.components) {
  6926. const blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  6927. const blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  6928. const blocksPerLineForMcu = mcusPerLine * component.h;
  6929. const blocksPerColumnForMcu = mcusPerColumn * component.v;
  6930. const blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  6931. component.blockData = new Int16Array(blocksBufferSize);
  6932. component.blocksPerLine = blocksPerLine;
  6933. component.blocksPerColumn = blocksPerColumn;
  6934. }
  6935. frame.mcusPerLine = mcusPerLine;
  6936. frame.mcusPerColumn = mcusPerColumn;
  6937. }
  6938. let offset = 0;
  6939. let jfif = null;
  6940. let adobe = null;
  6941. let frame, resetInterval;
  6942. let numSOSMarkers = 0;
  6943. const quantizationTables = [];
  6944. const huffmanTablesAC = [],
  6945. huffmanTablesDC = [];
  6946. let fileMarker = readUint16(data, offset);
  6947. offset += 2;
  6948. if (fileMarker !== 0xffd8) {
  6949. throw new JpegError("SOI not found");
  6950. }
  6951. fileMarker = readUint16(data, offset);
  6952. offset += 2;
  6953. markerLoop: while (fileMarker !== 0xffd9) {
  6954. let i, j, l;
  6955. switch (fileMarker) {
  6956. case 0xffe0:
  6957. case 0xffe1:
  6958. case 0xffe2:
  6959. case 0xffe3:
  6960. case 0xffe4:
  6961. case 0xffe5:
  6962. case 0xffe6:
  6963. case 0xffe7:
  6964. case 0xffe8:
  6965. case 0xffe9:
  6966. case 0xffea:
  6967. case 0xffeb:
  6968. case 0xffec:
  6969. case 0xffed:
  6970. case 0xffee:
  6971. case 0xffef:
  6972. case 0xfffe:
  6973. const appData = readDataBlock();
  6974. if (fileMarker === 0xffe0) {
  6975. if (appData[0] === 0x4a && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  6976. jfif = {
  6977. version: {
  6978. major: appData[5],
  6979. minor: appData[6]
  6980. },
  6981. densityUnits: appData[7],
  6982. xDensity: appData[8] << 8 | appData[9],
  6983. yDensity: appData[10] << 8 | appData[11],
  6984. thumbWidth: appData[12],
  6985. thumbHeight: appData[13],
  6986. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  6987. };
  6988. }
  6989. }
  6990. if (fileMarker === 0xffee) {
  6991. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6f && appData[3] === 0x62 && appData[4] === 0x65) {
  6992. adobe = {
  6993. version: appData[5] << 8 | appData[6],
  6994. flags0: appData[7] << 8 | appData[8],
  6995. flags1: appData[9] << 8 | appData[10],
  6996. transformCode: appData[11]
  6997. };
  6998. }
  6999. }
  7000. break;
  7001. case 0xffdb:
  7002. const quantizationTablesLength = readUint16(data, offset);
  7003. offset += 2;
  7004. const quantizationTablesEnd = quantizationTablesLength + offset - 2;
  7005. let z;
  7006. while (offset < quantizationTablesEnd) {
  7007. const quantizationTableSpec = data[offset++];
  7008. const tableData = new Uint16Array(64);
  7009. if (quantizationTableSpec >> 4 === 0) {
  7010. for (j = 0; j < 64; j++) {
  7011. z = dctZigZag[j];
  7012. tableData[z] = data[offset++];
  7013. }
  7014. } else if (quantizationTableSpec >> 4 === 1) {
  7015. for (j = 0; j < 64; j++) {
  7016. z = dctZigZag[j];
  7017. tableData[z] = readUint16(data, offset);
  7018. offset += 2;
  7019. }
  7020. } else {
  7021. throw new JpegError("DQT - invalid table spec");
  7022. }
  7023. quantizationTables[quantizationTableSpec & 15] = tableData;
  7024. }
  7025. break;
  7026. case 0xffc0:
  7027. case 0xffc1:
  7028. case 0xffc2:
  7029. if (frame) {
  7030. throw new JpegError("Only single frame JPEGs supported");
  7031. }
  7032. offset += 2;
  7033. frame = {};
  7034. frame.extended = fileMarker === 0xffc1;
  7035. frame.progressive = fileMarker === 0xffc2;
  7036. frame.precision = data[offset++];
  7037. const sofScanLines = readUint16(data, offset);
  7038. offset += 2;
  7039. frame.scanLines = dnlScanLines || sofScanLines;
  7040. frame.samplesPerLine = readUint16(data, offset);
  7041. offset += 2;
  7042. frame.components = [];
  7043. frame.componentIds = {};
  7044. const componentsCount = data[offset++];
  7045. let maxH = 0,
  7046. maxV = 0;
  7047. for (i = 0; i < componentsCount; i++) {
  7048. const componentId = data[offset];
  7049. const h = data[offset + 1] >> 4;
  7050. const v = data[offset + 1] & 15;
  7051. if (maxH < h) {
  7052. maxH = h;
  7053. }
  7054. if (maxV < v) {
  7055. maxV = v;
  7056. }
  7057. const qId = data[offset + 2];
  7058. l = frame.components.push({
  7059. h,
  7060. v,
  7061. quantizationId: qId,
  7062. quantizationTable: null
  7063. });
  7064. frame.componentIds[componentId] = l - 1;
  7065. offset += 3;
  7066. }
  7067. frame.maxH = maxH;
  7068. frame.maxV = maxV;
  7069. prepareComponents(frame);
  7070. break;
  7071. case 0xffc4:
  7072. const huffmanLength = readUint16(data, offset);
  7073. offset += 2;
  7074. for (i = 2; i < huffmanLength;) {
  7075. const huffmanTableSpec = data[offset++];
  7076. const codeLengths = new Uint8Array(16);
  7077. let codeLengthSum = 0;
  7078. for (j = 0; j < 16; j++, offset++) {
  7079. codeLengthSum += codeLengths[j] = data[offset];
  7080. }
  7081. const huffmanValues = new Uint8Array(codeLengthSum);
  7082. for (j = 0; j < codeLengthSum; j++, offset++) {
  7083. huffmanValues[j] = data[offset];
  7084. }
  7085. i += 17 + codeLengthSum;
  7086. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  7087. }
  7088. break;
  7089. case 0xffdd:
  7090. offset += 2;
  7091. resetInterval = readUint16(data, offset);
  7092. offset += 2;
  7093. break;
  7094. case 0xffda:
  7095. const parseDNLMarker = ++numSOSMarkers === 1 && !dnlScanLines;
  7096. offset += 2;
  7097. const selectorsCount = data[offset++],
  7098. components = [];
  7099. for (i = 0; i < selectorsCount; i++) {
  7100. const index = data[offset++];
  7101. const componentIndex = frame.componentIds[index];
  7102. const component = frame.components[componentIndex];
  7103. component.index = index;
  7104. const tableSpec = data[offset++];
  7105. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  7106. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  7107. components.push(component);
  7108. }
  7109. const spectralStart = data[offset++],
  7110. spectralEnd = data[offset++],
  7111. successiveApproximation = data[offset++];
  7112. try {
  7113. const processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15, parseDNLMarker);
  7114. offset += processed;
  7115. } catch (ex) {
  7116. if (ex instanceof DNLMarkerError) {
  7117. warn(`${ex.message} -- attempting to re-parse the JPEG image.`);
  7118. return this.parse(data, {
  7119. dnlScanLines: ex.scanLines
  7120. });
  7121. } else if (ex instanceof EOIMarkerError) {
  7122. warn(`${ex.message} -- ignoring the rest of the image data.`);
  7123. break markerLoop;
  7124. }
  7125. throw ex;
  7126. }
  7127. break;
  7128. case 0xffdc:
  7129. offset += 4;
  7130. break;
  7131. case 0xffff:
  7132. if (data[offset] !== 0xff) {
  7133. offset--;
  7134. }
  7135. break;
  7136. default:
  7137. const nextFileMarker = findNextFileMarker(data, offset - 2, offset - 3);
  7138. if (nextFileMarker?.invalid) {
  7139. warn("JpegImage.parse - unexpected data, current marker is: " + nextFileMarker.invalid);
  7140. offset = nextFileMarker.offset;
  7141. break;
  7142. }
  7143. if (!nextFileMarker || offset >= data.length - 1) {
  7144. warn("JpegImage.parse - reached the end of the image data " + "without finding an EOI marker (0xFFD9).");
  7145. break markerLoop;
  7146. }
  7147. throw new JpegError("JpegImage.parse - unknown marker: " + fileMarker.toString(16));
  7148. }
  7149. fileMarker = readUint16(data, offset);
  7150. offset += 2;
  7151. }
  7152. if (!frame) {
  7153. throw new JpegError("JpegImage.parse - no frame data found.");
  7154. }
  7155. this.width = frame.samplesPerLine;
  7156. this.height = frame.scanLines;
  7157. this.jfif = jfif;
  7158. this.adobe = adobe;
  7159. this.components = [];
  7160. for (const component of frame.components) {
  7161. const quantizationTable = quantizationTables[component.quantizationId];
  7162. if (quantizationTable) {
  7163. component.quantizationTable = quantizationTable;
  7164. }
  7165. this.components.push({
  7166. index: component.index,
  7167. output: buildComponentData(frame, component),
  7168. scaleX: component.h / frame.maxH,
  7169. scaleY: component.v / frame.maxV,
  7170. blocksPerLine: component.blocksPerLine,
  7171. blocksPerColumn: component.blocksPerColumn
  7172. });
  7173. }
  7174. this.numComponents = this.components.length;
  7175. return undefined;
  7176. }
  7177. _getLinearizedBlockData(width, height, isSourcePDF = false) {
  7178. const scaleX = this.width / width,
  7179. scaleY = this.height / height;
  7180. let component, componentScaleX, componentScaleY, blocksPerScanline;
  7181. let x, y, i, j, k;
  7182. let index;
  7183. let offset = 0;
  7184. let output;
  7185. const numComponents = this.components.length;
  7186. const dataLength = width * height * numComponents;
  7187. const data = new Uint8ClampedArray(dataLength);
  7188. const xScaleBlockOffset = new Uint32Array(width);
  7189. const mask3LSB = 0xfffffff8;
  7190. let lastComponentScaleX;
  7191. for (i = 0; i < numComponents; i++) {
  7192. component = this.components[i];
  7193. componentScaleX = component.scaleX * scaleX;
  7194. componentScaleY = component.scaleY * scaleY;
  7195. offset = i;
  7196. output = component.output;
  7197. blocksPerScanline = component.blocksPerLine + 1 << 3;
  7198. if (componentScaleX !== lastComponentScaleX) {
  7199. for (x = 0; x < width; x++) {
  7200. j = 0 | x * componentScaleX;
  7201. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  7202. }
  7203. lastComponentScaleX = componentScaleX;
  7204. }
  7205. for (y = 0; y < height; y++) {
  7206. j = 0 | y * componentScaleY;
  7207. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  7208. for (x = 0; x < width; x++) {
  7209. data[offset] = output[index + xScaleBlockOffset[x]];
  7210. offset += numComponents;
  7211. }
  7212. }
  7213. }
  7214. let transform = this._decodeTransform;
  7215. if (!isSourcePDF && numComponents === 4 && !transform) {
  7216. transform = new Int32Array([-256, 255, -256, 255, -256, 255, -256, 255]);
  7217. }
  7218. if (transform) {
  7219. for (i = 0; i < dataLength;) {
  7220. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  7221. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  7222. }
  7223. }
  7224. }
  7225. return data;
  7226. }
  7227. get _isColorConversionNeeded() {
  7228. if (this.adobe) {
  7229. return !!this.adobe.transformCode;
  7230. }
  7231. if (this.numComponents === 3) {
  7232. if (this._colorTransform === 0) {
  7233. return false;
  7234. } else if (this.components[0].index === 0x52 && this.components[1].index === 0x47 && this.components[2].index === 0x42) {
  7235. return false;
  7236. }
  7237. return true;
  7238. }
  7239. if (this._colorTransform === 1) {
  7240. return true;
  7241. }
  7242. return false;
  7243. }
  7244. _convertYccToRgb(data) {
  7245. let Y, Cb, Cr;
  7246. for (let i = 0, length = data.length; i < length; i += 3) {
  7247. Y = data[i];
  7248. Cb = data[i + 1];
  7249. Cr = data[i + 2];
  7250. data[i] = Y - 179.456 + 1.402 * Cr;
  7251. data[i + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
  7252. data[i + 2] = Y - 226.816 + 1.772 * Cb;
  7253. }
  7254. return data;
  7255. }
  7256. _convertYccToRgba(data, out) {
  7257. for (let i = 0, j = 0, length = data.length; i < length; i += 3, j += 4) {
  7258. const Y = data[i];
  7259. const Cb = data[i + 1];
  7260. const Cr = data[i + 2];
  7261. out[j] = Y - 179.456 + 1.402 * Cr;
  7262. out[j + 1] = Y + 135.459 - 0.344 * Cb - 0.714 * Cr;
  7263. out[j + 2] = Y - 226.816 + 1.772 * Cb;
  7264. out[j + 3] = 255;
  7265. }
  7266. return out;
  7267. }
  7268. _convertYcckToRgb(data) {
  7269. let Y, Cb, Cr, k;
  7270. let offset = 0;
  7271. for (let i = 0, length = data.length; i < length; i += 4) {
  7272. Y = data[i];
  7273. Cb = data[i + 1];
  7274. Cr = data[i + 2];
  7275. k = data[i + 3];
  7276. data[offset++] = -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);
  7277. data[offset++] = 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);
  7278. data[offset++] = -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);
  7279. }
  7280. return data.subarray(0, offset);
  7281. }
  7282. _convertYcckToRgba(data) {
  7283. for (let i = 0, length = data.length; i < length; i += 4) {
  7284. const Y = data[i];
  7285. const Cb = data[i + 1];
  7286. const Cr = data[i + 2];
  7287. const k = data[i + 3];
  7288. data[i] = -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);
  7289. data[i + 1] = 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);
  7290. data[i + 2] = -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);
  7291. data[i + 3] = 255;
  7292. }
  7293. return data;
  7294. }
  7295. _convertYcckToCmyk(data) {
  7296. let Y, Cb, Cr;
  7297. for (let i = 0, length = data.length; i < length; i += 4) {
  7298. Y = data[i];
  7299. Cb = data[i + 1];
  7300. Cr = data[i + 2];
  7301. data[i] = 434.456 - Y - 1.402 * Cr;
  7302. data[i + 1] = 119.541 - Y + 0.344 * Cb + 0.714 * Cr;
  7303. data[i + 2] = 481.816 - Y - 1.772 * Cb;
  7304. }
  7305. return data;
  7306. }
  7307. _convertCmykToRgb(data) {
  7308. let c, m, y, k;
  7309. let offset = 0;
  7310. for (let i = 0, length = data.length; i < length; i += 4) {
  7311. c = data[i];
  7312. m = data[i + 1];
  7313. y = data[i + 2];
  7314. k = data[i + 3];
  7315. data[offset++] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254);
  7316. data[offset++] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.0003189131175883281 * k + 0.7364883807733168);
  7317. data[offset++] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144);
  7318. }
  7319. return data.subarray(0, offset);
  7320. }
  7321. _convertCmykToRgba(data) {
  7322. for (let i = 0, length = data.length; i < length; i += 4) {
  7323. const c = data[i];
  7324. const m = data[i + 1];
  7325. const y = data[i + 2];
  7326. const k = data[i + 3];
  7327. data[i] = 255 + c * (-0.00006747147073602441 * c + 0.0008379262121013727 * m + 0.0002894718188643294 * y + 0.003264231057537806 * k - 1.1185611867203937) + m * (0.000026374107616089405 * m - 0.00008626949158638572 * y - 0.0002748769067499491 * k - 0.02155688794978967) + y * (-0.00003878099212869363 * y - 0.0003267808279485286 * k + 0.0686742238595345) - k * (0.0003361971776183937 * k + 0.7430659151342254);
  7328. data[i + 1] = 255 + c * (0.00013596372813588848 * c + 0.000924537132573585 * m + 0.00010567359618683593 * y + 0.0004791864687436512 * k - 0.3109689587515875) + m * (-0.00023545346108370344 * m + 0.0002702845253534714 * y + 0.0020200308977307156 * k - 0.7488052167015494) + y * (0.00006834815998235662 * y + 0.00015168452363460973 * k - 0.09751927774728933) - k * (0.0003189131175883281 * k + 0.7364883807733168);
  7329. data[i + 2] = 255 + c * (0.000013598650411385307 * c + 0.00012423956175490851 * m + 0.0004751985097583589 * y - 0.0000036729317476630422 * k - 0.05562186980264034) + m * (0.00016141380598724676 * m + 0.0009692239130725186 * y + 0.0007782692450036253 * k - 0.44015232367526463) + y * (5.068882914068769e-7 * y + 0.0017778369011375071 * k - 0.7591454649749609) - k * (0.0003435319965105553 * k + 0.7063770186160144);
  7330. data[i + 3] = 255;
  7331. }
  7332. return data;
  7333. }
  7334. getData({
  7335. width,
  7336. height,
  7337. forceRGBA = false,
  7338. forceRGB = false,
  7339. isSourcePDF = false
  7340. }) {
  7341. if (this.numComponents > 4) {
  7342. throw new JpegError("Unsupported color mode");
  7343. }
  7344. const data = this._getLinearizedBlockData(width, height, isSourcePDF);
  7345. if (this.numComponents === 1 && (forceRGBA || forceRGB)) {
  7346. const len = data.length * (forceRGBA ? 4 : 3);
  7347. const rgbaData = new Uint8ClampedArray(len);
  7348. let offset = 0;
  7349. if (forceRGBA) {
  7350. grayToRGBA(data, new Uint32Array(rgbaData.buffer));
  7351. } else {
  7352. for (const grayColor of data) {
  7353. rgbaData[offset++] = grayColor;
  7354. rgbaData[offset++] = grayColor;
  7355. rgbaData[offset++] = grayColor;
  7356. }
  7357. }
  7358. return rgbaData;
  7359. } else if (this.numComponents === 3 && this._isColorConversionNeeded) {
  7360. if (forceRGBA) {
  7361. const rgbaData = new Uint8ClampedArray(data.length / 3 * 4);
  7362. return this._convertYccToRgba(data, rgbaData);
  7363. }
  7364. return this._convertYccToRgb(data);
  7365. } else if (this.numComponents === 4) {
  7366. if (this._isColorConversionNeeded) {
  7367. if (forceRGBA) {
  7368. return this._convertYcckToRgba(data);
  7369. }
  7370. if (forceRGB) {
  7371. return this._convertYcckToRgb(data);
  7372. }
  7373. return this._convertYcckToCmyk(data);
  7374. } else if (forceRGBA) {
  7375. return this._convertCmykToRgba(data);
  7376. } else if (forceRGB) {
  7377. return this._convertCmykToRgb(data);
  7378. }
  7379. }
  7380. return data;
  7381. }
  7382. }
  7383. ;// CONCATENATED MODULE: ./src/core/jpeg_stream.js
  7384. class JpegStream extends DecodeStream {
  7385. constructor(stream, maybeLength, params) {
  7386. let ch;
  7387. while ((ch = stream.getByte()) !== -1) {
  7388. if (ch === 0xff) {
  7389. stream.skip(-1);
  7390. break;
  7391. }
  7392. }
  7393. super(maybeLength);
  7394. this.stream = stream;
  7395. this.dict = stream.dict;
  7396. this.maybeLength = maybeLength;
  7397. this.params = params;
  7398. }
  7399. get bytes() {
  7400. return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
  7401. }
  7402. ensureBuffer(requested) {}
  7403. readBlock() {
  7404. if (this.eof) {
  7405. return;
  7406. }
  7407. const jpegOptions = {
  7408. decodeTransform: undefined,
  7409. colorTransform: undefined
  7410. };
  7411. const decodeArr = this.dict.getArray("D", "Decode");
  7412. if ((this.forceRGBA || this.forceRGB) && Array.isArray(decodeArr)) {
  7413. const bitsPerComponent = this.dict.get("BPC", "BitsPerComponent") || 8;
  7414. const decodeArrLength = decodeArr.length;
  7415. const transform = new Int32Array(decodeArrLength);
  7416. let transformNeeded = false;
  7417. const maxValue = (1 << bitsPerComponent) - 1;
  7418. for (let i = 0; i < decodeArrLength; i += 2) {
  7419. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  7420. transform[i + 1] = decodeArr[i] * maxValue | 0;
  7421. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  7422. transformNeeded = true;
  7423. }
  7424. }
  7425. if (transformNeeded) {
  7426. jpegOptions.decodeTransform = transform;
  7427. }
  7428. }
  7429. if (this.params instanceof Dict) {
  7430. const colorTransform = this.params.get("ColorTransform");
  7431. if (Number.isInteger(colorTransform)) {
  7432. jpegOptions.colorTransform = colorTransform;
  7433. }
  7434. }
  7435. const jpegImage = new JpegImage(jpegOptions);
  7436. jpegImage.parse(this.bytes);
  7437. const data = jpegImage.getData({
  7438. width: this.drawWidth,
  7439. height: this.drawHeight,
  7440. forceRGBA: this.forceRGBA,
  7441. forceRGB: this.forceRGB,
  7442. isSourcePDF: true
  7443. });
  7444. this.buffer = data;
  7445. this.bufferLength = data.length;
  7446. this.eof = true;
  7447. }
  7448. }
  7449. ;// CONCATENATED MODULE: ./src/core/jpx.js
  7450. class JpxError extends BaseException {
  7451. constructor(msg) {
  7452. super(`JPX error: ${msg}`, "JpxError");
  7453. }
  7454. }
  7455. const SubbandsGainLog2 = {
  7456. LL: 0,
  7457. LH: 1,
  7458. HL: 1,
  7459. HH: 2
  7460. };
  7461. class JpxImage {
  7462. constructor() {
  7463. this.failOnCorruptedImage = false;
  7464. }
  7465. parse(data) {
  7466. const head = readUint16(data, 0);
  7467. if (head === 0xff4f) {
  7468. this.parseCodestream(data, 0, data.length);
  7469. return;
  7470. }
  7471. const length = data.length;
  7472. let position = 0;
  7473. while (position < length) {
  7474. let headerSize = 8;
  7475. let lbox = readUint32(data, position);
  7476. const tbox = readUint32(data, position + 4);
  7477. position += headerSize;
  7478. if (lbox === 1) {
  7479. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  7480. position += 8;
  7481. headerSize += 8;
  7482. }
  7483. if (lbox === 0) {
  7484. lbox = length - position + headerSize;
  7485. }
  7486. if (lbox < headerSize) {
  7487. throw new JpxError("Invalid box field size");
  7488. }
  7489. const dataLength = lbox - headerSize;
  7490. let jumpDataLength = true;
  7491. switch (tbox) {
  7492. case 0x6a703268:
  7493. jumpDataLength = false;
  7494. break;
  7495. case 0x636f6c72:
  7496. const method = data[position];
  7497. if (method === 1) {
  7498. const colorspace = readUint32(data, position + 3);
  7499. switch (colorspace) {
  7500. case 16:
  7501. case 17:
  7502. case 18:
  7503. break;
  7504. default:
  7505. warn("Unknown colorspace " + colorspace);
  7506. break;
  7507. }
  7508. } else if (method === 2) {
  7509. info("ICC profile not supported");
  7510. }
  7511. break;
  7512. case 0x6a703263:
  7513. this.parseCodestream(data, position, position + dataLength);
  7514. break;
  7515. case 0x6a502020:
  7516. if (readUint32(data, position) !== 0x0d0a870a) {
  7517. warn("Invalid JP2 signature");
  7518. }
  7519. break;
  7520. case 0x6a501a1a:
  7521. case 0x66747970:
  7522. case 0x72726571:
  7523. case 0x72657320:
  7524. case 0x69686472:
  7525. break;
  7526. default:
  7527. const headerType = String.fromCharCode(tbox >> 24 & 0xff, tbox >> 16 & 0xff, tbox >> 8 & 0xff, tbox & 0xff);
  7528. warn(`Unsupported header type ${tbox} (${headerType}).`);
  7529. break;
  7530. }
  7531. if (jumpDataLength) {
  7532. position += dataLength;
  7533. }
  7534. }
  7535. }
  7536. parseImageProperties(stream) {
  7537. let newByte = stream.getByte();
  7538. while (newByte >= 0) {
  7539. const oldByte = newByte;
  7540. newByte = stream.getByte();
  7541. const code = oldByte << 8 | newByte;
  7542. if (code === 0xff51) {
  7543. stream.skip(4);
  7544. const Xsiz = stream.getInt32() >>> 0;
  7545. const Ysiz = stream.getInt32() >>> 0;
  7546. const XOsiz = stream.getInt32() >>> 0;
  7547. const YOsiz = stream.getInt32() >>> 0;
  7548. stream.skip(16);
  7549. const Csiz = stream.getUint16();
  7550. this.width = Xsiz - XOsiz;
  7551. this.height = Ysiz - YOsiz;
  7552. this.componentsCount = Csiz;
  7553. this.bitsPerComponent = 8;
  7554. return;
  7555. }
  7556. }
  7557. throw new JpxError("No size marker found in JPX stream");
  7558. }
  7559. parseCodestream(data, start, end) {
  7560. const context = {};
  7561. let doNotRecover = false;
  7562. try {
  7563. let position = start;
  7564. while (position + 1 < end) {
  7565. const code = readUint16(data, position);
  7566. position += 2;
  7567. let length = 0,
  7568. j,
  7569. sqcd,
  7570. spqcds,
  7571. spqcdSize,
  7572. scalarExpounded,
  7573. tile;
  7574. switch (code) {
  7575. case 0xff4f:
  7576. context.mainHeader = true;
  7577. break;
  7578. case 0xffd9:
  7579. break;
  7580. case 0xff51:
  7581. length = readUint16(data, position);
  7582. const siz = {};
  7583. siz.Xsiz = readUint32(data, position + 4);
  7584. siz.Ysiz = readUint32(data, position + 8);
  7585. siz.XOsiz = readUint32(data, position + 12);
  7586. siz.YOsiz = readUint32(data, position + 16);
  7587. siz.XTsiz = readUint32(data, position + 20);
  7588. siz.YTsiz = readUint32(data, position + 24);
  7589. siz.XTOsiz = readUint32(data, position + 28);
  7590. siz.YTOsiz = readUint32(data, position + 32);
  7591. const componentsCount = readUint16(data, position + 36);
  7592. siz.Csiz = componentsCount;
  7593. const components = [];
  7594. j = position + 38;
  7595. for (let i = 0; i < componentsCount; i++) {
  7596. const component = {
  7597. precision: (data[j] & 0x7f) + 1,
  7598. isSigned: !!(data[j] & 0x80),
  7599. XRsiz: data[j + 1],
  7600. YRsiz: data[j + 2]
  7601. };
  7602. j += 3;
  7603. calculateComponentDimensions(component, siz);
  7604. components.push(component);
  7605. }
  7606. context.SIZ = siz;
  7607. context.components = components;
  7608. calculateTileGrids(context, components);
  7609. context.QCC = [];
  7610. context.COC = [];
  7611. break;
  7612. case 0xff5c:
  7613. length = readUint16(data, position);
  7614. const qcd = {};
  7615. j = position + 2;
  7616. sqcd = data[j++];
  7617. switch (sqcd & 0x1f) {
  7618. case 0:
  7619. spqcdSize = 8;
  7620. scalarExpounded = true;
  7621. break;
  7622. case 1:
  7623. spqcdSize = 16;
  7624. scalarExpounded = false;
  7625. break;
  7626. case 2:
  7627. spqcdSize = 16;
  7628. scalarExpounded = true;
  7629. break;
  7630. default:
  7631. throw new Error("Invalid SQcd value " + sqcd);
  7632. }
  7633. qcd.noQuantization = spqcdSize === 8;
  7634. qcd.scalarExpounded = scalarExpounded;
  7635. qcd.guardBits = sqcd >> 5;
  7636. spqcds = [];
  7637. while (j < length + position) {
  7638. const spqcd = {};
  7639. if (spqcdSize === 8) {
  7640. spqcd.epsilon = data[j++] >> 3;
  7641. spqcd.mu = 0;
  7642. } else {
  7643. spqcd.epsilon = data[j] >> 3;
  7644. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  7645. j += 2;
  7646. }
  7647. spqcds.push(spqcd);
  7648. }
  7649. qcd.SPqcds = spqcds;
  7650. if (context.mainHeader) {
  7651. context.QCD = qcd;
  7652. } else {
  7653. context.currentTile.QCD = qcd;
  7654. context.currentTile.QCC = [];
  7655. }
  7656. break;
  7657. case 0xff5d:
  7658. length = readUint16(data, position);
  7659. const qcc = {};
  7660. j = position + 2;
  7661. let cqcc;
  7662. if (context.SIZ.Csiz < 257) {
  7663. cqcc = data[j++];
  7664. } else {
  7665. cqcc = readUint16(data, j);
  7666. j += 2;
  7667. }
  7668. sqcd = data[j++];
  7669. switch (sqcd & 0x1f) {
  7670. case 0:
  7671. spqcdSize = 8;
  7672. scalarExpounded = true;
  7673. break;
  7674. case 1:
  7675. spqcdSize = 16;
  7676. scalarExpounded = false;
  7677. break;
  7678. case 2:
  7679. spqcdSize = 16;
  7680. scalarExpounded = true;
  7681. break;
  7682. default:
  7683. throw new Error("Invalid SQcd value " + sqcd);
  7684. }
  7685. qcc.noQuantization = spqcdSize === 8;
  7686. qcc.scalarExpounded = scalarExpounded;
  7687. qcc.guardBits = sqcd >> 5;
  7688. spqcds = [];
  7689. while (j < length + position) {
  7690. const spqcd = {};
  7691. if (spqcdSize === 8) {
  7692. spqcd.epsilon = data[j++] >> 3;
  7693. spqcd.mu = 0;
  7694. } else {
  7695. spqcd.epsilon = data[j] >> 3;
  7696. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  7697. j += 2;
  7698. }
  7699. spqcds.push(spqcd);
  7700. }
  7701. qcc.SPqcds = spqcds;
  7702. if (context.mainHeader) {
  7703. context.QCC[cqcc] = qcc;
  7704. } else {
  7705. context.currentTile.QCC[cqcc] = qcc;
  7706. }
  7707. break;
  7708. case 0xff52:
  7709. length = readUint16(data, position);
  7710. const cod = {};
  7711. j = position + 2;
  7712. const scod = data[j++];
  7713. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  7714. cod.sopMarkerUsed = !!(scod & 2);
  7715. cod.ephMarkerUsed = !!(scod & 4);
  7716. cod.progressionOrder = data[j++];
  7717. cod.layersCount = readUint16(data, j);
  7718. j += 2;
  7719. cod.multipleComponentTransform = data[j++];
  7720. cod.decompositionLevelsCount = data[j++];
  7721. cod.xcb = (data[j++] & 0xf) + 2;
  7722. cod.ycb = (data[j++] & 0xf) + 2;
  7723. const blockStyle = data[j++];
  7724. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  7725. cod.resetContextProbabilities = !!(blockStyle & 2);
  7726. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  7727. cod.verticallyStripe = !!(blockStyle & 8);
  7728. cod.predictableTermination = !!(blockStyle & 16);
  7729. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  7730. cod.reversibleTransformation = data[j++];
  7731. if (cod.entropyCoderWithCustomPrecincts) {
  7732. const precinctsSizes = [];
  7733. while (j < length + position) {
  7734. const precinctsSize = data[j++];
  7735. precinctsSizes.push({
  7736. PPx: precinctsSize & 0xf,
  7737. PPy: precinctsSize >> 4
  7738. });
  7739. }
  7740. cod.precinctsSizes = precinctsSizes;
  7741. }
  7742. const unsupported = [];
  7743. if (cod.selectiveArithmeticCodingBypass) {
  7744. unsupported.push("selectiveArithmeticCodingBypass");
  7745. }
  7746. if (cod.terminationOnEachCodingPass) {
  7747. unsupported.push("terminationOnEachCodingPass");
  7748. }
  7749. if (cod.verticallyStripe) {
  7750. unsupported.push("verticallyStripe");
  7751. }
  7752. if (cod.predictableTermination) {
  7753. unsupported.push("predictableTermination");
  7754. }
  7755. if (unsupported.length > 0) {
  7756. doNotRecover = true;
  7757. warn(`JPX: Unsupported COD options (${unsupported.join(", ")}).`);
  7758. }
  7759. if (context.mainHeader) {
  7760. context.COD = cod;
  7761. } else {
  7762. context.currentTile.COD = cod;
  7763. context.currentTile.COC = [];
  7764. }
  7765. break;
  7766. case 0xff90:
  7767. length = readUint16(data, position);
  7768. tile = {};
  7769. tile.index = readUint16(data, position + 2);
  7770. tile.length = readUint32(data, position + 4);
  7771. tile.dataEnd = tile.length + position - 2;
  7772. tile.partIndex = data[position + 8];
  7773. tile.partsCount = data[position + 9];
  7774. context.mainHeader = false;
  7775. if (tile.partIndex === 0) {
  7776. tile.COD = context.COD;
  7777. tile.COC = context.COC.slice(0);
  7778. tile.QCD = context.QCD;
  7779. tile.QCC = context.QCC.slice(0);
  7780. }
  7781. context.currentTile = tile;
  7782. break;
  7783. case 0xff93:
  7784. tile = context.currentTile;
  7785. if (tile.partIndex === 0) {
  7786. initializeTile(context, tile.index);
  7787. buildPackets(context);
  7788. }
  7789. length = tile.dataEnd - position;
  7790. parseTilePackets(context, data, position, length);
  7791. break;
  7792. case 0xff53:
  7793. warn("JPX: Codestream code 0xFF53 (COC) is not implemented.");
  7794. case 0xff55:
  7795. case 0xff57:
  7796. case 0xff58:
  7797. case 0xff64:
  7798. length = readUint16(data, position);
  7799. break;
  7800. default:
  7801. throw new Error("Unknown codestream code: " + code.toString(16));
  7802. }
  7803. position += length;
  7804. }
  7805. } catch (e) {
  7806. if (doNotRecover || this.failOnCorruptedImage) {
  7807. throw new JpxError(e.message);
  7808. } else {
  7809. warn(`JPX: Trying to recover from: "${e.message}".`);
  7810. }
  7811. }
  7812. this.tiles = transformComponents(context);
  7813. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  7814. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  7815. this.componentsCount = context.SIZ.Csiz;
  7816. }
  7817. }
  7818. function calculateComponentDimensions(component, siz) {
  7819. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  7820. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  7821. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  7822. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  7823. component.width = component.x1 - component.x0;
  7824. component.height = component.y1 - component.y0;
  7825. }
  7826. function calculateTileGrids(context, components) {
  7827. const siz = context.SIZ;
  7828. const tiles = [];
  7829. let tile;
  7830. const numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  7831. const numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  7832. for (let q = 0; q < numYtiles; q++) {
  7833. for (let p = 0; p < numXtiles; p++) {
  7834. tile = {};
  7835. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  7836. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  7837. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  7838. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  7839. tile.width = tile.tx1 - tile.tx0;
  7840. tile.height = tile.ty1 - tile.ty0;
  7841. tile.components = [];
  7842. tiles.push(tile);
  7843. }
  7844. }
  7845. context.tiles = tiles;
  7846. const componentsCount = siz.Csiz;
  7847. for (let i = 0, ii = componentsCount; i < ii; i++) {
  7848. const component = components[i];
  7849. for (let j = 0, jj = tiles.length; j < jj; j++) {
  7850. const tileComponent = {};
  7851. tile = tiles[j];
  7852. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  7853. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  7854. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  7855. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  7856. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  7857. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  7858. tile.components[i] = tileComponent;
  7859. }
  7860. }
  7861. }
  7862. function getBlocksDimensions(context, component, r) {
  7863. const codOrCoc = component.codingStyleParameters;
  7864. const result = {};
  7865. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  7866. result.PPx = 15;
  7867. result.PPy = 15;
  7868. } else {
  7869. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  7870. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  7871. }
  7872. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  7873. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  7874. return result;
  7875. }
  7876. function buildPrecincts(context, resolution, dimensions) {
  7877. const precinctWidth = 1 << dimensions.PPx;
  7878. const precinctHeight = 1 << dimensions.PPy;
  7879. const isZeroRes = resolution.resLevel === 0;
  7880. const precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  7881. const precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  7882. const numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  7883. const numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  7884. const numprecincts = numprecinctswide * numprecinctshigh;
  7885. resolution.precinctParameters = {
  7886. precinctWidth,
  7887. precinctHeight,
  7888. numprecinctswide,
  7889. numprecinctshigh,
  7890. numprecincts,
  7891. precinctWidthInSubband,
  7892. precinctHeightInSubband
  7893. };
  7894. }
  7895. function buildCodeblocks(context, subband, dimensions) {
  7896. const xcb_ = dimensions.xcb_;
  7897. const ycb_ = dimensions.ycb_;
  7898. const codeblockWidth = 1 << xcb_;
  7899. const codeblockHeight = 1 << ycb_;
  7900. const cbx0 = subband.tbx0 >> xcb_;
  7901. const cby0 = subband.tby0 >> ycb_;
  7902. const cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  7903. const cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  7904. const precinctParameters = subband.resolution.precinctParameters;
  7905. const codeblocks = [];
  7906. const precincts = [];
  7907. let i, j, codeblock, precinctNumber;
  7908. for (j = cby0; j < cby1; j++) {
  7909. for (i = cbx0; i < cbx1; i++) {
  7910. codeblock = {
  7911. cbx: i,
  7912. cby: j,
  7913. tbx0: codeblockWidth * i,
  7914. tby0: codeblockHeight * j,
  7915. tbx1: codeblockWidth * (i + 1),
  7916. tby1: codeblockHeight * (j + 1)
  7917. };
  7918. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  7919. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  7920. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  7921. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  7922. const pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  7923. const pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  7924. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  7925. codeblock.precinctNumber = precinctNumber;
  7926. codeblock.subbandType = subband.type;
  7927. codeblock.Lblock = 3;
  7928. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  7929. continue;
  7930. }
  7931. codeblocks.push(codeblock);
  7932. let precinct = precincts[precinctNumber];
  7933. if (precinct !== undefined) {
  7934. if (i < precinct.cbxMin) {
  7935. precinct.cbxMin = i;
  7936. } else if (i > precinct.cbxMax) {
  7937. precinct.cbxMax = i;
  7938. }
  7939. if (j < precinct.cbyMin) {
  7940. precinct.cbxMin = j;
  7941. } else if (j > precinct.cbyMax) {
  7942. precinct.cbyMax = j;
  7943. }
  7944. } else {
  7945. precincts[precinctNumber] = precinct = {
  7946. cbxMin: i,
  7947. cbyMin: j,
  7948. cbxMax: i,
  7949. cbyMax: j
  7950. };
  7951. }
  7952. codeblock.precinct = precinct;
  7953. }
  7954. }
  7955. subband.codeblockParameters = {
  7956. codeblockWidth: xcb_,
  7957. codeblockHeight: ycb_,
  7958. numcodeblockwide: cbx1 - cbx0 + 1,
  7959. numcodeblockhigh: cby1 - cby0 + 1
  7960. };
  7961. subband.codeblocks = codeblocks;
  7962. subband.precincts = precincts;
  7963. }
  7964. function createPacket(resolution, precinctNumber, layerNumber) {
  7965. const precinctCodeblocks = [];
  7966. const subbands = resolution.subbands;
  7967. for (let i = 0, ii = subbands.length; i < ii; i++) {
  7968. const subband = subbands[i];
  7969. const codeblocks = subband.codeblocks;
  7970. for (let j = 0, jj = codeblocks.length; j < jj; j++) {
  7971. const codeblock = codeblocks[j];
  7972. if (codeblock.precinctNumber !== precinctNumber) {
  7973. continue;
  7974. }
  7975. precinctCodeblocks.push(codeblock);
  7976. }
  7977. }
  7978. return {
  7979. layerNumber,
  7980. codeblocks: precinctCodeblocks
  7981. };
  7982. }
  7983. function LayerResolutionComponentPositionIterator(context) {
  7984. const siz = context.SIZ;
  7985. const tileIndex = context.currentTile.index;
  7986. const tile = context.tiles[tileIndex];
  7987. const layersCount = tile.codingStyleDefaultParameters.layersCount;
  7988. const componentsCount = siz.Csiz;
  7989. let maxDecompositionLevelsCount = 0;
  7990. for (let q = 0; q < componentsCount; q++) {
  7991. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  7992. }
  7993. let l = 0,
  7994. r = 0,
  7995. i = 0,
  7996. k = 0;
  7997. this.nextPacket = function JpxImage_nextPacket() {
  7998. for (; l < layersCount; l++) {
  7999. for (; r <= maxDecompositionLevelsCount; r++) {
  8000. for (; i < componentsCount; i++) {
  8001. const component = tile.components[i];
  8002. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  8003. continue;
  8004. }
  8005. const resolution = component.resolutions[r];
  8006. const numprecincts = resolution.precinctParameters.numprecincts;
  8007. for (; k < numprecincts;) {
  8008. const packet = createPacket(resolution, k, l);
  8009. k++;
  8010. return packet;
  8011. }
  8012. k = 0;
  8013. }
  8014. i = 0;
  8015. }
  8016. r = 0;
  8017. }
  8018. throw new JpxError("Out of packets");
  8019. };
  8020. }
  8021. function ResolutionLayerComponentPositionIterator(context) {
  8022. const siz = context.SIZ;
  8023. const tileIndex = context.currentTile.index;
  8024. const tile = context.tiles[tileIndex];
  8025. const layersCount = tile.codingStyleDefaultParameters.layersCount;
  8026. const componentsCount = siz.Csiz;
  8027. let maxDecompositionLevelsCount = 0;
  8028. for (let q = 0; q < componentsCount; q++) {
  8029. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  8030. }
  8031. let r = 0,
  8032. l = 0,
  8033. i = 0,
  8034. k = 0;
  8035. this.nextPacket = function JpxImage_nextPacket() {
  8036. for (; r <= maxDecompositionLevelsCount; r++) {
  8037. for (; l < layersCount; l++) {
  8038. for (; i < componentsCount; i++) {
  8039. const component = tile.components[i];
  8040. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  8041. continue;
  8042. }
  8043. const resolution = component.resolutions[r];
  8044. const numprecincts = resolution.precinctParameters.numprecincts;
  8045. for (; k < numprecincts;) {
  8046. const packet = createPacket(resolution, k, l);
  8047. k++;
  8048. return packet;
  8049. }
  8050. k = 0;
  8051. }
  8052. i = 0;
  8053. }
  8054. l = 0;
  8055. }
  8056. throw new JpxError("Out of packets");
  8057. };
  8058. }
  8059. function ResolutionPositionComponentLayerIterator(context) {
  8060. const siz = context.SIZ;
  8061. const tileIndex = context.currentTile.index;
  8062. const tile = context.tiles[tileIndex];
  8063. const layersCount = tile.codingStyleDefaultParameters.layersCount;
  8064. const componentsCount = siz.Csiz;
  8065. let l, r, c, p;
  8066. let maxDecompositionLevelsCount = 0;
  8067. for (c = 0; c < componentsCount; c++) {
  8068. const component = tile.components[c];
  8069. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  8070. }
  8071. const maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  8072. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  8073. let maxNumPrecincts = 0;
  8074. for (c = 0; c < componentsCount; ++c) {
  8075. const resolutions = tile.components[c].resolutions;
  8076. if (r < resolutions.length) {
  8077. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  8078. }
  8079. }
  8080. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  8081. }
  8082. l = 0;
  8083. r = 0;
  8084. c = 0;
  8085. p = 0;
  8086. this.nextPacket = function JpxImage_nextPacket() {
  8087. for (; r <= maxDecompositionLevelsCount; r++) {
  8088. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  8089. for (; c < componentsCount; c++) {
  8090. const component = tile.components[c];
  8091. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  8092. continue;
  8093. }
  8094. const resolution = component.resolutions[r];
  8095. const numprecincts = resolution.precinctParameters.numprecincts;
  8096. if (p >= numprecincts) {
  8097. continue;
  8098. }
  8099. for (; l < layersCount;) {
  8100. const packet = createPacket(resolution, p, l);
  8101. l++;
  8102. return packet;
  8103. }
  8104. l = 0;
  8105. }
  8106. c = 0;
  8107. }
  8108. p = 0;
  8109. }
  8110. throw new JpxError("Out of packets");
  8111. };
  8112. }
  8113. function PositionComponentResolutionLayerIterator(context) {
  8114. const siz = context.SIZ;
  8115. const tileIndex = context.currentTile.index;
  8116. const tile = context.tiles[tileIndex];
  8117. const layersCount = tile.codingStyleDefaultParameters.layersCount;
  8118. const componentsCount = siz.Csiz;
  8119. const precinctsSizes = getPrecinctSizesInImageScale(tile);
  8120. const precinctsIterationSizes = precinctsSizes;
  8121. let l = 0,
  8122. r = 0,
  8123. c = 0,
  8124. px = 0,
  8125. py = 0;
  8126. this.nextPacket = function JpxImage_nextPacket() {
  8127. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  8128. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  8129. for (; c < componentsCount; c++) {
  8130. const component = tile.components[c];
  8131. const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  8132. for (; r <= decompositionLevelsCount; r++) {
  8133. const resolution = component.resolutions[r];
  8134. const sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  8135. const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  8136. if (k === null) {
  8137. continue;
  8138. }
  8139. for (; l < layersCount;) {
  8140. const packet = createPacket(resolution, k, l);
  8141. l++;
  8142. return packet;
  8143. }
  8144. l = 0;
  8145. }
  8146. r = 0;
  8147. }
  8148. c = 0;
  8149. }
  8150. px = 0;
  8151. }
  8152. throw new JpxError("Out of packets");
  8153. };
  8154. }
  8155. function ComponentPositionResolutionLayerIterator(context) {
  8156. const siz = context.SIZ;
  8157. const tileIndex = context.currentTile.index;
  8158. const tile = context.tiles[tileIndex];
  8159. const layersCount = tile.codingStyleDefaultParameters.layersCount;
  8160. const componentsCount = siz.Csiz;
  8161. const precinctsSizes = getPrecinctSizesInImageScale(tile);
  8162. let l = 0,
  8163. r = 0,
  8164. c = 0,
  8165. px = 0,
  8166. py = 0;
  8167. this.nextPacket = function JpxImage_nextPacket() {
  8168. for (; c < componentsCount; ++c) {
  8169. const component = tile.components[c];
  8170. const precinctsIterationSizes = precinctsSizes.components[c];
  8171. const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  8172. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  8173. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  8174. for (; r <= decompositionLevelsCount; r++) {
  8175. const resolution = component.resolutions[r];
  8176. const sizeInImageScale = precinctsIterationSizes.resolutions[r];
  8177. const k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  8178. if (k === null) {
  8179. continue;
  8180. }
  8181. for (; l < layersCount;) {
  8182. const packet = createPacket(resolution, k, l);
  8183. l++;
  8184. return packet;
  8185. }
  8186. l = 0;
  8187. }
  8188. r = 0;
  8189. }
  8190. px = 0;
  8191. }
  8192. py = 0;
  8193. }
  8194. throw new JpxError("Out of packets");
  8195. };
  8196. }
  8197. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  8198. const posX = pxIndex * precinctIterationSizes.minWidth;
  8199. const posY = pyIndex * precinctIterationSizes.minHeight;
  8200. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  8201. return null;
  8202. }
  8203. const startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  8204. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  8205. }
  8206. function getPrecinctSizesInImageScale(tile) {
  8207. const componentsCount = tile.components.length;
  8208. let minWidth = Number.MAX_VALUE;
  8209. let minHeight = Number.MAX_VALUE;
  8210. let maxNumWide = 0;
  8211. let maxNumHigh = 0;
  8212. const sizePerComponent = new Array(componentsCount);
  8213. for (let c = 0; c < componentsCount; c++) {
  8214. const component = tile.components[c];
  8215. const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  8216. const sizePerResolution = new Array(decompositionLevelsCount + 1);
  8217. let minWidthCurrentComponent = Number.MAX_VALUE;
  8218. let minHeightCurrentComponent = Number.MAX_VALUE;
  8219. let maxNumWideCurrentComponent = 0;
  8220. let maxNumHighCurrentComponent = 0;
  8221. let scale = 1;
  8222. for (let r = decompositionLevelsCount; r >= 0; --r) {
  8223. const resolution = component.resolutions[r];
  8224. const widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  8225. const heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  8226. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  8227. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  8228. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  8229. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  8230. sizePerResolution[r] = {
  8231. width: widthCurrentResolution,
  8232. height: heightCurrentResolution
  8233. };
  8234. scale <<= 1;
  8235. }
  8236. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  8237. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  8238. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  8239. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  8240. sizePerComponent[c] = {
  8241. resolutions: sizePerResolution,
  8242. minWidth: minWidthCurrentComponent,
  8243. minHeight: minHeightCurrentComponent,
  8244. maxNumWide: maxNumWideCurrentComponent,
  8245. maxNumHigh: maxNumHighCurrentComponent
  8246. };
  8247. }
  8248. return {
  8249. components: sizePerComponent,
  8250. minWidth,
  8251. minHeight,
  8252. maxNumWide,
  8253. maxNumHigh
  8254. };
  8255. }
  8256. function buildPackets(context) {
  8257. const siz = context.SIZ;
  8258. const tileIndex = context.currentTile.index;
  8259. const tile = context.tiles[tileIndex];
  8260. const componentsCount = siz.Csiz;
  8261. for (let c = 0; c < componentsCount; c++) {
  8262. const component = tile.components[c];
  8263. const decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  8264. const resolutions = [];
  8265. const subbands = [];
  8266. for (let r = 0; r <= decompositionLevelsCount; r++) {
  8267. const blocksDimensions = getBlocksDimensions(context, component, r);
  8268. const resolution = {};
  8269. const scale = 1 << decompositionLevelsCount - r;
  8270. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  8271. resolution.try0 = Math.ceil(component.tcy0 / scale);
  8272. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  8273. resolution.try1 = Math.ceil(component.tcy1 / scale);
  8274. resolution.resLevel = r;
  8275. buildPrecincts(context, resolution, blocksDimensions);
  8276. resolutions.push(resolution);
  8277. let subband;
  8278. if (r === 0) {
  8279. subband = {};
  8280. subband.type = "LL";
  8281. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  8282. subband.tby0 = Math.ceil(component.tcy0 / scale);
  8283. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  8284. subband.tby1 = Math.ceil(component.tcy1 / scale);
  8285. subband.resolution = resolution;
  8286. buildCodeblocks(context, subband, blocksDimensions);
  8287. subbands.push(subband);
  8288. resolution.subbands = [subband];
  8289. } else {
  8290. const bscale = 1 << decompositionLevelsCount - r + 1;
  8291. const resolutionSubbands = [];
  8292. subband = {};
  8293. subband.type = "HL";
  8294. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  8295. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  8296. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  8297. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  8298. subband.resolution = resolution;
  8299. buildCodeblocks(context, subband, blocksDimensions);
  8300. subbands.push(subband);
  8301. resolutionSubbands.push(subband);
  8302. subband = {};
  8303. subband.type = "LH";
  8304. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  8305. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  8306. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  8307. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  8308. subband.resolution = resolution;
  8309. buildCodeblocks(context, subband, blocksDimensions);
  8310. subbands.push(subband);
  8311. resolutionSubbands.push(subband);
  8312. subband = {};
  8313. subband.type = "HH";
  8314. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  8315. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  8316. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  8317. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  8318. subband.resolution = resolution;
  8319. buildCodeblocks(context, subband, blocksDimensions);
  8320. subbands.push(subband);
  8321. resolutionSubbands.push(subband);
  8322. resolution.subbands = resolutionSubbands;
  8323. }
  8324. }
  8325. component.resolutions = resolutions;
  8326. component.subbands = subbands;
  8327. }
  8328. const progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  8329. switch (progressionOrder) {
  8330. case 0:
  8331. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  8332. break;
  8333. case 1:
  8334. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  8335. break;
  8336. case 2:
  8337. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  8338. break;
  8339. case 3:
  8340. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  8341. break;
  8342. case 4:
  8343. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  8344. break;
  8345. default:
  8346. throw new JpxError(`Unsupported progression order ${progressionOrder}`);
  8347. }
  8348. }
  8349. function parseTilePackets(context, data, offset, dataLength) {
  8350. let position = 0;
  8351. let buffer,
  8352. bufferSize = 0,
  8353. skipNextBit = false;
  8354. function readBits(count) {
  8355. while (bufferSize < count) {
  8356. const b = data[offset + position];
  8357. position++;
  8358. if (skipNextBit) {
  8359. buffer = buffer << 7 | b;
  8360. bufferSize += 7;
  8361. skipNextBit = false;
  8362. } else {
  8363. buffer = buffer << 8 | b;
  8364. bufferSize += 8;
  8365. }
  8366. if (b === 0xff) {
  8367. skipNextBit = true;
  8368. }
  8369. }
  8370. bufferSize -= count;
  8371. return buffer >>> bufferSize & (1 << count) - 1;
  8372. }
  8373. function skipMarkerIfEqual(value) {
  8374. if (data[offset + position - 1] === 0xff && data[offset + position] === value) {
  8375. skipBytes(1);
  8376. return true;
  8377. } else if (data[offset + position] === 0xff && data[offset + position + 1] === value) {
  8378. skipBytes(2);
  8379. return true;
  8380. }
  8381. return false;
  8382. }
  8383. function skipBytes(count) {
  8384. position += count;
  8385. }
  8386. function alignToByte() {
  8387. bufferSize = 0;
  8388. if (skipNextBit) {
  8389. position++;
  8390. skipNextBit = false;
  8391. }
  8392. }
  8393. function readCodingpasses() {
  8394. if (readBits(1) === 0) {
  8395. return 1;
  8396. }
  8397. if (readBits(1) === 0) {
  8398. return 2;
  8399. }
  8400. let value = readBits(2);
  8401. if (value < 3) {
  8402. return value + 3;
  8403. }
  8404. value = readBits(5);
  8405. if (value < 31) {
  8406. return value + 6;
  8407. }
  8408. value = readBits(7);
  8409. return value + 37;
  8410. }
  8411. const tileIndex = context.currentTile.index;
  8412. const tile = context.tiles[tileIndex];
  8413. const sopMarkerUsed = context.COD.sopMarkerUsed;
  8414. const ephMarkerUsed = context.COD.ephMarkerUsed;
  8415. const packetsIterator = tile.packetsIterator;
  8416. while (position < dataLength) {
  8417. alignToByte();
  8418. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  8419. skipBytes(4);
  8420. }
  8421. const packet = packetsIterator.nextPacket();
  8422. if (!readBits(1)) {
  8423. continue;
  8424. }
  8425. const layerNumber = packet.layerNumber,
  8426. queue = [];
  8427. let codeblock;
  8428. for (let i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  8429. codeblock = packet.codeblocks[i];
  8430. let precinct = codeblock.precinct;
  8431. const codeblockColumn = codeblock.cbx - precinct.cbxMin;
  8432. const codeblockRow = codeblock.cby - precinct.cbyMin;
  8433. let codeblockIncluded = false;
  8434. let firstTimeInclusion = false;
  8435. let valueReady, zeroBitPlanesTree;
  8436. if (codeblock.included !== undefined) {
  8437. codeblockIncluded = !!readBits(1);
  8438. } else {
  8439. precinct = codeblock.precinct;
  8440. let inclusionTree;
  8441. if (precinct.inclusionTree !== undefined) {
  8442. inclusionTree = precinct.inclusionTree;
  8443. } else {
  8444. const width = precinct.cbxMax - precinct.cbxMin + 1;
  8445. const height = precinct.cbyMax - precinct.cbyMin + 1;
  8446. inclusionTree = new InclusionTree(width, height, layerNumber);
  8447. zeroBitPlanesTree = new TagTree(width, height);
  8448. precinct.inclusionTree = inclusionTree;
  8449. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  8450. for (let l = 0; l < layerNumber; l++) {
  8451. if (readBits(1) !== 0) {
  8452. throw new JpxError("Invalid tag tree");
  8453. }
  8454. }
  8455. }
  8456. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  8457. while (true) {
  8458. if (readBits(1)) {
  8459. valueReady = !inclusionTree.nextLevel();
  8460. if (valueReady) {
  8461. codeblock.included = true;
  8462. codeblockIncluded = firstTimeInclusion = true;
  8463. break;
  8464. }
  8465. } else {
  8466. inclusionTree.incrementValue(layerNumber);
  8467. break;
  8468. }
  8469. }
  8470. }
  8471. }
  8472. if (!codeblockIncluded) {
  8473. continue;
  8474. }
  8475. if (firstTimeInclusion) {
  8476. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  8477. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  8478. while (true) {
  8479. if (readBits(1)) {
  8480. valueReady = !zeroBitPlanesTree.nextLevel();
  8481. if (valueReady) {
  8482. break;
  8483. }
  8484. } else {
  8485. zeroBitPlanesTree.incrementValue();
  8486. }
  8487. }
  8488. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  8489. }
  8490. const codingpasses = readCodingpasses();
  8491. while (readBits(1)) {
  8492. codeblock.Lblock++;
  8493. }
  8494. const codingpassesLog2 = log2(codingpasses);
  8495. const bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  8496. const codedDataLength = readBits(bits);
  8497. queue.push({
  8498. codeblock,
  8499. codingpasses,
  8500. dataLength: codedDataLength
  8501. });
  8502. }
  8503. alignToByte();
  8504. if (ephMarkerUsed) {
  8505. skipMarkerIfEqual(0x92);
  8506. }
  8507. while (queue.length > 0) {
  8508. const packetItem = queue.shift();
  8509. codeblock = packetItem.codeblock;
  8510. if (codeblock.data === undefined) {
  8511. codeblock.data = [];
  8512. }
  8513. codeblock.data.push({
  8514. data,
  8515. start: offset + position,
  8516. end: offset + position + packetItem.dataLength,
  8517. codingpasses: packetItem.codingpasses
  8518. });
  8519. position += packetItem.dataLength;
  8520. }
  8521. }
  8522. return position;
  8523. }
  8524. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities) {
  8525. const x0 = subband.tbx0;
  8526. const y0 = subband.tby0;
  8527. const width = subband.tbx1 - subband.tbx0;
  8528. const codeblocks = subband.codeblocks;
  8529. const right = subband.type.charAt(0) === "H" ? 1 : 0;
  8530. const bottom = subband.type.charAt(1) === "H" ? levelWidth : 0;
  8531. for (let i = 0, ii = codeblocks.length; i < ii; ++i) {
  8532. const codeblock = codeblocks[i];
  8533. const blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  8534. const blockHeight = codeblock.tby1_ - codeblock.tby0_;
  8535. if (blockWidth === 0 || blockHeight === 0) {
  8536. continue;
  8537. }
  8538. if (codeblock.data === undefined) {
  8539. continue;
  8540. }
  8541. const bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  8542. let currentCodingpassType = 2;
  8543. const data = codeblock.data;
  8544. let totalLength = 0,
  8545. codingpasses = 0;
  8546. let j, jj, dataItem;
  8547. for (j = 0, jj = data.length; j < jj; j++) {
  8548. dataItem = data[j];
  8549. totalLength += dataItem.end - dataItem.start;
  8550. codingpasses += dataItem.codingpasses;
  8551. }
  8552. const encodedData = new Uint8Array(totalLength);
  8553. let position = 0;
  8554. for (j = 0, jj = data.length; j < jj; j++) {
  8555. dataItem = data[j];
  8556. const chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  8557. encodedData.set(chunk, position);
  8558. position += chunk.length;
  8559. }
  8560. const decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  8561. bitModel.setDecoder(decoder);
  8562. for (j = 0; j < codingpasses; j++) {
  8563. switch (currentCodingpassType) {
  8564. case 0:
  8565. bitModel.runSignificancePropagationPass();
  8566. break;
  8567. case 1:
  8568. bitModel.runMagnitudeRefinementPass();
  8569. break;
  8570. case 2:
  8571. bitModel.runCleanupPass();
  8572. if (segmentationSymbolUsed) {
  8573. bitModel.checkSegmentationSymbol();
  8574. }
  8575. break;
  8576. }
  8577. if (resetContextProbabilities) {
  8578. bitModel.reset();
  8579. }
  8580. currentCodingpassType = (currentCodingpassType + 1) % 3;
  8581. }
  8582. let offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  8583. const sign = bitModel.coefficentsSign;
  8584. const magnitude = bitModel.coefficentsMagnitude;
  8585. const bitsDecoded = bitModel.bitsDecoded;
  8586. const magnitudeCorrection = reversible ? 0 : 0.5;
  8587. let k, n, nb;
  8588. position = 0;
  8589. const interleave = subband.type !== "LL";
  8590. for (j = 0; j < blockHeight; j++) {
  8591. const row = offset / width | 0;
  8592. const levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  8593. for (k = 0; k < blockWidth; k++) {
  8594. n = magnitude[position];
  8595. if (n !== 0) {
  8596. n = (n + magnitudeCorrection) * delta;
  8597. if (sign[position] !== 0) {
  8598. n = -n;
  8599. }
  8600. nb = bitsDecoded[position];
  8601. const pos = interleave ? levelOffset + (offset << 1) : offset;
  8602. coefficients[pos] = reversible && nb >= mb ? n : n * (1 << mb - nb);
  8603. }
  8604. offset++;
  8605. position++;
  8606. }
  8607. offset += width - blockWidth;
  8608. }
  8609. }
  8610. }
  8611. function transformTile(context, tile, c) {
  8612. const component = tile.components[c];
  8613. const codingStyleParameters = component.codingStyleParameters;
  8614. const quantizationParameters = component.quantizationParameters;
  8615. const decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  8616. const spqcds = quantizationParameters.SPqcds;
  8617. const scalarExpounded = quantizationParameters.scalarExpounded;
  8618. const guardBits = quantizationParameters.guardBits;
  8619. const segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  8620. const resetContextProbabilities = codingStyleParameters.resetContextProbabilities;
  8621. const precision = context.components[c].precision;
  8622. const reversible = codingStyleParameters.reversibleTransformation;
  8623. const transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  8624. const subbandCoefficients = [];
  8625. let b = 0;
  8626. for (let i = 0; i <= decompositionLevelsCount; i++) {
  8627. const resolution = component.resolutions[i];
  8628. const width = resolution.trx1 - resolution.trx0;
  8629. const height = resolution.try1 - resolution.try0;
  8630. const coefficients = new Float32Array(width * height);
  8631. for (let j = 0, jj = resolution.subbands.length; j < jj; j++) {
  8632. let mu, epsilon;
  8633. if (!scalarExpounded) {
  8634. mu = spqcds[0].mu;
  8635. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  8636. } else {
  8637. mu = spqcds[b].mu;
  8638. epsilon = spqcds[b].epsilon;
  8639. b++;
  8640. }
  8641. const subband = resolution.subbands[j];
  8642. const gainLog2 = SubbandsGainLog2[subband.type];
  8643. const delta = reversible ? 1 : 2 ** (precision + gainLog2 - epsilon) * (1 + mu / 2048);
  8644. const mb = guardBits + epsilon - 1;
  8645. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed, resetContextProbabilities);
  8646. }
  8647. subbandCoefficients.push({
  8648. width,
  8649. height,
  8650. items: coefficients
  8651. });
  8652. }
  8653. const result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  8654. return {
  8655. left: component.tcx0,
  8656. top: component.tcy0,
  8657. width: result.width,
  8658. height: result.height,
  8659. items: result.items
  8660. };
  8661. }
  8662. function transformComponents(context) {
  8663. const siz = context.SIZ;
  8664. const components = context.components;
  8665. const componentsCount = siz.Csiz;
  8666. const resultImages = [];
  8667. for (let i = 0, ii = context.tiles.length; i < ii; i++) {
  8668. const tile = context.tiles[i];
  8669. const transformedTiles = [];
  8670. for (let c = 0; c < componentsCount; c++) {
  8671. transformedTiles[c] = transformTile(context, tile, c);
  8672. }
  8673. const tile0 = transformedTiles[0];
  8674. const out = new Uint8ClampedArray(tile0.items.length * componentsCount);
  8675. const result = {
  8676. left: tile0.left,
  8677. top: tile0.top,
  8678. width: tile0.width,
  8679. height: tile0.height,
  8680. items: out
  8681. };
  8682. let shift, offset;
  8683. let pos = 0,
  8684. j,
  8685. jj,
  8686. y0,
  8687. y1,
  8688. y2;
  8689. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  8690. const fourComponents = componentsCount === 4;
  8691. const y0items = transformedTiles[0].items;
  8692. const y1items = transformedTiles[1].items;
  8693. const y2items = transformedTiles[2].items;
  8694. const y3items = fourComponents ? transformedTiles[3].items : null;
  8695. shift = components[0].precision - 8;
  8696. offset = (128 << shift) + 0.5;
  8697. const component0 = tile.components[0];
  8698. const alpha01 = componentsCount - 3;
  8699. jj = y0items.length;
  8700. if (!component0.codingStyleParameters.reversibleTransformation) {
  8701. for (j = 0; j < jj; j++, pos += alpha01) {
  8702. y0 = y0items[j] + offset;
  8703. y1 = y1items[j];
  8704. y2 = y2items[j];
  8705. out[pos++] = y0 + 1.402 * y2 >> shift;
  8706. out[pos++] = y0 - 0.34413 * y1 - 0.71414 * y2 >> shift;
  8707. out[pos++] = y0 + 1.772 * y1 >> shift;
  8708. }
  8709. } else {
  8710. for (j = 0; j < jj; j++, pos += alpha01) {
  8711. y0 = y0items[j] + offset;
  8712. y1 = y1items[j];
  8713. y2 = y2items[j];
  8714. const g = y0 - (y2 + y1 >> 2);
  8715. out[pos++] = g + y2 >> shift;
  8716. out[pos++] = g >> shift;
  8717. out[pos++] = g + y1 >> shift;
  8718. }
  8719. }
  8720. if (fourComponents) {
  8721. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  8722. out[pos] = y3items[j] + offset >> shift;
  8723. }
  8724. }
  8725. } else {
  8726. for (let c = 0; c < componentsCount; c++) {
  8727. const items = transformedTiles[c].items;
  8728. shift = components[c].precision - 8;
  8729. offset = (128 << shift) + 0.5;
  8730. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  8731. out[pos] = items[j] + offset >> shift;
  8732. pos += componentsCount;
  8733. }
  8734. }
  8735. }
  8736. resultImages.push(result);
  8737. }
  8738. return resultImages;
  8739. }
  8740. function initializeTile(context, tileIndex) {
  8741. const siz = context.SIZ;
  8742. const componentsCount = siz.Csiz;
  8743. const tile = context.tiles[tileIndex];
  8744. for (let c = 0; c < componentsCount; c++) {
  8745. const component = tile.components[c];
  8746. const qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  8747. component.quantizationParameters = qcdOrQcc;
  8748. const codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  8749. component.codingStyleParameters = codOrCoc;
  8750. }
  8751. tile.codingStyleDefaultParameters = context.currentTile.COD;
  8752. }
  8753. class TagTree {
  8754. constructor(width, height) {
  8755. const levelsLength = log2(Math.max(width, height)) + 1;
  8756. this.levels = [];
  8757. for (let i = 0; i < levelsLength; i++) {
  8758. const level = {
  8759. width,
  8760. height,
  8761. items: []
  8762. };
  8763. this.levels.push(level);
  8764. width = Math.ceil(width / 2);
  8765. height = Math.ceil(height / 2);
  8766. }
  8767. }
  8768. reset(i, j) {
  8769. let currentLevel = 0,
  8770. value = 0,
  8771. level;
  8772. while (currentLevel < this.levels.length) {
  8773. level = this.levels[currentLevel];
  8774. const index = i + j * level.width;
  8775. if (level.items[index] !== undefined) {
  8776. value = level.items[index];
  8777. break;
  8778. }
  8779. level.index = index;
  8780. i >>= 1;
  8781. j >>= 1;
  8782. currentLevel++;
  8783. }
  8784. currentLevel--;
  8785. level = this.levels[currentLevel];
  8786. level.items[level.index] = value;
  8787. this.currentLevel = currentLevel;
  8788. delete this.value;
  8789. }
  8790. incrementValue() {
  8791. const level = this.levels[this.currentLevel];
  8792. level.items[level.index]++;
  8793. }
  8794. nextLevel() {
  8795. let currentLevel = this.currentLevel;
  8796. let level = this.levels[currentLevel];
  8797. const value = level.items[level.index];
  8798. currentLevel--;
  8799. if (currentLevel < 0) {
  8800. this.value = value;
  8801. return false;
  8802. }
  8803. this.currentLevel = currentLevel;
  8804. level = this.levels[currentLevel];
  8805. level.items[level.index] = value;
  8806. return true;
  8807. }
  8808. }
  8809. class InclusionTree {
  8810. constructor(width, height, defaultValue) {
  8811. const levelsLength = log2(Math.max(width, height)) + 1;
  8812. this.levels = [];
  8813. for (let i = 0; i < levelsLength; i++) {
  8814. const items = new Uint8Array(width * height);
  8815. for (let j = 0, jj = items.length; j < jj; j++) {
  8816. items[j] = defaultValue;
  8817. }
  8818. const level = {
  8819. width,
  8820. height,
  8821. items
  8822. };
  8823. this.levels.push(level);
  8824. width = Math.ceil(width / 2);
  8825. height = Math.ceil(height / 2);
  8826. }
  8827. }
  8828. reset(i, j, stopValue) {
  8829. let currentLevel = 0;
  8830. while (currentLevel < this.levels.length) {
  8831. const level = this.levels[currentLevel];
  8832. const index = i + j * level.width;
  8833. level.index = index;
  8834. const value = level.items[index];
  8835. if (value === 0xff) {
  8836. break;
  8837. }
  8838. if (value > stopValue) {
  8839. this.currentLevel = currentLevel;
  8840. this.propagateValues();
  8841. return false;
  8842. }
  8843. i >>= 1;
  8844. j >>= 1;
  8845. currentLevel++;
  8846. }
  8847. this.currentLevel = currentLevel - 1;
  8848. return true;
  8849. }
  8850. incrementValue(stopValue) {
  8851. const level = this.levels[this.currentLevel];
  8852. level.items[level.index] = stopValue + 1;
  8853. this.propagateValues();
  8854. }
  8855. propagateValues() {
  8856. let levelIndex = this.currentLevel;
  8857. let level = this.levels[levelIndex];
  8858. const currentValue = level.items[level.index];
  8859. while (--levelIndex >= 0) {
  8860. level = this.levels[levelIndex];
  8861. level.items[level.index] = currentValue;
  8862. }
  8863. }
  8864. nextLevel() {
  8865. let currentLevel = this.currentLevel;
  8866. let level = this.levels[currentLevel];
  8867. const value = level.items[level.index];
  8868. level.items[level.index] = 0xff;
  8869. currentLevel--;
  8870. if (currentLevel < 0) {
  8871. return false;
  8872. }
  8873. this.currentLevel = currentLevel;
  8874. level = this.levels[currentLevel];
  8875. level.items[level.index] = value;
  8876. return true;
  8877. }
  8878. }
  8879. class BitModel {
  8880. static UNIFORM_CONTEXT = 17;
  8881. static RUNLENGTH_CONTEXT = 18;
  8882. static LLAndLHContextsLabel = new Uint8Array([0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8]);
  8883. static HLContextLabel = new Uint8Array([0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8]);
  8884. static HHContextLabel = new Uint8Array([0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5, 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8]);
  8885. constructor(width, height, subband, zeroBitPlanes, mb) {
  8886. this.width = width;
  8887. this.height = height;
  8888. let contextLabelTable;
  8889. if (subband === "HH") {
  8890. contextLabelTable = BitModel.HHContextLabel;
  8891. } else if (subband === "HL") {
  8892. contextLabelTable = BitModel.HLContextLabel;
  8893. } else {
  8894. contextLabelTable = BitModel.LLAndLHContextsLabel;
  8895. }
  8896. this.contextLabelTable = contextLabelTable;
  8897. const coefficientCount = width * height;
  8898. this.neighborsSignificance = new Uint8Array(coefficientCount);
  8899. this.coefficentsSign = new Uint8Array(coefficientCount);
  8900. let coefficentsMagnitude;
  8901. if (mb > 14) {
  8902. coefficentsMagnitude = new Uint32Array(coefficientCount);
  8903. } else if (mb > 6) {
  8904. coefficentsMagnitude = new Uint16Array(coefficientCount);
  8905. } else {
  8906. coefficentsMagnitude = new Uint8Array(coefficientCount);
  8907. }
  8908. this.coefficentsMagnitude = coefficentsMagnitude;
  8909. this.processingFlags = new Uint8Array(coefficientCount);
  8910. const bitsDecoded = new Uint8Array(coefficientCount);
  8911. if (zeroBitPlanes !== 0) {
  8912. for (let i = 0; i < coefficientCount; i++) {
  8913. bitsDecoded[i] = zeroBitPlanes;
  8914. }
  8915. }
  8916. this.bitsDecoded = bitsDecoded;
  8917. this.reset();
  8918. }
  8919. setDecoder(decoder) {
  8920. this.decoder = decoder;
  8921. }
  8922. reset() {
  8923. this.contexts = new Int8Array(19);
  8924. this.contexts[0] = 4 << 1 | 0;
  8925. this.contexts[BitModel.UNIFORM_CONTEXT] = 46 << 1 | 0;
  8926. this.contexts[BitModel.RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  8927. }
  8928. setNeighborsSignificance(row, column, index) {
  8929. const neighborsSignificance = this.neighborsSignificance;
  8930. const width = this.width,
  8931. height = this.height;
  8932. const left = column > 0;
  8933. const right = column + 1 < width;
  8934. let i;
  8935. if (row > 0) {
  8936. i = index - width;
  8937. if (left) {
  8938. neighborsSignificance[i - 1] += 0x10;
  8939. }
  8940. if (right) {
  8941. neighborsSignificance[i + 1] += 0x10;
  8942. }
  8943. neighborsSignificance[i] += 0x04;
  8944. }
  8945. if (row + 1 < height) {
  8946. i = index + width;
  8947. if (left) {
  8948. neighborsSignificance[i - 1] += 0x10;
  8949. }
  8950. if (right) {
  8951. neighborsSignificance[i + 1] += 0x10;
  8952. }
  8953. neighborsSignificance[i] += 0x04;
  8954. }
  8955. if (left) {
  8956. neighborsSignificance[index - 1] += 0x01;
  8957. }
  8958. if (right) {
  8959. neighborsSignificance[index + 1] += 0x01;
  8960. }
  8961. neighborsSignificance[index] |= 0x80;
  8962. }
  8963. runSignificancePropagationPass() {
  8964. const decoder = this.decoder;
  8965. const width = this.width,
  8966. height = this.height;
  8967. const coefficentsMagnitude = this.coefficentsMagnitude;
  8968. const coefficentsSign = this.coefficentsSign;
  8969. const neighborsSignificance = this.neighborsSignificance;
  8970. const processingFlags = this.processingFlags;
  8971. const contexts = this.contexts;
  8972. const labels = this.contextLabelTable;
  8973. const bitsDecoded = this.bitsDecoded;
  8974. const processedInverseMask = ~1;
  8975. const processedMask = 1;
  8976. const firstMagnitudeBitMask = 2;
  8977. for (let i0 = 0; i0 < height; i0 += 4) {
  8978. for (let j = 0; j < width; j++) {
  8979. let index = i0 * width + j;
  8980. for (let i1 = 0; i1 < 4; i1++, index += width) {
  8981. const i = i0 + i1;
  8982. if (i >= height) {
  8983. break;
  8984. }
  8985. processingFlags[index] &= processedInverseMask;
  8986. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  8987. continue;
  8988. }
  8989. const contextLabel = labels[neighborsSignificance[index]];
  8990. const decision = decoder.readBit(contexts, contextLabel);
  8991. if (decision) {
  8992. const sign = this.decodeSignBit(i, j, index);
  8993. coefficentsSign[index] = sign;
  8994. coefficentsMagnitude[index] = 1;
  8995. this.setNeighborsSignificance(i, j, index);
  8996. processingFlags[index] |= firstMagnitudeBitMask;
  8997. }
  8998. bitsDecoded[index]++;
  8999. processingFlags[index] |= processedMask;
  9000. }
  9001. }
  9002. }
  9003. }
  9004. decodeSignBit(row, column, index) {
  9005. const width = this.width,
  9006. height = this.height;
  9007. const coefficentsMagnitude = this.coefficentsMagnitude;
  9008. const coefficentsSign = this.coefficentsSign;
  9009. let contribution, sign0, sign1, significance1;
  9010. let contextLabel, decoded;
  9011. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  9012. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  9013. sign1 = coefficentsSign[index + 1];
  9014. if (significance1) {
  9015. sign0 = coefficentsSign[index - 1];
  9016. contribution = 1 - sign1 - sign0;
  9017. } else {
  9018. contribution = 1 - sign1 - sign1;
  9019. }
  9020. } else if (significance1) {
  9021. sign0 = coefficentsSign[index - 1];
  9022. contribution = 1 - sign0 - sign0;
  9023. } else {
  9024. contribution = 0;
  9025. }
  9026. const horizontalContribution = 3 * contribution;
  9027. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  9028. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  9029. sign1 = coefficentsSign[index + width];
  9030. if (significance1) {
  9031. sign0 = coefficentsSign[index - width];
  9032. contribution = 1 - sign1 - sign0 + horizontalContribution;
  9033. } else {
  9034. contribution = 1 - sign1 - sign1 + horizontalContribution;
  9035. }
  9036. } else if (significance1) {
  9037. sign0 = coefficentsSign[index - width];
  9038. contribution = 1 - sign0 - sign0 + horizontalContribution;
  9039. } else {
  9040. contribution = horizontalContribution;
  9041. }
  9042. if (contribution >= 0) {
  9043. contextLabel = 9 + contribution;
  9044. decoded = this.decoder.readBit(this.contexts, contextLabel);
  9045. } else {
  9046. contextLabel = 9 - contribution;
  9047. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  9048. }
  9049. return decoded;
  9050. }
  9051. runMagnitudeRefinementPass() {
  9052. const decoder = this.decoder;
  9053. const width = this.width,
  9054. height = this.height;
  9055. const coefficentsMagnitude = this.coefficentsMagnitude;
  9056. const neighborsSignificance = this.neighborsSignificance;
  9057. const contexts = this.contexts;
  9058. const bitsDecoded = this.bitsDecoded;
  9059. const processingFlags = this.processingFlags;
  9060. const processedMask = 1;
  9061. const firstMagnitudeBitMask = 2;
  9062. const length = width * height;
  9063. const width4 = width * 4;
  9064. for (let index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  9065. indexNext = Math.min(length, index0 + width4);
  9066. for (let j = 0; j < width; j++) {
  9067. for (let index = index0 + j; index < indexNext; index += width) {
  9068. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  9069. continue;
  9070. }
  9071. let contextLabel = 16;
  9072. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  9073. processingFlags[index] ^= firstMagnitudeBitMask;
  9074. const significance = neighborsSignificance[index] & 127;
  9075. contextLabel = significance === 0 ? 15 : 14;
  9076. }
  9077. const bit = decoder.readBit(contexts, contextLabel);
  9078. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  9079. bitsDecoded[index]++;
  9080. processingFlags[index] |= processedMask;
  9081. }
  9082. }
  9083. }
  9084. }
  9085. runCleanupPass() {
  9086. const decoder = this.decoder;
  9087. const width = this.width,
  9088. height = this.height;
  9089. const neighborsSignificance = this.neighborsSignificance;
  9090. const coefficentsMagnitude = this.coefficentsMagnitude;
  9091. const coefficentsSign = this.coefficentsSign;
  9092. const contexts = this.contexts;
  9093. const labels = this.contextLabelTable;
  9094. const bitsDecoded = this.bitsDecoded;
  9095. const processingFlags = this.processingFlags;
  9096. const processedMask = 1;
  9097. const firstMagnitudeBitMask = 2;
  9098. const oneRowDown = width;
  9099. const twoRowsDown = width * 2;
  9100. const threeRowsDown = width * 3;
  9101. let iNext;
  9102. for (let i0 = 0; i0 < height; i0 = iNext) {
  9103. iNext = Math.min(i0 + 4, height);
  9104. const indexBase = i0 * width;
  9105. const checkAllEmpty = i0 + 3 < height;
  9106. for (let j = 0; j < width; j++) {
  9107. const index0 = indexBase + j;
  9108. const 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;
  9109. let i1 = 0,
  9110. index = index0;
  9111. let i = i0,
  9112. sign;
  9113. if (allEmpty) {
  9114. const hasSignificantCoefficent = decoder.readBit(contexts, BitModel.RUNLENGTH_CONTEXT);
  9115. if (!hasSignificantCoefficent) {
  9116. bitsDecoded[index0]++;
  9117. bitsDecoded[index0 + oneRowDown]++;
  9118. bitsDecoded[index0 + twoRowsDown]++;
  9119. bitsDecoded[index0 + threeRowsDown]++;
  9120. continue;
  9121. }
  9122. i1 = decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT);
  9123. if (i1 !== 0) {
  9124. i = i0 + i1;
  9125. index += i1 * width;
  9126. }
  9127. sign = this.decodeSignBit(i, j, index);
  9128. coefficentsSign[index] = sign;
  9129. coefficentsMagnitude[index] = 1;
  9130. this.setNeighborsSignificance(i, j, index);
  9131. processingFlags[index] |= firstMagnitudeBitMask;
  9132. index = index0;
  9133. for (let i2 = i0; i2 <= i; i2++, index += width) {
  9134. bitsDecoded[index]++;
  9135. }
  9136. i1++;
  9137. }
  9138. for (i = i0 + i1; i < iNext; i++, index += width) {
  9139. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  9140. continue;
  9141. }
  9142. const contextLabel = labels[neighborsSignificance[index]];
  9143. const decision = decoder.readBit(contexts, contextLabel);
  9144. if (decision === 1) {
  9145. sign = this.decodeSignBit(i, j, index);
  9146. coefficentsSign[index] = sign;
  9147. coefficentsMagnitude[index] = 1;
  9148. this.setNeighborsSignificance(i, j, index);
  9149. processingFlags[index] |= firstMagnitudeBitMask;
  9150. }
  9151. bitsDecoded[index]++;
  9152. }
  9153. }
  9154. }
  9155. }
  9156. checkSegmentationSymbol() {
  9157. const decoder = this.decoder;
  9158. const contexts = this.contexts;
  9159. const symbol = decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, BitModel.UNIFORM_CONTEXT);
  9160. if (symbol !== 0xa) {
  9161. throw new JpxError("Invalid segmentation symbol");
  9162. }
  9163. }
  9164. }
  9165. class Transform {
  9166. constructor() {
  9167. if (this.constructor === Transform) {
  9168. unreachable("Cannot initialize Transform.");
  9169. }
  9170. }
  9171. calculate(subbands, u0, v0) {
  9172. let ll = subbands[0];
  9173. for (let i = 1, ii = subbands.length; i < ii; i++) {
  9174. ll = this.iterate(ll, subbands[i], u0, v0);
  9175. }
  9176. return ll;
  9177. }
  9178. extend(buffer, offset, size) {
  9179. let i1 = offset - 1,
  9180. j1 = offset + 1;
  9181. let i2 = offset + size - 2,
  9182. j2 = offset + size;
  9183. buffer[i1--] = buffer[j1++];
  9184. buffer[j2++] = buffer[i2--];
  9185. buffer[i1--] = buffer[j1++];
  9186. buffer[j2++] = buffer[i2--];
  9187. buffer[i1--] = buffer[j1++];
  9188. buffer[j2++] = buffer[i2--];
  9189. buffer[i1] = buffer[j1];
  9190. buffer[j2] = buffer[i2];
  9191. }
  9192. filter(x, offset, length) {
  9193. unreachable("Abstract method `filter` called");
  9194. }
  9195. iterate(ll, hl_lh_hh, u0, v0) {
  9196. const llWidth = ll.width,
  9197. llHeight = ll.height;
  9198. let llItems = ll.items;
  9199. const width = hl_lh_hh.width;
  9200. const height = hl_lh_hh.height;
  9201. const items = hl_lh_hh.items;
  9202. let i, j, k, l, u, v;
  9203. for (k = 0, i = 0; i < llHeight; i++) {
  9204. l = i * 2 * width;
  9205. for (j = 0; j < llWidth; j++, k++, l += 2) {
  9206. items[l] = llItems[k];
  9207. }
  9208. }
  9209. llItems = ll.items = null;
  9210. const bufferPadding = 4;
  9211. const rowBuffer = new Float32Array(width + 2 * bufferPadding);
  9212. if (width === 1) {
  9213. if ((u0 & 1) !== 0) {
  9214. for (v = 0, k = 0; v < height; v++, k += width) {
  9215. items[k] *= 0.5;
  9216. }
  9217. }
  9218. } else {
  9219. for (v = 0, k = 0; v < height; v++, k += width) {
  9220. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  9221. this.extend(rowBuffer, bufferPadding, width);
  9222. this.filter(rowBuffer, bufferPadding, width);
  9223. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  9224. }
  9225. }
  9226. let numBuffers = 16;
  9227. const colBuffers = [];
  9228. for (i = 0; i < numBuffers; i++) {
  9229. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  9230. }
  9231. let b,
  9232. currentBuffer = 0;
  9233. ll = bufferPadding + height;
  9234. if (height === 1) {
  9235. if ((v0 & 1) !== 0) {
  9236. for (u = 0; u < width; u++) {
  9237. items[u] *= 0.5;
  9238. }
  9239. }
  9240. } else {
  9241. for (u = 0; u < width; u++) {
  9242. if (currentBuffer === 0) {
  9243. numBuffers = Math.min(width - u, numBuffers);
  9244. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  9245. for (b = 0; b < numBuffers; b++) {
  9246. colBuffers[b][l] = items[k + b];
  9247. }
  9248. }
  9249. currentBuffer = numBuffers;
  9250. }
  9251. currentBuffer--;
  9252. const buffer = colBuffers[currentBuffer];
  9253. this.extend(buffer, bufferPadding, height);
  9254. this.filter(buffer, bufferPadding, height);
  9255. if (currentBuffer === 0) {
  9256. k = u - numBuffers + 1;
  9257. for (l = bufferPadding; l < ll; k += width, l++) {
  9258. for (b = 0; b < numBuffers; b++) {
  9259. items[k + b] = colBuffers[b][l];
  9260. }
  9261. }
  9262. }
  9263. }
  9264. }
  9265. return {
  9266. width,
  9267. height,
  9268. items
  9269. };
  9270. }
  9271. }
  9272. class IrreversibleTransform extends Transform {
  9273. filter(x, offset, length) {
  9274. const len = length >> 1;
  9275. offset |= 0;
  9276. let j, n, current, next;
  9277. const alpha = -1.586134342059924;
  9278. const beta = -0.052980118572961;
  9279. const gamma = 0.882911075530934;
  9280. const delta = 0.443506852043971;
  9281. const K = 1.230174104914001;
  9282. const K_ = 1 / K;
  9283. j = offset - 3;
  9284. for (n = len + 4; n--; j += 2) {
  9285. x[j] *= K_;
  9286. }
  9287. j = offset - 2;
  9288. current = delta * x[j - 1];
  9289. for (n = len + 3; n--; j += 2) {
  9290. next = delta * x[j + 1];
  9291. x[j] = K * x[j] - current - next;
  9292. if (n--) {
  9293. j += 2;
  9294. current = delta * x[j + 1];
  9295. x[j] = K * x[j] - current - next;
  9296. } else {
  9297. break;
  9298. }
  9299. }
  9300. j = offset - 1;
  9301. current = gamma * x[j - 1];
  9302. for (n = len + 2; n--; j += 2) {
  9303. next = gamma * x[j + 1];
  9304. x[j] -= current + next;
  9305. if (n--) {
  9306. j += 2;
  9307. current = gamma * x[j + 1];
  9308. x[j] -= current + next;
  9309. } else {
  9310. break;
  9311. }
  9312. }
  9313. j = offset;
  9314. current = beta * x[j - 1];
  9315. for (n = len + 1; n--; j += 2) {
  9316. next = beta * x[j + 1];
  9317. x[j] -= current + next;
  9318. if (n--) {
  9319. j += 2;
  9320. current = beta * x[j + 1];
  9321. x[j] -= current + next;
  9322. } else {
  9323. break;
  9324. }
  9325. }
  9326. if (len !== 0) {
  9327. j = offset + 1;
  9328. current = alpha * x[j - 1];
  9329. for (n = len; n--; j += 2) {
  9330. next = alpha * x[j + 1];
  9331. x[j] -= current + next;
  9332. if (n--) {
  9333. j += 2;
  9334. current = alpha * x[j + 1];
  9335. x[j] -= current + next;
  9336. } else {
  9337. break;
  9338. }
  9339. }
  9340. }
  9341. }
  9342. }
  9343. class ReversibleTransform extends Transform {
  9344. filter(x, offset, length) {
  9345. const len = length >> 1;
  9346. offset |= 0;
  9347. let j, n;
  9348. for (j = offset, n = len + 1; n--; j += 2) {
  9349. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  9350. }
  9351. for (j = offset + 1, n = len; n--; j += 2) {
  9352. x[j] += x[j - 1] + x[j + 1] >> 1;
  9353. }
  9354. }
  9355. }
  9356. ;// CONCATENATED MODULE: ./src/core/jpx_stream.js
  9357. class JpxStream extends DecodeStream {
  9358. constructor(stream, maybeLength, params) {
  9359. super(maybeLength);
  9360. this.stream = stream;
  9361. this.dict = stream.dict;
  9362. this.maybeLength = maybeLength;
  9363. this.params = params;
  9364. }
  9365. get bytes() {
  9366. return shadow(this, "bytes", this.stream.getBytes(this.maybeLength));
  9367. }
  9368. ensureBuffer(requested) {}
  9369. readBlock() {
  9370. if (this.eof) {
  9371. return;
  9372. }
  9373. const jpxImage = new JpxImage();
  9374. jpxImage.parse(this.bytes);
  9375. const width = jpxImage.width;
  9376. const height = jpxImage.height;
  9377. const componentsCount = jpxImage.componentsCount;
  9378. const tileCount = jpxImage.tiles.length;
  9379. if (tileCount === 1) {
  9380. this.buffer = jpxImage.tiles[0].items;
  9381. } else {
  9382. const data = new Uint8ClampedArray(width * height * componentsCount);
  9383. for (let k = 0; k < tileCount; k++) {
  9384. const tileComponents = jpxImage.tiles[k];
  9385. const tileWidth = tileComponents.width;
  9386. const tileHeight = tileComponents.height;
  9387. const tileLeft = tileComponents.left;
  9388. const tileTop = tileComponents.top;
  9389. const src = tileComponents.items;
  9390. let srcPosition = 0;
  9391. let dataPosition = (width * tileTop + tileLeft) * componentsCount;
  9392. const imgRowSize = width * componentsCount;
  9393. const tileRowSize = tileWidth * componentsCount;
  9394. for (let j = 0; j < tileHeight; j++) {
  9395. const rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  9396. data.set(rowBytes, dataPosition);
  9397. srcPosition += tileRowSize;
  9398. dataPosition += imgRowSize;
  9399. }
  9400. }
  9401. this.buffer = data;
  9402. }
  9403. this.bufferLength = this.buffer.length;
  9404. this.eof = true;
  9405. }
  9406. }
  9407. ;// CONCATENATED MODULE: ./src/core/lzw_stream.js
  9408. class LZWStream extends DecodeStream {
  9409. constructor(str, maybeLength, earlyChange) {
  9410. super(maybeLength);
  9411. this.str = str;
  9412. this.dict = str.dict;
  9413. this.cachedData = 0;
  9414. this.bitsCached = 0;
  9415. const maxLzwDictionarySize = 4096;
  9416. const lzwState = {
  9417. earlyChange,
  9418. codeLength: 9,
  9419. nextCode: 258,
  9420. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  9421. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  9422. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  9423. currentSequence: new Uint8Array(maxLzwDictionarySize),
  9424. currentSequenceLength: 0
  9425. };
  9426. for (let i = 0; i < 256; ++i) {
  9427. lzwState.dictionaryValues[i] = i;
  9428. lzwState.dictionaryLengths[i] = 1;
  9429. }
  9430. this.lzwState = lzwState;
  9431. }
  9432. readBits(n) {
  9433. let bitsCached = this.bitsCached;
  9434. let cachedData = this.cachedData;
  9435. while (bitsCached < n) {
  9436. const c = this.str.getByte();
  9437. if (c === -1) {
  9438. this.eof = true;
  9439. return null;
  9440. }
  9441. cachedData = cachedData << 8 | c;
  9442. bitsCached += 8;
  9443. }
  9444. this.bitsCached = bitsCached -= n;
  9445. this.cachedData = cachedData;
  9446. this.lastCode = null;
  9447. return cachedData >>> bitsCached & (1 << n) - 1;
  9448. }
  9449. readBlock() {
  9450. const blockSize = 512,
  9451. decodedSizeDelta = blockSize;
  9452. let estimatedDecodedSize = blockSize * 2;
  9453. let i, j, q;
  9454. const lzwState = this.lzwState;
  9455. if (!lzwState) {
  9456. return;
  9457. }
  9458. const earlyChange = lzwState.earlyChange;
  9459. let nextCode = lzwState.nextCode;
  9460. const dictionaryValues = lzwState.dictionaryValues;
  9461. const dictionaryLengths = lzwState.dictionaryLengths;
  9462. const dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  9463. let codeLength = lzwState.codeLength;
  9464. let prevCode = lzwState.prevCode;
  9465. const currentSequence = lzwState.currentSequence;
  9466. let currentSequenceLength = lzwState.currentSequenceLength;
  9467. let decodedLength = 0;
  9468. let currentBufferLength = this.bufferLength;
  9469. let buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  9470. for (i = 0; i < blockSize; i++) {
  9471. const code = this.readBits(codeLength);
  9472. const hasPrev = currentSequenceLength > 0;
  9473. if (code < 256) {
  9474. currentSequence[0] = code;
  9475. currentSequenceLength = 1;
  9476. } else if (code >= 258) {
  9477. if (code < nextCode) {
  9478. currentSequenceLength = dictionaryLengths[code];
  9479. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  9480. currentSequence[j] = dictionaryValues[q];
  9481. q = dictionaryPrevCodes[q];
  9482. }
  9483. } else {
  9484. currentSequence[currentSequenceLength++] = currentSequence[0];
  9485. }
  9486. } else if (code === 256) {
  9487. codeLength = 9;
  9488. nextCode = 258;
  9489. currentSequenceLength = 0;
  9490. continue;
  9491. } else {
  9492. this.eof = true;
  9493. delete this.lzwState;
  9494. break;
  9495. }
  9496. if (hasPrev) {
  9497. dictionaryPrevCodes[nextCode] = prevCode;
  9498. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  9499. dictionaryValues[nextCode] = currentSequence[0];
  9500. nextCode++;
  9501. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  9502. }
  9503. prevCode = code;
  9504. decodedLength += currentSequenceLength;
  9505. if (estimatedDecodedSize < decodedLength) {
  9506. do {
  9507. estimatedDecodedSize += decodedSizeDelta;
  9508. } while (estimatedDecodedSize < decodedLength);
  9509. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  9510. }
  9511. for (j = 0; j < currentSequenceLength; j++) {
  9512. buffer[currentBufferLength++] = currentSequence[j];
  9513. }
  9514. }
  9515. lzwState.nextCode = nextCode;
  9516. lzwState.codeLength = codeLength;
  9517. lzwState.prevCode = prevCode;
  9518. lzwState.currentSequenceLength = currentSequenceLength;
  9519. this.bufferLength = currentBufferLength;
  9520. }
  9521. }
  9522. ;// CONCATENATED MODULE: ./src/core/predictor_stream.js
  9523. class PredictorStream extends DecodeStream {
  9524. constructor(str, maybeLength, params) {
  9525. super(maybeLength);
  9526. if (!(params instanceof Dict)) {
  9527. return str;
  9528. }
  9529. const predictor = this.predictor = params.get("Predictor") || 1;
  9530. if (predictor <= 1) {
  9531. return str;
  9532. }
  9533. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  9534. throw new FormatError(`Unsupported predictor: ${predictor}`);
  9535. }
  9536. this.readBlock = predictor === 2 ? this.readBlockTiff : this.readBlockPng;
  9537. this.str = str;
  9538. this.dict = str.dict;
  9539. const colors = this.colors = params.get("Colors") || 1;
  9540. const bits = this.bits = params.get("BPC", "BitsPerComponent") || 8;
  9541. const columns = this.columns = params.get("Columns") || 1;
  9542. this.pixBytes = colors * bits + 7 >> 3;
  9543. this.rowBytes = columns * colors * bits + 7 >> 3;
  9544. return this;
  9545. }
  9546. readBlockTiff() {
  9547. const rowBytes = this.rowBytes;
  9548. const bufferLength = this.bufferLength;
  9549. const buffer = this.ensureBuffer(bufferLength + rowBytes);
  9550. const bits = this.bits;
  9551. const colors = this.colors;
  9552. const rawBytes = this.str.getBytes(rowBytes);
  9553. this.eof = !rawBytes.length;
  9554. if (this.eof) {
  9555. return;
  9556. }
  9557. let inbuf = 0,
  9558. outbuf = 0;
  9559. let inbits = 0,
  9560. outbits = 0;
  9561. let pos = bufferLength;
  9562. let i;
  9563. if (bits === 1 && colors === 1) {
  9564. for (i = 0; i < rowBytes; ++i) {
  9565. let c = rawBytes[i] ^ inbuf;
  9566. c ^= c >> 1;
  9567. c ^= c >> 2;
  9568. c ^= c >> 4;
  9569. inbuf = (c & 1) << 7;
  9570. buffer[pos++] = c;
  9571. }
  9572. } else if (bits === 8) {
  9573. for (i = 0; i < colors; ++i) {
  9574. buffer[pos++] = rawBytes[i];
  9575. }
  9576. for (; i < rowBytes; ++i) {
  9577. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  9578. pos++;
  9579. }
  9580. } else if (bits === 16) {
  9581. const bytesPerPixel = colors * 2;
  9582. for (i = 0; i < bytesPerPixel; ++i) {
  9583. buffer[pos++] = rawBytes[i];
  9584. }
  9585. for (; i < rowBytes; i += 2) {
  9586. const sum = ((rawBytes[i] & 0xff) << 8) + (rawBytes[i + 1] & 0xff) + ((buffer[pos - bytesPerPixel] & 0xff) << 8) + (buffer[pos - bytesPerPixel + 1] & 0xff);
  9587. buffer[pos++] = sum >> 8 & 0xff;
  9588. buffer[pos++] = sum & 0xff;
  9589. }
  9590. } else {
  9591. const compArray = new Uint8Array(colors + 1);
  9592. const bitMask = (1 << bits) - 1;
  9593. let j = 0,
  9594. k = bufferLength;
  9595. const columns = this.columns;
  9596. for (i = 0; i < columns; ++i) {
  9597. for (let kk = 0; kk < colors; ++kk) {
  9598. if (inbits < bits) {
  9599. inbuf = inbuf << 8 | rawBytes[j++] & 0xff;
  9600. inbits += 8;
  9601. }
  9602. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  9603. inbits -= bits;
  9604. outbuf = outbuf << bits | compArray[kk];
  9605. outbits += bits;
  9606. if (outbits >= 8) {
  9607. buffer[k++] = outbuf >> outbits - 8 & 0xff;
  9608. outbits -= 8;
  9609. }
  9610. }
  9611. }
  9612. if (outbits > 0) {
  9613. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  9614. }
  9615. }
  9616. this.bufferLength += rowBytes;
  9617. }
  9618. readBlockPng() {
  9619. const rowBytes = this.rowBytes;
  9620. const pixBytes = this.pixBytes;
  9621. const predictor = this.str.getByte();
  9622. const rawBytes = this.str.getBytes(rowBytes);
  9623. this.eof = !rawBytes.length;
  9624. if (this.eof) {
  9625. return;
  9626. }
  9627. const bufferLength = this.bufferLength;
  9628. const buffer = this.ensureBuffer(bufferLength + rowBytes);
  9629. let prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  9630. if (prevRow.length === 0) {
  9631. prevRow = new Uint8Array(rowBytes);
  9632. }
  9633. let i,
  9634. j = bufferLength,
  9635. up,
  9636. c;
  9637. switch (predictor) {
  9638. case 0:
  9639. for (i = 0; i < rowBytes; ++i) {
  9640. buffer[j++] = rawBytes[i];
  9641. }
  9642. break;
  9643. case 1:
  9644. for (i = 0; i < pixBytes; ++i) {
  9645. buffer[j++] = rawBytes[i];
  9646. }
  9647. for (; i < rowBytes; ++i) {
  9648. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xff;
  9649. j++;
  9650. }
  9651. break;
  9652. case 2:
  9653. for (i = 0; i < rowBytes; ++i) {
  9654. buffer[j++] = prevRow[i] + rawBytes[i] & 0xff;
  9655. }
  9656. break;
  9657. case 3:
  9658. for (i = 0; i < pixBytes; ++i) {
  9659. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  9660. }
  9661. for (; i < rowBytes; ++i) {
  9662. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xff;
  9663. j++;
  9664. }
  9665. break;
  9666. case 4:
  9667. for (i = 0; i < pixBytes; ++i) {
  9668. up = prevRow[i];
  9669. c = rawBytes[i];
  9670. buffer[j++] = up + c;
  9671. }
  9672. for (; i < rowBytes; ++i) {
  9673. up = prevRow[i];
  9674. const upLeft = prevRow[i - pixBytes];
  9675. const left = buffer[j - pixBytes];
  9676. const p = left + up - upLeft;
  9677. let pa = p - left;
  9678. if (pa < 0) {
  9679. pa = -pa;
  9680. }
  9681. let pb = p - up;
  9682. if (pb < 0) {
  9683. pb = -pb;
  9684. }
  9685. let pc = p - upLeft;
  9686. if (pc < 0) {
  9687. pc = -pc;
  9688. }
  9689. c = rawBytes[i];
  9690. if (pa <= pb && pa <= pc) {
  9691. buffer[j++] = left + c;
  9692. } else if (pb <= pc) {
  9693. buffer[j++] = up + c;
  9694. } else {
  9695. buffer[j++] = upLeft + c;
  9696. }
  9697. }
  9698. break;
  9699. default:
  9700. throw new FormatError(`Unsupported predictor: ${predictor}`);
  9701. }
  9702. this.bufferLength += rowBytes;
  9703. }
  9704. }
  9705. ;// CONCATENATED MODULE: ./src/core/run_length_stream.js
  9706. class RunLengthStream extends DecodeStream {
  9707. constructor(str, maybeLength) {
  9708. super(maybeLength);
  9709. this.str = str;
  9710. this.dict = str.dict;
  9711. }
  9712. readBlock() {
  9713. const repeatHeader = this.str.getBytes(2);
  9714. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  9715. this.eof = true;
  9716. return;
  9717. }
  9718. let buffer;
  9719. let bufferLength = this.bufferLength;
  9720. let n = repeatHeader[0];
  9721. if (n < 128) {
  9722. buffer = this.ensureBuffer(bufferLength + n + 1);
  9723. buffer[bufferLength++] = repeatHeader[1];
  9724. if (n > 0) {
  9725. const source = this.str.getBytes(n);
  9726. buffer.set(source, bufferLength);
  9727. bufferLength += n;
  9728. }
  9729. } else {
  9730. n = 257 - n;
  9731. const b = repeatHeader[1];
  9732. buffer = this.ensureBuffer(bufferLength + n + 1);
  9733. for (let i = 0; i < n; i++) {
  9734. buffer[bufferLength++] = b;
  9735. }
  9736. }
  9737. this.bufferLength = bufferLength;
  9738. }
  9739. }
  9740. ;// CONCATENATED MODULE: ./src/core/parser.js
  9741. const MAX_LENGTH_TO_CACHE = 1000;
  9742. function getInlineImageCacheKey(bytes) {
  9743. const strBuf = [],
  9744. ii = bytes.length;
  9745. let i = 0;
  9746. while (i < ii - 1) {
  9747. strBuf.push(bytes[i++] << 8 | bytes[i++]);
  9748. }
  9749. if (i < ii) {
  9750. strBuf.push(bytes[i]);
  9751. }
  9752. return ii + "_" + String.fromCharCode.apply(null, strBuf);
  9753. }
  9754. class Parser {
  9755. constructor({
  9756. lexer,
  9757. xref,
  9758. allowStreams = false,
  9759. recoveryMode = false
  9760. }) {
  9761. this.lexer = lexer;
  9762. this.xref = xref;
  9763. this.allowStreams = allowStreams;
  9764. this.recoveryMode = recoveryMode;
  9765. this.imageCache = Object.create(null);
  9766. this._imageId = 0;
  9767. this.refill();
  9768. }
  9769. refill() {
  9770. this.buf1 = this.lexer.getObj();
  9771. this.buf2 = this.lexer.getObj();
  9772. }
  9773. shift() {
  9774. if (this.buf2 instanceof Cmd && this.buf2.cmd === "ID") {
  9775. this.buf1 = this.buf2;
  9776. this.buf2 = null;
  9777. } else {
  9778. this.buf1 = this.buf2;
  9779. this.buf2 = this.lexer.getObj();
  9780. }
  9781. }
  9782. tryShift() {
  9783. try {
  9784. this.shift();
  9785. return true;
  9786. } catch (e) {
  9787. if (e instanceof MissingDataException) {
  9788. throw e;
  9789. }
  9790. return false;
  9791. }
  9792. }
  9793. getObj(cipherTransform = null) {
  9794. const buf1 = this.buf1;
  9795. this.shift();
  9796. if (buf1 instanceof Cmd) {
  9797. switch (buf1.cmd) {
  9798. case "BI":
  9799. return this.makeInlineImage(cipherTransform);
  9800. case "[":
  9801. const array = [];
  9802. while (!isCmd(this.buf1, "]") && this.buf1 !== EOF) {
  9803. array.push(this.getObj(cipherTransform));
  9804. }
  9805. if (this.buf1 === EOF) {
  9806. if (this.recoveryMode) {
  9807. return array;
  9808. }
  9809. throw new ParserEOFException("End of file inside array.");
  9810. }
  9811. this.shift();
  9812. return array;
  9813. case "<<":
  9814. const dict = new Dict(this.xref);
  9815. while (!isCmd(this.buf1, ">>") && this.buf1 !== EOF) {
  9816. if (!(this.buf1 instanceof Name)) {
  9817. info("Malformed dictionary: key must be a name object");
  9818. this.shift();
  9819. continue;
  9820. }
  9821. const key = this.buf1.name;
  9822. this.shift();
  9823. if (this.buf1 === EOF) {
  9824. break;
  9825. }
  9826. dict.set(key, this.getObj(cipherTransform));
  9827. }
  9828. if (this.buf1 === EOF) {
  9829. if (this.recoveryMode) {
  9830. return dict;
  9831. }
  9832. throw new ParserEOFException("End of file inside dictionary.");
  9833. }
  9834. if (isCmd(this.buf2, "stream")) {
  9835. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  9836. }
  9837. this.shift();
  9838. return dict;
  9839. default:
  9840. return buf1;
  9841. }
  9842. }
  9843. if (Number.isInteger(buf1)) {
  9844. if (Number.isInteger(this.buf1) && isCmd(this.buf2, "R")) {
  9845. const ref = Ref.get(buf1, this.buf1);
  9846. this.shift();
  9847. this.shift();
  9848. return ref;
  9849. }
  9850. return buf1;
  9851. }
  9852. if (typeof buf1 === "string") {
  9853. if (cipherTransform) {
  9854. return cipherTransform.decryptString(buf1);
  9855. }
  9856. return buf1;
  9857. }
  9858. return buf1;
  9859. }
  9860. findDefaultInlineStreamEnd(stream) {
  9861. const E = 0x45,
  9862. I = 0x49,
  9863. SPACE = 0x20,
  9864. LF = 0xa,
  9865. CR = 0xd,
  9866. NUL = 0x0;
  9867. const {
  9868. knownCommands
  9869. } = this.lexer,
  9870. startPos = stream.pos,
  9871. n = 15;
  9872. let state = 0,
  9873. ch,
  9874. maybeEIPos;
  9875. while ((ch = stream.getByte()) !== -1) {
  9876. if (state === 0) {
  9877. state = ch === E ? 1 : 0;
  9878. } else if (state === 1) {
  9879. state = ch === I ? 2 : 0;
  9880. } else {
  9881. if (ch === SPACE || ch === LF || ch === CR) {
  9882. maybeEIPos = stream.pos;
  9883. const followingBytes = stream.peekBytes(n);
  9884. const ii = followingBytes.length;
  9885. if (ii === 0) {
  9886. break;
  9887. }
  9888. for (let i = 0; i < ii; i++) {
  9889. ch = followingBytes[i];
  9890. if (ch === NUL && followingBytes[i + 1] !== NUL) {
  9891. continue;
  9892. }
  9893. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7f)) {
  9894. state = 0;
  9895. break;
  9896. }
  9897. }
  9898. if (state !== 2) {
  9899. continue;
  9900. }
  9901. if (!knownCommands) {
  9902. warn("findDefaultInlineStreamEnd - `lexer.knownCommands` is undefined.");
  9903. continue;
  9904. }
  9905. const tmpLexer = new Lexer(new Stream(followingBytes.slice()), knownCommands);
  9906. tmpLexer._hexStringWarn = () => {};
  9907. let numArgs = 0;
  9908. while (true) {
  9909. const nextObj = tmpLexer.getObj();
  9910. if (nextObj === EOF) {
  9911. state = 0;
  9912. break;
  9913. }
  9914. if (nextObj instanceof Cmd) {
  9915. const knownCommand = knownCommands[nextObj.cmd];
  9916. if (!knownCommand) {
  9917. state = 0;
  9918. break;
  9919. } else if (knownCommand.variableArgs ? numArgs <= knownCommand.numArgs : numArgs === knownCommand.numArgs) {
  9920. break;
  9921. }
  9922. numArgs = 0;
  9923. continue;
  9924. }
  9925. numArgs++;
  9926. }
  9927. if (state === 2) {
  9928. break;
  9929. }
  9930. } else {
  9931. state = 0;
  9932. }
  9933. }
  9934. }
  9935. if (ch === -1) {
  9936. warn("findDefaultInlineStreamEnd: " + "Reached the end of the stream without finding a valid EI marker");
  9937. if (maybeEIPos) {
  9938. warn('... trying to recover by using the last "EI" occurrence.');
  9939. stream.skip(-(stream.pos - maybeEIPos));
  9940. }
  9941. }
  9942. let endOffset = 4;
  9943. stream.skip(-endOffset);
  9944. ch = stream.peekByte();
  9945. stream.skip(endOffset);
  9946. if (!isWhiteSpace(ch)) {
  9947. endOffset--;
  9948. }
  9949. return stream.pos - endOffset - startPos;
  9950. }
  9951. findDCTDecodeInlineStreamEnd(stream) {
  9952. const startPos = stream.pos;
  9953. let foundEOI = false,
  9954. b,
  9955. markerLength;
  9956. while ((b = stream.getByte()) !== -1) {
  9957. if (b !== 0xff) {
  9958. continue;
  9959. }
  9960. switch (stream.getByte()) {
  9961. case 0x00:
  9962. break;
  9963. case 0xff:
  9964. stream.skip(-1);
  9965. break;
  9966. case 0xd9:
  9967. foundEOI = true;
  9968. break;
  9969. case 0xc0:
  9970. case 0xc1:
  9971. case 0xc2:
  9972. case 0xc3:
  9973. case 0xc5:
  9974. case 0xc6:
  9975. case 0xc7:
  9976. case 0xc9:
  9977. case 0xca:
  9978. case 0xcb:
  9979. case 0xcd:
  9980. case 0xce:
  9981. case 0xcf:
  9982. case 0xc4:
  9983. case 0xcc:
  9984. case 0xda:
  9985. case 0xdb:
  9986. case 0xdc:
  9987. case 0xdd:
  9988. case 0xde:
  9989. case 0xdf:
  9990. case 0xe0:
  9991. case 0xe1:
  9992. case 0xe2:
  9993. case 0xe3:
  9994. case 0xe4:
  9995. case 0xe5:
  9996. case 0xe6:
  9997. case 0xe7:
  9998. case 0xe8:
  9999. case 0xe9:
  10000. case 0xea:
  10001. case 0xeb:
  10002. case 0xec:
  10003. case 0xed:
  10004. case 0xee:
  10005. case 0xef:
  10006. case 0xfe:
  10007. markerLength = stream.getUint16();
  10008. if (markerLength > 2) {
  10009. stream.skip(markerLength - 2);
  10010. } else {
  10011. stream.skip(-2);
  10012. }
  10013. break;
  10014. }
  10015. if (foundEOI) {
  10016. break;
  10017. }
  10018. }
  10019. const length = stream.pos - startPos;
  10020. if (b === -1) {
  10021. warn("Inline DCTDecode image stream: " + "EOI marker not found, searching for /EI/ instead.");
  10022. stream.skip(-length);
  10023. return this.findDefaultInlineStreamEnd(stream);
  10024. }
  10025. this.inlineStreamSkipEI(stream);
  10026. return length;
  10027. }
  10028. findASCII85DecodeInlineStreamEnd(stream) {
  10029. const TILDE = 0x7e,
  10030. GT = 0x3e;
  10031. const startPos = stream.pos;
  10032. let ch;
  10033. while ((ch = stream.getByte()) !== -1) {
  10034. if (ch === TILDE) {
  10035. const tildePos = stream.pos;
  10036. ch = stream.peekByte();
  10037. while (isWhiteSpace(ch)) {
  10038. stream.skip();
  10039. ch = stream.peekByte();
  10040. }
  10041. if (ch === GT) {
  10042. stream.skip();
  10043. break;
  10044. }
  10045. if (stream.pos > tildePos) {
  10046. const maybeEI = stream.peekBytes(2);
  10047. if (maybeEI[0] === 0x45 && maybeEI[1] === 0x49) {
  10048. break;
  10049. }
  10050. }
  10051. }
  10052. }
  10053. const length = stream.pos - startPos;
  10054. if (ch === -1) {
  10055. warn("Inline ASCII85Decode image stream: " + "EOD marker not found, searching for /EI/ instead.");
  10056. stream.skip(-length);
  10057. return this.findDefaultInlineStreamEnd(stream);
  10058. }
  10059. this.inlineStreamSkipEI(stream);
  10060. return length;
  10061. }
  10062. findASCIIHexDecodeInlineStreamEnd(stream) {
  10063. const GT = 0x3e;
  10064. const startPos = stream.pos;
  10065. let ch;
  10066. while ((ch = stream.getByte()) !== -1) {
  10067. if (ch === GT) {
  10068. break;
  10069. }
  10070. }
  10071. const length = stream.pos - startPos;
  10072. if (ch === -1) {
  10073. warn("Inline ASCIIHexDecode image stream: " + "EOD marker not found, searching for /EI/ instead.");
  10074. stream.skip(-length);
  10075. return this.findDefaultInlineStreamEnd(stream);
  10076. }
  10077. this.inlineStreamSkipEI(stream);
  10078. return length;
  10079. }
  10080. inlineStreamSkipEI(stream) {
  10081. const E = 0x45,
  10082. I = 0x49;
  10083. let state = 0,
  10084. ch;
  10085. while ((ch = stream.getByte()) !== -1) {
  10086. if (state === 0) {
  10087. state = ch === E ? 1 : 0;
  10088. } else if (state === 1) {
  10089. state = ch === I ? 2 : 0;
  10090. } else if (state === 2) {
  10091. break;
  10092. }
  10093. }
  10094. }
  10095. makeInlineImage(cipherTransform) {
  10096. const lexer = this.lexer;
  10097. const stream = lexer.stream;
  10098. const dictMap = Object.create(null);
  10099. let dictLength;
  10100. while (!isCmd(this.buf1, "ID") && this.buf1 !== EOF) {
  10101. if (!(this.buf1 instanceof Name)) {
  10102. throw new FormatError("Dictionary key must be a name object");
  10103. }
  10104. const key = this.buf1.name;
  10105. this.shift();
  10106. if (this.buf1 === EOF) {
  10107. break;
  10108. }
  10109. dictMap[key] = this.getObj(cipherTransform);
  10110. }
  10111. if (lexer.beginInlineImagePos !== -1) {
  10112. dictLength = stream.pos - lexer.beginInlineImagePos;
  10113. }
  10114. const filter = this.xref.fetchIfRef(dictMap.F || dictMap.Filter);
  10115. let filterName;
  10116. if (filter instanceof Name) {
  10117. filterName = filter.name;
  10118. } else if (Array.isArray(filter)) {
  10119. const filterZero = this.xref.fetchIfRef(filter[0]);
  10120. if (filterZero instanceof Name) {
  10121. filterName = filterZero.name;
  10122. }
  10123. }
  10124. const startPos = stream.pos;
  10125. let length;
  10126. switch (filterName) {
  10127. case "DCT":
  10128. case "DCTDecode":
  10129. length = this.findDCTDecodeInlineStreamEnd(stream);
  10130. break;
  10131. case "A85":
  10132. case "ASCII85Decode":
  10133. length = this.findASCII85DecodeInlineStreamEnd(stream);
  10134. break;
  10135. case "AHx":
  10136. case "ASCIIHexDecode":
  10137. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  10138. break;
  10139. default:
  10140. length = this.findDefaultInlineStreamEnd(stream);
  10141. }
  10142. let cacheKey;
  10143. if (length < MAX_LENGTH_TO_CACHE && dictLength > 0) {
  10144. const initialStreamPos = stream.pos;
  10145. stream.pos = lexer.beginInlineImagePos;
  10146. cacheKey = getInlineImageCacheKey(stream.getBytes(dictLength + length));
  10147. stream.pos = initialStreamPos;
  10148. const cacheEntry = this.imageCache[cacheKey];
  10149. if (cacheEntry !== undefined) {
  10150. this.buf2 = Cmd.get("EI");
  10151. this.shift();
  10152. cacheEntry.reset();
  10153. return cacheEntry;
  10154. }
  10155. }
  10156. const dict = new Dict(this.xref);
  10157. for (const key in dictMap) {
  10158. dict.set(key, dictMap[key]);
  10159. }
  10160. let imageStream = stream.makeSubStream(startPos, length, dict);
  10161. if (cipherTransform) {
  10162. imageStream = cipherTransform.createStream(imageStream, length);
  10163. }
  10164. imageStream = this.filter(imageStream, dict, length);
  10165. imageStream.dict = dict;
  10166. if (cacheKey !== undefined) {
  10167. imageStream.cacheKey = `inline_img_${++this._imageId}`;
  10168. this.imageCache[cacheKey] = imageStream;
  10169. }
  10170. this.buf2 = Cmd.get("EI");
  10171. this.shift();
  10172. return imageStream;
  10173. }
  10174. _findStreamLength(startPos, signature) {
  10175. const {
  10176. stream
  10177. } = this.lexer;
  10178. stream.pos = startPos;
  10179. const SCAN_BLOCK_LENGTH = 2048;
  10180. const signatureLength = signature.length;
  10181. while (stream.pos < stream.end) {
  10182. const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  10183. const scanLength = scanBytes.length - signatureLength;
  10184. if (scanLength <= 0) {
  10185. break;
  10186. }
  10187. let pos = 0;
  10188. while (pos < scanLength) {
  10189. let j = 0;
  10190. while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
  10191. j++;
  10192. }
  10193. if (j >= signatureLength) {
  10194. stream.pos += pos;
  10195. return stream.pos - startPos;
  10196. }
  10197. pos++;
  10198. }
  10199. stream.pos += scanLength;
  10200. }
  10201. return -1;
  10202. }
  10203. makeStream(dict, cipherTransform) {
  10204. const lexer = this.lexer;
  10205. let stream = lexer.stream;
  10206. lexer.skipToNextLine();
  10207. const startPos = stream.pos - 1;
  10208. let length = dict.get("Length");
  10209. if (!Number.isInteger(length)) {
  10210. info(`Bad length "${length && length.toString()}" in stream.`);
  10211. length = 0;
  10212. }
  10213. stream.pos = startPos + length;
  10214. lexer.nextChar();
  10215. if (this.tryShift() && isCmd(this.buf2, "endstream")) {
  10216. this.shift();
  10217. } else {
  10218. const ENDSTREAM_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d]);
  10219. let actualLength = this._findStreamLength(startPos, ENDSTREAM_SIGNATURE);
  10220. if (actualLength < 0) {
  10221. const MAX_TRUNCATION = 1;
  10222. for (let i = 1; i <= MAX_TRUNCATION; i++) {
  10223. const end = ENDSTREAM_SIGNATURE.length - i;
  10224. const TRUNCATED_SIGNATURE = ENDSTREAM_SIGNATURE.slice(0, end);
  10225. const maybeLength = this._findStreamLength(startPos, TRUNCATED_SIGNATURE);
  10226. if (maybeLength >= 0) {
  10227. const lastByte = stream.peekBytes(end + 1)[end];
  10228. if (!isWhiteSpace(lastByte)) {
  10229. break;
  10230. }
  10231. info(`Found "${bytesToString(TRUNCATED_SIGNATURE)}" when ` + "searching for endstream command.");
  10232. actualLength = maybeLength;
  10233. break;
  10234. }
  10235. }
  10236. if (actualLength < 0) {
  10237. throw new FormatError("Missing endstream command.");
  10238. }
  10239. }
  10240. length = actualLength;
  10241. lexer.nextChar();
  10242. this.shift();
  10243. this.shift();
  10244. }
  10245. this.shift();
  10246. stream = stream.makeSubStream(startPos, length, dict);
  10247. if (cipherTransform) {
  10248. stream = cipherTransform.createStream(stream, length);
  10249. }
  10250. stream = this.filter(stream, dict, length);
  10251. stream.dict = dict;
  10252. return stream;
  10253. }
  10254. filter(stream, dict, length) {
  10255. let filter = dict.get("F", "Filter");
  10256. let params = dict.get("DP", "DecodeParms");
  10257. if (filter instanceof Name) {
  10258. if (Array.isArray(params)) {
  10259. warn("/DecodeParms should not be an Array, when /Filter is a Name.");
  10260. }
  10261. return this.makeFilter(stream, filter.name, length, params);
  10262. }
  10263. let maybeLength = length;
  10264. if (Array.isArray(filter)) {
  10265. const filterArray = filter;
  10266. const paramsArray = params;
  10267. for (let i = 0, ii = filterArray.length; i < ii; ++i) {
  10268. filter = this.xref.fetchIfRef(filterArray[i]);
  10269. if (!(filter instanceof Name)) {
  10270. throw new FormatError(`Bad filter name "${filter}"`);
  10271. }
  10272. params = null;
  10273. if (Array.isArray(paramsArray) && i in paramsArray) {
  10274. params = this.xref.fetchIfRef(paramsArray[i]);
  10275. }
  10276. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  10277. maybeLength = null;
  10278. }
  10279. }
  10280. return stream;
  10281. }
  10282. makeFilter(stream, name, maybeLength, params) {
  10283. if (maybeLength === 0) {
  10284. warn(`Empty "${name}" stream.`);
  10285. return new NullStream();
  10286. }
  10287. try {
  10288. switch (name) {
  10289. case "Fl":
  10290. case "FlateDecode":
  10291. if (params) {
  10292. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  10293. }
  10294. return new FlateStream(stream, maybeLength);
  10295. case "LZW":
  10296. case "LZWDecode":
  10297. let earlyChange = 1;
  10298. if (params) {
  10299. if (params.has("EarlyChange")) {
  10300. earlyChange = params.get("EarlyChange");
  10301. }
  10302. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  10303. }
  10304. return new LZWStream(stream, maybeLength, earlyChange);
  10305. case "DCT":
  10306. case "DCTDecode":
  10307. return new JpegStream(stream, maybeLength, params);
  10308. case "JPX":
  10309. case "JPXDecode":
  10310. return new JpxStream(stream, maybeLength, params);
  10311. case "A85":
  10312. case "ASCII85Decode":
  10313. return new Ascii85Stream(stream, maybeLength);
  10314. case "AHx":
  10315. case "ASCIIHexDecode":
  10316. return new AsciiHexStream(stream, maybeLength);
  10317. case "CCF":
  10318. case "CCITTFaxDecode":
  10319. return new CCITTFaxStream(stream, maybeLength, params);
  10320. case "RL":
  10321. case "RunLengthDecode":
  10322. return new RunLengthStream(stream, maybeLength);
  10323. case "JBIG2Decode":
  10324. return new Jbig2Stream(stream, maybeLength, params);
  10325. }
  10326. warn(`Filter "${name}" is not supported.`);
  10327. return stream;
  10328. } catch (ex) {
  10329. if (ex instanceof MissingDataException) {
  10330. throw ex;
  10331. }
  10332. warn(`Invalid stream: "${ex}"`);
  10333. return new NullStream();
  10334. }
  10335. }
  10336. }
  10337. const specialChars = [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  10338. function toHexDigit(ch) {
  10339. if (ch >= 0x30 && ch <= 0x39) {
  10340. return ch & 0x0f;
  10341. }
  10342. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  10343. return (ch & 0x0f) + 9;
  10344. }
  10345. return -1;
  10346. }
  10347. class Lexer {
  10348. constructor(stream, knownCommands = null) {
  10349. this.stream = stream;
  10350. this.nextChar();
  10351. this.strBuf = [];
  10352. this.knownCommands = knownCommands;
  10353. this._hexStringNumWarn = 0;
  10354. this.beginInlineImagePos = -1;
  10355. }
  10356. nextChar() {
  10357. return this.currentChar = this.stream.getByte();
  10358. }
  10359. peekChar() {
  10360. return this.stream.peekByte();
  10361. }
  10362. getNumber() {
  10363. let ch = this.currentChar;
  10364. let eNotation = false;
  10365. let divideBy = 0;
  10366. let sign = 1;
  10367. if (ch === 0x2d) {
  10368. sign = -1;
  10369. ch = this.nextChar();
  10370. if (ch === 0x2d) {
  10371. ch = this.nextChar();
  10372. }
  10373. } else if (ch === 0x2b) {
  10374. ch = this.nextChar();
  10375. }
  10376. if (ch === 0x0a || ch === 0x0d) {
  10377. do {
  10378. ch = this.nextChar();
  10379. } while (ch === 0x0a || ch === 0x0d);
  10380. }
  10381. if (ch === 0x2e) {
  10382. divideBy = 10;
  10383. ch = this.nextChar();
  10384. }
  10385. if (ch < 0x30 || ch > 0x39) {
  10386. const msg = `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`;
  10387. if (isWhiteSpace(ch) || ch === -1) {
  10388. info(`Lexer.getNumber - "${msg}".`);
  10389. return 0;
  10390. }
  10391. throw new FormatError(msg);
  10392. }
  10393. let baseValue = ch - 0x30;
  10394. let powerValue = 0;
  10395. let powerValueSign = 1;
  10396. while ((ch = this.nextChar()) >= 0) {
  10397. if (ch >= 0x30 && ch <= 0x39) {
  10398. const currentDigit = ch - 0x30;
  10399. if (eNotation) {
  10400. powerValue = powerValue * 10 + currentDigit;
  10401. } else {
  10402. if (divideBy !== 0) {
  10403. divideBy *= 10;
  10404. }
  10405. baseValue = baseValue * 10 + currentDigit;
  10406. }
  10407. } else if (ch === 0x2e) {
  10408. if (divideBy === 0) {
  10409. divideBy = 1;
  10410. } else {
  10411. break;
  10412. }
  10413. } else if (ch === 0x2d) {
  10414. warn("Badly formatted number: minus sign in the middle");
  10415. } else if (ch === 0x45 || ch === 0x65) {
  10416. ch = this.peekChar();
  10417. if (ch === 0x2b || ch === 0x2d) {
  10418. powerValueSign = ch === 0x2d ? -1 : 1;
  10419. this.nextChar();
  10420. } else if (ch < 0x30 || ch > 0x39) {
  10421. break;
  10422. }
  10423. eNotation = true;
  10424. } else {
  10425. break;
  10426. }
  10427. }
  10428. if (divideBy !== 0) {
  10429. baseValue /= divideBy;
  10430. }
  10431. if (eNotation) {
  10432. baseValue *= 10 ** (powerValueSign * powerValue);
  10433. }
  10434. return sign * baseValue;
  10435. }
  10436. getString() {
  10437. let numParen = 1;
  10438. let done = false;
  10439. const strBuf = this.strBuf;
  10440. strBuf.length = 0;
  10441. let ch = this.nextChar();
  10442. while (true) {
  10443. let charBuffered = false;
  10444. switch (ch | 0) {
  10445. case -1:
  10446. warn("Unterminated string");
  10447. done = true;
  10448. break;
  10449. case 0x28:
  10450. ++numParen;
  10451. strBuf.push("(");
  10452. break;
  10453. case 0x29:
  10454. if (--numParen === 0) {
  10455. this.nextChar();
  10456. done = true;
  10457. } else {
  10458. strBuf.push(")");
  10459. }
  10460. break;
  10461. case 0x5c:
  10462. ch = this.nextChar();
  10463. switch (ch) {
  10464. case -1:
  10465. warn("Unterminated string");
  10466. done = true;
  10467. break;
  10468. case 0x6e:
  10469. strBuf.push("\n");
  10470. break;
  10471. case 0x72:
  10472. strBuf.push("\r");
  10473. break;
  10474. case 0x74:
  10475. strBuf.push("\t");
  10476. break;
  10477. case 0x62:
  10478. strBuf.push("\b");
  10479. break;
  10480. case 0x66:
  10481. strBuf.push("\f");
  10482. break;
  10483. case 0x5c:
  10484. case 0x28:
  10485. case 0x29:
  10486. strBuf.push(String.fromCharCode(ch));
  10487. break;
  10488. case 0x30:
  10489. case 0x31:
  10490. case 0x32:
  10491. case 0x33:
  10492. case 0x34:
  10493. case 0x35:
  10494. case 0x36:
  10495. case 0x37:
  10496. let x = ch & 0x0f;
  10497. ch = this.nextChar();
  10498. charBuffered = true;
  10499. if (ch >= 0x30 && ch <= 0x37) {
  10500. x = (x << 3) + (ch & 0x0f);
  10501. ch = this.nextChar();
  10502. if (ch >= 0x30 && ch <= 0x37) {
  10503. charBuffered = false;
  10504. x = (x << 3) + (ch & 0x0f);
  10505. }
  10506. }
  10507. strBuf.push(String.fromCharCode(x));
  10508. break;
  10509. case 0x0d:
  10510. if (this.peekChar() === 0x0a) {
  10511. this.nextChar();
  10512. }
  10513. break;
  10514. case 0x0a:
  10515. break;
  10516. default:
  10517. strBuf.push(String.fromCharCode(ch));
  10518. break;
  10519. }
  10520. break;
  10521. default:
  10522. strBuf.push(String.fromCharCode(ch));
  10523. break;
  10524. }
  10525. if (done) {
  10526. break;
  10527. }
  10528. if (!charBuffered) {
  10529. ch = this.nextChar();
  10530. }
  10531. }
  10532. return strBuf.join("");
  10533. }
  10534. getName() {
  10535. let ch, previousCh;
  10536. const strBuf = this.strBuf;
  10537. strBuf.length = 0;
  10538. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  10539. if (ch === 0x23) {
  10540. ch = this.nextChar();
  10541. if (specialChars[ch]) {
  10542. warn("Lexer_getName: " + "NUMBER SIGN (#) should be followed by a hexadecimal number.");
  10543. strBuf.push("#");
  10544. break;
  10545. }
  10546. const x = toHexDigit(ch);
  10547. if (x !== -1) {
  10548. previousCh = ch;
  10549. ch = this.nextChar();
  10550. const x2 = toHexDigit(ch);
  10551. if (x2 === -1) {
  10552. warn(`Lexer_getName: Illegal digit (${String.fromCharCode(ch)}) ` + "in hexadecimal number.");
  10553. strBuf.push("#", String.fromCharCode(previousCh));
  10554. if (specialChars[ch]) {
  10555. break;
  10556. }
  10557. strBuf.push(String.fromCharCode(ch));
  10558. continue;
  10559. }
  10560. strBuf.push(String.fromCharCode(x << 4 | x2));
  10561. } else {
  10562. strBuf.push("#", String.fromCharCode(ch));
  10563. }
  10564. } else {
  10565. strBuf.push(String.fromCharCode(ch));
  10566. }
  10567. }
  10568. if (strBuf.length > 127) {
  10569. warn(`Name token is longer than allowed by the spec: ${strBuf.length}`);
  10570. }
  10571. return Name.get(strBuf.join(""));
  10572. }
  10573. _hexStringWarn(ch) {
  10574. const MAX_HEX_STRING_NUM_WARN = 5;
  10575. if (this._hexStringNumWarn++ === MAX_HEX_STRING_NUM_WARN) {
  10576. warn("getHexString - ignoring additional invalid characters.");
  10577. return;
  10578. }
  10579. if (this._hexStringNumWarn > MAX_HEX_STRING_NUM_WARN) {
  10580. return;
  10581. }
  10582. warn(`getHexString - ignoring invalid character: ${ch}`);
  10583. }
  10584. getHexString() {
  10585. const strBuf = this.strBuf;
  10586. strBuf.length = 0;
  10587. let ch = this.currentChar;
  10588. let isFirstHex = true;
  10589. let firstDigit, secondDigit;
  10590. this._hexStringNumWarn = 0;
  10591. while (true) {
  10592. if (ch < 0) {
  10593. warn("Unterminated hex string");
  10594. break;
  10595. } else if (ch === 0x3e) {
  10596. this.nextChar();
  10597. break;
  10598. } else if (specialChars[ch] === 1) {
  10599. ch = this.nextChar();
  10600. continue;
  10601. } else {
  10602. if (isFirstHex) {
  10603. firstDigit = toHexDigit(ch);
  10604. if (firstDigit === -1) {
  10605. this._hexStringWarn(ch);
  10606. ch = this.nextChar();
  10607. continue;
  10608. }
  10609. } else {
  10610. secondDigit = toHexDigit(ch);
  10611. if (secondDigit === -1) {
  10612. this._hexStringWarn(ch);
  10613. ch = this.nextChar();
  10614. continue;
  10615. }
  10616. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  10617. }
  10618. isFirstHex = !isFirstHex;
  10619. ch = this.nextChar();
  10620. }
  10621. }
  10622. return strBuf.join("");
  10623. }
  10624. getObj() {
  10625. let comment = false;
  10626. let ch = this.currentChar;
  10627. while (true) {
  10628. if (ch < 0) {
  10629. return EOF;
  10630. }
  10631. if (comment) {
  10632. if (ch === 0x0a || ch === 0x0d) {
  10633. comment = false;
  10634. }
  10635. } else if (ch === 0x25) {
  10636. comment = true;
  10637. } else if (specialChars[ch] !== 1) {
  10638. break;
  10639. }
  10640. ch = this.nextChar();
  10641. }
  10642. switch (ch | 0) {
  10643. case 0x30:
  10644. case 0x31:
  10645. case 0x32:
  10646. case 0x33:
  10647. case 0x34:
  10648. case 0x35:
  10649. case 0x36:
  10650. case 0x37:
  10651. case 0x38:
  10652. case 0x39:
  10653. case 0x2b:
  10654. case 0x2d:
  10655. case 0x2e:
  10656. return this.getNumber();
  10657. case 0x28:
  10658. return this.getString();
  10659. case 0x2f:
  10660. return this.getName();
  10661. case 0x5b:
  10662. this.nextChar();
  10663. return Cmd.get("[");
  10664. case 0x5d:
  10665. this.nextChar();
  10666. return Cmd.get("]");
  10667. case 0x3c:
  10668. ch = this.nextChar();
  10669. if (ch === 0x3c) {
  10670. this.nextChar();
  10671. return Cmd.get("<<");
  10672. }
  10673. return this.getHexString();
  10674. case 0x3e:
  10675. ch = this.nextChar();
  10676. if (ch === 0x3e) {
  10677. this.nextChar();
  10678. return Cmd.get(">>");
  10679. }
  10680. return Cmd.get(">");
  10681. case 0x7b:
  10682. this.nextChar();
  10683. return Cmd.get("{");
  10684. case 0x7d:
  10685. this.nextChar();
  10686. return Cmd.get("}");
  10687. case 0x29:
  10688. this.nextChar();
  10689. throw new FormatError(`Illegal character: ${ch}`);
  10690. }
  10691. let str = String.fromCharCode(ch);
  10692. if (ch < 0x20 || ch > 0x7f) {
  10693. const nextCh = this.peekChar();
  10694. if (nextCh >= 0x20 && nextCh <= 0x7f) {
  10695. this.nextChar();
  10696. return Cmd.get(str);
  10697. }
  10698. }
  10699. const knownCommands = this.knownCommands;
  10700. let knownCommandFound = knownCommands?.[str] !== undefined;
  10701. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  10702. const possibleCommand = str + String.fromCharCode(ch);
  10703. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  10704. break;
  10705. }
  10706. if (str.length === 128) {
  10707. throw new FormatError(`Command token too long: ${str.length}`);
  10708. }
  10709. str = possibleCommand;
  10710. knownCommandFound = knownCommands?.[str] !== undefined;
  10711. }
  10712. if (str === "true") {
  10713. return true;
  10714. }
  10715. if (str === "false") {
  10716. return false;
  10717. }
  10718. if (str === "null") {
  10719. return null;
  10720. }
  10721. if (str === "BI") {
  10722. this.beginInlineImagePos = this.stream.pos;
  10723. }
  10724. return Cmd.get(str);
  10725. }
  10726. skipToNextLine() {
  10727. let ch = this.currentChar;
  10728. while (ch >= 0) {
  10729. if (ch === 0x0d) {
  10730. ch = this.nextChar();
  10731. if (ch === 0x0a) {
  10732. this.nextChar();
  10733. }
  10734. break;
  10735. } else if (ch === 0x0a) {
  10736. this.nextChar();
  10737. break;
  10738. }
  10739. ch = this.nextChar();
  10740. }
  10741. }
  10742. }
  10743. class Linearization {
  10744. static create(stream) {
  10745. function getInt(linDict, name, allowZeroValue = false) {
  10746. const obj = linDict.get(name);
  10747. if (Number.isInteger(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  10748. return obj;
  10749. }
  10750. throw new Error(`The "${name}" parameter in the linearization ` + "dictionary is invalid.");
  10751. }
  10752. function getHints(linDict) {
  10753. const hints = linDict.get("H");
  10754. let hintsLength;
  10755. if (Array.isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  10756. for (let index = 0; index < hintsLength; index++) {
  10757. const hint = hints[index];
  10758. if (!(Number.isInteger(hint) && hint > 0)) {
  10759. throw new Error(`Hint (${index}) in the linearization dictionary is invalid.`);
  10760. }
  10761. }
  10762. return hints;
  10763. }
  10764. throw new Error("Hint array in the linearization dictionary is invalid.");
  10765. }
  10766. const parser = new Parser({
  10767. lexer: new Lexer(stream),
  10768. xref: null
  10769. });
  10770. const obj1 = parser.getObj();
  10771. const obj2 = parser.getObj();
  10772. const obj3 = parser.getObj();
  10773. const linDict = parser.getObj();
  10774. let obj, length;
  10775. if (!(Number.isInteger(obj1) && Number.isInteger(obj2) && isCmd(obj3, "obj") && linDict instanceof Dict && typeof (obj = linDict.get("Linearized")) === "number" && obj > 0)) {
  10776. return null;
  10777. } else if ((length = getInt(linDict, "L")) !== stream.length) {
  10778. throw new Error('The "L" parameter in the linearization dictionary ' + "does not equal the stream length.");
  10779. }
  10780. return {
  10781. length,
  10782. hints: getHints(linDict),
  10783. objectNumberFirst: getInt(linDict, "O"),
  10784. endFirst: getInt(linDict, "E"),
  10785. numPages: getInt(linDict, "N"),
  10786. mainXRefEntriesOffset: getInt(linDict, "T"),
  10787. pageFirst: linDict.has("P") ? getInt(linDict, "P", true) : 0
  10788. };
  10789. }
  10790. }
  10791. ;// CONCATENATED MODULE: ./src/core/cmap.js
  10792. const BUILT_IN_CMAPS = ["Adobe-GB1-UCS2", "Adobe-CNS1-UCS2", "Adobe-Japan1-UCS2", "Adobe-Korea1-UCS2", "78-EUC-H", "78-EUC-V", "78-H", "78-RKSJ-H", "78-RKSJ-V", "78-V", "78ms-RKSJ-H", "78ms-RKSJ-V", "83pv-RKSJ-H", "90ms-RKSJ-H", "90ms-RKSJ-V", "90msp-RKSJ-H", "90msp-RKSJ-V", "90pv-RKSJ-H", "90pv-RKSJ-V", "Add-H", "Add-RKSJ-H", "Add-RKSJ-V", "Add-V", "Adobe-CNS1-0", "Adobe-CNS1-1", "Adobe-CNS1-2", "Adobe-CNS1-3", "Adobe-CNS1-4", "Adobe-CNS1-5", "Adobe-CNS1-6", "Adobe-GB1-0", "Adobe-GB1-1", "Adobe-GB1-2", "Adobe-GB1-3", "Adobe-GB1-4", "Adobe-GB1-5", "Adobe-Japan1-0", "Adobe-Japan1-1", "Adobe-Japan1-2", "Adobe-Japan1-3", "Adobe-Japan1-4", "Adobe-Japan1-5", "Adobe-Japan1-6", "Adobe-Korea1-0", "Adobe-Korea1-1", "Adobe-Korea1-2", "B5-H", "B5-V", "B5pc-H", "B5pc-V", "CNS-EUC-H", "CNS-EUC-V", "CNS1-H", "CNS1-V", "CNS2-H", "CNS2-V", "ETHK-B5-H", "ETHK-B5-V", "ETen-B5-H", "ETen-B5-V", "ETenms-B5-H", "ETenms-B5-V", "EUC-H", "EUC-V", "Ext-H", "Ext-RKSJ-H", "Ext-RKSJ-V", "Ext-V", "GB-EUC-H", "GB-EUC-V", "GB-H", "GB-V", "GBK-EUC-H", "GBK-EUC-V", "GBK2K-H", "GBK2K-V", "GBKp-EUC-H", "GBKp-EUC-V", "GBT-EUC-H", "GBT-EUC-V", "GBT-H", "GBT-V", "GBTpc-EUC-H", "GBTpc-EUC-V", "GBpc-EUC-H", "GBpc-EUC-V", "H", "HKdla-B5-H", "HKdla-B5-V", "HKdlb-B5-H", "HKdlb-B5-V", "HKgccs-B5-H", "HKgccs-B5-V", "HKm314-B5-H", "HKm314-B5-V", "HKm471-B5-H", "HKm471-B5-V", "HKscs-B5-H", "HKscs-B5-V", "Hankaku", "Hiragana", "KSC-EUC-H", "KSC-EUC-V", "KSC-H", "KSC-Johab-H", "KSC-Johab-V", "KSC-V", "KSCms-UHC-H", "KSCms-UHC-HW-H", "KSCms-UHC-HW-V", "KSCms-UHC-V", "KSCpc-EUC-H", "KSCpc-EUC-V", "Katakana", "NWP-H", "NWP-V", "RKSJ-H", "RKSJ-V", "Roman", "UniCNS-UCS2-H", "UniCNS-UCS2-V", "UniCNS-UTF16-H", "UniCNS-UTF16-V", "UniCNS-UTF32-H", "UniCNS-UTF32-V", "UniCNS-UTF8-H", "UniCNS-UTF8-V", "UniGB-UCS2-H", "UniGB-UCS2-V", "UniGB-UTF16-H", "UniGB-UTF16-V", "UniGB-UTF32-H", "UniGB-UTF32-V", "UniGB-UTF8-H", "UniGB-UTF8-V", "UniJIS-UCS2-H", "UniJIS-UCS2-HW-H", "UniJIS-UCS2-HW-V", "UniJIS-UCS2-V", "UniJIS-UTF16-H", "UniJIS-UTF16-V", "UniJIS-UTF32-H", "UniJIS-UTF32-V", "UniJIS-UTF8-H", "UniJIS-UTF8-V", "UniJIS2004-UTF16-H", "UniJIS2004-UTF16-V", "UniJIS2004-UTF32-H", "UniJIS2004-UTF32-V", "UniJIS2004-UTF8-H", "UniJIS2004-UTF8-V", "UniJISPro-UCS2-HW-V", "UniJISPro-UCS2-V", "UniJISPro-UTF8-V", "UniJISX0213-UTF32-H", "UniJISX0213-UTF32-V", "UniJISX02132004-UTF32-H", "UniJISX02132004-UTF32-V", "UniKS-UCS2-H", "UniKS-UCS2-V", "UniKS-UTF16-H", "UniKS-UTF16-V", "UniKS-UTF32-H", "UniKS-UTF32-V", "UniKS-UTF8-H", "UniKS-UTF8-V", "V", "WP-Symbol"];
  10793. const MAX_MAP_RANGE = 2 ** 24 - 1;
  10794. class CMap {
  10795. constructor(builtInCMap = false) {
  10796. this.codespaceRanges = [[], [], [], []];
  10797. this.numCodespaceRanges = 0;
  10798. this._map = [];
  10799. this.name = "";
  10800. this.vertical = false;
  10801. this.useCMap = null;
  10802. this.builtInCMap = builtInCMap;
  10803. }
  10804. addCodespaceRange(n, low, high) {
  10805. this.codespaceRanges[n - 1].push(low, high);
  10806. this.numCodespaceRanges++;
  10807. }
  10808. mapCidRange(low, high, dstLow) {
  10809. if (high - low > MAX_MAP_RANGE) {
  10810. throw new Error("mapCidRange - ignoring data above MAX_MAP_RANGE.");
  10811. }
  10812. while (low <= high) {
  10813. this._map[low++] = dstLow++;
  10814. }
  10815. }
  10816. mapBfRange(low, high, dstLow) {
  10817. if (high - low > MAX_MAP_RANGE) {
  10818. throw new Error("mapBfRange - ignoring data above MAX_MAP_RANGE.");
  10819. }
  10820. const lastByte = dstLow.length - 1;
  10821. while (low <= high) {
  10822. this._map[low++] = dstLow;
  10823. const nextCharCode = dstLow.charCodeAt(lastByte) + 1;
  10824. if (nextCharCode > 0xff) {
  10825. dstLow = dstLow.substring(0, lastByte - 1) + String.fromCharCode(dstLow.charCodeAt(lastByte - 1) + 1) + "\x00";
  10826. continue;
  10827. }
  10828. dstLow = dstLow.substring(0, lastByte) + String.fromCharCode(nextCharCode);
  10829. }
  10830. }
  10831. mapBfRangeToArray(low, high, array) {
  10832. if (high - low > MAX_MAP_RANGE) {
  10833. throw new Error("mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.");
  10834. }
  10835. const ii = array.length;
  10836. let i = 0;
  10837. while (low <= high && i < ii) {
  10838. this._map[low] = array[i++];
  10839. ++low;
  10840. }
  10841. }
  10842. mapOne(src, dst) {
  10843. this._map[src] = dst;
  10844. }
  10845. lookup(code) {
  10846. return this._map[code];
  10847. }
  10848. contains(code) {
  10849. return this._map[code] !== undefined;
  10850. }
  10851. forEach(callback) {
  10852. const map = this._map;
  10853. const length = map.length;
  10854. if (length <= 0x10000) {
  10855. for (let i = 0; i < length; i++) {
  10856. if (map[i] !== undefined) {
  10857. callback(i, map[i]);
  10858. }
  10859. }
  10860. } else {
  10861. for (const i in map) {
  10862. callback(i, map[i]);
  10863. }
  10864. }
  10865. }
  10866. charCodeOf(value) {
  10867. const map = this._map;
  10868. if (map.length <= 0x10000) {
  10869. return map.indexOf(value);
  10870. }
  10871. for (const charCode in map) {
  10872. if (map[charCode] === value) {
  10873. return charCode | 0;
  10874. }
  10875. }
  10876. return -1;
  10877. }
  10878. getMap() {
  10879. return this._map;
  10880. }
  10881. readCharCode(str, offset, out) {
  10882. let c = 0;
  10883. const codespaceRanges = this.codespaceRanges;
  10884. for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
  10885. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  10886. const codespaceRange = codespaceRanges[n];
  10887. for (let k = 0, kk = codespaceRange.length; k < kk;) {
  10888. const low = codespaceRange[k++];
  10889. const high = codespaceRange[k++];
  10890. if (c >= low && c <= high) {
  10891. out.charcode = c;
  10892. out.length = n + 1;
  10893. return;
  10894. }
  10895. }
  10896. }
  10897. out.charcode = 0;
  10898. out.length = 1;
  10899. }
  10900. getCharCodeLength(charCode) {
  10901. const codespaceRanges = this.codespaceRanges;
  10902. for (let n = 0, nn = codespaceRanges.length; n < nn; n++) {
  10903. const codespaceRange = codespaceRanges[n];
  10904. for (let k = 0, kk = codespaceRange.length; k < kk;) {
  10905. const low = codespaceRange[k++];
  10906. const high = codespaceRange[k++];
  10907. if (charCode >= low && charCode <= high) {
  10908. return n + 1;
  10909. }
  10910. }
  10911. }
  10912. return 1;
  10913. }
  10914. get length() {
  10915. return this._map.length;
  10916. }
  10917. get isIdentityCMap() {
  10918. if (!(this.name === "Identity-H" || this.name === "Identity-V")) {
  10919. return false;
  10920. }
  10921. if (this._map.length !== 0x10000) {
  10922. return false;
  10923. }
  10924. for (let i = 0; i < 0x10000; i++) {
  10925. if (this._map[i] !== i) {
  10926. return false;
  10927. }
  10928. }
  10929. return true;
  10930. }
  10931. }
  10932. class IdentityCMap extends CMap {
  10933. constructor(vertical, n) {
  10934. super();
  10935. this.vertical = vertical;
  10936. this.addCodespaceRange(n, 0, 0xffff);
  10937. }
  10938. mapCidRange(low, high, dstLow) {
  10939. unreachable("should not call mapCidRange");
  10940. }
  10941. mapBfRange(low, high, dstLow) {
  10942. unreachable("should not call mapBfRange");
  10943. }
  10944. mapBfRangeToArray(low, high, array) {
  10945. unreachable("should not call mapBfRangeToArray");
  10946. }
  10947. mapOne(src, dst) {
  10948. unreachable("should not call mapCidOne");
  10949. }
  10950. lookup(code) {
  10951. return Number.isInteger(code) && code <= 0xffff ? code : undefined;
  10952. }
  10953. contains(code) {
  10954. return Number.isInteger(code) && code <= 0xffff;
  10955. }
  10956. forEach(callback) {
  10957. for (let i = 0; i <= 0xffff; i++) {
  10958. callback(i, i);
  10959. }
  10960. }
  10961. charCodeOf(value) {
  10962. return Number.isInteger(value) && value <= 0xffff ? value : -1;
  10963. }
  10964. getMap() {
  10965. const map = new Array(0x10000);
  10966. for (let i = 0; i <= 0xffff; i++) {
  10967. map[i] = i;
  10968. }
  10969. return map;
  10970. }
  10971. get length() {
  10972. return 0x10000;
  10973. }
  10974. get isIdentityCMap() {
  10975. unreachable("should not access .isIdentityCMap");
  10976. }
  10977. }
  10978. function strToInt(str) {
  10979. let a = 0;
  10980. for (let i = 0; i < str.length; i++) {
  10981. a = a << 8 | str.charCodeAt(i);
  10982. }
  10983. return a >>> 0;
  10984. }
  10985. function expectString(obj) {
  10986. if (typeof obj !== "string") {
  10987. throw new FormatError("Malformed CMap: expected string.");
  10988. }
  10989. }
  10990. function expectInt(obj) {
  10991. if (!Number.isInteger(obj)) {
  10992. throw new FormatError("Malformed CMap: expected int.");
  10993. }
  10994. }
  10995. function parseBfChar(cMap, lexer) {
  10996. while (true) {
  10997. let obj = lexer.getObj();
  10998. if (obj === EOF) {
  10999. break;
  11000. }
  11001. if (isCmd(obj, "endbfchar")) {
  11002. return;
  11003. }
  11004. expectString(obj);
  11005. const src = strToInt(obj);
  11006. obj = lexer.getObj();
  11007. expectString(obj);
  11008. const dst = obj;
  11009. cMap.mapOne(src, dst);
  11010. }
  11011. }
  11012. function parseBfRange(cMap, lexer) {
  11013. while (true) {
  11014. let obj = lexer.getObj();
  11015. if (obj === EOF) {
  11016. break;
  11017. }
  11018. if (isCmd(obj, "endbfrange")) {
  11019. return;
  11020. }
  11021. expectString(obj);
  11022. const low = strToInt(obj);
  11023. obj = lexer.getObj();
  11024. expectString(obj);
  11025. const high = strToInt(obj);
  11026. obj = lexer.getObj();
  11027. if (Number.isInteger(obj) || typeof obj === "string") {
  11028. const dstLow = Number.isInteger(obj) ? String.fromCharCode(obj) : obj;
  11029. cMap.mapBfRange(low, high, dstLow);
  11030. } else if (isCmd(obj, "[")) {
  11031. obj = lexer.getObj();
  11032. const array = [];
  11033. while (!isCmd(obj, "]") && obj !== EOF) {
  11034. array.push(obj);
  11035. obj = lexer.getObj();
  11036. }
  11037. cMap.mapBfRangeToArray(low, high, array);
  11038. } else {
  11039. break;
  11040. }
  11041. }
  11042. throw new FormatError("Invalid bf range.");
  11043. }
  11044. function parseCidChar(cMap, lexer) {
  11045. while (true) {
  11046. let obj = lexer.getObj();
  11047. if (obj === EOF) {
  11048. break;
  11049. }
  11050. if (isCmd(obj, "endcidchar")) {
  11051. return;
  11052. }
  11053. expectString(obj);
  11054. const src = strToInt(obj);
  11055. obj = lexer.getObj();
  11056. expectInt(obj);
  11057. const dst = obj;
  11058. cMap.mapOne(src, dst);
  11059. }
  11060. }
  11061. function parseCidRange(cMap, lexer) {
  11062. while (true) {
  11063. let obj = lexer.getObj();
  11064. if (obj === EOF) {
  11065. break;
  11066. }
  11067. if (isCmd(obj, "endcidrange")) {
  11068. return;
  11069. }
  11070. expectString(obj);
  11071. const low = strToInt(obj);
  11072. obj = lexer.getObj();
  11073. expectString(obj);
  11074. const high = strToInt(obj);
  11075. obj = lexer.getObj();
  11076. expectInt(obj);
  11077. const dstLow = obj;
  11078. cMap.mapCidRange(low, high, dstLow);
  11079. }
  11080. }
  11081. function parseCodespaceRange(cMap, lexer) {
  11082. while (true) {
  11083. let obj = lexer.getObj();
  11084. if (obj === EOF) {
  11085. break;
  11086. }
  11087. if (isCmd(obj, "endcodespacerange")) {
  11088. return;
  11089. }
  11090. if (typeof obj !== "string") {
  11091. break;
  11092. }
  11093. const low = strToInt(obj);
  11094. obj = lexer.getObj();
  11095. if (typeof obj !== "string") {
  11096. break;
  11097. }
  11098. const high = strToInt(obj);
  11099. cMap.addCodespaceRange(obj.length, low, high);
  11100. }
  11101. throw new FormatError("Invalid codespace range.");
  11102. }
  11103. function parseWMode(cMap, lexer) {
  11104. const obj = lexer.getObj();
  11105. if (Number.isInteger(obj)) {
  11106. cMap.vertical = !!obj;
  11107. }
  11108. }
  11109. function parseCMapName(cMap, lexer) {
  11110. const obj = lexer.getObj();
  11111. if (obj instanceof Name) {
  11112. cMap.name = obj.name;
  11113. }
  11114. }
  11115. async function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {
  11116. let previous, embeddedUseCMap;
  11117. objLoop: while (true) {
  11118. try {
  11119. const obj = lexer.getObj();
  11120. if (obj === EOF) {
  11121. break;
  11122. } else if (obj instanceof Name) {
  11123. if (obj.name === "WMode") {
  11124. parseWMode(cMap, lexer);
  11125. } else if (obj.name === "CMapName") {
  11126. parseCMapName(cMap, lexer);
  11127. }
  11128. previous = obj;
  11129. } else if (obj instanceof Cmd) {
  11130. switch (obj.cmd) {
  11131. case "endcmap":
  11132. break objLoop;
  11133. case "usecmap":
  11134. if (previous instanceof Name) {
  11135. embeddedUseCMap = previous.name;
  11136. }
  11137. break;
  11138. case "begincodespacerange":
  11139. parseCodespaceRange(cMap, lexer);
  11140. break;
  11141. case "beginbfchar":
  11142. parseBfChar(cMap, lexer);
  11143. break;
  11144. case "begincidchar":
  11145. parseCidChar(cMap, lexer);
  11146. break;
  11147. case "beginbfrange":
  11148. parseBfRange(cMap, lexer);
  11149. break;
  11150. case "begincidrange":
  11151. parseCidRange(cMap, lexer);
  11152. break;
  11153. }
  11154. }
  11155. } catch (ex) {
  11156. if (ex instanceof MissingDataException) {
  11157. throw ex;
  11158. }
  11159. warn("Invalid cMap data: " + ex);
  11160. continue;
  11161. }
  11162. }
  11163. if (!useCMap && embeddedUseCMap) {
  11164. useCMap = embeddedUseCMap;
  11165. }
  11166. if (useCMap) {
  11167. return extendCMap(cMap, fetchBuiltInCMap, useCMap);
  11168. }
  11169. return cMap;
  11170. }
  11171. async function extendCMap(cMap, fetchBuiltInCMap, useCMap) {
  11172. cMap.useCMap = await createBuiltInCMap(useCMap, fetchBuiltInCMap);
  11173. if (cMap.numCodespaceRanges === 0) {
  11174. const useCodespaceRanges = cMap.useCMap.codespaceRanges;
  11175. for (let i = 0; i < useCodespaceRanges.length; i++) {
  11176. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  11177. }
  11178. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  11179. }
  11180. cMap.useCMap.forEach(function (key, value) {
  11181. if (!cMap.contains(key)) {
  11182. cMap.mapOne(key, cMap.useCMap.lookup(key));
  11183. }
  11184. });
  11185. return cMap;
  11186. }
  11187. async function createBuiltInCMap(name, fetchBuiltInCMap) {
  11188. if (name === "Identity-H") {
  11189. return new IdentityCMap(false, 2);
  11190. } else if (name === "Identity-V") {
  11191. return new IdentityCMap(true, 2);
  11192. }
  11193. if (!BUILT_IN_CMAPS.includes(name)) {
  11194. throw new Error("Unknown CMap name: " + name);
  11195. }
  11196. if (!fetchBuiltInCMap) {
  11197. throw new Error("Built-in CMap parameters are not provided.");
  11198. }
  11199. const {
  11200. cMapData,
  11201. compressionType
  11202. } = await fetchBuiltInCMap(name);
  11203. const cMap = new CMap(true);
  11204. if (compressionType === CMapCompressionType.BINARY) {
  11205. return new BinaryCMapReader().process(cMapData, cMap, useCMap => {
  11206. return extendCMap(cMap, fetchBuiltInCMap, useCMap);
  11207. });
  11208. }
  11209. if (compressionType === CMapCompressionType.NONE) {
  11210. const lexer = new Lexer(new Stream(cMapData));
  11211. return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
  11212. }
  11213. throw new Error(`Invalid CMap "compressionType" value: ${compressionType}`);
  11214. }
  11215. class CMapFactory {
  11216. static async create({
  11217. encoding,
  11218. fetchBuiltInCMap,
  11219. useCMap
  11220. }) {
  11221. if (encoding instanceof Name) {
  11222. return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
  11223. } else if (encoding instanceof BaseStream) {
  11224. const parsedCMap = await parseCMap(new CMap(), new Lexer(encoding), fetchBuiltInCMap, useCMap);
  11225. if (parsedCMap.isIdentityCMap) {
  11226. return createBuiltInCMap(parsedCMap.name, fetchBuiltInCMap);
  11227. }
  11228. return parsedCMap;
  11229. }
  11230. throw new Error("Encoding required.");
  11231. }
  11232. }
  11233. ;// CONCATENATED MODULE: ./src/core/charsets.js
  11234. const ISOAdobeCharset = [".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl", "periodcentered", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", "eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute", "ydieresis", "zcaron"];
  11235. const ExpertCharset = [".notdef", "space", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle", "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", "onequarter", "onehalf", "threequarters", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall"];
  11236. const ExpertSubsetCharset = [".notdef", "space", "dollaroldstyle", "dollarsuperior", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "hyphensuperior", "colonmonetary", "onefitted", "rupiah", "centoldstyle", "figuredash", "hypheninferior", "onequarter", "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior"];
  11237. ;// CONCATENATED MODULE: ./src/core/encodings.js
  11238. const ExpertEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclamsmall", "Hungarumlautsmall", "", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "", "", "", "isuperior", "", "", "lsuperior", "msuperior", "nsuperior", "osuperior", "", "", "rsuperior", "ssuperior", "tsuperior", "", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "exclamdownsmall", "centoldstyle", "Lslashsmall", "", "", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "", "Dotaccentsmall", "", "", "Macronsmall", "", "", "figuredash", "hypheninferior", "", "", "Ogoneksmall", "Ringsmall", "Cedillasmall", "", "", "", "onequarter", "onehalf", "threequarters", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "", "", "zerosuperior", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall"];
  11239. const MacExpertEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclamsmall", "Hungarumlautsmall", "centoldstyle", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "comma", "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "colon", "semicolon", "", "threequartersemdash", "", "questionsmall", "", "", "", "", "Ethsmall", "", "", "onequarter", "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "", "", "", "", "", "", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior", "", "parenrightinferior", "Circumflexsmall", "hypheninferior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "", "", "asuperior", "centsuperior", "", "", "", "", "Aacutesmall", "Agravesmall", "Acircumflexsmall", "Adieresissmall", "Atildesmall", "Aringsmall", "Ccedillasmall", "Eacutesmall", "Egravesmall", "Ecircumflexsmall", "Edieresissmall", "Iacutesmall", "Igravesmall", "Icircumflexsmall", "Idieresissmall", "Ntildesmall", "Oacutesmall", "Ogravesmall", "Ocircumflexsmall", "Odieresissmall", "Otildesmall", "Uacutesmall", "Ugravesmall", "Ucircumflexsmall", "Udieresissmall", "", "eightsuperior", "fourinferior", "threeinferior", "sixinferior", "eightinferior", "seveninferior", "Scaronsmall", "", "centinferior", "twoinferior", "", "Dieresissmall", "", "Caronsmall", "osuperior", "fiveinferior", "", "commainferior", "periodinferior", "Yacutesmall", "", "dollarinferior", "", "", "Thornsmall", "", "nineinferior", "zeroinferior", "Zcaronsmall", "AEsmall", "Oslashsmall", "questiondownsmall", "oneinferior", "Lslashsmall", "", "", "", "", "", "", "Cedillasmall", "", "", "", "", "", "OEsmall", "figuredash", "hyphensuperior", "", "", "", "", "exclamdownsmall", "", "Ydieresissmall", "", "onesuperior", "twosuperior", "threesuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "ninesuperior", "zerosuperior", "", "esuperior", "rsuperior", "tsuperior", "", "", "isuperior", "ssuperior", "dsuperior", "", "", "", "", "", "lsuperior", "Ogoneksmall", "Brevesmall", "Macronsmall", "bsuperior", "nsuperior", "msuperior", "commasuperior", "periodsuperior", "Dotaccentsmall", "Ringsmall", "", "", "", ""];
  11240. const MacRomanEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "", "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft", "guillemotright", "ellipsis", "space", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron"];
  11241. const StandardEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "", "endash", "dagger", "daggerdbl", "periodcentered", "", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "", "questiondown", "", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "", "ring", "cedilla", "", "hungarumlaut", "ogonek", "caron", "emdash", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "AE", "", "ordfeminine", "", "", "", "", "Lslash", "Oslash", "OE", "ordmasculine", "", "", "", "", "", "ae", "", "", "", "dotlessi", "", "", "lslash", "oslash", "oe", "germandbls", "", "", "", ""];
  11242. const WinAnsiEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "bullet", "Euro", "bullet", "quotesinglbase", "florin", "quotedblbase", "ellipsis", "dagger", "daggerdbl", "circumflex", "perthousand", "Scaron", "guilsinglleft", "OE", "bullet", "Zcaron", "bullet", "bullet", "quoteleft", "quoteright", "quotedblleft", "quotedblright", "bullet", "endash", "emdash", "tilde", "trademark", "scaron", "guilsinglright", "oe", "bullet", "zcaron", "Ydieresis", "space", "exclamdown", "cent", "sterling", "currency", "yen", "brokenbar", "section", "dieresis", "copyright", "ordfeminine", "guillemotleft", "logicalnot", "hyphen", "registered", "macron", "degree", "plusminus", "twosuperior", "threesuperior", "acute", "mu", "paragraph", "periodcentered", "cedilla", "onesuperior", "ordmasculine", "guillemotright", "onequarter", "onehalf", "threequarters", "questiondown", "Agrave", "Aacute", "Acircumflex", "Atilde", "Adieresis", "Aring", "AE", "Ccedilla", "Egrave", "Eacute", "Ecircumflex", "Edieresis", "Igrave", "Iacute", "Icircumflex", "Idieresis", "Eth", "Ntilde", "Ograve", "Oacute", "Ocircumflex", "Otilde", "Odieresis", "multiply", "Oslash", "Ugrave", "Uacute", "Ucircumflex", "Udieresis", "Yacute", "Thorn", "germandbls", "agrave", "aacute", "acircumflex", "atilde", "adieresis", "aring", "ae", "ccedilla", "egrave", "eacute", "ecircumflex", "edieresis", "igrave", "iacute", "icircumflex", "idieresis", "eth", "ntilde", "ograve", "oacute", "ocircumflex", "otilde", "odieresis", "divide", "oslash", "ugrave", "uacute", "ucircumflex", "udieresis", "yacute", "thorn", "ydieresis"];
  11243. const SymbolSetEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "exclam", "universal", "numbersign", "existential", "percent", "ampersand", "suchthat", "parenleft", "parenright", "asteriskmath", "plus", "comma", "minus", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "congruent", "Alpha", "Beta", "Chi", "Delta", "Epsilon", "Phi", "Gamma", "Eta", "Iota", "theta1", "Kappa", "Lambda", "Mu", "Nu", "Omicron", "Pi", "Theta", "Rho", "Sigma", "Tau", "Upsilon", "sigma1", "Omega", "Xi", "Psi", "Zeta", "bracketleft", "therefore", "bracketright", "perpendicular", "underscore", "radicalex", "alpha", "beta", "chi", "delta", "epsilon", "phi", "gamma", "eta", "iota", "phi1", "kappa", "lambda", "mu", "nu", "omicron", "pi", "theta", "rho", "sigma", "tau", "upsilon", "omega1", "omega", "xi", "psi", "zeta", "braceleft", "bar", "braceright", "similar", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Euro", "Upsilon1", "minute", "lessequal", "fraction", "infinity", "florin", "club", "diamond", "heart", "spade", "arrowboth", "arrowleft", "arrowup", "arrowright", "arrowdown", "degree", "plusminus", "second", "greaterequal", "multiply", "proportional", "partialdiff", "bullet", "divide", "notequal", "equivalence", "approxequal", "ellipsis", "arrowvertex", "arrowhorizex", "carriagereturn", "aleph", "Ifraktur", "Rfraktur", "weierstrass", "circlemultiply", "circleplus", "emptyset", "intersection", "union", "propersuperset", "reflexsuperset", "notsubset", "propersubset", "reflexsubset", "element", "notelement", "angle", "gradient", "registerserif", "copyrightserif", "trademarkserif", "product", "radical", "dotmath", "logicalnot", "logicaland", "logicalor", "arrowdblboth", "arrowdblleft", "arrowdblup", "arrowdblright", "arrowdbldown", "lozenge", "angleleft", "registersans", "copyrightsans", "trademarksans", "summation", "parenlefttp", "parenleftex", "parenleftbt", "bracketlefttp", "bracketleftex", "bracketleftbt", "bracelefttp", "braceleftmid", "braceleftbt", "braceex", "", "angleright", "integral", "integraltp", "integralex", "integralbt", "parenrighttp", "parenrightex", "parenrightbt", "bracketrighttp", "bracketrightex", "bracketrightbt", "bracerighttp", "bracerightmid", "bracerightbt", ""];
  11244. const ZapfDingbatsEncoding = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "space", "a1", "a2", "a202", "a3", "a4", "a5", "a119", "a118", "a117", "a11", "a12", "a13", "a14", "a15", "a16", "a105", "a17", "a18", "a19", "a20", "a21", "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a6", "a7", "a8", "a9", "a10", "a29", "a30", "a31", "a32", "a33", "a34", "a35", "a36", "a37", "a38", "a39", "a40", "a41", "a42", "a43", "a44", "a45", "a46", "a47", "a48", "a49", "a50", "a51", "a52", "a53", "a54", "a55", "a56", "a57", "a58", "a59", "a60", "a61", "a62", "a63", "a64", "a65", "a66", "a67", "a68", "a69", "a70", "a71", "a72", "a73", "a74", "a203", "a75", "a204", "a76", "a77", "a78", "a79", "a81", "a82", "a83", "a84", "a97", "a98", "a99", "a100", "", "a89", "a90", "a93", "a94", "a91", "a92", "a205", "a85", "a206", "a86", "a87", "a88", "a95", "a96", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "a101", "a102", "a103", "a104", "a106", "a107", "a108", "a112", "a111", "a110", "a109", "a120", "a121", "a122", "a123", "a124", "a125", "a126", "a127", "a128", "a129", "a130", "a131", "a132", "a133", "a134", "a135", "a136", "a137", "a138", "a139", "a140", "a141", "a142", "a143", "a144", "a145", "a146", "a147", "a148", "a149", "a150", "a151", "a152", "a153", "a154", "a155", "a156", "a157", "a158", "a159", "a160", "a161", "a163", "a164", "a196", "a165", "a192", "a166", "a167", "a168", "a169", "a170", "a171", "a172", "a173", "a162", "a174", "a175", "a176", "a177", "a178", "a179", "a193", "a180", "a199", "a181", "a200", "a182", "", "a201", "a183", "a184", "a197", "a185", "a194", "a198", "a186", "a195", "a187", "a188", "a189", "a190", "a191", ""];
  11245. function getEncoding(encodingName) {
  11246. switch (encodingName) {
  11247. case "WinAnsiEncoding":
  11248. return WinAnsiEncoding;
  11249. case "StandardEncoding":
  11250. return StandardEncoding;
  11251. case "MacRomanEncoding":
  11252. return MacRomanEncoding;
  11253. case "SymbolSetEncoding":
  11254. return SymbolSetEncoding;
  11255. case "ZapfDingbatsEncoding":
  11256. return ZapfDingbatsEncoding;
  11257. case "ExpertEncoding":
  11258. return ExpertEncoding;
  11259. case "MacExpertEncoding":
  11260. return MacExpertEncoding;
  11261. default:
  11262. return null;
  11263. }
  11264. }
  11265. ;// CONCATENATED MODULE: ./src/core/cff_parser.js
  11266. const MAX_SUBR_NESTING = 10;
  11267. const CFFStandardStrings = [".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent", "sterling", "fraction", "yen", "florin", "section", "currency", "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft", "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl", "periodcentered", "paragraph", "bullet", "quotesinglbase", "quotedblbase", "quotedblright", "guillemotright", "ellipsis", "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde", "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine", "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash", "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu", "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter", "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior", "registered", "minus", "eth", "multiply", "threesuperior", "copyright", "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde", "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex", "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex", "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute", "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla", "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex", "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis", "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis", "ugrave", "yacute", "ydieresis", "zcaron", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle", "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior", "parenrightsuperior", "twodotenleader", "onedotenleader", "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle", "commasuperior", "threequartersemdash", "periodsuperior", "questionsmall", "asuperior", "bsuperior", "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior", "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior", "tsuperior", "ff", "ffi", "ffl", "parenleftinferior", "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall", "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall", "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall", "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall", "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary", "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle", "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall", "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall", "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall", "Cedillasmall", "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths", "seveneighths", "onethird", "twothirds", "zerosuperior", "foursuperior", "fivesuperior", "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior", "zeroinferior", "oneinferior", "twoinferior", "threeinferior", "fourinferior", "fiveinferior", "sixinferior", "seveninferior", "eightinferior", "nineinferior", "centinferior", "dollarinferior", "periodinferior", "commainferior", "Agravesmall", "Aacutesmall", "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall", "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall", "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall", "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall", "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall", "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall", "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall", "Ydieresissmall", "001.000", "001.001", "001.002", "001.003", "Black", "Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold"];
  11268. const NUM_STANDARD_CFF_STRINGS = 391;
  11269. const CharstringValidationData = [null, {
  11270. id: "hstem",
  11271. min: 2,
  11272. stackClearing: true,
  11273. stem: true
  11274. }, null, {
  11275. id: "vstem",
  11276. min: 2,
  11277. stackClearing: true,
  11278. stem: true
  11279. }, {
  11280. id: "vmoveto",
  11281. min: 1,
  11282. stackClearing: true
  11283. }, {
  11284. id: "rlineto",
  11285. min: 2,
  11286. resetStack: true
  11287. }, {
  11288. id: "hlineto",
  11289. min: 1,
  11290. resetStack: true
  11291. }, {
  11292. id: "vlineto",
  11293. min: 1,
  11294. resetStack: true
  11295. }, {
  11296. id: "rrcurveto",
  11297. min: 6,
  11298. resetStack: true
  11299. }, null, {
  11300. id: "callsubr",
  11301. min: 1,
  11302. undefStack: true
  11303. }, {
  11304. id: "return",
  11305. min: 0,
  11306. undefStack: true
  11307. }, null, null, {
  11308. id: "endchar",
  11309. min: 0,
  11310. stackClearing: true
  11311. }, null, null, null, {
  11312. id: "hstemhm",
  11313. min: 2,
  11314. stackClearing: true,
  11315. stem: true
  11316. }, {
  11317. id: "hintmask",
  11318. min: 0,
  11319. stackClearing: true
  11320. }, {
  11321. id: "cntrmask",
  11322. min: 0,
  11323. stackClearing: true
  11324. }, {
  11325. id: "rmoveto",
  11326. min: 2,
  11327. stackClearing: true
  11328. }, {
  11329. id: "hmoveto",
  11330. min: 1,
  11331. stackClearing: true
  11332. }, {
  11333. id: "vstemhm",
  11334. min: 2,
  11335. stackClearing: true,
  11336. stem: true
  11337. }, {
  11338. id: "rcurveline",
  11339. min: 8,
  11340. resetStack: true
  11341. }, {
  11342. id: "rlinecurve",
  11343. min: 8,
  11344. resetStack: true
  11345. }, {
  11346. id: "vvcurveto",
  11347. min: 4,
  11348. resetStack: true
  11349. }, {
  11350. id: "hhcurveto",
  11351. min: 4,
  11352. resetStack: true
  11353. }, null, {
  11354. id: "callgsubr",
  11355. min: 1,
  11356. undefStack: true
  11357. }, {
  11358. id: "vhcurveto",
  11359. min: 4,
  11360. resetStack: true
  11361. }, {
  11362. id: "hvcurveto",
  11363. min: 4,
  11364. resetStack: true
  11365. }];
  11366. const CharstringValidationData12 = [null, null, null, {
  11367. id: "and",
  11368. min: 2,
  11369. stackDelta: -1
  11370. }, {
  11371. id: "or",
  11372. min: 2,
  11373. stackDelta: -1
  11374. }, {
  11375. id: "not",
  11376. min: 1,
  11377. stackDelta: 0
  11378. }, null, null, null, {
  11379. id: "abs",
  11380. min: 1,
  11381. stackDelta: 0
  11382. }, {
  11383. id: "add",
  11384. min: 2,
  11385. stackDelta: -1,
  11386. stackFn(stack, index) {
  11387. stack[index - 2] = stack[index - 2] + stack[index - 1];
  11388. }
  11389. }, {
  11390. id: "sub",
  11391. min: 2,
  11392. stackDelta: -1,
  11393. stackFn(stack, index) {
  11394. stack[index - 2] = stack[index - 2] - stack[index - 1];
  11395. }
  11396. }, {
  11397. id: "div",
  11398. min: 2,
  11399. stackDelta: -1,
  11400. stackFn(stack, index) {
  11401. stack[index - 2] = stack[index - 2] / stack[index - 1];
  11402. }
  11403. }, null, {
  11404. id: "neg",
  11405. min: 1,
  11406. stackDelta: 0,
  11407. stackFn(stack, index) {
  11408. stack[index - 1] = -stack[index - 1];
  11409. }
  11410. }, {
  11411. id: "eq",
  11412. min: 2,
  11413. stackDelta: -1
  11414. }, null, null, {
  11415. id: "drop",
  11416. min: 1,
  11417. stackDelta: -1
  11418. }, null, {
  11419. id: "put",
  11420. min: 2,
  11421. stackDelta: -2
  11422. }, {
  11423. id: "get",
  11424. min: 1,
  11425. stackDelta: 0
  11426. }, {
  11427. id: "ifelse",
  11428. min: 4,
  11429. stackDelta: -3
  11430. }, {
  11431. id: "random",
  11432. min: 0,
  11433. stackDelta: 1
  11434. }, {
  11435. id: "mul",
  11436. min: 2,
  11437. stackDelta: -1,
  11438. stackFn(stack, index) {
  11439. stack[index - 2] = stack[index - 2] * stack[index - 1];
  11440. }
  11441. }, null, {
  11442. id: "sqrt",
  11443. min: 1,
  11444. stackDelta: 0
  11445. }, {
  11446. id: "dup",
  11447. min: 1,
  11448. stackDelta: 1
  11449. }, {
  11450. id: "exch",
  11451. min: 2,
  11452. stackDelta: 0
  11453. }, {
  11454. id: "index",
  11455. min: 2,
  11456. stackDelta: 0
  11457. }, {
  11458. id: "roll",
  11459. min: 3,
  11460. stackDelta: -2
  11461. }, null, null, null, {
  11462. id: "hflex",
  11463. min: 7,
  11464. resetStack: true
  11465. }, {
  11466. id: "flex",
  11467. min: 13,
  11468. resetStack: true
  11469. }, {
  11470. id: "hflex1",
  11471. min: 9,
  11472. resetStack: true
  11473. }, {
  11474. id: "flex1",
  11475. min: 11,
  11476. resetStack: true
  11477. }];
  11478. class CFFParser {
  11479. constructor(file, properties, seacAnalysisEnabled) {
  11480. this.bytes = file.getBytes();
  11481. this.properties = properties;
  11482. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  11483. }
  11484. parse() {
  11485. const properties = this.properties;
  11486. const cff = new CFF();
  11487. this.cff = cff;
  11488. const header = this.parseHeader();
  11489. const nameIndex = this.parseIndex(header.endPos);
  11490. const topDictIndex = this.parseIndex(nameIndex.endPos);
  11491. const stringIndex = this.parseIndex(topDictIndex.endPos);
  11492. const globalSubrIndex = this.parseIndex(stringIndex.endPos);
  11493. const topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  11494. const topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  11495. cff.header = header.obj;
  11496. cff.names = this.parseNameIndex(nameIndex.obj);
  11497. cff.strings = this.parseStringIndex(stringIndex.obj);
  11498. cff.topDict = topDict;
  11499. cff.globalSubrIndex = globalSubrIndex.obj;
  11500. this.parsePrivateDict(cff.topDict);
  11501. cff.isCIDFont = topDict.hasName("ROS");
  11502. const charStringOffset = topDict.getByName("CharStrings");
  11503. const charStringIndex = this.parseIndex(charStringOffset).obj;
  11504. const fontMatrix = topDict.getByName("FontMatrix");
  11505. if (fontMatrix) {
  11506. properties.fontMatrix = fontMatrix;
  11507. }
  11508. const fontBBox = topDict.getByName("FontBBox");
  11509. if (fontBBox) {
  11510. properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
  11511. properties.descent = Math.min(fontBBox[1], fontBBox[3]);
  11512. properties.ascentScaled = true;
  11513. }
  11514. let charset, encoding;
  11515. if (cff.isCIDFont) {
  11516. const fdArrayIndex = this.parseIndex(topDict.getByName("FDArray")).obj;
  11517. for (let i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  11518. const dictRaw = fdArrayIndex.get(i);
  11519. const fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  11520. this.parsePrivateDict(fontDict);
  11521. cff.fdArray.push(fontDict);
  11522. }
  11523. encoding = null;
  11524. charset = this.parseCharsets(topDict.getByName("charset"), charStringIndex.count, cff.strings, true);
  11525. cff.fdSelect = this.parseFDSelect(topDict.getByName("FDSelect"), charStringIndex.count);
  11526. } else {
  11527. charset = this.parseCharsets(topDict.getByName("charset"), charStringIndex.count, cff.strings, false);
  11528. encoding = this.parseEncoding(topDict.getByName("Encoding"), properties, cff.strings, charset.charset);
  11529. }
  11530. cff.charset = charset;
  11531. cff.encoding = encoding;
  11532. const charStringsAndSeacs = this.parseCharStrings({
  11533. charStrings: charStringIndex,
  11534. localSubrIndex: topDict.privateDict.subrsIndex,
  11535. globalSubrIndex: globalSubrIndex.obj,
  11536. fdSelect: cff.fdSelect,
  11537. fdArray: cff.fdArray,
  11538. privateDict: topDict.privateDict
  11539. });
  11540. cff.charStrings = charStringsAndSeacs.charStrings;
  11541. cff.seacs = charStringsAndSeacs.seacs;
  11542. cff.widths = charStringsAndSeacs.widths;
  11543. return cff;
  11544. }
  11545. parseHeader() {
  11546. let bytes = this.bytes;
  11547. const bytesLength = bytes.length;
  11548. let offset = 0;
  11549. while (offset < bytesLength && bytes[offset] !== 1) {
  11550. ++offset;
  11551. }
  11552. if (offset >= bytesLength) {
  11553. throw new FormatError("Invalid CFF header");
  11554. }
  11555. if (offset !== 0) {
  11556. info("cff data is shifted");
  11557. bytes = bytes.subarray(offset);
  11558. this.bytes = bytes;
  11559. }
  11560. const major = bytes[0];
  11561. const minor = bytes[1];
  11562. const hdrSize = bytes[2];
  11563. const offSize = bytes[3];
  11564. const header = new CFFHeader(major, minor, hdrSize, offSize);
  11565. return {
  11566. obj: header,
  11567. endPos: hdrSize
  11568. };
  11569. }
  11570. parseDict(dict) {
  11571. let pos = 0;
  11572. function parseOperand() {
  11573. let value = dict[pos++];
  11574. if (value === 30) {
  11575. return parseFloatOperand();
  11576. } else if (value === 28) {
  11577. value = dict[pos++];
  11578. value = (value << 24 | dict[pos++] << 16) >> 16;
  11579. return value;
  11580. } else if (value === 29) {
  11581. value = dict[pos++];
  11582. value = value << 8 | dict[pos++];
  11583. value = value << 8 | dict[pos++];
  11584. value = value << 8 | dict[pos++];
  11585. return value;
  11586. } else if (value >= 32 && value <= 246) {
  11587. return value - 139;
  11588. } else if (value >= 247 && value <= 250) {
  11589. return (value - 247) * 256 + dict[pos++] + 108;
  11590. } else if (value >= 251 && value <= 254) {
  11591. return -((value - 251) * 256) - dict[pos++] - 108;
  11592. }
  11593. warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
  11594. return NaN;
  11595. }
  11596. function parseFloatOperand() {
  11597. let str = "";
  11598. const eof = 15;
  11599. const lookup = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "E", "E-", null, "-"];
  11600. const length = dict.length;
  11601. while (pos < length) {
  11602. const b = dict[pos++];
  11603. const b1 = b >> 4;
  11604. const b2 = b & 15;
  11605. if (b1 === eof) {
  11606. break;
  11607. }
  11608. str += lookup[b1];
  11609. if (b2 === eof) {
  11610. break;
  11611. }
  11612. str += lookup[b2];
  11613. }
  11614. return parseFloat(str);
  11615. }
  11616. let operands = [];
  11617. const entries = [];
  11618. pos = 0;
  11619. const end = dict.length;
  11620. while (pos < end) {
  11621. let b = dict[pos];
  11622. if (b <= 21) {
  11623. if (b === 12) {
  11624. b = b << 8 | dict[++pos];
  11625. }
  11626. entries.push([b, operands]);
  11627. operands = [];
  11628. ++pos;
  11629. } else {
  11630. operands.push(parseOperand());
  11631. }
  11632. }
  11633. return entries;
  11634. }
  11635. parseIndex(pos) {
  11636. const cffIndex = new CFFIndex();
  11637. const bytes = this.bytes;
  11638. const count = bytes[pos++] << 8 | bytes[pos++];
  11639. const offsets = [];
  11640. let end = pos;
  11641. let i, ii;
  11642. if (count !== 0) {
  11643. const offsetSize = bytes[pos++];
  11644. const startPos = pos + (count + 1) * offsetSize - 1;
  11645. for (i = 0, ii = count + 1; i < ii; ++i) {
  11646. let offset = 0;
  11647. for (let j = 0; j < offsetSize; ++j) {
  11648. offset <<= 8;
  11649. offset += bytes[pos++];
  11650. }
  11651. offsets.push(startPos + offset);
  11652. }
  11653. end = offsets[count];
  11654. }
  11655. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  11656. const offsetStart = offsets[i];
  11657. const offsetEnd = offsets[i + 1];
  11658. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  11659. }
  11660. return {
  11661. obj: cffIndex,
  11662. endPos: end
  11663. };
  11664. }
  11665. parseNameIndex(index) {
  11666. const names = [];
  11667. for (let i = 0, ii = index.count; i < ii; ++i) {
  11668. const name = index.get(i);
  11669. names.push(bytesToString(name));
  11670. }
  11671. return names;
  11672. }
  11673. parseStringIndex(index) {
  11674. const strings = new CFFStrings();
  11675. for (let i = 0, ii = index.count; i < ii; ++i) {
  11676. const data = index.get(i);
  11677. strings.add(bytesToString(data));
  11678. }
  11679. return strings;
  11680. }
  11681. createDict(Type, dict, strings) {
  11682. const cffDict = new Type(strings);
  11683. for (const [key, value] of dict) {
  11684. cffDict.setByKey(key, value);
  11685. }
  11686. return cffDict;
  11687. }
  11688. parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  11689. if (!data || state.callDepth > MAX_SUBR_NESTING) {
  11690. return false;
  11691. }
  11692. let stackSize = state.stackSize;
  11693. const stack = state.stack;
  11694. let length = data.length;
  11695. for (let j = 0; j < length;) {
  11696. const value = data[j++];
  11697. let validationCommand = null;
  11698. if (value === 12) {
  11699. const q = data[j++];
  11700. if (q === 0) {
  11701. data[j - 2] = 139;
  11702. data[j - 1] = 22;
  11703. stackSize = 0;
  11704. } else {
  11705. validationCommand = CharstringValidationData12[q];
  11706. }
  11707. } else if (value === 28) {
  11708. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  11709. j += 2;
  11710. stackSize++;
  11711. } else if (value === 14) {
  11712. if (stackSize >= 4) {
  11713. stackSize -= 4;
  11714. if (this.seacAnalysisEnabled) {
  11715. state.seac = stack.slice(stackSize, stackSize + 4);
  11716. return false;
  11717. }
  11718. }
  11719. validationCommand = CharstringValidationData[value];
  11720. } else if (value >= 32 && value <= 246) {
  11721. stack[stackSize] = value - 139;
  11722. stackSize++;
  11723. } else if (value >= 247 && value <= 254) {
  11724. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  11725. j++;
  11726. stackSize++;
  11727. } else if (value === 255) {
  11728. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  11729. j += 4;
  11730. stackSize++;
  11731. } else if (value === 19 || value === 20) {
  11732. state.hints += stackSize >> 1;
  11733. if (state.hints === 0) {
  11734. data.copyWithin(j - 1, j, -1);
  11735. j -= 1;
  11736. length -= 1;
  11737. continue;
  11738. }
  11739. j += state.hints + 7 >> 3;
  11740. stackSize %= 2;
  11741. validationCommand = CharstringValidationData[value];
  11742. } else if (value === 10 || value === 29) {
  11743. const subrsIndex = value === 10 ? localSubrIndex : globalSubrIndex;
  11744. if (!subrsIndex) {
  11745. validationCommand = CharstringValidationData[value];
  11746. warn("Missing subrsIndex for " + validationCommand.id);
  11747. return false;
  11748. }
  11749. let bias = 32768;
  11750. if (subrsIndex.count < 1240) {
  11751. bias = 107;
  11752. } else if (subrsIndex.count < 33900) {
  11753. bias = 1131;
  11754. }
  11755. const subrNumber = stack[--stackSize] + bias;
  11756. if (subrNumber < 0 || subrNumber >= subrsIndex.count || isNaN(subrNumber)) {
  11757. validationCommand = CharstringValidationData[value];
  11758. warn("Out of bounds subrIndex for " + validationCommand.id);
  11759. return false;
  11760. }
  11761. state.stackSize = stackSize;
  11762. state.callDepth++;
  11763. const valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  11764. if (!valid) {
  11765. return false;
  11766. }
  11767. state.callDepth--;
  11768. stackSize = state.stackSize;
  11769. continue;
  11770. } else if (value === 11) {
  11771. state.stackSize = stackSize;
  11772. return true;
  11773. } else if (value === 0 && j === data.length) {
  11774. data[j - 1] = 14;
  11775. validationCommand = CharstringValidationData[14];
  11776. } else if (value === 9) {
  11777. data.copyWithin(j - 1, j, -1);
  11778. j -= 1;
  11779. length -= 1;
  11780. continue;
  11781. } else {
  11782. validationCommand = CharstringValidationData[value];
  11783. }
  11784. if (validationCommand) {
  11785. if (validationCommand.stem) {
  11786. state.hints += stackSize >> 1;
  11787. if (value === 3 || value === 23) {
  11788. state.hasVStems = true;
  11789. } else if (state.hasVStems && (value === 1 || value === 18)) {
  11790. warn("CFF stem hints are in wrong order");
  11791. data[j - 1] = value === 1 ? 3 : 23;
  11792. }
  11793. }
  11794. if ("min" in validationCommand) {
  11795. if (!state.undefStack && stackSize < validationCommand.min) {
  11796. warn("Not enough parameters for " + validationCommand.id + "; actual: " + stackSize + ", expected: " + validationCommand.min);
  11797. if (stackSize === 0) {
  11798. data[j - 1] = 14;
  11799. return true;
  11800. }
  11801. return false;
  11802. }
  11803. }
  11804. if (state.firstStackClearing && validationCommand.stackClearing) {
  11805. state.firstStackClearing = false;
  11806. stackSize -= validationCommand.min;
  11807. if (stackSize >= 2 && validationCommand.stem) {
  11808. stackSize %= 2;
  11809. } else if (stackSize > 1) {
  11810. warn("Found too many parameters for stack-clearing command");
  11811. }
  11812. if (stackSize > 0) {
  11813. state.width = stack[stackSize - 1];
  11814. }
  11815. }
  11816. if ("stackDelta" in validationCommand) {
  11817. if ("stackFn" in validationCommand) {
  11818. validationCommand.stackFn(stack, stackSize);
  11819. }
  11820. stackSize += validationCommand.stackDelta;
  11821. } else if (validationCommand.stackClearing) {
  11822. stackSize = 0;
  11823. } else if (validationCommand.resetStack) {
  11824. stackSize = 0;
  11825. state.undefStack = false;
  11826. } else if (validationCommand.undefStack) {
  11827. stackSize = 0;
  11828. state.undefStack = true;
  11829. state.firstStackClearing = false;
  11830. }
  11831. }
  11832. }
  11833. if (length < data.length) {
  11834. data.fill(14, length);
  11835. }
  11836. state.stackSize = stackSize;
  11837. return true;
  11838. }
  11839. parseCharStrings({
  11840. charStrings,
  11841. localSubrIndex,
  11842. globalSubrIndex,
  11843. fdSelect,
  11844. fdArray,
  11845. privateDict
  11846. }) {
  11847. const seacs = [];
  11848. const widths = [];
  11849. const count = charStrings.count;
  11850. for (let i = 0; i < count; i++) {
  11851. const charstring = charStrings.get(i);
  11852. const state = {
  11853. callDepth: 0,
  11854. stackSize: 0,
  11855. stack: [],
  11856. undefStack: true,
  11857. hints: 0,
  11858. firstStackClearing: true,
  11859. seac: null,
  11860. width: null,
  11861. hasVStems: false
  11862. };
  11863. let valid = true;
  11864. let localSubrToUse = null;
  11865. let privateDictToUse = privateDict;
  11866. if (fdSelect && fdArray.length) {
  11867. const fdIndex = fdSelect.getFDIndex(i);
  11868. if (fdIndex === -1) {
  11869. warn("Glyph index is not in fd select.");
  11870. valid = false;
  11871. }
  11872. if (fdIndex >= fdArray.length) {
  11873. warn("Invalid fd index for glyph index.");
  11874. valid = false;
  11875. }
  11876. if (valid) {
  11877. privateDictToUse = fdArray[fdIndex].privateDict;
  11878. localSubrToUse = privateDictToUse.subrsIndex;
  11879. }
  11880. } else if (localSubrIndex) {
  11881. localSubrToUse = localSubrIndex;
  11882. }
  11883. if (valid) {
  11884. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  11885. }
  11886. if (state.width !== null) {
  11887. const nominalWidth = privateDictToUse.getByName("nominalWidthX");
  11888. widths[i] = nominalWidth + state.width;
  11889. } else {
  11890. const defaultWidth = privateDictToUse.getByName("defaultWidthX");
  11891. widths[i] = defaultWidth;
  11892. }
  11893. if (state.seac !== null) {
  11894. seacs[i] = state.seac;
  11895. }
  11896. if (!valid) {
  11897. charStrings.set(i, new Uint8Array([14]));
  11898. }
  11899. }
  11900. return {
  11901. charStrings,
  11902. seacs,
  11903. widths
  11904. };
  11905. }
  11906. emptyPrivateDictionary(parentDict) {
  11907. const privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  11908. parentDict.setByKey(18, [0, 0]);
  11909. parentDict.privateDict = privateDict;
  11910. }
  11911. parsePrivateDict(parentDict) {
  11912. if (!parentDict.hasName("Private")) {
  11913. this.emptyPrivateDictionary(parentDict);
  11914. return;
  11915. }
  11916. const privateOffset = parentDict.getByName("Private");
  11917. if (!Array.isArray(privateOffset) || privateOffset.length !== 2) {
  11918. parentDict.removeByName("Private");
  11919. return;
  11920. }
  11921. const size = privateOffset[0];
  11922. const offset = privateOffset[1];
  11923. if (size === 0 || offset >= this.bytes.length) {
  11924. this.emptyPrivateDictionary(parentDict);
  11925. return;
  11926. }
  11927. const privateDictEnd = offset + size;
  11928. const dictData = this.bytes.subarray(offset, privateDictEnd);
  11929. const dict = this.parseDict(dictData);
  11930. const privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  11931. parentDict.privateDict = privateDict;
  11932. if (privateDict.getByName("ExpansionFactor") === 0) {
  11933. privateDict.setByName("ExpansionFactor", 0.06);
  11934. }
  11935. if (!privateDict.getByName("Subrs")) {
  11936. return;
  11937. }
  11938. const subrsOffset = privateDict.getByName("Subrs");
  11939. const relativeOffset = offset + subrsOffset;
  11940. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  11941. this.emptyPrivateDictionary(parentDict);
  11942. return;
  11943. }
  11944. const subrsIndex = this.parseIndex(relativeOffset);
  11945. privateDict.subrsIndex = subrsIndex.obj;
  11946. }
  11947. parseCharsets(pos, length, strings, cid) {
  11948. if (pos === 0) {
  11949. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  11950. } else if (pos === 1) {
  11951. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  11952. } else if (pos === 2) {
  11953. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  11954. }
  11955. const bytes = this.bytes;
  11956. const start = pos;
  11957. const format = bytes[pos++];
  11958. const charset = [cid ? 0 : ".notdef"];
  11959. let id, count, i;
  11960. length -= 1;
  11961. switch (format) {
  11962. case 0:
  11963. for (i = 0; i < length; i++) {
  11964. id = bytes[pos++] << 8 | bytes[pos++];
  11965. charset.push(cid ? id : strings.get(id));
  11966. }
  11967. break;
  11968. case 1:
  11969. while (charset.length <= length) {
  11970. id = bytes[pos++] << 8 | bytes[pos++];
  11971. count = bytes[pos++];
  11972. for (i = 0; i <= count; i++) {
  11973. charset.push(cid ? id++ : strings.get(id++));
  11974. }
  11975. }
  11976. break;
  11977. case 2:
  11978. while (charset.length <= length) {
  11979. id = bytes[pos++] << 8 | bytes[pos++];
  11980. count = bytes[pos++] << 8 | bytes[pos++];
  11981. for (i = 0; i <= count; i++) {
  11982. charset.push(cid ? id++ : strings.get(id++));
  11983. }
  11984. }
  11985. break;
  11986. default:
  11987. throw new FormatError("Unknown charset format");
  11988. }
  11989. const end = pos;
  11990. const raw = bytes.subarray(start, end);
  11991. return new CFFCharset(false, format, charset, raw);
  11992. }
  11993. parseEncoding(pos, properties, strings, charset) {
  11994. const encoding = Object.create(null);
  11995. const bytes = this.bytes;
  11996. let predefined = false;
  11997. let format, i, ii;
  11998. let raw = null;
  11999. function readSupplement() {
  12000. const supplementsCount = bytes[pos++];
  12001. for (i = 0; i < supplementsCount; i++) {
  12002. const code = bytes[pos++];
  12003. const sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  12004. encoding[code] = charset.indexOf(strings.get(sid));
  12005. }
  12006. }
  12007. if (pos === 0 || pos === 1) {
  12008. predefined = true;
  12009. format = pos;
  12010. const baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  12011. for (i = 0, ii = charset.length; i < ii; i++) {
  12012. const index = baseEncoding.indexOf(charset[i]);
  12013. if (index !== -1) {
  12014. encoding[index] = i;
  12015. }
  12016. }
  12017. } else {
  12018. const dataStart = pos;
  12019. format = bytes[pos++];
  12020. switch (format & 0x7f) {
  12021. case 0:
  12022. const glyphsCount = bytes[pos++];
  12023. for (i = 1; i <= glyphsCount; i++) {
  12024. encoding[bytes[pos++]] = i;
  12025. }
  12026. break;
  12027. case 1:
  12028. const rangesCount = bytes[pos++];
  12029. let gid = 1;
  12030. for (i = 0; i < rangesCount; i++) {
  12031. const start = bytes[pos++];
  12032. const left = bytes[pos++];
  12033. for (let j = start; j <= start + left; j++) {
  12034. encoding[j] = gid++;
  12035. }
  12036. }
  12037. break;
  12038. default:
  12039. throw new FormatError(`Unknown encoding format: ${format} in CFF`);
  12040. }
  12041. const dataEnd = pos;
  12042. if (format & 0x80) {
  12043. bytes[dataStart] &= 0x7f;
  12044. readSupplement();
  12045. }
  12046. raw = bytes.subarray(dataStart, dataEnd);
  12047. }
  12048. format &= 0x7f;
  12049. return new CFFEncoding(predefined, format, encoding, raw);
  12050. }
  12051. parseFDSelect(pos, length) {
  12052. const bytes = this.bytes;
  12053. const format = bytes[pos++];
  12054. const fdSelect = [];
  12055. let i;
  12056. switch (format) {
  12057. case 0:
  12058. for (i = 0; i < length; ++i) {
  12059. const id = bytes[pos++];
  12060. fdSelect.push(id);
  12061. }
  12062. break;
  12063. case 3:
  12064. const rangesCount = bytes[pos++] << 8 | bytes[pos++];
  12065. for (i = 0; i < rangesCount; ++i) {
  12066. let first = bytes[pos++] << 8 | bytes[pos++];
  12067. if (i === 0 && first !== 0) {
  12068. warn("parseFDSelect: The first range must have a first GID of 0" + " -- trying to recover.");
  12069. first = 0;
  12070. }
  12071. const fdIndex = bytes[pos++];
  12072. const next = bytes[pos] << 8 | bytes[pos + 1];
  12073. for (let j = first; j < next; ++j) {
  12074. fdSelect.push(fdIndex);
  12075. }
  12076. }
  12077. pos += 2;
  12078. break;
  12079. default:
  12080. throw new FormatError(`parseFDSelect: Unknown format "${format}".`);
  12081. }
  12082. if (fdSelect.length !== length) {
  12083. throw new FormatError("parseFDSelect: Invalid font data.");
  12084. }
  12085. return new CFFFDSelect(format, fdSelect);
  12086. }
  12087. }
  12088. class CFF {
  12089. constructor() {
  12090. this.header = null;
  12091. this.names = [];
  12092. this.topDict = null;
  12093. this.strings = new CFFStrings();
  12094. this.globalSubrIndex = null;
  12095. this.encoding = null;
  12096. this.charset = null;
  12097. this.charStrings = null;
  12098. this.fdArray = [];
  12099. this.fdSelect = null;
  12100. this.isCIDFont = false;
  12101. }
  12102. duplicateFirstGlyph() {
  12103. if (this.charStrings.count >= 65535) {
  12104. warn("Not enough space in charstrings to duplicate first glyph.");
  12105. return;
  12106. }
  12107. const glyphZero = this.charStrings.get(0);
  12108. this.charStrings.add(glyphZero);
  12109. if (this.isCIDFont) {
  12110. this.fdSelect.fdSelect.push(this.fdSelect.fdSelect[0]);
  12111. }
  12112. }
  12113. hasGlyphId(id) {
  12114. if (id < 0 || id >= this.charStrings.count) {
  12115. return false;
  12116. }
  12117. const glyph = this.charStrings.get(id);
  12118. return glyph.length > 0;
  12119. }
  12120. }
  12121. class CFFHeader {
  12122. constructor(major, minor, hdrSize, offSize) {
  12123. this.major = major;
  12124. this.minor = minor;
  12125. this.hdrSize = hdrSize;
  12126. this.offSize = offSize;
  12127. }
  12128. }
  12129. class CFFStrings {
  12130. constructor() {
  12131. this.strings = [];
  12132. }
  12133. get(index) {
  12134. if (index >= 0 && index <= NUM_STANDARD_CFF_STRINGS - 1) {
  12135. return CFFStandardStrings[index];
  12136. }
  12137. if (index - NUM_STANDARD_CFF_STRINGS <= this.strings.length) {
  12138. return this.strings[index - NUM_STANDARD_CFF_STRINGS];
  12139. }
  12140. return CFFStandardStrings[0];
  12141. }
  12142. getSID(str) {
  12143. let index = CFFStandardStrings.indexOf(str);
  12144. if (index !== -1) {
  12145. return index;
  12146. }
  12147. index = this.strings.indexOf(str);
  12148. if (index !== -1) {
  12149. return index + NUM_STANDARD_CFF_STRINGS;
  12150. }
  12151. return -1;
  12152. }
  12153. add(value) {
  12154. this.strings.push(value);
  12155. }
  12156. get count() {
  12157. return this.strings.length;
  12158. }
  12159. }
  12160. class CFFIndex {
  12161. constructor() {
  12162. this.objects = [];
  12163. this.length = 0;
  12164. }
  12165. add(data) {
  12166. this.length += data.length;
  12167. this.objects.push(data);
  12168. }
  12169. set(index, data) {
  12170. this.length += data.length - this.objects[index].length;
  12171. this.objects[index] = data;
  12172. }
  12173. get(index) {
  12174. return this.objects[index];
  12175. }
  12176. get count() {
  12177. return this.objects.length;
  12178. }
  12179. }
  12180. class CFFDict {
  12181. constructor(tables, strings) {
  12182. this.keyToNameMap = tables.keyToNameMap;
  12183. this.nameToKeyMap = tables.nameToKeyMap;
  12184. this.defaults = tables.defaults;
  12185. this.types = tables.types;
  12186. this.opcodes = tables.opcodes;
  12187. this.order = tables.order;
  12188. this.strings = strings;
  12189. this.values = Object.create(null);
  12190. }
  12191. setByKey(key, value) {
  12192. if (!(key in this.keyToNameMap)) {
  12193. return false;
  12194. }
  12195. if (value.length === 0) {
  12196. return true;
  12197. }
  12198. for (const val of value) {
  12199. if (isNaN(val)) {
  12200. warn(`Invalid CFFDict value: "${value}" for key "${key}".`);
  12201. return true;
  12202. }
  12203. }
  12204. const type = this.types[key];
  12205. if (type === "num" || type === "sid" || type === "offset") {
  12206. value = value[0];
  12207. }
  12208. this.values[key] = value;
  12209. return true;
  12210. }
  12211. setByName(name, value) {
  12212. if (!(name in this.nameToKeyMap)) {
  12213. throw new FormatError(`Invalid dictionary name "${name}"`);
  12214. }
  12215. this.values[this.nameToKeyMap[name]] = value;
  12216. }
  12217. hasName(name) {
  12218. return this.nameToKeyMap[name] in this.values;
  12219. }
  12220. getByName(name) {
  12221. if (!(name in this.nameToKeyMap)) {
  12222. throw new FormatError(`Invalid dictionary name ${name}"`);
  12223. }
  12224. const key = this.nameToKeyMap[name];
  12225. if (!(key in this.values)) {
  12226. return this.defaults[key];
  12227. }
  12228. return this.values[key];
  12229. }
  12230. removeByName(name) {
  12231. delete this.values[this.nameToKeyMap[name]];
  12232. }
  12233. static createTables(layout) {
  12234. const tables = {
  12235. keyToNameMap: {},
  12236. nameToKeyMap: {},
  12237. defaults: {},
  12238. types: {},
  12239. opcodes: {},
  12240. order: []
  12241. };
  12242. for (const entry of layout) {
  12243. const key = Array.isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  12244. tables.keyToNameMap[key] = entry[1];
  12245. tables.nameToKeyMap[entry[1]] = key;
  12246. tables.types[key] = entry[2];
  12247. tables.defaults[key] = entry[3];
  12248. tables.opcodes[key] = Array.isArray(entry[0]) ? entry[0] : [entry[0]];
  12249. tables.order.push(key);
  12250. }
  12251. return tables;
  12252. }
  12253. }
  12254. const CFFTopDictLayout = [[[12, 30], "ROS", ["sid", "sid", "num"], null], [[12, 20], "SyntheticBase", "num", null], [0, "version", "sid", null], [1, "Notice", "sid", null], [[12, 0], "Copyright", "sid", null], [2, "FullName", "sid", null], [3, "FamilyName", "sid", null], [4, "Weight", "sid", null], [[12, 1], "isFixedPitch", "num", 0], [[12, 2], "ItalicAngle", "num", 0], [[12, 3], "UnderlinePosition", "num", -100], [[12, 4], "UnderlineThickness", "num", 50], [[12, 5], "PaintType", "num", 0], [[12, 6], "CharstringType", "num", 2], [[12, 7], "FontMatrix", ["num", "num", "num", "num", "num", "num"], [0.001, 0, 0, 0.001, 0, 0]], [13, "UniqueID", "num", null], [5, "FontBBox", ["num", "num", "num", "num"], [0, 0, 0, 0]], [[12, 8], "StrokeWidth", "num", 0], [14, "XUID", "array", null], [15, "charset", "offset", 0], [16, "Encoding", "offset", 0], [17, "CharStrings", "offset", 0], [18, "Private", ["offset", "offset"], null], [[12, 21], "PostScript", "sid", null], [[12, 22], "BaseFontName", "sid", null], [[12, 23], "BaseFontBlend", "delta", null], [[12, 31], "CIDFontVersion", "num", 0], [[12, 32], "CIDFontRevision", "num", 0], [[12, 33], "CIDFontType", "num", 0], [[12, 34], "CIDCount", "num", 8720], [[12, 35], "UIDBase", "num", null], [[12, 37], "FDSelect", "offset", null], [[12, 36], "FDArray", "offset", null], [[12, 38], "FontName", "sid", null]];
  12255. class CFFTopDict extends CFFDict {
  12256. static get tables() {
  12257. return shadow(this, "tables", this.createTables(CFFTopDictLayout));
  12258. }
  12259. constructor(strings) {
  12260. super(CFFTopDict.tables, strings);
  12261. this.privateDict = null;
  12262. }
  12263. }
  12264. const CFFPrivateDictLayout = [[6, "BlueValues", "delta", null], [7, "OtherBlues", "delta", null], [8, "FamilyBlues", "delta", null], [9, "FamilyOtherBlues", "delta", null], [[12, 9], "BlueScale", "num", 0.039625], [[12, 10], "BlueShift", "num", 7], [[12, 11], "BlueFuzz", "num", 1], [10, "StdHW", "num", null], [11, "StdVW", "num", null], [[12, 12], "StemSnapH", "delta", null], [[12, 13], "StemSnapV", "delta", null], [[12, 14], "ForceBold", "num", 0], [[12, 17], "LanguageGroup", "num", 0], [[12, 18], "ExpansionFactor", "num", 0.06], [[12, 19], "initialRandomSeed", "num", 0], [20, "defaultWidthX", "num", 0], [21, "nominalWidthX", "num", 0], [19, "Subrs", "offset", null]];
  12265. class CFFPrivateDict extends CFFDict {
  12266. static get tables() {
  12267. return shadow(this, "tables", this.createTables(CFFPrivateDictLayout));
  12268. }
  12269. constructor(strings) {
  12270. super(CFFPrivateDict.tables, strings);
  12271. this.subrsIndex = null;
  12272. }
  12273. }
  12274. const CFFCharsetPredefinedTypes = {
  12275. ISO_ADOBE: 0,
  12276. EXPERT: 1,
  12277. EXPERT_SUBSET: 2
  12278. };
  12279. class CFFCharset {
  12280. constructor(predefined, format, charset, raw) {
  12281. this.predefined = predefined;
  12282. this.format = format;
  12283. this.charset = charset;
  12284. this.raw = raw;
  12285. }
  12286. }
  12287. class CFFEncoding {
  12288. constructor(predefined, format, encoding, raw) {
  12289. this.predefined = predefined;
  12290. this.format = format;
  12291. this.encoding = encoding;
  12292. this.raw = raw;
  12293. }
  12294. }
  12295. class CFFFDSelect {
  12296. constructor(format, fdSelect) {
  12297. this.format = format;
  12298. this.fdSelect = fdSelect;
  12299. }
  12300. getFDIndex(glyphIndex) {
  12301. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  12302. return -1;
  12303. }
  12304. return this.fdSelect[glyphIndex];
  12305. }
  12306. }
  12307. class CFFOffsetTracker {
  12308. constructor() {
  12309. this.offsets = Object.create(null);
  12310. }
  12311. isTracking(key) {
  12312. return key in this.offsets;
  12313. }
  12314. track(key, location) {
  12315. if (key in this.offsets) {
  12316. throw new FormatError(`Already tracking location of ${key}`);
  12317. }
  12318. this.offsets[key] = location;
  12319. }
  12320. offset(value) {
  12321. for (const key in this.offsets) {
  12322. this.offsets[key] += value;
  12323. }
  12324. }
  12325. setEntryLocation(key, values, output) {
  12326. if (!(key in this.offsets)) {
  12327. throw new FormatError(`Not tracking location of ${key}`);
  12328. }
  12329. const data = output.data;
  12330. const dataOffset = this.offsets[key];
  12331. const size = 5;
  12332. for (let i = 0, ii = values.length; i < ii; ++i) {
  12333. const offset0 = i * size + dataOffset;
  12334. const offset1 = offset0 + 1;
  12335. const offset2 = offset0 + 2;
  12336. const offset3 = offset0 + 3;
  12337. const offset4 = offset0 + 4;
  12338. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  12339. throw new FormatError("writing to an offset that is not empty");
  12340. }
  12341. const value = values[i];
  12342. data[offset0] = 0x1d;
  12343. data[offset1] = value >> 24 & 0xff;
  12344. data[offset2] = value >> 16 & 0xff;
  12345. data[offset3] = value >> 8 & 0xff;
  12346. data[offset4] = value & 0xff;
  12347. }
  12348. }
  12349. }
  12350. class CFFCompiler {
  12351. constructor(cff) {
  12352. this.cff = cff;
  12353. }
  12354. compile() {
  12355. const cff = this.cff;
  12356. const output = {
  12357. data: [],
  12358. length: 0,
  12359. add(data) {
  12360. try {
  12361. this.data.push(...data);
  12362. } catch {
  12363. this.data = this.data.concat(data);
  12364. }
  12365. this.length = this.data.length;
  12366. }
  12367. };
  12368. const header = this.compileHeader(cff.header);
  12369. output.add(header);
  12370. const nameIndex = this.compileNameIndex(cff.names);
  12371. output.add(nameIndex);
  12372. if (cff.isCIDFont) {
  12373. if (cff.topDict.hasName("FontMatrix")) {
  12374. const base = cff.topDict.getByName("FontMatrix");
  12375. cff.topDict.removeByName("FontMatrix");
  12376. for (const subDict of cff.fdArray) {
  12377. let matrix = base.slice(0);
  12378. if (subDict.hasName("FontMatrix")) {
  12379. matrix = Util.transform(matrix, subDict.getByName("FontMatrix"));
  12380. }
  12381. subDict.setByName("FontMatrix", matrix);
  12382. }
  12383. }
  12384. }
  12385. const xuid = cff.topDict.getByName("XUID");
  12386. if (xuid?.length > 16) {
  12387. cff.topDict.removeByName("XUID");
  12388. }
  12389. cff.topDict.setByName("charset", 0);
  12390. let compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  12391. output.add(compiled.output);
  12392. const topDictTracker = compiled.trackers[0];
  12393. const stringIndex = this.compileStringIndex(cff.strings.strings);
  12394. output.add(stringIndex);
  12395. const globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  12396. output.add(globalSubrIndex);
  12397. if (cff.encoding && cff.topDict.hasName("Encoding")) {
  12398. if (cff.encoding.predefined) {
  12399. topDictTracker.setEntryLocation("Encoding", [cff.encoding.format], output);
  12400. } else {
  12401. const encoding = this.compileEncoding(cff.encoding);
  12402. topDictTracker.setEntryLocation("Encoding", [output.length], output);
  12403. output.add(encoding);
  12404. }
  12405. }
  12406. const charset = this.compileCharset(cff.charset, cff.charStrings.count, cff.strings, cff.isCIDFont);
  12407. topDictTracker.setEntryLocation("charset", [output.length], output);
  12408. output.add(charset);
  12409. const charStrings = this.compileCharStrings(cff.charStrings);
  12410. topDictTracker.setEntryLocation("CharStrings", [output.length], output);
  12411. output.add(charStrings);
  12412. if (cff.isCIDFont) {
  12413. topDictTracker.setEntryLocation("FDSelect", [output.length], output);
  12414. const fdSelect = this.compileFDSelect(cff.fdSelect);
  12415. output.add(fdSelect);
  12416. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  12417. topDictTracker.setEntryLocation("FDArray", [output.length], output);
  12418. output.add(compiled.output);
  12419. const fontDictTrackers = compiled.trackers;
  12420. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  12421. }
  12422. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  12423. output.add([0]);
  12424. return output.data;
  12425. }
  12426. encodeNumber(value) {
  12427. if (Number.isInteger(value)) {
  12428. return this.encodeInteger(value);
  12429. }
  12430. return this.encodeFloat(value);
  12431. }
  12432. static get EncodeFloatRegExp() {
  12433. return shadow(this, "EncodeFloatRegExp", /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/);
  12434. }
  12435. encodeFloat(num) {
  12436. let value = num.toString();
  12437. const m = CFFCompiler.EncodeFloatRegExp.exec(value);
  12438. if (m) {
  12439. const epsilon = parseFloat("1e" + ((m[2] ? +m[2] : 0) + m[1].length));
  12440. value = (Math.round(num * epsilon) / epsilon).toString();
  12441. }
  12442. let nibbles = "";
  12443. let i, ii;
  12444. for (i = 0, ii = value.length; i < ii; ++i) {
  12445. const a = value[i];
  12446. if (a === "e") {
  12447. nibbles += value[++i] === "-" ? "c" : "b";
  12448. } else if (a === ".") {
  12449. nibbles += "a";
  12450. } else if (a === "-") {
  12451. nibbles += "e";
  12452. } else {
  12453. nibbles += a;
  12454. }
  12455. }
  12456. nibbles += nibbles.length & 1 ? "f" : "ff";
  12457. const out = [30];
  12458. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  12459. out.push(parseInt(nibbles.substring(i, i + 2), 16));
  12460. }
  12461. return out;
  12462. }
  12463. encodeInteger(value) {
  12464. let code;
  12465. if (value >= -107 && value <= 107) {
  12466. code = [value + 139];
  12467. } else if (value >= 108 && value <= 1131) {
  12468. value -= 108;
  12469. code = [(value >> 8) + 247, value & 0xff];
  12470. } else if (value >= -1131 && value <= -108) {
  12471. value = -value - 108;
  12472. code = [(value >> 8) + 251, value & 0xff];
  12473. } else if (value >= -32768 && value <= 32767) {
  12474. code = [0x1c, value >> 8 & 0xff, value & 0xff];
  12475. } else {
  12476. code = [0x1d, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff];
  12477. }
  12478. return code;
  12479. }
  12480. compileHeader(header) {
  12481. return [header.major, header.minor, 4, header.offSize];
  12482. }
  12483. compileNameIndex(names) {
  12484. const nameIndex = new CFFIndex();
  12485. for (const name of names) {
  12486. const length = Math.min(name.length, 127);
  12487. let sanitizedName = new Array(length);
  12488. for (let j = 0; j < length; j++) {
  12489. let char = name[j];
  12490. if (char < "!" || char > "~" || char === "[" || char === "]" || char === "(" || char === ")" || char === "{" || char === "}" || char === "<" || char === ">" || char === "/" || char === "%") {
  12491. char = "_";
  12492. }
  12493. sanitizedName[j] = char;
  12494. }
  12495. sanitizedName = sanitizedName.join("");
  12496. if (sanitizedName === "") {
  12497. sanitizedName = "Bad_Font_Name";
  12498. }
  12499. nameIndex.add(stringToBytes(sanitizedName));
  12500. }
  12501. return this.compileIndex(nameIndex);
  12502. }
  12503. compileTopDicts(dicts, length, removeCidKeys) {
  12504. const fontDictTrackers = [];
  12505. let fdArrayIndex = new CFFIndex();
  12506. for (const fontDict of dicts) {
  12507. if (removeCidKeys) {
  12508. fontDict.removeByName("CIDFontVersion");
  12509. fontDict.removeByName("CIDFontRevision");
  12510. fontDict.removeByName("CIDFontType");
  12511. fontDict.removeByName("CIDCount");
  12512. fontDict.removeByName("UIDBase");
  12513. }
  12514. const fontDictTracker = new CFFOffsetTracker();
  12515. const fontDictData = this.compileDict(fontDict, fontDictTracker);
  12516. fontDictTrackers.push(fontDictTracker);
  12517. fdArrayIndex.add(fontDictData);
  12518. fontDictTracker.offset(length);
  12519. }
  12520. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  12521. return {
  12522. trackers: fontDictTrackers,
  12523. output: fdArrayIndex
  12524. };
  12525. }
  12526. compilePrivateDicts(dicts, trackers, output) {
  12527. for (let i = 0, ii = dicts.length; i < ii; ++i) {
  12528. const fontDict = dicts[i];
  12529. const privateDict = fontDict.privateDict;
  12530. if (!privateDict || !fontDict.hasName("Private")) {
  12531. throw new FormatError("There must be a private dictionary.");
  12532. }
  12533. const privateDictTracker = new CFFOffsetTracker();
  12534. const privateDictData = this.compileDict(privateDict, privateDictTracker);
  12535. let outputLength = output.length;
  12536. privateDictTracker.offset(outputLength);
  12537. if (!privateDictData.length) {
  12538. outputLength = 0;
  12539. }
  12540. trackers[i].setEntryLocation("Private", [privateDictData.length, outputLength], output);
  12541. output.add(privateDictData);
  12542. if (privateDict.subrsIndex && privateDict.hasName("Subrs")) {
  12543. const subrs = this.compileIndex(privateDict.subrsIndex);
  12544. privateDictTracker.setEntryLocation("Subrs", [privateDictData.length], output);
  12545. output.add(subrs);
  12546. }
  12547. }
  12548. }
  12549. compileDict(dict, offsetTracker) {
  12550. const out = [];
  12551. for (const key of dict.order) {
  12552. if (!(key in dict.values)) {
  12553. continue;
  12554. }
  12555. let values = dict.values[key];
  12556. let types = dict.types[key];
  12557. if (!Array.isArray(types)) {
  12558. types = [types];
  12559. }
  12560. if (!Array.isArray(values)) {
  12561. values = [values];
  12562. }
  12563. if (values.length === 0) {
  12564. continue;
  12565. }
  12566. for (let j = 0, jj = types.length; j < jj; ++j) {
  12567. const type = types[j];
  12568. const value = values[j];
  12569. switch (type) {
  12570. case "num":
  12571. case "sid":
  12572. out.push(...this.encodeNumber(value));
  12573. break;
  12574. case "offset":
  12575. const name = dict.keyToNameMap[key];
  12576. if (!offsetTracker.isTracking(name)) {
  12577. offsetTracker.track(name, out.length);
  12578. }
  12579. out.push(0x1d, 0, 0, 0, 0);
  12580. break;
  12581. case "array":
  12582. case "delta":
  12583. out.push(...this.encodeNumber(value));
  12584. for (let k = 1, kk = values.length; k < kk; ++k) {
  12585. out.push(...this.encodeNumber(values[k]));
  12586. }
  12587. break;
  12588. default:
  12589. throw new FormatError(`Unknown data type of ${type}`);
  12590. }
  12591. }
  12592. out.push(...dict.opcodes[key]);
  12593. }
  12594. return out;
  12595. }
  12596. compileStringIndex(strings) {
  12597. const stringIndex = new CFFIndex();
  12598. for (const string of strings) {
  12599. stringIndex.add(stringToBytes(string));
  12600. }
  12601. return this.compileIndex(stringIndex);
  12602. }
  12603. compileCharStrings(charStrings) {
  12604. const charStringsIndex = new CFFIndex();
  12605. for (let i = 0; i < charStrings.count; i++) {
  12606. const glyph = charStrings.get(i);
  12607. if (glyph.length === 0) {
  12608. charStringsIndex.add(new Uint8Array([0x8b, 0x0e]));
  12609. continue;
  12610. }
  12611. charStringsIndex.add(glyph);
  12612. }
  12613. return this.compileIndex(charStringsIndex);
  12614. }
  12615. compileCharset(charset, numGlyphs, strings, isCIDFont) {
  12616. let out;
  12617. const numGlyphsLessNotDef = numGlyphs - 1;
  12618. if (isCIDFont) {
  12619. out = new Uint8Array([2, 0, 0, numGlyphsLessNotDef >> 8 & 0xff, numGlyphsLessNotDef & 0xff]);
  12620. } else {
  12621. const length = 1 + numGlyphsLessNotDef * 2;
  12622. out = new Uint8Array(length);
  12623. out[0] = 0;
  12624. let charsetIndex = 0;
  12625. const numCharsets = charset.charset.length;
  12626. let warned = false;
  12627. for (let i = 1; i < out.length; i += 2) {
  12628. let sid = 0;
  12629. if (charsetIndex < numCharsets) {
  12630. const name = charset.charset[charsetIndex++];
  12631. sid = strings.getSID(name);
  12632. if (sid === -1) {
  12633. sid = 0;
  12634. if (!warned) {
  12635. warned = true;
  12636. warn(`Couldn't find ${name} in CFF strings`);
  12637. }
  12638. }
  12639. }
  12640. out[i] = sid >> 8 & 0xff;
  12641. out[i + 1] = sid & 0xff;
  12642. }
  12643. }
  12644. return this.compileTypedArray(out);
  12645. }
  12646. compileEncoding(encoding) {
  12647. return this.compileTypedArray(encoding.raw);
  12648. }
  12649. compileFDSelect(fdSelect) {
  12650. const format = fdSelect.format;
  12651. let out, i;
  12652. switch (format) {
  12653. case 0:
  12654. out = new Uint8Array(1 + fdSelect.fdSelect.length);
  12655. out[0] = format;
  12656. for (i = 0; i < fdSelect.fdSelect.length; i++) {
  12657. out[i + 1] = fdSelect.fdSelect[i];
  12658. }
  12659. break;
  12660. case 3:
  12661. const start = 0;
  12662. let lastFD = fdSelect.fdSelect[0];
  12663. const ranges = [format, 0, 0, start >> 8 & 0xff, start & 0xff, lastFD];
  12664. for (i = 1; i < fdSelect.fdSelect.length; i++) {
  12665. const currentFD = fdSelect.fdSelect[i];
  12666. if (currentFD !== lastFD) {
  12667. ranges.push(i >> 8 & 0xff, i & 0xff, currentFD);
  12668. lastFD = currentFD;
  12669. }
  12670. }
  12671. const numRanges = (ranges.length - 3) / 3;
  12672. ranges[1] = numRanges >> 8 & 0xff;
  12673. ranges[2] = numRanges & 0xff;
  12674. ranges.push(i >> 8 & 0xff, i & 0xff);
  12675. out = new Uint8Array(ranges);
  12676. break;
  12677. }
  12678. return this.compileTypedArray(out);
  12679. }
  12680. compileTypedArray(data) {
  12681. return Array.from(data);
  12682. }
  12683. compileIndex(index, trackers = []) {
  12684. const objects = index.objects;
  12685. const count = objects.length;
  12686. if (count === 0) {
  12687. return [0, 0];
  12688. }
  12689. const data = [count >> 8 & 0xff, count & 0xff];
  12690. let lastOffset = 1,
  12691. i;
  12692. for (i = 0; i < count; ++i) {
  12693. lastOffset += objects[i].length;
  12694. }
  12695. let offsetSize;
  12696. if (lastOffset < 0x100) {
  12697. offsetSize = 1;
  12698. } else if (lastOffset < 0x10000) {
  12699. offsetSize = 2;
  12700. } else if (lastOffset < 0x1000000) {
  12701. offsetSize = 3;
  12702. } else {
  12703. offsetSize = 4;
  12704. }
  12705. data.push(offsetSize);
  12706. let relativeOffset = 1;
  12707. for (i = 0; i < count + 1; i++) {
  12708. if (offsetSize === 1) {
  12709. data.push(relativeOffset & 0xff);
  12710. } else if (offsetSize === 2) {
  12711. data.push(relativeOffset >> 8 & 0xff, relativeOffset & 0xff);
  12712. } else if (offsetSize === 3) {
  12713. data.push(relativeOffset >> 16 & 0xff, relativeOffset >> 8 & 0xff, relativeOffset & 0xff);
  12714. } else {
  12715. data.push(relativeOffset >>> 24 & 0xff, relativeOffset >> 16 & 0xff, relativeOffset >> 8 & 0xff, relativeOffset & 0xff);
  12716. }
  12717. if (objects[i]) {
  12718. relativeOffset += objects[i].length;
  12719. }
  12720. }
  12721. for (i = 0; i < count; i++) {
  12722. if (trackers[i]) {
  12723. trackers[i].offset(data.length);
  12724. }
  12725. data.push(...objects[i]);
  12726. }
  12727. return data;
  12728. }
  12729. }
  12730. ;// CONCATENATED MODULE: ./src/core/glyphlist.js
  12731. const getGlyphsUnicode = getLookupTableFactory(function (t) {
  12732. t.A = 0x0041;
  12733. t.AE = 0x00c6;
  12734. t.AEacute = 0x01fc;
  12735. t.AEmacron = 0x01e2;
  12736. t.AEsmall = 0xf7e6;
  12737. t.Aacute = 0x00c1;
  12738. t.Aacutesmall = 0xf7e1;
  12739. t.Abreve = 0x0102;
  12740. t.Abreveacute = 0x1eae;
  12741. t.Abrevecyrillic = 0x04d0;
  12742. t.Abrevedotbelow = 0x1eb6;
  12743. t.Abrevegrave = 0x1eb0;
  12744. t.Abrevehookabove = 0x1eb2;
  12745. t.Abrevetilde = 0x1eb4;
  12746. t.Acaron = 0x01cd;
  12747. t.Acircle = 0x24b6;
  12748. t.Acircumflex = 0x00c2;
  12749. t.Acircumflexacute = 0x1ea4;
  12750. t.Acircumflexdotbelow = 0x1eac;
  12751. t.Acircumflexgrave = 0x1ea6;
  12752. t.Acircumflexhookabove = 0x1ea8;
  12753. t.Acircumflexsmall = 0xf7e2;
  12754. t.Acircumflextilde = 0x1eaa;
  12755. t.Acute = 0xf6c9;
  12756. t.Acutesmall = 0xf7b4;
  12757. t.Acyrillic = 0x0410;
  12758. t.Adblgrave = 0x0200;
  12759. t.Adieresis = 0x00c4;
  12760. t.Adieresiscyrillic = 0x04d2;
  12761. t.Adieresismacron = 0x01de;
  12762. t.Adieresissmall = 0xf7e4;
  12763. t.Adotbelow = 0x1ea0;
  12764. t.Adotmacron = 0x01e0;
  12765. t.Agrave = 0x00c0;
  12766. t.Agravesmall = 0xf7e0;
  12767. t.Ahookabove = 0x1ea2;
  12768. t.Aiecyrillic = 0x04d4;
  12769. t.Ainvertedbreve = 0x0202;
  12770. t.Alpha = 0x0391;
  12771. t.Alphatonos = 0x0386;
  12772. t.Amacron = 0x0100;
  12773. t.Amonospace = 0xff21;
  12774. t.Aogonek = 0x0104;
  12775. t.Aring = 0x00c5;
  12776. t.Aringacute = 0x01fa;
  12777. t.Aringbelow = 0x1e00;
  12778. t.Aringsmall = 0xf7e5;
  12779. t.Asmall = 0xf761;
  12780. t.Atilde = 0x00c3;
  12781. t.Atildesmall = 0xf7e3;
  12782. t.Aybarmenian = 0x0531;
  12783. t.B = 0x0042;
  12784. t.Bcircle = 0x24b7;
  12785. t.Bdotaccent = 0x1e02;
  12786. t.Bdotbelow = 0x1e04;
  12787. t.Becyrillic = 0x0411;
  12788. t.Benarmenian = 0x0532;
  12789. t.Beta = 0x0392;
  12790. t.Bhook = 0x0181;
  12791. t.Blinebelow = 0x1e06;
  12792. t.Bmonospace = 0xff22;
  12793. t.Brevesmall = 0xf6f4;
  12794. t.Bsmall = 0xf762;
  12795. t.Btopbar = 0x0182;
  12796. t.C = 0x0043;
  12797. t.Caarmenian = 0x053e;
  12798. t.Cacute = 0x0106;
  12799. t.Caron = 0xf6ca;
  12800. t.Caronsmall = 0xf6f5;
  12801. t.Ccaron = 0x010c;
  12802. t.Ccedilla = 0x00c7;
  12803. t.Ccedillaacute = 0x1e08;
  12804. t.Ccedillasmall = 0xf7e7;
  12805. t.Ccircle = 0x24b8;
  12806. t.Ccircumflex = 0x0108;
  12807. t.Cdot = 0x010a;
  12808. t.Cdotaccent = 0x010a;
  12809. t.Cedillasmall = 0xf7b8;
  12810. t.Chaarmenian = 0x0549;
  12811. t.Cheabkhasiancyrillic = 0x04bc;
  12812. t.Checyrillic = 0x0427;
  12813. t.Chedescenderabkhasiancyrillic = 0x04be;
  12814. t.Chedescendercyrillic = 0x04b6;
  12815. t.Chedieresiscyrillic = 0x04f4;
  12816. t.Cheharmenian = 0x0543;
  12817. t.Chekhakassiancyrillic = 0x04cb;
  12818. t.Cheverticalstrokecyrillic = 0x04b8;
  12819. t.Chi = 0x03a7;
  12820. t.Chook = 0x0187;
  12821. t.Circumflexsmall = 0xf6f6;
  12822. t.Cmonospace = 0xff23;
  12823. t.Coarmenian = 0x0551;
  12824. t.Csmall = 0xf763;
  12825. t.D = 0x0044;
  12826. t.DZ = 0x01f1;
  12827. t.DZcaron = 0x01c4;
  12828. t.Daarmenian = 0x0534;
  12829. t.Dafrican = 0x0189;
  12830. t.Dcaron = 0x010e;
  12831. t.Dcedilla = 0x1e10;
  12832. t.Dcircle = 0x24b9;
  12833. t.Dcircumflexbelow = 0x1e12;
  12834. t.Dcroat = 0x0110;
  12835. t.Ddotaccent = 0x1e0a;
  12836. t.Ddotbelow = 0x1e0c;
  12837. t.Decyrillic = 0x0414;
  12838. t.Deicoptic = 0x03ee;
  12839. t.Delta = 0x2206;
  12840. t.Deltagreek = 0x0394;
  12841. t.Dhook = 0x018a;
  12842. t.Dieresis = 0xf6cb;
  12843. t.DieresisAcute = 0xf6cc;
  12844. t.DieresisGrave = 0xf6cd;
  12845. t.Dieresissmall = 0xf7a8;
  12846. t.Digammagreek = 0x03dc;
  12847. t.Djecyrillic = 0x0402;
  12848. t.Dlinebelow = 0x1e0e;
  12849. t.Dmonospace = 0xff24;
  12850. t.Dotaccentsmall = 0xf6f7;
  12851. t.Dslash = 0x0110;
  12852. t.Dsmall = 0xf764;
  12853. t.Dtopbar = 0x018b;
  12854. t.Dz = 0x01f2;
  12855. t.Dzcaron = 0x01c5;
  12856. t.Dzeabkhasiancyrillic = 0x04e0;
  12857. t.Dzecyrillic = 0x0405;
  12858. t.Dzhecyrillic = 0x040f;
  12859. t.E = 0x0045;
  12860. t.Eacute = 0x00c9;
  12861. t.Eacutesmall = 0xf7e9;
  12862. t.Ebreve = 0x0114;
  12863. t.Ecaron = 0x011a;
  12864. t.Ecedillabreve = 0x1e1c;
  12865. t.Echarmenian = 0x0535;
  12866. t.Ecircle = 0x24ba;
  12867. t.Ecircumflex = 0x00ca;
  12868. t.Ecircumflexacute = 0x1ebe;
  12869. t.Ecircumflexbelow = 0x1e18;
  12870. t.Ecircumflexdotbelow = 0x1ec6;
  12871. t.Ecircumflexgrave = 0x1ec0;
  12872. t.Ecircumflexhookabove = 0x1ec2;
  12873. t.Ecircumflexsmall = 0xf7ea;
  12874. t.Ecircumflextilde = 0x1ec4;
  12875. t.Ecyrillic = 0x0404;
  12876. t.Edblgrave = 0x0204;
  12877. t.Edieresis = 0x00cb;
  12878. t.Edieresissmall = 0xf7eb;
  12879. t.Edot = 0x0116;
  12880. t.Edotaccent = 0x0116;
  12881. t.Edotbelow = 0x1eb8;
  12882. t.Efcyrillic = 0x0424;
  12883. t.Egrave = 0x00c8;
  12884. t.Egravesmall = 0xf7e8;
  12885. t.Eharmenian = 0x0537;
  12886. t.Ehookabove = 0x1eba;
  12887. t.Eightroman = 0x2167;
  12888. t.Einvertedbreve = 0x0206;
  12889. t.Eiotifiedcyrillic = 0x0464;
  12890. t.Elcyrillic = 0x041b;
  12891. t.Elevenroman = 0x216a;
  12892. t.Emacron = 0x0112;
  12893. t.Emacronacute = 0x1e16;
  12894. t.Emacrongrave = 0x1e14;
  12895. t.Emcyrillic = 0x041c;
  12896. t.Emonospace = 0xff25;
  12897. t.Encyrillic = 0x041d;
  12898. t.Endescendercyrillic = 0x04a2;
  12899. t.Eng = 0x014a;
  12900. t.Enghecyrillic = 0x04a4;
  12901. t.Enhookcyrillic = 0x04c7;
  12902. t.Eogonek = 0x0118;
  12903. t.Eopen = 0x0190;
  12904. t.Epsilon = 0x0395;
  12905. t.Epsilontonos = 0x0388;
  12906. t.Ercyrillic = 0x0420;
  12907. t.Ereversed = 0x018e;
  12908. t.Ereversedcyrillic = 0x042d;
  12909. t.Escyrillic = 0x0421;
  12910. t.Esdescendercyrillic = 0x04aa;
  12911. t.Esh = 0x01a9;
  12912. t.Esmall = 0xf765;
  12913. t.Eta = 0x0397;
  12914. t.Etarmenian = 0x0538;
  12915. t.Etatonos = 0x0389;
  12916. t.Eth = 0x00d0;
  12917. t.Ethsmall = 0xf7f0;
  12918. t.Etilde = 0x1ebc;
  12919. t.Etildebelow = 0x1e1a;
  12920. t.Euro = 0x20ac;
  12921. t.Ezh = 0x01b7;
  12922. t.Ezhcaron = 0x01ee;
  12923. t.Ezhreversed = 0x01b8;
  12924. t.F = 0x0046;
  12925. t.Fcircle = 0x24bb;
  12926. t.Fdotaccent = 0x1e1e;
  12927. t.Feharmenian = 0x0556;
  12928. t.Feicoptic = 0x03e4;
  12929. t.Fhook = 0x0191;
  12930. t.Fitacyrillic = 0x0472;
  12931. t.Fiveroman = 0x2164;
  12932. t.Fmonospace = 0xff26;
  12933. t.Fourroman = 0x2163;
  12934. t.Fsmall = 0xf766;
  12935. t.G = 0x0047;
  12936. t.GBsquare = 0x3387;
  12937. t.Gacute = 0x01f4;
  12938. t.Gamma = 0x0393;
  12939. t.Gammaafrican = 0x0194;
  12940. t.Gangiacoptic = 0x03ea;
  12941. t.Gbreve = 0x011e;
  12942. t.Gcaron = 0x01e6;
  12943. t.Gcedilla = 0x0122;
  12944. t.Gcircle = 0x24bc;
  12945. t.Gcircumflex = 0x011c;
  12946. t.Gcommaaccent = 0x0122;
  12947. t.Gdot = 0x0120;
  12948. t.Gdotaccent = 0x0120;
  12949. t.Gecyrillic = 0x0413;
  12950. t.Ghadarmenian = 0x0542;
  12951. t.Ghemiddlehookcyrillic = 0x0494;
  12952. t.Ghestrokecyrillic = 0x0492;
  12953. t.Gheupturncyrillic = 0x0490;
  12954. t.Ghook = 0x0193;
  12955. t.Gimarmenian = 0x0533;
  12956. t.Gjecyrillic = 0x0403;
  12957. t.Gmacron = 0x1e20;
  12958. t.Gmonospace = 0xff27;
  12959. t.Grave = 0xf6ce;
  12960. t.Gravesmall = 0xf760;
  12961. t.Gsmall = 0xf767;
  12962. t.Gsmallhook = 0x029b;
  12963. t.Gstroke = 0x01e4;
  12964. t.H = 0x0048;
  12965. t.H18533 = 0x25cf;
  12966. t.H18543 = 0x25aa;
  12967. t.H18551 = 0x25ab;
  12968. t.H22073 = 0x25a1;
  12969. t.HPsquare = 0x33cb;
  12970. t.Haabkhasiancyrillic = 0x04a8;
  12971. t.Hadescendercyrillic = 0x04b2;
  12972. t.Hardsigncyrillic = 0x042a;
  12973. t.Hbar = 0x0126;
  12974. t.Hbrevebelow = 0x1e2a;
  12975. t.Hcedilla = 0x1e28;
  12976. t.Hcircle = 0x24bd;
  12977. t.Hcircumflex = 0x0124;
  12978. t.Hdieresis = 0x1e26;
  12979. t.Hdotaccent = 0x1e22;
  12980. t.Hdotbelow = 0x1e24;
  12981. t.Hmonospace = 0xff28;
  12982. t.Hoarmenian = 0x0540;
  12983. t.Horicoptic = 0x03e8;
  12984. t.Hsmall = 0xf768;
  12985. t.Hungarumlaut = 0xf6cf;
  12986. t.Hungarumlautsmall = 0xf6f8;
  12987. t.Hzsquare = 0x3390;
  12988. t.I = 0x0049;
  12989. t.IAcyrillic = 0x042f;
  12990. t.IJ = 0x0132;
  12991. t.IUcyrillic = 0x042e;
  12992. t.Iacute = 0x00cd;
  12993. t.Iacutesmall = 0xf7ed;
  12994. t.Ibreve = 0x012c;
  12995. t.Icaron = 0x01cf;
  12996. t.Icircle = 0x24be;
  12997. t.Icircumflex = 0x00ce;
  12998. t.Icircumflexsmall = 0xf7ee;
  12999. t.Icyrillic = 0x0406;
  13000. t.Idblgrave = 0x0208;
  13001. t.Idieresis = 0x00cf;
  13002. t.Idieresisacute = 0x1e2e;
  13003. t.Idieresiscyrillic = 0x04e4;
  13004. t.Idieresissmall = 0xf7ef;
  13005. t.Idot = 0x0130;
  13006. t.Idotaccent = 0x0130;
  13007. t.Idotbelow = 0x1eca;
  13008. t.Iebrevecyrillic = 0x04d6;
  13009. t.Iecyrillic = 0x0415;
  13010. t.Ifraktur = 0x2111;
  13011. t.Igrave = 0x00cc;
  13012. t.Igravesmall = 0xf7ec;
  13013. t.Ihookabove = 0x1ec8;
  13014. t.Iicyrillic = 0x0418;
  13015. t.Iinvertedbreve = 0x020a;
  13016. t.Iishortcyrillic = 0x0419;
  13017. t.Imacron = 0x012a;
  13018. t.Imacroncyrillic = 0x04e2;
  13019. t.Imonospace = 0xff29;
  13020. t.Iniarmenian = 0x053b;
  13021. t.Iocyrillic = 0x0401;
  13022. t.Iogonek = 0x012e;
  13023. t.Iota = 0x0399;
  13024. t.Iotaafrican = 0x0196;
  13025. t.Iotadieresis = 0x03aa;
  13026. t.Iotatonos = 0x038a;
  13027. t.Ismall = 0xf769;
  13028. t.Istroke = 0x0197;
  13029. t.Itilde = 0x0128;
  13030. t.Itildebelow = 0x1e2c;
  13031. t.Izhitsacyrillic = 0x0474;
  13032. t.Izhitsadblgravecyrillic = 0x0476;
  13033. t.J = 0x004a;
  13034. t.Jaarmenian = 0x0541;
  13035. t.Jcircle = 0x24bf;
  13036. t.Jcircumflex = 0x0134;
  13037. t.Jecyrillic = 0x0408;
  13038. t.Jheharmenian = 0x054b;
  13039. t.Jmonospace = 0xff2a;
  13040. t.Jsmall = 0xf76a;
  13041. t.K = 0x004b;
  13042. t.KBsquare = 0x3385;
  13043. t.KKsquare = 0x33cd;
  13044. t.Kabashkircyrillic = 0x04a0;
  13045. t.Kacute = 0x1e30;
  13046. t.Kacyrillic = 0x041a;
  13047. t.Kadescendercyrillic = 0x049a;
  13048. t.Kahookcyrillic = 0x04c3;
  13049. t.Kappa = 0x039a;
  13050. t.Kastrokecyrillic = 0x049e;
  13051. t.Kaverticalstrokecyrillic = 0x049c;
  13052. t.Kcaron = 0x01e8;
  13053. t.Kcedilla = 0x0136;
  13054. t.Kcircle = 0x24c0;
  13055. t.Kcommaaccent = 0x0136;
  13056. t.Kdotbelow = 0x1e32;
  13057. t.Keharmenian = 0x0554;
  13058. t.Kenarmenian = 0x053f;
  13059. t.Khacyrillic = 0x0425;
  13060. t.Kheicoptic = 0x03e6;
  13061. t.Khook = 0x0198;
  13062. t.Kjecyrillic = 0x040c;
  13063. t.Klinebelow = 0x1e34;
  13064. t.Kmonospace = 0xff2b;
  13065. t.Koppacyrillic = 0x0480;
  13066. t.Koppagreek = 0x03de;
  13067. t.Ksicyrillic = 0x046e;
  13068. t.Ksmall = 0xf76b;
  13069. t.L = 0x004c;
  13070. t.LJ = 0x01c7;
  13071. t.LL = 0xf6bf;
  13072. t.Lacute = 0x0139;
  13073. t.Lambda = 0x039b;
  13074. t.Lcaron = 0x013d;
  13075. t.Lcedilla = 0x013b;
  13076. t.Lcircle = 0x24c1;
  13077. t.Lcircumflexbelow = 0x1e3c;
  13078. t.Lcommaaccent = 0x013b;
  13079. t.Ldot = 0x013f;
  13080. t.Ldotaccent = 0x013f;
  13081. t.Ldotbelow = 0x1e36;
  13082. t.Ldotbelowmacron = 0x1e38;
  13083. t.Liwnarmenian = 0x053c;
  13084. t.Lj = 0x01c8;
  13085. t.Ljecyrillic = 0x0409;
  13086. t.Llinebelow = 0x1e3a;
  13087. t.Lmonospace = 0xff2c;
  13088. t.Lslash = 0x0141;
  13089. t.Lslashsmall = 0xf6f9;
  13090. t.Lsmall = 0xf76c;
  13091. t.M = 0x004d;
  13092. t.MBsquare = 0x3386;
  13093. t.Macron = 0xf6d0;
  13094. t.Macronsmall = 0xf7af;
  13095. t.Macute = 0x1e3e;
  13096. t.Mcircle = 0x24c2;
  13097. t.Mdotaccent = 0x1e40;
  13098. t.Mdotbelow = 0x1e42;
  13099. t.Menarmenian = 0x0544;
  13100. t.Mmonospace = 0xff2d;
  13101. t.Msmall = 0xf76d;
  13102. t.Mturned = 0x019c;
  13103. t.Mu = 0x039c;
  13104. t.N = 0x004e;
  13105. t.NJ = 0x01ca;
  13106. t.Nacute = 0x0143;
  13107. t.Ncaron = 0x0147;
  13108. t.Ncedilla = 0x0145;
  13109. t.Ncircle = 0x24c3;
  13110. t.Ncircumflexbelow = 0x1e4a;
  13111. t.Ncommaaccent = 0x0145;
  13112. t.Ndotaccent = 0x1e44;
  13113. t.Ndotbelow = 0x1e46;
  13114. t.Nhookleft = 0x019d;
  13115. t.Nineroman = 0x2168;
  13116. t.Nj = 0x01cb;
  13117. t.Njecyrillic = 0x040a;
  13118. t.Nlinebelow = 0x1e48;
  13119. t.Nmonospace = 0xff2e;
  13120. t.Nowarmenian = 0x0546;
  13121. t.Nsmall = 0xf76e;
  13122. t.Ntilde = 0x00d1;
  13123. t.Ntildesmall = 0xf7f1;
  13124. t.Nu = 0x039d;
  13125. t.O = 0x004f;
  13126. t.OE = 0x0152;
  13127. t.OEsmall = 0xf6fa;
  13128. t.Oacute = 0x00d3;
  13129. t.Oacutesmall = 0xf7f3;
  13130. t.Obarredcyrillic = 0x04e8;
  13131. t.Obarreddieresiscyrillic = 0x04ea;
  13132. t.Obreve = 0x014e;
  13133. t.Ocaron = 0x01d1;
  13134. t.Ocenteredtilde = 0x019f;
  13135. t.Ocircle = 0x24c4;
  13136. t.Ocircumflex = 0x00d4;
  13137. t.Ocircumflexacute = 0x1ed0;
  13138. t.Ocircumflexdotbelow = 0x1ed8;
  13139. t.Ocircumflexgrave = 0x1ed2;
  13140. t.Ocircumflexhookabove = 0x1ed4;
  13141. t.Ocircumflexsmall = 0xf7f4;
  13142. t.Ocircumflextilde = 0x1ed6;
  13143. t.Ocyrillic = 0x041e;
  13144. t.Odblacute = 0x0150;
  13145. t.Odblgrave = 0x020c;
  13146. t.Odieresis = 0x00d6;
  13147. t.Odieresiscyrillic = 0x04e6;
  13148. t.Odieresissmall = 0xf7f6;
  13149. t.Odotbelow = 0x1ecc;
  13150. t.Ogoneksmall = 0xf6fb;
  13151. t.Ograve = 0x00d2;
  13152. t.Ogravesmall = 0xf7f2;
  13153. t.Oharmenian = 0x0555;
  13154. t.Ohm = 0x2126;
  13155. t.Ohookabove = 0x1ece;
  13156. t.Ohorn = 0x01a0;
  13157. t.Ohornacute = 0x1eda;
  13158. t.Ohorndotbelow = 0x1ee2;
  13159. t.Ohorngrave = 0x1edc;
  13160. t.Ohornhookabove = 0x1ede;
  13161. t.Ohorntilde = 0x1ee0;
  13162. t.Ohungarumlaut = 0x0150;
  13163. t.Oi = 0x01a2;
  13164. t.Oinvertedbreve = 0x020e;
  13165. t.Omacron = 0x014c;
  13166. t.Omacronacute = 0x1e52;
  13167. t.Omacrongrave = 0x1e50;
  13168. t.Omega = 0x2126;
  13169. t.Omegacyrillic = 0x0460;
  13170. t.Omegagreek = 0x03a9;
  13171. t.Omegaroundcyrillic = 0x047a;
  13172. t.Omegatitlocyrillic = 0x047c;
  13173. t.Omegatonos = 0x038f;
  13174. t.Omicron = 0x039f;
  13175. t.Omicrontonos = 0x038c;
  13176. t.Omonospace = 0xff2f;
  13177. t.Oneroman = 0x2160;
  13178. t.Oogonek = 0x01ea;
  13179. t.Oogonekmacron = 0x01ec;
  13180. t.Oopen = 0x0186;
  13181. t.Oslash = 0x00d8;
  13182. t.Oslashacute = 0x01fe;
  13183. t.Oslashsmall = 0xf7f8;
  13184. t.Osmall = 0xf76f;
  13185. t.Ostrokeacute = 0x01fe;
  13186. t.Otcyrillic = 0x047e;
  13187. t.Otilde = 0x00d5;
  13188. t.Otildeacute = 0x1e4c;
  13189. t.Otildedieresis = 0x1e4e;
  13190. t.Otildesmall = 0xf7f5;
  13191. t.P = 0x0050;
  13192. t.Pacute = 0x1e54;
  13193. t.Pcircle = 0x24c5;
  13194. t.Pdotaccent = 0x1e56;
  13195. t.Pecyrillic = 0x041f;
  13196. t.Peharmenian = 0x054a;
  13197. t.Pemiddlehookcyrillic = 0x04a6;
  13198. t.Phi = 0x03a6;
  13199. t.Phook = 0x01a4;
  13200. t.Pi = 0x03a0;
  13201. t.Piwrarmenian = 0x0553;
  13202. t.Pmonospace = 0xff30;
  13203. t.Psi = 0x03a8;
  13204. t.Psicyrillic = 0x0470;
  13205. t.Psmall = 0xf770;
  13206. t.Q = 0x0051;
  13207. t.Qcircle = 0x24c6;
  13208. t.Qmonospace = 0xff31;
  13209. t.Qsmall = 0xf771;
  13210. t.R = 0x0052;
  13211. t.Raarmenian = 0x054c;
  13212. t.Racute = 0x0154;
  13213. t.Rcaron = 0x0158;
  13214. t.Rcedilla = 0x0156;
  13215. t.Rcircle = 0x24c7;
  13216. t.Rcommaaccent = 0x0156;
  13217. t.Rdblgrave = 0x0210;
  13218. t.Rdotaccent = 0x1e58;
  13219. t.Rdotbelow = 0x1e5a;
  13220. t.Rdotbelowmacron = 0x1e5c;
  13221. t.Reharmenian = 0x0550;
  13222. t.Rfraktur = 0x211c;
  13223. t.Rho = 0x03a1;
  13224. t.Ringsmall = 0xf6fc;
  13225. t.Rinvertedbreve = 0x0212;
  13226. t.Rlinebelow = 0x1e5e;
  13227. t.Rmonospace = 0xff32;
  13228. t.Rsmall = 0xf772;
  13229. t.Rsmallinverted = 0x0281;
  13230. t.Rsmallinvertedsuperior = 0x02b6;
  13231. t.S = 0x0053;
  13232. t.SF010000 = 0x250c;
  13233. t.SF020000 = 0x2514;
  13234. t.SF030000 = 0x2510;
  13235. t.SF040000 = 0x2518;
  13236. t.SF050000 = 0x253c;
  13237. t.SF060000 = 0x252c;
  13238. t.SF070000 = 0x2534;
  13239. t.SF080000 = 0x251c;
  13240. t.SF090000 = 0x2524;
  13241. t.SF100000 = 0x2500;
  13242. t.SF110000 = 0x2502;
  13243. t.SF190000 = 0x2561;
  13244. t.SF200000 = 0x2562;
  13245. t.SF210000 = 0x2556;
  13246. t.SF220000 = 0x2555;
  13247. t.SF230000 = 0x2563;
  13248. t.SF240000 = 0x2551;
  13249. t.SF250000 = 0x2557;
  13250. t.SF260000 = 0x255d;
  13251. t.SF270000 = 0x255c;
  13252. t.SF280000 = 0x255b;
  13253. t.SF360000 = 0x255e;
  13254. t.SF370000 = 0x255f;
  13255. t.SF380000 = 0x255a;
  13256. t.SF390000 = 0x2554;
  13257. t.SF400000 = 0x2569;
  13258. t.SF410000 = 0x2566;
  13259. t.SF420000 = 0x2560;
  13260. t.SF430000 = 0x2550;
  13261. t.SF440000 = 0x256c;
  13262. t.SF450000 = 0x2567;
  13263. t.SF460000 = 0x2568;
  13264. t.SF470000 = 0x2564;
  13265. t.SF480000 = 0x2565;
  13266. t.SF490000 = 0x2559;
  13267. t.SF500000 = 0x2558;
  13268. t.SF510000 = 0x2552;
  13269. t.SF520000 = 0x2553;
  13270. t.SF530000 = 0x256b;
  13271. t.SF540000 = 0x256a;
  13272. t.Sacute = 0x015a;
  13273. t.Sacutedotaccent = 0x1e64;
  13274. t.Sampigreek = 0x03e0;
  13275. t.Scaron = 0x0160;
  13276. t.Scarondotaccent = 0x1e66;
  13277. t.Scaronsmall = 0xf6fd;
  13278. t.Scedilla = 0x015e;
  13279. t.Schwa = 0x018f;
  13280. t.Schwacyrillic = 0x04d8;
  13281. t.Schwadieresiscyrillic = 0x04da;
  13282. t.Scircle = 0x24c8;
  13283. t.Scircumflex = 0x015c;
  13284. t.Scommaaccent = 0x0218;
  13285. t.Sdotaccent = 0x1e60;
  13286. t.Sdotbelow = 0x1e62;
  13287. t.Sdotbelowdotaccent = 0x1e68;
  13288. t.Seharmenian = 0x054d;
  13289. t.Sevenroman = 0x2166;
  13290. t.Shaarmenian = 0x0547;
  13291. t.Shacyrillic = 0x0428;
  13292. t.Shchacyrillic = 0x0429;
  13293. t.Sheicoptic = 0x03e2;
  13294. t.Shhacyrillic = 0x04ba;
  13295. t.Shimacoptic = 0x03ec;
  13296. t.Sigma = 0x03a3;
  13297. t.Sixroman = 0x2165;
  13298. t.Smonospace = 0xff33;
  13299. t.Softsigncyrillic = 0x042c;
  13300. t.Ssmall = 0xf773;
  13301. t.Stigmagreek = 0x03da;
  13302. t.T = 0x0054;
  13303. t.Tau = 0x03a4;
  13304. t.Tbar = 0x0166;
  13305. t.Tcaron = 0x0164;
  13306. t.Tcedilla = 0x0162;
  13307. t.Tcircle = 0x24c9;
  13308. t.Tcircumflexbelow = 0x1e70;
  13309. t.Tcommaaccent = 0x0162;
  13310. t.Tdotaccent = 0x1e6a;
  13311. t.Tdotbelow = 0x1e6c;
  13312. t.Tecyrillic = 0x0422;
  13313. t.Tedescendercyrillic = 0x04ac;
  13314. t.Tenroman = 0x2169;
  13315. t.Tetsecyrillic = 0x04b4;
  13316. t.Theta = 0x0398;
  13317. t.Thook = 0x01ac;
  13318. t.Thorn = 0x00de;
  13319. t.Thornsmall = 0xf7fe;
  13320. t.Threeroman = 0x2162;
  13321. t.Tildesmall = 0xf6fe;
  13322. t.Tiwnarmenian = 0x054f;
  13323. t.Tlinebelow = 0x1e6e;
  13324. t.Tmonospace = 0xff34;
  13325. t.Toarmenian = 0x0539;
  13326. t.Tonefive = 0x01bc;
  13327. t.Tonesix = 0x0184;
  13328. t.Tonetwo = 0x01a7;
  13329. t.Tretroflexhook = 0x01ae;
  13330. t.Tsecyrillic = 0x0426;
  13331. t.Tshecyrillic = 0x040b;
  13332. t.Tsmall = 0xf774;
  13333. t.Twelveroman = 0x216b;
  13334. t.Tworoman = 0x2161;
  13335. t.U = 0x0055;
  13336. t.Uacute = 0x00da;
  13337. t.Uacutesmall = 0xf7fa;
  13338. t.Ubreve = 0x016c;
  13339. t.Ucaron = 0x01d3;
  13340. t.Ucircle = 0x24ca;
  13341. t.Ucircumflex = 0x00db;
  13342. t.Ucircumflexbelow = 0x1e76;
  13343. t.Ucircumflexsmall = 0xf7fb;
  13344. t.Ucyrillic = 0x0423;
  13345. t.Udblacute = 0x0170;
  13346. t.Udblgrave = 0x0214;
  13347. t.Udieresis = 0x00dc;
  13348. t.Udieresisacute = 0x01d7;
  13349. t.Udieresisbelow = 0x1e72;
  13350. t.Udieresiscaron = 0x01d9;
  13351. t.Udieresiscyrillic = 0x04f0;
  13352. t.Udieresisgrave = 0x01db;
  13353. t.Udieresismacron = 0x01d5;
  13354. t.Udieresissmall = 0xf7fc;
  13355. t.Udotbelow = 0x1ee4;
  13356. t.Ugrave = 0x00d9;
  13357. t.Ugravesmall = 0xf7f9;
  13358. t.Uhookabove = 0x1ee6;
  13359. t.Uhorn = 0x01af;
  13360. t.Uhornacute = 0x1ee8;
  13361. t.Uhorndotbelow = 0x1ef0;
  13362. t.Uhorngrave = 0x1eea;
  13363. t.Uhornhookabove = 0x1eec;
  13364. t.Uhorntilde = 0x1eee;
  13365. t.Uhungarumlaut = 0x0170;
  13366. t.Uhungarumlautcyrillic = 0x04f2;
  13367. t.Uinvertedbreve = 0x0216;
  13368. t.Ukcyrillic = 0x0478;
  13369. t.Umacron = 0x016a;
  13370. t.Umacroncyrillic = 0x04ee;
  13371. t.Umacrondieresis = 0x1e7a;
  13372. t.Umonospace = 0xff35;
  13373. t.Uogonek = 0x0172;
  13374. t.Upsilon = 0x03a5;
  13375. t.Upsilon1 = 0x03d2;
  13376. t.Upsilonacutehooksymbolgreek = 0x03d3;
  13377. t.Upsilonafrican = 0x01b1;
  13378. t.Upsilondieresis = 0x03ab;
  13379. t.Upsilondieresishooksymbolgreek = 0x03d4;
  13380. t.Upsilonhooksymbol = 0x03d2;
  13381. t.Upsilontonos = 0x038e;
  13382. t.Uring = 0x016e;
  13383. t.Ushortcyrillic = 0x040e;
  13384. t.Usmall = 0xf775;
  13385. t.Ustraightcyrillic = 0x04ae;
  13386. t.Ustraightstrokecyrillic = 0x04b0;
  13387. t.Utilde = 0x0168;
  13388. t.Utildeacute = 0x1e78;
  13389. t.Utildebelow = 0x1e74;
  13390. t.V = 0x0056;
  13391. t.Vcircle = 0x24cb;
  13392. t.Vdotbelow = 0x1e7e;
  13393. t.Vecyrillic = 0x0412;
  13394. t.Vewarmenian = 0x054e;
  13395. t.Vhook = 0x01b2;
  13396. t.Vmonospace = 0xff36;
  13397. t.Voarmenian = 0x0548;
  13398. t.Vsmall = 0xf776;
  13399. t.Vtilde = 0x1e7c;
  13400. t.W = 0x0057;
  13401. t.Wacute = 0x1e82;
  13402. t.Wcircle = 0x24cc;
  13403. t.Wcircumflex = 0x0174;
  13404. t.Wdieresis = 0x1e84;
  13405. t.Wdotaccent = 0x1e86;
  13406. t.Wdotbelow = 0x1e88;
  13407. t.Wgrave = 0x1e80;
  13408. t.Wmonospace = 0xff37;
  13409. t.Wsmall = 0xf777;
  13410. t.X = 0x0058;
  13411. t.Xcircle = 0x24cd;
  13412. t.Xdieresis = 0x1e8c;
  13413. t.Xdotaccent = 0x1e8a;
  13414. t.Xeharmenian = 0x053d;
  13415. t.Xi = 0x039e;
  13416. t.Xmonospace = 0xff38;
  13417. t.Xsmall = 0xf778;
  13418. t.Y = 0x0059;
  13419. t.Yacute = 0x00dd;
  13420. t.Yacutesmall = 0xf7fd;
  13421. t.Yatcyrillic = 0x0462;
  13422. t.Ycircle = 0x24ce;
  13423. t.Ycircumflex = 0x0176;
  13424. t.Ydieresis = 0x0178;
  13425. t.Ydieresissmall = 0xf7ff;
  13426. t.Ydotaccent = 0x1e8e;
  13427. t.Ydotbelow = 0x1ef4;
  13428. t.Yericyrillic = 0x042b;
  13429. t.Yerudieresiscyrillic = 0x04f8;
  13430. t.Ygrave = 0x1ef2;
  13431. t.Yhook = 0x01b3;
  13432. t.Yhookabove = 0x1ef6;
  13433. t.Yiarmenian = 0x0545;
  13434. t.Yicyrillic = 0x0407;
  13435. t.Yiwnarmenian = 0x0552;
  13436. t.Ymonospace = 0xff39;
  13437. t.Ysmall = 0xf779;
  13438. t.Ytilde = 0x1ef8;
  13439. t.Yusbigcyrillic = 0x046a;
  13440. t.Yusbigiotifiedcyrillic = 0x046c;
  13441. t.Yuslittlecyrillic = 0x0466;
  13442. t.Yuslittleiotifiedcyrillic = 0x0468;
  13443. t.Z = 0x005a;
  13444. t.Zaarmenian = 0x0536;
  13445. t.Zacute = 0x0179;
  13446. t.Zcaron = 0x017d;
  13447. t.Zcaronsmall = 0xf6ff;
  13448. t.Zcircle = 0x24cf;
  13449. t.Zcircumflex = 0x1e90;
  13450. t.Zdot = 0x017b;
  13451. t.Zdotaccent = 0x017b;
  13452. t.Zdotbelow = 0x1e92;
  13453. t.Zecyrillic = 0x0417;
  13454. t.Zedescendercyrillic = 0x0498;
  13455. t.Zedieresiscyrillic = 0x04de;
  13456. t.Zeta = 0x0396;
  13457. t.Zhearmenian = 0x053a;
  13458. t.Zhebrevecyrillic = 0x04c1;
  13459. t.Zhecyrillic = 0x0416;
  13460. t.Zhedescendercyrillic = 0x0496;
  13461. t.Zhedieresiscyrillic = 0x04dc;
  13462. t.Zlinebelow = 0x1e94;
  13463. t.Zmonospace = 0xff3a;
  13464. t.Zsmall = 0xf77a;
  13465. t.Zstroke = 0x01b5;
  13466. t.a = 0x0061;
  13467. t.aabengali = 0x0986;
  13468. t.aacute = 0x00e1;
  13469. t.aadeva = 0x0906;
  13470. t.aagujarati = 0x0a86;
  13471. t.aagurmukhi = 0x0a06;
  13472. t.aamatragurmukhi = 0x0a3e;
  13473. t.aarusquare = 0x3303;
  13474. t.aavowelsignbengali = 0x09be;
  13475. t.aavowelsigndeva = 0x093e;
  13476. t.aavowelsigngujarati = 0x0abe;
  13477. t.abbreviationmarkarmenian = 0x055f;
  13478. t.abbreviationsigndeva = 0x0970;
  13479. t.abengali = 0x0985;
  13480. t.abopomofo = 0x311a;
  13481. t.abreve = 0x0103;
  13482. t.abreveacute = 0x1eaf;
  13483. t.abrevecyrillic = 0x04d1;
  13484. t.abrevedotbelow = 0x1eb7;
  13485. t.abrevegrave = 0x1eb1;
  13486. t.abrevehookabove = 0x1eb3;
  13487. t.abrevetilde = 0x1eb5;
  13488. t.acaron = 0x01ce;
  13489. t.acircle = 0x24d0;
  13490. t.acircumflex = 0x00e2;
  13491. t.acircumflexacute = 0x1ea5;
  13492. t.acircumflexdotbelow = 0x1ead;
  13493. t.acircumflexgrave = 0x1ea7;
  13494. t.acircumflexhookabove = 0x1ea9;
  13495. t.acircumflextilde = 0x1eab;
  13496. t.acute = 0x00b4;
  13497. t.acutebelowcmb = 0x0317;
  13498. t.acutecmb = 0x0301;
  13499. t.acutecomb = 0x0301;
  13500. t.acutedeva = 0x0954;
  13501. t.acutelowmod = 0x02cf;
  13502. t.acutetonecmb = 0x0341;
  13503. t.acyrillic = 0x0430;
  13504. t.adblgrave = 0x0201;
  13505. t.addakgurmukhi = 0x0a71;
  13506. t.adeva = 0x0905;
  13507. t.adieresis = 0x00e4;
  13508. t.adieresiscyrillic = 0x04d3;
  13509. t.adieresismacron = 0x01df;
  13510. t.adotbelow = 0x1ea1;
  13511. t.adotmacron = 0x01e1;
  13512. t.ae = 0x00e6;
  13513. t.aeacute = 0x01fd;
  13514. t.aekorean = 0x3150;
  13515. t.aemacron = 0x01e3;
  13516. t.afii00208 = 0x2015;
  13517. t.afii08941 = 0x20a4;
  13518. t.afii10017 = 0x0410;
  13519. t.afii10018 = 0x0411;
  13520. t.afii10019 = 0x0412;
  13521. t.afii10020 = 0x0413;
  13522. t.afii10021 = 0x0414;
  13523. t.afii10022 = 0x0415;
  13524. t.afii10023 = 0x0401;
  13525. t.afii10024 = 0x0416;
  13526. t.afii10025 = 0x0417;
  13527. t.afii10026 = 0x0418;
  13528. t.afii10027 = 0x0419;
  13529. t.afii10028 = 0x041a;
  13530. t.afii10029 = 0x041b;
  13531. t.afii10030 = 0x041c;
  13532. t.afii10031 = 0x041d;
  13533. t.afii10032 = 0x041e;
  13534. t.afii10033 = 0x041f;
  13535. t.afii10034 = 0x0420;
  13536. t.afii10035 = 0x0421;
  13537. t.afii10036 = 0x0422;
  13538. t.afii10037 = 0x0423;
  13539. t.afii10038 = 0x0424;
  13540. t.afii10039 = 0x0425;
  13541. t.afii10040 = 0x0426;
  13542. t.afii10041 = 0x0427;
  13543. t.afii10042 = 0x0428;
  13544. t.afii10043 = 0x0429;
  13545. t.afii10044 = 0x042a;
  13546. t.afii10045 = 0x042b;
  13547. t.afii10046 = 0x042c;
  13548. t.afii10047 = 0x042d;
  13549. t.afii10048 = 0x042e;
  13550. t.afii10049 = 0x042f;
  13551. t.afii10050 = 0x0490;
  13552. t.afii10051 = 0x0402;
  13553. t.afii10052 = 0x0403;
  13554. t.afii10053 = 0x0404;
  13555. t.afii10054 = 0x0405;
  13556. t.afii10055 = 0x0406;
  13557. t.afii10056 = 0x0407;
  13558. t.afii10057 = 0x0408;
  13559. t.afii10058 = 0x0409;
  13560. t.afii10059 = 0x040a;
  13561. t.afii10060 = 0x040b;
  13562. t.afii10061 = 0x040c;
  13563. t.afii10062 = 0x040e;
  13564. t.afii10063 = 0xf6c4;
  13565. t.afii10064 = 0xf6c5;
  13566. t.afii10065 = 0x0430;
  13567. t.afii10066 = 0x0431;
  13568. t.afii10067 = 0x0432;
  13569. t.afii10068 = 0x0433;
  13570. t.afii10069 = 0x0434;
  13571. t.afii10070 = 0x0435;
  13572. t.afii10071 = 0x0451;
  13573. t.afii10072 = 0x0436;
  13574. t.afii10073 = 0x0437;
  13575. t.afii10074 = 0x0438;
  13576. t.afii10075 = 0x0439;
  13577. t.afii10076 = 0x043a;
  13578. t.afii10077 = 0x043b;
  13579. t.afii10078 = 0x043c;
  13580. t.afii10079 = 0x043d;
  13581. t.afii10080 = 0x043e;
  13582. t.afii10081 = 0x043f;
  13583. t.afii10082 = 0x0440;
  13584. t.afii10083 = 0x0441;
  13585. t.afii10084 = 0x0442;
  13586. t.afii10085 = 0x0443;
  13587. t.afii10086 = 0x0444;
  13588. t.afii10087 = 0x0445;
  13589. t.afii10088 = 0x0446;
  13590. t.afii10089 = 0x0447;
  13591. t.afii10090 = 0x0448;
  13592. t.afii10091 = 0x0449;
  13593. t.afii10092 = 0x044a;
  13594. t.afii10093 = 0x044b;
  13595. t.afii10094 = 0x044c;
  13596. t.afii10095 = 0x044d;
  13597. t.afii10096 = 0x044e;
  13598. t.afii10097 = 0x044f;
  13599. t.afii10098 = 0x0491;
  13600. t.afii10099 = 0x0452;
  13601. t.afii10100 = 0x0453;
  13602. t.afii10101 = 0x0454;
  13603. t.afii10102 = 0x0455;
  13604. t.afii10103 = 0x0456;
  13605. t.afii10104 = 0x0457;
  13606. t.afii10105 = 0x0458;
  13607. t.afii10106 = 0x0459;
  13608. t.afii10107 = 0x045a;
  13609. t.afii10108 = 0x045b;
  13610. t.afii10109 = 0x045c;
  13611. t.afii10110 = 0x045e;
  13612. t.afii10145 = 0x040f;
  13613. t.afii10146 = 0x0462;
  13614. t.afii10147 = 0x0472;
  13615. t.afii10148 = 0x0474;
  13616. t.afii10192 = 0xf6c6;
  13617. t.afii10193 = 0x045f;
  13618. t.afii10194 = 0x0463;
  13619. t.afii10195 = 0x0473;
  13620. t.afii10196 = 0x0475;
  13621. t.afii10831 = 0xf6c7;
  13622. t.afii10832 = 0xf6c8;
  13623. t.afii10846 = 0x04d9;
  13624. t.afii299 = 0x200e;
  13625. t.afii300 = 0x200f;
  13626. t.afii301 = 0x200d;
  13627. t.afii57381 = 0x066a;
  13628. t.afii57388 = 0x060c;
  13629. t.afii57392 = 0x0660;
  13630. t.afii57393 = 0x0661;
  13631. t.afii57394 = 0x0662;
  13632. t.afii57395 = 0x0663;
  13633. t.afii57396 = 0x0664;
  13634. t.afii57397 = 0x0665;
  13635. t.afii57398 = 0x0666;
  13636. t.afii57399 = 0x0667;
  13637. t.afii57400 = 0x0668;
  13638. t.afii57401 = 0x0669;
  13639. t.afii57403 = 0x061b;
  13640. t.afii57407 = 0x061f;
  13641. t.afii57409 = 0x0621;
  13642. t.afii57410 = 0x0622;
  13643. t.afii57411 = 0x0623;
  13644. t.afii57412 = 0x0624;
  13645. t.afii57413 = 0x0625;
  13646. t.afii57414 = 0x0626;
  13647. t.afii57415 = 0x0627;
  13648. t.afii57416 = 0x0628;
  13649. t.afii57417 = 0x0629;
  13650. t.afii57418 = 0x062a;
  13651. t.afii57419 = 0x062b;
  13652. t.afii57420 = 0x062c;
  13653. t.afii57421 = 0x062d;
  13654. t.afii57422 = 0x062e;
  13655. t.afii57423 = 0x062f;
  13656. t.afii57424 = 0x0630;
  13657. t.afii57425 = 0x0631;
  13658. t.afii57426 = 0x0632;
  13659. t.afii57427 = 0x0633;
  13660. t.afii57428 = 0x0634;
  13661. t.afii57429 = 0x0635;
  13662. t.afii57430 = 0x0636;
  13663. t.afii57431 = 0x0637;
  13664. t.afii57432 = 0x0638;
  13665. t.afii57433 = 0x0639;
  13666. t.afii57434 = 0x063a;
  13667. t.afii57440 = 0x0640;
  13668. t.afii57441 = 0x0641;
  13669. t.afii57442 = 0x0642;
  13670. t.afii57443 = 0x0643;
  13671. t.afii57444 = 0x0644;
  13672. t.afii57445 = 0x0645;
  13673. t.afii57446 = 0x0646;
  13674. t.afii57448 = 0x0648;
  13675. t.afii57449 = 0x0649;
  13676. t.afii57450 = 0x064a;
  13677. t.afii57451 = 0x064b;
  13678. t.afii57452 = 0x064c;
  13679. t.afii57453 = 0x064d;
  13680. t.afii57454 = 0x064e;
  13681. t.afii57455 = 0x064f;
  13682. t.afii57456 = 0x0650;
  13683. t.afii57457 = 0x0651;
  13684. t.afii57458 = 0x0652;
  13685. t.afii57470 = 0x0647;
  13686. t.afii57505 = 0x06a4;
  13687. t.afii57506 = 0x067e;
  13688. t.afii57507 = 0x0686;
  13689. t.afii57508 = 0x0698;
  13690. t.afii57509 = 0x06af;
  13691. t.afii57511 = 0x0679;
  13692. t.afii57512 = 0x0688;
  13693. t.afii57513 = 0x0691;
  13694. t.afii57514 = 0x06ba;
  13695. t.afii57519 = 0x06d2;
  13696. t.afii57534 = 0x06d5;
  13697. t.afii57636 = 0x20aa;
  13698. t.afii57645 = 0x05be;
  13699. t.afii57658 = 0x05c3;
  13700. t.afii57664 = 0x05d0;
  13701. t.afii57665 = 0x05d1;
  13702. t.afii57666 = 0x05d2;
  13703. t.afii57667 = 0x05d3;
  13704. t.afii57668 = 0x05d4;
  13705. t.afii57669 = 0x05d5;
  13706. t.afii57670 = 0x05d6;
  13707. t.afii57671 = 0x05d7;
  13708. t.afii57672 = 0x05d8;
  13709. t.afii57673 = 0x05d9;
  13710. t.afii57674 = 0x05da;
  13711. t.afii57675 = 0x05db;
  13712. t.afii57676 = 0x05dc;
  13713. t.afii57677 = 0x05dd;
  13714. t.afii57678 = 0x05de;
  13715. t.afii57679 = 0x05df;
  13716. t.afii57680 = 0x05e0;
  13717. t.afii57681 = 0x05e1;
  13718. t.afii57682 = 0x05e2;
  13719. t.afii57683 = 0x05e3;
  13720. t.afii57684 = 0x05e4;
  13721. t.afii57685 = 0x05e5;
  13722. t.afii57686 = 0x05e6;
  13723. t.afii57687 = 0x05e7;
  13724. t.afii57688 = 0x05e8;
  13725. t.afii57689 = 0x05e9;
  13726. t.afii57690 = 0x05ea;
  13727. t.afii57694 = 0xfb2a;
  13728. t.afii57695 = 0xfb2b;
  13729. t.afii57700 = 0xfb4b;
  13730. t.afii57705 = 0xfb1f;
  13731. t.afii57716 = 0x05f0;
  13732. t.afii57717 = 0x05f1;
  13733. t.afii57718 = 0x05f2;
  13734. t.afii57723 = 0xfb35;
  13735. t.afii57793 = 0x05b4;
  13736. t.afii57794 = 0x05b5;
  13737. t.afii57795 = 0x05b6;
  13738. t.afii57796 = 0x05bb;
  13739. t.afii57797 = 0x05b8;
  13740. t.afii57798 = 0x05b7;
  13741. t.afii57799 = 0x05b0;
  13742. t.afii57800 = 0x05b2;
  13743. t.afii57801 = 0x05b1;
  13744. t.afii57802 = 0x05b3;
  13745. t.afii57803 = 0x05c2;
  13746. t.afii57804 = 0x05c1;
  13747. t.afii57806 = 0x05b9;
  13748. t.afii57807 = 0x05bc;
  13749. t.afii57839 = 0x05bd;
  13750. t.afii57841 = 0x05bf;
  13751. t.afii57842 = 0x05c0;
  13752. t.afii57929 = 0x02bc;
  13753. t.afii61248 = 0x2105;
  13754. t.afii61289 = 0x2113;
  13755. t.afii61352 = 0x2116;
  13756. t.afii61573 = 0x202c;
  13757. t.afii61574 = 0x202d;
  13758. t.afii61575 = 0x202e;
  13759. t.afii61664 = 0x200c;
  13760. t.afii63167 = 0x066d;
  13761. t.afii64937 = 0x02bd;
  13762. t.agrave = 0x00e0;
  13763. t.agujarati = 0x0a85;
  13764. t.agurmukhi = 0x0a05;
  13765. t.ahiragana = 0x3042;
  13766. t.ahookabove = 0x1ea3;
  13767. t.aibengali = 0x0990;
  13768. t.aibopomofo = 0x311e;
  13769. t.aideva = 0x0910;
  13770. t.aiecyrillic = 0x04d5;
  13771. t.aigujarati = 0x0a90;
  13772. t.aigurmukhi = 0x0a10;
  13773. t.aimatragurmukhi = 0x0a48;
  13774. t.ainarabic = 0x0639;
  13775. t.ainfinalarabic = 0xfeca;
  13776. t.aininitialarabic = 0xfecb;
  13777. t.ainmedialarabic = 0xfecc;
  13778. t.ainvertedbreve = 0x0203;
  13779. t.aivowelsignbengali = 0x09c8;
  13780. t.aivowelsigndeva = 0x0948;
  13781. t.aivowelsigngujarati = 0x0ac8;
  13782. t.akatakana = 0x30a2;
  13783. t.akatakanahalfwidth = 0xff71;
  13784. t.akorean = 0x314f;
  13785. t.alef = 0x05d0;
  13786. t.alefarabic = 0x0627;
  13787. t.alefdageshhebrew = 0xfb30;
  13788. t.aleffinalarabic = 0xfe8e;
  13789. t.alefhamzaabovearabic = 0x0623;
  13790. t.alefhamzaabovefinalarabic = 0xfe84;
  13791. t.alefhamzabelowarabic = 0x0625;
  13792. t.alefhamzabelowfinalarabic = 0xfe88;
  13793. t.alefhebrew = 0x05d0;
  13794. t.aleflamedhebrew = 0xfb4f;
  13795. t.alefmaddaabovearabic = 0x0622;
  13796. t.alefmaddaabovefinalarabic = 0xfe82;
  13797. t.alefmaksuraarabic = 0x0649;
  13798. t.alefmaksurafinalarabic = 0xfef0;
  13799. t.alefmaksurainitialarabic = 0xfef3;
  13800. t.alefmaksuramedialarabic = 0xfef4;
  13801. t.alefpatahhebrew = 0xfb2e;
  13802. t.alefqamatshebrew = 0xfb2f;
  13803. t.aleph = 0x2135;
  13804. t.allequal = 0x224c;
  13805. t.alpha = 0x03b1;
  13806. t.alphatonos = 0x03ac;
  13807. t.amacron = 0x0101;
  13808. t.amonospace = 0xff41;
  13809. t.ampersand = 0x0026;
  13810. t.ampersandmonospace = 0xff06;
  13811. t.ampersandsmall = 0xf726;
  13812. t.amsquare = 0x33c2;
  13813. t.anbopomofo = 0x3122;
  13814. t.angbopomofo = 0x3124;
  13815. t.angbracketleft = 0x3008;
  13816. t.angbracketright = 0x3009;
  13817. t.angkhankhuthai = 0x0e5a;
  13818. t.angle = 0x2220;
  13819. t.anglebracketleft = 0x3008;
  13820. t.anglebracketleftvertical = 0xfe3f;
  13821. t.anglebracketright = 0x3009;
  13822. t.anglebracketrightvertical = 0xfe40;
  13823. t.angleleft = 0x2329;
  13824. t.angleright = 0x232a;
  13825. t.angstrom = 0x212b;
  13826. t.anoteleia = 0x0387;
  13827. t.anudattadeva = 0x0952;
  13828. t.anusvarabengali = 0x0982;
  13829. t.anusvaradeva = 0x0902;
  13830. t.anusvaragujarati = 0x0a82;
  13831. t.aogonek = 0x0105;
  13832. t.apaatosquare = 0x3300;
  13833. t.aparen = 0x249c;
  13834. t.apostrophearmenian = 0x055a;
  13835. t.apostrophemod = 0x02bc;
  13836. t.apple = 0xf8ff;
  13837. t.approaches = 0x2250;
  13838. t.approxequal = 0x2248;
  13839. t.approxequalorimage = 0x2252;
  13840. t.approximatelyequal = 0x2245;
  13841. t.araeaekorean = 0x318e;
  13842. t.araeakorean = 0x318d;
  13843. t.arc = 0x2312;
  13844. t.arighthalfring = 0x1e9a;
  13845. t.aring = 0x00e5;
  13846. t.aringacute = 0x01fb;
  13847. t.aringbelow = 0x1e01;
  13848. t.arrowboth = 0x2194;
  13849. t.arrowdashdown = 0x21e3;
  13850. t.arrowdashleft = 0x21e0;
  13851. t.arrowdashright = 0x21e2;
  13852. t.arrowdashup = 0x21e1;
  13853. t.arrowdblboth = 0x21d4;
  13854. t.arrowdbldown = 0x21d3;
  13855. t.arrowdblleft = 0x21d0;
  13856. t.arrowdblright = 0x21d2;
  13857. t.arrowdblup = 0x21d1;
  13858. t.arrowdown = 0x2193;
  13859. t.arrowdownleft = 0x2199;
  13860. t.arrowdownright = 0x2198;
  13861. t.arrowdownwhite = 0x21e9;
  13862. t.arrowheaddownmod = 0x02c5;
  13863. t.arrowheadleftmod = 0x02c2;
  13864. t.arrowheadrightmod = 0x02c3;
  13865. t.arrowheadupmod = 0x02c4;
  13866. t.arrowhorizex = 0xf8e7;
  13867. t.arrowleft = 0x2190;
  13868. t.arrowleftdbl = 0x21d0;
  13869. t.arrowleftdblstroke = 0x21cd;
  13870. t.arrowleftoverright = 0x21c6;
  13871. t.arrowleftwhite = 0x21e6;
  13872. t.arrowright = 0x2192;
  13873. t.arrowrightdblstroke = 0x21cf;
  13874. t.arrowrightheavy = 0x279e;
  13875. t.arrowrightoverleft = 0x21c4;
  13876. t.arrowrightwhite = 0x21e8;
  13877. t.arrowtableft = 0x21e4;
  13878. t.arrowtabright = 0x21e5;
  13879. t.arrowup = 0x2191;
  13880. t.arrowupdn = 0x2195;
  13881. t.arrowupdnbse = 0x21a8;
  13882. t.arrowupdownbase = 0x21a8;
  13883. t.arrowupleft = 0x2196;
  13884. t.arrowupleftofdown = 0x21c5;
  13885. t.arrowupright = 0x2197;
  13886. t.arrowupwhite = 0x21e7;
  13887. t.arrowvertex = 0xf8e6;
  13888. t.asciicircum = 0x005e;
  13889. t.asciicircummonospace = 0xff3e;
  13890. t.asciitilde = 0x007e;
  13891. t.asciitildemonospace = 0xff5e;
  13892. t.ascript = 0x0251;
  13893. t.ascriptturned = 0x0252;
  13894. t.asmallhiragana = 0x3041;
  13895. t.asmallkatakana = 0x30a1;
  13896. t.asmallkatakanahalfwidth = 0xff67;
  13897. t.asterisk = 0x002a;
  13898. t.asteriskaltonearabic = 0x066d;
  13899. t.asteriskarabic = 0x066d;
  13900. t.asteriskmath = 0x2217;
  13901. t.asteriskmonospace = 0xff0a;
  13902. t.asterisksmall = 0xfe61;
  13903. t.asterism = 0x2042;
  13904. t.asuperior = 0xf6e9;
  13905. t.asymptoticallyequal = 0x2243;
  13906. t.at = 0x0040;
  13907. t.atilde = 0x00e3;
  13908. t.atmonospace = 0xff20;
  13909. t.atsmall = 0xfe6b;
  13910. t.aturned = 0x0250;
  13911. t.aubengali = 0x0994;
  13912. t.aubopomofo = 0x3120;
  13913. t.audeva = 0x0914;
  13914. t.augujarati = 0x0a94;
  13915. t.augurmukhi = 0x0a14;
  13916. t.aulengthmarkbengali = 0x09d7;
  13917. t.aumatragurmukhi = 0x0a4c;
  13918. t.auvowelsignbengali = 0x09cc;
  13919. t.auvowelsigndeva = 0x094c;
  13920. t.auvowelsigngujarati = 0x0acc;
  13921. t.avagrahadeva = 0x093d;
  13922. t.aybarmenian = 0x0561;
  13923. t.ayin = 0x05e2;
  13924. t.ayinaltonehebrew = 0xfb20;
  13925. t.ayinhebrew = 0x05e2;
  13926. t.b = 0x0062;
  13927. t.babengali = 0x09ac;
  13928. t.backslash = 0x005c;
  13929. t.backslashmonospace = 0xff3c;
  13930. t.badeva = 0x092c;
  13931. t.bagujarati = 0x0aac;
  13932. t.bagurmukhi = 0x0a2c;
  13933. t.bahiragana = 0x3070;
  13934. t.bahtthai = 0x0e3f;
  13935. t.bakatakana = 0x30d0;
  13936. t.bar = 0x007c;
  13937. t.barmonospace = 0xff5c;
  13938. t.bbopomofo = 0x3105;
  13939. t.bcircle = 0x24d1;
  13940. t.bdotaccent = 0x1e03;
  13941. t.bdotbelow = 0x1e05;
  13942. t.beamedsixteenthnotes = 0x266c;
  13943. t.because = 0x2235;
  13944. t.becyrillic = 0x0431;
  13945. t.beharabic = 0x0628;
  13946. t.behfinalarabic = 0xfe90;
  13947. t.behinitialarabic = 0xfe91;
  13948. t.behiragana = 0x3079;
  13949. t.behmedialarabic = 0xfe92;
  13950. t.behmeeminitialarabic = 0xfc9f;
  13951. t.behmeemisolatedarabic = 0xfc08;
  13952. t.behnoonfinalarabic = 0xfc6d;
  13953. t.bekatakana = 0x30d9;
  13954. t.benarmenian = 0x0562;
  13955. t.bet = 0x05d1;
  13956. t.beta = 0x03b2;
  13957. t.betasymbolgreek = 0x03d0;
  13958. t.betdagesh = 0xfb31;
  13959. t.betdageshhebrew = 0xfb31;
  13960. t.bethebrew = 0x05d1;
  13961. t.betrafehebrew = 0xfb4c;
  13962. t.bhabengali = 0x09ad;
  13963. t.bhadeva = 0x092d;
  13964. t.bhagujarati = 0x0aad;
  13965. t.bhagurmukhi = 0x0a2d;
  13966. t.bhook = 0x0253;
  13967. t.bihiragana = 0x3073;
  13968. t.bikatakana = 0x30d3;
  13969. t.bilabialclick = 0x0298;
  13970. t.bindigurmukhi = 0x0a02;
  13971. t.birusquare = 0x3331;
  13972. t.blackcircle = 0x25cf;
  13973. t.blackdiamond = 0x25c6;
  13974. t.blackdownpointingtriangle = 0x25bc;
  13975. t.blackleftpointingpointer = 0x25c4;
  13976. t.blackleftpointingtriangle = 0x25c0;
  13977. t.blacklenticularbracketleft = 0x3010;
  13978. t.blacklenticularbracketleftvertical = 0xfe3b;
  13979. t.blacklenticularbracketright = 0x3011;
  13980. t.blacklenticularbracketrightvertical = 0xfe3c;
  13981. t.blacklowerlefttriangle = 0x25e3;
  13982. t.blacklowerrighttriangle = 0x25e2;
  13983. t.blackrectangle = 0x25ac;
  13984. t.blackrightpointingpointer = 0x25ba;
  13985. t.blackrightpointingtriangle = 0x25b6;
  13986. t.blacksmallsquare = 0x25aa;
  13987. t.blacksmilingface = 0x263b;
  13988. t.blacksquare = 0x25a0;
  13989. t.blackstar = 0x2605;
  13990. t.blackupperlefttriangle = 0x25e4;
  13991. t.blackupperrighttriangle = 0x25e5;
  13992. t.blackuppointingsmalltriangle = 0x25b4;
  13993. t.blackuppointingtriangle = 0x25b2;
  13994. t.blank = 0x2423;
  13995. t.blinebelow = 0x1e07;
  13996. t.block = 0x2588;
  13997. t.bmonospace = 0xff42;
  13998. t.bobaimaithai = 0x0e1a;
  13999. t.bohiragana = 0x307c;
  14000. t.bokatakana = 0x30dc;
  14001. t.bparen = 0x249d;
  14002. t.bqsquare = 0x33c3;
  14003. t.braceex = 0xf8f4;
  14004. t.braceleft = 0x007b;
  14005. t.braceleftbt = 0xf8f3;
  14006. t.braceleftmid = 0xf8f2;
  14007. t.braceleftmonospace = 0xff5b;
  14008. t.braceleftsmall = 0xfe5b;
  14009. t.bracelefttp = 0xf8f1;
  14010. t.braceleftvertical = 0xfe37;
  14011. t.braceright = 0x007d;
  14012. t.bracerightbt = 0xf8fe;
  14013. t.bracerightmid = 0xf8fd;
  14014. t.bracerightmonospace = 0xff5d;
  14015. t.bracerightsmall = 0xfe5c;
  14016. t.bracerighttp = 0xf8fc;
  14017. t.bracerightvertical = 0xfe38;
  14018. t.bracketleft = 0x005b;
  14019. t.bracketleftbt = 0xf8f0;
  14020. t.bracketleftex = 0xf8ef;
  14021. t.bracketleftmonospace = 0xff3b;
  14022. t.bracketlefttp = 0xf8ee;
  14023. t.bracketright = 0x005d;
  14024. t.bracketrightbt = 0xf8fb;
  14025. t.bracketrightex = 0xf8fa;
  14026. t.bracketrightmonospace = 0xff3d;
  14027. t.bracketrighttp = 0xf8f9;
  14028. t.breve = 0x02d8;
  14029. t.brevebelowcmb = 0x032e;
  14030. t.brevecmb = 0x0306;
  14031. t.breveinvertedbelowcmb = 0x032f;
  14032. t.breveinvertedcmb = 0x0311;
  14033. t.breveinverteddoublecmb = 0x0361;
  14034. t.bridgebelowcmb = 0x032a;
  14035. t.bridgeinvertedbelowcmb = 0x033a;
  14036. t.brokenbar = 0x00a6;
  14037. t.bstroke = 0x0180;
  14038. t.bsuperior = 0xf6ea;
  14039. t.btopbar = 0x0183;
  14040. t.buhiragana = 0x3076;
  14041. t.bukatakana = 0x30d6;
  14042. t.bullet = 0x2022;
  14043. t.bulletinverse = 0x25d8;
  14044. t.bulletoperator = 0x2219;
  14045. t.bullseye = 0x25ce;
  14046. t.c = 0x0063;
  14047. t.caarmenian = 0x056e;
  14048. t.cabengali = 0x099a;
  14049. t.cacute = 0x0107;
  14050. t.cadeva = 0x091a;
  14051. t.cagujarati = 0x0a9a;
  14052. t.cagurmukhi = 0x0a1a;
  14053. t.calsquare = 0x3388;
  14054. t.candrabindubengali = 0x0981;
  14055. t.candrabinducmb = 0x0310;
  14056. t.candrabindudeva = 0x0901;
  14057. t.candrabindugujarati = 0x0a81;
  14058. t.capslock = 0x21ea;
  14059. t.careof = 0x2105;
  14060. t.caron = 0x02c7;
  14061. t.caronbelowcmb = 0x032c;
  14062. t.caroncmb = 0x030c;
  14063. t.carriagereturn = 0x21b5;
  14064. t.cbopomofo = 0x3118;
  14065. t.ccaron = 0x010d;
  14066. t.ccedilla = 0x00e7;
  14067. t.ccedillaacute = 0x1e09;
  14068. t.ccircle = 0x24d2;
  14069. t.ccircumflex = 0x0109;
  14070. t.ccurl = 0x0255;
  14071. t.cdot = 0x010b;
  14072. t.cdotaccent = 0x010b;
  14073. t.cdsquare = 0x33c5;
  14074. t.cedilla = 0x00b8;
  14075. t.cedillacmb = 0x0327;
  14076. t.cent = 0x00a2;
  14077. t.centigrade = 0x2103;
  14078. t.centinferior = 0xf6df;
  14079. t.centmonospace = 0xffe0;
  14080. t.centoldstyle = 0xf7a2;
  14081. t.centsuperior = 0xf6e0;
  14082. t.chaarmenian = 0x0579;
  14083. t.chabengali = 0x099b;
  14084. t.chadeva = 0x091b;
  14085. t.chagujarati = 0x0a9b;
  14086. t.chagurmukhi = 0x0a1b;
  14087. t.chbopomofo = 0x3114;
  14088. t.cheabkhasiancyrillic = 0x04bd;
  14089. t.checkmark = 0x2713;
  14090. t.checyrillic = 0x0447;
  14091. t.chedescenderabkhasiancyrillic = 0x04bf;
  14092. t.chedescendercyrillic = 0x04b7;
  14093. t.chedieresiscyrillic = 0x04f5;
  14094. t.cheharmenian = 0x0573;
  14095. t.chekhakassiancyrillic = 0x04cc;
  14096. t.cheverticalstrokecyrillic = 0x04b9;
  14097. t.chi = 0x03c7;
  14098. t.chieuchacirclekorean = 0x3277;
  14099. t.chieuchaparenkorean = 0x3217;
  14100. t.chieuchcirclekorean = 0x3269;
  14101. t.chieuchkorean = 0x314a;
  14102. t.chieuchparenkorean = 0x3209;
  14103. t.chochangthai = 0x0e0a;
  14104. t.chochanthai = 0x0e08;
  14105. t.chochingthai = 0x0e09;
  14106. t.chochoethai = 0x0e0c;
  14107. t.chook = 0x0188;
  14108. t.cieucacirclekorean = 0x3276;
  14109. t.cieucaparenkorean = 0x3216;
  14110. t.cieuccirclekorean = 0x3268;
  14111. t.cieuckorean = 0x3148;
  14112. t.cieucparenkorean = 0x3208;
  14113. t.cieucuparenkorean = 0x321c;
  14114. t.circle = 0x25cb;
  14115. t.circlecopyrt = 0x00a9;
  14116. t.circlemultiply = 0x2297;
  14117. t.circleot = 0x2299;
  14118. t.circleplus = 0x2295;
  14119. t.circlepostalmark = 0x3036;
  14120. t.circlewithlefthalfblack = 0x25d0;
  14121. t.circlewithrighthalfblack = 0x25d1;
  14122. t.circumflex = 0x02c6;
  14123. t.circumflexbelowcmb = 0x032d;
  14124. t.circumflexcmb = 0x0302;
  14125. t.clear = 0x2327;
  14126. t.clickalveolar = 0x01c2;
  14127. t.clickdental = 0x01c0;
  14128. t.clicklateral = 0x01c1;
  14129. t.clickretroflex = 0x01c3;
  14130. t.club = 0x2663;
  14131. t.clubsuitblack = 0x2663;
  14132. t.clubsuitwhite = 0x2667;
  14133. t.cmcubedsquare = 0x33a4;
  14134. t.cmonospace = 0xff43;
  14135. t.cmsquaredsquare = 0x33a0;
  14136. t.coarmenian = 0x0581;
  14137. t.colon = 0x003a;
  14138. t.colonmonetary = 0x20a1;
  14139. t.colonmonospace = 0xff1a;
  14140. t.colonsign = 0x20a1;
  14141. t.colonsmall = 0xfe55;
  14142. t.colontriangularhalfmod = 0x02d1;
  14143. t.colontriangularmod = 0x02d0;
  14144. t.comma = 0x002c;
  14145. t.commaabovecmb = 0x0313;
  14146. t.commaaboverightcmb = 0x0315;
  14147. t.commaaccent = 0xf6c3;
  14148. t.commaarabic = 0x060c;
  14149. t.commaarmenian = 0x055d;
  14150. t.commainferior = 0xf6e1;
  14151. t.commamonospace = 0xff0c;
  14152. t.commareversedabovecmb = 0x0314;
  14153. t.commareversedmod = 0x02bd;
  14154. t.commasmall = 0xfe50;
  14155. t.commasuperior = 0xf6e2;
  14156. t.commaturnedabovecmb = 0x0312;
  14157. t.commaturnedmod = 0x02bb;
  14158. t.compass = 0x263c;
  14159. t.congruent = 0x2245;
  14160. t.contourintegral = 0x222e;
  14161. t.control = 0x2303;
  14162. t.controlACK = 0x0006;
  14163. t.controlBEL = 0x0007;
  14164. t.controlBS = 0x0008;
  14165. t.controlCAN = 0x0018;
  14166. t.controlCR = 0x000d;
  14167. t.controlDC1 = 0x0011;
  14168. t.controlDC2 = 0x0012;
  14169. t.controlDC3 = 0x0013;
  14170. t.controlDC4 = 0x0014;
  14171. t.controlDEL = 0x007f;
  14172. t.controlDLE = 0x0010;
  14173. t.controlEM = 0x0019;
  14174. t.controlENQ = 0x0005;
  14175. t.controlEOT = 0x0004;
  14176. t.controlESC = 0x001b;
  14177. t.controlETB = 0x0017;
  14178. t.controlETX = 0x0003;
  14179. t.controlFF = 0x000c;
  14180. t.controlFS = 0x001c;
  14181. t.controlGS = 0x001d;
  14182. t.controlHT = 0x0009;
  14183. t.controlLF = 0x000a;
  14184. t.controlNAK = 0x0015;
  14185. t.controlNULL = 0x0000;
  14186. t.controlRS = 0x001e;
  14187. t.controlSI = 0x000f;
  14188. t.controlSO = 0x000e;
  14189. t.controlSOT = 0x0002;
  14190. t.controlSTX = 0x0001;
  14191. t.controlSUB = 0x001a;
  14192. t.controlSYN = 0x0016;
  14193. t.controlUS = 0x001f;
  14194. t.controlVT = 0x000b;
  14195. t.copyright = 0x00a9;
  14196. t.copyrightsans = 0xf8e9;
  14197. t.copyrightserif = 0xf6d9;
  14198. t.cornerbracketleft = 0x300c;
  14199. t.cornerbracketlefthalfwidth = 0xff62;
  14200. t.cornerbracketleftvertical = 0xfe41;
  14201. t.cornerbracketright = 0x300d;
  14202. t.cornerbracketrighthalfwidth = 0xff63;
  14203. t.cornerbracketrightvertical = 0xfe42;
  14204. t.corporationsquare = 0x337f;
  14205. t.cosquare = 0x33c7;
  14206. t.coverkgsquare = 0x33c6;
  14207. t.cparen = 0x249e;
  14208. t.cruzeiro = 0x20a2;
  14209. t.cstretched = 0x0297;
  14210. t.curlyand = 0x22cf;
  14211. t.curlyor = 0x22ce;
  14212. t.currency = 0x00a4;
  14213. t.cyrBreve = 0xf6d1;
  14214. t.cyrFlex = 0xf6d2;
  14215. t.cyrbreve = 0xf6d4;
  14216. t.cyrflex = 0xf6d5;
  14217. t.d = 0x0064;
  14218. t.daarmenian = 0x0564;
  14219. t.dabengali = 0x09a6;
  14220. t.dadarabic = 0x0636;
  14221. t.dadeva = 0x0926;
  14222. t.dadfinalarabic = 0xfebe;
  14223. t.dadinitialarabic = 0xfebf;
  14224. t.dadmedialarabic = 0xfec0;
  14225. t.dagesh = 0x05bc;
  14226. t.dageshhebrew = 0x05bc;
  14227. t.dagger = 0x2020;
  14228. t.daggerdbl = 0x2021;
  14229. t.dagujarati = 0x0aa6;
  14230. t.dagurmukhi = 0x0a26;
  14231. t.dahiragana = 0x3060;
  14232. t.dakatakana = 0x30c0;
  14233. t.dalarabic = 0x062f;
  14234. t.dalet = 0x05d3;
  14235. t.daletdagesh = 0xfb33;
  14236. t.daletdageshhebrew = 0xfb33;
  14237. t.dalethebrew = 0x05d3;
  14238. t.dalfinalarabic = 0xfeaa;
  14239. t.dammaarabic = 0x064f;
  14240. t.dammalowarabic = 0x064f;
  14241. t.dammatanaltonearabic = 0x064c;
  14242. t.dammatanarabic = 0x064c;
  14243. t.danda = 0x0964;
  14244. t.dargahebrew = 0x05a7;
  14245. t.dargalefthebrew = 0x05a7;
  14246. t.dasiapneumatacyrilliccmb = 0x0485;
  14247. t.dblGrave = 0xf6d3;
  14248. t.dblanglebracketleft = 0x300a;
  14249. t.dblanglebracketleftvertical = 0xfe3d;
  14250. t.dblanglebracketright = 0x300b;
  14251. t.dblanglebracketrightvertical = 0xfe3e;
  14252. t.dblarchinvertedbelowcmb = 0x032b;
  14253. t.dblarrowleft = 0x21d4;
  14254. t.dblarrowright = 0x21d2;
  14255. t.dbldanda = 0x0965;
  14256. t.dblgrave = 0xf6d6;
  14257. t.dblgravecmb = 0x030f;
  14258. t.dblintegral = 0x222c;
  14259. t.dbllowline = 0x2017;
  14260. t.dbllowlinecmb = 0x0333;
  14261. t.dbloverlinecmb = 0x033f;
  14262. t.dblprimemod = 0x02ba;
  14263. t.dblverticalbar = 0x2016;
  14264. t.dblverticallineabovecmb = 0x030e;
  14265. t.dbopomofo = 0x3109;
  14266. t.dbsquare = 0x33c8;
  14267. t.dcaron = 0x010f;
  14268. t.dcedilla = 0x1e11;
  14269. t.dcircle = 0x24d3;
  14270. t.dcircumflexbelow = 0x1e13;
  14271. t.dcroat = 0x0111;
  14272. t.ddabengali = 0x09a1;
  14273. t.ddadeva = 0x0921;
  14274. t.ddagujarati = 0x0aa1;
  14275. t.ddagurmukhi = 0x0a21;
  14276. t.ddalarabic = 0x0688;
  14277. t.ddalfinalarabic = 0xfb89;
  14278. t.dddhadeva = 0x095c;
  14279. t.ddhabengali = 0x09a2;
  14280. t.ddhadeva = 0x0922;
  14281. t.ddhagujarati = 0x0aa2;
  14282. t.ddhagurmukhi = 0x0a22;
  14283. t.ddotaccent = 0x1e0b;
  14284. t.ddotbelow = 0x1e0d;
  14285. t.decimalseparatorarabic = 0x066b;
  14286. t.decimalseparatorpersian = 0x066b;
  14287. t.decyrillic = 0x0434;
  14288. t.degree = 0x00b0;
  14289. t.dehihebrew = 0x05ad;
  14290. t.dehiragana = 0x3067;
  14291. t.deicoptic = 0x03ef;
  14292. t.dekatakana = 0x30c7;
  14293. t.deleteleft = 0x232b;
  14294. t.deleteright = 0x2326;
  14295. t.delta = 0x03b4;
  14296. t.deltaturned = 0x018d;
  14297. t.denominatorminusonenumeratorbengali = 0x09f8;
  14298. t.dezh = 0x02a4;
  14299. t.dhabengali = 0x09a7;
  14300. t.dhadeva = 0x0927;
  14301. t.dhagujarati = 0x0aa7;
  14302. t.dhagurmukhi = 0x0a27;
  14303. t.dhook = 0x0257;
  14304. t.dialytikatonos = 0x0385;
  14305. t.dialytikatonoscmb = 0x0344;
  14306. t.diamond = 0x2666;
  14307. t.diamondsuitwhite = 0x2662;
  14308. t.dieresis = 0x00a8;
  14309. t.dieresisacute = 0xf6d7;
  14310. t.dieresisbelowcmb = 0x0324;
  14311. t.dieresiscmb = 0x0308;
  14312. t.dieresisgrave = 0xf6d8;
  14313. t.dieresistonos = 0x0385;
  14314. t.dihiragana = 0x3062;
  14315. t.dikatakana = 0x30c2;
  14316. t.dittomark = 0x3003;
  14317. t.divide = 0x00f7;
  14318. t.divides = 0x2223;
  14319. t.divisionslash = 0x2215;
  14320. t.djecyrillic = 0x0452;
  14321. t.dkshade = 0x2593;
  14322. t.dlinebelow = 0x1e0f;
  14323. t.dlsquare = 0x3397;
  14324. t.dmacron = 0x0111;
  14325. t.dmonospace = 0xff44;
  14326. t.dnblock = 0x2584;
  14327. t.dochadathai = 0x0e0e;
  14328. t.dodekthai = 0x0e14;
  14329. t.dohiragana = 0x3069;
  14330. t.dokatakana = 0x30c9;
  14331. t.dollar = 0x0024;
  14332. t.dollarinferior = 0xf6e3;
  14333. t.dollarmonospace = 0xff04;
  14334. t.dollaroldstyle = 0xf724;
  14335. t.dollarsmall = 0xfe69;
  14336. t.dollarsuperior = 0xf6e4;
  14337. t.dong = 0x20ab;
  14338. t.dorusquare = 0x3326;
  14339. t.dotaccent = 0x02d9;
  14340. t.dotaccentcmb = 0x0307;
  14341. t.dotbelowcmb = 0x0323;
  14342. t.dotbelowcomb = 0x0323;
  14343. t.dotkatakana = 0x30fb;
  14344. t.dotlessi = 0x0131;
  14345. t.dotlessj = 0xf6be;
  14346. t.dotlessjstrokehook = 0x0284;
  14347. t.dotmath = 0x22c5;
  14348. t.dottedcircle = 0x25cc;
  14349. t.doubleyodpatah = 0xfb1f;
  14350. t.doubleyodpatahhebrew = 0xfb1f;
  14351. t.downtackbelowcmb = 0x031e;
  14352. t.downtackmod = 0x02d5;
  14353. t.dparen = 0x249f;
  14354. t.dsuperior = 0xf6eb;
  14355. t.dtail = 0x0256;
  14356. t.dtopbar = 0x018c;
  14357. t.duhiragana = 0x3065;
  14358. t.dukatakana = 0x30c5;
  14359. t.dz = 0x01f3;
  14360. t.dzaltone = 0x02a3;
  14361. t.dzcaron = 0x01c6;
  14362. t.dzcurl = 0x02a5;
  14363. t.dzeabkhasiancyrillic = 0x04e1;
  14364. t.dzecyrillic = 0x0455;
  14365. t.dzhecyrillic = 0x045f;
  14366. t.e = 0x0065;
  14367. t.eacute = 0x00e9;
  14368. t.earth = 0x2641;
  14369. t.ebengali = 0x098f;
  14370. t.ebopomofo = 0x311c;
  14371. t.ebreve = 0x0115;
  14372. t.ecandradeva = 0x090d;
  14373. t.ecandragujarati = 0x0a8d;
  14374. t.ecandravowelsigndeva = 0x0945;
  14375. t.ecandravowelsigngujarati = 0x0ac5;
  14376. t.ecaron = 0x011b;
  14377. t.ecedillabreve = 0x1e1d;
  14378. t.echarmenian = 0x0565;
  14379. t.echyiwnarmenian = 0x0587;
  14380. t.ecircle = 0x24d4;
  14381. t.ecircumflex = 0x00ea;
  14382. t.ecircumflexacute = 0x1ebf;
  14383. t.ecircumflexbelow = 0x1e19;
  14384. t.ecircumflexdotbelow = 0x1ec7;
  14385. t.ecircumflexgrave = 0x1ec1;
  14386. t.ecircumflexhookabove = 0x1ec3;
  14387. t.ecircumflextilde = 0x1ec5;
  14388. t.ecyrillic = 0x0454;
  14389. t.edblgrave = 0x0205;
  14390. t.edeva = 0x090f;
  14391. t.edieresis = 0x00eb;
  14392. t.edot = 0x0117;
  14393. t.edotaccent = 0x0117;
  14394. t.edotbelow = 0x1eb9;
  14395. t.eegurmukhi = 0x0a0f;
  14396. t.eematragurmukhi = 0x0a47;
  14397. t.efcyrillic = 0x0444;
  14398. t.egrave = 0x00e8;
  14399. t.egujarati = 0x0a8f;
  14400. t.eharmenian = 0x0567;
  14401. t.ehbopomofo = 0x311d;
  14402. t.ehiragana = 0x3048;
  14403. t.ehookabove = 0x1ebb;
  14404. t.eibopomofo = 0x311f;
  14405. t.eight = 0x0038;
  14406. t.eightarabic = 0x0668;
  14407. t.eightbengali = 0x09ee;
  14408. t.eightcircle = 0x2467;
  14409. t.eightcircleinversesansserif = 0x2791;
  14410. t.eightdeva = 0x096e;
  14411. t.eighteencircle = 0x2471;
  14412. t.eighteenparen = 0x2485;
  14413. t.eighteenperiod = 0x2499;
  14414. t.eightgujarati = 0x0aee;
  14415. t.eightgurmukhi = 0x0a6e;
  14416. t.eighthackarabic = 0x0668;
  14417. t.eighthangzhou = 0x3028;
  14418. t.eighthnotebeamed = 0x266b;
  14419. t.eightideographicparen = 0x3227;
  14420. t.eightinferior = 0x2088;
  14421. t.eightmonospace = 0xff18;
  14422. t.eightoldstyle = 0xf738;
  14423. t.eightparen = 0x247b;
  14424. t.eightperiod = 0x248f;
  14425. t.eightpersian = 0x06f8;
  14426. t.eightroman = 0x2177;
  14427. t.eightsuperior = 0x2078;
  14428. t.eightthai = 0x0e58;
  14429. t.einvertedbreve = 0x0207;
  14430. t.eiotifiedcyrillic = 0x0465;
  14431. t.ekatakana = 0x30a8;
  14432. t.ekatakanahalfwidth = 0xff74;
  14433. t.ekonkargurmukhi = 0x0a74;
  14434. t.ekorean = 0x3154;
  14435. t.elcyrillic = 0x043b;
  14436. t.element = 0x2208;
  14437. t.elevencircle = 0x246a;
  14438. t.elevenparen = 0x247e;
  14439. t.elevenperiod = 0x2492;
  14440. t.elevenroman = 0x217a;
  14441. t.ellipsis = 0x2026;
  14442. t.ellipsisvertical = 0x22ee;
  14443. t.emacron = 0x0113;
  14444. t.emacronacute = 0x1e17;
  14445. t.emacrongrave = 0x1e15;
  14446. t.emcyrillic = 0x043c;
  14447. t.emdash = 0x2014;
  14448. t.emdashvertical = 0xfe31;
  14449. t.emonospace = 0xff45;
  14450. t.emphasismarkarmenian = 0x055b;
  14451. t.emptyset = 0x2205;
  14452. t.enbopomofo = 0x3123;
  14453. t.encyrillic = 0x043d;
  14454. t.endash = 0x2013;
  14455. t.endashvertical = 0xfe32;
  14456. t.endescendercyrillic = 0x04a3;
  14457. t.eng = 0x014b;
  14458. t.engbopomofo = 0x3125;
  14459. t.enghecyrillic = 0x04a5;
  14460. t.enhookcyrillic = 0x04c8;
  14461. t.enspace = 0x2002;
  14462. t.eogonek = 0x0119;
  14463. t.eokorean = 0x3153;
  14464. t.eopen = 0x025b;
  14465. t.eopenclosed = 0x029a;
  14466. t.eopenreversed = 0x025c;
  14467. t.eopenreversedclosed = 0x025e;
  14468. t.eopenreversedhook = 0x025d;
  14469. t.eparen = 0x24a0;
  14470. t.epsilon = 0x03b5;
  14471. t.epsilontonos = 0x03ad;
  14472. t.equal = 0x003d;
  14473. t.equalmonospace = 0xff1d;
  14474. t.equalsmall = 0xfe66;
  14475. t.equalsuperior = 0x207c;
  14476. t.equivalence = 0x2261;
  14477. t.erbopomofo = 0x3126;
  14478. t.ercyrillic = 0x0440;
  14479. t.ereversed = 0x0258;
  14480. t.ereversedcyrillic = 0x044d;
  14481. t.escyrillic = 0x0441;
  14482. t.esdescendercyrillic = 0x04ab;
  14483. t.esh = 0x0283;
  14484. t.eshcurl = 0x0286;
  14485. t.eshortdeva = 0x090e;
  14486. t.eshortvowelsigndeva = 0x0946;
  14487. t.eshreversedloop = 0x01aa;
  14488. t.eshsquatreversed = 0x0285;
  14489. t.esmallhiragana = 0x3047;
  14490. t.esmallkatakana = 0x30a7;
  14491. t.esmallkatakanahalfwidth = 0xff6a;
  14492. t.estimated = 0x212e;
  14493. t.esuperior = 0xf6ec;
  14494. t.eta = 0x03b7;
  14495. t.etarmenian = 0x0568;
  14496. t.etatonos = 0x03ae;
  14497. t.eth = 0x00f0;
  14498. t.etilde = 0x1ebd;
  14499. t.etildebelow = 0x1e1b;
  14500. t.etnahtafoukhhebrew = 0x0591;
  14501. t.etnahtafoukhlefthebrew = 0x0591;
  14502. t.etnahtahebrew = 0x0591;
  14503. t.etnahtalefthebrew = 0x0591;
  14504. t.eturned = 0x01dd;
  14505. t.eukorean = 0x3161;
  14506. t.euro = 0x20ac;
  14507. t.evowelsignbengali = 0x09c7;
  14508. t.evowelsigndeva = 0x0947;
  14509. t.evowelsigngujarati = 0x0ac7;
  14510. t.exclam = 0x0021;
  14511. t.exclamarmenian = 0x055c;
  14512. t.exclamdbl = 0x203c;
  14513. t.exclamdown = 0x00a1;
  14514. t.exclamdownsmall = 0xf7a1;
  14515. t.exclammonospace = 0xff01;
  14516. t.exclamsmall = 0xf721;
  14517. t.existential = 0x2203;
  14518. t.ezh = 0x0292;
  14519. t.ezhcaron = 0x01ef;
  14520. t.ezhcurl = 0x0293;
  14521. t.ezhreversed = 0x01b9;
  14522. t.ezhtail = 0x01ba;
  14523. t.f = 0x0066;
  14524. t.fadeva = 0x095e;
  14525. t.fagurmukhi = 0x0a5e;
  14526. t.fahrenheit = 0x2109;
  14527. t.fathaarabic = 0x064e;
  14528. t.fathalowarabic = 0x064e;
  14529. t.fathatanarabic = 0x064b;
  14530. t.fbopomofo = 0x3108;
  14531. t.fcircle = 0x24d5;
  14532. t.fdotaccent = 0x1e1f;
  14533. t.feharabic = 0x0641;
  14534. t.feharmenian = 0x0586;
  14535. t.fehfinalarabic = 0xfed2;
  14536. t.fehinitialarabic = 0xfed3;
  14537. t.fehmedialarabic = 0xfed4;
  14538. t.feicoptic = 0x03e5;
  14539. t.female = 0x2640;
  14540. t.ff = 0xfb00;
  14541. t.f_f = 0xfb00;
  14542. t.ffi = 0xfb03;
  14543. t.f_f_i = 0xfb03;
  14544. t.ffl = 0xfb04;
  14545. t.f_f_l = 0xfb04;
  14546. t.fi = 0xfb01;
  14547. t.f_i = 0xfb01;
  14548. t.fifteencircle = 0x246e;
  14549. t.fifteenparen = 0x2482;
  14550. t.fifteenperiod = 0x2496;
  14551. t.figuredash = 0x2012;
  14552. t.filledbox = 0x25a0;
  14553. t.filledrect = 0x25ac;
  14554. t.finalkaf = 0x05da;
  14555. t.finalkafdagesh = 0xfb3a;
  14556. t.finalkafdageshhebrew = 0xfb3a;
  14557. t.finalkafhebrew = 0x05da;
  14558. t.finalmem = 0x05dd;
  14559. t.finalmemhebrew = 0x05dd;
  14560. t.finalnun = 0x05df;
  14561. t.finalnunhebrew = 0x05df;
  14562. t.finalpe = 0x05e3;
  14563. t.finalpehebrew = 0x05e3;
  14564. t.finaltsadi = 0x05e5;
  14565. t.finaltsadihebrew = 0x05e5;
  14566. t.firsttonechinese = 0x02c9;
  14567. t.fisheye = 0x25c9;
  14568. t.fitacyrillic = 0x0473;
  14569. t.five = 0x0035;
  14570. t.fivearabic = 0x0665;
  14571. t.fivebengali = 0x09eb;
  14572. t.fivecircle = 0x2464;
  14573. t.fivecircleinversesansserif = 0x278e;
  14574. t.fivedeva = 0x096b;
  14575. t.fiveeighths = 0x215d;
  14576. t.fivegujarati = 0x0aeb;
  14577. t.fivegurmukhi = 0x0a6b;
  14578. t.fivehackarabic = 0x0665;
  14579. t.fivehangzhou = 0x3025;
  14580. t.fiveideographicparen = 0x3224;
  14581. t.fiveinferior = 0x2085;
  14582. t.fivemonospace = 0xff15;
  14583. t.fiveoldstyle = 0xf735;
  14584. t.fiveparen = 0x2478;
  14585. t.fiveperiod = 0x248c;
  14586. t.fivepersian = 0x06f5;
  14587. t.fiveroman = 0x2174;
  14588. t.fivesuperior = 0x2075;
  14589. t.fivethai = 0x0e55;
  14590. t.fl = 0xfb02;
  14591. t.f_l = 0xfb02;
  14592. t.florin = 0x0192;
  14593. t.fmonospace = 0xff46;
  14594. t.fmsquare = 0x3399;
  14595. t.fofanthai = 0x0e1f;
  14596. t.fofathai = 0x0e1d;
  14597. t.fongmanthai = 0x0e4f;
  14598. t.forall = 0x2200;
  14599. t.four = 0x0034;
  14600. t.fourarabic = 0x0664;
  14601. t.fourbengali = 0x09ea;
  14602. t.fourcircle = 0x2463;
  14603. t.fourcircleinversesansserif = 0x278d;
  14604. t.fourdeva = 0x096a;
  14605. t.fourgujarati = 0x0aea;
  14606. t.fourgurmukhi = 0x0a6a;
  14607. t.fourhackarabic = 0x0664;
  14608. t.fourhangzhou = 0x3024;
  14609. t.fourideographicparen = 0x3223;
  14610. t.fourinferior = 0x2084;
  14611. t.fourmonospace = 0xff14;
  14612. t.fournumeratorbengali = 0x09f7;
  14613. t.fouroldstyle = 0xf734;
  14614. t.fourparen = 0x2477;
  14615. t.fourperiod = 0x248b;
  14616. t.fourpersian = 0x06f4;
  14617. t.fourroman = 0x2173;
  14618. t.foursuperior = 0x2074;
  14619. t.fourteencircle = 0x246d;
  14620. t.fourteenparen = 0x2481;
  14621. t.fourteenperiod = 0x2495;
  14622. t.fourthai = 0x0e54;
  14623. t.fourthtonechinese = 0x02cb;
  14624. t.fparen = 0x24a1;
  14625. t.fraction = 0x2044;
  14626. t.franc = 0x20a3;
  14627. t.g = 0x0067;
  14628. t.gabengali = 0x0997;
  14629. t.gacute = 0x01f5;
  14630. t.gadeva = 0x0917;
  14631. t.gafarabic = 0x06af;
  14632. t.gaffinalarabic = 0xfb93;
  14633. t.gafinitialarabic = 0xfb94;
  14634. t.gafmedialarabic = 0xfb95;
  14635. t.gagujarati = 0x0a97;
  14636. t.gagurmukhi = 0x0a17;
  14637. t.gahiragana = 0x304c;
  14638. t.gakatakana = 0x30ac;
  14639. t.gamma = 0x03b3;
  14640. t.gammalatinsmall = 0x0263;
  14641. t.gammasuperior = 0x02e0;
  14642. t.gangiacoptic = 0x03eb;
  14643. t.gbopomofo = 0x310d;
  14644. t.gbreve = 0x011f;
  14645. t.gcaron = 0x01e7;
  14646. t.gcedilla = 0x0123;
  14647. t.gcircle = 0x24d6;
  14648. t.gcircumflex = 0x011d;
  14649. t.gcommaaccent = 0x0123;
  14650. t.gdot = 0x0121;
  14651. t.gdotaccent = 0x0121;
  14652. t.gecyrillic = 0x0433;
  14653. t.gehiragana = 0x3052;
  14654. t.gekatakana = 0x30b2;
  14655. t.geometricallyequal = 0x2251;
  14656. t.gereshaccenthebrew = 0x059c;
  14657. t.gereshhebrew = 0x05f3;
  14658. t.gereshmuqdamhebrew = 0x059d;
  14659. t.germandbls = 0x00df;
  14660. t.gershayimaccenthebrew = 0x059e;
  14661. t.gershayimhebrew = 0x05f4;
  14662. t.getamark = 0x3013;
  14663. t.ghabengali = 0x0998;
  14664. t.ghadarmenian = 0x0572;
  14665. t.ghadeva = 0x0918;
  14666. t.ghagujarati = 0x0a98;
  14667. t.ghagurmukhi = 0x0a18;
  14668. t.ghainarabic = 0x063a;
  14669. t.ghainfinalarabic = 0xfece;
  14670. t.ghaininitialarabic = 0xfecf;
  14671. t.ghainmedialarabic = 0xfed0;
  14672. t.ghemiddlehookcyrillic = 0x0495;
  14673. t.ghestrokecyrillic = 0x0493;
  14674. t.gheupturncyrillic = 0x0491;
  14675. t.ghhadeva = 0x095a;
  14676. t.ghhagurmukhi = 0x0a5a;
  14677. t.ghook = 0x0260;
  14678. t.ghzsquare = 0x3393;
  14679. t.gihiragana = 0x304e;
  14680. t.gikatakana = 0x30ae;
  14681. t.gimarmenian = 0x0563;
  14682. t.gimel = 0x05d2;
  14683. t.gimeldagesh = 0xfb32;
  14684. t.gimeldageshhebrew = 0xfb32;
  14685. t.gimelhebrew = 0x05d2;
  14686. t.gjecyrillic = 0x0453;
  14687. t.glottalinvertedstroke = 0x01be;
  14688. t.glottalstop = 0x0294;
  14689. t.glottalstopinverted = 0x0296;
  14690. t.glottalstopmod = 0x02c0;
  14691. t.glottalstopreversed = 0x0295;
  14692. t.glottalstopreversedmod = 0x02c1;
  14693. t.glottalstopreversedsuperior = 0x02e4;
  14694. t.glottalstopstroke = 0x02a1;
  14695. t.glottalstopstrokereversed = 0x02a2;
  14696. t.gmacron = 0x1e21;
  14697. t.gmonospace = 0xff47;
  14698. t.gohiragana = 0x3054;
  14699. t.gokatakana = 0x30b4;
  14700. t.gparen = 0x24a2;
  14701. t.gpasquare = 0x33ac;
  14702. t.gradient = 0x2207;
  14703. t.grave = 0x0060;
  14704. t.gravebelowcmb = 0x0316;
  14705. t.gravecmb = 0x0300;
  14706. t.gravecomb = 0x0300;
  14707. t.gravedeva = 0x0953;
  14708. t.gravelowmod = 0x02ce;
  14709. t.gravemonospace = 0xff40;
  14710. t.gravetonecmb = 0x0340;
  14711. t.greater = 0x003e;
  14712. t.greaterequal = 0x2265;
  14713. t.greaterequalorless = 0x22db;
  14714. t.greatermonospace = 0xff1e;
  14715. t.greaterorequivalent = 0x2273;
  14716. t.greaterorless = 0x2277;
  14717. t.greateroverequal = 0x2267;
  14718. t.greatersmall = 0xfe65;
  14719. t.gscript = 0x0261;
  14720. t.gstroke = 0x01e5;
  14721. t.guhiragana = 0x3050;
  14722. t.guillemotleft = 0x00ab;
  14723. t.guillemotright = 0x00bb;
  14724. t.guilsinglleft = 0x2039;
  14725. t.guilsinglright = 0x203a;
  14726. t.gukatakana = 0x30b0;
  14727. t.guramusquare = 0x3318;
  14728. t.gysquare = 0x33c9;
  14729. t.h = 0x0068;
  14730. t.haabkhasiancyrillic = 0x04a9;
  14731. t.haaltonearabic = 0x06c1;
  14732. t.habengali = 0x09b9;
  14733. t.hadescendercyrillic = 0x04b3;
  14734. t.hadeva = 0x0939;
  14735. t.hagujarati = 0x0ab9;
  14736. t.hagurmukhi = 0x0a39;
  14737. t.haharabic = 0x062d;
  14738. t.hahfinalarabic = 0xfea2;
  14739. t.hahinitialarabic = 0xfea3;
  14740. t.hahiragana = 0x306f;
  14741. t.hahmedialarabic = 0xfea4;
  14742. t.haitusquare = 0x332a;
  14743. t.hakatakana = 0x30cf;
  14744. t.hakatakanahalfwidth = 0xff8a;
  14745. t.halantgurmukhi = 0x0a4d;
  14746. t.hamzaarabic = 0x0621;
  14747. t.hamzalowarabic = 0x0621;
  14748. t.hangulfiller = 0x3164;
  14749. t.hardsigncyrillic = 0x044a;
  14750. t.harpoonleftbarbup = 0x21bc;
  14751. t.harpoonrightbarbup = 0x21c0;
  14752. t.hasquare = 0x33ca;
  14753. t.hatafpatah = 0x05b2;
  14754. t.hatafpatah16 = 0x05b2;
  14755. t.hatafpatah23 = 0x05b2;
  14756. t.hatafpatah2f = 0x05b2;
  14757. t.hatafpatahhebrew = 0x05b2;
  14758. t.hatafpatahnarrowhebrew = 0x05b2;
  14759. t.hatafpatahquarterhebrew = 0x05b2;
  14760. t.hatafpatahwidehebrew = 0x05b2;
  14761. t.hatafqamats = 0x05b3;
  14762. t.hatafqamats1b = 0x05b3;
  14763. t.hatafqamats28 = 0x05b3;
  14764. t.hatafqamats34 = 0x05b3;
  14765. t.hatafqamatshebrew = 0x05b3;
  14766. t.hatafqamatsnarrowhebrew = 0x05b3;
  14767. t.hatafqamatsquarterhebrew = 0x05b3;
  14768. t.hatafqamatswidehebrew = 0x05b3;
  14769. t.hatafsegol = 0x05b1;
  14770. t.hatafsegol17 = 0x05b1;
  14771. t.hatafsegol24 = 0x05b1;
  14772. t.hatafsegol30 = 0x05b1;
  14773. t.hatafsegolhebrew = 0x05b1;
  14774. t.hatafsegolnarrowhebrew = 0x05b1;
  14775. t.hatafsegolquarterhebrew = 0x05b1;
  14776. t.hatafsegolwidehebrew = 0x05b1;
  14777. t.hbar = 0x0127;
  14778. t.hbopomofo = 0x310f;
  14779. t.hbrevebelow = 0x1e2b;
  14780. t.hcedilla = 0x1e29;
  14781. t.hcircle = 0x24d7;
  14782. t.hcircumflex = 0x0125;
  14783. t.hdieresis = 0x1e27;
  14784. t.hdotaccent = 0x1e23;
  14785. t.hdotbelow = 0x1e25;
  14786. t.he = 0x05d4;
  14787. t.heart = 0x2665;
  14788. t.heartsuitblack = 0x2665;
  14789. t.heartsuitwhite = 0x2661;
  14790. t.hedagesh = 0xfb34;
  14791. t.hedageshhebrew = 0xfb34;
  14792. t.hehaltonearabic = 0x06c1;
  14793. t.heharabic = 0x0647;
  14794. t.hehebrew = 0x05d4;
  14795. t.hehfinalaltonearabic = 0xfba7;
  14796. t.hehfinalalttwoarabic = 0xfeea;
  14797. t.hehfinalarabic = 0xfeea;
  14798. t.hehhamzaabovefinalarabic = 0xfba5;
  14799. t.hehhamzaaboveisolatedarabic = 0xfba4;
  14800. t.hehinitialaltonearabic = 0xfba8;
  14801. t.hehinitialarabic = 0xfeeb;
  14802. t.hehiragana = 0x3078;
  14803. t.hehmedialaltonearabic = 0xfba9;
  14804. t.hehmedialarabic = 0xfeec;
  14805. t.heiseierasquare = 0x337b;
  14806. t.hekatakana = 0x30d8;
  14807. t.hekatakanahalfwidth = 0xff8d;
  14808. t.hekutaarusquare = 0x3336;
  14809. t.henghook = 0x0267;
  14810. t.herutusquare = 0x3339;
  14811. t.het = 0x05d7;
  14812. t.hethebrew = 0x05d7;
  14813. t.hhook = 0x0266;
  14814. t.hhooksuperior = 0x02b1;
  14815. t.hieuhacirclekorean = 0x327b;
  14816. t.hieuhaparenkorean = 0x321b;
  14817. t.hieuhcirclekorean = 0x326d;
  14818. t.hieuhkorean = 0x314e;
  14819. t.hieuhparenkorean = 0x320d;
  14820. t.hihiragana = 0x3072;
  14821. t.hikatakana = 0x30d2;
  14822. t.hikatakanahalfwidth = 0xff8b;
  14823. t.hiriq = 0x05b4;
  14824. t.hiriq14 = 0x05b4;
  14825. t.hiriq21 = 0x05b4;
  14826. t.hiriq2d = 0x05b4;
  14827. t.hiriqhebrew = 0x05b4;
  14828. t.hiriqnarrowhebrew = 0x05b4;
  14829. t.hiriqquarterhebrew = 0x05b4;
  14830. t.hiriqwidehebrew = 0x05b4;
  14831. t.hlinebelow = 0x1e96;
  14832. t.hmonospace = 0xff48;
  14833. t.hoarmenian = 0x0570;
  14834. t.hohipthai = 0x0e2b;
  14835. t.hohiragana = 0x307b;
  14836. t.hokatakana = 0x30db;
  14837. t.hokatakanahalfwidth = 0xff8e;
  14838. t.holam = 0x05b9;
  14839. t.holam19 = 0x05b9;
  14840. t.holam26 = 0x05b9;
  14841. t.holam32 = 0x05b9;
  14842. t.holamhebrew = 0x05b9;
  14843. t.holamnarrowhebrew = 0x05b9;
  14844. t.holamquarterhebrew = 0x05b9;
  14845. t.holamwidehebrew = 0x05b9;
  14846. t.honokhukthai = 0x0e2e;
  14847. t.hookabovecomb = 0x0309;
  14848. t.hookcmb = 0x0309;
  14849. t.hookpalatalizedbelowcmb = 0x0321;
  14850. t.hookretroflexbelowcmb = 0x0322;
  14851. t.hoonsquare = 0x3342;
  14852. t.horicoptic = 0x03e9;
  14853. t.horizontalbar = 0x2015;
  14854. t.horncmb = 0x031b;
  14855. t.hotsprings = 0x2668;
  14856. t.house = 0x2302;
  14857. t.hparen = 0x24a3;
  14858. t.hsuperior = 0x02b0;
  14859. t.hturned = 0x0265;
  14860. t.huhiragana = 0x3075;
  14861. t.huiitosquare = 0x3333;
  14862. t.hukatakana = 0x30d5;
  14863. t.hukatakanahalfwidth = 0xff8c;
  14864. t.hungarumlaut = 0x02dd;
  14865. t.hungarumlautcmb = 0x030b;
  14866. t.hv = 0x0195;
  14867. t.hyphen = 0x002d;
  14868. t.hypheninferior = 0xf6e5;
  14869. t.hyphenmonospace = 0xff0d;
  14870. t.hyphensmall = 0xfe63;
  14871. t.hyphensuperior = 0xf6e6;
  14872. t.hyphentwo = 0x2010;
  14873. t.i = 0x0069;
  14874. t.iacute = 0x00ed;
  14875. t.iacyrillic = 0x044f;
  14876. t.ibengali = 0x0987;
  14877. t.ibopomofo = 0x3127;
  14878. t.ibreve = 0x012d;
  14879. t.icaron = 0x01d0;
  14880. t.icircle = 0x24d8;
  14881. t.icircumflex = 0x00ee;
  14882. t.icyrillic = 0x0456;
  14883. t.idblgrave = 0x0209;
  14884. t.ideographearthcircle = 0x328f;
  14885. t.ideographfirecircle = 0x328b;
  14886. t.ideographicallianceparen = 0x323f;
  14887. t.ideographiccallparen = 0x323a;
  14888. t.ideographiccentrecircle = 0x32a5;
  14889. t.ideographicclose = 0x3006;
  14890. t.ideographiccomma = 0x3001;
  14891. t.ideographiccommaleft = 0xff64;
  14892. t.ideographiccongratulationparen = 0x3237;
  14893. t.ideographiccorrectcircle = 0x32a3;
  14894. t.ideographicearthparen = 0x322f;
  14895. t.ideographicenterpriseparen = 0x323d;
  14896. t.ideographicexcellentcircle = 0x329d;
  14897. t.ideographicfestivalparen = 0x3240;
  14898. t.ideographicfinancialcircle = 0x3296;
  14899. t.ideographicfinancialparen = 0x3236;
  14900. t.ideographicfireparen = 0x322b;
  14901. t.ideographichaveparen = 0x3232;
  14902. t.ideographichighcircle = 0x32a4;
  14903. t.ideographiciterationmark = 0x3005;
  14904. t.ideographiclaborcircle = 0x3298;
  14905. t.ideographiclaborparen = 0x3238;
  14906. t.ideographicleftcircle = 0x32a7;
  14907. t.ideographiclowcircle = 0x32a6;
  14908. t.ideographicmedicinecircle = 0x32a9;
  14909. t.ideographicmetalparen = 0x322e;
  14910. t.ideographicmoonparen = 0x322a;
  14911. t.ideographicnameparen = 0x3234;
  14912. t.ideographicperiod = 0x3002;
  14913. t.ideographicprintcircle = 0x329e;
  14914. t.ideographicreachparen = 0x3243;
  14915. t.ideographicrepresentparen = 0x3239;
  14916. t.ideographicresourceparen = 0x323e;
  14917. t.ideographicrightcircle = 0x32a8;
  14918. t.ideographicsecretcircle = 0x3299;
  14919. t.ideographicselfparen = 0x3242;
  14920. t.ideographicsocietyparen = 0x3233;
  14921. t.ideographicspace = 0x3000;
  14922. t.ideographicspecialparen = 0x3235;
  14923. t.ideographicstockparen = 0x3231;
  14924. t.ideographicstudyparen = 0x323b;
  14925. t.ideographicsunparen = 0x3230;
  14926. t.ideographicsuperviseparen = 0x323c;
  14927. t.ideographicwaterparen = 0x322c;
  14928. t.ideographicwoodparen = 0x322d;
  14929. t.ideographiczero = 0x3007;
  14930. t.ideographmetalcircle = 0x328e;
  14931. t.ideographmooncircle = 0x328a;
  14932. t.ideographnamecircle = 0x3294;
  14933. t.ideographsuncircle = 0x3290;
  14934. t.ideographwatercircle = 0x328c;
  14935. t.ideographwoodcircle = 0x328d;
  14936. t.ideva = 0x0907;
  14937. t.idieresis = 0x00ef;
  14938. t.idieresisacute = 0x1e2f;
  14939. t.idieresiscyrillic = 0x04e5;
  14940. t.idotbelow = 0x1ecb;
  14941. t.iebrevecyrillic = 0x04d7;
  14942. t.iecyrillic = 0x0435;
  14943. t.ieungacirclekorean = 0x3275;
  14944. t.ieungaparenkorean = 0x3215;
  14945. t.ieungcirclekorean = 0x3267;
  14946. t.ieungkorean = 0x3147;
  14947. t.ieungparenkorean = 0x3207;
  14948. t.igrave = 0x00ec;
  14949. t.igujarati = 0x0a87;
  14950. t.igurmukhi = 0x0a07;
  14951. t.ihiragana = 0x3044;
  14952. t.ihookabove = 0x1ec9;
  14953. t.iibengali = 0x0988;
  14954. t.iicyrillic = 0x0438;
  14955. t.iideva = 0x0908;
  14956. t.iigujarati = 0x0a88;
  14957. t.iigurmukhi = 0x0a08;
  14958. t.iimatragurmukhi = 0x0a40;
  14959. t.iinvertedbreve = 0x020b;
  14960. t.iishortcyrillic = 0x0439;
  14961. t.iivowelsignbengali = 0x09c0;
  14962. t.iivowelsigndeva = 0x0940;
  14963. t.iivowelsigngujarati = 0x0ac0;
  14964. t.ij = 0x0133;
  14965. t.ikatakana = 0x30a4;
  14966. t.ikatakanahalfwidth = 0xff72;
  14967. t.ikorean = 0x3163;
  14968. t.ilde = 0x02dc;
  14969. t.iluyhebrew = 0x05ac;
  14970. t.imacron = 0x012b;
  14971. t.imacroncyrillic = 0x04e3;
  14972. t.imageorapproximatelyequal = 0x2253;
  14973. t.imatragurmukhi = 0x0a3f;
  14974. t.imonospace = 0xff49;
  14975. t.increment = 0x2206;
  14976. t.infinity = 0x221e;
  14977. t.iniarmenian = 0x056b;
  14978. t.integral = 0x222b;
  14979. t.integralbottom = 0x2321;
  14980. t.integralbt = 0x2321;
  14981. t.integralex = 0xf8f5;
  14982. t.integraltop = 0x2320;
  14983. t.integraltp = 0x2320;
  14984. t.intersection = 0x2229;
  14985. t.intisquare = 0x3305;
  14986. t.invbullet = 0x25d8;
  14987. t.invcircle = 0x25d9;
  14988. t.invsmileface = 0x263b;
  14989. t.iocyrillic = 0x0451;
  14990. t.iogonek = 0x012f;
  14991. t.iota = 0x03b9;
  14992. t.iotadieresis = 0x03ca;
  14993. t.iotadieresistonos = 0x0390;
  14994. t.iotalatin = 0x0269;
  14995. t.iotatonos = 0x03af;
  14996. t.iparen = 0x24a4;
  14997. t.irigurmukhi = 0x0a72;
  14998. t.ismallhiragana = 0x3043;
  14999. t.ismallkatakana = 0x30a3;
  15000. t.ismallkatakanahalfwidth = 0xff68;
  15001. t.issharbengali = 0x09fa;
  15002. t.istroke = 0x0268;
  15003. t.isuperior = 0xf6ed;
  15004. t.iterationhiragana = 0x309d;
  15005. t.iterationkatakana = 0x30fd;
  15006. t.itilde = 0x0129;
  15007. t.itildebelow = 0x1e2d;
  15008. t.iubopomofo = 0x3129;
  15009. t.iucyrillic = 0x044e;
  15010. t.ivowelsignbengali = 0x09bf;
  15011. t.ivowelsigndeva = 0x093f;
  15012. t.ivowelsigngujarati = 0x0abf;
  15013. t.izhitsacyrillic = 0x0475;
  15014. t.izhitsadblgravecyrillic = 0x0477;
  15015. t.j = 0x006a;
  15016. t.jaarmenian = 0x0571;
  15017. t.jabengali = 0x099c;
  15018. t.jadeva = 0x091c;
  15019. t.jagujarati = 0x0a9c;
  15020. t.jagurmukhi = 0x0a1c;
  15021. t.jbopomofo = 0x3110;
  15022. t.jcaron = 0x01f0;
  15023. t.jcircle = 0x24d9;
  15024. t.jcircumflex = 0x0135;
  15025. t.jcrossedtail = 0x029d;
  15026. t.jdotlessstroke = 0x025f;
  15027. t.jecyrillic = 0x0458;
  15028. t.jeemarabic = 0x062c;
  15029. t.jeemfinalarabic = 0xfe9e;
  15030. t.jeeminitialarabic = 0xfe9f;
  15031. t.jeemmedialarabic = 0xfea0;
  15032. t.jeharabic = 0x0698;
  15033. t.jehfinalarabic = 0xfb8b;
  15034. t.jhabengali = 0x099d;
  15035. t.jhadeva = 0x091d;
  15036. t.jhagujarati = 0x0a9d;
  15037. t.jhagurmukhi = 0x0a1d;
  15038. t.jheharmenian = 0x057b;
  15039. t.jis = 0x3004;
  15040. t.jmonospace = 0xff4a;
  15041. t.jparen = 0x24a5;
  15042. t.jsuperior = 0x02b2;
  15043. t.k = 0x006b;
  15044. t.kabashkircyrillic = 0x04a1;
  15045. t.kabengali = 0x0995;
  15046. t.kacute = 0x1e31;
  15047. t.kacyrillic = 0x043a;
  15048. t.kadescendercyrillic = 0x049b;
  15049. t.kadeva = 0x0915;
  15050. t.kaf = 0x05db;
  15051. t.kafarabic = 0x0643;
  15052. t.kafdagesh = 0xfb3b;
  15053. t.kafdageshhebrew = 0xfb3b;
  15054. t.kaffinalarabic = 0xfeda;
  15055. t.kafhebrew = 0x05db;
  15056. t.kafinitialarabic = 0xfedb;
  15057. t.kafmedialarabic = 0xfedc;
  15058. t.kafrafehebrew = 0xfb4d;
  15059. t.kagujarati = 0x0a95;
  15060. t.kagurmukhi = 0x0a15;
  15061. t.kahiragana = 0x304b;
  15062. t.kahookcyrillic = 0x04c4;
  15063. t.kakatakana = 0x30ab;
  15064. t.kakatakanahalfwidth = 0xff76;
  15065. t.kappa = 0x03ba;
  15066. t.kappasymbolgreek = 0x03f0;
  15067. t.kapyeounmieumkorean = 0x3171;
  15068. t.kapyeounphieuphkorean = 0x3184;
  15069. t.kapyeounpieupkorean = 0x3178;
  15070. t.kapyeounssangpieupkorean = 0x3179;
  15071. t.karoriisquare = 0x330d;
  15072. t.kashidaautoarabic = 0x0640;
  15073. t.kashidaautonosidebearingarabic = 0x0640;
  15074. t.kasmallkatakana = 0x30f5;
  15075. t.kasquare = 0x3384;
  15076. t.kasraarabic = 0x0650;
  15077. t.kasratanarabic = 0x064d;
  15078. t.kastrokecyrillic = 0x049f;
  15079. t.katahiraprolongmarkhalfwidth = 0xff70;
  15080. t.kaverticalstrokecyrillic = 0x049d;
  15081. t.kbopomofo = 0x310e;
  15082. t.kcalsquare = 0x3389;
  15083. t.kcaron = 0x01e9;
  15084. t.kcedilla = 0x0137;
  15085. t.kcircle = 0x24da;
  15086. t.kcommaaccent = 0x0137;
  15087. t.kdotbelow = 0x1e33;
  15088. t.keharmenian = 0x0584;
  15089. t.kehiragana = 0x3051;
  15090. t.kekatakana = 0x30b1;
  15091. t.kekatakanahalfwidth = 0xff79;
  15092. t.kenarmenian = 0x056f;
  15093. t.kesmallkatakana = 0x30f6;
  15094. t.kgreenlandic = 0x0138;
  15095. t.khabengali = 0x0996;
  15096. t.khacyrillic = 0x0445;
  15097. t.khadeva = 0x0916;
  15098. t.khagujarati = 0x0a96;
  15099. t.khagurmukhi = 0x0a16;
  15100. t.khaharabic = 0x062e;
  15101. t.khahfinalarabic = 0xfea6;
  15102. t.khahinitialarabic = 0xfea7;
  15103. t.khahmedialarabic = 0xfea8;
  15104. t.kheicoptic = 0x03e7;
  15105. t.khhadeva = 0x0959;
  15106. t.khhagurmukhi = 0x0a59;
  15107. t.khieukhacirclekorean = 0x3278;
  15108. t.khieukhaparenkorean = 0x3218;
  15109. t.khieukhcirclekorean = 0x326a;
  15110. t.khieukhkorean = 0x314b;
  15111. t.khieukhparenkorean = 0x320a;
  15112. t.khokhaithai = 0x0e02;
  15113. t.khokhonthai = 0x0e05;
  15114. t.khokhuatthai = 0x0e03;
  15115. t.khokhwaithai = 0x0e04;
  15116. t.khomutthai = 0x0e5b;
  15117. t.khook = 0x0199;
  15118. t.khorakhangthai = 0x0e06;
  15119. t.khzsquare = 0x3391;
  15120. t.kihiragana = 0x304d;
  15121. t.kikatakana = 0x30ad;
  15122. t.kikatakanahalfwidth = 0xff77;
  15123. t.kiroguramusquare = 0x3315;
  15124. t.kiromeetorusquare = 0x3316;
  15125. t.kirosquare = 0x3314;
  15126. t.kiyeokacirclekorean = 0x326e;
  15127. t.kiyeokaparenkorean = 0x320e;
  15128. t.kiyeokcirclekorean = 0x3260;
  15129. t.kiyeokkorean = 0x3131;
  15130. t.kiyeokparenkorean = 0x3200;
  15131. t.kiyeoksioskorean = 0x3133;
  15132. t.kjecyrillic = 0x045c;
  15133. t.klinebelow = 0x1e35;
  15134. t.klsquare = 0x3398;
  15135. t.kmcubedsquare = 0x33a6;
  15136. t.kmonospace = 0xff4b;
  15137. t.kmsquaredsquare = 0x33a2;
  15138. t.kohiragana = 0x3053;
  15139. t.kohmsquare = 0x33c0;
  15140. t.kokaithai = 0x0e01;
  15141. t.kokatakana = 0x30b3;
  15142. t.kokatakanahalfwidth = 0xff7a;
  15143. t.kooposquare = 0x331e;
  15144. t.koppacyrillic = 0x0481;
  15145. t.koreanstandardsymbol = 0x327f;
  15146. t.koroniscmb = 0x0343;
  15147. t.kparen = 0x24a6;
  15148. t.kpasquare = 0x33aa;
  15149. t.ksicyrillic = 0x046f;
  15150. t.ktsquare = 0x33cf;
  15151. t.kturned = 0x029e;
  15152. t.kuhiragana = 0x304f;
  15153. t.kukatakana = 0x30af;
  15154. t.kukatakanahalfwidth = 0xff78;
  15155. t.kvsquare = 0x33b8;
  15156. t.kwsquare = 0x33be;
  15157. t.l = 0x006c;
  15158. t.labengali = 0x09b2;
  15159. t.lacute = 0x013a;
  15160. t.ladeva = 0x0932;
  15161. t.lagujarati = 0x0ab2;
  15162. t.lagurmukhi = 0x0a32;
  15163. t.lakkhangyaothai = 0x0e45;
  15164. t.lamaleffinalarabic = 0xfefc;
  15165. t.lamalefhamzaabovefinalarabic = 0xfef8;
  15166. t.lamalefhamzaaboveisolatedarabic = 0xfef7;
  15167. t.lamalefhamzabelowfinalarabic = 0xfefa;
  15168. t.lamalefhamzabelowisolatedarabic = 0xfef9;
  15169. t.lamalefisolatedarabic = 0xfefb;
  15170. t.lamalefmaddaabovefinalarabic = 0xfef6;
  15171. t.lamalefmaddaaboveisolatedarabic = 0xfef5;
  15172. t.lamarabic = 0x0644;
  15173. t.lambda = 0x03bb;
  15174. t.lambdastroke = 0x019b;
  15175. t.lamed = 0x05dc;
  15176. t.lameddagesh = 0xfb3c;
  15177. t.lameddageshhebrew = 0xfb3c;
  15178. t.lamedhebrew = 0x05dc;
  15179. t.lamfinalarabic = 0xfede;
  15180. t.lamhahinitialarabic = 0xfcca;
  15181. t.laminitialarabic = 0xfedf;
  15182. t.lamjeeminitialarabic = 0xfcc9;
  15183. t.lamkhahinitialarabic = 0xfccb;
  15184. t.lamlamhehisolatedarabic = 0xfdf2;
  15185. t.lammedialarabic = 0xfee0;
  15186. t.lammeemhahinitialarabic = 0xfd88;
  15187. t.lammeeminitialarabic = 0xfccc;
  15188. t.largecircle = 0x25ef;
  15189. t.lbar = 0x019a;
  15190. t.lbelt = 0x026c;
  15191. t.lbopomofo = 0x310c;
  15192. t.lcaron = 0x013e;
  15193. t.lcedilla = 0x013c;
  15194. t.lcircle = 0x24db;
  15195. t.lcircumflexbelow = 0x1e3d;
  15196. t.lcommaaccent = 0x013c;
  15197. t.ldot = 0x0140;
  15198. t.ldotaccent = 0x0140;
  15199. t.ldotbelow = 0x1e37;
  15200. t.ldotbelowmacron = 0x1e39;
  15201. t.leftangleabovecmb = 0x031a;
  15202. t.lefttackbelowcmb = 0x0318;
  15203. t.less = 0x003c;
  15204. t.lessequal = 0x2264;
  15205. t.lessequalorgreater = 0x22da;
  15206. t.lessmonospace = 0xff1c;
  15207. t.lessorequivalent = 0x2272;
  15208. t.lessorgreater = 0x2276;
  15209. t.lessoverequal = 0x2266;
  15210. t.lesssmall = 0xfe64;
  15211. t.lezh = 0x026e;
  15212. t.lfblock = 0x258c;
  15213. t.lhookretroflex = 0x026d;
  15214. t.lira = 0x20a4;
  15215. t.liwnarmenian = 0x056c;
  15216. t.lj = 0x01c9;
  15217. t.ljecyrillic = 0x0459;
  15218. t.ll = 0xf6c0;
  15219. t.lladeva = 0x0933;
  15220. t.llagujarati = 0x0ab3;
  15221. t.llinebelow = 0x1e3b;
  15222. t.llladeva = 0x0934;
  15223. t.llvocalicbengali = 0x09e1;
  15224. t.llvocalicdeva = 0x0961;
  15225. t.llvocalicvowelsignbengali = 0x09e3;
  15226. t.llvocalicvowelsigndeva = 0x0963;
  15227. t.lmiddletilde = 0x026b;
  15228. t.lmonospace = 0xff4c;
  15229. t.lmsquare = 0x33d0;
  15230. t.lochulathai = 0x0e2c;
  15231. t.logicaland = 0x2227;
  15232. t.logicalnot = 0x00ac;
  15233. t.logicalnotreversed = 0x2310;
  15234. t.logicalor = 0x2228;
  15235. t.lolingthai = 0x0e25;
  15236. t.longs = 0x017f;
  15237. t.lowlinecenterline = 0xfe4e;
  15238. t.lowlinecmb = 0x0332;
  15239. t.lowlinedashed = 0xfe4d;
  15240. t.lozenge = 0x25ca;
  15241. t.lparen = 0x24a7;
  15242. t.lslash = 0x0142;
  15243. t.lsquare = 0x2113;
  15244. t.lsuperior = 0xf6ee;
  15245. t.ltshade = 0x2591;
  15246. t.luthai = 0x0e26;
  15247. t.lvocalicbengali = 0x098c;
  15248. t.lvocalicdeva = 0x090c;
  15249. t.lvocalicvowelsignbengali = 0x09e2;
  15250. t.lvocalicvowelsigndeva = 0x0962;
  15251. t.lxsquare = 0x33d3;
  15252. t.m = 0x006d;
  15253. t.mabengali = 0x09ae;
  15254. t.macron = 0x00af;
  15255. t.macronbelowcmb = 0x0331;
  15256. t.macroncmb = 0x0304;
  15257. t.macronlowmod = 0x02cd;
  15258. t.macronmonospace = 0xffe3;
  15259. t.macute = 0x1e3f;
  15260. t.madeva = 0x092e;
  15261. t.magujarati = 0x0aae;
  15262. t.magurmukhi = 0x0a2e;
  15263. t.mahapakhhebrew = 0x05a4;
  15264. t.mahapakhlefthebrew = 0x05a4;
  15265. t.mahiragana = 0x307e;
  15266. t.maichattawalowleftthai = 0xf895;
  15267. t.maichattawalowrightthai = 0xf894;
  15268. t.maichattawathai = 0x0e4b;
  15269. t.maichattawaupperleftthai = 0xf893;
  15270. t.maieklowleftthai = 0xf88c;
  15271. t.maieklowrightthai = 0xf88b;
  15272. t.maiekthai = 0x0e48;
  15273. t.maiekupperleftthai = 0xf88a;
  15274. t.maihanakatleftthai = 0xf884;
  15275. t.maihanakatthai = 0x0e31;
  15276. t.maitaikhuleftthai = 0xf889;
  15277. t.maitaikhuthai = 0x0e47;
  15278. t.maitholowleftthai = 0xf88f;
  15279. t.maitholowrightthai = 0xf88e;
  15280. t.maithothai = 0x0e49;
  15281. t.maithoupperleftthai = 0xf88d;
  15282. t.maitrilowleftthai = 0xf892;
  15283. t.maitrilowrightthai = 0xf891;
  15284. t.maitrithai = 0x0e4a;
  15285. t.maitriupperleftthai = 0xf890;
  15286. t.maiyamokthai = 0x0e46;
  15287. t.makatakana = 0x30de;
  15288. t.makatakanahalfwidth = 0xff8f;
  15289. t.male = 0x2642;
  15290. t.mansyonsquare = 0x3347;
  15291. t.maqafhebrew = 0x05be;
  15292. t.mars = 0x2642;
  15293. t.masoracirclehebrew = 0x05af;
  15294. t.masquare = 0x3383;
  15295. t.mbopomofo = 0x3107;
  15296. t.mbsquare = 0x33d4;
  15297. t.mcircle = 0x24dc;
  15298. t.mcubedsquare = 0x33a5;
  15299. t.mdotaccent = 0x1e41;
  15300. t.mdotbelow = 0x1e43;
  15301. t.meemarabic = 0x0645;
  15302. t.meemfinalarabic = 0xfee2;
  15303. t.meeminitialarabic = 0xfee3;
  15304. t.meemmedialarabic = 0xfee4;
  15305. t.meemmeeminitialarabic = 0xfcd1;
  15306. t.meemmeemisolatedarabic = 0xfc48;
  15307. t.meetorusquare = 0x334d;
  15308. t.mehiragana = 0x3081;
  15309. t.meizierasquare = 0x337e;
  15310. t.mekatakana = 0x30e1;
  15311. t.mekatakanahalfwidth = 0xff92;
  15312. t.mem = 0x05de;
  15313. t.memdagesh = 0xfb3e;
  15314. t.memdageshhebrew = 0xfb3e;
  15315. t.memhebrew = 0x05de;
  15316. t.menarmenian = 0x0574;
  15317. t.merkhahebrew = 0x05a5;
  15318. t.merkhakefulahebrew = 0x05a6;
  15319. t.merkhakefulalefthebrew = 0x05a6;
  15320. t.merkhalefthebrew = 0x05a5;
  15321. t.mhook = 0x0271;
  15322. t.mhzsquare = 0x3392;
  15323. t.middledotkatakanahalfwidth = 0xff65;
  15324. t.middot = 0x00b7;
  15325. t.mieumacirclekorean = 0x3272;
  15326. t.mieumaparenkorean = 0x3212;
  15327. t.mieumcirclekorean = 0x3264;
  15328. t.mieumkorean = 0x3141;
  15329. t.mieumpansioskorean = 0x3170;
  15330. t.mieumparenkorean = 0x3204;
  15331. t.mieumpieupkorean = 0x316e;
  15332. t.mieumsioskorean = 0x316f;
  15333. t.mihiragana = 0x307f;
  15334. t.mikatakana = 0x30df;
  15335. t.mikatakanahalfwidth = 0xff90;
  15336. t.minus = 0x2212;
  15337. t.minusbelowcmb = 0x0320;
  15338. t.minuscircle = 0x2296;
  15339. t.minusmod = 0x02d7;
  15340. t.minusplus = 0x2213;
  15341. t.minute = 0x2032;
  15342. t.miribaarusquare = 0x334a;
  15343. t.mirisquare = 0x3349;
  15344. t.mlonglegturned = 0x0270;
  15345. t.mlsquare = 0x3396;
  15346. t.mmcubedsquare = 0x33a3;
  15347. t.mmonospace = 0xff4d;
  15348. t.mmsquaredsquare = 0x339f;
  15349. t.mohiragana = 0x3082;
  15350. t.mohmsquare = 0x33c1;
  15351. t.mokatakana = 0x30e2;
  15352. t.mokatakanahalfwidth = 0xff93;
  15353. t.molsquare = 0x33d6;
  15354. t.momathai = 0x0e21;
  15355. t.moverssquare = 0x33a7;
  15356. t.moverssquaredsquare = 0x33a8;
  15357. t.mparen = 0x24a8;
  15358. t.mpasquare = 0x33ab;
  15359. t.mssquare = 0x33b3;
  15360. t.msuperior = 0xf6ef;
  15361. t.mturned = 0x026f;
  15362. t.mu = 0x00b5;
  15363. t.mu1 = 0x00b5;
  15364. t.muasquare = 0x3382;
  15365. t.muchgreater = 0x226b;
  15366. t.muchless = 0x226a;
  15367. t.mufsquare = 0x338c;
  15368. t.mugreek = 0x03bc;
  15369. t.mugsquare = 0x338d;
  15370. t.muhiragana = 0x3080;
  15371. t.mukatakana = 0x30e0;
  15372. t.mukatakanahalfwidth = 0xff91;
  15373. t.mulsquare = 0x3395;
  15374. t.multiply = 0x00d7;
  15375. t.mumsquare = 0x339b;
  15376. t.munahhebrew = 0x05a3;
  15377. t.munahlefthebrew = 0x05a3;
  15378. t.musicalnote = 0x266a;
  15379. t.musicalnotedbl = 0x266b;
  15380. t.musicflatsign = 0x266d;
  15381. t.musicsharpsign = 0x266f;
  15382. t.mussquare = 0x33b2;
  15383. t.muvsquare = 0x33b6;
  15384. t.muwsquare = 0x33bc;
  15385. t.mvmegasquare = 0x33b9;
  15386. t.mvsquare = 0x33b7;
  15387. t.mwmegasquare = 0x33bf;
  15388. t.mwsquare = 0x33bd;
  15389. t.n = 0x006e;
  15390. t.nabengali = 0x09a8;
  15391. t.nabla = 0x2207;
  15392. t.nacute = 0x0144;
  15393. t.nadeva = 0x0928;
  15394. t.nagujarati = 0x0aa8;
  15395. t.nagurmukhi = 0x0a28;
  15396. t.nahiragana = 0x306a;
  15397. t.nakatakana = 0x30ca;
  15398. t.nakatakanahalfwidth = 0xff85;
  15399. t.napostrophe = 0x0149;
  15400. t.nasquare = 0x3381;
  15401. t.nbopomofo = 0x310b;
  15402. t.nbspace = 0x00a0;
  15403. t.ncaron = 0x0148;
  15404. t.ncedilla = 0x0146;
  15405. t.ncircle = 0x24dd;
  15406. t.ncircumflexbelow = 0x1e4b;
  15407. t.ncommaaccent = 0x0146;
  15408. t.ndotaccent = 0x1e45;
  15409. t.ndotbelow = 0x1e47;
  15410. t.nehiragana = 0x306d;
  15411. t.nekatakana = 0x30cd;
  15412. t.nekatakanahalfwidth = 0xff88;
  15413. t.newsheqelsign = 0x20aa;
  15414. t.nfsquare = 0x338b;
  15415. t.ngabengali = 0x0999;
  15416. t.ngadeva = 0x0919;
  15417. t.ngagujarati = 0x0a99;
  15418. t.ngagurmukhi = 0x0a19;
  15419. t.ngonguthai = 0x0e07;
  15420. t.nhiragana = 0x3093;
  15421. t.nhookleft = 0x0272;
  15422. t.nhookretroflex = 0x0273;
  15423. t.nieunacirclekorean = 0x326f;
  15424. t.nieunaparenkorean = 0x320f;
  15425. t.nieuncieuckorean = 0x3135;
  15426. t.nieuncirclekorean = 0x3261;
  15427. t.nieunhieuhkorean = 0x3136;
  15428. t.nieunkorean = 0x3134;
  15429. t.nieunpansioskorean = 0x3168;
  15430. t.nieunparenkorean = 0x3201;
  15431. t.nieunsioskorean = 0x3167;
  15432. t.nieuntikeutkorean = 0x3166;
  15433. t.nihiragana = 0x306b;
  15434. t.nikatakana = 0x30cb;
  15435. t.nikatakanahalfwidth = 0xff86;
  15436. t.nikhahitleftthai = 0xf899;
  15437. t.nikhahitthai = 0x0e4d;
  15438. t.nine = 0x0039;
  15439. t.ninearabic = 0x0669;
  15440. t.ninebengali = 0x09ef;
  15441. t.ninecircle = 0x2468;
  15442. t.ninecircleinversesansserif = 0x2792;
  15443. t.ninedeva = 0x096f;
  15444. t.ninegujarati = 0x0aef;
  15445. t.ninegurmukhi = 0x0a6f;
  15446. t.ninehackarabic = 0x0669;
  15447. t.ninehangzhou = 0x3029;
  15448. t.nineideographicparen = 0x3228;
  15449. t.nineinferior = 0x2089;
  15450. t.ninemonospace = 0xff19;
  15451. t.nineoldstyle = 0xf739;
  15452. t.nineparen = 0x247c;
  15453. t.nineperiod = 0x2490;
  15454. t.ninepersian = 0x06f9;
  15455. t.nineroman = 0x2178;
  15456. t.ninesuperior = 0x2079;
  15457. t.nineteencircle = 0x2472;
  15458. t.nineteenparen = 0x2486;
  15459. t.nineteenperiod = 0x249a;
  15460. t.ninethai = 0x0e59;
  15461. t.nj = 0x01cc;
  15462. t.njecyrillic = 0x045a;
  15463. t.nkatakana = 0x30f3;
  15464. t.nkatakanahalfwidth = 0xff9d;
  15465. t.nlegrightlong = 0x019e;
  15466. t.nlinebelow = 0x1e49;
  15467. t.nmonospace = 0xff4e;
  15468. t.nmsquare = 0x339a;
  15469. t.nnabengali = 0x09a3;
  15470. t.nnadeva = 0x0923;
  15471. t.nnagujarati = 0x0aa3;
  15472. t.nnagurmukhi = 0x0a23;
  15473. t.nnnadeva = 0x0929;
  15474. t.nohiragana = 0x306e;
  15475. t.nokatakana = 0x30ce;
  15476. t.nokatakanahalfwidth = 0xff89;
  15477. t.nonbreakingspace = 0x00a0;
  15478. t.nonenthai = 0x0e13;
  15479. t.nonuthai = 0x0e19;
  15480. t.noonarabic = 0x0646;
  15481. t.noonfinalarabic = 0xfee6;
  15482. t.noonghunnaarabic = 0x06ba;
  15483. t.noonghunnafinalarabic = 0xfb9f;
  15484. t.nooninitialarabic = 0xfee7;
  15485. t.noonjeeminitialarabic = 0xfcd2;
  15486. t.noonjeemisolatedarabic = 0xfc4b;
  15487. t.noonmedialarabic = 0xfee8;
  15488. t.noonmeeminitialarabic = 0xfcd5;
  15489. t.noonmeemisolatedarabic = 0xfc4e;
  15490. t.noonnoonfinalarabic = 0xfc8d;
  15491. t.notcontains = 0x220c;
  15492. t.notelement = 0x2209;
  15493. t.notelementof = 0x2209;
  15494. t.notequal = 0x2260;
  15495. t.notgreater = 0x226f;
  15496. t.notgreaternorequal = 0x2271;
  15497. t.notgreaternorless = 0x2279;
  15498. t.notidentical = 0x2262;
  15499. t.notless = 0x226e;
  15500. t.notlessnorequal = 0x2270;
  15501. t.notparallel = 0x2226;
  15502. t.notprecedes = 0x2280;
  15503. t.notsubset = 0x2284;
  15504. t.notsucceeds = 0x2281;
  15505. t.notsuperset = 0x2285;
  15506. t.nowarmenian = 0x0576;
  15507. t.nparen = 0x24a9;
  15508. t.nssquare = 0x33b1;
  15509. t.nsuperior = 0x207f;
  15510. t.ntilde = 0x00f1;
  15511. t.nu = 0x03bd;
  15512. t.nuhiragana = 0x306c;
  15513. t.nukatakana = 0x30cc;
  15514. t.nukatakanahalfwidth = 0xff87;
  15515. t.nuktabengali = 0x09bc;
  15516. t.nuktadeva = 0x093c;
  15517. t.nuktagujarati = 0x0abc;
  15518. t.nuktagurmukhi = 0x0a3c;
  15519. t.numbersign = 0x0023;
  15520. t.numbersignmonospace = 0xff03;
  15521. t.numbersignsmall = 0xfe5f;
  15522. t.numeralsigngreek = 0x0374;
  15523. t.numeralsignlowergreek = 0x0375;
  15524. t.numero = 0x2116;
  15525. t.nun = 0x05e0;
  15526. t.nundagesh = 0xfb40;
  15527. t.nundageshhebrew = 0xfb40;
  15528. t.nunhebrew = 0x05e0;
  15529. t.nvsquare = 0x33b5;
  15530. t.nwsquare = 0x33bb;
  15531. t.nyabengali = 0x099e;
  15532. t.nyadeva = 0x091e;
  15533. t.nyagujarati = 0x0a9e;
  15534. t.nyagurmukhi = 0x0a1e;
  15535. t.o = 0x006f;
  15536. t.oacute = 0x00f3;
  15537. t.oangthai = 0x0e2d;
  15538. t.obarred = 0x0275;
  15539. t.obarredcyrillic = 0x04e9;
  15540. t.obarreddieresiscyrillic = 0x04eb;
  15541. t.obengali = 0x0993;
  15542. t.obopomofo = 0x311b;
  15543. t.obreve = 0x014f;
  15544. t.ocandradeva = 0x0911;
  15545. t.ocandragujarati = 0x0a91;
  15546. t.ocandravowelsigndeva = 0x0949;
  15547. t.ocandravowelsigngujarati = 0x0ac9;
  15548. t.ocaron = 0x01d2;
  15549. t.ocircle = 0x24de;
  15550. t.ocircumflex = 0x00f4;
  15551. t.ocircumflexacute = 0x1ed1;
  15552. t.ocircumflexdotbelow = 0x1ed9;
  15553. t.ocircumflexgrave = 0x1ed3;
  15554. t.ocircumflexhookabove = 0x1ed5;
  15555. t.ocircumflextilde = 0x1ed7;
  15556. t.ocyrillic = 0x043e;
  15557. t.odblacute = 0x0151;
  15558. t.odblgrave = 0x020d;
  15559. t.odeva = 0x0913;
  15560. t.odieresis = 0x00f6;
  15561. t.odieresiscyrillic = 0x04e7;
  15562. t.odotbelow = 0x1ecd;
  15563. t.oe = 0x0153;
  15564. t.oekorean = 0x315a;
  15565. t.ogonek = 0x02db;
  15566. t.ogonekcmb = 0x0328;
  15567. t.ograve = 0x00f2;
  15568. t.ogujarati = 0x0a93;
  15569. t.oharmenian = 0x0585;
  15570. t.ohiragana = 0x304a;
  15571. t.ohookabove = 0x1ecf;
  15572. t.ohorn = 0x01a1;
  15573. t.ohornacute = 0x1edb;
  15574. t.ohorndotbelow = 0x1ee3;
  15575. t.ohorngrave = 0x1edd;
  15576. t.ohornhookabove = 0x1edf;
  15577. t.ohorntilde = 0x1ee1;
  15578. t.ohungarumlaut = 0x0151;
  15579. t.oi = 0x01a3;
  15580. t.oinvertedbreve = 0x020f;
  15581. t.okatakana = 0x30aa;
  15582. t.okatakanahalfwidth = 0xff75;
  15583. t.okorean = 0x3157;
  15584. t.olehebrew = 0x05ab;
  15585. t.omacron = 0x014d;
  15586. t.omacronacute = 0x1e53;
  15587. t.omacrongrave = 0x1e51;
  15588. t.omdeva = 0x0950;
  15589. t.omega = 0x03c9;
  15590. t.omega1 = 0x03d6;
  15591. t.omegacyrillic = 0x0461;
  15592. t.omegalatinclosed = 0x0277;
  15593. t.omegaroundcyrillic = 0x047b;
  15594. t.omegatitlocyrillic = 0x047d;
  15595. t.omegatonos = 0x03ce;
  15596. t.omgujarati = 0x0ad0;
  15597. t.omicron = 0x03bf;
  15598. t.omicrontonos = 0x03cc;
  15599. t.omonospace = 0xff4f;
  15600. t.one = 0x0031;
  15601. t.onearabic = 0x0661;
  15602. t.onebengali = 0x09e7;
  15603. t.onecircle = 0x2460;
  15604. t.onecircleinversesansserif = 0x278a;
  15605. t.onedeva = 0x0967;
  15606. t.onedotenleader = 0x2024;
  15607. t.oneeighth = 0x215b;
  15608. t.onefitted = 0xf6dc;
  15609. t.onegujarati = 0x0ae7;
  15610. t.onegurmukhi = 0x0a67;
  15611. t.onehackarabic = 0x0661;
  15612. t.onehalf = 0x00bd;
  15613. t.onehangzhou = 0x3021;
  15614. t.oneideographicparen = 0x3220;
  15615. t.oneinferior = 0x2081;
  15616. t.onemonospace = 0xff11;
  15617. t.onenumeratorbengali = 0x09f4;
  15618. t.oneoldstyle = 0xf731;
  15619. t.oneparen = 0x2474;
  15620. t.oneperiod = 0x2488;
  15621. t.onepersian = 0x06f1;
  15622. t.onequarter = 0x00bc;
  15623. t.oneroman = 0x2170;
  15624. t.onesuperior = 0x00b9;
  15625. t.onethai = 0x0e51;
  15626. t.onethird = 0x2153;
  15627. t.oogonek = 0x01eb;
  15628. t.oogonekmacron = 0x01ed;
  15629. t.oogurmukhi = 0x0a13;
  15630. t.oomatragurmukhi = 0x0a4b;
  15631. t.oopen = 0x0254;
  15632. t.oparen = 0x24aa;
  15633. t.openbullet = 0x25e6;
  15634. t.option = 0x2325;
  15635. t.ordfeminine = 0x00aa;
  15636. t.ordmasculine = 0x00ba;
  15637. t.orthogonal = 0x221f;
  15638. t.oshortdeva = 0x0912;
  15639. t.oshortvowelsigndeva = 0x094a;
  15640. t.oslash = 0x00f8;
  15641. t.oslashacute = 0x01ff;
  15642. t.osmallhiragana = 0x3049;
  15643. t.osmallkatakana = 0x30a9;
  15644. t.osmallkatakanahalfwidth = 0xff6b;
  15645. t.ostrokeacute = 0x01ff;
  15646. t.osuperior = 0xf6f0;
  15647. t.otcyrillic = 0x047f;
  15648. t.otilde = 0x00f5;
  15649. t.otildeacute = 0x1e4d;
  15650. t.otildedieresis = 0x1e4f;
  15651. t.oubopomofo = 0x3121;
  15652. t.overline = 0x203e;
  15653. t.overlinecenterline = 0xfe4a;
  15654. t.overlinecmb = 0x0305;
  15655. t.overlinedashed = 0xfe49;
  15656. t.overlinedblwavy = 0xfe4c;
  15657. t.overlinewavy = 0xfe4b;
  15658. t.overscore = 0x00af;
  15659. t.ovowelsignbengali = 0x09cb;
  15660. t.ovowelsigndeva = 0x094b;
  15661. t.ovowelsigngujarati = 0x0acb;
  15662. t.p = 0x0070;
  15663. t.paampssquare = 0x3380;
  15664. t.paasentosquare = 0x332b;
  15665. t.pabengali = 0x09aa;
  15666. t.pacute = 0x1e55;
  15667. t.padeva = 0x092a;
  15668. t.pagedown = 0x21df;
  15669. t.pageup = 0x21de;
  15670. t.pagujarati = 0x0aaa;
  15671. t.pagurmukhi = 0x0a2a;
  15672. t.pahiragana = 0x3071;
  15673. t.paiyannoithai = 0x0e2f;
  15674. t.pakatakana = 0x30d1;
  15675. t.palatalizationcyrilliccmb = 0x0484;
  15676. t.palochkacyrillic = 0x04c0;
  15677. t.pansioskorean = 0x317f;
  15678. t.paragraph = 0x00b6;
  15679. t.parallel = 0x2225;
  15680. t.parenleft = 0x0028;
  15681. t.parenleftaltonearabic = 0xfd3e;
  15682. t.parenleftbt = 0xf8ed;
  15683. t.parenleftex = 0xf8ec;
  15684. t.parenleftinferior = 0x208d;
  15685. t.parenleftmonospace = 0xff08;
  15686. t.parenleftsmall = 0xfe59;
  15687. t.parenleftsuperior = 0x207d;
  15688. t.parenlefttp = 0xf8eb;
  15689. t.parenleftvertical = 0xfe35;
  15690. t.parenright = 0x0029;
  15691. t.parenrightaltonearabic = 0xfd3f;
  15692. t.parenrightbt = 0xf8f8;
  15693. t.parenrightex = 0xf8f7;
  15694. t.parenrightinferior = 0x208e;
  15695. t.parenrightmonospace = 0xff09;
  15696. t.parenrightsmall = 0xfe5a;
  15697. t.parenrightsuperior = 0x207e;
  15698. t.parenrighttp = 0xf8f6;
  15699. t.parenrightvertical = 0xfe36;
  15700. t.partialdiff = 0x2202;
  15701. t.paseqhebrew = 0x05c0;
  15702. t.pashtahebrew = 0x0599;
  15703. t.pasquare = 0x33a9;
  15704. t.patah = 0x05b7;
  15705. t.patah11 = 0x05b7;
  15706. t.patah1d = 0x05b7;
  15707. t.patah2a = 0x05b7;
  15708. t.patahhebrew = 0x05b7;
  15709. t.patahnarrowhebrew = 0x05b7;
  15710. t.patahquarterhebrew = 0x05b7;
  15711. t.patahwidehebrew = 0x05b7;
  15712. t.pazerhebrew = 0x05a1;
  15713. t.pbopomofo = 0x3106;
  15714. t.pcircle = 0x24df;
  15715. t.pdotaccent = 0x1e57;
  15716. t.pe = 0x05e4;
  15717. t.pecyrillic = 0x043f;
  15718. t.pedagesh = 0xfb44;
  15719. t.pedageshhebrew = 0xfb44;
  15720. t.peezisquare = 0x333b;
  15721. t.pefinaldageshhebrew = 0xfb43;
  15722. t.peharabic = 0x067e;
  15723. t.peharmenian = 0x057a;
  15724. t.pehebrew = 0x05e4;
  15725. t.pehfinalarabic = 0xfb57;
  15726. t.pehinitialarabic = 0xfb58;
  15727. t.pehiragana = 0x307a;
  15728. t.pehmedialarabic = 0xfb59;
  15729. t.pekatakana = 0x30da;
  15730. t.pemiddlehookcyrillic = 0x04a7;
  15731. t.perafehebrew = 0xfb4e;
  15732. t.percent = 0x0025;
  15733. t.percentarabic = 0x066a;
  15734. t.percentmonospace = 0xff05;
  15735. t.percentsmall = 0xfe6a;
  15736. t.period = 0x002e;
  15737. t.periodarmenian = 0x0589;
  15738. t.periodcentered = 0x00b7;
  15739. t.periodhalfwidth = 0xff61;
  15740. t.periodinferior = 0xf6e7;
  15741. t.periodmonospace = 0xff0e;
  15742. t.periodsmall = 0xfe52;
  15743. t.periodsuperior = 0xf6e8;
  15744. t.perispomenigreekcmb = 0x0342;
  15745. t.perpendicular = 0x22a5;
  15746. t.perthousand = 0x2030;
  15747. t.peseta = 0x20a7;
  15748. t.pfsquare = 0x338a;
  15749. t.phabengali = 0x09ab;
  15750. t.phadeva = 0x092b;
  15751. t.phagujarati = 0x0aab;
  15752. t.phagurmukhi = 0x0a2b;
  15753. t.phi = 0x03c6;
  15754. t.phi1 = 0x03d5;
  15755. t.phieuphacirclekorean = 0x327a;
  15756. t.phieuphaparenkorean = 0x321a;
  15757. t.phieuphcirclekorean = 0x326c;
  15758. t.phieuphkorean = 0x314d;
  15759. t.phieuphparenkorean = 0x320c;
  15760. t.philatin = 0x0278;
  15761. t.phinthuthai = 0x0e3a;
  15762. t.phisymbolgreek = 0x03d5;
  15763. t.phook = 0x01a5;
  15764. t.phophanthai = 0x0e1e;
  15765. t.phophungthai = 0x0e1c;
  15766. t.phosamphaothai = 0x0e20;
  15767. t.pi = 0x03c0;
  15768. t.pieupacirclekorean = 0x3273;
  15769. t.pieupaparenkorean = 0x3213;
  15770. t.pieupcieuckorean = 0x3176;
  15771. t.pieupcirclekorean = 0x3265;
  15772. t.pieupkiyeokkorean = 0x3172;
  15773. t.pieupkorean = 0x3142;
  15774. t.pieupparenkorean = 0x3205;
  15775. t.pieupsioskiyeokkorean = 0x3174;
  15776. t.pieupsioskorean = 0x3144;
  15777. t.pieupsiostikeutkorean = 0x3175;
  15778. t.pieupthieuthkorean = 0x3177;
  15779. t.pieuptikeutkorean = 0x3173;
  15780. t.pihiragana = 0x3074;
  15781. t.pikatakana = 0x30d4;
  15782. t.pisymbolgreek = 0x03d6;
  15783. t.piwrarmenian = 0x0583;
  15784. t.planckover2pi = 0x210f;
  15785. t.planckover2pi1 = 0x210f;
  15786. t.plus = 0x002b;
  15787. t.plusbelowcmb = 0x031f;
  15788. t.pluscircle = 0x2295;
  15789. t.plusminus = 0x00b1;
  15790. t.plusmod = 0x02d6;
  15791. t.plusmonospace = 0xff0b;
  15792. t.plussmall = 0xfe62;
  15793. t.plussuperior = 0x207a;
  15794. t.pmonospace = 0xff50;
  15795. t.pmsquare = 0x33d8;
  15796. t.pohiragana = 0x307d;
  15797. t.pointingindexdownwhite = 0x261f;
  15798. t.pointingindexleftwhite = 0x261c;
  15799. t.pointingindexrightwhite = 0x261e;
  15800. t.pointingindexupwhite = 0x261d;
  15801. t.pokatakana = 0x30dd;
  15802. t.poplathai = 0x0e1b;
  15803. t.postalmark = 0x3012;
  15804. t.postalmarkface = 0x3020;
  15805. t.pparen = 0x24ab;
  15806. t.precedes = 0x227a;
  15807. t.prescription = 0x211e;
  15808. t.primemod = 0x02b9;
  15809. t.primereversed = 0x2035;
  15810. t.product = 0x220f;
  15811. t.projective = 0x2305;
  15812. t.prolongedkana = 0x30fc;
  15813. t.propellor = 0x2318;
  15814. t.propersubset = 0x2282;
  15815. t.propersuperset = 0x2283;
  15816. t.proportion = 0x2237;
  15817. t.proportional = 0x221d;
  15818. t.psi = 0x03c8;
  15819. t.psicyrillic = 0x0471;
  15820. t.psilipneumatacyrilliccmb = 0x0486;
  15821. t.pssquare = 0x33b0;
  15822. t.puhiragana = 0x3077;
  15823. t.pukatakana = 0x30d7;
  15824. t.pvsquare = 0x33b4;
  15825. t.pwsquare = 0x33ba;
  15826. t.q = 0x0071;
  15827. t.qadeva = 0x0958;
  15828. t.qadmahebrew = 0x05a8;
  15829. t.qafarabic = 0x0642;
  15830. t.qaffinalarabic = 0xfed6;
  15831. t.qafinitialarabic = 0xfed7;
  15832. t.qafmedialarabic = 0xfed8;
  15833. t.qamats = 0x05b8;
  15834. t.qamats10 = 0x05b8;
  15835. t.qamats1a = 0x05b8;
  15836. t.qamats1c = 0x05b8;
  15837. t.qamats27 = 0x05b8;
  15838. t.qamats29 = 0x05b8;
  15839. t.qamats33 = 0x05b8;
  15840. t.qamatsde = 0x05b8;
  15841. t.qamatshebrew = 0x05b8;
  15842. t.qamatsnarrowhebrew = 0x05b8;
  15843. t.qamatsqatanhebrew = 0x05b8;
  15844. t.qamatsqatannarrowhebrew = 0x05b8;
  15845. t.qamatsqatanquarterhebrew = 0x05b8;
  15846. t.qamatsqatanwidehebrew = 0x05b8;
  15847. t.qamatsquarterhebrew = 0x05b8;
  15848. t.qamatswidehebrew = 0x05b8;
  15849. t.qarneyparahebrew = 0x059f;
  15850. t.qbopomofo = 0x3111;
  15851. t.qcircle = 0x24e0;
  15852. t.qhook = 0x02a0;
  15853. t.qmonospace = 0xff51;
  15854. t.qof = 0x05e7;
  15855. t.qofdagesh = 0xfb47;
  15856. t.qofdageshhebrew = 0xfb47;
  15857. t.qofhebrew = 0x05e7;
  15858. t.qparen = 0x24ac;
  15859. t.quarternote = 0x2669;
  15860. t.qubuts = 0x05bb;
  15861. t.qubuts18 = 0x05bb;
  15862. t.qubuts25 = 0x05bb;
  15863. t.qubuts31 = 0x05bb;
  15864. t.qubutshebrew = 0x05bb;
  15865. t.qubutsnarrowhebrew = 0x05bb;
  15866. t.qubutsquarterhebrew = 0x05bb;
  15867. t.qubutswidehebrew = 0x05bb;
  15868. t.question = 0x003f;
  15869. t.questionarabic = 0x061f;
  15870. t.questionarmenian = 0x055e;
  15871. t.questiondown = 0x00bf;
  15872. t.questiondownsmall = 0xf7bf;
  15873. t.questiongreek = 0x037e;
  15874. t.questionmonospace = 0xff1f;
  15875. t.questionsmall = 0xf73f;
  15876. t.quotedbl = 0x0022;
  15877. t.quotedblbase = 0x201e;
  15878. t.quotedblleft = 0x201c;
  15879. t.quotedblmonospace = 0xff02;
  15880. t.quotedblprime = 0x301e;
  15881. t.quotedblprimereversed = 0x301d;
  15882. t.quotedblright = 0x201d;
  15883. t.quoteleft = 0x2018;
  15884. t.quoteleftreversed = 0x201b;
  15885. t.quotereversed = 0x201b;
  15886. t.quoteright = 0x2019;
  15887. t.quoterightn = 0x0149;
  15888. t.quotesinglbase = 0x201a;
  15889. t.quotesingle = 0x0027;
  15890. t.quotesinglemonospace = 0xff07;
  15891. t.r = 0x0072;
  15892. t.raarmenian = 0x057c;
  15893. t.rabengali = 0x09b0;
  15894. t.racute = 0x0155;
  15895. t.radeva = 0x0930;
  15896. t.radical = 0x221a;
  15897. t.radicalex = 0xf8e5;
  15898. t.radoverssquare = 0x33ae;
  15899. t.radoverssquaredsquare = 0x33af;
  15900. t.radsquare = 0x33ad;
  15901. t.rafe = 0x05bf;
  15902. t.rafehebrew = 0x05bf;
  15903. t.ragujarati = 0x0ab0;
  15904. t.ragurmukhi = 0x0a30;
  15905. t.rahiragana = 0x3089;
  15906. t.rakatakana = 0x30e9;
  15907. t.rakatakanahalfwidth = 0xff97;
  15908. t.ralowerdiagonalbengali = 0x09f1;
  15909. t.ramiddlediagonalbengali = 0x09f0;
  15910. t.ramshorn = 0x0264;
  15911. t.ratio = 0x2236;
  15912. t.rbopomofo = 0x3116;
  15913. t.rcaron = 0x0159;
  15914. t.rcedilla = 0x0157;
  15915. t.rcircle = 0x24e1;
  15916. t.rcommaaccent = 0x0157;
  15917. t.rdblgrave = 0x0211;
  15918. t.rdotaccent = 0x1e59;
  15919. t.rdotbelow = 0x1e5b;
  15920. t.rdotbelowmacron = 0x1e5d;
  15921. t.referencemark = 0x203b;
  15922. t.reflexsubset = 0x2286;
  15923. t.reflexsuperset = 0x2287;
  15924. t.registered = 0x00ae;
  15925. t.registersans = 0xf8e8;
  15926. t.registerserif = 0xf6da;
  15927. t.reharabic = 0x0631;
  15928. t.reharmenian = 0x0580;
  15929. t.rehfinalarabic = 0xfeae;
  15930. t.rehiragana = 0x308c;
  15931. t.rekatakana = 0x30ec;
  15932. t.rekatakanahalfwidth = 0xff9a;
  15933. t.resh = 0x05e8;
  15934. t.reshdageshhebrew = 0xfb48;
  15935. t.reshhebrew = 0x05e8;
  15936. t.reversedtilde = 0x223d;
  15937. t.reviahebrew = 0x0597;
  15938. t.reviamugrashhebrew = 0x0597;
  15939. t.revlogicalnot = 0x2310;
  15940. t.rfishhook = 0x027e;
  15941. t.rfishhookreversed = 0x027f;
  15942. t.rhabengali = 0x09dd;
  15943. t.rhadeva = 0x095d;
  15944. t.rho = 0x03c1;
  15945. t.rhook = 0x027d;
  15946. t.rhookturned = 0x027b;
  15947. t.rhookturnedsuperior = 0x02b5;
  15948. t.rhosymbolgreek = 0x03f1;
  15949. t.rhotichookmod = 0x02de;
  15950. t.rieulacirclekorean = 0x3271;
  15951. t.rieulaparenkorean = 0x3211;
  15952. t.rieulcirclekorean = 0x3263;
  15953. t.rieulhieuhkorean = 0x3140;
  15954. t.rieulkiyeokkorean = 0x313a;
  15955. t.rieulkiyeoksioskorean = 0x3169;
  15956. t.rieulkorean = 0x3139;
  15957. t.rieulmieumkorean = 0x313b;
  15958. t.rieulpansioskorean = 0x316c;
  15959. t.rieulparenkorean = 0x3203;
  15960. t.rieulphieuphkorean = 0x313f;
  15961. t.rieulpieupkorean = 0x313c;
  15962. t.rieulpieupsioskorean = 0x316b;
  15963. t.rieulsioskorean = 0x313d;
  15964. t.rieulthieuthkorean = 0x313e;
  15965. t.rieultikeutkorean = 0x316a;
  15966. t.rieulyeorinhieuhkorean = 0x316d;
  15967. t.rightangle = 0x221f;
  15968. t.righttackbelowcmb = 0x0319;
  15969. t.righttriangle = 0x22bf;
  15970. t.rihiragana = 0x308a;
  15971. t.rikatakana = 0x30ea;
  15972. t.rikatakanahalfwidth = 0xff98;
  15973. t.ring = 0x02da;
  15974. t.ringbelowcmb = 0x0325;
  15975. t.ringcmb = 0x030a;
  15976. t.ringhalfleft = 0x02bf;
  15977. t.ringhalfleftarmenian = 0x0559;
  15978. t.ringhalfleftbelowcmb = 0x031c;
  15979. t.ringhalfleftcentered = 0x02d3;
  15980. t.ringhalfright = 0x02be;
  15981. t.ringhalfrightbelowcmb = 0x0339;
  15982. t.ringhalfrightcentered = 0x02d2;
  15983. t.rinvertedbreve = 0x0213;
  15984. t.rittorusquare = 0x3351;
  15985. t.rlinebelow = 0x1e5f;
  15986. t.rlongleg = 0x027c;
  15987. t.rlonglegturned = 0x027a;
  15988. t.rmonospace = 0xff52;
  15989. t.rohiragana = 0x308d;
  15990. t.rokatakana = 0x30ed;
  15991. t.rokatakanahalfwidth = 0xff9b;
  15992. t.roruathai = 0x0e23;
  15993. t.rparen = 0x24ad;
  15994. t.rrabengali = 0x09dc;
  15995. t.rradeva = 0x0931;
  15996. t.rragurmukhi = 0x0a5c;
  15997. t.rreharabic = 0x0691;
  15998. t.rrehfinalarabic = 0xfb8d;
  15999. t.rrvocalicbengali = 0x09e0;
  16000. t.rrvocalicdeva = 0x0960;
  16001. t.rrvocalicgujarati = 0x0ae0;
  16002. t.rrvocalicvowelsignbengali = 0x09c4;
  16003. t.rrvocalicvowelsigndeva = 0x0944;
  16004. t.rrvocalicvowelsigngujarati = 0x0ac4;
  16005. t.rsuperior = 0xf6f1;
  16006. t.rtblock = 0x2590;
  16007. t.rturned = 0x0279;
  16008. t.rturnedsuperior = 0x02b4;
  16009. t.ruhiragana = 0x308b;
  16010. t.rukatakana = 0x30eb;
  16011. t.rukatakanahalfwidth = 0xff99;
  16012. t.rupeemarkbengali = 0x09f2;
  16013. t.rupeesignbengali = 0x09f3;
  16014. t.rupiah = 0xf6dd;
  16015. t.ruthai = 0x0e24;
  16016. t.rvocalicbengali = 0x098b;
  16017. t.rvocalicdeva = 0x090b;
  16018. t.rvocalicgujarati = 0x0a8b;
  16019. t.rvocalicvowelsignbengali = 0x09c3;
  16020. t.rvocalicvowelsigndeva = 0x0943;
  16021. t.rvocalicvowelsigngujarati = 0x0ac3;
  16022. t.s = 0x0073;
  16023. t.sabengali = 0x09b8;
  16024. t.sacute = 0x015b;
  16025. t.sacutedotaccent = 0x1e65;
  16026. t.sadarabic = 0x0635;
  16027. t.sadeva = 0x0938;
  16028. t.sadfinalarabic = 0xfeba;
  16029. t.sadinitialarabic = 0xfebb;
  16030. t.sadmedialarabic = 0xfebc;
  16031. t.sagujarati = 0x0ab8;
  16032. t.sagurmukhi = 0x0a38;
  16033. t.sahiragana = 0x3055;
  16034. t.sakatakana = 0x30b5;
  16035. t.sakatakanahalfwidth = 0xff7b;
  16036. t.sallallahoualayhewasallamarabic = 0xfdfa;
  16037. t.samekh = 0x05e1;
  16038. t.samekhdagesh = 0xfb41;
  16039. t.samekhdageshhebrew = 0xfb41;
  16040. t.samekhhebrew = 0x05e1;
  16041. t.saraaathai = 0x0e32;
  16042. t.saraaethai = 0x0e41;
  16043. t.saraaimaimalaithai = 0x0e44;
  16044. t.saraaimaimuanthai = 0x0e43;
  16045. t.saraamthai = 0x0e33;
  16046. t.saraathai = 0x0e30;
  16047. t.saraethai = 0x0e40;
  16048. t.saraiileftthai = 0xf886;
  16049. t.saraiithai = 0x0e35;
  16050. t.saraileftthai = 0xf885;
  16051. t.saraithai = 0x0e34;
  16052. t.saraothai = 0x0e42;
  16053. t.saraueeleftthai = 0xf888;
  16054. t.saraueethai = 0x0e37;
  16055. t.saraueleftthai = 0xf887;
  16056. t.sarauethai = 0x0e36;
  16057. t.sarauthai = 0x0e38;
  16058. t.sarauuthai = 0x0e39;
  16059. t.sbopomofo = 0x3119;
  16060. t.scaron = 0x0161;
  16061. t.scarondotaccent = 0x1e67;
  16062. t.scedilla = 0x015f;
  16063. t.schwa = 0x0259;
  16064. t.schwacyrillic = 0x04d9;
  16065. t.schwadieresiscyrillic = 0x04db;
  16066. t.schwahook = 0x025a;
  16067. t.scircle = 0x24e2;
  16068. t.scircumflex = 0x015d;
  16069. t.scommaaccent = 0x0219;
  16070. t.sdotaccent = 0x1e61;
  16071. t.sdotbelow = 0x1e63;
  16072. t.sdotbelowdotaccent = 0x1e69;
  16073. t.seagullbelowcmb = 0x033c;
  16074. t.second = 0x2033;
  16075. t.secondtonechinese = 0x02ca;
  16076. t.section = 0x00a7;
  16077. t.seenarabic = 0x0633;
  16078. t.seenfinalarabic = 0xfeb2;
  16079. t.seeninitialarabic = 0xfeb3;
  16080. t.seenmedialarabic = 0xfeb4;
  16081. t.segol = 0x05b6;
  16082. t.segol13 = 0x05b6;
  16083. t.segol1f = 0x05b6;
  16084. t.segol2c = 0x05b6;
  16085. t.segolhebrew = 0x05b6;
  16086. t.segolnarrowhebrew = 0x05b6;
  16087. t.segolquarterhebrew = 0x05b6;
  16088. t.segoltahebrew = 0x0592;
  16089. t.segolwidehebrew = 0x05b6;
  16090. t.seharmenian = 0x057d;
  16091. t.sehiragana = 0x305b;
  16092. t.sekatakana = 0x30bb;
  16093. t.sekatakanahalfwidth = 0xff7e;
  16094. t.semicolon = 0x003b;
  16095. t.semicolonarabic = 0x061b;
  16096. t.semicolonmonospace = 0xff1b;
  16097. t.semicolonsmall = 0xfe54;
  16098. t.semivoicedmarkkana = 0x309c;
  16099. t.semivoicedmarkkanahalfwidth = 0xff9f;
  16100. t.sentisquare = 0x3322;
  16101. t.sentosquare = 0x3323;
  16102. t.seven = 0x0037;
  16103. t.sevenarabic = 0x0667;
  16104. t.sevenbengali = 0x09ed;
  16105. t.sevencircle = 0x2466;
  16106. t.sevencircleinversesansserif = 0x2790;
  16107. t.sevendeva = 0x096d;
  16108. t.seveneighths = 0x215e;
  16109. t.sevengujarati = 0x0aed;
  16110. t.sevengurmukhi = 0x0a6d;
  16111. t.sevenhackarabic = 0x0667;
  16112. t.sevenhangzhou = 0x3027;
  16113. t.sevenideographicparen = 0x3226;
  16114. t.seveninferior = 0x2087;
  16115. t.sevenmonospace = 0xff17;
  16116. t.sevenoldstyle = 0xf737;
  16117. t.sevenparen = 0x247a;
  16118. t.sevenperiod = 0x248e;
  16119. t.sevenpersian = 0x06f7;
  16120. t.sevenroman = 0x2176;
  16121. t.sevensuperior = 0x2077;
  16122. t.seventeencircle = 0x2470;
  16123. t.seventeenparen = 0x2484;
  16124. t.seventeenperiod = 0x2498;
  16125. t.seventhai = 0x0e57;
  16126. t.sfthyphen = 0x00ad;
  16127. t.shaarmenian = 0x0577;
  16128. t.shabengali = 0x09b6;
  16129. t.shacyrillic = 0x0448;
  16130. t.shaddaarabic = 0x0651;
  16131. t.shaddadammaarabic = 0xfc61;
  16132. t.shaddadammatanarabic = 0xfc5e;
  16133. t.shaddafathaarabic = 0xfc60;
  16134. t.shaddakasraarabic = 0xfc62;
  16135. t.shaddakasratanarabic = 0xfc5f;
  16136. t.shade = 0x2592;
  16137. t.shadedark = 0x2593;
  16138. t.shadelight = 0x2591;
  16139. t.shademedium = 0x2592;
  16140. t.shadeva = 0x0936;
  16141. t.shagujarati = 0x0ab6;
  16142. t.shagurmukhi = 0x0a36;
  16143. t.shalshelethebrew = 0x0593;
  16144. t.shbopomofo = 0x3115;
  16145. t.shchacyrillic = 0x0449;
  16146. t.sheenarabic = 0x0634;
  16147. t.sheenfinalarabic = 0xfeb6;
  16148. t.sheeninitialarabic = 0xfeb7;
  16149. t.sheenmedialarabic = 0xfeb8;
  16150. t.sheicoptic = 0x03e3;
  16151. t.sheqel = 0x20aa;
  16152. t.sheqelhebrew = 0x20aa;
  16153. t.sheva = 0x05b0;
  16154. t.sheva115 = 0x05b0;
  16155. t.sheva15 = 0x05b0;
  16156. t.sheva22 = 0x05b0;
  16157. t.sheva2e = 0x05b0;
  16158. t.shevahebrew = 0x05b0;
  16159. t.shevanarrowhebrew = 0x05b0;
  16160. t.shevaquarterhebrew = 0x05b0;
  16161. t.shevawidehebrew = 0x05b0;
  16162. t.shhacyrillic = 0x04bb;
  16163. t.shimacoptic = 0x03ed;
  16164. t.shin = 0x05e9;
  16165. t.shindagesh = 0xfb49;
  16166. t.shindageshhebrew = 0xfb49;
  16167. t.shindageshshindot = 0xfb2c;
  16168. t.shindageshshindothebrew = 0xfb2c;
  16169. t.shindageshsindot = 0xfb2d;
  16170. t.shindageshsindothebrew = 0xfb2d;
  16171. t.shindothebrew = 0x05c1;
  16172. t.shinhebrew = 0x05e9;
  16173. t.shinshindot = 0xfb2a;
  16174. t.shinshindothebrew = 0xfb2a;
  16175. t.shinsindot = 0xfb2b;
  16176. t.shinsindothebrew = 0xfb2b;
  16177. t.shook = 0x0282;
  16178. t.sigma = 0x03c3;
  16179. t.sigma1 = 0x03c2;
  16180. t.sigmafinal = 0x03c2;
  16181. t.sigmalunatesymbolgreek = 0x03f2;
  16182. t.sihiragana = 0x3057;
  16183. t.sikatakana = 0x30b7;
  16184. t.sikatakanahalfwidth = 0xff7c;
  16185. t.siluqhebrew = 0x05bd;
  16186. t.siluqlefthebrew = 0x05bd;
  16187. t.similar = 0x223c;
  16188. t.sindothebrew = 0x05c2;
  16189. t.siosacirclekorean = 0x3274;
  16190. t.siosaparenkorean = 0x3214;
  16191. t.sioscieuckorean = 0x317e;
  16192. t.sioscirclekorean = 0x3266;
  16193. t.sioskiyeokkorean = 0x317a;
  16194. t.sioskorean = 0x3145;
  16195. t.siosnieunkorean = 0x317b;
  16196. t.siosparenkorean = 0x3206;
  16197. t.siospieupkorean = 0x317d;
  16198. t.siostikeutkorean = 0x317c;
  16199. t.six = 0x0036;
  16200. t.sixarabic = 0x0666;
  16201. t.sixbengali = 0x09ec;
  16202. t.sixcircle = 0x2465;
  16203. t.sixcircleinversesansserif = 0x278f;
  16204. t.sixdeva = 0x096c;
  16205. t.sixgujarati = 0x0aec;
  16206. t.sixgurmukhi = 0x0a6c;
  16207. t.sixhackarabic = 0x0666;
  16208. t.sixhangzhou = 0x3026;
  16209. t.sixideographicparen = 0x3225;
  16210. t.sixinferior = 0x2086;
  16211. t.sixmonospace = 0xff16;
  16212. t.sixoldstyle = 0xf736;
  16213. t.sixparen = 0x2479;
  16214. t.sixperiod = 0x248d;
  16215. t.sixpersian = 0x06f6;
  16216. t.sixroman = 0x2175;
  16217. t.sixsuperior = 0x2076;
  16218. t.sixteencircle = 0x246f;
  16219. t.sixteencurrencydenominatorbengali = 0x09f9;
  16220. t.sixteenparen = 0x2483;
  16221. t.sixteenperiod = 0x2497;
  16222. t.sixthai = 0x0e56;
  16223. t.slash = 0x002f;
  16224. t.slashmonospace = 0xff0f;
  16225. t.slong = 0x017f;
  16226. t.slongdotaccent = 0x1e9b;
  16227. t.smileface = 0x263a;
  16228. t.smonospace = 0xff53;
  16229. t.sofpasuqhebrew = 0x05c3;
  16230. t.softhyphen = 0x00ad;
  16231. t.softsigncyrillic = 0x044c;
  16232. t.sohiragana = 0x305d;
  16233. t.sokatakana = 0x30bd;
  16234. t.sokatakanahalfwidth = 0xff7f;
  16235. t.soliduslongoverlaycmb = 0x0338;
  16236. t.solidusshortoverlaycmb = 0x0337;
  16237. t.sorusithai = 0x0e29;
  16238. t.sosalathai = 0x0e28;
  16239. t.sosothai = 0x0e0b;
  16240. t.sosuathai = 0x0e2a;
  16241. t.space = 0x0020;
  16242. t.spacehackarabic = 0x0020;
  16243. t.spade = 0x2660;
  16244. t.spadesuitblack = 0x2660;
  16245. t.spadesuitwhite = 0x2664;
  16246. t.sparen = 0x24ae;
  16247. t.squarebelowcmb = 0x033b;
  16248. t.squarecc = 0x33c4;
  16249. t.squarecm = 0x339d;
  16250. t.squarediagonalcrosshatchfill = 0x25a9;
  16251. t.squarehorizontalfill = 0x25a4;
  16252. t.squarekg = 0x338f;
  16253. t.squarekm = 0x339e;
  16254. t.squarekmcapital = 0x33ce;
  16255. t.squareln = 0x33d1;
  16256. t.squarelog = 0x33d2;
  16257. t.squaremg = 0x338e;
  16258. t.squaremil = 0x33d5;
  16259. t.squaremm = 0x339c;
  16260. t.squaremsquared = 0x33a1;
  16261. t.squareorthogonalcrosshatchfill = 0x25a6;
  16262. t.squareupperlefttolowerrightfill = 0x25a7;
  16263. t.squareupperrighttolowerleftfill = 0x25a8;
  16264. t.squareverticalfill = 0x25a5;
  16265. t.squarewhitewithsmallblack = 0x25a3;
  16266. t.srsquare = 0x33db;
  16267. t.ssabengali = 0x09b7;
  16268. t.ssadeva = 0x0937;
  16269. t.ssagujarati = 0x0ab7;
  16270. t.ssangcieuckorean = 0x3149;
  16271. t.ssanghieuhkorean = 0x3185;
  16272. t.ssangieungkorean = 0x3180;
  16273. t.ssangkiyeokkorean = 0x3132;
  16274. t.ssangnieunkorean = 0x3165;
  16275. t.ssangpieupkorean = 0x3143;
  16276. t.ssangsioskorean = 0x3146;
  16277. t.ssangtikeutkorean = 0x3138;
  16278. t.ssuperior = 0xf6f2;
  16279. t.sterling = 0x00a3;
  16280. t.sterlingmonospace = 0xffe1;
  16281. t.strokelongoverlaycmb = 0x0336;
  16282. t.strokeshortoverlaycmb = 0x0335;
  16283. t.subset = 0x2282;
  16284. t.subsetnotequal = 0x228a;
  16285. t.subsetorequal = 0x2286;
  16286. t.succeeds = 0x227b;
  16287. t.suchthat = 0x220b;
  16288. t.suhiragana = 0x3059;
  16289. t.sukatakana = 0x30b9;
  16290. t.sukatakanahalfwidth = 0xff7d;
  16291. t.sukunarabic = 0x0652;
  16292. t.summation = 0x2211;
  16293. t.sun = 0x263c;
  16294. t.superset = 0x2283;
  16295. t.supersetnotequal = 0x228b;
  16296. t.supersetorequal = 0x2287;
  16297. t.svsquare = 0x33dc;
  16298. t.syouwaerasquare = 0x337c;
  16299. t.t = 0x0074;
  16300. t.tabengali = 0x09a4;
  16301. t.tackdown = 0x22a4;
  16302. t.tackleft = 0x22a3;
  16303. t.tadeva = 0x0924;
  16304. t.tagujarati = 0x0aa4;
  16305. t.tagurmukhi = 0x0a24;
  16306. t.taharabic = 0x0637;
  16307. t.tahfinalarabic = 0xfec2;
  16308. t.tahinitialarabic = 0xfec3;
  16309. t.tahiragana = 0x305f;
  16310. t.tahmedialarabic = 0xfec4;
  16311. t.taisyouerasquare = 0x337d;
  16312. t.takatakana = 0x30bf;
  16313. t.takatakanahalfwidth = 0xff80;
  16314. t.tatweelarabic = 0x0640;
  16315. t.tau = 0x03c4;
  16316. t.tav = 0x05ea;
  16317. t.tavdages = 0xfb4a;
  16318. t.tavdagesh = 0xfb4a;
  16319. t.tavdageshhebrew = 0xfb4a;
  16320. t.tavhebrew = 0x05ea;
  16321. t.tbar = 0x0167;
  16322. t.tbopomofo = 0x310a;
  16323. t.tcaron = 0x0165;
  16324. t.tccurl = 0x02a8;
  16325. t.tcedilla = 0x0163;
  16326. t.tcheharabic = 0x0686;
  16327. t.tchehfinalarabic = 0xfb7b;
  16328. t.tchehinitialarabic = 0xfb7c;
  16329. t.tchehmedialarabic = 0xfb7d;
  16330. t.tcircle = 0x24e3;
  16331. t.tcircumflexbelow = 0x1e71;
  16332. t.tcommaaccent = 0x0163;
  16333. t.tdieresis = 0x1e97;
  16334. t.tdotaccent = 0x1e6b;
  16335. t.tdotbelow = 0x1e6d;
  16336. t.tecyrillic = 0x0442;
  16337. t.tedescendercyrillic = 0x04ad;
  16338. t.teharabic = 0x062a;
  16339. t.tehfinalarabic = 0xfe96;
  16340. t.tehhahinitialarabic = 0xfca2;
  16341. t.tehhahisolatedarabic = 0xfc0c;
  16342. t.tehinitialarabic = 0xfe97;
  16343. t.tehiragana = 0x3066;
  16344. t.tehjeeminitialarabic = 0xfca1;
  16345. t.tehjeemisolatedarabic = 0xfc0b;
  16346. t.tehmarbutaarabic = 0x0629;
  16347. t.tehmarbutafinalarabic = 0xfe94;
  16348. t.tehmedialarabic = 0xfe98;
  16349. t.tehmeeminitialarabic = 0xfca4;
  16350. t.tehmeemisolatedarabic = 0xfc0e;
  16351. t.tehnoonfinalarabic = 0xfc73;
  16352. t.tekatakana = 0x30c6;
  16353. t.tekatakanahalfwidth = 0xff83;
  16354. t.telephone = 0x2121;
  16355. t.telephoneblack = 0x260e;
  16356. t.telishagedolahebrew = 0x05a0;
  16357. t.telishaqetanahebrew = 0x05a9;
  16358. t.tencircle = 0x2469;
  16359. t.tenideographicparen = 0x3229;
  16360. t.tenparen = 0x247d;
  16361. t.tenperiod = 0x2491;
  16362. t.tenroman = 0x2179;
  16363. t.tesh = 0x02a7;
  16364. t.tet = 0x05d8;
  16365. t.tetdagesh = 0xfb38;
  16366. t.tetdageshhebrew = 0xfb38;
  16367. t.tethebrew = 0x05d8;
  16368. t.tetsecyrillic = 0x04b5;
  16369. t.tevirhebrew = 0x059b;
  16370. t.tevirlefthebrew = 0x059b;
  16371. t.thabengali = 0x09a5;
  16372. t.thadeva = 0x0925;
  16373. t.thagujarati = 0x0aa5;
  16374. t.thagurmukhi = 0x0a25;
  16375. t.thalarabic = 0x0630;
  16376. t.thalfinalarabic = 0xfeac;
  16377. t.thanthakhatlowleftthai = 0xf898;
  16378. t.thanthakhatlowrightthai = 0xf897;
  16379. t.thanthakhatthai = 0x0e4c;
  16380. t.thanthakhatupperleftthai = 0xf896;
  16381. t.theharabic = 0x062b;
  16382. t.thehfinalarabic = 0xfe9a;
  16383. t.thehinitialarabic = 0xfe9b;
  16384. t.thehmedialarabic = 0xfe9c;
  16385. t.thereexists = 0x2203;
  16386. t.therefore = 0x2234;
  16387. t.theta = 0x03b8;
  16388. t.theta1 = 0x03d1;
  16389. t.thetasymbolgreek = 0x03d1;
  16390. t.thieuthacirclekorean = 0x3279;
  16391. t.thieuthaparenkorean = 0x3219;
  16392. t.thieuthcirclekorean = 0x326b;
  16393. t.thieuthkorean = 0x314c;
  16394. t.thieuthparenkorean = 0x320b;
  16395. t.thirteencircle = 0x246c;
  16396. t.thirteenparen = 0x2480;
  16397. t.thirteenperiod = 0x2494;
  16398. t.thonangmonthothai = 0x0e11;
  16399. t.thook = 0x01ad;
  16400. t.thophuthaothai = 0x0e12;
  16401. t.thorn = 0x00fe;
  16402. t.thothahanthai = 0x0e17;
  16403. t.thothanthai = 0x0e10;
  16404. t.thothongthai = 0x0e18;
  16405. t.thothungthai = 0x0e16;
  16406. t.thousandcyrillic = 0x0482;
  16407. t.thousandsseparatorarabic = 0x066c;
  16408. t.thousandsseparatorpersian = 0x066c;
  16409. t.three = 0x0033;
  16410. t.threearabic = 0x0663;
  16411. t.threebengali = 0x09e9;
  16412. t.threecircle = 0x2462;
  16413. t.threecircleinversesansserif = 0x278c;
  16414. t.threedeva = 0x0969;
  16415. t.threeeighths = 0x215c;
  16416. t.threegujarati = 0x0ae9;
  16417. t.threegurmukhi = 0x0a69;
  16418. t.threehackarabic = 0x0663;
  16419. t.threehangzhou = 0x3023;
  16420. t.threeideographicparen = 0x3222;
  16421. t.threeinferior = 0x2083;
  16422. t.threemonospace = 0xff13;
  16423. t.threenumeratorbengali = 0x09f6;
  16424. t.threeoldstyle = 0xf733;
  16425. t.threeparen = 0x2476;
  16426. t.threeperiod = 0x248a;
  16427. t.threepersian = 0x06f3;
  16428. t.threequarters = 0x00be;
  16429. t.threequartersemdash = 0xf6de;
  16430. t.threeroman = 0x2172;
  16431. t.threesuperior = 0x00b3;
  16432. t.threethai = 0x0e53;
  16433. t.thzsquare = 0x3394;
  16434. t.tihiragana = 0x3061;
  16435. t.tikatakana = 0x30c1;
  16436. t.tikatakanahalfwidth = 0xff81;
  16437. t.tikeutacirclekorean = 0x3270;
  16438. t.tikeutaparenkorean = 0x3210;
  16439. t.tikeutcirclekorean = 0x3262;
  16440. t.tikeutkorean = 0x3137;
  16441. t.tikeutparenkorean = 0x3202;
  16442. t.tilde = 0x02dc;
  16443. t.tildebelowcmb = 0x0330;
  16444. t.tildecmb = 0x0303;
  16445. t.tildecomb = 0x0303;
  16446. t.tildedoublecmb = 0x0360;
  16447. t.tildeoperator = 0x223c;
  16448. t.tildeoverlaycmb = 0x0334;
  16449. t.tildeverticalcmb = 0x033e;
  16450. t.timescircle = 0x2297;
  16451. t.tipehahebrew = 0x0596;
  16452. t.tipehalefthebrew = 0x0596;
  16453. t.tippigurmukhi = 0x0a70;
  16454. t.titlocyrilliccmb = 0x0483;
  16455. t.tiwnarmenian = 0x057f;
  16456. t.tlinebelow = 0x1e6f;
  16457. t.tmonospace = 0xff54;
  16458. t.toarmenian = 0x0569;
  16459. t.tohiragana = 0x3068;
  16460. t.tokatakana = 0x30c8;
  16461. t.tokatakanahalfwidth = 0xff84;
  16462. t.tonebarextrahighmod = 0x02e5;
  16463. t.tonebarextralowmod = 0x02e9;
  16464. t.tonebarhighmod = 0x02e6;
  16465. t.tonebarlowmod = 0x02e8;
  16466. t.tonebarmidmod = 0x02e7;
  16467. t.tonefive = 0x01bd;
  16468. t.tonesix = 0x0185;
  16469. t.tonetwo = 0x01a8;
  16470. t.tonos = 0x0384;
  16471. t.tonsquare = 0x3327;
  16472. t.topatakthai = 0x0e0f;
  16473. t.tortoiseshellbracketleft = 0x3014;
  16474. t.tortoiseshellbracketleftsmall = 0xfe5d;
  16475. t.tortoiseshellbracketleftvertical = 0xfe39;
  16476. t.tortoiseshellbracketright = 0x3015;
  16477. t.tortoiseshellbracketrightsmall = 0xfe5e;
  16478. t.tortoiseshellbracketrightvertical = 0xfe3a;
  16479. t.totaothai = 0x0e15;
  16480. t.tpalatalhook = 0x01ab;
  16481. t.tparen = 0x24af;
  16482. t.trademark = 0x2122;
  16483. t.trademarksans = 0xf8ea;
  16484. t.trademarkserif = 0xf6db;
  16485. t.tretroflexhook = 0x0288;
  16486. t.triagdn = 0x25bc;
  16487. t.triaglf = 0x25c4;
  16488. t.triagrt = 0x25ba;
  16489. t.triagup = 0x25b2;
  16490. t.ts = 0x02a6;
  16491. t.tsadi = 0x05e6;
  16492. t.tsadidagesh = 0xfb46;
  16493. t.tsadidageshhebrew = 0xfb46;
  16494. t.tsadihebrew = 0x05e6;
  16495. t.tsecyrillic = 0x0446;
  16496. t.tsere = 0x05b5;
  16497. t.tsere12 = 0x05b5;
  16498. t.tsere1e = 0x05b5;
  16499. t.tsere2b = 0x05b5;
  16500. t.tserehebrew = 0x05b5;
  16501. t.tserenarrowhebrew = 0x05b5;
  16502. t.tserequarterhebrew = 0x05b5;
  16503. t.tserewidehebrew = 0x05b5;
  16504. t.tshecyrillic = 0x045b;
  16505. t.tsuperior = 0xf6f3;
  16506. t.ttabengali = 0x099f;
  16507. t.ttadeva = 0x091f;
  16508. t.ttagujarati = 0x0a9f;
  16509. t.ttagurmukhi = 0x0a1f;
  16510. t.tteharabic = 0x0679;
  16511. t.ttehfinalarabic = 0xfb67;
  16512. t.ttehinitialarabic = 0xfb68;
  16513. t.ttehmedialarabic = 0xfb69;
  16514. t.tthabengali = 0x09a0;
  16515. t.tthadeva = 0x0920;
  16516. t.tthagujarati = 0x0aa0;
  16517. t.tthagurmukhi = 0x0a20;
  16518. t.tturned = 0x0287;
  16519. t.tuhiragana = 0x3064;
  16520. t.tukatakana = 0x30c4;
  16521. t.tukatakanahalfwidth = 0xff82;
  16522. t.tusmallhiragana = 0x3063;
  16523. t.tusmallkatakana = 0x30c3;
  16524. t.tusmallkatakanahalfwidth = 0xff6f;
  16525. t.twelvecircle = 0x246b;
  16526. t.twelveparen = 0x247f;
  16527. t.twelveperiod = 0x2493;
  16528. t.twelveroman = 0x217b;
  16529. t.twentycircle = 0x2473;
  16530. t.twentyhangzhou = 0x5344;
  16531. t.twentyparen = 0x2487;
  16532. t.twentyperiod = 0x249b;
  16533. t.two = 0x0032;
  16534. t.twoarabic = 0x0662;
  16535. t.twobengali = 0x09e8;
  16536. t.twocircle = 0x2461;
  16537. t.twocircleinversesansserif = 0x278b;
  16538. t.twodeva = 0x0968;
  16539. t.twodotenleader = 0x2025;
  16540. t.twodotleader = 0x2025;
  16541. t.twodotleadervertical = 0xfe30;
  16542. t.twogujarati = 0x0ae8;
  16543. t.twogurmukhi = 0x0a68;
  16544. t.twohackarabic = 0x0662;
  16545. t.twohangzhou = 0x3022;
  16546. t.twoideographicparen = 0x3221;
  16547. t.twoinferior = 0x2082;
  16548. t.twomonospace = 0xff12;
  16549. t.twonumeratorbengali = 0x09f5;
  16550. t.twooldstyle = 0xf732;
  16551. t.twoparen = 0x2475;
  16552. t.twoperiod = 0x2489;
  16553. t.twopersian = 0x06f2;
  16554. t.tworoman = 0x2171;
  16555. t.twostroke = 0x01bb;
  16556. t.twosuperior = 0x00b2;
  16557. t.twothai = 0x0e52;
  16558. t.twothirds = 0x2154;
  16559. t.u = 0x0075;
  16560. t.uacute = 0x00fa;
  16561. t.ubar = 0x0289;
  16562. t.ubengali = 0x0989;
  16563. t.ubopomofo = 0x3128;
  16564. t.ubreve = 0x016d;
  16565. t.ucaron = 0x01d4;
  16566. t.ucircle = 0x24e4;
  16567. t.ucircumflex = 0x00fb;
  16568. t.ucircumflexbelow = 0x1e77;
  16569. t.ucyrillic = 0x0443;
  16570. t.udattadeva = 0x0951;
  16571. t.udblacute = 0x0171;
  16572. t.udblgrave = 0x0215;
  16573. t.udeva = 0x0909;
  16574. t.udieresis = 0x00fc;
  16575. t.udieresisacute = 0x01d8;
  16576. t.udieresisbelow = 0x1e73;
  16577. t.udieresiscaron = 0x01da;
  16578. t.udieresiscyrillic = 0x04f1;
  16579. t.udieresisgrave = 0x01dc;
  16580. t.udieresismacron = 0x01d6;
  16581. t.udotbelow = 0x1ee5;
  16582. t.ugrave = 0x00f9;
  16583. t.ugujarati = 0x0a89;
  16584. t.ugurmukhi = 0x0a09;
  16585. t.uhiragana = 0x3046;
  16586. t.uhookabove = 0x1ee7;
  16587. t.uhorn = 0x01b0;
  16588. t.uhornacute = 0x1ee9;
  16589. t.uhorndotbelow = 0x1ef1;
  16590. t.uhorngrave = 0x1eeb;
  16591. t.uhornhookabove = 0x1eed;
  16592. t.uhorntilde = 0x1eef;
  16593. t.uhungarumlaut = 0x0171;
  16594. t.uhungarumlautcyrillic = 0x04f3;
  16595. t.uinvertedbreve = 0x0217;
  16596. t.ukatakana = 0x30a6;
  16597. t.ukatakanahalfwidth = 0xff73;
  16598. t.ukcyrillic = 0x0479;
  16599. t.ukorean = 0x315c;
  16600. t.umacron = 0x016b;
  16601. t.umacroncyrillic = 0x04ef;
  16602. t.umacrondieresis = 0x1e7b;
  16603. t.umatragurmukhi = 0x0a41;
  16604. t.umonospace = 0xff55;
  16605. t.underscore = 0x005f;
  16606. t.underscoredbl = 0x2017;
  16607. t.underscoremonospace = 0xff3f;
  16608. t.underscorevertical = 0xfe33;
  16609. t.underscorewavy = 0xfe4f;
  16610. t.union = 0x222a;
  16611. t.universal = 0x2200;
  16612. t.uogonek = 0x0173;
  16613. t.uparen = 0x24b0;
  16614. t.upblock = 0x2580;
  16615. t.upperdothebrew = 0x05c4;
  16616. t.upsilon = 0x03c5;
  16617. t.upsilondieresis = 0x03cb;
  16618. t.upsilondieresistonos = 0x03b0;
  16619. t.upsilonlatin = 0x028a;
  16620. t.upsilontonos = 0x03cd;
  16621. t.uptackbelowcmb = 0x031d;
  16622. t.uptackmod = 0x02d4;
  16623. t.uragurmukhi = 0x0a73;
  16624. t.uring = 0x016f;
  16625. t.ushortcyrillic = 0x045e;
  16626. t.usmallhiragana = 0x3045;
  16627. t.usmallkatakana = 0x30a5;
  16628. t.usmallkatakanahalfwidth = 0xff69;
  16629. t.ustraightcyrillic = 0x04af;
  16630. t.ustraightstrokecyrillic = 0x04b1;
  16631. t.utilde = 0x0169;
  16632. t.utildeacute = 0x1e79;
  16633. t.utildebelow = 0x1e75;
  16634. t.uubengali = 0x098a;
  16635. t.uudeva = 0x090a;
  16636. t.uugujarati = 0x0a8a;
  16637. t.uugurmukhi = 0x0a0a;
  16638. t.uumatragurmukhi = 0x0a42;
  16639. t.uuvowelsignbengali = 0x09c2;
  16640. t.uuvowelsigndeva = 0x0942;
  16641. t.uuvowelsigngujarati = 0x0ac2;
  16642. t.uvowelsignbengali = 0x09c1;
  16643. t.uvowelsigndeva = 0x0941;
  16644. t.uvowelsigngujarati = 0x0ac1;
  16645. t.v = 0x0076;
  16646. t.vadeva = 0x0935;
  16647. t.vagujarati = 0x0ab5;
  16648. t.vagurmukhi = 0x0a35;
  16649. t.vakatakana = 0x30f7;
  16650. t.vav = 0x05d5;
  16651. t.vavdagesh = 0xfb35;
  16652. t.vavdagesh65 = 0xfb35;
  16653. t.vavdageshhebrew = 0xfb35;
  16654. t.vavhebrew = 0x05d5;
  16655. t.vavholam = 0xfb4b;
  16656. t.vavholamhebrew = 0xfb4b;
  16657. t.vavvavhebrew = 0x05f0;
  16658. t.vavyodhebrew = 0x05f1;
  16659. t.vcircle = 0x24e5;
  16660. t.vdotbelow = 0x1e7f;
  16661. t.vecyrillic = 0x0432;
  16662. t.veharabic = 0x06a4;
  16663. t.vehfinalarabic = 0xfb6b;
  16664. t.vehinitialarabic = 0xfb6c;
  16665. t.vehmedialarabic = 0xfb6d;
  16666. t.vekatakana = 0x30f9;
  16667. t.venus = 0x2640;
  16668. t.verticalbar = 0x007c;
  16669. t.verticallineabovecmb = 0x030d;
  16670. t.verticallinebelowcmb = 0x0329;
  16671. t.verticallinelowmod = 0x02cc;
  16672. t.verticallinemod = 0x02c8;
  16673. t.vewarmenian = 0x057e;
  16674. t.vhook = 0x028b;
  16675. t.vikatakana = 0x30f8;
  16676. t.viramabengali = 0x09cd;
  16677. t.viramadeva = 0x094d;
  16678. t.viramagujarati = 0x0acd;
  16679. t.visargabengali = 0x0983;
  16680. t.visargadeva = 0x0903;
  16681. t.visargagujarati = 0x0a83;
  16682. t.vmonospace = 0xff56;
  16683. t.voarmenian = 0x0578;
  16684. t.voicediterationhiragana = 0x309e;
  16685. t.voicediterationkatakana = 0x30fe;
  16686. t.voicedmarkkana = 0x309b;
  16687. t.voicedmarkkanahalfwidth = 0xff9e;
  16688. t.vokatakana = 0x30fa;
  16689. t.vparen = 0x24b1;
  16690. t.vtilde = 0x1e7d;
  16691. t.vturned = 0x028c;
  16692. t.vuhiragana = 0x3094;
  16693. t.vukatakana = 0x30f4;
  16694. t.w = 0x0077;
  16695. t.wacute = 0x1e83;
  16696. t.waekorean = 0x3159;
  16697. t.wahiragana = 0x308f;
  16698. t.wakatakana = 0x30ef;
  16699. t.wakatakanahalfwidth = 0xff9c;
  16700. t.wakorean = 0x3158;
  16701. t.wasmallhiragana = 0x308e;
  16702. t.wasmallkatakana = 0x30ee;
  16703. t.wattosquare = 0x3357;
  16704. t.wavedash = 0x301c;
  16705. t.wavyunderscorevertical = 0xfe34;
  16706. t.wawarabic = 0x0648;
  16707. t.wawfinalarabic = 0xfeee;
  16708. t.wawhamzaabovearabic = 0x0624;
  16709. t.wawhamzaabovefinalarabic = 0xfe86;
  16710. t.wbsquare = 0x33dd;
  16711. t.wcircle = 0x24e6;
  16712. t.wcircumflex = 0x0175;
  16713. t.wdieresis = 0x1e85;
  16714. t.wdotaccent = 0x1e87;
  16715. t.wdotbelow = 0x1e89;
  16716. t.wehiragana = 0x3091;
  16717. t.weierstrass = 0x2118;
  16718. t.wekatakana = 0x30f1;
  16719. t.wekorean = 0x315e;
  16720. t.weokorean = 0x315d;
  16721. t.wgrave = 0x1e81;
  16722. t.whitebullet = 0x25e6;
  16723. t.whitecircle = 0x25cb;
  16724. t.whitecircleinverse = 0x25d9;
  16725. t.whitecornerbracketleft = 0x300e;
  16726. t.whitecornerbracketleftvertical = 0xfe43;
  16727. t.whitecornerbracketright = 0x300f;
  16728. t.whitecornerbracketrightvertical = 0xfe44;
  16729. t.whitediamond = 0x25c7;
  16730. t.whitediamondcontainingblacksmalldiamond = 0x25c8;
  16731. t.whitedownpointingsmalltriangle = 0x25bf;
  16732. t.whitedownpointingtriangle = 0x25bd;
  16733. t.whiteleftpointingsmalltriangle = 0x25c3;
  16734. t.whiteleftpointingtriangle = 0x25c1;
  16735. t.whitelenticularbracketleft = 0x3016;
  16736. t.whitelenticularbracketright = 0x3017;
  16737. t.whiterightpointingsmalltriangle = 0x25b9;
  16738. t.whiterightpointingtriangle = 0x25b7;
  16739. t.whitesmallsquare = 0x25ab;
  16740. t.whitesmilingface = 0x263a;
  16741. t.whitesquare = 0x25a1;
  16742. t.whitestar = 0x2606;
  16743. t.whitetelephone = 0x260f;
  16744. t.whitetortoiseshellbracketleft = 0x3018;
  16745. t.whitetortoiseshellbracketright = 0x3019;
  16746. t.whiteuppointingsmalltriangle = 0x25b5;
  16747. t.whiteuppointingtriangle = 0x25b3;
  16748. t.wihiragana = 0x3090;
  16749. t.wikatakana = 0x30f0;
  16750. t.wikorean = 0x315f;
  16751. t.wmonospace = 0xff57;
  16752. t.wohiragana = 0x3092;
  16753. t.wokatakana = 0x30f2;
  16754. t.wokatakanahalfwidth = 0xff66;
  16755. t.won = 0x20a9;
  16756. t.wonmonospace = 0xffe6;
  16757. t.wowaenthai = 0x0e27;
  16758. t.wparen = 0x24b2;
  16759. t.wring = 0x1e98;
  16760. t.wsuperior = 0x02b7;
  16761. t.wturned = 0x028d;
  16762. t.wynn = 0x01bf;
  16763. t.x = 0x0078;
  16764. t.xabovecmb = 0x033d;
  16765. t.xbopomofo = 0x3112;
  16766. t.xcircle = 0x24e7;
  16767. t.xdieresis = 0x1e8d;
  16768. t.xdotaccent = 0x1e8b;
  16769. t.xeharmenian = 0x056d;
  16770. t.xi = 0x03be;
  16771. t.xmonospace = 0xff58;
  16772. t.xparen = 0x24b3;
  16773. t.xsuperior = 0x02e3;
  16774. t.y = 0x0079;
  16775. t.yaadosquare = 0x334e;
  16776. t.yabengali = 0x09af;
  16777. t.yacute = 0x00fd;
  16778. t.yadeva = 0x092f;
  16779. t.yaekorean = 0x3152;
  16780. t.yagujarati = 0x0aaf;
  16781. t.yagurmukhi = 0x0a2f;
  16782. t.yahiragana = 0x3084;
  16783. t.yakatakana = 0x30e4;
  16784. t.yakatakanahalfwidth = 0xff94;
  16785. t.yakorean = 0x3151;
  16786. t.yamakkanthai = 0x0e4e;
  16787. t.yasmallhiragana = 0x3083;
  16788. t.yasmallkatakana = 0x30e3;
  16789. t.yasmallkatakanahalfwidth = 0xff6c;
  16790. t.yatcyrillic = 0x0463;
  16791. t.ycircle = 0x24e8;
  16792. t.ycircumflex = 0x0177;
  16793. t.ydieresis = 0x00ff;
  16794. t.ydotaccent = 0x1e8f;
  16795. t.ydotbelow = 0x1ef5;
  16796. t.yeharabic = 0x064a;
  16797. t.yehbarreearabic = 0x06d2;
  16798. t.yehbarreefinalarabic = 0xfbaf;
  16799. t.yehfinalarabic = 0xfef2;
  16800. t.yehhamzaabovearabic = 0x0626;
  16801. t.yehhamzaabovefinalarabic = 0xfe8a;
  16802. t.yehhamzaaboveinitialarabic = 0xfe8b;
  16803. t.yehhamzaabovemedialarabic = 0xfe8c;
  16804. t.yehinitialarabic = 0xfef3;
  16805. t.yehmedialarabic = 0xfef4;
  16806. t.yehmeeminitialarabic = 0xfcdd;
  16807. t.yehmeemisolatedarabic = 0xfc58;
  16808. t.yehnoonfinalarabic = 0xfc94;
  16809. t.yehthreedotsbelowarabic = 0x06d1;
  16810. t.yekorean = 0x3156;
  16811. t.yen = 0x00a5;
  16812. t.yenmonospace = 0xffe5;
  16813. t.yeokorean = 0x3155;
  16814. t.yeorinhieuhkorean = 0x3186;
  16815. t.yerahbenyomohebrew = 0x05aa;
  16816. t.yerahbenyomolefthebrew = 0x05aa;
  16817. t.yericyrillic = 0x044b;
  16818. t.yerudieresiscyrillic = 0x04f9;
  16819. t.yesieungkorean = 0x3181;
  16820. t.yesieungpansioskorean = 0x3183;
  16821. t.yesieungsioskorean = 0x3182;
  16822. t.yetivhebrew = 0x059a;
  16823. t.ygrave = 0x1ef3;
  16824. t.yhook = 0x01b4;
  16825. t.yhookabove = 0x1ef7;
  16826. t.yiarmenian = 0x0575;
  16827. t.yicyrillic = 0x0457;
  16828. t.yikorean = 0x3162;
  16829. t.yinyang = 0x262f;
  16830. t.yiwnarmenian = 0x0582;
  16831. t.ymonospace = 0xff59;
  16832. t.yod = 0x05d9;
  16833. t.yoddagesh = 0xfb39;
  16834. t.yoddageshhebrew = 0xfb39;
  16835. t.yodhebrew = 0x05d9;
  16836. t.yodyodhebrew = 0x05f2;
  16837. t.yodyodpatahhebrew = 0xfb1f;
  16838. t.yohiragana = 0x3088;
  16839. t.yoikorean = 0x3189;
  16840. t.yokatakana = 0x30e8;
  16841. t.yokatakanahalfwidth = 0xff96;
  16842. t.yokorean = 0x315b;
  16843. t.yosmallhiragana = 0x3087;
  16844. t.yosmallkatakana = 0x30e7;
  16845. t.yosmallkatakanahalfwidth = 0xff6e;
  16846. t.yotgreek = 0x03f3;
  16847. t.yoyaekorean = 0x3188;
  16848. t.yoyakorean = 0x3187;
  16849. t.yoyakthai = 0x0e22;
  16850. t.yoyingthai = 0x0e0d;
  16851. t.yparen = 0x24b4;
  16852. t.ypogegrammeni = 0x037a;
  16853. t.ypogegrammenigreekcmb = 0x0345;
  16854. t.yr = 0x01a6;
  16855. t.yring = 0x1e99;
  16856. t.ysuperior = 0x02b8;
  16857. t.ytilde = 0x1ef9;
  16858. t.yturned = 0x028e;
  16859. t.yuhiragana = 0x3086;
  16860. t.yuikorean = 0x318c;
  16861. t.yukatakana = 0x30e6;
  16862. t.yukatakanahalfwidth = 0xff95;
  16863. t.yukorean = 0x3160;
  16864. t.yusbigcyrillic = 0x046b;
  16865. t.yusbigiotifiedcyrillic = 0x046d;
  16866. t.yuslittlecyrillic = 0x0467;
  16867. t.yuslittleiotifiedcyrillic = 0x0469;
  16868. t.yusmallhiragana = 0x3085;
  16869. t.yusmallkatakana = 0x30e5;
  16870. t.yusmallkatakanahalfwidth = 0xff6d;
  16871. t.yuyekorean = 0x318b;
  16872. t.yuyeokorean = 0x318a;
  16873. t.yyabengali = 0x09df;
  16874. t.yyadeva = 0x095f;
  16875. t.z = 0x007a;
  16876. t.zaarmenian = 0x0566;
  16877. t.zacute = 0x017a;
  16878. t.zadeva = 0x095b;
  16879. t.zagurmukhi = 0x0a5b;
  16880. t.zaharabic = 0x0638;
  16881. t.zahfinalarabic = 0xfec6;
  16882. t.zahinitialarabic = 0xfec7;
  16883. t.zahiragana = 0x3056;
  16884. t.zahmedialarabic = 0xfec8;
  16885. t.zainarabic = 0x0632;
  16886. t.zainfinalarabic = 0xfeb0;
  16887. t.zakatakana = 0x30b6;
  16888. t.zaqefgadolhebrew = 0x0595;
  16889. t.zaqefqatanhebrew = 0x0594;
  16890. t.zarqahebrew = 0x0598;
  16891. t.zayin = 0x05d6;
  16892. t.zayindagesh = 0xfb36;
  16893. t.zayindageshhebrew = 0xfb36;
  16894. t.zayinhebrew = 0x05d6;
  16895. t.zbopomofo = 0x3117;
  16896. t.zcaron = 0x017e;
  16897. t.zcircle = 0x24e9;
  16898. t.zcircumflex = 0x1e91;
  16899. t.zcurl = 0x0291;
  16900. t.zdot = 0x017c;
  16901. t.zdotaccent = 0x017c;
  16902. t.zdotbelow = 0x1e93;
  16903. t.zecyrillic = 0x0437;
  16904. t.zedescendercyrillic = 0x0499;
  16905. t.zedieresiscyrillic = 0x04df;
  16906. t.zehiragana = 0x305c;
  16907. t.zekatakana = 0x30bc;
  16908. t.zero = 0x0030;
  16909. t.zeroarabic = 0x0660;
  16910. t.zerobengali = 0x09e6;
  16911. t.zerodeva = 0x0966;
  16912. t.zerogujarati = 0x0ae6;
  16913. t.zerogurmukhi = 0x0a66;
  16914. t.zerohackarabic = 0x0660;
  16915. t.zeroinferior = 0x2080;
  16916. t.zeromonospace = 0xff10;
  16917. t.zerooldstyle = 0xf730;
  16918. t.zeropersian = 0x06f0;
  16919. t.zerosuperior = 0x2070;
  16920. t.zerothai = 0x0e50;
  16921. t.zerowidthjoiner = 0xfeff;
  16922. t.zerowidthnonjoiner = 0x200c;
  16923. t.zerowidthspace = 0x200b;
  16924. t.zeta = 0x03b6;
  16925. t.zhbopomofo = 0x3113;
  16926. t.zhearmenian = 0x056a;
  16927. t.zhebrevecyrillic = 0x04c2;
  16928. t.zhecyrillic = 0x0436;
  16929. t.zhedescendercyrillic = 0x0497;
  16930. t.zhedieresiscyrillic = 0x04dd;
  16931. t.zihiragana = 0x3058;
  16932. t.zikatakana = 0x30b8;
  16933. t.zinorhebrew = 0x05ae;
  16934. t.zlinebelow = 0x1e95;
  16935. t.zmonospace = 0xff5a;
  16936. t.zohiragana = 0x305e;
  16937. t.zokatakana = 0x30be;
  16938. t.zparen = 0x24b5;
  16939. t.zretroflexhook = 0x0290;
  16940. t.zstroke = 0x01b6;
  16941. t.zuhiragana = 0x305a;
  16942. t.zukatakana = 0x30ba;
  16943. t[".notdef"] = 0x0000;
  16944. t.angbracketleftbig = 0x2329;
  16945. t.angbracketleftBig = 0x2329;
  16946. t.angbracketleftbigg = 0x2329;
  16947. t.angbracketleftBigg = 0x2329;
  16948. t.angbracketrightBig = 0x232a;
  16949. t.angbracketrightbig = 0x232a;
  16950. t.angbracketrightBigg = 0x232a;
  16951. t.angbracketrightbigg = 0x232a;
  16952. t.arrowhookleft = 0x21aa;
  16953. t.arrowhookright = 0x21a9;
  16954. t.arrowlefttophalf = 0x21bc;
  16955. t.arrowleftbothalf = 0x21bd;
  16956. t.arrownortheast = 0x2197;
  16957. t.arrownorthwest = 0x2196;
  16958. t.arrowrighttophalf = 0x21c0;
  16959. t.arrowrightbothalf = 0x21c1;
  16960. t.arrowsoutheast = 0x2198;
  16961. t.arrowsouthwest = 0x2199;
  16962. t.backslashbig = 0x2216;
  16963. t.backslashBig = 0x2216;
  16964. t.backslashBigg = 0x2216;
  16965. t.backslashbigg = 0x2216;
  16966. t.bardbl = 0x2016;
  16967. t.bracehtipdownleft = 0xfe37;
  16968. t.bracehtipdownright = 0xfe37;
  16969. t.bracehtipupleft = 0xfe38;
  16970. t.bracehtipupright = 0xfe38;
  16971. t.braceleftBig = 0x007b;
  16972. t.braceleftbig = 0x007b;
  16973. t.braceleftbigg = 0x007b;
  16974. t.braceleftBigg = 0x007b;
  16975. t.bracerightBig = 0x007d;
  16976. t.bracerightbig = 0x007d;
  16977. t.bracerightbigg = 0x007d;
  16978. t.bracerightBigg = 0x007d;
  16979. t.bracketleftbig = 0x005b;
  16980. t.bracketleftBig = 0x005b;
  16981. t.bracketleftbigg = 0x005b;
  16982. t.bracketleftBigg = 0x005b;
  16983. t.bracketrightBig = 0x005d;
  16984. t.bracketrightbig = 0x005d;
  16985. t.bracketrightbigg = 0x005d;
  16986. t.bracketrightBigg = 0x005d;
  16987. t.ceilingleftbig = 0x2308;
  16988. t.ceilingleftBig = 0x2308;
  16989. t.ceilingleftBigg = 0x2308;
  16990. t.ceilingleftbigg = 0x2308;
  16991. t.ceilingrightbig = 0x2309;
  16992. t.ceilingrightBig = 0x2309;
  16993. t.ceilingrightbigg = 0x2309;
  16994. t.ceilingrightBigg = 0x2309;
  16995. t.circledotdisplay = 0x2299;
  16996. t.circledottext = 0x2299;
  16997. t.circlemultiplydisplay = 0x2297;
  16998. t.circlemultiplytext = 0x2297;
  16999. t.circleplusdisplay = 0x2295;
  17000. t.circleplustext = 0x2295;
  17001. t.contintegraldisplay = 0x222e;
  17002. t.contintegraltext = 0x222e;
  17003. t.coproductdisplay = 0x2210;
  17004. t.coproducttext = 0x2210;
  17005. t.floorleftBig = 0x230a;
  17006. t.floorleftbig = 0x230a;
  17007. t.floorleftbigg = 0x230a;
  17008. t.floorleftBigg = 0x230a;
  17009. t.floorrightbig = 0x230b;
  17010. t.floorrightBig = 0x230b;
  17011. t.floorrightBigg = 0x230b;
  17012. t.floorrightbigg = 0x230b;
  17013. t.hatwide = 0x0302;
  17014. t.hatwider = 0x0302;
  17015. t.hatwidest = 0x0302;
  17016. t.intercal = 0x1d40;
  17017. t.integraldisplay = 0x222b;
  17018. t.integraltext = 0x222b;
  17019. t.intersectiondisplay = 0x22c2;
  17020. t.intersectiontext = 0x22c2;
  17021. t.logicalanddisplay = 0x2227;
  17022. t.logicalandtext = 0x2227;
  17023. t.logicalordisplay = 0x2228;
  17024. t.logicalortext = 0x2228;
  17025. t.parenleftBig = 0x0028;
  17026. t.parenleftbig = 0x0028;
  17027. t.parenleftBigg = 0x0028;
  17028. t.parenleftbigg = 0x0028;
  17029. t.parenrightBig = 0x0029;
  17030. t.parenrightbig = 0x0029;
  17031. t.parenrightBigg = 0x0029;
  17032. t.parenrightbigg = 0x0029;
  17033. t.prime = 0x2032;
  17034. t.productdisplay = 0x220f;
  17035. t.producttext = 0x220f;
  17036. t.radicalbig = 0x221a;
  17037. t.radicalBig = 0x221a;
  17038. t.radicalBigg = 0x221a;
  17039. t.radicalbigg = 0x221a;
  17040. t.radicalbt = 0x221a;
  17041. t.radicaltp = 0x221a;
  17042. t.radicalvertex = 0x221a;
  17043. t.slashbig = 0x002f;
  17044. t.slashBig = 0x002f;
  17045. t.slashBigg = 0x002f;
  17046. t.slashbigg = 0x002f;
  17047. t.summationdisplay = 0x2211;
  17048. t.summationtext = 0x2211;
  17049. t.tildewide = 0x02dc;
  17050. t.tildewider = 0x02dc;
  17051. t.tildewidest = 0x02dc;
  17052. t.uniondisplay = 0x22c3;
  17053. t.unionmultidisplay = 0x228e;
  17054. t.unionmultitext = 0x228e;
  17055. t.unionsqdisplay = 0x2294;
  17056. t.unionsqtext = 0x2294;
  17057. t.uniontext = 0x22c3;
  17058. t.vextenddouble = 0x2225;
  17059. t.vextendsingle = 0x2223;
  17060. });
  17061. const getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  17062. t.space = 0x0020;
  17063. t.a1 = 0x2701;
  17064. t.a2 = 0x2702;
  17065. t.a202 = 0x2703;
  17066. t.a3 = 0x2704;
  17067. t.a4 = 0x260e;
  17068. t.a5 = 0x2706;
  17069. t.a119 = 0x2707;
  17070. t.a118 = 0x2708;
  17071. t.a117 = 0x2709;
  17072. t.a11 = 0x261b;
  17073. t.a12 = 0x261e;
  17074. t.a13 = 0x270c;
  17075. t.a14 = 0x270d;
  17076. t.a15 = 0x270e;
  17077. t.a16 = 0x270f;
  17078. t.a105 = 0x2710;
  17079. t.a17 = 0x2711;
  17080. t.a18 = 0x2712;
  17081. t.a19 = 0x2713;
  17082. t.a20 = 0x2714;
  17083. t.a21 = 0x2715;
  17084. t.a22 = 0x2716;
  17085. t.a23 = 0x2717;
  17086. t.a24 = 0x2718;
  17087. t.a25 = 0x2719;
  17088. t.a26 = 0x271a;
  17089. t.a27 = 0x271b;
  17090. t.a28 = 0x271c;
  17091. t.a6 = 0x271d;
  17092. t.a7 = 0x271e;
  17093. t.a8 = 0x271f;
  17094. t.a9 = 0x2720;
  17095. t.a10 = 0x2721;
  17096. t.a29 = 0x2722;
  17097. t.a30 = 0x2723;
  17098. t.a31 = 0x2724;
  17099. t.a32 = 0x2725;
  17100. t.a33 = 0x2726;
  17101. t.a34 = 0x2727;
  17102. t.a35 = 0x2605;
  17103. t.a36 = 0x2729;
  17104. t.a37 = 0x272a;
  17105. t.a38 = 0x272b;
  17106. t.a39 = 0x272c;
  17107. t.a40 = 0x272d;
  17108. t.a41 = 0x272e;
  17109. t.a42 = 0x272f;
  17110. t.a43 = 0x2730;
  17111. t.a44 = 0x2731;
  17112. t.a45 = 0x2732;
  17113. t.a46 = 0x2733;
  17114. t.a47 = 0x2734;
  17115. t.a48 = 0x2735;
  17116. t.a49 = 0x2736;
  17117. t.a50 = 0x2737;
  17118. t.a51 = 0x2738;
  17119. t.a52 = 0x2739;
  17120. t.a53 = 0x273a;
  17121. t.a54 = 0x273b;
  17122. t.a55 = 0x273c;
  17123. t.a56 = 0x273d;
  17124. t.a57 = 0x273e;
  17125. t.a58 = 0x273f;
  17126. t.a59 = 0x2740;
  17127. t.a60 = 0x2741;
  17128. t.a61 = 0x2742;
  17129. t.a62 = 0x2743;
  17130. t.a63 = 0x2744;
  17131. t.a64 = 0x2745;
  17132. t.a65 = 0x2746;
  17133. t.a66 = 0x2747;
  17134. t.a67 = 0x2748;
  17135. t.a68 = 0x2749;
  17136. t.a69 = 0x274a;
  17137. t.a70 = 0x274b;
  17138. t.a71 = 0x25cf;
  17139. t.a72 = 0x274d;
  17140. t.a73 = 0x25a0;
  17141. t.a74 = 0x274f;
  17142. t.a203 = 0x2750;
  17143. t.a75 = 0x2751;
  17144. t.a204 = 0x2752;
  17145. t.a76 = 0x25b2;
  17146. t.a77 = 0x25bc;
  17147. t.a78 = 0x25c6;
  17148. t.a79 = 0x2756;
  17149. t.a81 = 0x25d7;
  17150. t.a82 = 0x2758;
  17151. t.a83 = 0x2759;
  17152. t.a84 = 0x275a;
  17153. t.a97 = 0x275b;
  17154. t.a98 = 0x275c;
  17155. t.a99 = 0x275d;
  17156. t.a100 = 0x275e;
  17157. t.a101 = 0x2761;
  17158. t.a102 = 0x2762;
  17159. t.a103 = 0x2763;
  17160. t.a104 = 0x2764;
  17161. t.a106 = 0x2765;
  17162. t.a107 = 0x2766;
  17163. t.a108 = 0x2767;
  17164. t.a112 = 0x2663;
  17165. t.a111 = 0x2666;
  17166. t.a110 = 0x2665;
  17167. t.a109 = 0x2660;
  17168. t.a120 = 0x2460;
  17169. t.a121 = 0x2461;
  17170. t.a122 = 0x2462;
  17171. t.a123 = 0x2463;
  17172. t.a124 = 0x2464;
  17173. t.a125 = 0x2465;
  17174. t.a126 = 0x2466;
  17175. t.a127 = 0x2467;
  17176. t.a128 = 0x2468;
  17177. t.a129 = 0x2469;
  17178. t.a130 = 0x2776;
  17179. t.a131 = 0x2777;
  17180. t.a132 = 0x2778;
  17181. t.a133 = 0x2779;
  17182. t.a134 = 0x277a;
  17183. t.a135 = 0x277b;
  17184. t.a136 = 0x277c;
  17185. t.a137 = 0x277d;
  17186. t.a138 = 0x277e;
  17187. t.a139 = 0x277f;
  17188. t.a140 = 0x2780;
  17189. t.a141 = 0x2781;
  17190. t.a142 = 0x2782;
  17191. t.a143 = 0x2783;
  17192. t.a144 = 0x2784;
  17193. t.a145 = 0x2785;
  17194. t.a146 = 0x2786;
  17195. t.a147 = 0x2787;
  17196. t.a148 = 0x2788;
  17197. t.a149 = 0x2789;
  17198. t.a150 = 0x278a;
  17199. t.a151 = 0x278b;
  17200. t.a152 = 0x278c;
  17201. t.a153 = 0x278d;
  17202. t.a154 = 0x278e;
  17203. t.a155 = 0x278f;
  17204. t.a156 = 0x2790;
  17205. t.a157 = 0x2791;
  17206. t.a158 = 0x2792;
  17207. t.a159 = 0x2793;
  17208. t.a160 = 0x2794;
  17209. t.a161 = 0x2192;
  17210. t.a163 = 0x2194;
  17211. t.a164 = 0x2195;
  17212. t.a196 = 0x2798;
  17213. t.a165 = 0x2799;
  17214. t.a192 = 0x279a;
  17215. t.a166 = 0x279b;
  17216. t.a167 = 0x279c;
  17217. t.a168 = 0x279d;
  17218. t.a169 = 0x279e;
  17219. t.a170 = 0x279f;
  17220. t.a171 = 0x27a0;
  17221. t.a172 = 0x27a1;
  17222. t.a173 = 0x27a2;
  17223. t.a162 = 0x27a3;
  17224. t.a174 = 0x27a4;
  17225. t.a175 = 0x27a5;
  17226. t.a176 = 0x27a6;
  17227. t.a177 = 0x27a7;
  17228. t.a178 = 0x27a8;
  17229. t.a179 = 0x27a9;
  17230. t.a193 = 0x27aa;
  17231. t.a180 = 0x27ab;
  17232. t.a199 = 0x27ac;
  17233. t.a181 = 0x27ad;
  17234. t.a200 = 0x27ae;
  17235. t.a182 = 0x27af;
  17236. t.a201 = 0x27b1;
  17237. t.a183 = 0x27b2;
  17238. t.a184 = 0x27b3;
  17239. t.a197 = 0x27b4;
  17240. t.a185 = 0x27b5;
  17241. t.a194 = 0x27b6;
  17242. t.a198 = 0x27b7;
  17243. t.a186 = 0x27b8;
  17244. t.a195 = 0x27b9;
  17245. t.a187 = 0x27ba;
  17246. t.a188 = 0x27bb;
  17247. t.a189 = 0x27bc;
  17248. t.a190 = 0x27bd;
  17249. t.a191 = 0x27be;
  17250. t.a89 = 0x2768;
  17251. t.a90 = 0x2769;
  17252. t.a93 = 0x276a;
  17253. t.a94 = 0x276b;
  17254. t.a91 = 0x276c;
  17255. t.a92 = 0x276d;
  17256. t.a205 = 0x276e;
  17257. t.a85 = 0x276f;
  17258. t.a206 = 0x2770;
  17259. t.a86 = 0x2771;
  17260. t.a87 = 0x2772;
  17261. t.a88 = 0x2773;
  17262. t.a95 = 0x2774;
  17263. t.a96 = 0x2775;
  17264. t[".notdef"] = 0x0000;
  17265. });
  17266. ;// CONCATENATED MODULE: ./src/core/unicode.js
  17267. const getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17268. t[63721] = 0x00a9;
  17269. t[63193] = 0x00a9;
  17270. t[63720] = 0x00ae;
  17271. t[63194] = 0x00ae;
  17272. t[63722] = 0x2122;
  17273. t[63195] = 0x2122;
  17274. t[63729] = 0x23a7;
  17275. t[63730] = 0x23a8;
  17276. t[63731] = 0x23a9;
  17277. t[63740] = 0x23ab;
  17278. t[63741] = 0x23ac;
  17279. t[63742] = 0x23ad;
  17280. t[63726] = 0x23a1;
  17281. t[63727] = 0x23a2;
  17282. t[63728] = 0x23a3;
  17283. t[63737] = 0x23a4;
  17284. t[63738] = 0x23a5;
  17285. t[63739] = 0x23a6;
  17286. t[63723] = 0x239b;
  17287. t[63724] = 0x239c;
  17288. t[63725] = 0x239d;
  17289. t[63734] = 0x239e;
  17290. t[63735] = 0x239f;
  17291. t[63736] = 0x23a0;
  17292. });
  17293. function mapSpecialUnicodeValues(code) {
  17294. if (code >= 0xfff0 && code <= 0xffff) {
  17295. return 0;
  17296. } else if (code >= 0xf600 && code <= 0xf8ff) {
  17297. return getSpecialPUASymbols()[code] || code;
  17298. } else if (code === 0x00ad) {
  17299. return 0x002d;
  17300. }
  17301. return code;
  17302. }
  17303. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17304. let unicode = glyphsUnicodeMap[name];
  17305. if (unicode !== undefined) {
  17306. return unicode;
  17307. }
  17308. if (!name) {
  17309. return -1;
  17310. }
  17311. if (name[0] === "u") {
  17312. const nameLen = name.length;
  17313. let hexStr;
  17314. if (nameLen === 7 && name[1] === "n" && name[2] === "i") {
  17315. hexStr = name.substring(3);
  17316. } else if (nameLen >= 5 && nameLen <= 7) {
  17317. hexStr = name.substring(1);
  17318. } else {
  17319. return -1;
  17320. }
  17321. if (hexStr === hexStr.toUpperCase()) {
  17322. unicode = parseInt(hexStr, 16);
  17323. if (unicode >= 0) {
  17324. return unicode;
  17325. }
  17326. }
  17327. }
  17328. return -1;
  17329. }
  17330. const UnicodeRanges = [[0x0000, 0x007f], [0x0080, 0x00ff], [0x0100, 0x017f], [0x0180, 0x024f], [0x0250, 0x02af, 0x1d00, 0x1d7f, 0x1d80, 0x1dbf], [0x02b0, 0x02ff, 0xa700, 0xa71f], [0x0300, 0x036f, 0x1dc0, 0x1dff], [0x0370, 0x03ff], [0x2c80, 0x2cff], [0x0400, 0x04ff, 0x0500, 0x052f, 0x2de0, 0x2dff, 0xa640, 0xa69f], [0x0530, 0x058f], [0x0590, 0x05ff], [0xa500, 0xa63f], [0x0600, 0x06ff, 0x0750, 0x077f], [0x07c0, 0x07ff], [0x0900, 0x097f], [0x0980, 0x09ff], [0x0a00, 0x0a7f], [0x0a80, 0x0aff], [0x0b00, 0x0b7f], [0x0b80, 0x0bff], [0x0c00, 0x0c7f], [0x0c80, 0x0cff], [0x0d00, 0x0d7f], [0x0e00, 0x0e7f], [0x0e80, 0x0eff], [0x10a0, 0x10ff, 0x2d00, 0x2d2f], [0x1b00, 0x1b7f], [0x1100, 0x11ff], [0x1e00, 0x1eff, 0x2c60, 0x2c7f, 0xa720, 0xa7ff], [0x1f00, 0x1fff], [0x2000, 0x206f, 0x2e00, 0x2e7f], [0x2070, 0x209f], [0x20a0, 0x20cf], [0x20d0, 0x20ff], [0x2100, 0x214f], [0x2150, 0x218f], [0x2190, 0x21ff, 0x27f0, 0x27ff, 0x2900, 0x297f, 0x2b00, 0x2bff], [0x2200, 0x22ff, 0x2a00, 0x2aff, 0x27c0, 0x27ef, 0x2980, 0x29ff], [0x2300, 0x23ff], [0x2400, 0x243f], [0x2440, 0x245f], [0x2460, 0x24ff], [0x2500, 0x257f], [0x2580, 0x259f], [0x25a0, 0x25ff], [0x2600, 0x26ff], [0x2700, 0x27bf], [0x3000, 0x303f], [0x3040, 0x309f], [0x30a0, 0x30ff, 0x31f0, 0x31ff], [0x3100, 0x312f, 0x31a0, 0x31bf], [0x3130, 0x318f], [0xa840, 0xa87f], [0x3200, 0x32ff], [0x3300, 0x33ff], [0xac00, 0xd7af], [0xd800, 0xdfff], [0x10900, 0x1091f], [0x4e00, 0x9fff, 0x2e80, 0x2eff, 0x2f00, 0x2fdf, 0x2ff0, 0x2fff, 0x3400, 0x4dbf, 0x20000, 0x2a6df, 0x3190, 0x319f], [0xe000, 0xf8ff], [0x31c0, 0x31ef, 0xf900, 0xfaff, 0x2f800, 0x2fa1f], [0xfb00, 0xfb4f], [0xfb50, 0xfdff], [0xfe20, 0xfe2f], [0xfe10, 0xfe1f], [0xfe50, 0xfe6f], [0xfe70, 0xfeff], [0xff00, 0xffef], [0xfff0, 0xffff], [0x0f00, 0x0fff], [0x0700, 0x074f], [0x0780, 0x07bf], [0x0d80, 0x0dff], [0x1000, 0x109f], [0x1200, 0x137f, 0x1380, 0x139f, 0x2d80, 0x2ddf], [0x13a0, 0x13ff], [0x1400, 0x167f], [0x1680, 0x169f], [0x16a0, 0x16ff], [0x1780, 0x17ff], [0x1800, 0x18af], [0x2800, 0x28ff], [0xa000, 0xa48f], [0x1700, 0x171f, 0x1720, 0x173f, 0x1740, 0x175f, 0x1760, 0x177f], [0x10300, 0x1032f], [0x10330, 0x1034f], [0x10400, 0x1044f], [0x1d000, 0x1d0ff, 0x1d100, 0x1d1ff, 0x1d200, 0x1d24f], [0x1d400, 0x1d7ff], [0xff000, 0xffffd], [0xfe00, 0xfe0f, 0xe0100, 0xe01ef], [0xe0000, 0xe007f], [0x1900, 0x194f], [0x1950, 0x197f], [0x1980, 0x19df], [0x1a00, 0x1a1f], [0x2c00, 0x2c5f], [0x2d30, 0x2d7f], [0x4dc0, 0x4dff], [0xa800, 0xa82f], [0x10000, 0x1007f, 0x10080, 0x100ff, 0x10100, 0x1013f], [0x10140, 0x1018f], [0x10380, 0x1039f], [0x103a0, 0x103df], [0x10450, 0x1047f], [0x10480, 0x104af], [0x10800, 0x1083f], [0x10a00, 0x10a5f], [0x1d300, 0x1d35f], [0x12000, 0x123ff, 0x12400, 0x1247f], [0x1d360, 0x1d37f], [0x1b80, 0x1bbf], [0x1c00, 0x1c4f], [0x1c50, 0x1c7f], [0xa880, 0xa8df], [0xa900, 0xa92f], [0xa930, 0xa95f], [0xaa00, 0xaa5f], [0x10190, 0x101cf], [0x101d0, 0x101ff], [0x102a0, 0x102df, 0x10280, 0x1029f, 0x10920, 0x1093f], [0x1f030, 0x1f09f, 0x1f000, 0x1f02f]];
  17331. function getUnicodeRangeFor(value, lastPosition = -1) {
  17332. if (lastPosition !== -1) {
  17333. const range = UnicodeRanges[lastPosition];
  17334. for (let i = 0, ii = range.length; i < ii; i += 2) {
  17335. if (value >= range[i] && value <= range[i + 1]) {
  17336. return lastPosition;
  17337. }
  17338. }
  17339. }
  17340. for (let i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17341. const range = UnicodeRanges[i];
  17342. for (let j = 0, jj = range.length; j < jj; j += 2) {
  17343. if (value >= range[j] && value <= range[j + 1]) {
  17344. return i;
  17345. }
  17346. }
  17347. }
  17348. return -1;
  17349. }
  17350. const SpecialCharRegExp = new RegExp("^(\\s)|(\\p{Mn})|(\\p{Cf})$", "u");
  17351. const CategoryCache = new Map();
  17352. function getCharUnicodeCategory(char) {
  17353. const cachedCategory = CategoryCache.get(char);
  17354. if (cachedCategory) {
  17355. return cachedCategory;
  17356. }
  17357. const groups = char.match(SpecialCharRegExp);
  17358. const category = {
  17359. isWhitespace: !!groups?.[1],
  17360. isZeroWidthDiacritic: !!groups?.[2],
  17361. isInvisibleFormatMark: !!groups?.[3]
  17362. };
  17363. CategoryCache.set(char, category);
  17364. return category;
  17365. }
  17366. function clearUnicodeCaches() {
  17367. CategoryCache.clear();
  17368. }
  17369. ;// CONCATENATED MODULE: ./src/core/fonts_utils.js
  17370. const SEAC_ANALYSIS_ENABLED = true;
  17371. const FontFlags = {
  17372. FixedPitch: 1,
  17373. Serif: 2,
  17374. Symbolic: 4,
  17375. Script: 8,
  17376. Nonsymbolic: 32,
  17377. Italic: 64,
  17378. AllCap: 65536,
  17379. SmallCap: 131072,
  17380. ForceBold: 262144
  17381. };
  17382. const MacStandardGlyphOrdering = [".notdef", ".null", "nonmarkingreturn", "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quotesingle", "parenleft", "parenright", "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "grave", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Adieresis", "Aring", "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis", "aacute", "agrave", "acircumflex", "adieresis", "atilde", "aring", "ccedilla", "eacute", "egrave", "ecircumflex", "edieresis", "iacute", "igrave", "icircumflex", "idieresis", "ntilde", "oacute", "ograve", "ocircumflex", "odieresis", "otilde", "uacute", "ugrave", "ucircumflex", "udieresis", "dagger", "degree", "cent", "sterling", "section", "bullet", "paragraph", "germandbls", "registered", "copyright", "trademark", "acute", "dieresis", "notequal", "AE", "Oslash", "infinity", "plusminus", "lessequal", "greaterequal", "yen", "mu", "partialdiff", "summation", "product", "pi", "integral", "ordfeminine", "ordmasculine", "Omega", "ae", "oslash", "questiondown", "exclamdown", "logicalnot", "radical", "florin", "approxequal", "Delta", "guillemotleft", "guillemotright", "ellipsis", "nonbreakingspace", "Agrave", "Atilde", "Otilde", "OE", "oe", "endash", "emdash", "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide", "lozenge", "ydieresis", "Ydieresis", "fraction", "currency", "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl", "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex", "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute", "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex", "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave", "dotlessi", "circumflex", "tilde", "macron", "breve", "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek", "caron", "Lslash", "lslash", "Scaron", "scaron", "Zcaron", "zcaron", "brokenbar", "Eth", "eth", "Yacute", "yacute", "Thorn", "thorn", "minus", "multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf", "onequarter", "threequarters", "franc", "Gbreve", "gbreve", "Idotaccent", "Scedilla", "scedilla", "Cacute", "cacute", "Ccaron", "ccaron", "dcroat"];
  17383. function recoverGlyphName(name, glyphsUnicodeMap) {
  17384. if (glyphsUnicodeMap[name] !== undefined) {
  17385. return name;
  17386. }
  17387. const unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  17388. if (unicode !== -1) {
  17389. for (const key in glyphsUnicodeMap) {
  17390. if (glyphsUnicodeMap[key] === unicode) {
  17391. return key;
  17392. }
  17393. }
  17394. }
  17395. info("Unable to recover a standard glyph name for: " + name);
  17396. return name;
  17397. }
  17398. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17399. const charCodeToGlyphId = Object.create(null);
  17400. let glyphId, charCode, baseEncoding;
  17401. const isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  17402. if (properties.isInternalFont) {
  17403. baseEncoding = builtInEncoding;
  17404. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17405. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17406. charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
  17407. }
  17408. } else if (properties.baseEncodingName) {
  17409. baseEncoding = getEncoding(properties.baseEncodingName);
  17410. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17411. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17412. charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
  17413. }
  17414. } else if (isSymbolicFont) {
  17415. for (charCode in builtInEncoding) {
  17416. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17417. }
  17418. } else {
  17419. baseEncoding = StandardEncoding;
  17420. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17421. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17422. charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
  17423. }
  17424. }
  17425. const differences = properties.differences;
  17426. let glyphsUnicodeMap;
  17427. if (differences) {
  17428. for (charCode in differences) {
  17429. const glyphName = differences[charCode];
  17430. glyphId = glyphNames.indexOf(glyphName);
  17431. if (glyphId === -1) {
  17432. if (!glyphsUnicodeMap) {
  17433. glyphsUnicodeMap = getGlyphsUnicode();
  17434. }
  17435. const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  17436. if (standardGlyphName !== glyphName) {
  17437. glyphId = glyphNames.indexOf(standardGlyphName);
  17438. }
  17439. }
  17440. charCodeToGlyphId[charCode] = glyphId >= 0 ? glyphId : 0;
  17441. }
  17442. }
  17443. return charCodeToGlyphId;
  17444. }
  17445. function normalizeFontName(name) {
  17446. return name.replaceAll(/[,_]/g, "-").replaceAll(/\s/g, "");
  17447. }
  17448. ;// CONCATENATED MODULE: ./src/core/standard_fonts.js
  17449. const getStdFontMap = getLookupTableFactory(function (t) {
  17450. t["Times-Roman"] = "Times-Roman";
  17451. t.Helvetica = "Helvetica";
  17452. t.Courier = "Courier";
  17453. t.Symbol = "Symbol";
  17454. t["Times-Bold"] = "Times-Bold";
  17455. t["Helvetica-Bold"] = "Helvetica-Bold";
  17456. t["Courier-Bold"] = "Courier-Bold";
  17457. t.ZapfDingbats = "ZapfDingbats";
  17458. t["Times-Italic"] = "Times-Italic";
  17459. t["Helvetica-Oblique"] = "Helvetica-Oblique";
  17460. t["Courier-Oblique"] = "Courier-Oblique";
  17461. t["Times-BoldItalic"] = "Times-BoldItalic";
  17462. t["Helvetica-BoldOblique"] = "Helvetica-BoldOblique";
  17463. t["Courier-BoldOblique"] = "Courier-BoldOblique";
  17464. t.ArialNarrow = "Helvetica";
  17465. t["ArialNarrow-Bold"] = "Helvetica-Bold";
  17466. t["ArialNarrow-BoldItalic"] = "Helvetica-BoldOblique";
  17467. t["ArialNarrow-Italic"] = "Helvetica-Oblique";
  17468. t.ArialBlack = "Helvetica";
  17469. t["ArialBlack-Bold"] = "Helvetica-Bold";
  17470. t["ArialBlack-BoldItalic"] = "Helvetica-BoldOblique";
  17471. t["ArialBlack-Italic"] = "Helvetica-Oblique";
  17472. t["Arial-Black"] = "Helvetica";
  17473. t["Arial-Black-Bold"] = "Helvetica-Bold";
  17474. t["Arial-Black-BoldItalic"] = "Helvetica-BoldOblique";
  17475. t["Arial-Black-Italic"] = "Helvetica-Oblique";
  17476. t.Arial = "Helvetica";
  17477. t["Arial-Bold"] = "Helvetica-Bold";
  17478. t["Arial-BoldItalic"] = "Helvetica-BoldOblique";
  17479. t["Arial-Italic"] = "Helvetica-Oblique";
  17480. t.ArialMT = "Helvetica";
  17481. t["Arial-BoldItalicMT"] = "Helvetica-BoldOblique";
  17482. t["Arial-BoldMT"] = "Helvetica-Bold";
  17483. t["Arial-ItalicMT"] = "Helvetica-Oblique";
  17484. t["Arial-BoldItalicMT-BoldItalic"] = "Helvetica-BoldOblique";
  17485. t["Arial-BoldMT-Bold"] = "Helvetica-Bold";
  17486. t["Arial-ItalicMT-Italic"] = "Helvetica-Oblique";
  17487. t.ArialUnicodeMS = "Helvetica";
  17488. t["ArialUnicodeMS-Bold"] = "Helvetica-Bold";
  17489. t["ArialUnicodeMS-BoldItalic"] = "Helvetica-BoldOblique";
  17490. t["ArialUnicodeMS-Italic"] = "Helvetica-Oblique";
  17491. t["Courier-BoldItalic"] = "Courier-BoldOblique";
  17492. t["Courier-Italic"] = "Courier-Oblique";
  17493. t.CourierNew = "Courier";
  17494. t["CourierNew-Bold"] = "Courier-Bold";
  17495. t["CourierNew-BoldItalic"] = "Courier-BoldOblique";
  17496. t["CourierNew-Italic"] = "Courier-Oblique";
  17497. t["CourierNewPS-BoldItalicMT"] = "Courier-BoldOblique";
  17498. t["CourierNewPS-BoldMT"] = "Courier-Bold";
  17499. t["CourierNewPS-ItalicMT"] = "Courier-Oblique";
  17500. t.CourierNewPSMT = "Courier";
  17501. t["Helvetica-BoldItalic"] = "Helvetica-BoldOblique";
  17502. t["Helvetica-Italic"] = "Helvetica-Oblique";
  17503. t["Symbol-Bold"] = "Symbol";
  17504. t["Symbol-BoldItalic"] = "Symbol";
  17505. t["Symbol-Italic"] = "Symbol";
  17506. t.TimesNewRoman = "Times-Roman";
  17507. t["TimesNewRoman-Bold"] = "Times-Bold";
  17508. t["TimesNewRoman-BoldItalic"] = "Times-BoldItalic";
  17509. t["TimesNewRoman-Italic"] = "Times-Italic";
  17510. t.TimesNewRomanPS = "Times-Roman";
  17511. t["TimesNewRomanPS-Bold"] = "Times-Bold";
  17512. t["TimesNewRomanPS-BoldItalic"] = "Times-BoldItalic";
  17513. t["TimesNewRomanPS-BoldItalicMT"] = "Times-BoldItalic";
  17514. t["TimesNewRomanPS-BoldMT"] = "Times-Bold";
  17515. t["TimesNewRomanPS-Italic"] = "Times-Italic";
  17516. t["TimesNewRomanPS-ItalicMT"] = "Times-Italic";
  17517. t.TimesNewRomanPSMT = "Times-Roman";
  17518. t["TimesNewRomanPSMT-Bold"] = "Times-Bold";
  17519. t["TimesNewRomanPSMT-BoldItalic"] = "Times-BoldItalic";
  17520. t["TimesNewRomanPSMT-Italic"] = "Times-Italic";
  17521. });
  17522. const getFontNameToFileMap = getLookupTableFactory(function (t) {
  17523. t.Courier = "FoxitFixed.pfb";
  17524. t["Courier-Bold"] = "FoxitFixedBold.pfb";
  17525. t["Courier-BoldOblique"] = "FoxitFixedBoldItalic.pfb";
  17526. t["Courier-Oblique"] = "FoxitFixedItalic.pfb";
  17527. t.Helvetica = "LiberationSans-Regular.ttf";
  17528. t["Helvetica-Bold"] = "LiberationSans-Bold.ttf";
  17529. t["Helvetica-BoldOblique"] = "LiberationSans-BoldItalic.ttf";
  17530. t["Helvetica-Oblique"] = "LiberationSans-Italic.ttf";
  17531. t["Times-Roman"] = "FoxitSerif.pfb";
  17532. t["Times-Bold"] = "FoxitSerifBold.pfb";
  17533. t["Times-BoldItalic"] = "FoxitSerifBoldItalic.pfb";
  17534. t["Times-Italic"] = "FoxitSerifItalic.pfb";
  17535. t.Symbol = "FoxitSymbol.pfb";
  17536. t.ZapfDingbats = "FoxitDingbats.pfb";
  17537. t["LiberationSans-Regular"] = "LiberationSans-Regular.ttf";
  17538. t["LiberationSans-Bold"] = "LiberationSans-Bold.ttf";
  17539. t["LiberationSans-Italic"] = "LiberationSans-Italic.ttf";
  17540. t["LiberationSans-BoldItalic"] = "LiberationSans-BoldItalic.ttf";
  17541. });
  17542. const getNonStdFontMap = getLookupTableFactory(function (t) {
  17543. t.Calibri = "Helvetica";
  17544. t["Calibri-Bold"] = "Helvetica-Bold";
  17545. t["Calibri-BoldItalic"] = "Helvetica-BoldOblique";
  17546. t["Calibri-Italic"] = "Helvetica-Oblique";
  17547. t.CenturyGothic = "Helvetica";
  17548. t["CenturyGothic-Bold"] = "Helvetica-Bold";
  17549. t["CenturyGothic-BoldItalic"] = "Helvetica-BoldOblique";
  17550. t["CenturyGothic-Italic"] = "Helvetica-Oblique";
  17551. t.ComicSansMS = "Comic Sans MS";
  17552. t["ComicSansMS-Bold"] = "Comic Sans MS-Bold";
  17553. t["ComicSansMS-BoldItalic"] = "Comic Sans MS-BoldItalic";
  17554. t["ComicSansMS-Italic"] = "Comic Sans MS-Italic";
  17555. t.Impact = "Helvetica";
  17556. t["ItcSymbol-Bold"] = "Helvetica-Bold";
  17557. t["ItcSymbol-BoldItalic"] = "Helvetica-BoldOblique";
  17558. t["ItcSymbol-Book"] = "Helvetica";
  17559. t["ItcSymbol-BookItalic"] = "Helvetica-Oblique";
  17560. t["ItcSymbol-Medium"] = "Helvetica";
  17561. t["ItcSymbol-MediumItalic"] = "Helvetica-Oblique";
  17562. t.LucidaConsole = "Courier";
  17563. t["LucidaConsole-Bold"] = "Courier-Bold";
  17564. t["LucidaConsole-BoldItalic"] = "Courier-BoldOblique";
  17565. t["LucidaConsole-Italic"] = "Courier-Oblique";
  17566. t["LucidaSans-Demi"] = "Helvetica-Bold";
  17567. t["MS-Gothic"] = "MS Gothic";
  17568. t["MS-Gothic-Bold"] = "MS Gothic-Bold";
  17569. t["MS-Gothic-BoldItalic"] = "MS Gothic-BoldItalic";
  17570. t["MS-Gothic-Italic"] = "MS Gothic-Italic";
  17571. t["MS-Mincho"] = "MS Mincho";
  17572. t["MS-Mincho-Bold"] = "MS Mincho-Bold";
  17573. t["MS-Mincho-BoldItalic"] = "MS Mincho-BoldItalic";
  17574. t["MS-Mincho-Italic"] = "MS Mincho-Italic";
  17575. t["MS-PGothic"] = "MS PGothic";
  17576. t["MS-PGothic-Bold"] = "MS PGothic-Bold";
  17577. t["MS-PGothic-BoldItalic"] = "MS PGothic-BoldItalic";
  17578. t["MS-PGothic-Italic"] = "MS PGothic-Italic";
  17579. t["MS-PMincho"] = "MS PMincho";
  17580. t["MS-PMincho-Bold"] = "MS PMincho-Bold";
  17581. t["MS-PMincho-BoldItalic"] = "MS PMincho-BoldItalic";
  17582. t["MS-PMincho-Italic"] = "MS PMincho-Italic";
  17583. t.NuptialScript = "Times-Italic";
  17584. t.SegoeUISymbol = "Helvetica";
  17585. });
  17586. const getSerifFonts = getLookupTableFactory(function (t) {
  17587. t["Adobe Jenson"] = true;
  17588. t["Adobe Text"] = true;
  17589. t.Albertus = true;
  17590. t.Aldus = true;
  17591. t.Alexandria = true;
  17592. t.Algerian = true;
  17593. t["American Typewriter"] = true;
  17594. t.Antiqua = true;
  17595. t.Apex = true;
  17596. t.Arno = true;
  17597. t.Aster = true;
  17598. t.Aurora = true;
  17599. t.Baskerville = true;
  17600. t.Bell = true;
  17601. t.Bembo = true;
  17602. t["Bembo Schoolbook"] = true;
  17603. t.Benguiat = true;
  17604. t["Berkeley Old Style"] = true;
  17605. t["Bernhard Modern"] = true;
  17606. t["Berthold City"] = true;
  17607. t.Bodoni = true;
  17608. t["Bauer Bodoni"] = true;
  17609. t["Book Antiqua"] = true;
  17610. t.Bookman = true;
  17611. t["Bordeaux Roman"] = true;
  17612. t["Californian FB"] = true;
  17613. t.Calisto = true;
  17614. t.Calvert = true;
  17615. t.Capitals = true;
  17616. t.Cambria = true;
  17617. t.Cartier = true;
  17618. t.Caslon = true;
  17619. t.Catull = true;
  17620. t.Centaur = true;
  17621. t["Century Old Style"] = true;
  17622. t["Century Schoolbook"] = true;
  17623. t.Chaparral = true;
  17624. t["Charis SIL"] = true;
  17625. t.Cheltenham = true;
  17626. t["Cholla Slab"] = true;
  17627. t.Clarendon = true;
  17628. t.Clearface = true;
  17629. t.Cochin = true;
  17630. t.Colonna = true;
  17631. t["Computer Modern"] = true;
  17632. t["Concrete Roman"] = true;
  17633. t.Constantia = true;
  17634. t["Cooper Black"] = true;
  17635. t.Corona = true;
  17636. t.Ecotype = true;
  17637. t.Egyptienne = true;
  17638. t.Elephant = true;
  17639. t.Excelsior = true;
  17640. t.Fairfield = true;
  17641. t["FF Scala"] = true;
  17642. t.Folkard = true;
  17643. t.Footlight = true;
  17644. t.FreeSerif = true;
  17645. t["Friz Quadrata"] = true;
  17646. t.Garamond = true;
  17647. t.Gentium = true;
  17648. t.Georgia = true;
  17649. t.Gloucester = true;
  17650. t["Goudy Old Style"] = true;
  17651. t["Goudy Schoolbook"] = true;
  17652. t["Goudy Pro Font"] = true;
  17653. t.Granjon = true;
  17654. t["Guardian Egyptian"] = true;
  17655. t.Heather = true;
  17656. t.Hercules = true;
  17657. t["High Tower Text"] = true;
  17658. t.Hiroshige = true;
  17659. t["Hoefler Text"] = true;
  17660. t["Humana Serif"] = true;
  17661. t.Imprint = true;
  17662. t["Ionic No. 5"] = true;
  17663. t.Janson = true;
  17664. t.Joanna = true;
  17665. t.Korinna = true;
  17666. t.Lexicon = true;
  17667. t.LiberationSerif = true;
  17668. t["Liberation Serif"] = true;
  17669. t["Linux Libertine"] = true;
  17670. t.Literaturnaya = true;
  17671. t.Lucida = true;
  17672. t["Lucida Bright"] = true;
  17673. t.Melior = true;
  17674. t.Memphis = true;
  17675. t.Miller = true;
  17676. t.Minion = true;
  17677. t.Modern = true;
  17678. t["Mona Lisa"] = true;
  17679. t["Mrs Eaves"] = true;
  17680. t["MS Serif"] = true;
  17681. t["Museo Slab"] = true;
  17682. t["New York"] = true;
  17683. t["Nimbus Roman"] = true;
  17684. t["NPS Rawlinson Roadway"] = true;
  17685. t.NuptialScript = true;
  17686. t.Palatino = true;
  17687. t.Perpetua = true;
  17688. t.Plantin = true;
  17689. t["Plantin Schoolbook"] = true;
  17690. t.Playbill = true;
  17691. t["Poor Richard"] = true;
  17692. t["Rawlinson Roadway"] = true;
  17693. t.Renault = true;
  17694. t.Requiem = true;
  17695. t.Rockwell = true;
  17696. t.Roman = true;
  17697. t["Rotis Serif"] = true;
  17698. t.Sabon = true;
  17699. t.Scala = true;
  17700. t.Seagull = true;
  17701. t.Sistina = true;
  17702. t.Souvenir = true;
  17703. t.STIX = true;
  17704. t["Stone Informal"] = true;
  17705. t["Stone Serif"] = true;
  17706. t.Sylfaen = true;
  17707. t.Times = true;
  17708. t.Trajan = true;
  17709. t["Trinité"] = true;
  17710. t["Trump Mediaeval"] = true;
  17711. t.Utopia = true;
  17712. t["Vale Type"] = true;
  17713. t["Bitstream Vera"] = true;
  17714. t["Vera Serif"] = true;
  17715. t.Versailles = true;
  17716. t.Wanted = true;
  17717. t.Weiss = true;
  17718. t["Wide Latin"] = true;
  17719. t.Windsor = true;
  17720. t.XITS = true;
  17721. });
  17722. const getSymbolsFonts = getLookupTableFactory(function (t) {
  17723. t.Dingbats = true;
  17724. t.Symbol = true;
  17725. t.ZapfDingbats = true;
  17726. t.Wingdings = true;
  17727. t["Wingdings-Bold"] = true;
  17728. t["Wingdings-Regular"] = true;
  17729. });
  17730. const getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17731. t[2] = 10;
  17732. t[3] = 32;
  17733. t[4] = 33;
  17734. t[5] = 34;
  17735. t[6] = 35;
  17736. t[7] = 36;
  17737. t[8] = 37;
  17738. t[9] = 38;
  17739. t[10] = 39;
  17740. t[11] = 40;
  17741. t[12] = 41;
  17742. t[13] = 42;
  17743. t[14] = 43;
  17744. t[15] = 44;
  17745. t[16] = 45;
  17746. t[17] = 46;
  17747. t[18] = 47;
  17748. t[19] = 48;
  17749. t[20] = 49;
  17750. t[21] = 50;
  17751. t[22] = 51;
  17752. t[23] = 52;
  17753. t[24] = 53;
  17754. t[25] = 54;
  17755. t[26] = 55;
  17756. t[27] = 56;
  17757. t[28] = 57;
  17758. t[29] = 58;
  17759. t[30] = 894;
  17760. t[31] = 60;
  17761. t[32] = 61;
  17762. t[33] = 62;
  17763. t[34] = 63;
  17764. t[35] = 64;
  17765. t[36] = 65;
  17766. t[37] = 66;
  17767. t[38] = 67;
  17768. t[39] = 68;
  17769. t[40] = 69;
  17770. t[41] = 70;
  17771. t[42] = 71;
  17772. t[43] = 72;
  17773. t[44] = 73;
  17774. t[45] = 74;
  17775. t[46] = 75;
  17776. t[47] = 76;
  17777. t[48] = 77;
  17778. t[49] = 78;
  17779. t[50] = 79;
  17780. t[51] = 80;
  17781. t[52] = 81;
  17782. t[53] = 82;
  17783. t[54] = 83;
  17784. t[55] = 84;
  17785. t[56] = 85;
  17786. t[57] = 86;
  17787. t[58] = 87;
  17788. t[59] = 88;
  17789. t[60] = 89;
  17790. t[61] = 90;
  17791. t[62] = 91;
  17792. t[63] = 92;
  17793. t[64] = 93;
  17794. t[65] = 94;
  17795. t[66] = 95;
  17796. t[67] = 96;
  17797. t[68] = 97;
  17798. t[69] = 98;
  17799. t[70] = 99;
  17800. t[71] = 100;
  17801. t[72] = 101;
  17802. t[73] = 102;
  17803. t[74] = 103;
  17804. t[75] = 104;
  17805. t[76] = 105;
  17806. t[77] = 106;
  17807. t[78] = 107;
  17808. t[79] = 108;
  17809. t[80] = 109;
  17810. t[81] = 110;
  17811. t[82] = 111;
  17812. t[83] = 112;
  17813. t[84] = 113;
  17814. t[85] = 114;
  17815. t[86] = 115;
  17816. t[87] = 116;
  17817. t[88] = 117;
  17818. t[89] = 118;
  17819. t[90] = 119;
  17820. t[91] = 120;
  17821. t[92] = 121;
  17822. t[93] = 122;
  17823. t[94] = 123;
  17824. t[95] = 124;
  17825. t[96] = 125;
  17826. t[97] = 126;
  17827. t[98] = 196;
  17828. t[99] = 197;
  17829. t[100] = 199;
  17830. t[101] = 201;
  17831. t[102] = 209;
  17832. t[103] = 214;
  17833. t[104] = 220;
  17834. t[105] = 225;
  17835. t[106] = 224;
  17836. t[107] = 226;
  17837. t[108] = 228;
  17838. t[109] = 227;
  17839. t[110] = 229;
  17840. t[111] = 231;
  17841. t[112] = 233;
  17842. t[113] = 232;
  17843. t[114] = 234;
  17844. t[115] = 235;
  17845. t[116] = 237;
  17846. t[117] = 236;
  17847. t[118] = 238;
  17848. t[119] = 239;
  17849. t[120] = 241;
  17850. t[121] = 243;
  17851. t[122] = 242;
  17852. t[123] = 244;
  17853. t[124] = 246;
  17854. t[125] = 245;
  17855. t[126] = 250;
  17856. t[127] = 249;
  17857. t[128] = 251;
  17858. t[129] = 252;
  17859. t[130] = 8224;
  17860. t[131] = 176;
  17861. t[132] = 162;
  17862. t[133] = 163;
  17863. t[134] = 167;
  17864. t[135] = 8226;
  17865. t[136] = 182;
  17866. t[137] = 223;
  17867. t[138] = 174;
  17868. t[139] = 169;
  17869. t[140] = 8482;
  17870. t[141] = 180;
  17871. t[142] = 168;
  17872. t[143] = 8800;
  17873. t[144] = 198;
  17874. t[145] = 216;
  17875. t[146] = 8734;
  17876. t[147] = 177;
  17877. t[148] = 8804;
  17878. t[149] = 8805;
  17879. t[150] = 165;
  17880. t[151] = 181;
  17881. t[152] = 8706;
  17882. t[153] = 8721;
  17883. t[154] = 8719;
  17884. t[156] = 8747;
  17885. t[157] = 170;
  17886. t[158] = 186;
  17887. t[159] = 8486;
  17888. t[160] = 230;
  17889. t[161] = 248;
  17890. t[162] = 191;
  17891. t[163] = 161;
  17892. t[164] = 172;
  17893. t[165] = 8730;
  17894. t[166] = 402;
  17895. t[167] = 8776;
  17896. t[168] = 8710;
  17897. t[169] = 171;
  17898. t[170] = 187;
  17899. t[171] = 8230;
  17900. t[179] = 8220;
  17901. t[180] = 8221;
  17902. t[181] = 8216;
  17903. t[182] = 8217;
  17904. t[200] = 193;
  17905. t[203] = 205;
  17906. t[207] = 211;
  17907. t[210] = 218;
  17908. t[223] = 711;
  17909. t[224] = 321;
  17910. t[225] = 322;
  17911. t[226] = 352;
  17912. t[227] = 353;
  17913. t[228] = 381;
  17914. t[229] = 382;
  17915. t[233] = 221;
  17916. t[234] = 253;
  17917. t[252] = 263;
  17918. t[253] = 268;
  17919. t[254] = 269;
  17920. t[258] = 258;
  17921. t[260] = 260;
  17922. t[261] = 261;
  17923. t[265] = 280;
  17924. t[266] = 281;
  17925. t[267] = 282;
  17926. t[268] = 283;
  17927. t[269] = 313;
  17928. t[275] = 323;
  17929. t[276] = 324;
  17930. t[278] = 328;
  17931. t[283] = 344;
  17932. t[284] = 345;
  17933. t[285] = 346;
  17934. t[286] = 347;
  17935. t[292] = 367;
  17936. t[295] = 377;
  17937. t[296] = 378;
  17938. t[298] = 380;
  17939. t[305] = 963;
  17940. t[306] = 964;
  17941. t[307] = 966;
  17942. t[308] = 8215;
  17943. t[309] = 8252;
  17944. t[310] = 8319;
  17945. t[311] = 8359;
  17946. t[312] = 8592;
  17947. t[313] = 8593;
  17948. t[337] = 9552;
  17949. t[493] = 1039;
  17950. t[494] = 1040;
  17951. t[672] = 1488;
  17952. t[673] = 1489;
  17953. t[674] = 1490;
  17954. t[675] = 1491;
  17955. t[676] = 1492;
  17956. t[677] = 1493;
  17957. t[678] = 1494;
  17958. t[679] = 1495;
  17959. t[680] = 1496;
  17960. t[681] = 1497;
  17961. t[682] = 1498;
  17962. t[683] = 1499;
  17963. t[684] = 1500;
  17964. t[685] = 1501;
  17965. t[686] = 1502;
  17966. t[687] = 1503;
  17967. t[688] = 1504;
  17968. t[689] = 1505;
  17969. t[690] = 1506;
  17970. t[691] = 1507;
  17971. t[692] = 1508;
  17972. t[693] = 1509;
  17973. t[694] = 1510;
  17974. t[695] = 1511;
  17975. t[696] = 1512;
  17976. t[697] = 1513;
  17977. t[698] = 1514;
  17978. t[705] = 1524;
  17979. t[706] = 8362;
  17980. t[710] = 64288;
  17981. t[711] = 64298;
  17982. t[759] = 1617;
  17983. t[761] = 1776;
  17984. t[763] = 1778;
  17985. t[775] = 1652;
  17986. t[777] = 1764;
  17987. t[778] = 1780;
  17988. t[779] = 1781;
  17989. t[780] = 1782;
  17990. t[782] = 771;
  17991. t[783] = 64726;
  17992. t[786] = 8363;
  17993. t[788] = 8532;
  17994. t[790] = 768;
  17995. t[791] = 769;
  17996. t[792] = 768;
  17997. t[795] = 803;
  17998. t[797] = 64336;
  17999. t[798] = 64337;
  18000. t[799] = 64342;
  18001. t[800] = 64343;
  18002. t[801] = 64344;
  18003. t[802] = 64345;
  18004. t[803] = 64362;
  18005. t[804] = 64363;
  18006. t[805] = 64364;
  18007. t[2424] = 7821;
  18008. t[2425] = 7822;
  18009. t[2426] = 7823;
  18010. t[2427] = 7824;
  18011. t[2428] = 7825;
  18012. t[2429] = 7826;
  18013. t[2430] = 7827;
  18014. t[2433] = 7682;
  18015. t[2678] = 8045;
  18016. t[2679] = 8046;
  18017. t[2830] = 1552;
  18018. t[2838] = 686;
  18019. t[2840] = 751;
  18020. t[2842] = 753;
  18021. t[2843] = 754;
  18022. t[2844] = 755;
  18023. t[2846] = 757;
  18024. t[2856] = 767;
  18025. t[2857] = 848;
  18026. t[2858] = 849;
  18027. t[2862] = 853;
  18028. t[2863] = 854;
  18029. t[2864] = 855;
  18030. t[2865] = 861;
  18031. t[2866] = 862;
  18032. t[2906] = 7460;
  18033. t[2908] = 7462;
  18034. t[2909] = 7463;
  18035. t[2910] = 7464;
  18036. t[2912] = 7466;
  18037. t[2913] = 7467;
  18038. t[2914] = 7468;
  18039. t[2916] = 7470;
  18040. t[2917] = 7471;
  18041. t[2918] = 7472;
  18042. t[2920] = 7474;
  18043. t[2921] = 7475;
  18044. t[2922] = 7476;
  18045. t[2924] = 7478;
  18046. t[2925] = 7479;
  18047. t[2926] = 7480;
  18048. t[2928] = 7482;
  18049. t[2929] = 7483;
  18050. t[2930] = 7484;
  18051. t[2932] = 7486;
  18052. t[2933] = 7487;
  18053. t[2934] = 7488;
  18054. t[2936] = 7490;
  18055. t[2937] = 7491;
  18056. t[2938] = 7492;
  18057. t[2940] = 7494;
  18058. t[2941] = 7495;
  18059. t[2942] = 7496;
  18060. t[2944] = 7498;
  18061. t[2946] = 7500;
  18062. t[2948] = 7502;
  18063. t[2950] = 7504;
  18064. t[2951] = 7505;
  18065. t[2952] = 7506;
  18066. t[2954] = 7508;
  18067. t[2955] = 7509;
  18068. t[2956] = 7510;
  18069. t[2958] = 7512;
  18070. t[2959] = 7513;
  18071. t[2960] = 7514;
  18072. t[2962] = 7516;
  18073. t[2963] = 7517;
  18074. t[2964] = 7518;
  18075. t[2966] = 7520;
  18076. t[2967] = 7521;
  18077. t[2968] = 7522;
  18078. t[2970] = 7524;
  18079. t[2971] = 7525;
  18080. t[2972] = 7526;
  18081. t[2974] = 7528;
  18082. t[2975] = 7529;
  18083. t[2976] = 7530;
  18084. t[2978] = 1537;
  18085. t[2979] = 1538;
  18086. t[2980] = 1539;
  18087. t[2982] = 1549;
  18088. t[2983] = 1551;
  18089. t[2984] = 1552;
  18090. t[2986] = 1554;
  18091. t[2987] = 1555;
  18092. t[2988] = 1556;
  18093. t[2990] = 1623;
  18094. t[2991] = 1624;
  18095. t[2995] = 1775;
  18096. t[2999] = 1791;
  18097. t[3002] = 64290;
  18098. t[3003] = 64291;
  18099. t[3004] = 64292;
  18100. t[3006] = 64294;
  18101. t[3007] = 64295;
  18102. t[3008] = 64296;
  18103. t[3011] = 1900;
  18104. t[3014] = 8223;
  18105. t[3015] = 8244;
  18106. t[3017] = 7532;
  18107. t[3018] = 7533;
  18108. t[3019] = 7534;
  18109. t[3075] = 7590;
  18110. t[3076] = 7591;
  18111. t[3079] = 7594;
  18112. t[3080] = 7595;
  18113. t[3083] = 7598;
  18114. t[3084] = 7599;
  18115. t[3087] = 7602;
  18116. t[3088] = 7603;
  18117. t[3091] = 7606;
  18118. t[3092] = 7607;
  18119. t[3095] = 7610;
  18120. t[3096] = 7611;
  18121. t[3099] = 7614;
  18122. t[3100] = 7615;
  18123. t[3103] = 7618;
  18124. t[3104] = 7619;
  18125. t[3107] = 8337;
  18126. t[3108] = 8338;
  18127. t[3116] = 1884;
  18128. t[3119] = 1885;
  18129. t[3120] = 1885;
  18130. t[3123] = 1886;
  18131. t[3124] = 1886;
  18132. t[3127] = 1887;
  18133. t[3128] = 1887;
  18134. t[3131] = 1888;
  18135. t[3132] = 1888;
  18136. t[3135] = 1889;
  18137. t[3136] = 1889;
  18138. t[3139] = 1890;
  18139. t[3140] = 1890;
  18140. t[3143] = 1891;
  18141. t[3144] = 1891;
  18142. t[3147] = 1892;
  18143. t[3148] = 1892;
  18144. t[3153] = 580;
  18145. t[3154] = 581;
  18146. t[3157] = 584;
  18147. t[3158] = 585;
  18148. t[3161] = 588;
  18149. t[3162] = 589;
  18150. t[3165] = 891;
  18151. t[3166] = 892;
  18152. t[3169] = 1274;
  18153. t[3170] = 1275;
  18154. t[3173] = 1278;
  18155. t[3174] = 1279;
  18156. t[3181] = 7622;
  18157. t[3182] = 7623;
  18158. t[3282] = 11799;
  18159. t[3316] = 578;
  18160. t[3379] = 42785;
  18161. t[3393] = 1159;
  18162. t[3416] = 8377;
  18163. });
  18164. const getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  18165. t[227] = 322;
  18166. t[264] = 261;
  18167. t[291] = 346;
  18168. });
  18169. const getSupplementalGlyphMapForCalibri = getLookupTableFactory(function (t) {
  18170. t[1] = 32;
  18171. t[4] = 65;
  18172. t[5] = 192;
  18173. t[6] = 193;
  18174. t[9] = 196;
  18175. t[17] = 66;
  18176. t[18] = 67;
  18177. t[21] = 268;
  18178. t[24] = 68;
  18179. t[28] = 69;
  18180. t[29] = 200;
  18181. t[30] = 201;
  18182. t[32] = 282;
  18183. t[38] = 70;
  18184. t[39] = 71;
  18185. t[44] = 72;
  18186. t[47] = 73;
  18187. t[48] = 204;
  18188. t[49] = 205;
  18189. t[58] = 74;
  18190. t[60] = 75;
  18191. t[62] = 76;
  18192. t[68] = 77;
  18193. t[69] = 78;
  18194. t[75] = 79;
  18195. t[76] = 210;
  18196. t[80] = 214;
  18197. t[87] = 80;
  18198. t[89] = 81;
  18199. t[90] = 82;
  18200. t[92] = 344;
  18201. t[94] = 83;
  18202. t[97] = 352;
  18203. t[100] = 84;
  18204. t[104] = 85;
  18205. t[109] = 220;
  18206. t[115] = 86;
  18207. t[116] = 87;
  18208. t[121] = 88;
  18209. t[122] = 89;
  18210. t[124] = 221;
  18211. t[127] = 90;
  18212. t[129] = 381;
  18213. t[258] = 97;
  18214. t[259] = 224;
  18215. t[260] = 225;
  18216. t[263] = 228;
  18217. t[268] = 261;
  18218. t[271] = 98;
  18219. t[272] = 99;
  18220. t[273] = 263;
  18221. t[275] = 269;
  18222. t[282] = 100;
  18223. t[286] = 101;
  18224. t[287] = 232;
  18225. t[288] = 233;
  18226. t[290] = 283;
  18227. t[295] = 281;
  18228. t[296] = 102;
  18229. t[336] = 103;
  18230. t[346] = 104;
  18231. t[349] = 105;
  18232. t[350] = 236;
  18233. t[351] = 237;
  18234. t[361] = 106;
  18235. t[364] = 107;
  18236. t[367] = 108;
  18237. t[371] = 322;
  18238. t[373] = 109;
  18239. t[374] = 110;
  18240. t[381] = 111;
  18241. t[382] = 242;
  18242. t[383] = 243;
  18243. t[386] = 246;
  18244. t[393] = 112;
  18245. t[395] = 113;
  18246. t[396] = 114;
  18247. t[398] = 345;
  18248. t[400] = 115;
  18249. t[401] = 347;
  18250. t[403] = 353;
  18251. t[410] = 116;
  18252. t[437] = 117;
  18253. t[442] = 252;
  18254. t[448] = 118;
  18255. t[449] = 119;
  18256. t[454] = 120;
  18257. t[455] = 121;
  18258. t[457] = 253;
  18259. t[460] = 122;
  18260. t[462] = 382;
  18261. t[463] = 380;
  18262. t[853] = 44;
  18263. t[855] = 58;
  18264. t[856] = 46;
  18265. t[876] = 47;
  18266. t[878] = 45;
  18267. t[882] = 45;
  18268. t[894] = 40;
  18269. t[895] = 41;
  18270. t[896] = 91;
  18271. t[897] = 93;
  18272. t[923] = 64;
  18273. t[1004] = 48;
  18274. t[1005] = 49;
  18275. t[1006] = 50;
  18276. t[1007] = 51;
  18277. t[1008] = 52;
  18278. t[1009] = 53;
  18279. t[1010] = 54;
  18280. t[1011] = 55;
  18281. t[1012] = 56;
  18282. t[1013] = 57;
  18283. t[1081] = 37;
  18284. t[1085] = 43;
  18285. t[1086] = 45;
  18286. });
  18287. function getStandardFontName(name) {
  18288. const fontName = normalizeFontName(name);
  18289. const stdFontMap = getStdFontMap();
  18290. return stdFontMap[fontName];
  18291. }
  18292. function isKnownFontName(name) {
  18293. const fontName = normalizeFontName(name);
  18294. return !!(getStdFontMap()[fontName] || getNonStdFontMap()[fontName] || getSerifFonts()[fontName] || getSymbolsFonts()[fontName]);
  18295. }
  18296. ;// CONCATENATED MODULE: ./src/core/to_unicode_map.js
  18297. class ToUnicodeMap {
  18298. constructor(cmap = []) {
  18299. this._map = cmap;
  18300. }
  18301. get length() {
  18302. return this._map.length;
  18303. }
  18304. forEach(callback) {
  18305. for (const charCode in this._map) {
  18306. callback(charCode, this._map[charCode].charCodeAt(0));
  18307. }
  18308. }
  18309. has(i) {
  18310. return this._map[i] !== undefined;
  18311. }
  18312. get(i) {
  18313. return this._map[i];
  18314. }
  18315. charCodeOf(value) {
  18316. const map = this._map;
  18317. if (map.length <= 0x10000) {
  18318. return map.indexOf(value);
  18319. }
  18320. for (const charCode in map) {
  18321. if (map[charCode] === value) {
  18322. return charCode | 0;
  18323. }
  18324. }
  18325. return -1;
  18326. }
  18327. amend(map) {
  18328. for (const charCode in map) {
  18329. this._map[charCode] = map[charCode];
  18330. }
  18331. }
  18332. }
  18333. class IdentityToUnicodeMap {
  18334. constructor(firstChar, lastChar) {
  18335. this.firstChar = firstChar;
  18336. this.lastChar = lastChar;
  18337. }
  18338. get length() {
  18339. return this.lastChar + 1 - this.firstChar;
  18340. }
  18341. forEach(callback) {
  18342. for (let i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  18343. callback(i, i);
  18344. }
  18345. }
  18346. has(i) {
  18347. return this.firstChar <= i && i <= this.lastChar;
  18348. }
  18349. get(i) {
  18350. if (this.firstChar <= i && i <= this.lastChar) {
  18351. return String.fromCharCode(i);
  18352. }
  18353. return undefined;
  18354. }
  18355. charCodeOf(v) {
  18356. return Number.isInteger(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  18357. }
  18358. amend(map) {
  18359. unreachable("Should not call amend()");
  18360. }
  18361. }
  18362. ;// CONCATENATED MODULE: ./src/core/cff_font.js
  18363. class CFFFont {
  18364. constructor(file, properties) {
  18365. this.properties = properties;
  18366. const parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  18367. this.cff = parser.parse();
  18368. this.cff.duplicateFirstGlyph();
  18369. const compiler = new CFFCompiler(this.cff);
  18370. this.seacs = this.cff.seacs;
  18371. try {
  18372. this.data = compiler.compile();
  18373. } catch {
  18374. warn("Failed to compile font " + properties.loadedName);
  18375. this.data = file;
  18376. }
  18377. this._createBuiltInEncoding();
  18378. }
  18379. get numGlyphs() {
  18380. return this.cff.charStrings.count;
  18381. }
  18382. getCharset() {
  18383. return this.cff.charset.charset;
  18384. }
  18385. getGlyphMapping() {
  18386. const cff = this.cff;
  18387. const properties = this.properties;
  18388. const {
  18389. cidToGidMap,
  18390. cMap
  18391. } = properties;
  18392. const charsets = cff.charset.charset;
  18393. let charCodeToGlyphId;
  18394. let glyphId;
  18395. if (properties.composite) {
  18396. let invCidToGidMap;
  18397. if (cidToGidMap?.length > 0) {
  18398. invCidToGidMap = Object.create(null);
  18399. for (let i = 0, ii = cidToGidMap.length; i < ii; i++) {
  18400. const gid = cidToGidMap[i];
  18401. if (gid !== undefined) {
  18402. invCidToGidMap[gid] = i;
  18403. }
  18404. }
  18405. }
  18406. charCodeToGlyphId = Object.create(null);
  18407. let charCode;
  18408. if (cff.isCIDFont) {
  18409. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18410. const cid = charsets[glyphId];
  18411. charCode = cMap.charCodeOf(cid);
  18412. if (invCidToGidMap?.[charCode] !== undefined) {
  18413. charCode = invCidToGidMap[charCode];
  18414. }
  18415. charCodeToGlyphId[charCode] = glyphId;
  18416. }
  18417. } else {
  18418. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18419. charCode = cMap.charCodeOf(glyphId);
  18420. charCodeToGlyphId[charCode] = glyphId;
  18421. }
  18422. }
  18423. return charCodeToGlyphId;
  18424. }
  18425. let encoding = cff.encoding ? cff.encoding.encoding : null;
  18426. if (properties.isInternalFont) {
  18427. encoding = properties.defaultEncoding;
  18428. }
  18429. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18430. return charCodeToGlyphId;
  18431. }
  18432. hasGlyphId(id) {
  18433. return this.cff.hasGlyphId(id);
  18434. }
  18435. _createBuiltInEncoding() {
  18436. const {
  18437. charset,
  18438. encoding
  18439. } = this.cff;
  18440. if (!charset || !encoding) {
  18441. return;
  18442. }
  18443. const charsets = charset.charset,
  18444. encodings = encoding.encoding;
  18445. const map = [];
  18446. for (const charCode in encodings) {
  18447. const glyphId = encodings[charCode];
  18448. if (glyphId >= 0) {
  18449. const glyphName = charsets[glyphId];
  18450. if (glyphName) {
  18451. map[charCode] = glyphName;
  18452. }
  18453. }
  18454. }
  18455. if (map.length > 0) {
  18456. this.properties.builtInEncoding = map;
  18457. }
  18458. }
  18459. }
  18460. ;// CONCATENATED MODULE: ./src/core/font_renderer.js
  18461. function getUint32(data, offset) {
  18462. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  18463. }
  18464. function getUint16(data, offset) {
  18465. return data[offset] << 8 | data[offset + 1];
  18466. }
  18467. function getInt16(data, offset) {
  18468. return (data[offset] << 24 | data[offset + 1] << 16) >> 16;
  18469. }
  18470. function getInt8(data, offset) {
  18471. return data[offset] << 24 >> 24;
  18472. }
  18473. function getFloat214(data, offset) {
  18474. return getInt16(data, offset) / 16384;
  18475. }
  18476. function getSubroutineBias(subrs) {
  18477. const numSubrs = subrs.length;
  18478. let bias = 32768;
  18479. if (numSubrs < 1240) {
  18480. bias = 107;
  18481. } else if (numSubrs < 33900) {
  18482. bias = 1131;
  18483. }
  18484. return bias;
  18485. }
  18486. function parseCmap(data, start, end) {
  18487. const offset = getUint16(data, start + 2) === 1 ? getUint32(data, start + 8) : getUint32(data, start + 16);
  18488. const format = getUint16(data, start + offset);
  18489. let ranges, p, i;
  18490. if (format === 4) {
  18491. getUint16(data, start + offset + 2);
  18492. const segCount = getUint16(data, start + offset + 6) >> 1;
  18493. p = start + offset + 14;
  18494. ranges = [];
  18495. for (i = 0; i < segCount; i++, p += 2) {
  18496. ranges[i] = {
  18497. end: getUint16(data, p)
  18498. };
  18499. }
  18500. p += 2;
  18501. for (i = 0; i < segCount; i++, p += 2) {
  18502. ranges[i].start = getUint16(data, p);
  18503. }
  18504. for (i = 0; i < segCount; i++, p += 2) {
  18505. ranges[i].idDelta = getUint16(data, p);
  18506. }
  18507. for (i = 0; i < segCount; i++, p += 2) {
  18508. let idOffset = getUint16(data, p);
  18509. if (idOffset === 0) {
  18510. continue;
  18511. }
  18512. ranges[i].ids = [];
  18513. for (let j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  18514. ranges[i].ids[j] = getUint16(data, p + idOffset);
  18515. idOffset += 2;
  18516. }
  18517. }
  18518. return ranges;
  18519. } else if (format === 12) {
  18520. const groups = getUint32(data, start + offset + 12);
  18521. p = start + offset + 16;
  18522. ranges = [];
  18523. for (i = 0; i < groups; i++) {
  18524. start = getUint32(data, p);
  18525. ranges.push({
  18526. start,
  18527. end: getUint32(data, p + 4),
  18528. idDelta: getUint32(data, p + 8) - start
  18529. });
  18530. p += 12;
  18531. }
  18532. return ranges;
  18533. }
  18534. throw new FormatError(`unsupported cmap: ${format}`);
  18535. }
  18536. function parseCff(data, start, end, seacAnalysisEnabled) {
  18537. const properties = {};
  18538. const parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  18539. const cff = parser.parse();
  18540. return {
  18541. glyphs: cff.charStrings.objects,
  18542. subrs: cff.topDict.privateDict?.subrsIndex?.objects,
  18543. gsubrs: cff.globalSubrIndex?.objects,
  18544. isCFFCIDFont: cff.isCIDFont,
  18545. fdSelect: cff.fdSelect,
  18546. fdArray: cff.fdArray
  18547. };
  18548. }
  18549. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  18550. let itemSize, itemDecode;
  18551. if (isGlyphLocationsLong) {
  18552. itemSize = 4;
  18553. itemDecode = getUint32;
  18554. } else {
  18555. itemSize = 2;
  18556. itemDecode = (data, offset) => 2 * getUint16(data, offset);
  18557. }
  18558. const glyphs = [];
  18559. let startOffset = itemDecode(loca, 0);
  18560. for (let j = itemSize; j < loca.length; j += itemSize) {
  18561. const endOffset = itemDecode(loca, j);
  18562. glyphs.push(glyf.subarray(startOffset, endOffset));
  18563. startOffset = endOffset;
  18564. }
  18565. return glyphs;
  18566. }
  18567. function lookupCmap(ranges, unicode) {
  18568. const code = unicode.codePointAt(0);
  18569. let gid = 0,
  18570. l = 0,
  18571. r = ranges.length - 1;
  18572. while (l < r) {
  18573. const c = l + r + 1 >> 1;
  18574. if (code < ranges[c].start) {
  18575. r = c - 1;
  18576. } else {
  18577. l = c;
  18578. }
  18579. }
  18580. if (ranges[l].start <= code && code <= ranges[l].end) {
  18581. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xffff;
  18582. }
  18583. return {
  18584. charCode: code,
  18585. glyphId: gid
  18586. };
  18587. }
  18588. function compileGlyf(code, cmds, font) {
  18589. function moveTo(x, y) {
  18590. cmds.push({
  18591. cmd: "moveTo",
  18592. args: [x, y]
  18593. });
  18594. }
  18595. function lineTo(x, y) {
  18596. cmds.push({
  18597. cmd: "lineTo",
  18598. args: [x, y]
  18599. });
  18600. }
  18601. function quadraticCurveTo(xa, ya, x, y) {
  18602. cmds.push({
  18603. cmd: "quadraticCurveTo",
  18604. args: [xa, ya, x, y]
  18605. });
  18606. }
  18607. let i = 0;
  18608. const numberOfContours = getInt16(code, i);
  18609. let flags;
  18610. let x = 0,
  18611. y = 0;
  18612. i += 10;
  18613. if (numberOfContours < 0) {
  18614. do {
  18615. flags = getUint16(code, i);
  18616. const glyphIndex = getUint16(code, i + 2);
  18617. i += 4;
  18618. let arg1, arg2;
  18619. if (flags & 0x01) {
  18620. if (flags & 0x02) {
  18621. arg1 = getInt16(code, i);
  18622. arg2 = getInt16(code, i + 2);
  18623. } else {
  18624. arg1 = getUint16(code, i);
  18625. arg2 = getUint16(code, i + 2);
  18626. }
  18627. i += 4;
  18628. } else if (flags & 0x02) {
  18629. arg1 = getInt8(code, i++);
  18630. arg2 = getInt8(code, i++);
  18631. } else {
  18632. arg1 = code[i++];
  18633. arg2 = code[i++];
  18634. }
  18635. if (flags & 0x02) {
  18636. x = arg1;
  18637. y = arg2;
  18638. } else {
  18639. x = 0;
  18640. y = 0;
  18641. }
  18642. let scaleX = 1,
  18643. scaleY = 1,
  18644. scale01 = 0,
  18645. scale10 = 0;
  18646. if (flags & 0x08) {
  18647. scaleX = scaleY = getFloat214(code, i);
  18648. i += 2;
  18649. } else if (flags & 0x40) {
  18650. scaleX = getFloat214(code, i);
  18651. scaleY = getFloat214(code, i + 2);
  18652. i += 4;
  18653. } else if (flags & 0x80) {
  18654. scaleX = getFloat214(code, i);
  18655. scale01 = getFloat214(code, i + 2);
  18656. scale10 = getFloat214(code, i + 4);
  18657. scaleY = getFloat214(code, i + 6);
  18658. i += 8;
  18659. }
  18660. const subglyph = font.glyphs[glyphIndex];
  18661. if (subglyph) {
  18662. cmds.push({
  18663. cmd: "save"
  18664. }, {
  18665. cmd: "transform",
  18666. args: [scaleX, scale01, scale10, scaleY, x, y]
  18667. });
  18668. if (!(flags & 0x02)) {}
  18669. compileGlyf(subglyph, cmds, font);
  18670. cmds.push({
  18671. cmd: "restore"
  18672. });
  18673. }
  18674. } while (flags & 0x20);
  18675. } else {
  18676. const endPtsOfContours = [];
  18677. let j, jj;
  18678. for (j = 0; j < numberOfContours; j++) {
  18679. endPtsOfContours.push(getUint16(code, i));
  18680. i += 2;
  18681. }
  18682. const instructionLength = getUint16(code, i);
  18683. i += 2 + instructionLength;
  18684. const numberOfPoints = endPtsOfContours.at(-1) + 1;
  18685. const points = [];
  18686. while (points.length < numberOfPoints) {
  18687. flags = code[i++];
  18688. let repeat = 1;
  18689. if (flags & 0x08) {
  18690. repeat += code[i++];
  18691. }
  18692. while (repeat-- > 0) {
  18693. points.push({
  18694. flags
  18695. });
  18696. }
  18697. }
  18698. for (j = 0; j < numberOfPoints; j++) {
  18699. switch (points[j].flags & 0x12) {
  18700. case 0x00:
  18701. x += getInt16(code, i);
  18702. i += 2;
  18703. break;
  18704. case 0x02:
  18705. x -= code[i++];
  18706. break;
  18707. case 0x12:
  18708. x += code[i++];
  18709. break;
  18710. }
  18711. points[j].x = x;
  18712. }
  18713. for (j = 0; j < numberOfPoints; j++) {
  18714. switch (points[j].flags & 0x24) {
  18715. case 0x00:
  18716. y += getInt16(code, i);
  18717. i += 2;
  18718. break;
  18719. case 0x04:
  18720. y -= code[i++];
  18721. break;
  18722. case 0x24:
  18723. y += code[i++];
  18724. break;
  18725. }
  18726. points[j].y = y;
  18727. }
  18728. let startPoint = 0;
  18729. for (i = 0; i < numberOfContours; i++) {
  18730. const endPoint = endPtsOfContours[i];
  18731. const contour = points.slice(startPoint, endPoint + 1);
  18732. if (contour[0].flags & 1) {
  18733. contour.push(contour[0]);
  18734. } else if (contour.at(-1).flags & 1) {
  18735. contour.unshift(contour.at(-1));
  18736. } else {
  18737. const p = {
  18738. flags: 1,
  18739. x: (contour[0].x + contour.at(-1).x) / 2,
  18740. y: (contour[0].y + contour.at(-1).y) / 2
  18741. };
  18742. contour.unshift(p);
  18743. contour.push(p);
  18744. }
  18745. moveTo(contour[0].x, contour[0].y);
  18746. for (j = 1, jj = contour.length; j < jj; j++) {
  18747. if (contour[j].flags & 1) {
  18748. lineTo(contour[j].x, contour[j].y);
  18749. } else if (contour[j + 1].flags & 1) {
  18750. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  18751. j++;
  18752. } else {
  18753. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  18754. }
  18755. }
  18756. startPoint = endPoint + 1;
  18757. }
  18758. }
  18759. }
  18760. function compileCharString(charStringCode, cmds, font, glyphId) {
  18761. function moveTo(x, y) {
  18762. cmds.push({
  18763. cmd: "moveTo",
  18764. args: [x, y]
  18765. });
  18766. }
  18767. function lineTo(x, y) {
  18768. cmds.push({
  18769. cmd: "lineTo",
  18770. args: [x, y]
  18771. });
  18772. }
  18773. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  18774. cmds.push({
  18775. cmd: "bezierCurveTo",
  18776. args: [x1, y1, x2, y2, x, y]
  18777. });
  18778. }
  18779. const stack = [];
  18780. let x = 0,
  18781. y = 0;
  18782. let stems = 0;
  18783. function parse(code) {
  18784. let i = 0;
  18785. while (i < code.length) {
  18786. let stackClean = false;
  18787. let v = code[i++];
  18788. let xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  18789. switch (v) {
  18790. case 1:
  18791. stems += stack.length >> 1;
  18792. stackClean = true;
  18793. break;
  18794. case 3:
  18795. stems += stack.length >> 1;
  18796. stackClean = true;
  18797. break;
  18798. case 4:
  18799. y += stack.pop();
  18800. moveTo(x, y);
  18801. stackClean = true;
  18802. break;
  18803. case 5:
  18804. while (stack.length > 0) {
  18805. x += stack.shift();
  18806. y += stack.shift();
  18807. lineTo(x, y);
  18808. }
  18809. break;
  18810. case 6:
  18811. while (stack.length > 0) {
  18812. x += stack.shift();
  18813. lineTo(x, y);
  18814. if (stack.length === 0) {
  18815. break;
  18816. }
  18817. y += stack.shift();
  18818. lineTo(x, y);
  18819. }
  18820. break;
  18821. case 7:
  18822. while (stack.length > 0) {
  18823. y += stack.shift();
  18824. lineTo(x, y);
  18825. if (stack.length === 0) {
  18826. break;
  18827. }
  18828. x += stack.shift();
  18829. lineTo(x, y);
  18830. }
  18831. break;
  18832. case 8:
  18833. while (stack.length > 0) {
  18834. xa = x + stack.shift();
  18835. ya = y + stack.shift();
  18836. xb = xa + stack.shift();
  18837. yb = ya + stack.shift();
  18838. x = xb + stack.shift();
  18839. y = yb + stack.shift();
  18840. bezierCurveTo(xa, ya, xb, yb, x, y);
  18841. }
  18842. break;
  18843. case 10:
  18844. n = stack.pop();
  18845. subrCode = null;
  18846. if (font.isCFFCIDFont) {
  18847. const fdIndex = font.fdSelect.getFDIndex(glyphId);
  18848. if (fdIndex >= 0 && fdIndex < font.fdArray.length) {
  18849. const fontDict = font.fdArray[fdIndex];
  18850. let subrs;
  18851. if (fontDict.privateDict?.subrsIndex) {
  18852. subrs = fontDict.privateDict.subrsIndex.objects;
  18853. }
  18854. if (subrs) {
  18855. n += getSubroutineBias(subrs);
  18856. subrCode = subrs[n];
  18857. }
  18858. } else {
  18859. warn("Invalid fd index for glyph index.");
  18860. }
  18861. } else {
  18862. subrCode = font.subrs[n + font.subrsBias];
  18863. }
  18864. if (subrCode) {
  18865. parse(subrCode);
  18866. }
  18867. break;
  18868. case 11:
  18869. return;
  18870. case 12:
  18871. v = code[i++];
  18872. switch (v) {
  18873. case 34:
  18874. xa = x + stack.shift();
  18875. xb = xa + stack.shift();
  18876. y1 = y + stack.shift();
  18877. x = xb + stack.shift();
  18878. bezierCurveTo(xa, y, xb, y1, x, y1);
  18879. xa = x + stack.shift();
  18880. xb = xa + stack.shift();
  18881. x = xb + stack.shift();
  18882. bezierCurveTo(xa, y1, xb, y, x, y);
  18883. break;
  18884. case 35:
  18885. xa = x + stack.shift();
  18886. ya = y + stack.shift();
  18887. xb = xa + stack.shift();
  18888. yb = ya + stack.shift();
  18889. x = xb + stack.shift();
  18890. y = yb + stack.shift();
  18891. bezierCurveTo(xa, ya, xb, yb, x, y);
  18892. xa = x + stack.shift();
  18893. ya = y + stack.shift();
  18894. xb = xa + stack.shift();
  18895. yb = ya + stack.shift();
  18896. x = xb + stack.shift();
  18897. y = yb + stack.shift();
  18898. bezierCurveTo(xa, ya, xb, yb, x, y);
  18899. stack.pop();
  18900. break;
  18901. case 36:
  18902. xa = x + stack.shift();
  18903. y1 = y + stack.shift();
  18904. xb = xa + stack.shift();
  18905. y2 = y1 + stack.shift();
  18906. x = xb + stack.shift();
  18907. bezierCurveTo(xa, y1, xb, y2, x, y2);
  18908. xa = x + stack.shift();
  18909. xb = xa + stack.shift();
  18910. y3 = y2 + stack.shift();
  18911. x = xb + stack.shift();
  18912. bezierCurveTo(xa, y2, xb, y3, x, y);
  18913. break;
  18914. case 37:
  18915. const x0 = x,
  18916. y0 = y;
  18917. xa = x + stack.shift();
  18918. ya = y + stack.shift();
  18919. xb = xa + stack.shift();
  18920. yb = ya + stack.shift();
  18921. x = xb + stack.shift();
  18922. y = yb + stack.shift();
  18923. bezierCurveTo(xa, ya, xb, yb, x, y);
  18924. xa = x + stack.shift();
  18925. ya = y + stack.shift();
  18926. xb = xa + stack.shift();
  18927. yb = ya + stack.shift();
  18928. x = xb;
  18929. y = yb;
  18930. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  18931. x += stack.shift();
  18932. } else {
  18933. y += stack.shift();
  18934. }
  18935. bezierCurveTo(xa, ya, xb, yb, x, y);
  18936. break;
  18937. default:
  18938. throw new FormatError(`unknown operator: 12 ${v}`);
  18939. }
  18940. break;
  18941. case 14:
  18942. if (stack.length >= 4) {
  18943. const achar = stack.pop();
  18944. const bchar = stack.pop();
  18945. y = stack.pop();
  18946. x = stack.pop();
  18947. cmds.push({
  18948. cmd: "save"
  18949. }, {
  18950. cmd: "translate",
  18951. args: [x, y]
  18952. });
  18953. let cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  18954. compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
  18955. cmds.push({
  18956. cmd: "restore"
  18957. });
  18958. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  18959. compileCharString(font.glyphs[cmap.glyphId], cmds, font, cmap.glyphId);
  18960. }
  18961. return;
  18962. case 18:
  18963. stems += stack.length >> 1;
  18964. stackClean = true;
  18965. break;
  18966. case 19:
  18967. stems += stack.length >> 1;
  18968. i += stems + 7 >> 3;
  18969. stackClean = true;
  18970. break;
  18971. case 20:
  18972. stems += stack.length >> 1;
  18973. i += stems + 7 >> 3;
  18974. stackClean = true;
  18975. break;
  18976. case 21:
  18977. y += stack.pop();
  18978. x += stack.pop();
  18979. moveTo(x, y);
  18980. stackClean = true;
  18981. break;
  18982. case 22:
  18983. x += stack.pop();
  18984. moveTo(x, y);
  18985. stackClean = true;
  18986. break;
  18987. case 23:
  18988. stems += stack.length >> 1;
  18989. stackClean = true;
  18990. break;
  18991. case 24:
  18992. while (stack.length > 2) {
  18993. xa = x + stack.shift();
  18994. ya = y + stack.shift();
  18995. xb = xa + stack.shift();
  18996. yb = ya + stack.shift();
  18997. x = xb + stack.shift();
  18998. y = yb + stack.shift();
  18999. bezierCurveTo(xa, ya, xb, yb, x, y);
  19000. }
  19001. x += stack.shift();
  19002. y += stack.shift();
  19003. lineTo(x, y);
  19004. break;
  19005. case 25:
  19006. while (stack.length > 6) {
  19007. x += stack.shift();
  19008. y += stack.shift();
  19009. lineTo(x, y);
  19010. }
  19011. xa = x + stack.shift();
  19012. ya = y + stack.shift();
  19013. xb = xa + stack.shift();
  19014. yb = ya + stack.shift();
  19015. x = xb + stack.shift();
  19016. y = yb + stack.shift();
  19017. bezierCurveTo(xa, ya, xb, yb, x, y);
  19018. break;
  19019. case 26:
  19020. if (stack.length % 2) {
  19021. x += stack.shift();
  19022. }
  19023. while (stack.length > 0) {
  19024. xa = x;
  19025. ya = y + stack.shift();
  19026. xb = xa + stack.shift();
  19027. yb = ya + stack.shift();
  19028. x = xb;
  19029. y = yb + stack.shift();
  19030. bezierCurveTo(xa, ya, xb, yb, x, y);
  19031. }
  19032. break;
  19033. case 27:
  19034. if (stack.length % 2) {
  19035. y += stack.shift();
  19036. }
  19037. while (stack.length > 0) {
  19038. xa = x + stack.shift();
  19039. ya = y;
  19040. xb = xa + stack.shift();
  19041. yb = ya + stack.shift();
  19042. x = xb + stack.shift();
  19043. y = yb;
  19044. bezierCurveTo(xa, ya, xb, yb, x, y);
  19045. }
  19046. break;
  19047. case 28:
  19048. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  19049. i += 2;
  19050. break;
  19051. case 29:
  19052. n = stack.pop() + font.gsubrsBias;
  19053. subrCode = font.gsubrs[n];
  19054. if (subrCode) {
  19055. parse(subrCode);
  19056. }
  19057. break;
  19058. case 30:
  19059. while (stack.length > 0) {
  19060. xa = x;
  19061. ya = y + stack.shift();
  19062. xb = xa + stack.shift();
  19063. yb = ya + stack.shift();
  19064. x = xb + stack.shift();
  19065. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19066. bezierCurveTo(xa, ya, xb, yb, x, y);
  19067. if (stack.length === 0) {
  19068. break;
  19069. }
  19070. xa = x + stack.shift();
  19071. ya = y;
  19072. xb = xa + stack.shift();
  19073. yb = ya + stack.shift();
  19074. y = yb + stack.shift();
  19075. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19076. bezierCurveTo(xa, ya, xb, yb, x, y);
  19077. }
  19078. break;
  19079. case 31:
  19080. while (stack.length > 0) {
  19081. xa = x + stack.shift();
  19082. ya = y;
  19083. xb = xa + stack.shift();
  19084. yb = ya + stack.shift();
  19085. y = yb + stack.shift();
  19086. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19087. bezierCurveTo(xa, ya, xb, yb, x, y);
  19088. if (stack.length === 0) {
  19089. break;
  19090. }
  19091. xa = x;
  19092. ya = y + stack.shift();
  19093. xb = xa + stack.shift();
  19094. yb = ya + stack.shift();
  19095. x = xb + stack.shift();
  19096. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19097. bezierCurveTo(xa, ya, xb, yb, x, y);
  19098. }
  19099. break;
  19100. default:
  19101. if (v < 32) {
  19102. throw new FormatError(`unknown operator: ${v}`);
  19103. }
  19104. if (v < 247) {
  19105. stack.push(v - 139);
  19106. } else if (v < 251) {
  19107. stack.push((v - 247) * 256 + code[i++] + 108);
  19108. } else if (v < 255) {
  19109. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19110. } else {
  19111. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  19112. i += 4;
  19113. }
  19114. break;
  19115. }
  19116. if (stackClean) {
  19117. stack.length = 0;
  19118. }
  19119. }
  19120. }
  19121. parse(charStringCode);
  19122. }
  19123. const NOOP = [];
  19124. class CompiledFont {
  19125. constructor(fontMatrix) {
  19126. if (this.constructor === CompiledFont) {
  19127. unreachable("Cannot initialize CompiledFont.");
  19128. }
  19129. this.fontMatrix = fontMatrix;
  19130. this.compiledGlyphs = Object.create(null);
  19131. this.compiledCharCodeToGlyphId = Object.create(null);
  19132. }
  19133. getPathJs(unicode) {
  19134. const {
  19135. charCode,
  19136. glyphId
  19137. } = lookupCmap(this.cmap, unicode);
  19138. let fn = this.compiledGlyphs[glyphId];
  19139. if (!fn) {
  19140. try {
  19141. fn = this.compileGlyph(this.glyphs[glyphId], glyphId);
  19142. this.compiledGlyphs[glyphId] = fn;
  19143. } catch (ex) {
  19144. this.compiledGlyphs[glyphId] = NOOP;
  19145. if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
  19146. this.compiledCharCodeToGlyphId[charCode] = glyphId;
  19147. }
  19148. throw ex;
  19149. }
  19150. }
  19151. if (this.compiledCharCodeToGlyphId[charCode] === undefined) {
  19152. this.compiledCharCodeToGlyphId[charCode] = glyphId;
  19153. }
  19154. return fn;
  19155. }
  19156. compileGlyph(code, glyphId) {
  19157. if (!code || code.length === 0 || code[0] === 14) {
  19158. return NOOP;
  19159. }
  19160. let fontMatrix = this.fontMatrix;
  19161. if (this.isCFFCIDFont) {
  19162. const fdIndex = this.fdSelect.getFDIndex(glyphId);
  19163. if (fdIndex >= 0 && fdIndex < this.fdArray.length) {
  19164. const fontDict = this.fdArray[fdIndex];
  19165. fontMatrix = fontDict.getByName("FontMatrix") || FONT_IDENTITY_MATRIX;
  19166. } else {
  19167. warn("Invalid fd index for glyph index.");
  19168. }
  19169. }
  19170. const cmds = [{
  19171. cmd: "save"
  19172. }, {
  19173. cmd: "transform",
  19174. args: fontMatrix.slice()
  19175. }, {
  19176. cmd: "scale",
  19177. args: ["size", "-size"]
  19178. }];
  19179. this.compileGlyphImpl(code, cmds, glyphId);
  19180. cmds.push({
  19181. cmd: "restore"
  19182. });
  19183. return cmds;
  19184. }
  19185. compileGlyphImpl() {
  19186. unreachable("Children classes should implement this.");
  19187. }
  19188. hasBuiltPath(unicode) {
  19189. const {
  19190. charCode,
  19191. glyphId
  19192. } = lookupCmap(this.cmap, unicode);
  19193. return this.compiledGlyphs[glyphId] !== undefined && this.compiledCharCodeToGlyphId[charCode] !== undefined;
  19194. }
  19195. }
  19196. class TrueTypeCompiled extends CompiledFont {
  19197. constructor(glyphs, cmap, fontMatrix) {
  19198. super(fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0]);
  19199. this.glyphs = glyphs;
  19200. this.cmap = cmap;
  19201. }
  19202. compileGlyphImpl(code, cmds) {
  19203. compileGlyf(code, cmds, this);
  19204. }
  19205. }
  19206. class Type2Compiled extends CompiledFont {
  19207. constructor(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19208. super(fontMatrix || [0.001, 0, 0, 0.001, 0, 0]);
  19209. this.glyphs = cffInfo.glyphs;
  19210. this.gsubrs = cffInfo.gsubrs || [];
  19211. this.subrs = cffInfo.subrs || [];
  19212. this.cmap = cmap;
  19213. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  19214. this.gsubrsBias = getSubroutineBias(this.gsubrs);
  19215. this.subrsBias = getSubroutineBias(this.subrs);
  19216. this.isCFFCIDFont = cffInfo.isCFFCIDFont;
  19217. this.fdSelect = cffInfo.fdSelect;
  19218. this.fdArray = cffInfo.fdArray;
  19219. }
  19220. compileGlyphImpl(code, cmds, glyphId) {
  19221. compileCharString(code, cmds, this, glyphId);
  19222. }
  19223. }
  19224. class FontRendererFactory {
  19225. static create(font, seacAnalysisEnabled) {
  19226. const data = new Uint8Array(font.data);
  19227. let cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19228. const numTables = getUint16(data, 4);
  19229. for (let i = 0, p = 12; i < numTables; i++, p += 16) {
  19230. const tag = bytesToString(data.subarray(p, p + 4));
  19231. const offset = getUint32(data, p + 8);
  19232. const length = getUint32(data, p + 12);
  19233. switch (tag) {
  19234. case "cmap":
  19235. cmap = parseCmap(data, offset, offset + length);
  19236. break;
  19237. case "glyf":
  19238. glyf = data.subarray(offset, offset + length);
  19239. break;
  19240. case "loca":
  19241. loca = data.subarray(offset, offset + length);
  19242. break;
  19243. case "head":
  19244. unitsPerEm = getUint16(data, offset + 18);
  19245. indexToLocFormat = getUint16(data, offset + 50);
  19246. break;
  19247. case "CFF ":
  19248. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  19249. break;
  19250. }
  19251. }
  19252. if (glyf) {
  19253. const fontMatrix = !unitsPerEm ? font.fontMatrix : [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0];
  19254. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19255. }
  19256. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19257. }
  19258. }
  19259. ;// CONCATENATED MODULE: ./src/core/metrics.js
  19260. const getMetrics = getLookupTableFactory(function (t) {
  19261. t.Courier = 600;
  19262. t["Courier-Bold"] = 600;
  19263. t["Courier-BoldOblique"] = 600;
  19264. t["Courier-Oblique"] = 600;
  19265. t.Helvetica = getLookupTableFactory(function (t) {
  19266. t.space = 278;
  19267. t.exclam = 278;
  19268. t.quotedbl = 355;
  19269. t.numbersign = 556;
  19270. t.dollar = 556;
  19271. t.percent = 889;
  19272. t.ampersand = 667;
  19273. t.quoteright = 222;
  19274. t.parenleft = 333;
  19275. t.parenright = 333;
  19276. t.asterisk = 389;
  19277. t.plus = 584;
  19278. t.comma = 278;
  19279. t.hyphen = 333;
  19280. t.period = 278;
  19281. t.slash = 278;
  19282. t.zero = 556;
  19283. t.one = 556;
  19284. t.two = 556;
  19285. t.three = 556;
  19286. t.four = 556;
  19287. t.five = 556;
  19288. t.six = 556;
  19289. t.seven = 556;
  19290. t.eight = 556;
  19291. t.nine = 556;
  19292. t.colon = 278;
  19293. t.semicolon = 278;
  19294. t.less = 584;
  19295. t.equal = 584;
  19296. t.greater = 584;
  19297. t.question = 556;
  19298. t.at = 1015;
  19299. t.A = 667;
  19300. t.B = 667;
  19301. t.C = 722;
  19302. t.D = 722;
  19303. t.E = 667;
  19304. t.F = 611;
  19305. t.G = 778;
  19306. t.H = 722;
  19307. t.I = 278;
  19308. t.J = 500;
  19309. t.K = 667;
  19310. t.L = 556;
  19311. t.M = 833;
  19312. t.N = 722;
  19313. t.O = 778;
  19314. t.P = 667;
  19315. t.Q = 778;
  19316. t.R = 722;
  19317. t.S = 667;
  19318. t.T = 611;
  19319. t.U = 722;
  19320. t.V = 667;
  19321. t.W = 944;
  19322. t.X = 667;
  19323. t.Y = 667;
  19324. t.Z = 611;
  19325. t.bracketleft = 278;
  19326. t.backslash = 278;
  19327. t.bracketright = 278;
  19328. t.asciicircum = 469;
  19329. t.underscore = 556;
  19330. t.quoteleft = 222;
  19331. t.a = 556;
  19332. t.b = 556;
  19333. t.c = 500;
  19334. t.d = 556;
  19335. t.e = 556;
  19336. t.f = 278;
  19337. t.g = 556;
  19338. t.h = 556;
  19339. t.i = 222;
  19340. t.j = 222;
  19341. t.k = 500;
  19342. t.l = 222;
  19343. t.m = 833;
  19344. t.n = 556;
  19345. t.o = 556;
  19346. t.p = 556;
  19347. t.q = 556;
  19348. t.r = 333;
  19349. t.s = 500;
  19350. t.t = 278;
  19351. t.u = 556;
  19352. t.v = 500;
  19353. t.w = 722;
  19354. t.x = 500;
  19355. t.y = 500;
  19356. t.z = 500;
  19357. t.braceleft = 334;
  19358. t.bar = 260;
  19359. t.braceright = 334;
  19360. t.asciitilde = 584;
  19361. t.exclamdown = 333;
  19362. t.cent = 556;
  19363. t.sterling = 556;
  19364. t.fraction = 167;
  19365. t.yen = 556;
  19366. t.florin = 556;
  19367. t.section = 556;
  19368. t.currency = 556;
  19369. t.quotesingle = 191;
  19370. t.quotedblleft = 333;
  19371. t.guillemotleft = 556;
  19372. t.guilsinglleft = 333;
  19373. t.guilsinglright = 333;
  19374. t.fi = 500;
  19375. t.fl = 500;
  19376. t.endash = 556;
  19377. t.dagger = 556;
  19378. t.daggerdbl = 556;
  19379. t.periodcentered = 278;
  19380. t.paragraph = 537;
  19381. t.bullet = 350;
  19382. t.quotesinglbase = 222;
  19383. t.quotedblbase = 333;
  19384. t.quotedblright = 333;
  19385. t.guillemotright = 556;
  19386. t.ellipsis = 1000;
  19387. t.perthousand = 1000;
  19388. t.questiondown = 611;
  19389. t.grave = 333;
  19390. t.acute = 333;
  19391. t.circumflex = 333;
  19392. t.tilde = 333;
  19393. t.macron = 333;
  19394. t.breve = 333;
  19395. t.dotaccent = 333;
  19396. t.dieresis = 333;
  19397. t.ring = 333;
  19398. t.cedilla = 333;
  19399. t.hungarumlaut = 333;
  19400. t.ogonek = 333;
  19401. t.caron = 333;
  19402. t.emdash = 1000;
  19403. t.AE = 1000;
  19404. t.ordfeminine = 370;
  19405. t.Lslash = 556;
  19406. t.Oslash = 778;
  19407. t.OE = 1000;
  19408. t.ordmasculine = 365;
  19409. t.ae = 889;
  19410. t.dotlessi = 278;
  19411. t.lslash = 222;
  19412. t.oslash = 611;
  19413. t.oe = 944;
  19414. t.germandbls = 611;
  19415. t.Idieresis = 278;
  19416. t.eacute = 556;
  19417. t.abreve = 556;
  19418. t.uhungarumlaut = 556;
  19419. t.ecaron = 556;
  19420. t.Ydieresis = 667;
  19421. t.divide = 584;
  19422. t.Yacute = 667;
  19423. t.Acircumflex = 667;
  19424. t.aacute = 556;
  19425. t.Ucircumflex = 722;
  19426. t.yacute = 500;
  19427. t.scommaaccent = 500;
  19428. t.ecircumflex = 556;
  19429. t.Uring = 722;
  19430. t.Udieresis = 722;
  19431. t.aogonek = 556;
  19432. t.Uacute = 722;
  19433. t.uogonek = 556;
  19434. t.Edieresis = 667;
  19435. t.Dcroat = 722;
  19436. t.commaaccent = 250;
  19437. t.copyright = 737;
  19438. t.Emacron = 667;
  19439. t.ccaron = 500;
  19440. t.aring = 556;
  19441. t.Ncommaaccent = 722;
  19442. t.lacute = 222;
  19443. t.agrave = 556;
  19444. t.Tcommaaccent = 611;
  19445. t.Cacute = 722;
  19446. t.atilde = 556;
  19447. t.Edotaccent = 667;
  19448. t.scaron = 500;
  19449. t.scedilla = 500;
  19450. t.iacute = 278;
  19451. t.lozenge = 471;
  19452. t.Rcaron = 722;
  19453. t.Gcommaaccent = 778;
  19454. t.ucircumflex = 556;
  19455. t.acircumflex = 556;
  19456. t.Amacron = 667;
  19457. t.rcaron = 333;
  19458. t.ccedilla = 500;
  19459. t.Zdotaccent = 611;
  19460. t.Thorn = 667;
  19461. t.Omacron = 778;
  19462. t.Racute = 722;
  19463. t.Sacute = 667;
  19464. t.dcaron = 643;
  19465. t.Umacron = 722;
  19466. t.uring = 556;
  19467. t.threesuperior = 333;
  19468. t.Ograve = 778;
  19469. t.Agrave = 667;
  19470. t.Abreve = 667;
  19471. t.multiply = 584;
  19472. t.uacute = 556;
  19473. t.Tcaron = 611;
  19474. t.partialdiff = 476;
  19475. t.ydieresis = 500;
  19476. t.Nacute = 722;
  19477. t.icircumflex = 278;
  19478. t.Ecircumflex = 667;
  19479. t.adieresis = 556;
  19480. t.edieresis = 556;
  19481. t.cacute = 500;
  19482. t.nacute = 556;
  19483. t.umacron = 556;
  19484. t.Ncaron = 722;
  19485. t.Iacute = 278;
  19486. t.plusminus = 584;
  19487. t.brokenbar = 260;
  19488. t.registered = 737;
  19489. t.Gbreve = 778;
  19490. t.Idotaccent = 278;
  19491. t.summation = 600;
  19492. t.Egrave = 667;
  19493. t.racute = 333;
  19494. t.omacron = 556;
  19495. t.Zacute = 611;
  19496. t.Zcaron = 611;
  19497. t.greaterequal = 549;
  19498. t.Eth = 722;
  19499. t.Ccedilla = 722;
  19500. t.lcommaaccent = 222;
  19501. t.tcaron = 317;
  19502. t.eogonek = 556;
  19503. t.Uogonek = 722;
  19504. t.Aacute = 667;
  19505. t.Adieresis = 667;
  19506. t.egrave = 556;
  19507. t.zacute = 500;
  19508. t.iogonek = 222;
  19509. t.Oacute = 778;
  19510. t.oacute = 556;
  19511. t.amacron = 556;
  19512. t.sacute = 500;
  19513. t.idieresis = 278;
  19514. t.Ocircumflex = 778;
  19515. t.Ugrave = 722;
  19516. t.Delta = 612;
  19517. t.thorn = 556;
  19518. t.twosuperior = 333;
  19519. t.Odieresis = 778;
  19520. t.mu = 556;
  19521. t.igrave = 278;
  19522. t.ohungarumlaut = 556;
  19523. t.Eogonek = 667;
  19524. t.dcroat = 556;
  19525. t.threequarters = 834;
  19526. t.Scedilla = 667;
  19527. t.lcaron = 299;
  19528. t.Kcommaaccent = 667;
  19529. t.Lacute = 556;
  19530. t.trademark = 1000;
  19531. t.edotaccent = 556;
  19532. t.Igrave = 278;
  19533. t.Imacron = 278;
  19534. t.Lcaron = 556;
  19535. t.onehalf = 834;
  19536. t.lessequal = 549;
  19537. t.ocircumflex = 556;
  19538. t.ntilde = 556;
  19539. t.Uhungarumlaut = 722;
  19540. t.Eacute = 667;
  19541. t.emacron = 556;
  19542. t.gbreve = 556;
  19543. t.onequarter = 834;
  19544. t.Scaron = 667;
  19545. t.Scommaaccent = 667;
  19546. t.Ohungarumlaut = 778;
  19547. t.degree = 400;
  19548. t.ograve = 556;
  19549. t.Ccaron = 722;
  19550. t.ugrave = 556;
  19551. t.radical = 453;
  19552. t.Dcaron = 722;
  19553. t.rcommaaccent = 333;
  19554. t.Ntilde = 722;
  19555. t.otilde = 556;
  19556. t.Rcommaaccent = 722;
  19557. t.Lcommaaccent = 556;
  19558. t.Atilde = 667;
  19559. t.Aogonek = 667;
  19560. t.Aring = 667;
  19561. t.Otilde = 778;
  19562. t.zdotaccent = 500;
  19563. t.Ecaron = 667;
  19564. t.Iogonek = 278;
  19565. t.kcommaaccent = 500;
  19566. t.minus = 584;
  19567. t.Icircumflex = 278;
  19568. t.ncaron = 556;
  19569. t.tcommaaccent = 278;
  19570. t.logicalnot = 584;
  19571. t.odieresis = 556;
  19572. t.udieresis = 556;
  19573. t.notequal = 549;
  19574. t.gcommaaccent = 556;
  19575. t.eth = 556;
  19576. t.zcaron = 500;
  19577. t.ncommaaccent = 556;
  19578. t.onesuperior = 333;
  19579. t.imacron = 278;
  19580. t.Euro = 556;
  19581. });
  19582. t["Helvetica-Bold"] = getLookupTableFactory(function (t) {
  19583. t.space = 278;
  19584. t.exclam = 333;
  19585. t.quotedbl = 474;
  19586. t.numbersign = 556;
  19587. t.dollar = 556;
  19588. t.percent = 889;
  19589. t.ampersand = 722;
  19590. t.quoteright = 278;
  19591. t.parenleft = 333;
  19592. t.parenright = 333;
  19593. t.asterisk = 389;
  19594. t.plus = 584;
  19595. t.comma = 278;
  19596. t.hyphen = 333;
  19597. t.period = 278;
  19598. t.slash = 278;
  19599. t.zero = 556;
  19600. t.one = 556;
  19601. t.two = 556;
  19602. t.three = 556;
  19603. t.four = 556;
  19604. t.five = 556;
  19605. t.six = 556;
  19606. t.seven = 556;
  19607. t.eight = 556;
  19608. t.nine = 556;
  19609. t.colon = 333;
  19610. t.semicolon = 333;
  19611. t.less = 584;
  19612. t.equal = 584;
  19613. t.greater = 584;
  19614. t.question = 611;
  19615. t.at = 975;
  19616. t.A = 722;
  19617. t.B = 722;
  19618. t.C = 722;
  19619. t.D = 722;
  19620. t.E = 667;
  19621. t.F = 611;
  19622. t.G = 778;
  19623. t.H = 722;
  19624. t.I = 278;
  19625. t.J = 556;
  19626. t.K = 722;
  19627. t.L = 611;
  19628. t.M = 833;
  19629. t.N = 722;
  19630. t.O = 778;
  19631. t.P = 667;
  19632. t.Q = 778;
  19633. t.R = 722;
  19634. t.S = 667;
  19635. t.T = 611;
  19636. t.U = 722;
  19637. t.V = 667;
  19638. t.W = 944;
  19639. t.X = 667;
  19640. t.Y = 667;
  19641. t.Z = 611;
  19642. t.bracketleft = 333;
  19643. t.backslash = 278;
  19644. t.bracketright = 333;
  19645. t.asciicircum = 584;
  19646. t.underscore = 556;
  19647. t.quoteleft = 278;
  19648. t.a = 556;
  19649. t.b = 611;
  19650. t.c = 556;
  19651. t.d = 611;
  19652. t.e = 556;
  19653. t.f = 333;
  19654. t.g = 611;
  19655. t.h = 611;
  19656. t.i = 278;
  19657. t.j = 278;
  19658. t.k = 556;
  19659. t.l = 278;
  19660. t.m = 889;
  19661. t.n = 611;
  19662. t.o = 611;
  19663. t.p = 611;
  19664. t.q = 611;
  19665. t.r = 389;
  19666. t.s = 556;
  19667. t.t = 333;
  19668. t.u = 611;
  19669. t.v = 556;
  19670. t.w = 778;
  19671. t.x = 556;
  19672. t.y = 556;
  19673. t.z = 500;
  19674. t.braceleft = 389;
  19675. t.bar = 280;
  19676. t.braceright = 389;
  19677. t.asciitilde = 584;
  19678. t.exclamdown = 333;
  19679. t.cent = 556;
  19680. t.sterling = 556;
  19681. t.fraction = 167;
  19682. t.yen = 556;
  19683. t.florin = 556;
  19684. t.section = 556;
  19685. t.currency = 556;
  19686. t.quotesingle = 238;
  19687. t.quotedblleft = 500;
  19688. t.guillemotleft = 556;
  19689. t.guilsinglleft = 333;
  19690. t.guilsinglright = 333;
  19691. t.fi = 611;
  19692. t.fl = 611;
  19693. t.endash = 556;
  19694. t.dagger = 556;
  19695. t.daggerdbl = 556;
  19696. t.periodcentered = 278;
  19697. t.paragraph = 556;
  19698. t.bullet = 350;
  19699. t.quotesinglbase = 278;
  19700. t.quotedblbase = 500;
  19701. t.quotedblright = 500;
  19702. t.guillemotright = 556;
  19703. t.ellipsis = 1000;
  19704. t.perthousand = 1000;
  19705. t.questiondown = 611;
  19706. t.grave = 333;
  19707. t.acute = 333;
  19708. t.circumflex = 333;
  19709. t.tilde = 333;
  19710. t.macron = 333;
  19711. t.breve = 333;
  19712. t.dotaccent = 333;
  19713. t.dieresis = 333;
  19714. t.ring = 333;
  19715. t.cedilla = 333;
  19716. t.hungarumlaut = 333;
  19717. t.ogonek = 333;
  19718. t.caron = 333;
  19719. t.emdash = 1000;
  19720. t.AE = 1000;
  19721. t.ordfeminine = 370;
  19722. t.Lslash = 611;
  19723. t.Oslash = 778;
  19724. t.OE = 1000;
  19725. t.ordmasculine = 365;
  19726. t.ae = 889;
  19727. t.dotlessi = 278;
  19728. t.lslash = 278;
  19729. t.oslash = 611;
  19730. t.oe = 944;
  19731. t.germandbls = 611;
  19732. t.Idieresis = 278;
  19733. t.eacute = 556;
  19734. t.abreve = 556;
  19735. t.uhungarumlaut = 611;
  19736. t.ecaron = 556;
  19737. t.Ydieresis = 667;
  19738. t.divide = 584;
  19739. t.Yacute = 667;
  19740. t.Acircumflex = 722;
  19741. t.aacute = 556;
  19742. t.Ucircumflex = 722;
  19743. t.yacute = 556;
  19744. t.scommaaccent = 556;
  19745. t.ecircumflex = 556;
  19746. t.Uring = 722;
  19747. t.Udieresis = 722;
  19748. t.aogonek = 556;
  19749. t.Uacute = 722;
  19750. t.uogonek = 611;
  19751. t.Edieresis = 667;
  19752. t.Dcroat = 722;
  19753. t.commaaccent = 250;
  19754. t.copyright = 737;
  19755. t.Emacron = 667;
  19756. t.ccaron = 556;
  19757. t.aring = 556;
  19758. t.Ncommaaccent = 722;
  19759. t.lacute = 278;
  19760. t.agrave = 556;
  19761. t.Tcommaaccent = 611;
  19762. t.Cacute = 722;
  19763. t.atilde = 556;
  19764. t.Edotaccent = 667;
  19765. t.scaron = 556;
  19766. t.scedilla = 556;
  19767. t.iacute = 278;
  19768. t.lozenge = 494;
  19769. t.Rcaron = 722;
  19770. t.Gcommaaccent = 778;
  19771. t.ucircumflex = 611;
  19772. t.acircumflex = 556;
  19773. t.Amacron = 722;
  19774. t.rcaron = 389;
  19775. t.ccedilla = 556;
  19776. t.Zdotaccent = 611;
  19777. t.Thorn = 667;
  19778. t.Omacron = 778;
  19779. t.Racute = 722;
  19780. t.Sacute = 667;
  19781. t.dcaron = 743;
  19782. t.Umacron = 722;
  19783. t.uring = 611;
  19784. t.threesuperior = 333;
  19785. t.Ograve = 778;
  19786. t.Agrave = 722;
  19787. t.Abreve = 722;
  19788. t.multiply = 584;
  19789. t.uacute = 611;
  19790. t.Tcaron = 611;
  19791. t.partialdiff = 494;
  19792. t.ydieresis = 556;
  19793. t.Nacute = 722;
  19794. t.icircumflex = 278;
  19795. t.Ecircumflex = 667;
  19796. t.adieresis = 556;
  19797. t.edieresis = 556;
  19798. t.cacute = 556;
  19799. t.nacute = 611;
  19800. t.umacron = 611;
  19801. t.Ncaron = 722;
  19802. t.Iacute = 278;
  19803. t.plusminus = 584;
  19804. t.brokenbar = 280;
  19805. t.registered = 737;
  19806. t.Gbreve = 778;
  19807. t.Idotaccent = 278;
  19808. t.summation = 600;
  19809. t.Egrave = 667;
  19810. t.racute = 389;
  19811. t.omacron = 611;
  19812. t.Zacute = 611;
  19813. t.Zcaron = 611;
  19814. t.greaterequal = 549;
  19815. t.Eth = 722;
  19816. t.Ccedilla = 722;
  19817. t.lcommaaccent = 278;
  19818. t.tcaron = 389;
  19819. t.eogonek = 556;
  19820. t.Uogonek = 722;
  19821. t.Aacute = 722;
  19822. t.Adieresis = 722;
  19823. t.egrave = 556;
  19824. t.zacute = 500;
  19825. t.iogonek = 278;
  19826. t.Oacute = 778;
  19827. t.oacute = 611;
  19828. t.amacron = 556;
  19829. t.sacute = 556;
  19830. t.idieresis = 278;
  19831. t.Ocircumflex = 778;
  19832. t.Ugrave = 722;
  19833. t.Delta = 612;
  19834. t.thorn = 611;
  19835. t.twosuperior = 333;
  19836. t.Odieresis = 778;
  19837. t.mu = 611;
  19838. t.igrave = 278;
  19839. t.ohungarumlaut = 611;
  19840. t.Eogonek = 667;
  19841. t.dcroat = 611;
  19842. t.threequarters = 834;
  19843. t.Scedilla = 667;
  19844. t.lcaron = 400;
  19845. t.Kcommaaccent = 722;
  19846. t.Lacute = 611;
  19847. t.trademark = 1000;
  19848. t.edotaccent = 556;
  19849. t.Igrave = 278;
  19850. t.Imacron = 278;
  19851. t.Lcaron = 611;
  19852. t.onehalf = 834;
  19853. t.lessequal = 549;
  19854. t.ocircumflex = 611;
  19855. t.ntilde = 611;
  19856. t.Uhungarumlaut = 722;
  19857. t.Eacute = 667;
  19858. t.emacron = 556;
  19859. t.gbreve = 611;
  19860. t.onequarter = 834;
  19861. t.Scaron = 667;
  19862. t.Scommaaccent = 667;
  19863. t.Ohungarumlaut = 778;
  19864. t.degree = 400;
  19865. t.ograve = 611;
  19866. t.Ccaron = 722;
  19867. t.ugrave = 611;
  19868. t.radical = 549;
  19869. t.Dcaron = 722;
  19870. t.rcommaaccent = 389;
  19871. t.Ntilde = 722;
  19872. t.otilde = 611;
  19873. t.Rcommaaccent = 722;
  19874. t.Lcommaaccent = 611;
  19875. t.Atilde = 722;
  19876. t.Aogonek = 722;
  19877. t.Aring = 722;
  19878. t.Otilde = 778;
  19879. t.zdotaccent = 500;
  19880. t.Ecaron = 667;
  19881. t.Iogonek = 278;
  19882. t.kcommaaccent = 556;
  19883. t.minus = 584;
  19884. t.Icircumflex = 278;
  19885. t.ncaron = 611;
  19886. t.tcommaaccent = 333;
  19887. t.logicalnot = 584;
  19888. t.odieresis = 611;
  19889. t.udieresis = 611;
  19890. t.notequal = 549;
  19891. t.gcommaaccent = 611;
  19892. t.eth = 611;
  19893. t.zcaron = 500;
  19894. t.ncommaaccent = 611;
  19895. t.onesuperior = 333;
  19896. t.imacron = 278;
  19897. t.Euro = 556;
  19898. });
  19899. t["Helvetica-BoldOblique"] = getLookupTableFactory(function (t) {
  19900. t.space = 278;
  19901. t.exclam = 333;
  19902. t.quotedbl = 474;
  19903. t.numbersign = 556;
  19904. t.dollar = 556;
  19905. t.percent = 889;
  19906. t.ampersand = 722;
  19907. t.quoteright = 278;
  19908. t.parenleft = 333;
  19909. t.parenright = 333;
  19910. t.asterisk = 389;
  19911. t.plus = 584;
  19912. t.comma = 278;
  19913. t.hyphen = 333;
  19914. t.period = 278;
  19915. t.slash = 278;
  19916. t.zero = 556;
  19917. t.one = 556;
  19918. t.two = 556;
  19919. t.three = 556;
  19920. t.four = 556;
  19921. t.five = 556;
  19922. t.six = 556;
  19923. t.seven = 556;
  19924. t.eight = 556;
  19925. t.nine = 556;
  19926. t.colon = 333;
  19927. t.semicolon = 333;
  19928. t.less = 584;
  19929. t.equal = 584;
  19930. t.greater = 584;
  19931. t.question = 611;
  19932. t.at = 975;
  19933. t.A = 722;
  19934. t.B = 722;
  19935. t.C = 722;
  19936. t.D = 722;
  19937. t.E = 667;
  19938. t.F = 611;
  19939. t.G = 778;
  19940. t.H = 722;
  19941. t.I = 278;
  19942. t.J = 556;
  19943. t.K = 722;
  19944. t.L = 611;
  19945. t.M = 833;
  19946. t.N = 722;
  19947. t.O = 778;
  19948. t.P = 667;
  19949. t.Q = 778;
  19950. t.R = 722;
  19951. t.S = 667;
  19952. t.T = 611;
  19953. t.U = 722;
  19954. t.V = 667;
  19955. t.W = 944;
  19956. t.X = 667;
  19957. t.Y = 667;
  19958. t.Z = 611;
  19959. t.bracketleft = 333;
  19960. t.backslash = 278;
  19961. t.bracketright = 333;
  19962. t.asciicircum = 584;
  19963. t.underscore = 556;
  19964. t.quoteleft = 278;
  19965. t.a = 556;
  19966. t.b = 611;
  19967. t.c = 556;
  19968. t.d = 611;
  19969. t.e = 556;
  19970. t.f = 333;
  19971. t.g = 611;
  19972. t.h = 611;
  19973. t.i = 278;
  19974. t.j = 278;
  19975. t.k = 556;
  19976. t.l = 278;
  19977. t.m = 889;
  19978. t.n = 611;
  19979. t.o = 611;
  19980. t.p = 611;
  19981. t.q = 611;
  19982. t.r = 389;
  19983. t.s = 556;
  19984. t.t = 333;
  19985. t.u = 611;
  19986. t.v = 556;
  19987. t.w = 778;
  19988. t.x = 556;
  19989. t.y = 556;
  19990. t.z = 500;
  19991. t.braceleft = 389;
  19992. t.bar = 280;
  19993. t.braceright = 389;
  19994. t.asciitilde = 584;
  19995. t.exclamdown = 333;
  19996. t.cent = 556;
  19997. t.sterling = 556;
  19998. t.fraction = 167;
  19999. t.yen = 556;
  20000. t.florin = 556;
  20001. t.section = 556;
  20002. t.currency = 556;
  20003. t.quotesingle = 238;
  20004. t.quotedblleft = 500;
  20005. t.guillemotleft = 556;
  20006. t.guilsinglleft = 333;
  20007. t.guilsinglright = 333;
  20008. t.fi = 611;
  20009. t.fl = 611;
  20010. t.endash = 556;
  20011. t.dagger = 556;
  20012. t.daggerdbl = 556;
  20013. t.periodcentered = 278;
  20014. t.paragraph = 556;
  20015. t.bullet = 350;
  20016. t.quotesinglbase = 278;
  20017. t.quotedblbase = 500;
  20018. t.quotedblright = 500;
  20019. t.guillemotright = 556;
  20020. t.ellipsis = 1000;
  20021. t.perthousand = 1000;
  20022. t.questiondown = 611;
  20023. t.grave = 333;
  20024. t.acute = 333;
  20025. t.circumflex = 333;
  20026. t.tilde = 333;
  20027. t.macron = 333;
  20028. t.breve = 333;
  20029. t.dotaccent = 333;
  20030. t.dieresis = 333;
  20031. t.ring = 333;
  20032. t.cedilla = 333;
  20033. t.hungarumlaut = 333;
  20034. t.ogonek = 333;
  20035. t.caron = 333;
  20036. t.emdash = 1000;
  20037. t.AE = 1000;
  20038. t.ordfeminine = 370;
  20039. t.Lslash = 611;
  20040. t.Oslash = 778;
  20041. t.OE = 1000;
  20042. t.ordmasculine = 365;
  20043. t.ae = 889;
  20044. t.dotlessi = 278;
  20045. t.lslash = 278;
  20046. t.oslash = 611;
  20047. t.oe = 944;
  20048. t.germandbls = 611;
  20049. t.Idieresis = 278;
  20050. t.eacute = 556;
  20051. t.abreve = 556;
  20052. t.uhungarumlaut = 611;
  20053. t.ecaron = 556;
  20054. t.Ydieresis = 667;
  20055. t.divide = 584;
  20056. t.Yacute = 667;
  20057. t.Acircumflex = 722;
  20058. t.aacute = 556;
  20059. t.Ucircumflex = 722;
  20060. t.yacute = 556;
  20061. t.scommaaccent = 556;
  20062. t.ecircumflex = 556;
  20063. t.Uring = 722;
  20064. t.Udieresis = 722;
  20065. t.aogonek = 556;
  20066. t.Uacute = 722;
  20067. t.uogonek = 611;
  20068. t.Edieresis = 667;
  20069. t.Dcroat = 722;
  20070. t.commaaccent = 250;
  20071. t.copyright = 737;
  20072. t.Emacron = 667;
  20073. t.ccaron = 556;
  20074. t.aring = 556;
  20075. t.Ncommaaccent = 722;
  20076. t.lacute = 278;
  20077. t.agrave = 556;
  20078. t.Tcommaaccent = 611;
  20079. t.Cacute = 722;
  20080. t.atilde = 556;
  20081. t.Edotaccent = 667;
  20082. t.scaron = 556;
  20083. t.scedilla = 556;
  20084. t.iacute = 278;
  20085. t.lozenge = 494;
  20086. t.Rcaron = 722;
  20087. t.Gcommaaccent = 778;
  20088. t.ucircumflex = 611;
  20089. t.acircumflex = 556;
  20090. t.Amacron = 722;
  20091. t.rcaron = 389;
  20092. t.ccedilla = 556;
  20093. t.Zdotaccent = 611;
  20094. t.Thorn = 667;
  20095. t.Omacron = 778;
  20096. t.Racute = 722;
  20097. t.Sacute = 667;
  20098. t.dcaron = 743;
  20099. t.Umacron = 722;
  20100. t.uring = 611;
  20101. t.threesuperior = 333;
  20102. t.Ograve = 778;
  20103. t.Agrave = 722;
  20104. t.Abreve = 722;
  20105. t.multiply = 584;
  20106. t.uacute = 611;
  20107. t.Tcaron = 611;
  20108. t.partialdiff = 494;
  20109. t.ydieresis = 556;
  20110. t.Nacute = 722;
  20111. t.icircumflex = 278;
  20112. t.Ecircumflex = 667;
  20113. t.adieresis = 556;
  20114. t.edieresis = 556;
  20115. t.cacute = 556;
  20116. t.nacute = 611;
  20117. t.umacron = 611;
  20118. t.Ncaron = 722;
  20119. t.Iacute = 278;
  20120. t.plusminus = 584;
  20121. t.brokenbar = 280;
  20122. t.registered = 737;
  20123. t.Gbreve = 778;
  20124. t.Idotaccent = 278;
  20125. t.summation = 600;
  20126. t.Egrave = 667;
  20127. t.racute = 389;
  20128. t.omacron = 611;
  20129. t.Zacute = 611;
  20130. t.Zcaron = 611;
  20131. t.greaterequal = 549;
  20132. t.Eth = 722;
  20133. t.Ccedilla = 722;
  20134. t.lcommaaccent = 278;
  20135. t.tcaron = 389;
  20136. t.eogonek = 556;
  20137. t.Uogonek = 722;
  20138. t.Aacute = 722;
  20139. t.Adieresis = 722;
  20140. t.egrave = 556;
  20141. t.zacute = 500;
  20142. t.iogonek = 278;
  20143. t.Oacute = 778;
  20144. t.oacute = 611;
  20145. t.amacron = 556;
  20146. t.sacute = 556;
  20147. t.idieresis = 278;
  20148. t.Ocircumflex = 778;
  20149. t.Ugrave = 722;
  20150. t.Delta = 612;
  20151. t.thorn = 611;
  20152. t.twosuperior = 333;
  20153. t.Odieresis = 778;
  20154. t.mu = 611;
  20155. t.igrave = 278;
  20156. t.ohungarumlaut = 611;
  20157. t.Eogonek = 667;
  20158. t.dcroat = 611;
  20159. t.threequarters = 834;
  20160. t.Scedilla = 667;
  20161. t.lcaron = 400;
  20162. t.Kcommaaccent = 722;
  20163. t.Lacute = 611;
  20164. t.trademark = 1000;
  20165. t.edotaccent = 556;
  20166. t.Igrave = 278;
  20167. t.Imacron = 278;
  20168. t.Lcaron = 611;
  20169. t.onehalf = 834;
  20170. t.lessequal = 549;
  20171. t.ocircumflex = 611;
  20172. t.ntilde = 611;
  20173. t.Uhungarumlaut = 722;
  20174. t.Eacute = 667;
  20175. t.emacron = 556;
  20176. t.gbreve = 611;
  20177. t.onequarter = 834;
  20178. t.Scaron = 667;
  20179. t.Scommaaccent = 667;
  20180. t.Ohungarumlaut = 778;
  20181. t.degree = 400;
  20182. t.ograve = 611;
  20183. t.Ccaron = 722;
  20184. t.ugrave = 611;
  20185. t.radical = 549;
  20186. t.Dcaron = 722;
  20187. t.rcommaaccent = 389;
  20188. t.Ntilde = 722;
  20189. t.otilde = 611;
  20190. t.Rcommaaccent = 722;
  20191. t.Lcommaaccent = 611;
  20192. t.Atilde = 722;
  20193. t.Aogonek = 722;
  20194. t.Aring = 722;
  20195. t.Otilde = 778;
  20196. t.zdotaccent = 500;
  20197. t.Ecaron = 667;
  20198. t.Iogonek = 278;
  20199. t.kcommaaccent = 556;
  20200. t.minus = 584;
  20201. t.Icircumflex = 278;
  20202. t.ncaron = 611;
  20203. t.tcommaaccent = 333;
  20204. t.logicalnot = 584;
  20205. t.odieresis = 611;
  20206. t.udieresis = 611;
  20207. t.notequal = 549;
  20208. t.gcommaaccent = 611;
  20209. t.eth = 611;
  20210. t.zcaron = 500;
  20211. t.ncommaaccent = 611;
  20212. t.onesuperior = 333;
  20213. t.imacron = 278;
  20214. t.Euro = 556;
  20215. });
  20216. t["Helvetica-Oblique"] = getLookupTableFactory(function (t) {
  20217. t.space = 278;
  20218. t.exclam = 278;
  20219. t.quotedbl = 355;
  20220. t.numbersign = 556;
  20221. t.dollar = 556;
  20222. t.percent = 889;
  20223. t.ampersand = 667;
  20224. t.quoteright = 222;
  20225. t.parenleft = 333;
  20226. t.parenright = 333;
  20227. t.asterisk = 389;
  20228. t.plus = 584;
  20229. t.comma = 278;
  20230. t.hyphen = 333;
  20231. t.period = 278;
  20232. t.slash = 278;
  20233. t.zero = 556;
  20234. t.one = 556;
  20235. t.two = 556;
  20236. t.three = 556;
  20237. t.four = 556;
  20238. t.five = 556;
  20239. t.six = 556;
  20240. t.seven = 556;
  20241. t.eight = 556;
  20242. t.nine = 556;
  20243. t.colon = 278;
  20244. t.semicolon = 278;
  20245. t.less = 584;
  20246. t.equal = 584;
  20247. t.greater = 584;
  20248. t.question = 556;
  20249. t.at = 1015;
  20250. t.A = 667;
  20251. t.B = 667;
  20252. t.C = 722;
  20253. t.D = 722;
  20254. t.E = 667;
  20255. t.F = 611;
  20256. t.G = 778;
  20257. t.H = 722;
  20258. t.I = 278;
  20259. t.J = 500;
  20260. t.K = 667;
  20261. t.L = 556;
  20262. t.M = 833;
  20263. t.N = 722;
  20264. t.O = 778;
  20265. t.P = 667;
  20266. t.Q = 778;
  20267. t.R = 722;
  20268. t.S = 667;
  20269. t.T = 611;
  20270. t.U = 722;
  20271. t.V = 667;
  20272. t.W = 944;
  20273. t.X = 667;
  20274. t.Y = 667;
  20275. t.Z = 611;
  20276. t.bracketleft = 278;
  20277. t.backslash = 278;
  20278. t.bracketright = 278;
  20279. t.asciicircum = 469;
  20280. t.underscore = 556;
  20281. t.quoteleft = 222;
  20282. t.a = 556;
  20283. t.b = 556;
  20284. t.c = 500;
  20285. t.d = 556;
  20286. t.e = 556;
  20287. t.f = 278;
  20288. t.g = 556;
  20289. t.h = 556;
  20290. t.i = 222;
  20291. t.j = 222;
  20292. t.k = 500;
  20293. t.l = 222;
  20294. t.m = 833;
  20295. t.n = 556;
  20296. t.o = 556;
  20297. t.p = 556;
  20298. t.q = 556;
  20299. t.r = 333;
  20300. t.s = 500;
  20301. t.t = 278;
  20302. t.u = 556;
  20303. t.v = 500;
  20304. t.w = 722;
  20305. t.x = 500;
  20306. t.y = 500;
  20307. t.z = 500;
  20308. t.braceleft = 334;
  20309. t.bar = 260;
  20310. t.braceright = 334;
  20311. t.asciitilde = 584;
  20312. t.exclamdown = 333;
  20313. t.cent = 556;
  20314. t.sterling = 556;
  20315. t.fraction = 167;
  20316. t.yen = 556;
  20317. t.florin = 556;
  20318. t.section = 556;
  20319. t.currency = 556;
  20320. t.quotesingle = 191;
  20321. t.quotedblleft = 333;
  20322. t.guillemotleft = 556;
  20323. t.guilsinglleft = 333;
  20324. t.guilsinglright = 333;
  20325. t.fi = 500;
  20326. t.fl = 500;
  20327. t.endash = 556;
  20328. t.dagger = 556;
  20329. t.daggerdbl = 556;
  20330. t.periodcentered = 278;
  20331. t.paragraph = 537;
  20332. t.bullet = 350;
  20333. t.quotesinglbase = 222;
  20334. t.quotedblbase = 333;
  20335. t.quotedblright = 333;
  20336. t.guillemotright = 556;
  20337. t.ellipsis = 1000;
  20338. t.perthousand = 1000;
  20339. t.questiondown = 611;
  20340. t.grave = 333;
  20341. t.acute = 333;
  20342. t.circumflex = 333;
  20343. t.tilde = 333;
  20344. t.macron = 333;
  20345. t.breve = 333;
  20346. t.dotaccent = 333;
  20347. t.dieresis = 333;
  20348. t.ring = 333;
  20349. t.cedilla = 333;
  20350. t.hungarumlaut = 333;
  20351. t.ogonek = 333;
  20352. t.caron = 333;
  20353. t.emdash = 1000;
  20354. t.AE = 1000;
  20355. t.ordfeminine = 370;
  20356. t.Lslash = 556;
  20357. t.Oslash = 778;
  20358. t.OE = 1000;
  20359. t.ordmasculine = 365;
  20360. t.ae = 889;
  20361. t.dotlessi = 278;
  20362. t.lslash = 222;
  20363. t.oslash = 611;
  20364. t.oe = 944;
  20365. t.germandbls = 611;
  20366. t.Idieresis = 278;
  20367. t.eacute = 556;
  20368. t.abreve = 556;
  20369. t.uhungarumlaut = 556;
  20370. t.ecaron = 556;
  20371. t.Ydieresis = 667;
  20372. t.divide = 584;
  20373. t.Yacute = 667;
  20374. t.Acircumflex = 667;
  20375. t.aacute = 556;
  20376. t.Ucircumflex = 722;
  20377. t.yacute = 500;
  20378. t.scommaaccent = 500;
  20379. t.ecircumflex = 556;
  20380. t.Uring = 722;
  20381. t.Udieresis = 722;
  20382. t.aogonek = 556;
  20383. t.Uacute = 722;
  20384. t.uogonek = 556;
  20385. t.Edieresis = 667;
  20386. t.Dcroat = 722;
  20387. t.commaaccent = 250;
  20388. t.copyright = 737;
  20389. t.Emacron = 667;
  20390. t.ccaron = 500;
  20391. t.aring = 556;
  20392. t.Ncommaaccent = 722;
  20393. t.lacute = 222;
  20394. t.agrave = 556;
  20395. t.Tcommaaccent = 611;
  20396. t.Cacute = 722;
  20397. t.atilde = 556;
  20398. t.Edotaccent = 667;
  20399. t.scaron = 500;
  20400. t.scedilla = 500;
  20401. t.iacute = 278;
  20402. t.lozenge = 471;
  20403. t.Rcaron = 722;
  20404. t.Gcommaaccent = 778;
  20405. t.ucircumflex = 556;
  20406. t.acircumflex = 556;
  20407. t.Amacron = 667;
  20408. t.rcaron = 333;
  20409. t.ccedilla = 500;
  20410. t.Zdotaccent = 611;
  20411. t.Thorn = 667;
  20412. t.Omacron = 778;
  20413. t.Racute = 722;
  20414. t.Sacute = 667;
  20415. t.dcaron = 643;
  20416. t.Umacron = 722;
  20417. t.uring = 556;
  20418. t.threesuperior = 333;
  20419. t.Ograve = 778;
  20420. t.Agrave = 667;
  20421. t.Abreve = 667;
  20422. t.multiply = 584;
  20423. t.uacute = 556;
  20424. t.Tcaron = 611;
  20425. t.partialdiff = 476;
  20426. t.ydieresis = 500;
  20427. t.Nacute = 722;
  20428. t.icircumflex = 278;
  20429. t.Ecircumflex = 667;
  20430. t.adieresis = 556;
  20431. t.edieresis = 556;
  20432. t.cacute = 500;
  20433. t.nacute = 556;
  20434. t.umacron = 556;
  20435. t.Ncaron = 722;
  20436. t.Iacute = 278;
  20437. t.plusminus = 584;
  20438. t.brokenbar = 260;
  20439. t.registered = 737;
  20440. t.Gbreve = 778;
  20441. t.Idotaccent = 278;
  20442. t.summation = 600;
  20443. t.Egrave = 667;
  20444. t.racute = 333;
  20445. t.omacron = 556;
  20446. t.Zacute = 611;
  20447. t.Zcaron = 611;
  20448. t.greaterequal = 549;
  20449. t.Eth = 722;
  20450. t.Ccedilla = 722;
  20451. t.lcommaaccent = 222;
  20452. t.tcaron = 317;
  20453. t.eogonek = 556;
  20454. t.Uogonek = 722;
  20455. t.Aacute = 667;
  20456. t.Adieresis = 667;
  20457. t.egrave = 556;
  20458. t.zacute = 500;
  20459. t.iogonek = 222;
  20460. t.Oacute = 778;
  20461. t.oacute = 556;
  20462. t.amacron = 556;
  20463. t.sacute = 500;
  20464. t.idieresis = 278;
  20465. t.Ocircumflex = 778;
  20466. t.Ugrave = 722;
  20467. t.Delta = 612;
  20468. t.thorn = 556;
  20469. t.twosuperior = 333;
  20470. t.Odieresis = 778;
  20471. t.mu = 556;
  20472. t.igrave = 278;
  20473. t.ohungarumlaut = 556;
  20474. t.Eogonek = 667;
  20475. t.dcroat = 556;
  20476. t.threequarters = 834;
  20477. t.Scedilla = 667;
  20478. t.lcaron = 299;
  20479. t.Kcommaaccent = 667;
  20480. t.Lacute = 556;
  20481. t.trademark = 1000;
  20482. t.edotaccent = 556;
  20483. t.Igrave = 278;
  20484. t.Imacron = 278;
  20485. t.Lcaron = 556;
  20486. t.onehalf = 834;
  20487. t.lessequal = 549;
  20488. t.ocircumflex = 556;
  20489. t.ntilde = 556;
  20490. t.Uhungarumlaut = 722;
  20491. t.Eacute = 667;
  20492. t.emacron = 556;
  20493. t.gbreve = 556;
  20494. t.onequarter = 834;
  20495. t.Scaron = 667;
  20496. t.Scommaaccent = 667;
  20497. t.Ohungarumlaut = 778;
  20498. t.degree = 400;
  20499. t.ograve = 556;
  20500. t.Ccaron = 722;
  20501. t.ugrave = 556;
  20502. t.radical = 453;
  20503. t.Dcaron = 722;
  20504. t.rcommaaccent = 333;
  20505. t.Ntilde = 722;
  20506. t.otilde = 556;
  20507. t.Rcommaaccent = 722;
  20508. t.Lcommaaccent = 556;
  20509. t.Atilde = 667;
  20510. t.Aogonek = 667;
  20511. t.Aring = 667;
  20512. t.Otilde = 778;
  20513. t.zdotaccent = 500;
  20514. t.Ecaron = 667;
  20515. t.Iogonek = 278;
  20516. t.kcommaaccent = 500;
  20517. t.minus = 584;
  20518. t.Icircumflex = 278;
  20519. t.ncaron = 556;
  20520. t.tcommaaccent = 278;
  20521. t.logicalnot = 584;
  20522. t.odieresis = 556;
  20523. t.udieresis = 556;
  20524. t.notequal = 549;
  20525. t.gcommaaccent = 556;
  20526. t.eth = 556;
  20527. t.zcaron = 500;
  20528. t.ncommaaccent = 556;
  20529. t.onesuperior = 333;
  20530. t.imacron = 278;
  20531. t.Euro = 556;
  20532. });
  20533. t.Symbol = getLookupTableFactory(function (t) {
  20534. t.space = 250;
  20535. t.exclam = 333;
  20536. t.universal = 713;
  20537. t.numbersign = 500;
  20538. t.existential = 549;
  20539. t.percent = 833;
  20540. t.ampersand = 778;
  20541. t.suchthat = 439;
  20542. t.parenleft = 333;
  20543. t.parenright = 333;
  20544. t.asteriskmath = 500;
  20545. t.plus = 549;
  20546. t.comma = 250;
  20547. t.minus = 549;
  20548. t.period = 250;
  20549. t.slash = 278;
  20550. t.zero = 500;
  20551. t.one = 500;
  20552. t.two = 500;
  20553. t.three = 500;
  20554. t.four = 500;
  20555. t.five = 500;
  20556. t.six = 500;
  20557. t.seven = 500;
  20558. t.eight = 500;
  20559. t.nine = 500;
  20560. t.colon = 278;
  20561. t.semicolon = 278;
  20562. t.less = 549;
  20563. t.equal = 549;
  20564. t.greater = 549;
  20565. t.question = 444;
  20566. t.congruent = 549;
  20567. t.Alpha = 722;
  20568. t.Beta = 667;
  20569. t.Chi = 722;
  20570. t.Delta = 612;
  20571. t.Epsilon = 611;
  20572. t.Phi = 763;
  20573. t.Gamma = 603;
  20574. t.Eta = 722;
  20575. t.Iota = 333;
  20576. t.theta1 = 631;
  20577. t.Kappa = 722;
  20578. t.Lambda = 686;
  20579. t.Mu = 889;
  20580. t.Nu = 722;
  20581. t.Omicron = 722;
  20582. t.Pi = 768;
  20583. t.Theta = 741;
  20584. t.Rho = 556;
  20585. t.Sigma = 592;
  20586. t.Tau = 611;
  20587. t.Upsilon = 690;
  20588. t.sigma1 = 439;
  20589. t.Omega = 768;
  20590. t.Xi = 645;
  20591. t.Psi = 795;
  20592. t.Zeta = 611;
  20593. t.bracketleft = 333;
  20594. t.therefore = 863;
  20595. t.bracketright = 333;
  20596. t.perpendicular = 658;
  20597. t.underscore = 500;
  20598. t.radicalex = 500;
  20599. t.alpha = 631;
  20600. t.beta = 549;
  20601. t.chi = 549;
  20602. t.delta = 494;
  20603. t.epsilon = 439;
  20604. t.phi = 521;
  20605. t.gamma = 411;
  20606. t.eta = 603;
  20607. t.iota = 329;
  20608. t.phi1 = 603;
  20609. t.kappa = 549;
  20610. t.lambda = 549;
  20611. t.mu = 576;
  20612. t.nu = 521;
  20613. t.omicron = 549;
  20614. t.pi = 549;
  20615. t.theta = 521;
  20616. t.rho = 549;
  20617. t.sigma = 603;
  20618. t.tau = 439;
  20619. t.upsilon = 576;
  20620. t.omega1 = 713;
  20621. t.omega = 686;
  20622. t.xi = 493;
  20623. t.psi = 686;
  20624. t.zeta = 494;
  20625. t.braceleft = 480;
  20626. t.bar = 200;
  20627. t.braceright = 480;
  20628. t.similar = 549;
  20629. t.Euro = 750;
  20630. t.Upsilon1 = 620;
  20631. t.minute = 247;
  20632. t.lessequal = 549;
  20633. t.fraction = 167;
  20634. t.infinity = 713;
  20635. t.florin = 500;
  20636. t.club = 753;
  20637. t.diamond = 753;
  20638. t.heart = 753;
  20639. t.spade = 753;
  20640. t.arrowboth = 1042;
  20641. t.arrowleft = 987;
  20642. t.arrowup = 603;
  20643. t.arrowright = 987;
  20644. t.arrowdown = 603;
  20645. t.degree = 400;
  20646. t.plusminus = 549;
  20647. t.second = 411;
  20648. t.greaterequal = 549;
  20649. t.multiply = 549;
  20650. t.proportional = 713;
  20651. t.partialdiff = 494;
  20652. t.bullet = 460;
  20653. t.divide = 549;
  20654. t.notequal = 549;
  20655. t.equivalence = 549;
  20656. t.approxequal = 549;
  20657. t.ellipsis = 1000;
  20658. t.arrowvertex = 603;
  20659. t.arrowhorizex = 1000;
  20660. t.carriagereturn = 658;
  20661. t.aleph = 823;
  20662. t.Ifraktur = 686;
  20663. t.Rfraktur = 795;
  20664. t.weierstrass = 987;
  20665. t.circlemultiply = 768;
  20666. t.circleplus = 768;
  20667. t.emptyset = 823;
  20668. t.intersection = 768;
  20669. t.union = 768;
  20670. t.propersuperset = 713;
  20671. t.reflexsuperset = 713;
  20672. t.notsubset = 713;
  20673. t.propersubset = 713;
  20674. t.reflexsubset = 713;
  20675. t.element = 713;
  20676. t.notelement = 713;
  20677. t.angle = 768;
  20678. t.gradient = 713;
  20679. t.registerserif = 790;
  20680. t.copyrightserif = 790;
  20681. t.trademarkserif = 890;
  20682. t.product = 823;
  20683. t.radical = 549;
  20684. t.dotmath = 250;
  20685. t.logicalnot = 713;
  20686. t.logicaland = 603;
  20687. t.logicalor = 603;
  20688. t.arrowdblboth = 1042;
  20689. t.arrowdblleft = 987;
  20690. t.arrowdblup = 603;
  20691. t.arrowdblright = 987;
  20692. t.arrowdbldown = 603;
  20693. t.lozenge = 494;
  20694. t.angleleft = 329;
  20695. t.registersans = 790;
  20696. t.copyrightsans = 790;
  20697. t.trademarksans = 786;
  20698. t.summation = 713;
  20699. t.parenlefttp = 384;
  20700. t.parenleftex = 384;
  20701. t.parenleftbt = 384;
  20702. t.bracketlefttp = 384;
  20703. t.bracketleftex = 384;
  20704. t.bracketleftbt = 384;
  20705. t.bracelefttp = 494;
  20706. t.braceleftmid = 494;
  20707. t.braceleftbt = 494;
  20708. t.braceex = 494;
  20709. t.angleright = 329;
  20710. t.integral = 274;
  20711. t.integraltp = 686;
  20712. t.integralex = 686;
  20713. t.integralbt = 686;
  20714. t.parenrighttp = 384;
  20715. t.parenrightex = 384;
  20716. t.parenrightbt = 384;
  20717. t.bracketrighttp = 384;
  20718. t.bracketrightex = 384;
  20719. t.bracketrightbt = 384;
  20720. t.bracerighttp = 494;
  20721. t.bracerightmid = 494;
  20722. t.bracerightbt = 494;
  20723. t.apple = 790;
  20724. });
  20725. t["Times-Roman"] = getLookupTableFactory(function (t) {
  20726. t.space = 250;
  20727. t.exclam = 333;
  20728. t.quotedbl = 408;
  20729. t.numbersign = 500;
  20730. t.dollar = 500;
  20731. t.percent = 833;
  20732. t.ampersand = 778;
  20733. t.quoteright = 333;
  20734. t.parenleft = 333;
  20735. t.parenright = 333;
  20736. t.asterisk = 500;
  20737. t.plus = 564;
  20738. t.comma = 250;
  20739. t.hyphen = 333;
  20740. t.period = 250;
  20741. t.slash = 278;
  20742. t.zero = 500;
  20743. t.one = 500;
  20744. t.two = 500;
  20745. t.three = 500;
  20746. t.four = 500;
  20747. t.five = 500;
  20748. t.six = 500;
  20749. t.seven = 500;
  20750. t.eight = 500;
  20751. t.nine = 500;
  20752. t.colon = 278;
  20753. t.semicolon = 278;
  20754. t.less = 564;
  20755. t.equal = 564;
  20756. t.greater = 564;
  20757. t.question = 444;
  20758. t.at = 921;
  20759. t.A = 722;
  20760. t.B = 667;
  20761. t.C = 667;
  20762. t.D = 722;
  20763. t.E = 611;
  20764. t.F = 556;
  20765. t.G = 722;
  20766. t.H = 722;
  20767. t.I = 333;
  20768. t.J = 389;
  20769. t.K = 722;
  20770. t.L = 611;
  20771. t.M = 889;
  20772. t.N = 722;
  20773. t.O = 722;
  20774. t.P = 556;
  20775. t.Q = 722;
  20776. t.R = 667;
  20777. t.S = 556;
  20778. t.T = 611;
  20779. t.U = 722;
  20780. t.V = 722;
  20781. t.W = 944;
  20782. t.X = 722;
  20783. t.Y = 722;
  20784. t.Z = 611;
  20785. t.bracketleft = 333;
  20786. t.backslash = 278;
  20787. t.bracketright = 333;
  20788. t.asciicircum = 469;
  20789. t.underscore = 500;
  20790. t.quoteleft = 333;
  20791. t.a = 444;
  20792. t.b = 500;
  20793. t.c = 444;
  20794. t.d = 500;
  20795. t.e = 444;
  20796. t.f = 333;
  20797. t.g = 500;
  20798. t.h = 500;
  20799. t.i = 278;
  20800. t.j = 278;
  20801. t.k = 500;
  20802. t.l = 278;
  20803. t.m = 778;
  20804. t.n = 500;
  20805. t.o = 500;
  20806. t.p = 500;
  20807. t.q = 500;
  20808. t.r = 333;
  20809. t.s = 389;
  20810. t.t = 278;
  20811. t.u = 500;
  20812. t.v = 500;
  20813. t.w = 722;
  20814. t.x = 500;
  20815. t.y = 500;
  20816. t.z = 444;
  20817. t.braceleft = 480;
  20818. t.bar = 200;
  20819. t.braceright = 480;
  20820. t.asciitilde = 541;
  20821. t.exclamdown = 333;
  20822. t.cent = 500;
  20823. t.sterling = 500;
  20824. t.fraction = 167;
  20825. t.yen = 500;
  20826. t.florin = 500;
  20827. t.section = 500;
  20828. t.currency = 500;
  20829. t.quotesingle = 180;
  20830. t.quotedblleft = 444;
  20831. t.guillemotleft = 500;
  20832. t.guilsinglleft = 333;
  20833. t.guilsinglright = 333;
  20834. t.fi = 556;
  20835. t.fl = 556;
  20836. t.endash = 500;
  20837. t.dagger = 500;
  20838. t.daggerdbl = 500;
  20839. t.periodcentered = 250;
  20840. t.paragraph = 453;
  20841. t.bullet = 350;
  20842. t.quotesinglbase = 333;
  20843. t.quotedblbase = 444;
  20844. t.quotedblright = 444;
  20845. t.guillemotright = 500;
  20846. t.ellipsis = 1000;
  20847. t.perthousand = 1000;
  20848. t.questiondown = 444;
  20849. t.grave = 333;
  20850. t.acute = 333;
  20851. t.circumflex = 333;
  20852. t.tilde = 333;
  20853. t.macron = 333;
  20854. t.breve = 333;
  20855. t.dotaccent = 333;
  20856. t.dieresis = 333;
  20857. t.ring = 333;
  20858. t.cedilla = 333;
  20859. t.hungarumlaut = 333;
  20860. t.ogonek = 333;
  20861. t.caron = 333;
  20862. t.emdash = 1000;
  20863. t.AE = 889;
  20864. t.ordfeminine = 276;
  20865. t.Lslash = 611;
  20866. t.Oslash = 722;
  20867. t.OE = 889;
  20868. t.ordmasculine = 310;
  20869. t.ae = 667;
  20870. t.dotlessi = 278;
  20871. t.lslash = 278;
  20872. t.oslash = 500;
  20873. t.oe = 722;
  20874. t.germandbls = 500;
  20875. t.Idieresis = 333;
  20876. t.eacute = 444;
  20877. t.abreve = 444;
  20878. t.uhungarumlaut = 500;
  20879. t.ecaron = 444;
  20880. t.Ydieresis = 722;
  20881. t.divide = 564;
  20882. t.Yacute = 722;
  20883. t.Acircumflex = 722;
  20884. t.aacute = 444;
  20885. t.Ucircumflex = 722;
  20886. t.yacute = 500;
  20887. t.scommaaccent = 389;
  20888. t.ecircumflex = 444;
  20889. t.Uring = 722;
  20890. t.Udieresis = 722;
  20891. t.aogonek = 444;
  20892. t.Uacute = 722;
  20893. t.uogonek = 500;
  20894. t.Edieresis = 611;
  20895. t.Dcroat = 722;
  20896. t.commaaccent = 250;
  20897. t.copyright = 760;
  20898. t.Emacron = 611;
  20899. t.ccaron = 444;
  20900. t.aring = 444;
  20901. t.Ncommaaccent = 722;
  20902. t.lacute = 278;
  20903. t.agrave = 444;
  20904. t.Tcommaaccent = 611;
  20905. t.Cacute = 667;
  20906. t.atilde = 444;
  20907. t.Edotaccent = 611;
  20908. t.scaron = 389;
  20909. t.scedilla = 389;
  20910. t.iacute = 278;
  20911. t.lozenge = 471;
  20912. t.Rcaron = 667;
  20913. t.Gcommaaccent = 722;
  20914. t.ucircumflex = 500;
  20915. t.acircumflex = 444;
  20916. t.Amacron = 722;
  20917. t.rcaron = 333;
  20918. t.ccedilla = 444;
  20919. t.Zdotaccent = 611;
  20920. t.Thorn = 556;
  20921. t.Omacron = 722;
  20922. t.Racute = 667;
  20923. t.Sacute = 556;
  20924. t.dcaron = 588;
  20925. t.Umacron = 722;
  20926. t.uring = 500;
  20927. t.threesuperior = 300;
  20928. t.Ograve = 722;
  20929. t.Agrave = 722;
  20930. t.Abreve = 722;
  20931. t.multiply = 564;
  20932. t.uacute = 500;
  20933. t.Tcaron = 611;
  20934. t.partialdiff = 476;
  20935. t.ydieresis = 500;
  20936. t.Nacute = 722;
  20937. t.icircumflex = 278;
  20938. t.Ecircumflex = 611;
  20939. t.adieresis = 444;
  20940. t.edieresis = 444;
  20941. t.cacute = 444;
  20942. t.nacute = 500;
  20943. t.umacron = 500;
  20944. t.Ncaron = 722;
  20945. t.Iacute = 333;
  20946. t.plusminus = 564;
  20947. t.brokenbar = 200;
  20948. t.registered = 760;
  20949. t.Gbreve = 722;
  20950. t.Idotaccent = 333;
  20951. t.summation = 600;
  20952. t.Egrave = 611;
  20953. t.racute = 333;
  20954. t.omacron = 500;
  20955. t.Zacute = 611;
  20956. t.Zcaron = 611;
  20957. t.greaterequal = 549;
  20958. t.Eth = 722;
  20959. t.Ccedilla = 667;
  20960. t.lcommaaccent = 278;
  20961. t.tcaron = 326;
  20962. t.eogonek = 444;
  20963. t.Uogonek = 722;
  20964. t.Aacute = 722;
  20965. t.Adieresis = 722;
  20966. t.egrave = 444;
  20967. t.zacute = 444;
  20968. t.iogonek = 278;
  20969. t.Oacute = 722;
  20970. t.oacute = 500;
  20971. t.amacron = 444;
  20972. t.sacute = 389;
  20973. t.idieresis = 278;
  20974. t.Ocircumflex = 722;
  20975. t.Ugrave = 722;
  20976. t.Delta = 612;
  20977. t.thorn = 500;
  20978. t.twosuperior = 300;
  20979. t.Odieresis = 722;
  20980. t.mu = 500;
  20981. t.igrave = 278;
  20982. t.ohungarumlaut = 500;
  20983. t.Eogonek = 611;
  20984. t.dcroat = 500;
  20985. t.threequarters = 750;
  20986. t.Scedilla = 556;
  20987. t.lcaron = 344;
  20988. t.Kcommaaccent = 722;
  20989. t.Lacute = 611;
  20990. t.trademark = 980;
  20991. t.edotaccent = 444;
  20992. t.Igrave = 333;
  20993. t.Imacron = 333;
  20994. t.Lcaron = 611;
  20995. t.onehalf = 750;
  20996. t.lessequal = 549;
  20997. t.ocircumflex = 500;
  20998. t.ntilde = 500;
  20999. t.Uhungarumlaut = 722;
  21000. t.Eacute = 611;
  21001. t.emacron = 444;
  21002. t.gbreve = 500;
  21003. t.onequarter = 750;
  21004. t.Scaron = 556;
  21005. t.Scommaaccent = 556;
  21006. t.Ohungarumlaut = 722;
  21007. t.degree = 400;
  21008. t.ograve = 500;
  21009. t.Ccaron = 667;
  21010. t.ugrave = 500;
  21011. t.radical = 453;
  21012. t.Dcaron = 722;
  21013. t.rcommaaccent = 333;
  21014. t.Ntilde = 722;
  21015. t.otilde = 500;
  21016. t.Rcommaaccent = 667;
  21017. t.Lcommaaccent = 611;
  21018. t.Atilde = 722;
  21019. t.Aogonek = 722;
  21020. t.Aring = 722;
  21021. t.Otilde = 722;
  21022. t.zdotaccent = 444;
  21023. t.Ecaron = 611;
  21024. t.Iogonek = 333;
  21025. t.kcommaaccent = 500;
  21026. t.minus = 564;
  21027. t.Icircumflex = 333;
  21028. t.ncaron = 500;
  21029. t.tcommaaccent = 278;
  21030. t.logicalnot = 564;
  21031. t.odieresis = 500;
  21032. t.udieresis = 500;
  21033. t.notequal = 549;
  21034. t.gcommaaccent = 500;
  21035. t.eth = 500;
  21036. t.zcaron = 444;
  21037. t.ncommaaccent = 500;
  21038. t.onesuperior = 300;
  21039. t.imacron = 278;
  21040. t.Euro = 500;
  21041. });
  21042. t["Times-Bold"] = getLookupTableFactory(function (t) {
  21043. t.space = 250;
  21044. t.exclam = 333;
  21045. t.quotedbl = 555;
  21046. t.numbersign = 500;
  21047. t.dollar = 500;
  21048. t.percent = 1000;
  21049. t.ampersand = 833;
  21050. t.quoteright = 333;
  21051. t.parenleft = 333;
  21052. t.parenright = 333;
  21053. t.asterisk = 500;
  21054. t.plus = 570;
  21055. t.comma = 250;
  21056. t.hyphen = 333;
  21057. t.period = 250;
  21058. t.slash = 278;
  21059. t.zero = 500;
  21060. t.one = 500;
  21061. t.two = 500;
  21062. t.three = 500;
  21063. t.four = 500;
  21064. t.five = 500;
  21065. t.six = 500;
  21066. t.seven = 500;
  21067. t.eight = 500;
  21068. t.nine = 500;
  21069. t.colon = 333;
  21070. t.semicolon = 333;
  21071. t.less = 570;
  21072. t.equal = 570;
  21073. t.greater = 570;
  21074. t.question = 500;
  21075. t.at = 930;
  21076. t.A = 722;
  21077. t.B = 667;
  21078. t.C = 722;
  21079. t.D = 722;
  21080. t.E = 667;
  21081. t.F = 611;
  21082. t.G = 778;
  21083. t.H = 778;
  21084. t.I = 389;
  21085. t.J = 500;
  21086. t.K = 778;
  21087. t.L = 667;
  21088. t.M = 944;
  21089. t.N = 722;
  21090. t.O = 778;
  21091. t.P = 611;
  21092. t.Q = 778;
  21093. t.R = 722;
  21094. t.S = 556;
  21095. t.T = 667;
  21096. t.U = 722;
  21097. t.V = 722;
  21098. t.W = 1000;
  21099. t.X = 722;
  21100. t.Y = 722;
  21101. t.Z = 667;
  21102. t.bracketleft = 333;
  21103. t.backslash = 278;
  21104. t.bracketright = 333;
  21105. t.asciicircum = 581;
  21106. t.underscore = 500;
  21107. t.quoteleft = 333;
  21108. t.a = 500;
  21109. t.b = 556;
  21110. t.c = 444;
  21111. t.d = 556;
  21112. t.e = 444;
  21113. t.f = 333;
  21114. t.g = 500;
  21115. t.h = 556;
  21116. t.i = 278;
  21117. t.j = 333;
  21118. t.k = 556;
  21119. t.l = 278;
  21120. t.m = 833;
  21121. t.n = 556;
  21122. t.o = 500;
  21123. t.p = 556;
  21124. t.q = 556;
  21125. t.r = 444;
  21126. t.s = 389;
  21127. t.t = 333;
  21128. t.u = 556;
  21129. t.v = 500;
  21130. t.w = 722;
  21131. t.x = 500;
  21132. t.y = 500;
  21133. t.z = 444;
  21134. t.braceleft = 394;
  21135. t.bar = 220;
  21136. t.braceright = 394;
  21137. t.asciitilde = 520;
  21138. t.exclamdown = 333;
  21139. t.cent = 500;
  21140. t.sterling = 500;
  21141. t.fraction = 167;
  21142. t.yen = 500;
  21143. t.florin = 500;
  21144. t.section = 500;
  21145. t.currency = 500;
  21146. t.quotesingle = 278;
  21147. t.quotedblleft = 500;
  21148. t.guillemotleft = 500;
  21149. t.guilsinglleft = 333;
  21150. t.guilsinglright = 333;
  21151. t.fi = 556;
  21152. t.fl = 556;
  21153. t.endash = 500;
  21154. t.dagger = 500;
  21155. t.daggerdbl = 500;
  21156. t.periodcentered = 250;
  21157. t.paragraph = 540;
  21158. t.bullet = 350;
  21159. t.quotesinglbase = 333;
  21160. t.quotedblbase = 500;
  21161. t.quotedblright = 500;
  21162. t.guillemotright = 500;
  21163. t.ellipsis = 1000;
  21164. t.perthousand = 1000;
  21165. t.questiondown = 500;
  21166. t.grave = 333;
  21167. t.acute = 333;
  21168. t.circumflex = 333;
  21169. t.tilde = 333;
  21170. t.macron = 333;
  21171. t.breve = 333;
  21172. t.dotaccent = 333;
  21173. t.dieresis = 333;
  21174. t.ring = 333;
  21175. t.cedilla = 333;
  21176. t.hungarumlaut = 333;
  21177. t.ogonek = 333;
  21178. t.caron = 333;
  21179. t.emdash = 1000;
  21180. t.AE = 1000;
  21181. t.ordfeminine = 300;
  21182. t.Lslash = 667;
  21183. t.Oslash = 778;
  21184. t.OE = 1000;
  21185. t.ordmasculine = 330;
  21186. t.ae = 722;
  21187. t.dotlessi = 278;
  21188. t.lslash = 278;
  21189. t.oslash = 500;
  21190. t.oe = 722;
  21191. t.germandbls = 556;
  21192. t.Idieresis = 389;
  21193. t.eacute = 444;
  21194. t.abreve = 500;
  21195. t.uhungarumlaut = 556;
  21196. t.ecaron = 444;
  21197. t.Ydieresis = 722;
  21198. t.divide = 570;
  21199. t.Yacute = 722;
  21200. t.Acircumflex = 722;
  21201. t.aacute = 500;
  21202. t.Ucircumflex = 722;
  21203. t.yacute = 500;
  21204. t.scommaaccent = 389;
  21205. t.ecircumflex = 444;
  21206. t.Uring = 722;
  21207. t.Udieresis = 722;
  21208. t.aogonek = 500;
  21209. t.Uacute = 722;
  21210. t.uogonek = 556;
  21211. t.Edieresis = 667;
  21212. t.Dcroat = 722;
  21213. t.commaaccent = 250;
  21214. t.copyright = 747;
  21215. t.Emacron = 667;
  21216. t.ccaron = 444;
  21217. t.aring = 500;
  21218. t.Ncommaaccent = 722;
  21219. t.lacute = 278;
  21220. t.agrave = 500;
  21221. t.Tcommaaccent = 667;
  21222. t.Cacute = 722;
  21223. t.atilde = 500;
  21224. t.Edotaccent = 667;
  21225. t.scaron = 389;
  21226. t.scedilla = 389;
  21227. t.iacute = 278;
  21228. t.lozenge = 494;
  21229. t.Rcaron = 722;
  21230. t.Gcommaaccent = 778;
  21231. t.ucircumflex = 556;
  21232. t.acircumflex = 500;
  21233. t.Amacron = 722;
  21234. t.rcaron = 444;
  21235. t.ccedilla = 444;
  21236. t.Zdotaccent = 667;
  21237. t.Thorn = 611;
  21238. t.Omacron = 778;
  21239. t.Racute = 722;
  21240. t.Sacute = 556;
  21241. t.dcaron = 672;
  21242. t.Umacron = 722;
  21243. t.uring = 556;
  21244. t.threesuperior = 300;
  21245. t.Ograve = 778;
  21246. t.Agrave = 722;
  21247. t.Abreve = 722;
  21248. t.multiply = 570;
  21249. t.uacute = 556;
  21250. t.Tcaron = 667;
  21251. t.partialdiff = 494;
  21252. t.ydieresis = 500;
  21253. t.Nacute = 722;
  21254. t.icircumflex = 278;
  21255. t.Ecircumflex = 667;
  21256. t.adieresis = 500;
  21257. t.edieresis = 444;
  21258. t.cacute = 444;
  21259. t.nacute = 556;
  21260. t.umacron = 556;
  21261. t.Ncaron = 722;
  21262. t.Iacute = 389;
  21263. t.plusminus = 570;
  21264. t.brokenbar = 220;
  21265. t.registered = 747;
  21266. t.Gbreve = 778;
  21267. t.Idotaccent = 389;
  21268. t.summation = 600;
  21269. t.Egrave = 667;
  21270. t.racute = 444;
  21271. t.omacron = 500;
  21272. t.Zacute = 667;
  21273. t.Zcaron = 667;
  21274. t.greaterequal = 549;
  21275. t.Eth = 722;
  21276. t.Ccedilla = 722;
  21277. t.lcommaaccent = 278;
  21278. t.tcaron = 416;
  21279. t.eogonek = 444;
  21280. t.Uogonek = 722;
  21281. t.Aacute = 722;
  21282. t.Adieresis = 722;
  21283. t.egrave = 444;
  21284. t.zacute = 444;
  21285. t.iogonek = 278;
  21286. t.Oacute = 778;
  21287. t.oacute = 500;
  21288. t.amacron = 500;
  21289. t.sacute = 389;
  21290. t.idieresis = 278;
  21291. t.Ocircumflex = 778;
  21292. t.Ugrave = 722;
  21293. t.Delta = 612;
  21294. t.thorn = 556;
  21295. t.twosuperior = 300;
  21296. t.Odieresis = 778;
  21297. t.mu = 556;
  21298. t.igrave = 278;
  21299. t.ohungarumlaut = 500;
  21300. t.Eogonek = 667;
  21301. t.dcroat = 556;
  21302. t.threequarters = 750;
  21303. t.Scedilla = 556;
  21304. t.lcaron = 394;
  21305. t.Kcommaaccent = 778;
  21306. t.Lacute = 667;
  21307. t.trademark = 1000;
  21308. t.edotaccent = 444;
  21309. t.Igrave = 389;
  21310. t.Imacron = 389;
  21311. t.Lcaron = 667;
  21312. t.onehalf = 750;
  21313. t.lessequal = 549;
  21314. t.ocircumflex = 500;
  21315. t.ntilde = 556;
  21316. t.Uhungarumlaut = 722;
  21317. t.Eacute = 667;
  21318. t.emacron = 444;
  21319. t.gbreve = 500;
  21320. t.onequarter = 750;
  21321. t.Scaron = 556;
  21322. t.Scommaaccent = 556;
  21323. t.Ohungarumlaut = 778;
  21324. t.degree = 400;
  21325. t.ograve = 500;
  21326. t.Ccaron = 722;
  21327. t.ugrave = 556;
  21328. t.radical = 549;
  21329. t.Dcaron = 722;
  21330. t.rcommaaccent = 444;
  21331. t.Ntilde = 722;
  21332. t.otilde = 500;
  21333. t.Rcommaaccent = 722;
  21334. t.Lcommaaccent = 667;
  21335. t.Atilde = 722;
  21336. t.Aogonek = 722;
  21337. t.Aring = 722;
  21338. t.Otilde = 778;
  21339. t.zdotaccent = 444;
  21340. t.Ecaron = 667;
  21341. t.Iogonek = 389;
  21342. t.kcommaaccent = 556;
  21343. t.minus = 570;
  21344. t.Icircumflex = 389;
  21345. t.ncaron = 556;
  21346. t.tcommaaccent = 333;
  21347. t.logicalnot = 570;
  21348. t.odieresis = 500;
  21349. t.udieresis = 556;
  21350. t.notequal = 549;
  21351. t.gcommaaccent = 500;
  21352. t.eth = 500;
  21353. t.zcaron = 444;
  21354. t.ncommaaccent = 556;
  21355. t.onesuperior = 300;
  21356. t.imacron = 278;
  21357. t.Euro = 500;
  21358. });
  21359. t["Times-BoldItalic"] = getLookupTableFactory(function (t) {
  21360. t.space = 250;
  21361. t.exclam = 389;
  21362. t.quotedbl = 555;
  21363. t.numbersign = 500;
  21364. t.dollar = 500;
  21365. t.percent = 833;
  21366. t.ampersand = 778;
  21367. t.quoteright = 333;
  21368. t.parenleft = 333;
  21369. t.parenright = 333;
  21370. t.asterisk = 500;
  21371. t.plus = 570;
  21372. t.comma = 250;
  21373. t.hyphen = 333;
  21374. t.period = 250;
  21375. t.slash = 278;
  21376. t.zero = 500;
  21377. t.one = 500;
  21378. t.two = 500;
  21379. t.three = 500;
  21380. t.four = 500;
  21381. t.five = 500;
  21382. t.six = 500;
  21383. t.seven = 500;
  21384. t.eight = 500;
  21385. t.nine = 500;
  21386. t.colon = 333;
  21387. t.semicolon = 333;
  21388. t.less = 570;
  21389. t.equal = 570;
  21390. t.greater = 570;
  21391. t.question = 500;
  21392. t.at = 832;
  21393. t.A = 667;
  21394. t.B = 667;
  21395. t.C = 667;
  21396. t.D = 722;
  21397. t.E = 667;
  21398. t.F = 667;
  21399. t.G = 722;
  21400. t.H = 778;
  21401. t.I = 389;
  21402. t.J = 500;
  21403. t.K = 667;
  21404. t.L = 611;
  21405. t.M = 889;
  21406. t.N = 722;
  21407. t.O = 722;
  21408. t.P = 611;
  21409. t.Q = 722;
  21410. t.R = 667;
  21411. t.S = 556;
  21412. t.T = 611;
  21413. t.U = 722;
  21414. t.V = 667;
  21415. t.W = 889;
  21416. t.X = 667;
  21417. t.Y = 611;
  21418. t.Z = 611;
  21419. t.bracketleft = 333;
  21420. t.backslash = 278;
  21421. t.bracketright = 333;
  21422. t.asciicircum = 570;
  21423. t.underscore = 500;
  21424. t.quoteleft = 333;
  21425. t.a = 500;
  21426. t.b = 500;
  21427. t.c = 444;
  21428. t.d = 500;
  21429. t.e = 444;
  21430. t.f = 333;
  21431. t.g = 500;
  21432. t.h = 556;
  21433. t.i = 278;
  21434. t.j = 278;
  21435. t.k = 500;
  21436. t.l = 278;
  21437. t.m = 778;
  21438. t.n = 556;
  21439. t.o = 500;
  21440. t.p = 500;
  21441. t.q = 500;
  21442. t.r = 389;
  21443. t.s = 389;
  21444. t.t = 278;
  21445. t.u = 556;
  21446. t.v = 444;
  21447. t.w = 667;
  21448. t.x = 500;
  21449. t.y = 444;
  21450. t.z = 389;
  21451. t.braceleft = 348;
  21452. t.bar = 220;
  21453. t.braceright = 348;
  21454. t.asciitilde = 570;
  21455. t.exclamdown = 389;
  21456. t.cent = 500;
  21457. t.sterling = 500;
  21458. t.fraction = 167;
  21459. t.yen = 500;
  21460. t.florin = 500;
  21461. t.section = 500;
  21462. t.currency = 500;
  21463. t.quotesingle = 278;
  21464. t.quotedblleft = 500;
  21465. t.guillemotleft = 500;
  21466. t.guilsinglleft = 333;
  21467. t.guilsinglright = 333;
  21468. t.fi = 556;
  21469. t.fl = 556;
  21470. t.endash = 500;
  21471. t.dagger = 500;
  21472. t.daggerdbl = 500;
  21473. t.periodcentered = 250;
  21474. t.paragraph = 500;
  21475. t.bullet = 350;
  21476. t.quotesinglbase = 333;
  21477. t.quotedblbase = 500;
  21478. t.quotedblright = 500;
  21479. t.guillemotright = 500;
  21480. t.ellipsis = 1000;
  21481. t.perthousand = 1000;
  21482. t.questiondown = 500;
  21483. t.grave = 333;
  21484. t.acute = 333;
  21485. t.circumflex = 333;
  21486. t.tilde = 333;
  21487. t.macron = 333;
  21488. t.breve = 333;
  21489. t.dotaccent = 333;
  21490. t.dieresis = 333;
  21491. t.ring = 333;
  21492. t.cedilla = 333;
  21493. t.hungarumlaut = 333;
  21494. t.ogonek = 333;
  21495. t.caron = 333;
  21496. t.emdash = 1000;
  21497. t.AE = 944;
  21498. t.ordfeminine = 266;
  21499. t.Lslash = 611;
  21500. t.Oslash = 722;
  21501. t.OE = 944;
  21502. t.ordmasculine = 300;
  21503. t.ae = 722;
  21504. t.dotlessi = 278;
  21505. t.lslash = 278;
  21506. t.oslash = 500;
  21507. t.oe = 722;
  21508. t.germandbls = 500;
  21509. t.Idieresis = 389;
  21510. t.eacute = 444;
  21511. t.abreve = 500;
  21512. t.uhungarumlaut = 556;
  21513. t.ecaron = 444;
  21514. t.Ydieresis = 611;
  21515. t.divide = 570;
  21516. t.Yacute = 611;
  21517. t.Acircumflex = 667;
  21518. t.aacute = 500;
  21519. t.Ucircumflex = 722;
  21520. t.yacute = 444;
  21521. t.scommaaccent = 389;
  21522. t.ecircumflex = 444;
  21523. t.Uring = 722;
  21524. t.Udieresis = 722;
  21525. t.aogonek = 500;
  21526. t.Uacute = 722;
  21527. t.uogonek = 556;
  21528. t.Edieresis = 667;
  21529. t.Dcroat = 722;
  21530. t.commaaccent = 250;
  21531. t.copyright = 747;
  21532. t.Emacron = 667;
  21533. t.ccaron = 444;
  21534. t.aring = 500;
  21535. t.Ncommaaccent = 722;
  21536. t.lacute = 278;
  21537. t.agrave = 500;
  21538. t.Tcommaaccent = 611;
  21539. t.Cacute = 667;
  21540. t.atilde = 500;
  21541. t.Edotaccent = 667;
  21542. t.scaron = 389;
  21543. t.scedilla = 389;
  21544. t.iacute = 278;
  21545. t.lozenge = 494;
  21546. t.Rcaron = 667;
  21547. t.Gcommaaccent = 722;
  21548. t.ucircumflex = 556;
  21549. t.acircumflex = 500;
  21550. t.Amacron = 667;
  21551. t.rcaron = 389;
  21552. t.ccedilla = 444;
  21553. t.Zdotaccent = 611;
  21554. t.Thorn = 611;
  21555. t.Omacron = 722;
  21556. t.Racute = 667;
  21557. t.Sacute = 556;
  21558. t.dcaron = 608;
  21559. t.Umacron = 722;
  21560. t.uring = 556;
  21561. t.threesuperior = 300;
  21562. t.Ograve = 722;
  21563. t.Agrave = 667;
  21564. t.Abreve = 667;
  21565. t.multiply = 570;
  21566. t.uacute = 556;
  21567. t.Tcaron = 611;
  21568. t.partialdiff = 494;
  21569. t.ydieresis = 444;
  21570. t.Nacute = 722;
  21571. t.icircumflex = 278;
  21572. t.Ecircumflex = 667;
  21573. t.adieresis = 500;
  21574. t.edieresis = 444;
  21575. t.cacute = 444;
  21576. t.nacute = 556;
  21577. t.umacron = 556;
  21578. t.Ncaron = 722;
  21579. t.Iacute = 389;
  21580. t.plusminus = 570;
  21581. t.brokenbar = 220;
  21582. t.registered = 747;
  21583. t.Gbreve = 722;
  21584. t.Idotaccent = 389;
  21585. t.summation = 600;
  21586. t.Egrave = 667;
  21587. t.racute = 389;
  21588. t.omacron = 500;
  21589. t.Zacute = 611;
  21590. t.Zcaron = 611;
  21591. t.greaterequal = 549;
  21592. t.Eth = 722;
  21593. t.Ccedilla = 667;
  21594. t.lcommaaccent = 278;
  21595. t.tcaron = 366;
  21596. t.eogonek = 444;
  21597. t.Uogonek = 722;
  21598. t.Aacute = 667;
  21599. t.Adieresis = 667;
  21600. t.egrave = 444;
  21601. t.zacute = 389;
  21602. t.iogonek = 278;
  21603. t.Oacute = 722;
  21604. t.oacute = 500;
  21605. t.amacron = 500;
  21606. t.sacute = 389;
  21607. t.idieresis = 278;
  21608. t.Ocircumflex = 722;
  21609. t.Ugrave = 722;
  21610. t.Delta = 612;
  21611. t.thorn = 500;
  21612. t.twosuperior = 300;
  21613. t.Odieresis = 722;
  21614. t.mu = 576;
  21615. t.igrave = 278;
  21616. t.ohungarumlaut = 500;
  21617. t.Eogonek = 667;
  21618. t.dcroat = 500;
  21619. t.threequarters = 750;
  21620. t.Scedilla = 556;
  21621. t.lcaron = 382;
  21622. t.Kcommaaccent = 667;
  21623. t.Lacute = 611;
  21624. t.trademark = 1000;
  21625. t.edotaccent = 444;
  21626. t.Igrave = 389;
  21627. t.Imacron = 389;
  21628. t.Lcaron = 611;
  21629. t.onehalf = 750;
  21630. t.lessequal = 549;
  21631. t.ocircumflex = 500;
  21632. t.ntilde = 556;
  21633. t.Uhungarumlaut = 722;
  21634. t.Eacute = 667;
  21635. t.emacron = 444;
  21636. t.gbreve = 500;
  21637. t.onequarter = 750;
  21638. t.Scaron = 556;
  21639. t.Scommaaccent = 556;
  21640. t.Ohungarumlaut = 722;
  21641. t.degree = 400;
  21642. t.ograve = 500;
  21643. t.Ccaron = 667;
  21644. t.ugrave = 556;
  21645. t.radical = 549;
  21646. t.Dcaron = 722;
  21647. t.rcommaaccent = 389;
  21648. t.Ntilde = 722;
  21649. t.otilde = 500;
  21650. t.Rcommaaccent = 667;
  21651. t.Lcommaaccent = 611;
  21652. t.Atilde = 667;
  21653. t.Aogonek = 667;
  21654. t.Aring = 667;
  21655. t.Otilde = 722;
  21656. t.zdotaccent = 389;
  21657. t.Ecaron = 667;
  21658. t.Iogonek = 389;
  21659. t.kcommaaccent = 500;
  21660. t.minus = 606;
  21661. t.Icircumflex = 389;
  21662. t.ncaron = 556;
  21663. t.tcommaaccent = 278;
  21664. t.logicalnot = 606;
  21665. t.odieresis = 500;
  21666. t.udieresis = 556;
  21667. t.notequal = 549;
  21668. t.gcommaaccent = 500;
  21669. t.eth = 500;
  21670. t.zcaron = 389;
  21671. t.ncommaaccent = 556;
  21672. t.onesuperior = 300;
  21673. t.imacron = 278;
  21674. t.Euro = 500;
  21675. });
  21676. t["Times-Italic"] = getLookupTableFactory(function (t) {
  21677. t.space = 250;
  21678. t.exclam = 333;
  21679. t.quotedbl = 420;
  21680. t.numbersign = 500;
  21681. t.dollar = 500;
  21682. t.percent = 833;
  21683. t.ampersand = 778;
  21684. t.quoteright = 333;
  21685. t.parenleft = 333;
  21686. t.parenright = 333;
  21687. t.asterisk = 500;
  21688. t.plus = 675;
  21689. t.comma = 250;
  21690. t.hyphen = 333;
  21691. t.period = 250;
  21692. t.slash = 278;
  21693. t.zero = 500;
  21694. t.one = 500;
  21695. t.two = 500;
  21696. t.three = 500;
  21697. t.four = 500;
  21698. t.five = 500;
  21699. t.six = 500;
  21700. t.seven = 500;
  21701. t.eight = 500;
  21702. t.nine = 500;
  21703. t.colon = 333;
  21704. t.semicolon = 333;
  21705. t.less = 675;
  21706. t.equal = 675;
  21707. t.greater = 675;
  21708. t.question = 500;
  21709. t.at = 920;
  21710. t.A = 611;
  21711. t.B = 611;
  21712. t.C = 667;
  21713. t.D = 722;
  21714. t.E = 611;
  21715. t.F = 611;
  21716. t.G = 722;
  21717. t.H = 722;
  21718. t.I = 333;
  21719. t.J = 444;
  21720. t.K = 667;
  21721. t.L = 556;
  21722. t.M = 833;
  21723. t.N = 667;
  21724. t.O = 722;
  21725. t.P = 611;
  21726. t.Q = 722;
  21727. t.R = 611;
  21728. t.S = 500;
  21729. t.T = 556;
  21730. t.U = 722;
  21731. t.V = 611;
  21732. t.W = 833;
  21733. t.X = 611;
  21734. t.Y = 556;
  21735. t.Z = 556;
  21736. t.bracketleft = 389;
  21737. t.backslash = 278;
  21738. t.bracketright = 389;
  21739. t.asciicircum = 422;
  21740. t.underscore = 500;
  21741. t.quoteleft = 333;
  21742. t.a = 500;
  21743. t.b = 500;
  21744. t.c = 444;
  21745. t.d = 500;
  21746. t.e = 444;
  21747. t.f = 278;
  21748. t.g = 500;
  21749. t.h = 500;
  21750. t.i = 278;
  21751. t.j = 278;
  21752. t.k = 444;
  21753. t.l = 278;
  21754. t.m = 722;
  21755. t.n = 500;
  21756. t.o = 500;
  21757. t.p = 500;
  21758. t.q = 500;
  21759. t.r = 389;
  21760. t.s = 389;
  21761. t.t = 278;
  21762. t.u = 500;
  21763. t.v = 444;
  21764. t.w = 667;
  21765. t.x = 444;
  21766. t.y = 444;
  21767. t.z = 389;
  21768. t.braceleft = 400;
  21769. t.bar = 275;
  21770. t.braceright = 400;
  21771. t.asciitilde = 541;
  21772. t.exclamdown = 389;
  21773. t.cent = 500;
  21774. t.sterling = 500;
  21775. t.fraction = 167;
  21776. t.yen = 500;
  21777. t.florin = 500;
  21778. t.section = 500;
  21779. t.currency = 500;
  21780. t.quotesingle = 214;
  21781. t.quotedblleft = 556;
  21782. t.guillemotleft = 500;
  21783. t.guilsinglleft = 333;
  21784. t.guilsinglright = 333;
  21785. t.fi = 500;
  21786. t.fl = 500;
  21787. t.endash = 500;
  21788. t.dagger = 500;
  21789. t.daggerdbl = 500;
  21790. t.periodcentered = 250;
  21791. t.paragraph = 523;
  21792. t.bullet = 350;
  21793. t.quotesinglbase = 333;
  21794. t.quotedblbase = 556;
  21795. t.quotedblright = 556;
  21796. t.guillemotright = 500;
  21797. t.ellipsis = 889;
  21798. t.perthousand = 1000;
  21799. t.questiondown = 500;
  21800. t.grave = 333;
  21801. t.acute = 333;
  21802. t.circumflex = 333;
  21803. t.tilde = 333;
  21804. t.macron = 333;
  21805. t.breve = 333;
  21806. t.dotaccent = 333;
  21807. t.dieresis = 333;
  21808. t.ring = 333;
  21809. t.cedilla = 333;
  21810. t.hungarumlaut = 333;
  21811. t.ogonek = 333;
  21812. t.caron = 333;
  21813. t.emdash = 889;
  21814. t.AE = 889;
  21815. t.ordfeminine = 276;
  21816. t.Lslash = 556;
  21817. t.Oslash = 722;
  21818. t.OE = 944;
  21819. t.ordmasculine = 310;
  21820. t.ae = 667;
  21821. t.dotlessi = 278;
  21822. t.lslash = 278;
  21823. t.oslash = 500;
  21824. t.oe = 667;
  21825. t.germandbls = 500;
  21826. t.Idieresis = 333;
  21827. t.eacute = 444;
  21828. t.abreve = 500;
  21829. t.uhungarumlaut = 500;
  21830. t.ecaron = 444;
  21831. t.Ydieresis = 556;
  21832. t.divide = 675;
  21833. t.Yacute = 556;
  21834. t.Acircumflex = 611;
  21835. t.aacute = 500;
  21836. t.Ucircumflex = 722;
  21837. t.yacute = 444;
  21838. t.scommaaccent = 389;
  21839. t.ecircumflex = 444;
  21840. t.Uring = 722;
  21841. t.Udieresis = 722;
  21842. t.aogonek = 500;
  21843. t.Uacute = 722;
  21844. t.uogonek = 500;
  21845. t.Edieresis = 611;
  21846. t.Dcroat = 722;
  21847. t.commaaccent = 250;
  21848. t.copyright = 760;
  21849. t.Emacron = 611;
  21850. t.ccaron = 444;
  21851. t.aring = 500;
  21852. t.Ncommaaccent = 667;
  21853. t.lacute = 278;
  21854. t.agrave = 500;
  21855. t.Tcommaaccent = 556;
  21856. t.Cacute = 667;
  21857. t.atilde = 500;
  21858. t.Edotaccent = 611;
  21859. t.scaron = 389;
  21860. t.scedilla = 389;
  21861. t.iacute = 278;
  21862. t.lozenge = 471;
  21863. t.Rcaron = 611;
  21864. t.Gcommaaccent = 722;
  21865. t.ucircumflex = 500;
  21866. t.acircumflex = 500;
  21867. t.Amacron = 611;
  21868. t.rcaron = 389;
  21869. t.ccedilla = 444;
  21870. t.Zdotaccent = 556;
  21871. t.Thorn = 611;
  21872. t.Omacron = 722;
  21873. t.Racute = 611;
  21874. t.Sacute = 500;
  21875. t.dcaron = 544;
  21876. t.Umacron = 722;
  21877. t.uring = 500;
  21878. t.threesuperior = 300;
  21879. t.Ograve = 722;
  21880. t.Agrave = 611;
  21881. t.Abreve = 611;
  21882. t.multiply = 675;
  21883. t.uacute = 500;
  21884. t.Tcaron = 556;
  21885. t.partialdiff = 476;
  21886. t.ydieresis = 444;
  21887. t.Nacute = 667;
  21888. t.icircumflex = 278;
  21889. t.Ecircumflex = 611;
  21890. t.adieresis = 500;
  21891. t.edieresis = 444;
  21892. t.cacute = 444;
  21893. t.nacute = 500;
  21894. t.umacron = 500;
  21895. t.Ncaron = 667;
  21896. t.Iacute = 333;
  21897. t.plusminus = 675;
  21898. t.brokenbar = 275;
  21899. t.registered = 760;
  21900. t.Gbreve = 722;
  21901. t.Idotaccent = 333;
  21902. t.summation = 600;
  21903. t.Egrave = 611;
  21904. t.racute = 389;
  21905. t.omacron = 500;
  21906. t.Zacute = 556;
  21907. t.Zcaron = 556;
  21908. t.greaterequal = 549;
  21909. t.Eth = 722;
  21910. t.Ccedilla = 667;
  21911. t.lcommaaccent = 278;
  21912. t.tcaron = 300;
  21913. t.eogonek = 444;
  21914. t.Uogonek = 722;
  21915. t.Aacute = 611;
  21916. t.Adieresis = 611;
  21917. t.egrave = 444;
  21918. t.zacute = 389;
  21919. t.iogonek = 278;
  21920. t.Oacute = 722;
  21921. t.oacute = 500;
  21922. t.amacron = 500;
  21923. t.sacute = 389;
  21924. t.idieresis = 278;
  21925. t.Ocircumflex = 722;
  21926. t.Ugrave = 722;
  21927. t.Delta = 612;
  21928. t.thorn = 500;
  21929. t.twosuperior = 300;
  21930. t.Odieresis = 722;
  21931. t.mu = 500;
  21932. t.igrave = 278;
  21933. t.ohungarumlaut = 500;
  21934. t.Eogonek = 611;
  21935. t.dcroat = 500;
  21936. t.threequarters = 750;
  21937. t.Scedilla = 500;
  21938. t.lcaron = 300;
  21939. t.Kcommaaccent = 667;
  21940. t.Lacute = 556;
  21941. t.trademark = 980;
  21942. t.edotaccent = 444;
  21943. t.Igrave = 333;
  21944. t.Imacron = 333;
  21945. t.Lcaron = 611;
  21946. t.onehalf = 750;
  21947. t.lessequal = 549;
  21948. t.ocircumflex = 500;
  21949. t.ntilde = 500;
  21950. t.Uhungarumlaut = 722;
  21951. t.Eacute = 611;
  21952. t.emacron = 444;
  21953. t.gbreve = 500;
  21954. t.onequarter = 750;
  21955. t.Scaron = 500;
  21956. t.Scommaaccent = 500;
  21957. t.Ohungarumlaut = 722;
  21958. t.degree = 400;
  21959. t.ograve = 500;
  21960. t.Ccaron = 667;
  21961. t.ugrave = 500;
  21962. t.radical = 453;
  21963. t.Dcaron = 722;
  21964. t.rcommaaccent = 389;
  21965. t.Ntilde = 667;
  21966. t.otilde = 500;
  21967. t.Rcommaaccent = 611;
  21968. t.Lcommaaccent = 556;
  21969. t.Atilde = 611;
  21970. t.Aogonek = 611;
  21971. t.Aring = 611;
  21972. t.Otilde = 722;
  21973. t.zdotaccent = 389;
  21974. t.Ecaron = 611;
  21975. t.Iogonek = 333;
  21976. t.kcommaaccent = 444;
  21977. t.minus = 675;
  21978. t.Icircumflex = 333;
  21979. t.ncaron = 500;
  21980. t.tcommaaccent = 278;
  21981. t.logicalnot = 675;
  21982. t.odieresis = 500;
  21983. t.udieresis = 500;
  21984. t.notequal = 549;
  21985. t.gcommaaccent = 500;
  21986. t.eth = 500;
  21987. t.zcaron = 389;
  21988. t.ncommaaccent = 500;
  21989. t.onesuperior = 300;
  21990. t.imacron = 278;
  21991. t.Euro = 500;
  21992. });
  21993. t.ZapfDingbats = getLookupTableFactory(function (t) {
  21994. t.space = 278;
  21995. t.a1 = 974;
  21996. t.a2 = 961;
  21997. t.a202 = 974;
  21998. t.a3 = 980;
  21999. t.a4 = 719;
  22000. t.a5 = 789;
  22001. t.a119 = 790;
  22002. t.a118 = 791;
  22003. t.a117 = 690;
  22004. t.a11 = 960;
  22005. t.a12 = 939;
  22006. t.a13 = 549;
  22007. t.a14 = 855;
  22008. t.a15 = 911;
  22009. t.a16 = 933;
  22010. t.a105 = 911;
  22011. t.a17 = 945;
  22012. t.a18 = 974;
  22013. t.a19 = 755;
  22014. t.a20 = 846;
  22015. t.a21 = 762;
  22016. t.a22 = 761;
  22017. t.a23 = 571;
  22018. t.a24 = 677;
  22019. t.a25 = 763;
  22020. t.a26 = 760;
  22021. t.a27 = 759;
  22022. t.a28 = 754;
  22023. t.a6 = 494;
  22024. t.a7 = 552;
  22025. t.a8 = 537;
  22026. t.a9 = 577;
  22027. t.a10 = 692;
  22028. t.a29 = 786;
  22029. t.a30 = 788;
  22030. t.a31 = 788;
  22031. t.a32 = 790;
  22032. t.a33 = 793;
  22033. t.a34 = 794;
  22034. t.a35 = 816;
  22035. t.a36 = 823;
  22036. t.a37 = 789;
  22037. t.a38 = 841;
  22038. t.a39 = 823;
  22039. t.a40 = 833;
  22040. t.a41 = 816;
  22041. t.a42 = 831;
  22042. t.a43 = 923;
  22043. t.a44 = 744;
  22044. t.a45 = 723;
  22045. t.a46 = 749;
  22046. t.a47 = 790;
  22047. t.a48 = 792;
  22048. t.a49 = 695;
  22049. t.a50 = 776;
  22050. t.a51 = 768;
  22051. t.a52 = 792;
  22052. t.a53 = 759;
  22053. t.a54 = 707;
  22054. t.a55 = 708;
  22055. t.a56 = 682;
  22056. t.a57 = 701;
  22057. t.a58 = 826;
  22058. t.a59 = 815;
  22059. t.a60 = 789;
  22060. t.a61 = 789;
  22061. t.a62 = 707;
  22062. t.a63 = 687;
  22063. t.a64 = 696;
  22064. t.a65 = 689;
  22065. t.a66 = 786;
  22066. t.a67 = 787;
  22067. t.a68 = 713;
  22068. t.a69 = 791;
  22069. t.a70 = 785;
  22070. t.a71 = 791;
  22071. t.a72 = 873;
  22072. t.a73 = 761;
  22073. t.a74 = 762;
  22074. t.a203 = 762;
  22075. t.a75 = 759;
  22076. t.a204 = 759;
  22077. t.a76 = 892;
  22078. t.a77 = 892;
  22079. t.a78 = 788;
  22080. t.a79 = 784;
  22081. t.a81 = 438;
  22082. t.a82 = 138;
  22083. t.a83 = 277;
  22084. t.a84 = 415;
  22085. t.a97 = 392;
  22086. t.a98 = 392;
  22087. t.a99 = 668;
  22088. t.a100 = 668;
  22089. t.a89 = 390;
  22090. t.a90 = 390;
  22091. t.a93 = 317;
  22092. t.a94 = 317;
  22093. t.a91 = 276;
  22094. t.a92 = 276;
  22095. t.a205 = 509;
  22096. t.a85 = 509;
  22097. t.a206 = 410;
  22098. t.a86 = 410;
  22099. t.a87 = 234;
  22100. t.a88 = 234;
  22101. t.a95 = 334;
  22102. t.a96 = 334;
  22103. t.a101 = 732;
  22104. t.a102 = 544;
  22105. t.a103 = 544;
  22106. t.a104 = 910;
  22107. t.a106 = 667;
  22108. t.a107 = 760;
  22109. t.a108 = 760;
  22110. t.a112 = 776;
  22111. t.a111 = 595;
  22112. t.a110 = 694;
  22113. t.a109 = 626;
  22114. t.a120 = 788;
  22115. t.a121 = 788;
  22116. t.a122 = 788;
  22117. t.a123 = 788;
  22118. t.a124 = 788;
  22119. t.a125 = 788;
  22120. t.a126 = 788;
  22121. t.a127 = 788;
  22122. t.a128 = 788;
  22123. t.a129 = 788;
  22124. t.a130 = 788;
  22125. t.a131 = 788;
  22126. t.a132 = 788;
  22127. t.a133 = 788;
  22128. t.a134 = 788;
  22129. t.a135 = 788;
  22130. t.a136 = 788;
  22131. t.a137 = 788;
  22132. t.a138 = 788;
  22133. t.a139 = 788;
  22134. t.a140 = 788;
  22135. t.a141 = 788;
  22136. t.a142 = 788;
  22137. t.a143 = 788;
  22138. t.a144 = 788;
  22139. t.a145 = 788;
  22140. t.a146 = 788;
  22141. t.a147 = 788;
  22142. t.a148 = 788;
  22143. t.a149 = 788;
  22144. t.a150 = 788;
  22145. t.a151 = 788;
  22146. t.a152 = 788;
  22147. t.a153 = 788;
  22148. t.a154 = 788;
  22149. t.a155 = 788;
  22150. t.a156 = 788;
  22151. t.a157 = 788;
  22152. t.a158 = 788;
  22153. t.a159 = 788;
  22154. t.a160 = 894;
  22155. t.a161 = 838;
  22156. t.a163 = 1016;
  22157. t.a164 = 458;
  22158. t.a196 = 748;
  22159. t.a165 = 924;
  22160. t.a192 = 748;
  22161. t.a166 = 918;
  22162. t.a167 = 927;
  22163. t.a168 = 928;
  22164. t.a169 = 928;
  22165. t.a170 = 834;
  22166. t.a171 = 873;
  22167. t.a172 = 828;
  22168. t.a173 = 924;
  22169. t.a162 = 924;
  22170. t.a174 = 917;
  22171. t.a175 = 930;
  22172. t.a176 = 931;
  22173. t.a177 = 463;
  22174. t.a178 = 883;
  22175. t.a179 = 836;
  22176. t.a193 = 836;
  22177. t.a180 = 867;
  22178. t.a199 = 867;
  22179. t.a181 = 696;
  22180. t.a200 = 696;
  22181. t.a182 = 874;
  22182. t.a201 = 874;
  22183. t.a183 = 760;
  22184. t.a184 = 946;
  22185. t.a197 = 771;
  22186. t.a185 = 865;
  22187. t.a194 = 771;
  22188. t.a198 = 888;
  22189. t.a186 = 967;
  22190. t.a195 = 888;
  22191. t.a187 = 831;
  22192. t.a188 = 873;
  22193. t.a189 = 927;
  22194. t.a190 = 970;
  22195. t.a191 = 918;
  22196. });
  22197. });
  22198. const getFontBasicMetrics = getLookupTableFactory(function (t) {
  22199. t.Courier = {
  22200. ascent: 629,
  22201. descent: -157,
  22202. capHeight: 562,
  22203. xHeight: -426
  22204. };
  22205. t["Courier-Bold"] = {
  22206. ascent: 629,
  22207. descent: -157,
  22208. capHeight: 562,
  22209. xHeight: 439
  22210. };
  22211. t["Courier-Oblique"] = {
  22212. ascent: 629,
  22213. descent: -157,
  22214. capHeight: 562,
  22215. xHeight: 426
  22216. };
  22217. t["Courier-BoldOblique"] = {
  22218. ascent: 629,
  22219. descent: -157,
  22220. capHeight: 562,
  22221. xHeight: 426
  22222. };
  22223. t.Helvetica = {
  22224. ascent: 718,
  22225. descent: -207,
  22226. capHeight: 718,
  22227. xHeight: 523
  22228. };
  22229. t["Helvetica-Bold"] = {
  22230. ascent: 718,
  22231. descent: -207,
  22232. capHeight: 718,
  22233. xHeight: 532
  22234. };
  22235. t["Helvetica-Oblique"] = {
  22236. ascent: 718,
  22237. descent: -207,
  22238. capHeight: 718,
  22239. xHeight: 523
  22240. };
  22241. t["Helvetica-BoldOblique"] = {
  22242. ascent: 718,
  22243. descent: -207,
  22244. capHeight: 718,
  22245. xHeight: 532
  22246. };
  22247. t["Times-Roman"] = {
  22248. ascent: 683,
  22249. descent: -217,
  22250. capHeight: 662,
  22251. xHeight: 450
  22252. };
  22253. t["Times-Bold"] = {
  22254. ascent: 683,
  22255. descent: -217,
  22256. capHeight: 676,
  22257. xHeight: 461
  22258. };
  22259. t["Times-Italic"] = {
  22260. ascent: 683,
  22261. descent: -217,
  22262. capHeight: 653,
  22263. xHeight: 441
  22264. };
  22265. t["Times-BoldItalic"] = {
  22266. ascent: 683,
  22267. descent: -217,
  22268. capHeight: 669,
  22269. xHeight: 462
  22270. };
  22271. t.Symbol = {
  22272. ascent: Math.NaN,
  22273. descent: Math.NaN,
  22274. capHeight: Math.NaN,
  22275. xHeight: Math.NaN
  22276. };
  22277. t.ZapfDingbats = {
  22278. ascent: Math.NaN,
  22279. descent: Math.NaN,
  22280. capHeight: Math.NaN,
  22281. xHeight: Math.NaN
  22282. };
  22283. });
  22284. ;// CONCATENATED MODULE: ./src/core/glyf.js
  22285. const ON_CURVE_POINT = 1 << 0;
  22286. const X_SHORT_VECTOR = 1 << 1;
  22287. const Y_SHORT_VECTOR = 1 << 2;
  22288. const REPEAT_FLAG = 1 << 3;
  22289. const X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR = 1 << 4;
  22290. const Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR = 1 << 5;
  22291. const OVERLAP_SIMPLE = 1 << 6;
  22292. const ARG_1_AND_2_ARE_WORDS = 1 << 0;
  22293. const ARGS_ARE_XY_VALUES = 1 << 1;
  22294. const WE_HAVE_A_SCALE = 1 << 3;
  22295. const MORE_COMPONENTS = 1 << 5;
  22296. const WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6;
  22297. const WE_HAVE_A_TWO_BY_TWO = 1 << 7;
  22298. const WE_HAVE_INSTRUCTIONS = 1 << 8;
  22299. class GlyfTable {
  22300. constructor({
  22301. glyfTable,
  22302. isGlyphLocationsLong,
  22303. locaTable,
  22304. numGlyphs
  22305. }) {
  22306. this.glyphs = [];
  22307. const loca = new DataView(locaTable.buffer, locaTable.byteOffset, locaTable.byteLength);
  22308. const glyf = new DataView(glyfTable.buffer, glyfTable.byteOffset, glyfTable.byteLength);
  22309. const offsetSize = isGlyphLocationsLong ? 4 : 2;
  22310. let prev = isGlyphLocationsLong ? loca.getUint32(0) : 2 * loca.getUint16(0);
  22311. let pos = 0;
  22312. for (let i = 0; i < numGlyphs; i++) {
  22313. pos += offsetSize;
  22314. const next = isGlyphLocationsLong ? loca.getUint32(pos) : 2 * loca.getUint16(pos);
  22315. if (next === prev) {
  22316. this.glyphs.push(new Glyph({}));
  22317. continue;
  22318. }
  22319. const glyph = Glyph.parse(prev, glyf);
  22320. this.glyphs.push(glyph);
  22321. prev = next;
  22322. }
  22323. }
  22324. getSize() {
  22325. return this.glyphs.reduce((a, g) => {
  22326. const size = g.getSize();
  22327. return a + (size + 3 & ~3);
  22328. }, 0);
  22329. }
  22330. write() {
  22331. const totalSize = this.getSize();
  22332. const glyfTable = new DataView(new ArrayBuffer(totalSize));
  22333. const isLocationLong = totalSize > 0x1fffe;
  22334. const offsetSize = isLocationLong ? 4 : 2;
  22335. const locaTable = new DataView(new ArrayBuffer((this.glyphs.length + 1) * offsetSize));
  22336. if (isLocationLong) {
  22337. locaTable.setUint32(0, 0);
  22338. } else {
  22339. locaTable.setUint16(0, 0);
  22340. }
  22341. let pos = 0;
  22342. let locaIndex = 0;
  22343. for (const glyph of this.glyphs) {
  22344. pos += glyph.write(pos, glyfTable);
  22345. pos = pos + 3 & ~3;
  22346. locaIndex += offsetSize;
  22347. if (isLocationLong) {
  22348. locaTable.setUint32(locaIndex, pos);
  22349. } else {
  22350. locaTable.setUint16(locaIndex, pos >> 1);
  22351. }
  22352. }
  22353. return {
  22354. isLocationLong,
  22355. loca: new Uint8Array(locaTable.buffer),
  22356. glyf: new Uint8Array(glyfTable.buffer)
  22357. };
  22358. }
  22359. scale(factors) {
  22360. for (let i = 0, ii = this.glyphs.length; i < ii; i++) {
  22361. this.glyphs[i].scale(factors[i]);
  22362. }
  22363. }
  22364. }
  22365. class Glyph {
  22366. constructor({
  22367. header = null,
  22368. simple = null,
  22369. composites = null
  22370. }) {
  22371. this.header = header;
  22372. this.simple = simple;
  22373. this.composites = composites;
  22374. }
  22375. static parse(pos, glyf) {
  22376. const [read, header] = GlyphHeader.parse(pos, glyf);
  22377. pos += read;
  22378. if (header.numberOfContours < 0) {
  22379. const composites = [];
  22380. while (true) {
  22381. const [n, composite] = CompositeGlyph.parse(pos, glyf);
  22382. pos += n;
  22383. composites.push(composite);
  22384. if (!(composite.flags & MORE_COMPONENTS)) {
  22385. break;
  22386. }
  22387. }
  22388. return new Glyph({
  22389. header,
  22390. composites
  22391. });
  22392. }
  22393. const simple = SimpleGlyph.parse(pos, glyf, header.numberOfContours);
  22394. return new Glyph({
  22395. header,
  22396. simple
  22397. });
  22398. }
  22399. getSize() {
  22400. if (!this.header) {
  22401. return 0;
  22402. }
  22403. const size = this.simple ? this.simple.getSize() : this.composites.reduce((a, c) => a + c.getSize(), 0);
  22404. return this.header.getSize() + size;
  22405. }
  22406. write(pos, buf) {
  22407. if (!this.header) {
  22408. return 0;
  22409. }
  22410. const spos = pos;
  22411. pos += this.header.write(pos, buf);
  22412. if (this.simple) {
  22413. pos += this.simple.write(pos, buf);
  22414. } else {
  22415. for (const composite of this.composites) {
  22416. pos += composite.write(pos, buf);
  22417. }
  22418. }
  22419. return pos - spos;
  22420. }
  22421. scale(factor) {
  22422. if (!this.header) {
  22423. return;
  22424. }
  22425. const xMiddle = (this.header.xMin + this.header.xMax) / 2;
  22426. this.header.scale(xMiddle, factor);
  22427. if (this.simple) {
  22428. this.simple.scale(xMiddle, factor);
  22429. } else {
  22430. for (const composite of this.composites) {
  22431. composite.scale(xMiddle, factor);
  22432. }
  22433. }
  22434. }
  22435. }
  22436. class GlyphHeader {
  22437. constructor({
  22438. numberOfContours,
  22439. xMin,
  22440. yMin,
  22441. xMax,
  22442. yMax
  22443. }) {
  22444. this.numberOfContours = numberOfContours;
  22445. this.xMin = xMin;
  22446. this.yMin = yMin;
  22447. this.xMax = xMax;
  22448. this.yMax = yMax;
  22449. }
  22450. static parse(pos, glyf) {
  22451. return [10, new GlyphHeader({
  22452. numberOfContours: glyf.getInt16(pos),
  22453. xMin: glyf.getInt16(pos + 2),
  22454. yMin: glyf.getInt16(pos + 4),
  22455. xMax: glyf.getInt16(pos + 6),
  22456. yMax: glyf.getInt16(pos + 8)
  22457. })];
  22458. }
  22459. getSize() {
  22460. return 10;
  22461. }
  22462. write(pos, buf) {
  22463. buf.setInt16(pos, this.numberOfContours);
  22464. buf.setInt16(pos + 2, this.xMin);
  22465. buf.setInt16(pos + 4, this.yMin);
  22466. buf.setInt16(pos + 6, this.xMax);
  22467. buf.setInt16(pos + 8, this.yMax);
  22468. return 10;
  22469. }
  22470. scale(x, factor) {
  22471. this.xMin = Math.round(x + (this.xMin - x) * factor);
  22472. this.xMax = Math.round(x + (this.xMax - x) * factor);
  22473. }
  22474. }
  22475. class Contour {
  22476. constructor({
  22477. flags,
  22478. xCoordinates,
  22479. yCoordinates
  22480. }) {
  22481. this.xCoordinates = xCoordinates;
  22482. this.yCoordinates = yCoordinates;
  22483. this.flags = flags;
  22484. }
  22485. }
  22486. class SimpleGlyph {
  22487. constructor({
  22488. contours,
  22489. instructions
  22490. }) {
  22491. this.contours = contours;
  22492. this.instructions = instructions;
  22493. }
  22494. static parse(pos, glyf, numberOfContours) {
  22495. const endPtsOfContours = [];
  22496. for (let i = 0; i < numberOfContours; i++) {
  22497. const endPt = glyf.getUint16(pos);
  22498. pos += 2;
  22499. endPtsOfContours.push(endPt);
  22500. }
  22501. const numberOfPt = endPtsOfContours[numberOfContours - 1] + 1;
  22502. const instructionLength = glyf.getUint16(pos);
  22503. pos += 2;
  22504. const instructions = new Uint8Array(glyf).slice(pos, pos + instructionLength);
  22505. pos += instructionLength;
  22506. const flags = [];
  22507. for (let i = 0; i < numberOfPt; pos++, i++) {
  22508. let flag = glyf.getUint8(pos);
  22509. flags.push(flag);
  22510. if (flag & REPEAT_FLAG) {
  22511. const count = glyf.getUint8(++pos);
  22512. flag ^= REPEAT_FLAG;
  22513. for (let m = 0; m < count; m++) {
  22514. flags.push(flag);
  22515. }
  22516. i += count;
  22517. }
  22518. }
  22519. const allXCoordinates = [];
  22520. let xCoordinates = [];
  22521. let yCoordinates = [];
  22522. let pointFlags = [];
  22523. const contours = [];
  22524. let endPtsOfContoursIndex = 0;
  22525. let lastCoordinate = 0;
  22526. for (let i = 0; i < numberOfPt; i++) {
  22527. const flag = flags[i];
  22528. if (flag & X_SHORT_VECTOR) {
  22529. const x = glyf.getUint8(pos++);
  22530. lastCoordinate += flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR ? x : -x;
  22531. xCoordinates.push(lastCoordinate);
  22532. } else if (flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR) {
  22533. xCoordinates.push(lastCoordinate);
  22534. } else {
  22535. lastCoordinate += glyf.getInt16(pos);
  22536. pos += 2;
  22537. xCoordinates.push(lastCoordinate);
  22538. }
  22539. if (endPtsOfContours[endPtsOfContoursIndex] === i) {
  22540. endPtsOfContoursIndex++;
  22541. allXCoordinates.push(xCoordinates);
  22542. xCoordinates = [];
  22543. }
  22544. }
  22545. lastCoordinate = 0;
  22546. endPtsOfContoursIndex = 0;
  22547. for (let i = 0; i < numberOfPt; i++) {
  22548. const flag = flags[i];
  22549. if (flag & Y_SHORT_VECTOR) {
  22550. const y = glyf.getUint8(pos++);
  22551. lastCoordinate += flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR ? y : -y;
  22552. yCoordinates.push(lastCoordinate);
  22553. } else if (flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR) {
  22554. yCoordinates.push(lastCoordinate);
  22555. } else {
  22556. lastCoordinate += glyf.getInt16(pos);
  22557. pos += 2;
  22558. yCoordinates.push(lastCoordinate);
  22559. }
  22560. pointFlags.push(flag & ON_CURVE_POINT | flag & OVERLAP_SIMPLE);
  22561. if (endPtsOfContours[endPtsOfContoursIndex] === i) {
  22562. xCoordinates = allXCoordinates[endPtsOfContoursIndex];
  22563. endPtsOfContoursIndex++;
  22564. contours.push(new Contour({
  22565. flags: pointFlags,
  22566. xCoordinates,
  22567. yCoordinates
  22568. }));
  22569. yCoordinates = [];
  22570. pointFlags = [];
  22571. }
  22572. }
  22573. return new SimpleGlyph({
  22574. contours,
  22575. instructions
  22576. });
  22577. }
  22578. getSize() {
  22579. let size = this.contours.length * 2 + 2 + this.instructions.length;
  22580. let lastX = 0;
  22581. let lastY = 0;
  22582. for (const contour of this.contours) {
  22583. size += contour.flags.length;
  22584. for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) {
  22585. const x = contour.xCoordinates[i];
  22586. const y = contour.yCoordinates[i];
  22587. let abs = Math.abs(x - lastX);
  22588. if (abs > 255) {
  22589. size += 2;
  22590. } else if (abs > 0) {
  22591. size += 1;
  22592. }
  22593. lastX = x;
  22594. abs = Math.abs(y - lastY);
  22595. if (abs > 255) {
  22596. size += 2;
  22597. } else if (abs > 0) {
  22598. size += 1;
  22599. }
  22600. lastY = y;
  22601. }
  22602. }
  22603. return size;
  22604. }
  22605. write(pos, buf) {
  22606. const spos = pos;
  22607. const xCoordinates = [];
  22608. const yCoordinates = [];
  22609. const flags = [];
  22610. let lastX = 0;
  22611. let lastY = 0;
  22612. for (const contour of this.contours) {
  22613. for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) {
  22614. let flag = contour.flags[i];
  22615. const x = contour.xCoordinates[i];
  22616. let delta = x - lastX;
  22617. if (delta === 0) {
  22618. flag |= X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR;
  22619. xCoordinates.push(0);
  22620. } else {
  22621. const abs = Math.abs(delta);
  22622. if (abs <= 255) {
  22623. flag |= delta >= 0 ? X_SHORT_VECTOR | X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR : X_SHORT_VECTOR;
  22624. xCoordinates.push(abs);
  22625. } else {
  22626. xCoordinates.push(delta);
  22627. }
  22628. }
  22629. lastX = x;
  22630. const y = contour.yCoordinates[i];
  22631. delta = y - lastY;
  22632. if (delta === 0) {
  22633. flag |= Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR;
  22634. yCoordinates.push(0);
  22635. } else {
  22636. const abs = Math.abs(delta);
  22637. if (abs <= 255) {
  22638. flag |= delta >= 0 ? Y_SHORT_VECTOR | Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR : Y_SHORT_VECTOR;
  22639. yCoordinates.push(abs);
  22640. } else {
  22641. yCoordinates.push(delta);
  22642. }
  22643. }
  22644. lastY = y;
  22645. flags.push(flag);
  22646. }
  22647. buf.setUint16(pos, xCoordinates.length - 1);
  22648. pos += 2;
  22649. }
  22650. buf.setUint16(pos, this.instructions.length);
  22651. pos += 2;
  22652. if (this.instructions.length) {
  22653. new Uint8Array(buf.buffer, 0, buf.buffer.byteLength).set(this.instructions, pos);
  22654. pos += this.instructions.length;
  22655. }
  22656. for (const flag of flags) {
  22657. buf.setUint8(pos++, flag);
  22658. }
  22659. for (let i = 0, ii = xCoordinates.length; i < ii; i++) {
  22660. const x = xCoordinates[i];
  22661. const flag = flags[i];
  22662. if (flag & X_SHORT_VECTOR) {
  22663. buf.setUint8(pos++, x);
  22664. } else if (!(flag & X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR)) {
  22665. buf.setInt16(pos, x);
  22666. pos += 2;
  22667. }
  22668. }
  22669. for (let i = 0, ii = yCoordinates.length; i < ii; i++) {
  22670. const y = yCoordinates[i];
  22671. const flag = flags[i];
  22672. if (flag & Y_SHORT_VECTOR) {
  22673. buf.setUint8(pos++, y);
  22674. } else if (!(flag & Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR)) {
  22675. buf.setInt16(pos, y);
  22676. pos += 2;
  22677. }
  22678. }
  22679. return pos - spos;
  22680. }
  22681. scale(x, factor) {
  22682. for (const contour of this.contours) {
  22683. if (contour.xCoordinates.length === 0) {
  22684. continue;
  22685. }
  22686. for (let i = 0, ii = contour.xCoordinates.length; i < ii; i++) {
  22687. contour.xCoordinates[i] = Math.round(x + (contour.xCoordinates[i] - x) * factor);
  22688. }
  22689. }
  22690. }
  22691. }
  22692. class CompositeGlyph {
  22693. constructor({
  22694. flags,
  22695. glyphIndex,
  22696. argument1,
  22697. argument2,
  22698. transf,
  22699. instructions
  22700. }) {
  22701. this.flags = flags;
  22702. this.glyphIndex = glyphIndex;
  22703. this.argument1 = argument1;
  22704. this.argument2 = argument2;
  22705. this.transf = transf;
  22706. this.instructions = instructions;
  22707. }
  22708. static parse(pos, glyf) {
  22709. const spos = pos;
  22710. const transf = [];
  22711. let flags = glyf.getUint16(pos);
  22712. const glyphIndex = glyf.getUint16(pos + 2);
  22713. pos += 4;
  22714. let argument1, argument2;
  22715. if (flags & ARG_1_AND_2_ARE_WORDS) {
  22716. if (flags & ARGS_ARE_XY_VALUES) {
  22717. argument1 = glyf.getInt16(pos);
  22718. argument2 = glyf.getInt16(pos + 2);
  22719. } else {
  22720. argument1 = glyf.getUint16(pos);
  22721. argument2 = glyf.getUint16(pos + 2);
  22722. }
  22723. pos += 4;
  22724. flags ^= ARG_1_AND_2_ARE_WORDS;
  22725. } else {
  22726. if (flags & ARGS_ARE_XY_VALUES) {
  22727. argument1 = glyf.getInt8(pos);
  22728. argument2 = glyf.getInt8(pos + 1);
  22729. } else {
  22730. argument1 = glyf.getUint8(pos);
  22731. argument2 = glyf.getUint8(pos + 1);
  22732. }
  22733. pos += 2;
  22734. }
  22735. if (flags & WE_HAVE_A_SCALE) {
  22736. transf.push(glyf.getUint16(pos));
  22737. pos += 2;
  22738. } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) {
  22739. transf.push(glyf.getUint16(pos), glyf.getUint16(pos + 2));
  22740. pos += 4;
  22741. } else if (flags & WE_HAVE_A_TWO_BY_TWO) {
  22742. transf.push(glyf.getUint16(pos), glyf.getUint16(pos + 2), glyf.getUint16(pos + 4), glyf.getUint16(pos + 6));
  22743. pos += 8;
  22744. }
  22745. let instructions = null;
  22746. if (flags & WE_HAVE_INSTRUCTIONS) {
  22747. const instructionLength = glyf.getUint16(pos);
  22748. pos += 2;
  22749. instructions = new Uint8Array(glyf).slice(pos, pos + instructionLength);
  22750. pos += instructionLength;
  22751. }
  22752. return [pos - spos, new CompositeGlyph({
  22753. flags,
  22754. glyphIndex,
  22755. argument1,
  22756. argument2,
  22757. transf,
  22758. instructions
  22759. })];
  22760. }
  22761. getSize() {
  22762. let size = 2 + 2 + this.transf.length * 2;
  22763. if (this.flags & WE_HAVE_INSTRUCTIONS) {
  22764. size += 2 + this.instructions.length;
  22765. }
  22766. size += 2;
  22767. if (this.flags & 2) {
  22768. if (!(this.argument1 >= -128 && this.argument1 <= 127 && this.argument2 >= -128 && this.argument2 <= 127)) {
  22769. size += 2;
  22770. }
  22771. } else if (!(this.argument1 >= 0 && this.argument1 <= 255 && this.argument2 >= 0 && this.argument2 <= 255)) {
  22772. size += 2;
  22773. }
  22774. return size;
  22775. }
  22776. write(pos, buf) {
  22777. const spos = pos;
  22778. if (this.flags & ARGS_ARE_XY_VALUES) {
  22779. if (!(this.argument1 >= -128 && this.argument1 <= 127 && this.argument2 >= -128 && this.argument2 <= 127)) {
  22780. this.flags |= ARG_1_AND_2_ARE_WORDS;
  22781. }
  22782. } else if (!(this.argument1 >= 0 && this.argument1 <= 255 && this.argument2 >= 0 && this.argument2 <= 255)) {
  22783. this.flags |= ARG_1_AND_2_ARE_WORDS;
  22784. }
  22785. buf.setUint16(pos, this.flags);
  22786. buf.setUint16(pos + 2, this.glyphIndex);
  22787. pos += 4;
  22788. if (this.flags & ARG_1_AND_2_ARE_WORDS) {
  22789. if (this.flags & ARGS_ARE_XY_VALUES) {
  22790. buf.setInt16(pos, this.argument1);
  22791. buf.setInt16(pos + 2, this.argument2);
  22792. } else {
  22793. buf.setUint16(pos, this.argument1);
  22794. buf.setUint16(pos + 2, this.argument2);
  22795. }
  22796. pos += 4;
  22797. } else {
  22798. buf.setUint8(pos, this.argument1);
  22799. buf.setUint8(pos + 1, this.argument2);
  22800. pos += 2;
  22801. }
  22802. if (this.flags & WE_HAVE_INSTRUCTIONS) {
  22803. buf.setUint16(pos, this.instructions.length);
  22804. pos += 2;
  22805. if (this.instructions.length) {
  22806. new Uint8Array(buf.buffer, 0, buf.buffer.byteLength).set(this.instructions, pos);
  22807. pos += this.instructions.length;
  22808. }
  22809. }
  22810. return pos - spos;
  22811. }
  22812. scale(x, factor) {}
  22813. }
  22814. ;// CONCATENATED MODULE: ./src/core/opentype_file_builder.js
  22815. function writeInt16(dest, offset, num) {
  22816. dest[offset] = num >> 8 & 0xff;
  22817. dest[offset + 1] = num & 0xff;
  22818. }
  22819. function writeInt32(dest, offset, num) {
  22820. dest[offset] = num >> 24 & 0xff;
  22821. dest[offset + 1] = num >> 16 & 0xff;
  22822. dest[offset + 2] = num >> 8 & 0xff;
  22823. dest[offset + 3] = num & 0xff;
  22824. }
  22825. function writeData(dest, offset, data) {
  22826. if (data instanceof Uint8Array) {
  22827. dest.set(data, offset);
  22828. } else if (typeof data === "string") {
  22829. for (let i = 0, ii = data.length; i < ii; i++) {
  22830. dest[offset++] = data.charCodeAt(i) & 0xff;
  22831. }
  22832. } else {
  22833. for (const num of data) {
  22834. dest[offset++] = num & 0xff;
  22835. }
  22836. }
  22837. }
  22838. const OTF_HEADER_SIZE = 12;
  22839. const OTF_TABLE_ENTRY_SIZE = 16;
  22840. class OpenTypeFileBuilder {
  22841. constructor(sfnt) {
  22842. this.sfnt = sfnt;
  22843. this.tables = Object.create(null);
  22844. }
  22845. static getSearchParams(entriesCount, entrySize) {
  22846. let maxPower2 = 1,
  22847. log2 = 0;
  22848. while ((maxPower2 ^ entriesCount) > maxPower2) {
  22849. maxPower2 <<= 1;
  22850. log2++;
  22851. }
  22852. const searchRange = maxPower2 * entrySize;
  22853. return {
  22854. range: searchRange,
  22855. entry: log2,
  22856. rangeShift: entrySize * entriesCount - searchRange
  22857. };
  22858. }
  22859. toArray() {
  22860. let sfnt = this.sfnt;
  22861. const tables = this.tables;
  22862. const tablesNames = Object.keys(tables);
  22863. tablesNames.sort();
  22864. const numTables = tablesNames.length;
  22865. let i, j, jj, table, tableName;
  22866. let offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  22867. const tableOffsets = [offset];
  22868. for (i = 0; i < numTables; i++) {
  22869. table = tables[tablesNames[i]];
  22870. const paddedLength = (table.length + 3 & ~3) >>> 0;
  22871. offset += paddedLength;
  22872. tableOffsets.push(offset);
  22873. }
  22874. const file = new Uint8Array(offset);
  22875. for (i = 0; i < numTables; i++) {
  22876. table = tables[tablesNames[i]];
  22877. writeData(file, tableOffsets[i], table);
  22878. }
  22879. if (sfnt === "true") {
  22880. sfnt = string32(0x00010000);
  22881. }
  22882. file[0] = sfnt.charCodeAt(0) & 0xff;
  22883. file[1] = sfnt.charCodeAt(1) & 0xff;
  22884. file[2] = sfnt.charCodeAt(2) & 0xff;
  22885. file[3] = sfnt.charCodeAt(3) & 0xff;
  22886. writeInt16(file, 4, numTables);
  22887. const searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  22888. writeInt16(file, 6, searchParams.range);
  22889. writeInt16(file, 8, searchParams.entry);
  22890. writeInt16(file, 10, searchParams.rangeShift);
  22891. offset = OTF_HEADER_SIZE;
  22892. for (i = 0; i < numTables; i++) {
  22893. tableName = tablesNames[i];
  22894. file[offset] = tableName.charCodeAt(0) & 0xff;
  22895. file[offset + 1] = tableName.charCodeAt(1) & 0xff;
  22896. file[offset + 2] = tableName.charCodeAt(2) & 0xff;
  22897. file[offset + 3] = tableName.charCodeAt(3) & 0xff;
  22898. let checksum = 0;
  22899. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  22900. const quad = readUint32(file, j);
  22901. checksum = checksum + quad >>> 0;
  22902. }
  22903. writeInt32(file, offset + 4, checksum);
  22904. writeInt32(file, offset + 8, tableOffsets[i]);
  22905. writeInt32(file, offset + 12, tables[tableName].length);
  22906. offset += OTF_TABLE_ENTRY_SIZE;
  22907. }
  22908. return file;
  22909. }
  22910. addTable(tag, data) {
  22911. if (tag in this.tables) {
  22912. throw new Error("Table " + tag + " already exists");
  22913. }
  22914. this.tables[tag] = data;
  22915. }
  22916. }
  22917. ;// CONCATENATED MODULE: ./src/core/type1_parser.js
  22918. const HINTING_ENABLED = false;
  22919. const COMMAND_MAP = {
  22920. hstem: [1],
  22921. vstem: [3],
  22922. vmoveto: [4],
  22923. rlineto: [5],
  22924. hlineto: [6],
  22925. vlineto: [7],
  22926. rrcurveto: [8],
  22927. callsubr: [10],
  22928. flex: [12, 35],
  22929. drop: [12, 18],
  22930. endchar: [14],
  22931. rmoveto: [21],
  22932. hmoveto: [22],
  22933. vhcurveto: [30],
  22934. hvcurveto: [31]
  22935. };
  22936. class Type1CharString {
  22937. constructor() {
  22938. this.width = 0;
  22939. this.lsb = 0;
  22940. this.flexing = false;
  22941. this.output = [];
  22942. this.stack = [];
  22943. }
  22944. convert(encoded, subrs, seacAnalysisEnabled) {
  22945. const count = encoded.length;
  22946. let error = false;
  22947. let wx, sbx, subrNumber;
  22948. for (let i = 0; i < count; i++) {
  22949. let value = encoded[i];
  22950. if (value < 32) {
  22951. if (value === 12) {
  22952. value = (value << 8) + encoded[++i];
  22953. }
  22954. switch (value) {
  22955. case 1:
  22956. if (!HINTING_ENABLED) {
  22957. this.stack = [];
  22958. break;
  22959. }
  22960. error = this.executeCommand(2, COMMAND_MAP.hstem);
  22961. break;
  22962. case 3:
  22963. if (!HINTING_ENABLED) {
  22964. this.stack = [];
  22965. break;
  22966. }
  22967. error = this.executeCommand(2, COMMAND_MAP.vstem);
  22968. break;
  22969. case 4:
  22970. if (this.flexing) {
  22971. if (this.stack.length < 1) {
  22972. error = true;
  22973. break;
  22974. }
  22975. const dy = this.stack.pop();
  22976. this.stack.push(0, dy);
  22977. break;
  22978. }
  22979. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  22980. break;
  22981. case 5:
  22982. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  22983. break;
  22984. case 6:
  22985. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  22986. break;
  22987. case 7:
  22988. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  22989. break;
  22990. case 8:
  22991. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  22992. break;
  22993. case 9:
  22994. this.stack = [];
  22995. break;
  22996. case 10:
  22997. if (this.stack.length < 1) {
  22998. error = true;
  22999. break;
  23000. }
  23001. subrNumber = this.stack.pop();
  23002. if (!subrs[subrNumber]) {
  23003. error = true;
  23004. break;
  23005. }
  23006. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  23007. break;
  23008. case 11:
  23009. return error;
  23010. case 13:
  23011. if (this.stack.length < 2) {
  23012. error = true;
  23013. break;
  23014. }
  23015. wx = this.stack.pop();
  23016. sbx = this.stack.pop();
  23017. this.lsb = sbx;
  23018. this.width = wx;
  23019. this.stack.push(wx, sbx);
  23020. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23021. break;
  23022. case 14:
  23023. this.output.push(COMMAND_MAP.endchar[0]);
  23024. break;
  23025. case 21:
  23026. if (this.flexing) {
  23027. break;
  23028. }
  23029. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23030. break;
  23031. case 22:
  23032. if (this.flexing) {
  23033. this.stack.push(0);
  23034. break;
  23035. }
  23036. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23037. break;
  23038. case 30:
  23039. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23040. break;
  23041. case 31:
  23042. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23043. break;
  23044. case (12 << 8) + 0:
  23045. this.stack = [];
  23046. break;
  23047. case (12 << 8) + 1:
  23048. if (!HINTING_ENABLED) {
  23049. this.stack = [];
  23050. break;
  23051. }
  23052. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23053. break;
  23054. case (12 << 8) + 2:
  23055. if (!HINTING_ENABLED) {
  23056. this.stack = [];
  23057. break;
  23058. }
  23059. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23060. break;
  23061. case (12 << 8) + 6:
  23062. if (seacAnalysisEnabled) {
  23063. const asb = this.stack.at(-5);
  23064. this.seac = this.stack.splice(-4, 4);
  23065. this.seac[0] += this.lsb - asb;
  23066. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23067. } else {
  23068. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23069. }
  23070. break;
  23071. case (12 << 8) + 7:
  23072. if (this.stack.length < 4) {
  23073. error = true;
  23074. break;
  23075. }
  23076. this.stack.pop();
  23077. wx = this.stack.pop();
  23078. const sby = this.stack.pop();
  23079. sbx = this.stack.pop();
  23080. this.lsb = sbx;
  23081. this.width = wx;
  23082. this.stack.push(wx, sbx, sby);
  23083. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23084. break;
  23085. case (12 << 8) + 12:
  23086. if (this.stack.length < 2) {
  23087. error = true;
  23088. break;
  23089. }
  23090. const num2 = this.stack.pop();
  23091. const num1 = this.stack.pop();
  23092. this.stack.push(num1 / num2);
  23093. break;
  23094. case (12 << 8) + 16:
  23095. if (this.stack.length < 2) {
  23096. error = true;
  23097. break;
  23098. }
  23099. subrNumber = this.stack.pop();
  23100. const numArgs = this.stack.pop();
  23101. if (subrNumber === 0 && numArgs === 3) {
  23102. const flexArgs = this.stack.splice(-17, 17);
  23103. this.stack.push(flexArgs[2] + flexArgs[0], flexArgs[3] + flexArgs[1], flexArgs[4], flexArgs[5], flexArgs[6], flexArgs[7], flexArgs[8], flexArgs[9], flexArgs[10], flexArgs[11], flexArgs[12], flexArgs[13], flexArgs[14]);
  23104. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23105. this.flexing = false;
  23106. this.stack.push(flexArgs[15], flexArgs[16]);
  23107. } else if (subrNumber === 1 && numArgs === 0) {
  23108. this.flexing = true;
  23109. }
  23110. break;
  23111. case (12 << 8) + 17:
  23112. break;
  23113. case (12 << 8) + 33:
  23114. this.stack = [];
  23115. break;
  23116. default:
  23117. warn('Unknown type 1 charstring command of "' + value + '"');
  23118. break;
  23119. }
  23120. if (error) {
  23121. break;
  23122. }
  23123. continue;
  23124. } else if (value <= 246) {
  23125. value -= 139;
  23126. } else if (value <= 250) {
  23127. value = (value - 247) * 256 + encoded[++i] + 108;
  23128. } else if (value <= 254) {
  23129. value = -((value - 251) * 256) - encoded[++i] - 108;
  23130. } else {
  23131. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23132. }
  23133. this.stack.push(value);
  23134. }
  23135. return error;
  23136. }
  23137. executeCommand(howManyArgs, command, keepStack) {
  23138. const stackLength = this.stack.length;
  23139. if (howManyArgs > stackLength) {
  23140. return true;
  23141. }
  23142. const start = stackLength - howManyArgs;
  23143. for (let i = start; i < stackLength; i++) {
  23144. let value = this.stack[i];
  23145. if (Number.isInteger(value)) {
  23146. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  23147. } else {
  23148. value = 65536 * value | 0;
  23149. this.output.push(255, value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  23150. }
  23151. }
  23152. this.output.push(...command);
  23153. if (keepStack) {
  23154. this.stack.splice(start, howManyArgs);
  23155. } else {
  23156. this.stack.length = 0;
  23157. }
  23158. return false;
  23159. }
  23160. }
  23161. const EEXEC_ENCRYPT_KEY = 55665;
  23162. const CHAR_STRS_ENCRYPT_KEY = 4330;
  23163. function isHexDigit(code) {
  23164. return code >= 48 && code <= 57 || code >= 65 && code <= 70 || code >= 97 && code <= 102;
  23165. }
  23166. function decrypt(data, key, discardNumber) {
  23167. if (discardNumber >= data.length) {
  23168. return new Uint8Array(0);
  23169. }
  23170. const c1 = 52845,
  23171. c2 = 22719;
  23172. let r = key | 0,
  23173. i,
  23174. j;
  23175. for (i = 0; i < discardNumber; i++) {
  23176. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  23177. }
  23178. const count = data.length - discardNumber;
  23179. const decrypted = new Uint8Array(count);
  23180. for (i = discardNumber, j = 0; j < count; i++, j++) {
  23181. const value = data[i];
  23182. decrypted[j] = value ^ r >> 8;
  23183. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  23184. }
  23185. return decrypted;
  23186. }
  23187. function decryptAscii(data, key, discardNumber) {
  23188. const c1 = 52845,
  23189. c2 = 22719;
  23190. let r = key | 0;
  23191. const count = data.length,
  23192. maybeLength = count >>> 1;
  23193. const decrypted = new Uint8Array(maybeLength);
  23194. let i, j;
  23195. for (i = 0, j = 0; i < count; i++) {
  23196. const digit1 = data[i];
  23197. if (!isHexDigit(digit1)) {
  23198. continue;
  23199. }
  23200. i++;
  23201. let digit2;
  23202. while (i < count && !isHexDigit(digit2 = data[i])) {
  23203. i++;
  23204. }
  23205. if (i < count) {
  23206. const value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23207. decrypted[j++] = value ^ r >> 8;
  23208. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  23209. }
  23210. }
  23211. return decrypted.slice(discardNumber, j);
  23212. }
  23213. function isSpecial(c) {
  23214. return c === 0x2f || c === 0x5b || c === 0x5d || c === 0x7b || c === 0x7d || c === 0x28 || c === 0x29;
  23215. }
  23216. class Type1Parser {
  23217. constructor(stream, encrypted, seacAnalysisEnabled) {
  23218. if (encrypted) {
  23219. const data = stream.getBytes();
  23220. const isBinary = !((isHexDigit(data[0]) || isWhiteSpace(data[0])) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]) && isHexDigit(data[4]) && isHexDigit(data[5]) && isHexDigit(data[6]) && isHexDigit(data[7]));
  23221. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23222. }
  23223. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  23224. this.stream = stream;
  23225. this.nextChar();
  23226. }
  23227. readNumberArray() {
  23228. this.getToken();
  23229. const array = [];
  23230. while (true) {
  23231. const token = this.getToken();
  23232. if (token === null || token === "]" || token === "}") {
  23233. break;
  23234. }
  23235. array.push(parseFloat(token || 0));
  23236. }
  23237. return array;
  23238. }
  23239. readNumber() {
  23240. const token = this.getToken();
  23241. return parseFloat(token || 0);
  23242. }
  23243. readInt() {
  23244. const token = this.getToken();
  23245. return parseInt(token || 0, 10) | 0;
  23246. }
  23247. readBoolean() {
  23248. const token = this.getToken();
  23249. return token === "true" ? 1 : 0;
  23250. }
  23251. nextChar() {
  23252. return this.currentChar = this.stream.getByte();
  23253. }
  23254. prevChar() {
  23255. this.stream.skip(-2);
  23256. return this.currentChar = this.stream.getByte();
  23257. }
  23258. getToken() {
  23259. let comment = false;
  23260. let ch = this.currentChar;
  23261. while (true) {
  23262. if (ch === -1) {
  23263. return null;
  23264. }
  23265. if (comment) {
  23266. if (ch === 0x0a || ch === 0x0d) {
  23267. comment = false;
  23268. }
  23269. } else if (ch === 0x25) {
  23270. comment = true;
  23271. } else if (!isWhiteSpace(ch)) {
  23272. break;
  23273. }
  23274. ch = this.nextChar();
  23275. }
  23276. if (isSpecial(ch)) {
  23277. this.nextChar();
  23278. return String.fromCharCode(ch);
  23279. }
  23280. let token = "";
  23281. do {
  23282. token += String.fromCharCode(ch);
  23283. ch = this.nextChar();
  23284. } while (ch >= 0 && !isWhiteSpace(ch) && !isSpecial(ch));
  23285. return token;
  23286. }
  23287. readCharStrings(bytes, lenIV) {
  23288. if (lenIV === -1) {
  23289. return bytes;
  23290. }
  23291. return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV);
  23292. }
  23293. extractFontProgram(properties) {
  23294. const stream = this.stream;
  23295. const subrs = [],
  23296. charstrings = [];
  23297. const privateData = Object.create(null);
  23298. privateData.lenIV = 4;
  23299. const program = {
  23300. subrs: [],
  23301. charstrings: [],
  23302. properties: {
  23303. privateData
  23304. }
  23305. };
  23306. let token, length, data, lenIV;
  23307. while ((token = this.getToken()) !== null) {
  23308. if (token !== "/") {
  23309. continue;
  23310. }
  23311. token = this.getToken();
  23312. switch (token) {
  23313. case "CharStrings":
  23314. this.getToken();
  23315. this.getToken();
  23316. this.getToken();
  23317. this.getToken();
  23318. while (true) {
  23319. token = this.getToken();
  23320. if (token === null || token === "end") {
  23321. break;
  23322. }
  23323. if (token !== "/") {
  23324. continue;
  23325. }
  23326. const glyph = this.getToken();
  23327. length = this.readInt();
  23328. this.getToken();
  23329. data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
  23330. lenIV = program.properties.privateData.lenIV;
  23331. const encoded = this.readCharStrings(data, lenIV);
  23332. this.nextChar();
  23333. token = this.getToken();
  23334. if (token === "noaccess") {
  23335. this.getToken();
  23336. } else if (token === "/") {
  23337. this.prevChar();
  23338. }
  23339. charstrings.push({
  23340. glyph,
  23341. encoded
  23342. });
  23343. }
  23344. break;
  23345. case "Subrs":
  23346. this.readInt();
  23347. this.getToken();
  23348. while (this.getToken() === "dup") {
  23349. const index = this.readInt();
  23350. length = this.readInt();
  23351. this.getToken();
  23352. data = length > 0 ? stream.getBytes(length) : new Uint8Array(0);
  23353. lenIV = program.properties.privateData.lenIV;
  23354. const encoded = this.readCharStrings(data, lenIV);
  23355. this.nextChar();
  23356. token = this.getToken();
  23357. if (token === "noaccess") {
  23358. this.getToken();
  23359. }
  23360. subrs[index] = encoded;
  23361. }
  23362. break;
  23363. case "BlueValues":
  23364. case "OtherBlues":
  23365. case "FamilyBlues":
  23366. case "FamilyOtherBlues":
  23367. const blueArray = this.readNumberArray();
  23368. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  23369. program.properties.privateData[token] = blueArray;
  23370. }
  23371. break;
  23372. case "StemSnapH":
  23373. case "StemSnapV":
  23374. program.properties.privateData[token] = this.readNumberArray();
  23375. break;
  23376. case "StdHW":
  23377. case "StdVW":
  23378. program.properties.privateData[token] = this.readNumberArray()[0];
  23379. break;
  23380. case "BlueShift":
  23381. case "lenIV":
  23382. case "BlueFuzz":
  23383. case "BlueScale":
  23384. case "LanguageGroup":
  23385. program.properties.privateData[token] = this.readNumber();
  23386. break;
  23387. case "ExpansionFactor":
  23388. program.properties.privateData[token] = this.readNumber() || 0.06;
  23389. break;
  23390. case "ForceBold":
  23391. program.properties.privateData[token] = this.readBoolean();
  23392. break;
  23393. }
  23394. }
  23395. for (const {
  23396. encoded,
  23397. glyph
  23398. } of charstrings) {
  23399. const charString = new Type1CharString();
  23400. const error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  23401. let output = charString.output;
  23402. if (error) {
  23403. output = [14];
  23404. }
  23405. const charStringObject = {
  23406. glyphName: glyph,
  23407. charstring: output,
  23408. width: charString.width,
  23409. lsb: charString.lsb,
  23410. seac: charString.seac
  23411. };
  23412. if (glyph === ".notdef") {
  23413. program.charstrings.unshift(charStringObject);
  23414. } else {
  23415. program.charstrings.push(charStringObject);
  23416. }
  23417. if (properties.builtInEncoding) {
  23418. const index = properties.builtInEncoding.indexOf(glyph);
  23419. if (index > -1 && properties.widths[index] === undefined && index >= properties.firstChar && index <= properties.lastChar) {
  23420. properties.widths[index] = charString.width;
  23421. }
  23422. }
  23423. }
  23424. return program;
  23425. }
  23426. extractFontHeader(properties) {
  23427. let token;
  23428. while ((token = this.getToken()) !== null) {
  23429. if (token !== "/") {
  23430. continue;
  23431. }
  23432. token = this.getToken();
  23433. switch (token) {
  23434. case "FontMatrix":
  23435. const matrix = this.readNumberArray();
  23436. properties.fontMatrix = matrix;
  23437. break;
  23438. case "Encoding":
  23439. const encodingArg = this.getToken();
  23440. let encoding;
  23441. if (!/^\d+$/.test(encodingArg)) {
  23442. encoding = getEncoding(encodingArg);
  23443. } else {
  23444. encoding = [];
  23445. const size = parseInt(encodingArg, 10) | 0;
  23446. this.getToken();
  23447. for (let j = 0; j < size; j++) {
  23448. token = this.getToken();
  23449. while (token !== "dup" && token !== "def") {
  23450. token = this.getToken();
  23451. if (token === null) {
  23452. return;
  23453. }
  23454. }
  23455. if (token === "def") {
  23456. break;
  23457. }
  23458. const index = this.readInt();
  23459. this.getToken();
  23460. const glyph = this.getToken();
  23461. encoding[index] = glyph;
  23462. this.getToken();
  23463. }
  23464. }
  23465. properties.builtInEncoding = encoding;
  23466. break;
  23467. case "FontBBox":
  23468. const fontBBox = this.readNumberArray();
  23469. properties.ascent = Math.max(fontBBox[3], fontBBox[1]);
  23470. properties.descent = Math.min(fontBBox[1], fontBBox[3]);
  23471. properties.ascentScaled = true;
  23472. break;
  23473. }
  23474. }
  23475. }
  23476. }
  23477. ;// CONCATENATED MODULE: ./src/core/type1_font.js
  23478. function findBlock(streamBytes, signature, startIndex) {
  23479. const streamBytesLength = streamBytes.length;
  23480. const signatureLength = signature.length;
  23481. const scanLength = streamBytesLength - signatureLength;
  23482. let i = startIndex,
  23483. found = false;
  23484. while (i < scanLength) {
  23485. let j = 0;
  23486. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  23487. j++;
  23488. }
  23489. if (j >= signatureLength) {
  23490. i += j;
  23491. while (i < streamBytesLength && isWhiteSpace(streamBytes[i])) {
  23492. i++;
  23493. }
  23494. found = true;
  23495. break;
  23496. }
  23497. i++;
  23498. }
  23499. return {
  23500. found,
  23501. length: i
  23502. };
  23503. }
  23504. function getHeaderBlock(stream, suggestedLength) {
  23505. const EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  23506. const streamStartPos = stream.pos;
  23507. let headerBytes, headerBytesLength, block;
  23508. try {
  23509. headerBytes = stream.getBytes(suggestedLength);
  23510. headerBytesLength = headerBytes.length;
  23511. } catch {}
  23512. if (headerBytesLength === suggestedLength) {
  23513. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  23514. if (block.found && block.length === suggestedLength) {
  23515. return {
  23516. stream: new Stream(headerBytes),
  23517. length: suggestedLength
  23518. };
  23519. }
  23520. }
  23521. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  23522. stream.pos = streamStartPos;
  23523. const SCAN_BLOCK_LENGTH = 2048;
  23524. let actualLength;
  23525. while (true) {
  23526. const scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  23527. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  23528. if (block.length === 0) {
  23529. break;
  23530. }
  23531. stream.pos += block.length;
  23532. if (block.found) {
  23533. actualLength = stream.pos - streamStartPos;
  23534. break;
  23535. }
  23536. }
  23537. stream.pos = streamStartPos;
  23538. if (actualLength) {
  23539. return {
  23540. stream: new Stream(stream.getBytes(actualLength)),
  23541. length: actualLength
  23542. };
  23543. }
  23544. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  23545. return {
  23546. stream: new Stream(stream.getBytes(suggestedLength)),
  23547. length: suggestedLength
  23548. };
  23549. }
  23550. function getEexecBlock(stream, suggestedLength) {
  23551. const eexecBytes = stream.getBytes();
  23552. if (eexecBytes.length === 0) {
  23553. throw new FormatError("getEexecBlock - no font program found.");
  23554. }
  23555. return {
  23556. stream: new Stream(eexecBytes),
  23557. length: eexecBytes.length
  23558. };
  23559. }
  23560. class Type1Font {
  23561. constructor(name, file, properties) {
  23562. const PFB_HEADER_SIZE = 6;
  23563. let headerBlockLength = properties.length1;
  23564. let eexecBlockLength = properties.length2;
  23565. let pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23566. const pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23567. if (pfbHeaderPresent) {
  23568. file.skip(PFB_HEADER_SIZE);
  23569. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  23570. }
  23571. const headerBlock = getHeaderBlock(file, headerBlockLength);
  23572. const headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  23573. headerBlockParser.extractFontHeader(properties);
  23574. if (pfbHeaderPresent) {
  23575. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23576. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  23577. }
  23578. const eexecBlock = getEexecBlock(file, eexecBlockLength);
  23579. const eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  23580. const data = eexecBlockParser.extractFontProgram(properties);
  23581. for (const key in data.properties) {
  23582. properties[key] = data.properties[key];
  23583. }
  23584. const charstrings = data.charstrings;
  23585. const type2Charstrings = this.getType2Charstrings(charstrings);
  23586. const subrs = this.getType2Subrs(data.subrs);
  23587. this.charstrings = charstrings;
  23588. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  23589. this.seacs = this.getSeacs(data.charstrings);
  23590. }
  23591. get numGlyphs() {
  23592. return this.charstrings.length + 1;
  23593. }
  23594. getCharset() {
  23595. const charset = [".notdef"];
  23596. for (const {
  23597. glyphName
  23598. } of this.charstrings) {
  23599. charset.push(glyphName);
  23600. }
  23601. return charset;
  23602. }
  23603. getGlyphMapping(properties) {
  23604. const charstrings = this.charstrings;
  23605. if (properties.composite) {
  23606. const charCodeToGlyphId = Object.create(null);
  23607. for (let glyphId = 0, charstringsLen = charstrings.length; glyphId < charstringsLen; glyphId++) {
  23608. const charCode = properties.cMap.charCodeOf(glyphId);
  23609. charCodeToGlyphId[charCode] = glyphId + 1;
  23610. }
  23611. return charCodeToGlyphId;
  23612. }
  23613. const glyphNames = [".notdef"];
  23614. let builtInEncoding, glyphId;
  23615. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23616. glyphNames.push(charstrings[glyphId].glyphName);
  23617. }
  23618. const encoding = properties.builtInEncoding;
  23619. if (encoding) {
  23620. builtInEncoding = Object.create(null);
  23621. for (const charCode in encoding) {
  23622. glyphId = glyphNames.indexOf(encoding[charCode]);
  23623. if (glyphId >= 0) {
  23624. builtInEncoding[charCode] = glyphId;
  23625. }
  23626. }
  23627. }
  23628. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23629. }
  23630. hasGlyphId(id) {
  23631. if (id < 0 || id >= this.numGlyphs) {
  23632. return false;
  23633. }
  23634. if (id === 0) {
  23635. return true;
  23636. }
  23637. const glyph = this.charstrings[id - 1];
  23638. return glyph.charstring.length > 0;
  23639. }
  23640. getSeacs(charstrings) {
  23641. const seacMap = [];
  23642. for (let i = 0, ii = charstrings.length; i < ii; i++) {
  23643. const charstring = charstrings[i];
  23644. if (charstring.seac) {
  23645. seacMap[i + 1] = charstring.seac;
  23646. }
  23647. }
  23648. return seacMap;
  23649. }
  23650. getType2Charstrings(type1Charstrings) {
  23651. const type2Charstrings = [];
  23652. for (const type1Charstring of type1Charstrings) {
  23653. type2Charstrings.push(type1Charstring.charstring);
  23654. }
  23655. return type2Charstrings;
  23656. }
  23657. getType2Subrs(type1Subrs) {
  23658. let bias = 0;
  23659. const count = type1Subrs.length;
  23660. if (count < 1133) {
  23661. bias = 107;
  23662. } else if (count < 33769) {
  23663. bias = 1131;
  23664. } else {
  23665. bias = 32768;
  23666. }
  23667. const type2Subrs = [];
  23668. let i;
  23669. for (i = 0; i < bias; i++) {
  23670. type2Subrs.push([0x0b]);
  23671. }
  23672. for (i = 0; i < count; i++) {
  23673. type2Subrs.push(type1Subrs[i]);
  23674. }
  23675. return type2Subrs;
  23676. }
  23677. wrap(name, glyphs, charstrings, subrs, properties) {
  23678. const cff = new CFF();
  23679. cff.header = new CFFHeader(1, 0, 4, 4);
  23680. cff.names = [name];
  23681. const topDict = new CFFTopDict();
  23682. topDict.setByName("version", 391);
  23683. topDict.setByName("Notice", 392);
  23684. topDict.setByName("FullName", 393);
  23685. topDict.setByName("FamilyName", 394);
  23686. topDict.setByName("Weight", 395);
  23687. topDict.setByName("Encoding", null);
  23688. topDict.setByName("FontMatrix", properties.fontMatrix);
  23689. topDict.setByName("FontBBox", properties.bbox);
  23690. topDict.setByName("charset", null);
  23691. topDict.setByName("CharStrings", null);
  23692. topDict.setByName("Private", null);
  23693. cff.topDict = topDict;
  23694. const strings = new CFFStrings();
  23695. strings.add("Version 0.11");
  23696. strings.add("See original notice");
  23697. strings.add(name);
  23698. strings.add(name);
  23699. strings.add("Medium");
  23700. cff.strings = strings;
  23701. cff.globalSubrIndex = new CFFIndex();
  23702. const count = glyphs.length;
  23703. const charsetArray = [".notdef"];
  23704. let i, ii;
  23705. for (i = 0; i < count; i++) {
  23706. const glyphName = charstrings[i].glyphName;
  23707. const index = CFFStandardStrings.indexOf(glyphName);
  23708. if (index === -1) {
  23709. strings.add(glyphName);
  23710. }
  23711. charsetArray.push(glyphName);
  23712. }
  23713. cff.charset = new CFFCharset(false, 0, charsetArray);
  23714. const charStringsIndex = new CFFIndex();
  23715. charStringsIndex.add([0x8b, 0x0e]);
  23716. for (i = 0; i < count; i++) {
  23717. charStringsIndex.add(glyphs[i]);
  23718. }
  23719. cff.charStrings = charStringsIndex;
  23720. const privateDict = new CFFPrivateDict();
  23721. privateDict.setByName("Subrs", null);
  23722. const fields = ["BlueValues", "OtherBlues", "FamilyBlues", "FamilyOtherBlues", "StemSnapH", "StemSnapV", "BlueShift", "BlueFuzz", "BlueScale", "LanguageGroup", "ExpansionFactor", "ForceBold", "StdHW", "StdVW"];
  23723. for (i = 0, ii = fields.length; i < ii; i++) {
  23724. const field = fields[i];
  23725. if (!(field in properties.privateData)) {
  23726. continue;
  23727. }
  23728. const value = properties.privateData[field];
  23729. if (Array.isArray(value)) {
  23730. for (let j = value.length - 1; j > 0; j--) {
  23731. value[j] -= value[j - 1];
  23732. }
  23733. }
  23734. privateDict.setByName(field, value);
  23735. }
  23736. cff.topDict.privateDict = privateDict;
  23737. const subrIndex = new CFFIndex();
  23738. for (i = 0, ii = subrs.length; i < ii; i++) {
  23739. subrIndex.add(subrs[i]);
  23740. }
  23741. privateDict.subrsIndex = subrIndex;
  23742. const compiler = new CFFCompiler(cff);
  23743. return compiler.compile();
  23744. }
  23745. }
  23746. ;// CONCATENATED MODULE: ./src/core/fonts.js
  23747. const PRIVATE_USE_AREAS = [[0xe000, 0xf8ff], [0x100000, 0x10fffd]];
  23748. const PDF_GLYPH_SPACE_UNITS = 1000;
  23749. const EXPORT_DATA_PROPERTIES = ["ascent", "bbox", "black", "bold", "charProcOperatorList", "composite", "cssFontInfo", "data", "defaultVMetrics", "defaultWidth", "descent", "fallbackName", "fontMatrix", "isInvalidPDFjsFont", "isType3Font", "italic", "loadedName", "mimetype", "missingFile", "name", "remeasure", "subtype", "systemFontInfo", "type", "vertical"];
  23750. const EXPORT_DATA_EXTRA_PROPERTIES = ["cMap", "defaultEncoding", "differences", "isMonospace", "isSerifFont", "isSymbolicFont", "seacMap", "toFontChar", "toUnicode", "vmetrics", "widths"];
  23751. function adjustWidths(properties) {
  23752. if (!properties.fontMatrix) {
  23753. return;
  23754. }
  23755. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  23756. return;
  23757. }
  23758. const scale = 0.001 / properties.fontMatrix[0];
  23759. const glyphsWidths = properties.widths;
  23760. for (const glyph in glyphsWidths) {
  23761. glyphsWidths[glyph] *= scale;
  23762. }
  23763. properties.defaultWidth *= scale;
  23764. }
  23765. function adjustTrueTypeToUnicode(properties, isSymbolicFont, nameRecords) {
  23766. if (properties.isInternalFont) {
  23767. return;
  23768. }
  23769. if (properties.hasIncludedToUnicodeMap) {
  23770. return;
  23771. }
  23772. if (properties.hasEncoding) {
  23773. return;
  23774. }
  23775. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  23776. return;
  23777. }
  23778. if (!isSymbolicFont) {
  23779. return;
  23780. }
  23781. if (nameRecords.length === 0) {
  23782. return;
  23783. }
  23784. if (properties.defaultEncoding === WinAnsiEncoding) {
  23785. return;
  23786. }
  23787. for (const r of nameRecords) {
  23788. if (!isWinNameRecord(r)) {
  23789. return;
  23790. }
  23791. }
  23792. const encoding = WinAnsiEncoding;
  23793. const toUnicode = [],
  23794. glyphsUnicodeMap = getGlyphsUnicode();
  23795. for (const charCode in encoding) {
  23796. const glyphName = encoding[charCode];
  23797. if (glyphName === "") {
  23798. continue;
  23799. }
  23800. const unicode = glyphsUnicodeMap[glyphName];
  23801. if (unicode === undefined) {
  23802. continue;
  23803. }
  23804. toUnicode[charCode] = String.fromCharCode(unicode);
  23805. }
  23806. if (toUnicode.length > 0) {
  23807. properties.toUnicode.amend(toUnicode);
  23808. }
  23809. }
  23810. function adjustType1ToUnicode(properties, builtInEncoding) {
  23811. if (properties.isInternalFont) {
  23812. return;
  23813. }
  23814. if (properties.hasIncludedToUnicodeMap) {
  23815. return;
  23816. }
  23817. if (builtInEncoding === properties.defaultEncoding) {
  23818. return;
  23819. }
  23820. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  23821. return;
  23822. }
  23823. const toUnicode = [],
  23824. glyphsUnicodeMap = getGlyphsUnicode();
  23825. for (const charCode in builtInEncoding) {
  23826. if (properties.hasEncoding) {
  23827. if (properties.baseEncodingName || properties.differences[charCode] !== undefined) {
  23828. continue;
  23829. }
  23830. }
  23831. const glyphName = builtInEncoding[charCode];
  23832. const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  23833. if (unicode !== -1) {
  23834. toUnicode[charCode] = String.fromCharCode(unicode);
  23835. }
  23836. }
  23837. if (toUnicode.length > 0) {
  23838. properties.toUnicode.amend(toUnicode);
  23839. }
  23840. }
  23841. function amendFallbackToUnicode(properties) {
  23842. if (!properties.fallbackToUnicode) {
  23843. return;
  23844. }
  23845. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  23846. return;
  23847. }
  23848. const toUnicode = [];
  23849. for (const charCode in properties.fallbackToUnicode) {
  23850. if (properties.toUnicode.has(charCode)) {
  23851. continue;
  23852. }
  23853. toUnicode[charCode] = properties.fallbackToUnicode[charCode];
  23854. }
  23855. if (toUnicode.length > 0) {
  23856. properties.toUnicode.amend(toUnicode);
  23857. }
  23858. }
  23859. class fonts_Glyph {
  23860. constructor(originalCharCode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  23861. this.originalCharCode = originalCharCode;
  23862. this.fontChar = fontChar;
  23863. this.unicode = unicode;
  23864. this.accent = accent;
  23865. this.width = width;
  23866. this.vmetric = vmetric;
  23867. this.operatorListId = operatorListId;
  23868. this.isSpace = isSpace;
  23869. this.isInFont = isInFont;
  23870. }
  23871. get category() {
  23872. return shadow(this, "category", getCharUnicodeCategory(this.unicode), true);
  23873. }
  23874. }
  23875. function int16(b0, b1) {
  23876. return (b0 << 8) + b1;
  23877. }
  23878. function writeSignedInt16(bytes, index, value) {
  23879. bytes[index + 1] = value;
  23880. bytes[index] = value >>> 8;
  23881. }
  23882. function signedInt16(b0, b1) {
  23883. const value = (b0 << 8) + b1;
  23884. return value & 1 << 15 ? value - 0x10000 : value;
  23885. }
  23886. function writeUint32(bytes, index, value) {
  23887. bytes[index + 3] = value & 0xff;
  23888. bytes[index + 2] = value >>> 8;
  23889. bytes[index + 1] = value >>> 16;
  23890. bytes[index] = value >>> 24;
  23891. }
  23892. function int32(b0, b1, b2, b3) {
  23893. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  23894. }
  23895. function string16(value) {
  23896. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  23897. }
  23898. function safeString16(value) {
  23899. if (value > 0x7fff) {
  23900. value = 0x7fff;
  23901. } else if (value < -0x8000) {
  23902. value = -0x8000;
  23903. }
  23904. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  23905. }
  23906. function isTrueTypeFile(file) {
  23907. const header = file.peekBytes(4);
  23908. return readUint32(header, 0) === 0x00010000 || bytesToString(header) === "true";
  23909. }
  23910. function isTrueTypeCollectionFile(file) {
  23911. const header = file.peekBytes(4);
  23912. return bytesToString(header) === "ttcf";
  23913. }
  23914. function isOpenTypeFile(file) {
  23915. const header = file.peekBytes(4);
  23916. return bytesToString(header) === "OTTO";
  23917. }
  23918. function isType1File(file) {
  23919. const header = file.peekBytes(2);
  23920. if (header[0] === 0x25 && header[1] === 0x21) {
  23921. return true;
  23922. }
  23923. if (header[0] === 0x80 && header[1] === 0x01) {
  23924. return true;
  23925. }
  23926. return false;
  23927. }
  23928. function isCFFFile(file) {
  23929. const header = file.peekBytes(4);
  23930. if (header[0] >= 1 && header[3] >= 1 && header[3] <= 4) {
  23931. return true;
  23932. }
  23933. return false;
  23934. }
  23935. function getFontFileType(file, {
  23936. type,
  23937. subtype,
  23938. composite
  23939. }) {
  23940. let fileType, fileSubtype;
  23941. if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
  23942. fileType = composite ? "CIDFontType2" : "TrueType";
  23943. } else if (isOpenTypeFile(file)) {
  23944. fileType = composite ? "CIDFontType2" : "OpenType";
  23945. } else if (isType1File(file)) {
  23946. if (composite) {
  23947. fileType = "CIDFontType0";
  23948. } else {
  23949. fileType = type === "MMType1" ? "MMType1" : "Type1";
  23950. }
  23951. } else if (isCFFFile(file)) {
  23952. if (composite) {
  23953. fileType = "CIDFontType0";
  23954. fileSubtype = "CIDFontType0C";
  23955. } else {
  23956. fileType = type === "MMType1" ? "MMType1" : "Type1";
  23957. fileSubtype = "Type1C";
  23958. }
  23959. } else {
  23960. warn("getFontFileType: Unable to detect correct font file Type/Subtype.");
  23961. fileType = type;
  23962. fileSubtype = subtype;
  23963. }
  23964. return [fileType, fileSubtype];
  23965. }
  23966. function applyStandardFontGlyphMap(map, glyphMap) {
  23967. for (const charCode in glyphMap) {
  23968. map[+charCode] = glyphMap[charCode];
  23969. }
  23970. }
  23971. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  23972. const toFontChar = [];
  23973. let unicode;
  23974. for (let i = 0, ii = encoding.length; i < ii; i++) {
  23975. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  23976. if (unicode !== -1) {
  23977. toFontChar[i] = unicode;
  23978. }
  23979. }
  23980. for (const charCode in differences) {
  23981. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  23982. if (unicode !== -1) {
  23983. toFontChar[+charCode] = unicode;
  23984. }
  23985. }
  23986. return toFontChar;
  23987. }
  23988. function isMacNameRecord(r) {
  23989. return r.platform === 1 && r.encoding === 0 && r.language === 0;
  23990. }
  23991. function isWinNameRecord(r) {
  23992. return r.platform === 3 && r.encoding === 1 && r.language === 0x409;
  23993. }
  23994. function convertCidString(charCode, cid, shouldThrow = false) {
  23995. switch (cid.length) {
  23996. case 1:
  23997. return cid.charCodeAt(0);
  23998. case 2:
  23999. return cid.charCodeAt(0) << 8 | cid.charCodeAt(1);
  24000. }
  24001. const msg = `Unsupported CID string (charCode ${charCode}): "${cid}".`;
  24002. if (shouldThrow) {
  24003. throw new FormatError(msg);
  24004. }
  24005. warn(msg);
  24006. return cid;
  24007. }
  24008. function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) {
  24009. const newMap = Object.create(null);
  24010. const toUnicodeExtraMap = new Map();
  24011. const toFontChar = [];
  24012. const usedGlyphIds = new Set();
  24013. let privateUseAreaIndex = 0;
  24014. const privateUseOffetStart = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
  24015. let nextAvailableFontCharCode = privateUseOffetStart;
  24016. let privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
  24017. const isInPrivateArea = code => PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1] || PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1];
  24018. for (let originalCharCode in charCodeToGlyphId) {
  24019. originalCharCode |= 0;
  24020. let glyphId = charCodeToGlyphId[originalCharCode];
  24021. if (!hasGlyph(glyphId)) {
  24022. continue;
  24023. }
  24024. if (nextAvailableFontCharCode > privateUseOffetEnd) {
  24025. privateUseAreaIndex++;
  24026. if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
  24027. warn("Ran out of space in font private use area.");
  24028. break;
  24029. }
  24030. nextAvailableFontCharCode = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
  24031. privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
  24032. }
  24033. const fontCharCode = nextAvailableFontCharCode++;
  24034. if (glyphId === 0) {
  24035. glyphId = newGlyphZeroId;
  24036. }
  24037. let unicode = toUnicode.get(originalCharCode);
  24038. if (typeof unicode === "string") {
  24039. unicode = unicode.codePointAt(0);
  24040. }
  24041. if (unicode && !isInPrivateArea(unicode) && !usedGlyphIds.has(glyphId)) {
  24042. toUnicodeExtraMap.set(unicode, glyphId);
  24043. usedGlyphIds.add(glyphId);
  24044. }
  24045. newMap[fontCharCode] = glyphId;
  24046. toFontChar[originalCharCode] = fontCharCode;
  24047. }
  24048. return {
  24049. toFontChar,
  24050. charCodeToGlyphId: newMap,
  24051. toUnicodeExtraMap,
  24052. nextAvailableFontCharCode
  24053. };
  24054. }
  24055. function getRanges(glyphs, toUnicodeExtraMap, numGlyphs) {
  24056. const codes = [];
  24057. for (const charCode in glyphs) {
  24058. if (glyphs[charCode] >= numGlyphs) {
  24059. continue;
  24060. }
  24061. codes.push({
  24062. fontCharCode: charCode | 0,
  24063. glyphId: glyphs[charCode]
  24064. });
  24065. }
  24066. if (toUnicodeExtraMap) {
  24067. for (const [unicode, glyphId] of toUnicodeExtraMap) {
  24068. if (glyphId >= numGlyphs) {
  24069. continue;
  24070. }
  24071. codes.push({
  24072. fontCharCode: unicode,
  24073. glyphId
  24074. });
  24075. }
  24076. }
  24077. if (codes.length === 0) {
  24078. codes.push({
  24079. fontCharCode: 0,
  24080. glyphId: 0
  24081. });
  24082. }
  24083. codes.sort(function fontGetRangesSort(a, b) {
  24084. return a.fontCharCode - b.fontCharCode;
  24085. });
  24086. const ranges = [];
  24087. const length = codes.length;
  24088. for (let n = 0; n < length;) {
  24089. const start = codes[n].fontCharCode;
  24090. const codeIndices = [codes[n].glyphId];
  24091. ++n;
  24092. let end = start;
  24093. while (n < length && end + 1 === codes[n].fontCharCode) {
  24094. codeIndices.push(codes[n].glyphId);
  24095. ++end;
  24096. ++n;
  24097. if (end === 0xffff) {
  24098. break;
  24099. }
  24100. }
  24101. ranges.push([start, end, codeIndices]);
  24102. }
  24103. return ranges;
  24104. }
  24105. function createCmapTable(glyphs, toUnicodeExtraMap, numGlyphs) {
  24106. const ranges = getRanges(glyphs, toUnicodeExtraMap, numGlyphs);
  24107. const numTables = ranges.at(-1)[1] > 0xffff ? 2 : 1;
  24108. let cmap = "\x00\x00" + string16(numTables) + "\x00\x03" + "\x00\x01" + string32(4 + numTables * 8);
  24109. let i, ii, j, jj;
  24110. for (i = ranges.length - 1; i >= 0; --i) {
  24111. if (ranges[i][0] <= 0xffff) {
  24112. break;
  24113. }
  24114. }
  24115. const bmpLength = i + 1;
  24116. if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) {
  24117. ranges[i][1] = 0xfffe;
  24118. }
  24119. const trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0;
  24120. const segCount = bmpLength + trailingRangesCount;
  24121. const searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  24122. let startCount = "";
  24123. let endCount = "";
  24124. let idDeltas = "";
  24125. let idRangeOffsets = "";
  24126. let glyphsIds = "";
  24127. let bias = 0;
  24128. let range, start, end, codes;
  24129. for (i = 0, ii = bmpLength; i < ii; i++) {
  24130. range = ranges[i];
  24131. start = range[0];
  24132. end = range[1];
  24133. startCount += string16(start);
  24134. endCount += string16(end);
  24135. codes = range[2];
  24136. let contiguous = true;
  24137. for (j = 1, jj = codes.length; j < jj; ++j) {
  24138. if (codes[j] !== codes[j - 1] + 1) {
  24139. contiguous = false;
  24140. break;
  24141. }
  24142. }
  24143. if (!contiguous) {
  24144. const offset = (segCount - i) * 2 + bias * 2;
  24145. bias += end - start + 1;
  24146. idDeltas += string16(0);
  24147. idRangeOffsets += string16(offset);
  24148. for (j = 0, jj = codes.length; j < jj; ++j) {
  24149. glyphsIds += string16(codes[j]);
  24150. }
  24151. } else {
  24152. const startCode = codes[0];
  24153. idDeltas += string16(startCode - start & 0xffff);
  24154. idRangeOffsets += string16(0);
  24155. }
  24156. }
  24157. if (trailingRangesCount > 0) {
  24158. endCount += "\xFF\xFF";
  24159. startCount += "\xFF\xFF";
  24160. idDeltas += "\x00\x01";
  24161. idRangeOffsets += "\x00\x00";
  24162. }
  24163. const format314 = "\x00\x00" + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + "\x00\x00" + startCount + idDeltas + idRangeOffsets + glyphsIds;
  24164. let format31012 = "";
  24165. let header31012 = "";
  24166. if (numTables > 1) {
  24167. cmap += "\x00\x03" + "\x00\x0A" + string32(4 + numTables * 8 + 4 + format314.length);
  24168. format31012 = "";
  24169. for (i = 0, ii = ranges.length; i < ii; i++) {
  24170. range = ranges[i];
  24171. start = range[0];
  24172. codes = range[2];
  24173. let code = codes[0];
  24174. for (j = 1, jj = codes.length; j < jj; ++j) {
  24175. if (codes[j] !== codes[j - 1] + 1) {
  24176. end = range[0] + j - 1;
  24177. format31012 += string32(start) + string32(end) + string32(code);
  24178. start = end + 1;
  24179. code = codes[j];
  24180. }
  24181. }
  24182. format31012 += string32(start) + string32(range[1]) + string32(code);
  24183. }
  24184. header31012 = "\x00\x0C" + "\x00\x00" + string32(format31012.length + 16) + "\x00\x00\x00\x00" + string32(format31012.length / 12);
  24185. }
  24186. return cmap + "\x00\x04" + string16(format314.length + 4) + format314 + header31012 + format31012;
  24187. }
  24188. function validateOS2Table(os2, file) {
  24189. file.pos = (file.start || 0) + os2.offset;
  24190. const version = file.getUint16();
  24191. file.skip(60);
  24192. const selection = file.getUint16();
  24193. if (version < 4 && selection & 0x0300) {
  24194. return false;
  24195. }
  24196. const firstChar = file.getUint16();
  24197. const lastChar = file.getUint16();
  24198. if (firstChar > lastChar) {
  24199. return false;
  24200. }
  24201. file.skip(6);
  24202. const usWinAscent = file.getUint16();
  24203. if (usWinAscent === 0) {
  24204. return false;
  24205. }
  24206. os2.data[8] = os2.data[9] = 0;
  24207. return true;
  24208. }
  24209. function createOS2Table(properties, charstrings, override) {
  24210. override ||= {
  24211. unitsPerEm: 0,
  24212. yMax: 0,
  24213. yMin: 0,
  24214. ascent: 0,
  24215. descent: 0
  24216. };
  24217. let ulUnicodeRange1 = 0;
  24218. let ulUnicodeRange2 = 0;
  24219. let ulUnicodeRange3 = 0;
  24220. let ulUnicodeRange4 = 0;
  24221. let firstCharIndex = null;
  24222. let lastCharIndex = 0;
  24223. let position = -1;
  24224. if (charstrings) {
  24225. for (let code in charstrings) {
  24226. code |= 0;
  24227. if (firstCharIndex > code || !firstCharIndex) {
  24228. firstCharIndex = code;
  24229. }
  24230. if (lastCharIndex < code) {
  24231. lastCharIndex = code;
  24232. }
  24233. position = getUnicodeRangeFor(code, position);
  24234. if (position < 32) {
  24235. ulUnicodeRange1 |= 1 << position;
  24236. } else if (position < 64) {
  24237. ulUnicodeRange2 |= 1 << position - 32;
  24238. } else if (position < 96) {
  24239. ulUnicodeRange3 |= 1 << position - 64;
  24240. } else if (position < 123) {
  24241. ulUnicodeRange4 |= 1 << position - 96;
  24242. } else {
  24243. throw new FormatError("Unicode ranges Bits > 123 are reserved for internal usage");
  24244. }
  24245. }
  24246. if (lastCharIndex > 0xffff) {
  24247. lastCharIndex = 0xffff;
  24248. }
  24249. } else {
  24250. firstCharIndex = 0;
  24251. lastCharIndex = 255;
  24252. }
  24253. const bbox = properties.bbox || [0, 0, 0, 0];
  24254. const unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  24255. const scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  24256. const typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  24257. let typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  24258. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  24259. typoDescent = -typoDescent;
  24260. }
  24261. const winAscent = override.yMax || typoAscent;
  24262. const winDescent = -override.yMin || -typoDescent;
  24263. return "\x00\x03" + "\x02\x24" + "\x01\xF4" + "\x00\x05" + "\x00\x00" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x00\x8C" + "\x02\x8A" + "\x02\xBB" + "\x00\x00" + "\x01\xDF" + "\x00\x31" + "\x01\x02" + "\x00\x00" + "\x00\x00\x06" + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + "\x00\x00\x00\x00\x00\x00" + string32(ulUnicodeRange1) + string32(ulUnicodeRange2) + string32(ulUnicodeRange3) + string32(ulUnicodeRange4) + "\x2A\x32\x31\x2A" + string16(properties.italicAngle ? 1 : 0) + string16(firstCharIndex || properties.firstChar) + string16(lastCharIndex || properties.lastChar) + string16(typoAscent) + string16(typoDescent) + "\x00\x64" + string16(winAscent) + string16(winDescent) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + string16(properties.xHeight) + string16(properties.capHeight) + string16(0) + string16(firstCharIndex || properties.firstChar) + "\x00\x03";
  24264. }
  24265. function createPostTable(properties) {
  24266. const angle = Math.floor(properties.italicAngle * 2 ** 16);
  24267. return "\x00\x03\x00\x00" + string32(angle) + "\x00\x00" + "\x00\x00" + string32(properties.fixedPitch ? 1 : 0) + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00" + "\x00\x00\x00\x00";
  24268. }
  24269. function createPostscriptName(name) {
  24270. return name.replaceAll(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63);
  24271. }
  24272. function createNameTable(name, proto) {
  24273. if (!proto) {
  24274. proto = [[], []];
  24275. }
  24276. const strings = [proto[0][0] || "Original licence", proto[0][1] || name, proto[0][2] || "Unknown", proto[0][3] || "uniqueID", proto[0][4] || name, proto[0][5] || "Version 0.11", proto[0][6] || createPostscriptName(name), proto[0][7] || "Unknown", proto[0][8] || "Unknown", proto[0][9] || "Unknown"];
  24277. const stringsUnicode = [];
  24278. let i, ii, j, jj, str;
  24279. for (i = 0, ii = strings.length; i < ii; i++) {
  24280. str = proto[1][i] || strings[i];
  24281. const strBufUnicode = [];
  24282. for (j = 0, jj = str.length; j < jj; j++) {
  24283. strBufUnicode.push(string16(str.charCodeAt(j)));
  24284. }
  24285. stringsUnicode.push(strBufUnicode.join(""));
  24286. }
  24287. const names = [strings, stringsUnicode];
  24288. const platforms = ["\x00\x01", "\x00\x03"];
  24289. const encodings = ["\x00\x00", "\x00\x01"];
  24290. const languages = ["\x00\x00", "\x04\x09"];
  24291. const namesRecordCount = strings.length * platforms.length;
  24292. let nameTable = "\x00\x00" + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);
  24293. let strOffset = 0;
  24294. for (i = 0, ii = platforms.length; i < ii; i++) {
  24295. const strs = names[i];
  24296. for (j = 0, jj = strs.length; j < jj; j++) {
  24297. str = strs[j];
  24298. const nameRecord = platforms[i] + encodings[i] + languages[i] + string16(j) + string16(str.length) + string16(strOffset);
  24299. nameTable += nameRecord;
  24300. strOffset += str.length;
  24301. }
  24302. }
  24303. nameTable += strings.join("") + stringsUnicode.join("");
  24304. return nameTable;
  24305. }
  24306. class Font {
  24307. constructor(name, file, properties) {
  24308. this.name = name;
  24309. this.psName = null;
  24310. this.mimetype = null;
  24311. this.disableFontFace = false;
  24312. this.loadedName = properties.loadedName;
  24313. this.isType3Font = properties.isType3Font;
  24314. this.missingFile = false;
  24315. this.cssFontInfo = properties.cssFontInfo;
  24316. this._charsCache = Object.create(null);
  24317. this._glyphCache = Object.create(null);
  24318. let isSerifFont = !!(properties.flags & FontFlags.Serif);
  24319. if (!isSerifFont && !properties.isSimulatedFlags) {
  24320. const baseName = name.replaceAll(/[,_]/g, "-").split("-")[0],
  24321. serifFonts = getSerifFonts();
  24322. for (const namePart of baseName.split("+")) {
  24323. if (serifFonts[namePart]) {
  24324. isSerifFont = true;
  24325. break;
  24326. }
  24327. }
  24328. }
  24329. this.isSerifFont = isSerifFont;
  24330. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  24331. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  24332. let {
  24333. type,
  24334. subtype
  24335. } = properties;
  24336. this.type = type;
  24337. this.subtype = subtype;
  24338. this.systemFontInfo = properties.systemFontInfo;
  24339. const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/);
  24340. this.isInvalidPDFjsFont = !!matches;
  24341. if (this.isInvalidPDFjsFont) {
  24342. this.fallbackName = matches[1];
  24343. } else if (this.isMonospace) {
  24344. this.fallbackName = "monospace";
  24345. } else if (this.isSerifFont) {
  24346. this.fallbackName = "serif";
  24347. } else {
  24348. this.fallbackName = "sans-serif";
  24349. }
  24350. if (this.systemFontInfo?.guessFallback) {
  24351. this.systemFontInfo.guessFallback = false;
  24352. this.systemFontInfo.css += `,${this.fallbackName}`;
  24353. }
  24354. this.differences = properties.differences;
  24355. this.widths = properties.widths;
  24356. this.defaultWidth = properties.defaultWidth;
  24357. this.composite = properties.composite;
  24358. this.cMap = properties.cMap;
  24359. this.capHeight = properties.capHeight / PDF_GLYPH_SPACE_UNITS;
  24360. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  24361. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  24362. this.lineHeight = this.ascent - this.descent;
  24363. this.fontMatrix = properties.fontMatrix;
  24364. this.bbox = properties.bbox;
  24365. this.defaultEncoding = properties.defaultEncoding;
  24366. this.toUnicode = properties.toUnicode;
  24367. this.toFontChar = [];
  24368. if (properties.type === "Type3") {
  24369. for (let charCode = 0; charCode < 256; charCode++) {
  24370. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  24371. }
  24372. return;
  24373. }
  24374. this.cidEncoding = properties.cidEncoding || "";
  24375. this.vertical = !!properties.vertical;
  24376. if (this.vertical) {
  24377. this.vmetrics = properties.vmetrics;
  24378. this.defaultVMetrics = properties.defaultVMetrics;
  24379. }
  24380. if (!file || file.isEmpty) {
  24381. if (file) {
  24382. warn('Font file is empty in "' + name + '" (' + this.loadedName + ")");
  24383. }
  24384. this.fallbackToSystemFont(properties);
  24385. return;
  24386. }
  24387. [type, subtype] = getFontFileType(file, properties);
  24388. if (type !== this.type || subtype !== this.subtype) {
  24389. info("Inconsistent font file Type/SubType, expected: " + `${this.type}/${this.subtype} but found: ${type}/${subtype}.`);
  24390. }
  24391. let data;
  24392. try {
  24393. switch (type) {
  24394. case "MMType1":
  24395. info("MMType1 font (" + name + "), falling back to Type1.");
  24396. case "Type1":
  24397. case "CIDFontType0":
  24398. this.mimetype = "font/opentype";
  24399. const cff = subtype === "Type1C" || subtype === "CIDFontType0C" ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  24400. adjustWidths(properties);
  24401. data = this.convert(name, cff, properties);
  24402. break;
  24403. case "OpenType":
  24404. case "TrueType":
  24405. case "CIDFontType2":
  24406. this.mimetype = "font/opentype";
  24407. data = this.checkAndRepair(name, file, properties);
  24408. if (this.isOpenType) {
  24409. adjustWidths(properties);
  24410. type = "OpenType";
  24411. }
  24412. break;
  24413. default:
  24414. throw new FormatError(`Font ${type} is not supported`);
  24415. }
  24416. } catch (e) {
  24417. warn(e);
  24418. this.fallbackToSystemFont(properties);
  24419. return;
  24420. }
  24421. amendFallbackToUnicode(properties);
  24422. this.data = data;
  24423. this.type = type;
  24424. this.subtype = subtype;
  24425. this.fontMatrix = properties.fontMatrix;
  24426. this.widths = properties.widths;
  24427. this.defaultWidth = properties.defaultWidth;
  24428. this.toUnicode = properties.toUnicode;
  24429. this.seacMap = properties.seacMap;
  24430. }
  24431. get renderer() {
  24432. const renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  24433. return shadow(this, "renderer", renderer);
  24434. }
  24435. exportData(extraProperties = false) {
  24436. const exportDataProperties = extraProperties ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES] : EXPORT_DATA_PROPERTIES;
  24437. const data = Object.create(null);
  24438. let property, value;
  24439. for (property of exportDataProperties) {
  24440. value = this[property];
  24441. if (value !== undefined) {
  24442. data[property] = value;
  24443. }
  24444. }
  24445. return data;
  24446. }
  24447. fallbackToSystemFont(properties) {
  24448. this.missingFile = true;
  24449. const {
  24450. name,
  24451. type
  24452. } = this;
  24453. let fontName = normalizeFontName(name);
  24454. const stdFontMap = getStdFontMap(),
  24455. nonStdFontMap = getNonStdFontMap();
  24456. const isStandardFont = !!stdFontMap[fontName];
  24457. const isMappedToStandardFont = !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  24458. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  24459. const fontBasicMetricsMap = getFontBasicMetrics();
  24460. const metrics = fontBasicMetricsMap[fontName];
  24461. if (metrics) {
  24462. if (isNaN(this.ascent)) {
  24463. this.ascent = metrics.ascent / PDF_GLYPH_SPACE_UNITS;
  24464. }
  24465. if (isNaN(this.descent)) {
  24466. this.descent = metrics.descent / PDF_GLYPH_SPACE_UNITS;
  24467. }
  24468. if (isNaN(this.capHeight)) {
  24469. this.capHeight = metrics.capHeight / PDF_GLYPH_SPACE_UNITS;
  24470. }
  24471. }
  24472. this.bold = /bold/gi.test(fontName);
  24473. this.italic = /oblique|italic/gi.test(fontName);
  24474. this.black = /Black/g.test(name);
  24475. const isNarrow = /Narrow/g.test(name);
  24476. this.remeasure = (!isStandardFont || isNarrow) && Object.keys(this.widths).length > 0;
  24477. if ((isStandardFont || isMappedToStandardFont) && type === "CIDFontType2" && this.cidEncoding.startsWith("Identity-")) {
  24478. const cidToGidMap = properties.cidToGidMap;
  24479. const map = [];
  24480. applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
  24481. if (/Arial-?Black/i.test(name)) {
  24482. applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack());
  24483. } else if (/Calibri/i.test(name)) {
  24484. applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri());
  24485. }
  24486. if (cidToGidMap) {
  24487. for (const charCode in map) {
  24488. const cid = map[charCode];
  24489. if (cidToGidMap[cid] !== undefined) {
  24490. map[+charCode] = cidToGidMap[cid];
  24491. }
  24492. }
  24493. if (cidToGidMap.length !== this.toUnicode.length && properties.hasIncludedToUnicodeMap && this.toUnicode instanceof IdentityToUnicodeMap) {
  24494. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  24495. const cid = map[charCode];
  24496. if (cidToGidMap[cid] === undefined) {
  24497. map[+charCode] = unicodeCharCode;
  24498. }
  24499. });
  24500. }
  24501. }
  24502. if (!(this.toUnicode instanceof IdentityToUnicodeMap)) {
  24503. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  24504. map[+charCode] = unicodeCharCode;
  24505. });
  24506. }
  24507. this.toFontChar = map;
  24508. this.toUnicode = new ToUnicodeMap(map);
  24509. } else if (/Symbol/i.test(fontName)) {
  24510. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), this.differences);
  24511. } else if (/Dingbats/i.test(fontName)) {
  24512. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), this.differences);
  24513. } else if (isStandardFont) {
  24514. const map = buildToFontChar(this.defaultEncoding, getGlyphsUnicode(), this.differences);
  24515. if (type === "CIDFontType2" && !this.cidEncoding.startsWith("Identity-") && !(this.toUnicode instanceof IdentityToUnicodeMap)) {
  24516. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  24517. map[+charCode] = unicodeCharCode;
  24518. });
  24519. }
  24520. this.toFontChar = map;
  24521. } else {
  24522. const glyphsUnicodeMap = getGlyphsUnicode();
  24523. const map = [];
  24524. this.toUnicode.forEach((charCode, unicodeCharCode) => {
  24525. if (!this.composite) {
  24526. const glyphName = this.differences[charCode] || this.defaultEncoding[charCode];
  24527. const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  24528. if (unicode !== -1) {
  24529. unicodeCharCode = unicode;
  24530. }
  24531. }
  24532. map[+charCode] = unicodeCharCode;
  24533. });
  24534. if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
  24535. if (/Tahoma|Verdana/i.test(name)) {
  24536. applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
  24537. }
  24538. }
  24539. this.toFontChar = map;
  24540. }
  24541. amendFallbackToUnicode(properties);
  24542. this.loadedName = fontName.split("-")[0];
  24543. }
  24544. checkAndRepair(name, font, properties) {
  24545. const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
  24546. function readTables(file, numTables) {
  24547. const tables = Object.create(null);
  24548. tables["OS/2"] = null;
  24549. tables.cmap = null;
  24550. tables.head = null;
  24551. tables.hhea = null;
  24552. tables.hmtx = null;
  24553. tables.maxp = null;
  24554. tables.name = null;
  24555. tables.post = null;
  24556. for (let i = 0; i < numTables; i++) {
  24557. const table = readTableEntry(file);
  24558. if (!VALID_TABLES.includes(table.tag)) {
  24559. continue;
  24560. }
  24561. if (table.length === 0) {
  24562. continue;
  24563. }
  24564. tables[table.tag] = table;
  24565. }
  24566. return tables;
  24567. }
  24568. function readTableEntry(file) {
  24569. const tag = file.getString(4);
  24570. const checksum = file.getInt32() >>> 0;
  24571. const offset = file.getInt32() >>> 0;
  24572. const length = file.getInt32() >>> 0;
  24573. const previousPosition = file.pos;
  24574. file.pos = file.start || 0;
  24575. file.skip(offset);
  24576. const data = file.getBytes(length);
  24577. file.pos = previousPosition;
  24578. if (tag === "head") {
  24579. data[8] = data[9] = data[10] = data[11] = 0;
  24580. data[17] |= 0x20;
  24581. }
  24582. return {
  24583. tag,
  24584. checksum,
  24585. length,
  24586. offset,
  24587. data
  24588. };
  24589. }
  24590. function readOpenTypeHeader(ttf) {
  24591. return {
  24592. version: ttf.getString(4),
  24593. numTables: ttf.getUint16(),
  24594. searchRange: ttf.getUint16(),
  24595. entrySelector: ttf.getUint16(),
  24596. rangeShift: ttf.getUint16()
  24597. };
  24598. }
  24599. function readTrueTypeCollectionHeader(ttc) {
  24600. const ttcTag = ttc.getString(4);
  24601. assert(ttcTag === "ttcf", "Must be a TrueType Collection font.");
  24602. const majorVersion = ttc.getUint16();
  24603. const minorVersion = ttc.getUint16();
  24604. const numFonts = ttc.getInt32() >>> 0;
  24605. const offsetTable = [];
  24606. for (let i = 0; i < numFonts; i++) {
  24607. offsetTable.push(ttc.getInt32() >>> 0);
  24608. }
  24609. const header = {
  24610. ttcTag,
  24611. majorVersion,
  24612. minorVersion,
  24613. numFonts,
  24614. offsetTable
  24615. };
  24616. switch (majorVersion) {
  24617. case 1:
  24618. return header;
  24619. case 2:
  24620. header.dsigTag = ttc.getInt32() >>> 0;
  24621. header.dsigLength = ttc.getInt32() >>> 0;
  24622. header.dsigOffset = ttc.getInt32() >>> 0;
  24623. return header;
  24624. }
  24625. throw new FormatError(`Invalid TrueType Collection majorVersion: ${majorVersion}.`);
  24626. }
  24627. function readTrueTypeCollectionData(ttc, fontName) {
  24628. const {
  24629. numFonts,
  24630. offsetTable
  24631. } = readTrueTypeCollectionHeader(ttc);
  24632. const fontNameParts = fontName.split("+");
  24633. let fallbackData;
  24634. for (let i = 0; i < numFonts; i++) {
  24635. ttc.pos = (ttc.start || 0) + offsetTable[i];
  24636. const potentialHeader = readOpenTypeHeader(ttc);
  24637. const potentialTables = readTables(ttc, potentialHeader.numTables);
  24638. if (!potentialTables.name) {
  24639. throw new FormatError('TrueType Collection font must contain a "name" table.');
  24640. }
  24641. const [nameTable] = readNameTable(potentialTables.name);
  24642. for (let j = 0, jj = nameTable.length; j < jj; j++) {
  24643. for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
  24644. const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, "");
  24645. if (!nameEntry) {
  24646. continue;
  24647. }
  24648. if (nameEntry === fontName) {
  24649. return {
  24650. header: potentialHeader,
  24651. tables: potentialTables
  24652. };
  24653. }
  24654. if (fontNameParts.length < 2) {
  24655. continue;
  24656. }
  24657. for (const part of fontNameParts) {
  24658. if (nameEntry === part) {
  24659. fallbackData = {
  24660. name: part,
  24661. header: potentialHeader,
  24662. tables: potentialTables
  24663. };
  24664. }
  24665. }
  24666. }
  24667. }
  24668. }
  24669. if (fallbackData) {
  24670. warn(`TrueType Collection does not contain "${fontName}" font, ` + `falling back to "${fallbackData.name}" font instead.`);
  24671. return {
  24672. header: fallbackData.header,
  24673. tables: fallbackData.tables
  24674. };
  24675. }
  24676. throw new FormatError(`TrueType Collection does not contain "${fontName}" font.`);
  24677. }
  24678. function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
  24679. if (!cmap) {
  24680. warn("No cmap table available.");
  24681. return {
  24682. platformId: -1,
  24683. encodingId: -1,
  24684. mappings: [],
  24685. hasShortCmap: false
  24686. };
  24687. }
  24688. let segment;
  24689. let start = (file.start || 0) + cmap.offset;
  24690. file.pos = start;
  24691. file.skip(2);
  24692. const numTables = file.getUint16();
  24693. let potentialTable;
  24694. let canBreak = false;
  24695. for (let i = 0; i < numTables; i++) {
  24696. const platformId = file.getUint16();
  24697. const encodingId = file.getUint16();
  24698. const offset = file.getInt32() >>> 0;
  24699. let useTable = false;
  24700. if (potentialTable?.platformId === platformId && potentialTable?.encodingId === encodingId) {
  24701. continue;
  24702. }
  24703. if (platformId === 0 && (encodingId === 0 || encodingId === 1 || encodingId === 3)) {
  24704. useTable = true;
  24705. } else if (platformId === 1 && encodingId === 0) {
  24706. useTable = true;
  24707. } else if (platformId === 3 && encodingId === 1 && (hasEncoding || !potentialTable)) {
  24708. useTable = true;
  24709. if (!isSymbolicFont) {
  24710. canBreak = true;
  24711. }
  24712. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  24713. useTable = true;
  24714. let correctlySorted = true;
  24715. if (i < numTables - 1) {
  24716. const nextBytes = file.peekBytes(2),
  24717. nextPlatformId = int16(nextBytes[0], nextBytes[1]);
  24718. if (nextPlatformId < platformId) {
  24719. correctlySorted = false;
  24720. }
  24721. }
  24722. if (correctlySorted) {
  24723. canBreak = true;
  24724. }
  24725. }
  24726. if (useTable) {
  24727. potentialTable = {
  24728. platformId,
  24729. encodingId,
  24730. offset
  24731. };
  24732. }
  24733. if (canBreak) {
  24734. break;
  24735. }
  24736. }
  24737. if (potentialTable) {
  24738. file.pos = start + potentialTable.offset;
  24739. }
  24740. if (!potentialTable || file.peekByte() === -1) {
  24741. warn("Could not find a preferred cmap table.");
  24742. return {
  24743. platformId: -1,
  24744. encodingId: -1,
  24745. mappings: [],
  24746. hasShortCmap: false
  24747. };
  24748. }
  24749. const format = file.getUint16();
  24750. let hasShortCmap = false;
  24751. const mappings = [];
  24752. let j, glyphId;
  24753. if (format === 0) {
  24754. file.skip(2 + 2);
  24755. for (j = 0; j < 256; j++) {
  24756. const index = file.getByte();
  24757. if (!index) {
  24758. continue;
  24759. }
  24760. mappings.push({
  24761. charCode: j,
  24762. glyphId: index
  24763. });
  24764. }
  24765. hasShortCmap = true;
  24766. } else if (format === 2) {
  24767. file.skip(2 + 2);
  24768. const subHeaderKeys = [];
  24769. let maxSubHeaderKey = 0;
  24770. for (let i = 0; i < 256; i++) {
  24771. const subHeaderKey = file.getUint16() >> 3;
  24772. subHeaderKeys.push(subHeaderKey);
  24773. maxSubHeaderKey = Math.max(subHeaderKey, maxSubHeaderKey);
  24774. }
  24775. const subHeaders = [];
  24776. for (let i = 0; i <= maxSubHeaderKey; i++) {
  24777. subHeaders.push({
  24778. firstCode: file.getUint16(),
  24779. entryCount: file.getUint16(),
  24780. idDelta: signedInt16(file.getByte(), file.getByte()),
  24781. idRangePos: file.pos + file.getUint16()
  24782. });
  24783. }
  24784. for (let i = 0; i < 256; i++) {
  24785. if (subHeaderKeys[i] === 0) {
  24786. file.pos = subHeaders[0].idRangePos + 2 * i;
  24787. glyphId = file.getUint16();
  24788. mappings.push({
  24789. charCode: i,
  24790. glyphId
  24791. });
  24792. } else {
  24793. const s = subHeaders[subHeaderKeys[i]];
  24794. for (j = 0; j < s.entryCount; j++) {
  24795. const charCode = (i << 8) + j + s.firstCode;
  24796. file.pos = s.idRangePos + 2 * j;
  24797. glyphId = file.getUint16();
  24798. if (glyphId !== 0) {
  24799. glyphId = (glyphId + s.idDelta) % 65536;
  24800. }
  24801. mappings.push({
  24802. charCode,
  24803. glyphId
  24804. });
  24805. }
  24806. }
  24807. }
  24808. } else if (format === 4) {
  24809. file.skip(2 + 2);
  24810. const segCount = file.getUint16() >> 1;
  24811. file.skip(6);
  24812. const segments = [];
  24813. let segIndex;
  24814. for (segIndex = 0; segIndex < segCount; segIndex++) {
  24815. segments.push({
  24816. end: file.getUint16()
  24817. });
  24818. }
  24819. file.skip(2);
  24820. for (segIndex = 0; segIndex < segCount; segIndex++) {
  24821. segments[segIndex].start = file.getUint16();
  24822. }
  24823. for (segIndex = 0; segIndex < segCount; segIndex++) {
  24824. segments[segIndex].delta = file.getUint16();
  24825. }
  24826. let offsetsCount = 0,
  24827. offsetIndex;
  24828. for (segIndex = 0; segIndex < segCount; segIndex++) {
  24829. segment = segments[segIndex];
  24830. const rangeOffset = file.getUint16();
  24831. if (!rangeOffset) {
  24832. segment.offsetIndex = -1;
  24833. continue;
  24834. }
  24835. offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  24836. segment.offsetIndex = offsetIndex;
  24837. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  24838. }
  24839. const offsets = [];
  24840. for (j = 0; j < offsetsCount; j++) {
  24841. offsets.push(file.getUint16());
  24842. }
  24843. for (segIndex = 0; segIndex < segCount; segIndex++) {
  24844. segment = segments[segIndex];
  24845. start = segment.start;
  24846. const end = segment.end;
  24847. const delta = segment.delta;
  24848. offsetIndex = segment.offsetIndex;
  24849. for (j = start; j <= end; j++) {
  24850. if (j === 0xffff) {
  24851. continue;
  24852. }
  24853. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  24854. glyphId = glyphId + delta & 0xffff;
  24855. mappings.push({
  24856. charCode: j,
  24857. glyphId
  24858. });
  24859. }
  24860. }
  24861. } else if (format === 6) {
  24862. file.skip(2 + 2);
  24863. const firstCode = file.getUint16();
  24864. const entryCount = file.getUint16();
  24865. for (j = 0; j < entryCount; j++) {
  24866. glyphId = file.getUint16();
  24867. const charCode = firstCode + j;
  24868. mappings.push({
  24869. charCode,
  24870. glyphId
  24871. });
  24872. }
  24873. } else if (format === 12) {
  24874. file.skip(2 + 4 + 4);
  24875. const nGroups = file.getInt32() >>> 0;
  24876. for (j = 0; j < nGroups; j++) {
  24877. const startCharCode = file.getInt32() >>> 0;
  24878. const endCharCode = file.getInt32() >>> 0;
  24879. let glyphCode = file.getInt32() >>> 0;
  24880. for (let charCode = startCharCode; charCode <= endCharCode; charCode++) {
  24881. mappings.push({
  24882. charCode,
  24883. glyphId: glyphCode++
  24884. });
  24885. }
  24886. }
  24887. } else {
  24888. warn("cmap table has unsupported format: " + format);
  24889. return {
  24890. platformId: -1,
  24891. encodingId: -1,
  24892. mappings: [],
  24893. hasShortCmap: false
  24894. };
  24895. }
  24896. mappings.sort(function (a, b) {
  24897. return a.charCode - b.charCode;
  24898. });
  24899. for (let i = 1; i < mappings.length; i++) {
  24900. if (mappings[i - 1].charCode === mappings[i].charCode) {
  24901. mappings.splice(i, 1);
  24902. i--;
  24903. }
  24904. }
  24905. return {
  24906. platformId: potentialTable.platformId,
  24907. encodingId: potentialTable.encodingId,
  24908. mappings,
  24909. hasShortCmap
  24910. };
  24911. }
  24912. function sanitizeMetrics(file, header, metrics, headTable, numGlyphs, dupFirstEntry) {
  24913. if (!header) {
  24914. if (metrics) {
  24915. metrics.data = null;
  24916. }
  24917. return;
  24918. }
  24919. file.pos = (file.start || 0) + header.offset;
  24920. file.pos += 4;
  24921. file.pos += 2;
  24922. file.pos += 2;
  24923. file.pos += 2;
  24924. file.pos += 2;
  24925. file.pos += 2;
  24926. file.pos += 2;
  24927. file.pos += 2;
  24928. file.pos += 2;
  24929. file.pos += 2;
  24930. const caretOffset = file.getUint16();
  24931. file.pos += 8;
  24932. file.pos += 2;
  24933. let numOfMetrics = file.getUint16();
  24934. if (caretOffset !== 0) {
  24935. const macStyle = int16(headTable.data[44], headTable.data[45]);
  24936. if (!(macStyle & 2)) {
  24937. header.data[22] = 0;
  24938. header.data[23] = 0;
  24939. }
  24940. }
  24941. if (numOfMetrics > numGlyphs) {
  24942. info(`The numOfMetrics (${numOfMetrics}) should not be ` + `greater than the numGlyphs (${numGlyphs}).`);
  24943. numOfMetrics = numGlyphs;
  24944. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  24945. header.data[35] = numOfMetrics & 0x00ff;
  24946. }
  24947. const numOfSidebearings = numGlyphs - numOfMetrics;
  24948. const numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  24949. if (numMissing > 0) {
  24950. const entries = new Uint8Array(metrics.length + numMissing * 2);
  24951. entries.set(metrics.data);
  24952. if (dupFirstEntry) {
  24953. entries[metrics.length] = metrics.data[2];
  24954. entries[metrics.length + 1] = metrics.data[3];
  24955. }
  24956. metrics.data = entries;
  24957. }
  24958. }
  24959. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  24960. const glyphProfile = {
  24961. length: 0,
  24962. sizeOfInstructions: 0
  24963. };
  24964. if (sourceStart < 0 || sourceStart >= source.length || sourceEnd > source.length || sourceEnd - sourceStart <= 12) {
  24965. return glyphProfile;
  24966. }
  24967. const glyf = source.subarray(sourceStart, sourceEnd);
  24968. const xMin = signedInt16(glyf[2], glyf[3]);
  24969. const yMin = signedInt16(glyf[4], glyf[5]);
  24970. const xMax = signedInt16(glyf[6], glyf[7]);
  24971. const yMax = signedInt16(glyf[8], glyf[9]);
  24972. if (xMin > xMax) {
  24973. writeSignedInt16(glyf, 2, xMax);
  24974. writeSignedInt16(glyf, 6, xMin);
  24975. }
  24976. if (yMin > yMax) {
  24977. writeSignedInt16(glyf, 4, yMax);
  24978. writeSignedInt16(glyf, 8, yMin);
  24979. }
  24980. const contoursCount = signedInt16(glyf[0], glyf[1]);
  24981. if (contoursCount < 0) {
  24982. if (contoursCount < -1) {
  24983. return glyphProfile;
  24984. }
  24985. dest.set(glyf, destStart);
  24986. glyphProfile.length = glyf.length;
  24987. return glyphProfile;
  24988. }
  24989. let i,
  24990. j = 10,
  24991. flagsCount = 0;
  24992. for (i = 0; i < contoursCount; i++) {
  24993. const endPoint = glyf[j] << 8 | glyf[j + 1];
  24994. flagsCount = endPoint + 1;
  24995. j += 2;
  24996. }
  24997. const instructionsStart = j;
  24998. const instructionsLength = glyf[j] << 8 | glyf[j + 1];
  24999. glyphProfile.sizeOfInstructions = instructionsLength;
  25000. j += 2 + instructionsLength;
  25001. const instructionsEnd = j;
  25002. let coordinatesLength = 0;
  25003. for (i = 0; i < flagsCount; i++) {
  25004. const flag = glyf[j++];
  25005. if (flag & 0xc0) {
  25006. glyf[j - 1] = flag & 0x3f;
  25007. }
  25008. let xLength = 2;
  25009. if (flag & 2) {
  25010. xLength = 1;
  25011. } else if (flag & 16) {
  25012. xLength = 0;
  25013. }
  25014. let yLength = 2;
  25015. if (flag & 4) {
  25016. yLength = 1;
  25017. } else if (flag & 32) {
  25018. yLength = 0;
  25019. }
  25020. const xyLength = xLength + yLength;
  25021. coordinatesLength += xyLength;
  25022. if (flag & 8) {
  25023. const repeat = glyf[j++];
  25024. if (repeat === 0) {
  25025. glyf[j - 1] ^= 8;
  25026. }
  25027. i += repeat;
  25028. coordinatesLength += repeat * xyLength;
  25029. }
  25030. }
  25031. if (coordinatesLength === 0) {
  25032. return glyphProfile;
  25033. }
  25034. let glyphDataLength = j + coordinatesLength;
  25035. if (glyphDataLength > glyf.length) {
  25036. return glyphProfile;
  25037. }
  25038. if (!hintsValid && instructionsLength > 0) {
  25039. dest.set(glyf.subarray(0, instructionsStart), destStart);
  25040. dest.set([0, 0], destStart + instructionsStart);
  25041. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  25042. glyphDataLength -= instructionsLength;
  25043. if (glyf.length - glyphDataLength > 3) {
  25044. glyphDataLength = glyphDataLength + 3 & ~3;
  25045. }
  25046. glyphProfile.length = glyphDataLength;
  25047. return glyphProfile;
  25048. }
  25049. if (glyf.length - glyphDataLength > 3) {
  25050. glyphDataLength = glyphDataLength + 3 & ~3;
  25051. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  25052. glyphProfile.length = glyphDataLength;
  25053. return glyphProfile;
  25054. }
  25055. dest.set(glyf, destStart);
  25056. glyphProfile.length = glyf.length;
  25057. return glyphProfile;
  25058. }
  25059. function sanitizeHead(head, numGlyphs, locaLength) {
  25060. const data = head.data;
  25061. const version = int32(data[0], data[1], data[2], data[3]);
  25062. if (version >> 16 !== 1) {
  25063. info("Attempting to fix invalid version in head table: " + version);
  25064. data[0] = 0;
  25065. data[1] = 1;
  25066. data[2] = 0;
  25067. data[3] = 0;
  25068. }
  25069. const indexToLocFormat = int16(data[50], data[51]);
  25070. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  25071. info("Attempting to fix invalid indexToLocFormat in head table: " + indexToLocFormat);
  25072. const numGlyphsPlusOne = numGlyphs + 1;
  25073. if (locaLength === numGlyphsPlusOne << 1) {
  25074. data[50] = 0;
  25075. data[51] = 0;
  25076. } else if (locaLength === numGlyphsPlusOne << 2) {
  25077. data[50] = 0;
  25078. data[51] = 1;
  25079. } else {
  25080. throw new FormatError("Could not fix indexToLocFormat: " + indexToLocFormat);
  25081. }
  25082. }
  25083. }
  25084. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions) {
  25085. let itemSize, itemDecode, itemEncode;
  25086. if (isGlyphLocationsLong) {
  25087. itemSize = 4;
  25088. itemDecode = function fontItemDecodeLong(data, offset) {
  25089. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  25090. };
  25091. itemEncode = function fontItemEncodeLong(data, offset, value) {
  25092. data[offset] = value >>> 24 & 0xff;
  25093. data[offset + 1] = value >> 16 & 0xff;
  25094. data[offset + 2] = value >> 8 & 0xff;
  25095. data[offset + 3] = value & 0xff;
  25096. };
  25097. } else {
  25098. itemSize = 2;
  25099. itemDecode = function fontItemDecode(data, offset) {
  25100. return data[offset] << 9 | data[offset + 1] << 1;
  25101. };
  25102. itemEncode = function fontItemEncode(data, offset, value) {
  25103. data[offset] = value >> 9 & 0xff;
  25104. data[offset + 1] = value >> 1 & 0xff;
  25105. };
  25106. }
  25107. const numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
  25108. const locaDataSize = itemSize * (1 + numGlyphsOut);
  25109. const locaData = new Uint8Array(locaDataSize);
  25110. locaData.set(loca.data.subarray(0, locaDataSize));
  25111. loca.data = locaData;
  25112. const oldGlyfData = glyf.data;
  25113. const oldGlyfDataLength = oldGlyfData.length;
  25114. const newGlyfData = new Uint8Array(oldGlyfDataLength);
  25115. let i, j;
  25116. const locaEntries = [];
  25117. for (i = 0, j = 0; i < numGlyphs + 1; i++, j += itemSize) {
  25118. let offset = itemDecode(locaData, j);
  25119. if (offset > oldGlyfDataLength) {
  25120. offset = oldGlyfDataLength;
  25121. }
  25122. locaEntries.push({
  25123. index: i,
  25124. offset,
  25125. endOffset: 0
  25126. });
  25127. }
  25128. locaEntries.sort((a, b) => {
  25129. return a.offset - b.offset;
  25130. });
  25131. for (i = 0; i < numGlyphs; i++) {
  25132. locaEntries[i].endOffset = locaEntries[i + 1].offset;
  25133. }
  25134. locaEntries.sort((a, b) => {
  25135. return a.index - b.index;
  25136. });
  25137. for (i = 0; i < numGlyphs; i++) {
  25138. const {
  25139. offset,
  25140. endOffset
  25141. } = locaEntries[i];
  25142. if (offset !== 0 || endOffset !== 0) {
  25143. break;
  25144. }
  25145. const nextOffset = locaEntries[i + 1].offset;
  25146. if (nextOffset === 0) {
  25147. continue;
  25148. }
  25149. locaEntries[i].endOffset = nextOffset;
  25150. break;
  25151. }
  25152. const missingGlyphs = Object.create(null);
  25153. let writeOffset = 0;
  25154. itemEncode(locaData, 0, writeOffset);
  25155. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  25156. const glyphProfile = sanitizeGlyph(oldGlyfData, locaEntries[i].offset, locaEntries[i].endOffset, newGlyfData, writeOffset, hintsValid);
  25157. const newLength = glyphProfile.length;
  25158. if (newLength === 0) {
  25159. missingGlyphs[i] = true;
  25160. }
  25161. if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) {
  25162. maxSizeOfInstructions = glyphProfile.sizeOfInstructions;
  25163. }
  25164. writeOffset += newLength;
  25165. itemEncode(locaData, j, writeOffset);
  25166. }
  25167. if (writeOffset === 0) {
  25168. const simpleGlyph = new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  25169. for (i = 0, j = itemSize; i < numGlyphsOut; i++, j += itemSize) {
  25170. itemEncode(locaData, j, simpleGlyph.length);
  25171. }
  25172. glyf.data = simpleGlyph;
  25173. } else if (dupFirstEntry) {
  25174. const firstEntryLength = itemDecode(locaData, itemSize);
  25175. if (newGlyfData.length > firstEntryLength + writeOffset) {
  25176. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  25177. } else {
  25178. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  25179. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  25180. }
  25181. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  25182. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  25183. } else {
  25184. glyf.data = newGlyfData.subarray(0, writeOffset);
  25185. }
  25186. return {
  25187. missingGlyphs,
  25188. maxSizeOfInstructions
  25189. };
  25190. }
  25191. function readPostScriptTable(post, propertiesObj, maxpNumGlyphs) {
  25192. const start = (font.start || 0) + post.offset;
  25193. font.pos = start;
  25194. const length = post.length,
  25195. end = start + length;
  25196. const version = font.getInt32();
  25197. font.skip(28);
  25198. let glyphNames;
  25199. let valid = true;
  25200. let i;
  25201. switch (version) {
  25202. case 0x00010000:
  25203. glyphNames = MacStandardGlyphOrdering;
  25204. break;
  25205. case 0x00020000:
  25206. const numGlyphs = font.getUint16();
  25207. if (numGlyphs !== maxpNumGlyphs) {
  25208. valid = false;
  25209. break;
  25210. }
  25211. const glyphNameIndexes = [];
  25212. for (i = 0; i < numGlyphs; ++i) {
  25213. const index = font.getUint16();
  25214. if (index >= 32768) {
  25215. valid = false;
  25216. break;
  25217. }
  25218. glyphNameIndexes.push(index);
  25219. }
  25220. if (!valid) {
  25221. break;
  25222. }
  25223. const customNames = [],
  25224. strBuf = [];
  25225. while (font.pos < end) {
  25226. const stringLength = font.getByte();
  25227. strBuf.length = stringLength;
  25228. for (i = 0; i < stringLength; ++i) {
  25229. strBuf[i] = String.fromCharCode(font.getByte());
  25230. }
  25231. customNames.push(strBuf.join(""));
  25232. }
  25233. glyphNames = [];
  25234. for (i = 0; i < numGlyphs; ++i) {
  25235. const j = glyphNameIndexes[i];
  25236. if (j < 258) {
  25237. glyphNames.push(MacStandardGlyphOrdering[j]);
  25238. continue;
  25239. }
  25240. glyphNames.push(customNames[j - 258]);
  25241. }
  25242. break;
  25243. case 0x00030000:
  25244. break;
  25245. default:
  25246. warn("Unknown/unsupported post table version " + version);
  25247. valid = false;
  25248. if (propertiesObj.defaultEncoding) {
  25249. glyphNames = propertiesObj.defaultEncoding;
  25250. }
  25251. break;
  25252. }
  25253. propertiesObj.glyphNames = glyphNames;
  25254. return valid;
  25255. }
  25256. function readNameTable(nameTable) {
  25257. const start = (font.start || 0) + nameTable.offset;
  25258. font.pos = start;
  25259. const names = [[], []],
  25260. records = [];
  25261. const length = nameTable.length,
  25262. end = start + length;
  25263. const format = font.getUint16();
  25264. const FORMAT_0_HEADER_LENGTH = 6;
  25265. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  25266. return [names, records];
  25267. }
  25268. const numRecords = font.getUint16();
  25269. const stringsStart = font.getUint16();
  25270. const NAME_RECORD_LENGTH = 12;
  25271. let i, ii;
  25272. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  25273. const r = {
  25274. platform: font.getUint16(),
  25275. encoding: font.getUint16(),
  25276. language: font.getUint16(),
  25277. name: font.getUint16(),
  25278. length: font.getUint16(),
  25279. offset: font.getUint16()
  25280. };
  25281. if (isMacNameRecord(r) || isWinNameRecord(r)) {
  25282. records.push(r);
  25283. }
  25284. }
  25285. for (i = 0, ii = records.length; i < ii; i++) {
  25286. const record = records[i];
  25287. if (record.length <= 0) {
  25288. continue;
  25289. }
  25290. const pos = start + stringsStart + record.offset;
  25291. if (pos + record.length > end) {
  25292. continue;
  25293. }
  25294. font.pos = pos;
  25295. const nameIndex = record.name;
  25296. if (record.encoding) {
  25297. let str = "";
  25298. for (let j = 0, jj = record.length; j < jj; j += 2) {
  25299. str += String.fromCharCode(font.getUint16());
  25300. }
  25301. names[1][nameIndex] = str;
  25302. } else {
  25303. names[0][nameIndex] = font.getString(record.length);
  25304. }
  25305. }
  25306. return [names, records];
  25307. }
  25308. const TTOpsStackDeltas = [0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1, 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1, 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2, 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1, -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  25309. function sanitizeTTProgram(table, ttContext) {
  25310. let data = table.data;
  25311. let i = 0,
  25312. j,
  25313. n,
  25314. b,
  25315. funcId,
  25316. pc,
  25317. lastEndf = 0,
  25318. lastDeff = 0;
  25319. const stack = [];
  25320. const callstack = [];
  25321. const functionsCalled = [];
  25322. let tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  25323. let inFDEF = false,
  25324. ifLevel = 0,
  25325. inELSE = 0;
  25326. for (let ii = data.length; i < ii;) {
  25327. const op = data[i++];
  25328. if (op === 0x40) {
  25329. n = data[i++];
  25330. if (inFDEF || inELSE) {
  25331. i += n;
  25332. } else {
  25333. for (j = 0; j < n; j++) {
  25334. stack.push(data[i++]);
  25335. }
  25336. }
  25337. } else if (op === 0x41) {
  25338. n = data[i++];
  25339. if (inFDEF || inELSE) {
  25340. i += n * 2;
  25341. } else {
  25342. for (j = 0; j < n; j++) {
  25343. b = data[i++];
  25344. stack.push(b << 8 | data[i++]);
  25345. }
  25346. }
  25347. } else if ((op & 0xf8) === 0xb0) {
  25348. n = op - 0xb0 + 1;
  25349. if (inFDEF || inELSE) {
  25350. i += n;
  25351. } else {
  25352. for (j = 0; j < n; j++) {
  25353. stack.push(data[i++]);
  25354. }
  25355. }
  25356. } else if ((op & 0xf8) === 0xb8) {
  25357. n = op - 0xb8 + 1;
  25358. if (inFDEF || inELSE) {
  25359. i += n * 2;
  25360. } else {
  25361. for (j = 0; j < n; j++) {
  25362. b = data[i++];
  25363. stack.push(b << 8 | data[i++]);
  25364. }
  25365. }
  25366. } else if (op === 0x2b && !tooComplexToFollowFunctions) {
  25367. if (!inFDEF && !inELSE) {
  25368. funcId = stack.at(-1);
  25369. if (isNaN(funcId)) {
  25370. info("TT: CALL empty stack (or invalid entry).");
  25371. } else {
  25372. ttContext.functionsUsed[funcId] = true;
  25373. if (funcId in ttContext.functionsStackDeltas) {
  25374. const newStackLength = stack.length + ttContext.functionsStackDeltas[funcId];
  25375. if (newStackLength < 0) {
  25376. warn("TT: CALL invalid functions stack delta.");
  25377. ttContext.hintsValid = false;
  25378. return;
  25379. }
  25380. stack.length = newStackLength;
  25381. } else if (funcId in ttContext.functionsDefined && !functionsCalled.includes(funcId)) {
  25382. callstack.push({
  25383. data,
  25384. i,
  25385. stackTop: stack.length - 1
  25386. });
  25387. functionsCalled.push(funcId);
  25388. pc = ttContext.functionsDefined[funcId];
  25389. if (!pc) {
  25390. warn("TT: CALL non-existent function");
  25391. ttContext.hintsValid = false;
  25392. return;
  25393. }
  25394. data = pc.data;
  25395. i = pc.i;
  25396. }
  25397. }
  25398. }
  25399. } else if (op === 0x2c && !tooComplexToFollowFunctions) {
  25400. if (inFDEF || inELSE) {
  25401. warn("TT: nested FDEFs not allowed");
  25402. tooComplexToFollowFunctions = true;
  25403. }
  25404. inFDEF = true;
  25405. lastDeff = i;
  25406. funcId = stack.pop();
  25407. ttContext.functionsDefined[funcId] = {
  25408. data,
  25409. i
  25410. };
  25411. } else if (op === 0x2d) {
  25412. if (inFDEF) {
  25413. inFDEF = false;
  25414. lastEndf = i;
  25415. } else {
  25416. pc = callstack.pop();
  25417. if (!pc) {
  25418. warn("TT: ENDF bad stack");
  25419. ttContext.hintsValid = false;
  25420. return;
  25421. }
  25422. funcId = functionsCalled.pop();
  25423. data = pc.data;
  25424. i = pc.i;
  25425. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  25426. }
  25427. } else if (op === 0x89) {
  25428. if (inFDEF || inELSE) {
  25429. warn("TT: nested IDEFs not allowed");
  25430. tooComplexToFollowFunctions = true;
  25431. }
  25432. inFDEF = true;
  25433. lastDeff = i;
  25434. } else if (op === 0x58) {
  25435. ++ifLevel;
  25436. } else if (op === 0x1b) {
  25437. inELSE = ifLevel;
  25438. } else if (op === 0x59) {
  25439. if (inELSE === ifLevel) {
  25440. inELSE = 0;
  25441. }
  25442. --ifLevel;
  25443. } else if (op === 0x1c) {
  25444. if (!inFDEF && !inELSE) {
  25445. const offset = stack.at(-1);
  25446. if (offset > 0) {
  25447. i += offset - 1;
  25448. }
  25449. }
  25450. }
  25451. if (!inFDEF && !inELSE) {
  25452. let stackDelta = 0;
  25453. if (op <= 0x8e) {
  25454. stackDelta = TTOpsStackDeltas[op];
  25455. } else if (op >= 0xc0 && op <= 0xdf) {
  25456. stackDelta = -1;
  25457. } else if (op >= 0xe0) {
  25458. stackDelta = -2;
  25459. }
  25460. if (op >= 0x71 && op <= 0x75) {
  25461. n = stack.pop();
  25462. if (!isNaN(n)) {
  25463. stackDelta = -n * 2;
  25464. }
  25465. }
  25466. while (stackDelta < 0 && stack.length > 0) {
  25467. stack.pop();
  25468. stackDelta++;
  25469. }
  25470. while (stackDelta > 0) {
  25471. stack.push(NaN);
  25472. stackDelta--;
  25473. }
  25474. }
  25475. }
  25476. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  25477. const content = [data];
  25478. if (i > data.length) {
  25479. content.push(new Uint8Array(i - data.length));
  25480. }
  25481. if (lastDeff > lastEndf) {
  25482. warn("TT: complementing a missing function tail");
  25483. content.push(new Uint8Array([0x22, 0x2d]));
  25484. }
  25485. foldTTTable(table, content);
  25486. }
  25487. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  25488. if (ttContext.tooComplexToFollowFunctions) {
  25489. return;
  25490. }
  25491. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  25492. warn("TT: more functions defined than expected");
  25493. ttContext.hintsValid = false;
  25494. return;
  25495. }
  25496. for (let j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  25497. if (j > maxFunctionDefs) {
  25498. warn("TT: invalid function id: " + j);
  25499. ttContext.hintsValid = false;
  25500. return;
  25501. }
  25502. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  25503. warn("TT: undefined function: " + j);
  25504. ttContext.hintsValid = false;
  25505. return;
  25506. }
  25507. }
  25508. }
  25509. function foldTTTable(table, content) {
  25510. if (content.length > 1) {
  25511. let newLength = 0;
  25512. let j, jj;
  25513. for (j = 0, jj = content.length; j < jj; j++) {
  25514. newLength += content[j].length;
  25515. }
  25516. newLength = newLength + 3 & ~3;
  25517. const result = new Uint8Array(newLength);
  25518. let pos = 0;
  25519. for (j = 0, jj = content.length; j < jj; j++) {
  25520. result.set(content[j], pos);
  25521. pos += content[j].length;
  25522. }
  25523. table.data = result;
  25524. table.length = newLength;
  25525. }
  25526. }
  25527. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  25528. const ttContext = {
  25529. functionsDefined: [],
  25530. functionsUsed: [],
  25531. functionsStackDeltas: [],
  25532. tooComplexToFollowFunctions: false,
  25533. hintsValid: true
  25534. };
  25535. if (fpgm) {
  25536. sanitizeTTProgram(fpgm, ttContext);
  25537. }
  25538. if (prep) {
  25539. sanitizeTTProgram(prep, ttContext);
  25540. }
  25541. if (fpgm) {
  25542. checkInvalidFunctions(ttContext, maxFunctionDefs);
  25543. }
  25544. if (cvt && cvt.length & 1) {
  25545. const cvtData = new Uint8Array(cvt.length + 1);
  25546. cvtData.set(cvt.data);
  25547. cvt.data = cvtData;
  25548. }
  25549. return ttContext.hintsValid;
  25550. }
  25551. font = new Stream(new Uint8Array(font.getBytes()));
  25552. let header, tables;
  25553. if (isTrueTypeCollectionFile(font)) {
  25554. const ttcData = readTrueTypeCollectionData(font, this.name);
  25555. header = ttcData.header;
  25556. tables = ttcData.tables;
  25557. } else {
  25558. header = readOpenTypeHeader(font);
  25559. tables = readTables(font, header.numTables);
  25560. }
  25561. let cff, cffFile;
  25562. const isTrueType = !tables["CFF "];
  25563. if (!isTrueType) {
  25564. const isComposite = properties.composite && (properties.cidToGidMap?.length > 0 || !(properties.cMap instanceof IdentityCMap));
  25565. if (header.version === "OTTO" && !isComposite || !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  25566. cffFile = new Stream(tables["CFF "].data);
  25567. cff = new CFFFont(cffFile, properties);
  25568. adjustWidths(properties);
  25569. return this.convert(name, cff, properties);
  25570. }
  25571. delete tables.glyf;
  25572. delete tables.loca;
  25573. delete tables.fpgm;
  25574. delete tables.prep;
  25575. delete tables["cvt "];
  25576. this.isOpenType = true;
  25577. } else {
  25578. if (!tables.loca) {
  25579. throw new FormatError('Required "loca" table is not found');
  25580. }
  25581. if (!tables.glyf) {
  25582. warn('Required "glyf" table is not found -- trying to recover.');
  25583. tables.glyf = {
  25584. tag: "glyf",
  25585. data: new Uint8Array(0)
  25586. };
  25587. }
  25588. this.isOpenType = false;
  25589. }
  25590. if (!tables.maxp) {
  25591. throw new FormatError('Required "maxp" table is not found');
  25592. }
  25593. font.pos = (font.start || 0) + tables.maxp.offset;
  25594. let version = font.getInt32();
  25595. const numGlyphs = font.getUint16();
  25596. if (version !== 0x00010000 && version !== 0x00005000) {
  25597. if (tables.maxp.length === 6) {
  25598. version = 0x0005000;
  25599. } else if (tables.maxp.length >= 32) {
  25600. version = 0x00010000;
  25601. } else {
  25602. throw new FormatError(`"maxp" table has a wrong version number`);
  25603. }
  25604. writeUint32(tables.maxp.data, 0, version);
  25605. }
  25606. if (properties.scaleFactors?.length === numGlyphs && isTrueType) {
  25607. const {
  25608. scaleFactors
  25609. } = properties;
  25610. const isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
  25611. const glyphs = new GlyfTable({
  25612. glyfTable: tables.glyf.data,
  25613. isGlyphLocationsLong,
  25614. locaTable: tables.loca.data,
  25615. numGlyphs
  25616. });
  25617. glyphs.scale(scaleFactors);
  25618. const {
  25619. glyf,
  25620. loca,
  25621. isLocationLong
  25622. } = glyphs.write();
  25623. tables.glyf.data = glyf;
  25624. tables.loca.data = loca;
  25625. if (isLocationLong !== !!isGlyphLocationsLong) {
  25626. tables.head.data[50] = 0;
  25627. tables.head.data[51] = isLocationLong ? 1 : 0;
  25628. }
  25629. const metrics = tables.hmtx.data;
  25630. for (let i = 0; i < numGlyphs; i++) {
  25631. const j = 4 * i;
  25632. const advanceWidth = Math.round(scaleFactors[i] * int16(metrics[j], metrics[j + 1]));
  25633. metrics[j] = advanceWidth >> 8 & 0xff;
  25634. metrics[j + 1] = advanceWidth & 0xff;
  25635. const lsb = Math.round(scaleFactors[i] * signedInt16(metrics[j + 2], metrics[j + 3]));
  25636. writeSignedInt16(metrics, j + 2, lsb);
  25637. }
  25638. }
  25639. let numGlyphsOut = numGlyphs + 1;
  25640. let dupFirstEntry = true;
  25641. if (numGlyphsOut > 0xffff) {
  25642. dupFirstEntry = false;
  25643. numGlyphsOut = numGlyphs;
  25644. warn("Not enough space in glyfs to duplicate first glyph.");
  25645. }
  25646. let maxFunctionDefs = 0;
  25647. let maxSizeOfInstructions = 0;
  25648. if (version >= 0x00010000 && tables.maxp.length >= 32) {
  25649. font.pos += 8;
  25650. const maxZones = font.getUint16();
  25651. if (maxZones > 2) {
  25652. tables.maxp.data[14] = 0;
  25653. tables.maxp.data[15] = 2;
  25654. }
  25655. font.pos += 4;
  25656. maxFunctionDefs = font.getUint16();
  25657. font.pos += 4;
  25658. maxSizeOfInstructions = font.getUint16();
  25659. }
  25660. tables.maxp.data[4] = numGlyphsOut >> 8;
  25661. tables.maxp.data[5] = numGlyphsOut & 255;
  25662. const hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep, tables["cvt "], maxFunctionDefs);
  25663. if (!hintsValid) {
  25664. delete tables.fpgm;
  25665. delete tables.prep;
  25666. delete tables["cvt "];
  25667. }
  25668. sanitizeMetrics(font, tables.hhea, tables.hmtx, tables.head, numGlyphsOut, dupFirstEntry);
  25669. if (!tables.head) {
  25670. throw new FormatError('Required "head" table is not found');
  25671. }
  25672. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  25673. let missingGlyphs = Object.create(null);
  25674. if (isTrueType) {
  25675. const isGlyphLocationsLong = int16(tables.head.data[50], tables.head.data[51]);
  25676. const glyphsInfo = sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);
  25677. missingGlyphs = glyphsInfo.missingGlyphs;
  25678. if (version >= 0x00010000 && tables.maxp.length >= 32) {
  25679. tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
  25680. tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255;
  25681. }
  25682. }
  25683. if (!tables.hhea) {
  25684. throw new FormatError('Required "hhea" table is not found');
  25685. }
  25686. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  25687. tables.hhea.data[10] = 0xff;
  25688. tables.hhea.data[11] = 0xff;
  25689. }
  25690. const metricsOverride = {
  25691. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  25692. yMax: signedInt16(tables.head.data[42], tables.head.data[43]),
  25693. yMin: signedInt16(tables.head.data[38], tables.head.data[39]),
  25694. ascent: signedInt16(tables.hhea.data[4], tables.hhea.data[5]),
  25695. descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7]),
  25696. lineGap: signedInt16(tables.hhea.data[8], tables.hhea.data[9])
  25697. };
  25698. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  25699. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  25700. this.lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm;
  25701. if (this.cssFontInfo?.lineHeight) {
  25702. this.lineHeight = this.cssFontInfo.metrics.lineHeight;
  25703. this.lineGap = this.cssFontInfo.metrics.lineGap;
  25704. } else {
  25705. this.lineHeight = this.ascent - this.descent + this.lineGap;
  25706. }
  25707. if (tables.post) {
  25708. readPostScriptTable(tables.post, properties, numGlyphs);
  25709. }
  25710. tables.post = {
  25711. tag: "post",
  25712. data: createPostTable(properties)
  25713. };
  25714. const charCodeToGlyphId = [];
  25715. function hasGlyph(glyphId) {
  25716. return !missingGlyphs[glyphId];
  25717. }
  25718. if (properties.composite) {
  25719. const cidToGidMap = properties.cidToGidMap || [];
  25720. const isCidToGidMapEmpty = cidToGidMap.length === 0;
  25721. properties.cMap.forEach(function (charCode, cid) {
  25722. if (typeof cid === "string") {
  25723. cid = convertCidString(charCode, cid, true);
  25724. }
  25725. if (cid > 0xffff) {
  25726. throw new FormatError("Max size of CID is 65,535");
  25727. }
  25728. let glyphId = -1;
  25729. if (isCidToGidMapEmpty) {
  25730. glyphId = cid;
  25731. } else if (cidToGidMap[cid] !== undefined) {
  25732. glyphId = cidToGidMap[cid];
  25733. }
  25734. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) {
  25735. charCodeToGlyphId[charCode] = glyphId;
  25736. }
  25737. });
  25738. } else {
  25739. const cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont, properties.hasEncoding);
  25740. const cmapPlatformId = cmapTable.platformId;
  25741. const cmapEncodingId = cmapTable.encodingId;
  25742. const cmapMappings = cmapTable.mappings;
  25743. let baseEncoding = [],
  25744. forcePostTable = false;
  25745. if (properties.hasEncoding && (properties.baseEncodingName === "MacRomanEncoding" || properties.baseEncodingName === "WinAnsiEncoding")) {
  25746. baseEncoding = getEncoding(properties.baseEncodingName);
  25747. }
  25748. if (properties.hasEncoding && !this.isSymbolicFont && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0)) {
  25749. const glyphsUnicodeMap = getGlyphsUnicode();
  25750. for (let charCode = 0; charCode < 256; charCode++) {
  25751. let glyphName;
  25752. if (this.differences[charCode] !== undefined) {
  25753. glyphName = this.differences[charCode];
  25754. } else if (baseEncoding.length && baseEncoding[charCode] !== "") {
  25755. glyphName = baseEncoding[charCode];
  25756. } else {
  25757. glyphName = StandardEncoding[charCode];
  25758. }
  25759. if (!glyphName) {
  25760. continue;
  25761. }
  25762. const standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  25763. let unicodeOrCharCode;
  25764. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  25765. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  25766. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  25767. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  25768. }
  25769. if (unicodeOrCharCode === undefined) {
  25770. if (!properties.glyphNames && properties.hasIncludedToUnicodeMap && !(this.toUnicode instanceof IdentityToUnicodeMap)) {
  25771. const unicode = this.toUnicode.get(charCode);
  25772. if (unicode) {
  25773. unicodeOrCharCode = unicode.codePointAt(0);
  25774. }
  25775. }
  25776. if (unicodeOrCharCode === undefined) {
  25777. continue;
  25778. }
  25779. }
  25780. for (const mapping of cmapMappings) {
  25781. if (mapping.charCode !== unicodeOrCharCode) {
  25782. continue;
  25783. }
  25784. charCodeToGlyphId[charCode] = mapping.glyphId;
  25785. break;
  25786. }
  25787. }
  25788. } else if (cmapPlatformId === 0) {
  25789. for (const mapping of cmapMappings) {
  25790. charCodeToGlyphId[mapping.charCode] = mapping.glyphId;
  25791. }
  25792. forcePostTable = true;
  25793. } else {
  25794. for (const mapping of cmapMappings) {
  25795. let charCode = mapping.charCode;
  25796. if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) {
  25797. charCode &= 0xff;
  25798. }
  25799. charCodeToGlyphId[charCode] = mapping.glyphId;
  25800. }
  25801. }
  25802. if (properties.glyphNames && (baseEncoding.length || this.differences.length)) {
  25803. for (let i = 0; i < 256; ++i) {
  25804. if (!forcePostTable && charCodeToGlyphId[i] !== undefined) {
  25805. continue;
  25806. }
  25807. const glyphName = this.differences[i] || baseEncoding[i];
  25808. if (!glyphName) {
  25809. continue;
  25810. }
  25811. const glyphId = properties.glyphNames.indexOf(glyphName);
  25812. if (glyphId > 0 && hasGlyph(glyphId)) {
  25813. charCodeToGlyphId[i] = glyphId;
  25814. }
  25815. }
  25816. }
  25817. }
  25818. if (charCodeToGlyphId.length === 0) {
  25819. charCodeToGlyphId[0] = 0;
  25820. }
  25821. let glyphZeroId = numGlyphsOut - 1;
  25822. if (!dupFirstEntry) {
  25823. glyphZeroId = 0;
  25824. }
  25825. if (!properties.cssFontInfo) {
  25826. const newMapping = adjustMapping(charCodeToGlyphId, hasGlyph, glyphZeroId, this.toUnicode);
  25827. this.toFontChar = newMapping.toFontChar;
  25828. tables.cmap = {
  25829. tag: "cmap",
  25830. data: createCmapTable(newMapping.charCodeToGlyphId, newMapping.toUnicodeExtraMap, numGlyphsOut)
  25831. };
  25832. if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
  25833. tables["OS/2"] = {
  25834. tag: "OS/2",
  25835. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  25836. };
  25837. }
  25838. }
  25839. if (!isTrueType) {
  25840. try {
  25841. cffFile = new Stream(tables["CFF "].data);
  25842. const parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  25843. cff = parser.parse();
  25844. cff.duplicateFirstGlyph();
  25845. const compiler = new CFFCompiler(cff);
  25846. tables["CFF "].data = compiler.compile();
  25847. } catch {
  25848. warn("Failed to compile font " + properties.loadedName);
  25849. }
  25850. }
  25851. if (!tables.name) {
  25852. tables.name = {
  25853. tag: "name",
  25854. data: createNameTable(this.name)
  25855. };
  25856. } else {
  25857. const [namePrototype, nameRecords] = readNameTable(tables.name);
  25858. tables.name.data = createNameTable(name, namePrototype);
  25859. this.psName = namePrototype[0][6] || null;
  25860. if (!properties.composite) {
  25861. adjustTrueTypeToUnicode(properties, this.isSymbolicFont, nameRecords);
  25862. }
  25863. }
  25864. const builder = new OpenTypeFileBuilder(header.version);
  25865. for (const tableTag in tables) {
  25866. builder.addTable(tableTag, tables[tableTag].data);
  25867. }
  25868. return builder.toArray();
  25869. }
  25870. convert(fontName, font, properties) {
  25871. properties.fixedPitch = false;
  25872. if (properties.builtInEncoding) {
  25873. adjustType1ToUnicode(properties, properties.builtInEncoding);
  25874. }
  25875. let glyphZeroId = 1;
  25876. if (font instanceof CFFFont) {
  25877. glyphZeroId = font.numGlyphs - 1;
  25878. }
  25879. const mapping = font.getGlyphMapping(properties);
  25880. let newMapping = null;
  25881. let newCharCodeToGlyphId = mapping;
  25882. let toUnicodeExtraMap = null;
  25883. if (!properties.cssFontInfo) {
  25884. newMapping = adjustMapping(mapping, font.hasGlyphId.bind(font), glyphZeroId, this.toUnicode);
  25885. this.toFontChar = newMapping.toFontChar;
  25886. newCharCodeToGlyphId = newMapping.charCodeToGlyphId;
  25887. toUnicodeExtraMap = newMapping.toUnicodeExtraMap;
  25888. }
  25889. const numGlyphs = font.numGlyphs;
  25890. function getCharCodes(charCodeToGlyphId, glyphId) {
  25891. let charCodes = null;
  25892. for (const charCode in charCodeToGlyphId) {
  25893. if (glyphId === charCodeToGlyphId[charCode]) {
  25894. (charCodes ||= []).push(charCode | 0);
  25895. }
  25896. }
  25897. return charCodes;
  25898. }
  25899. function createCharCode(charCodeToGlyphId, glyphId) {
  25900. for (const charCode in charCodeToGlyphId) {
  25901. if (glyphId === charCodeToGlyphId[charCode]) {
  25902. return charCode | 0;
  25903. }
  25904. }
  25905. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  25906. return newMapping.nextAvailableFontCharCode++;
  25907. }
  25908. const seacs = font.seacs;
  25909. if (newMapping && SEAC_ANALYSIS_ENABLED && seacs?.length) {
  25910. const matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  25911. const charset = font.getCharset();
  25912. const seacMap = Object.create(null);
  25913. for (let glyphId in seacs) {
  25914. glyphId |= 0;
  25915. const seac = seacs[glyphId];
  25916. const baseGlyphName = StandardEncoding[seac[2]];
  25917. const accentGlyphName = StandardEncoding[seac[3]];
  25918. const baseGlyphId = charset.indexOf(baseGlyphName);
  25919. const accentGlyphId = charset.indexOf(accentGlyphName);
  25920. if (baseGlyphId < 0 || accentGlyphId < 0) {
  25921. continue;
  25922. }
  25923. const accentOffset = {
  25924. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  25925. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  25926. };
  25927. const charCodes = getCharCodes(mapping, glyphId);
  25928. if (!charCodes) {
  25929. continue;
  25930. }
  25931. for (const charCode of charCodes) {
  25932. const charCodeToGlyphId = newMapping.charCodeToGlyphId;
  25933. const baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  25934. const accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  25935. seacMap[charCode] = {
  25936. baseFontCharCode,
  25937. accentFontCharCode,
  25938. accentOffset
  25939. };
  25940. }
  25941. }
  25942. properties.seacMap = seacMap;
  25943. }
  25944. const unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  25945. const builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F");
  25946. builder.addTable("CFF ", font.data);
  25947. builder.addTable("OS/2", createOS2Table(properties, newCharCodeToGlyphId));
  25948. builder.addTable("cmap", createCmapTable(newCharCodeToGlyphId, toUnicodeExtraMap, numGlyphs));
  25949. builder.addTable("head", "\x00\x01\x00\x00" + "\x00\x00\x10\x00" + "\x00\x00\x00\x00" + "\x5F\x0F\x3C\xF5" + "\x00\x00" + safeString16(unitsPerEm) + "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + "\x00\x00" + safeString16(properties.descent) + "\x0F\xFF" + safeString16(properties.ascent) + string16(properties.italicAngle ? 2 : 0) + "\x00\x11" + "\x00\x00" + "\x00\x00" + "\x00\x00");
  25950. builder.addTable("hhea", "\x00\x01\x00\x00" + safeString16(properties.ascent) + safeString16(properties.descent) + "\x00\x00" + "\xFF\xFF" + "\x00\x00" + "\x00\x00" + "\x00\x00" + safeString16(properties.capHeight) + safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + "\x00\x00" + string16(numGlyphs));
  25951. builder.addTable("hmtx", function fontFieldsHmtx() {
  25952. const charstrings = font.charstrings;
  25953. const cffWidths = font.cff ? font.cff.widths : null;
  25954. let hmtx = "\x00\x00\x00\x00";
  25955. for (let i = 1, ii = numGlyphs; i < ii; i++) {
  25956. let width = 0;
  25957. if (charstrings) {
  25958. const charstring = charstrings[i - 1];
  25959. width = "width" in charstring ? charstring.width : 0;
  25960. } else if (cffWidths) {
  25961. width = Math.ceil(cffWidths[i] || 0);
  25962. }
  25963. hmtx += string16(width) + string16(0);
  25964. }
  25965. return hmtx;
  25966. }());
  25967. builder.addTable("maxp", "\x00\x00\x50\x00" + string16(numGlyphs));
  25968. builder.addTable("name", createNameTable(fontName));
  25969. builder.addTable("post", createPostTable(properties));
  25970. return builder.toArray();
  25971. }
  25972. get spaceWidth() {
  25973. const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
  25974. let width;
  25975. for (const glyphName of possibleSpaceReplacements) {
  25976. if (glyphName in this.widths) {
  25977. width = this.widths[glyphName];
  25978. break;
  25979. }
  25980. const glyphsUnicodeMap = getGlyphsUnicode();
  25981. const glyphUnicode = glyphsUnicodeMap[glyphName];
  25982. let charcode = 0;
  25983. if (this.composite && this.cMap.contains(glyphUnicode)) {
  25984. charcode = this.cMap.lookup(glyphUnicode);
  25985. if (typeof charcode === "string") {
  25986. charcode = convertCidString(glyphUnicode, charcode);
  25987. }
  25988. }
  25989. if (!charcode && this.toUnicode) {
  25990. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  25991. }
  25992. if (charcode <= 0) {
  25993. charcode = glyphUnicode;
  25994. }
  25995. width = this.widths[charcode];
  25996. if (width) {
  25997. break;
  25998. }
  25999. }
  26000. return shadow(this, "spaceWidth", width || this.defaultWidth);
  26001. }
  26002. _charToGlyph(charcode, isSpace = false) {
  26003. let glyph = this._glyphCache[charcode];
  26004. if (glyph?.isSpace === isSpace) {
  26005. return glyph;
  26006. }
  26007. let fontCharCode, width, operatorListId;
  26008. let widthCode = charcode;
  26009. if (this.cMap?.contains(charcode)) {
  26010. widthCode = this.cMap.lookup(charcode);
  26011. if (typeof widthCode === "string") {
  26012. widthCode = convertCidString(charcode, widthCode);
  26013. }
  26014. }
  26015. width = this.widths[widthCode];
  26016. if (typeof width !== "number") {
  26017. width = this.defaultWidth;
  26018. }
  26019. const vmetric = this.vmetrics?.[widthCode];
  26020. let unicode = this.toUnicode.get(charcode) || charcode;
  26021. if (typeof unicode === "number") {
  26022. unicode = String.fromCharCode(unicode);
  26023. }
  26024. let isInFont = this.toFontChar[charcode] !== undefined;
  26025. fontCharCode = this.toFontChar[charcode] || charcode;
  26026. if (this.missingFile) {
  26027. const glyphName = this.differences[charcode] || this.defaultEncoding[charcode];
  26028. if ((glyphName === ".notdef" || glyphName === "") && this.type === "Type1") {
  26029. fontCharCode = 0x20;
  26030. }
  26031. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  26032. }
  26033. if (this.isType3Font) {
  26034. operatorListId = fontCharCode;
  26035. }
  26036. let accent = null;
  26037. if (this.seacMap?.[charcode]) {
  26038. isInFont = true;
  26039. const seac = this.seacMap[charcode];
  26040. fontCharCode = seac.baseFontCharCode;
  26041. accent = {
  26042. fontChar: String.fromCodePoint(seac.accentFontCharCode),
  26043. offset: seac.accentOffset
  26044. };
  26045. }
  26046. let fontChar = "";
  26047. if (typeof fontCharCode === "number") {
  26048. if (fontCharCode <= 0x10ffff) {
  26049. fontChar = String.fromCodePoint(fontCharCode);
  26050. } else {
  26051. warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
  26052. }
  26053. }
  26054. glyph = new fonts_Glyph(charcode, fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  26055. return this._glyphCache[charcode] = glyph;
  26056. }
  26057. charsToGlyphs(chars) {
  26058. let glyphs = this._charsCache[chars];
  26059. if (glyphs) {
  26060. return glyphs;
  26061. }
  26062. glyphs = [];
  26063. if (this.cMap) {
  26064. const c = Object.create(null),
  26065. ii = chars.length;
  26066. let i = 0;
  26067. while (i < ii) {
  26068. this.cMap.readCharCode(chars, i, c);
  26069. const {
  26070. charcode,
  26071. length
  26072. } = c;
  26073. i += length;
  26074. const glyph = this._charToGlyph(charcode, length === 1 && chars.charCodeAt(i - 1) === 0x20);
  26075. glyphs.push(glyph);
  26076. }
  26077. } else {
  26078. for (let i = 0, ii = chars.length; i < ii; ++i) {
  26079. const charcode = chars.charCodeAt(i);
  26080. const glyph = this._charToGlyph(charcode, charcode === 0x20);
  26081. glyphs.push(glyph);
  26082. }
  26083. }
  26084. return this._charsCache[chars] = glyphs;
  26085. }
  26086. getCharPositions(chars) {
  26087. const positions = [];
  26088. if (this.cMap) {
  26089. const c = Object.create(null);
  26090. let i = 0;
  26091. while (i < chars.length) {
  26092. this.cMap.readCharCode(chars, i, c);
  26093. const length = c.length;
  26094. positions.push([i, i + length]);
  26095. i += length;
  26096. }
  26097. } else {
  26098. for (let i = 0, ii = chars.length; i < ii; ++i) {
  26099. positions.push([i, i + 1]);
  26100. }
  26101. }
  26102. return positions;
  26103. }
  26104. get glyphCacheValues() {
  26105. return Object.values(this._glyphCache);
  26106. }
  26107. encodeString(str) {
  26108. const buffers = [];
  26109. const currentBuf = [];
  26110. const hasCurrentBufErrors = () => buffers.length % 2 === 1;
  26111. const getCharCode = this.toUnicode instanceof IdentityToUnicodeMap ? unicode => this.toUnicode.charCodeOf(unicode) : unicode => this.toUnicode.charCodeOf(String.fromCodePoint(unicode));
  26112. for (let i = 0, ii = str.length; i < ii; i++) {
  26113. const unicode = str.codePointAt(i);
  26114. if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) {
  26115. i++;
  26116. }
  26117. if (this.toUnicode) {
  26118. const charCode = getCharCode(unicode);
  26119. if (charCode !== -1) {
  26120. if (hasCurrentBufErrors()) {
  26121. buffers.push(currentBuf.join(""));
  26122. currentBuf.length = 0;
  26123. }
  26124. const charCodeLength = this.cMap ? this.cMap.getCharCodeLength(charCode) : 1;
  26125. for (let j = charCodeLength - 1; j >= 0; j--) {
  26126. currentBuf.push(String.fromCharCode(charCode >> 8 * j & 0xff));
  26127. }
  26128. continue;
  26129. }
  26130. }
  26131. if (!hasCurrentBufErrors()) {
  26132. buffers.push(currentBuf.join(""));
  26133. currentBuf.length = 0;
  26134. }
  26135. currentBuf.push(String.fromCodePoint(unicode));
  26136. }
  26137. buffers.push(currentBuf.join(""));
  26138. return buffers;
  26139. }
  26140. }
  26141. class ErrorFont {
  26142. constructor(error) {
  26143. this.error = error;
  26144. this.loadedName = "g_font_error";
  26145. this.missingFile = true;
  26146. }
  26147. charsToGlyphs() {
  26148. return [];
  26149. }
  26150. encodeString(chars) {
  26151. return [chars];
  26152. }
  26153. exportData(extraProperties = false) {
  26154. return {
  26155. error: this.error
  26156. };
  26157. }
  26158. }
  26159. ;// CONCATENATED MODULE: ./src/core/pattern.js
  26160. const ShadingType = {
  26161. FUNCTION_BASED: 1,
  26162. AXIAL: 2,
  26163. RADIAL: 3,
  26164. FREE_FORM_MESH: 4,
  26165. LATTICE_FORM_MESH: 5,
  26166. COONS_PATCH_MESH: 6,
  26167. TENSOR_PATCH_MESH: 7
  26168. };
  26169. class Pattern {
  26170. constructor() {
  26171. unreachable("Cannot initialize Pattern.");
  26172. }
  26173. static parseShading(shading, xref, res, pdfFunctionFactory, localColorSpaceCache) {
  26174. const dict = shading instanceof BaseStream ? shading.dict : shading;
  26175. const type = dict.get("ShadingType");
  26176. try {
  26177. switch (type) {
  26178. case ShadingType.AXIAL:
  26179. case ShadingType.RADIAL:
  26180. return new RadialAxialShading(dict, xref, res, pdfFunctionFactory, localColorSpaceCache);
  26181. case ShadingType.FREE_FORM_MESH:
  26182. case ShadingType.LATTICE_FORM_MESH:
  26183. case ShadingType.COONS_PATCH_MESH:
  26184. case ShadingType.TENSOR_PATCH_MESH:
  26185. return new MeshShading(shading, xref, res, pdfFunctionFactory, localColorSpaceCache);
  26186. default:
  26187. throw new FormatError("Unsupported ShadingType: " + type);
  26188. }
  26189. } catch (ex) {
  26190. if (ex instanceof MissingDataException) {
  26191. throw ex;
  26192. }
  26193. warn(ex);
  26194. return new DummyShading();
  26195. }
  26196. }
  26197. }
  26198. class BaseShading {
  26199. static SMALL_NUMBER = 1e-6;
  26200. constructor() {
  26201. if (this.constructor === BaseShading) {
  26202. unreachable("Cannot initialize BaseShading.");
  26203. }
  26204. }
  26205. getIR() {
  26206. unreachable("Abstract method `getIR` called.");
  26207. }
  26208. }
  26209. class RadialAxialShading extends BaseShading {
  26210. constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
  26211. super();
  26212. this.coordsArr = dict.getArray("Coords");
  26213. this.shadingType = dict.get("ShadingType");
  26214. const cs = ColorSpace.parse({
  26215. cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
  26216. xref,
  26217. resources,
  26218. pdfFunctionFactory,
  26219. localColorSpaceCache
  26220. });
  26221. const bbox = dict.getArray("BBox");
  26222. this.bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
  26223. let t0 = 0.0,
  26224. t1 = 1.0;
  26225. if (dict.has("Domain")) {
  26226. const domainArr = dict.getArray("Domain");
  26227. t0 = domainArr[0];
  26228. t1 = domainArr[1];
  26229. }
  26230. let extendStart = false,
  26231. extendEnd = false;
  26232. if (dict.has("Extend")) {
  26233. const extendArr = dict.getArray("Extend");
  26234. extendStart = extendArr[0];
  26235. extendEnd = extendArr[1];
  26236. }
  26237. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  26238. const [x1, y1, r1, x2, y2, r2] = this.coordsArr;
  26239. const distance = Math.hypot(x1 - x2, y1 - y2);
  26240. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  26241. warn("Unsupported radial gradient.");
  26242. }
  26243. }
  26244. this.extendStart = extendStart;
  26245. this.extendEnd = extendEnd;
  26246. const fnObj = dict.getRaw("Function");
  26247. const fn = pdfFunctionFactory.createFromArray(fnObj);
  26248. const NUMBER_OF_SAMPLES = 840;
  26249. const step = (t1 - t0) / NUMBER_OF_SAMPLES;
  26250. const colorStops = this.colorStops = [];
  26251. if (t0 >= t1 || step <= 0) {
  26252. info("Bad shading domain.");
  26253. return;
  26254. }
  26255. const color = new Float32Array(cs.numComps),
  26256. ratio = new Float32Array(1);
  26257. let rgbColor;
  26258. let iBase = 0;
  26259. ratio[0] = t0;
  26260. fn(ratio, 0, color, 0);
  26261. let rgbBase = cs.getRgb(color, 0);
  26262. const cssColorBase = Util.makeHexColor(rgbBase[0], rgbBase[1], rgbBase[2]);
  26263. colorStops.push([0, cssColorBase]);
  26264. let iPrev = 1;
  26265. ratio[0] = t0 + step;
  26266. fn(ratio, 0, color, 0);
  26267. let rgbPrev = cs.getRgb(color, 0);
  26268. let maxSlopeR = rgbPrev[0] - rgbBase[0] + 1;
  26269. let maxSlopeG = rgbPrev[1] - rgbBase[1] + 1;
  26270. let maxSlopeB = rgbPrev[2] - rgbBase[2] + 1;
  26271. let minSlopeR = rgbPrev[0] - rgbBase[0] - 1;
  26272. let minSlopeG = rgbPrev[1] - rgbBase[1] - 1;
  26273. let minSlopeB = rgbPrev[2] - rgbBase[2] - 1;
  26274. for (let i = 2; i < NUMBER_OF_SAMPLES; i++) {
  26275. ratio[0] = t0 + i * step;
  26276. fn(ratio, 0, color, 0);
  26277. rgbColor = cs.getRgb(color, 0);
  26278. const run = i - iBase;
  26279. maxSlopeR = Math.min(maxSlopeR, (rgbColor[0] - rgbBase[0] + 1) / run);
  26280. maxSlopeG = Math.min(maxSlopeG, (rgbColor[1] - rgbBase[1] + 1) / run);
  26281. maxSlopeB = Math.min(maxSlopeB, (rgbColor[2] - rgbBase[2] + 1) / run);
  26282. minSlopeR = Math.max(minSlopeR, (rgbColor[0] - rgbBase[0] - 1) / run);
  26283. minSlopeG = Math.max(minSlopeG, (rgbColor[1] - rgbBase[1] - 1) / run);
  26284. minSlopeB = Math.max(minSlopeB, (rgbColor[2] - rgbBase[2] - 1) / run);
  26285. const slopesExist = minSlopeR <= maxSlopeR && minSlopeG <= maxSlopeG && minSlopeB <= maxSlopeB;
  26286. if (!slopesExist) {
  26287. const cssColor = Util.makeHexColor(rgbPrev[0], rgbPrev[1], rgbPrev[2]);
  26288. colorStops.push([iPrev / NUMBER_OF_SAMPLES, cssColor]);
  26289. maxSlopeR = rgbColor[0] - rgbPrev[0] + 1;
  26290. maxSlopeG = rgbColor[1] - rgbPrev[1] + 1;
  26291. maxSlopeB = rgbColor[2] - rgbPrev[2] + 1;
  26292. minSlopeR = rgbColor[0] - rgbPrev[0] - 1;
  26293. minSlopeG = rgbColor[1] - rgbPrev[1] - 1;
  26294. minSlopeB = rgbColor[2] - rgbPrev[2] - 1;
  26295. iBase = iPrev;
  26296. rgbBase = rgbPrev;
  26297. }
  26298. iPrev = i;
  26299. rgbPrev = rgbColor;
  26300. }
  26301. const cssColor = Util.makeHexColor(rgbPrev[0], rgbPrev[1], rgbPrev[2]);
  26302. colorStops.push([1, cssColor]);
  26303. let background = "transparent";
  26304. if (dict.has("Background")) {
  26305. rgbColor = cs.getRgb(dict.get("Background"), 0);
  26306. background = Util.makeHexColor(rgbColor[0], rgbColor[1], rgbColor[2]);
  26307. }
  26308. if (!extendStart) {
  26309. colorStops.unshift([0, background]);
  26310. colorStops[1][0] += BaseShading.SMALL_NUMBER;
  26311. }
  26312. if (!extendEnd) {
  26313. colorStops.at(-1)[0] -= BaseShading.SMALL_NUMBER;
  26314. colorStops.push([1, background]);
  26315. }
  26316. this.colorStops = colorStops;
  26317. }
  26318. getIR() {
  26319. const coordsArr = this.coordsArr;
  26320. const shadingType = this.shadingType;
  26321. let type, p0, p1, r0, r1;
  26322. if (shadingType === ShadingType.AXIAL) {
  26323. p0 = [coordsArr[0], coordsArr[1]];
  26324. p1 = [coordsArr[2], coordsArr[3]];
  26325. r0 = null;
  26326. r1 = null;
  26327. type = "axial";
  26328. } else if (shadingType === ShadingType.RADIAL) {
  26329. p0 = [coordsArr[0], coordsArr[1]];
  26330. p1 = [coordsArr[3], coordsArr[4]];
  26331. r0 = coordsArr[2];
  26332. r1 = coordsArr[5];
  26333. type = "radial";
  26334. } else {
  26335. unreachable(`getPattern type unknown: ${shadingType}`);
  26336. }
  26337. return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1];
  26338. }
  26339. }
  26340. class MeshStreamReader {
  26341. constructor(stream, context) {
  26342. this.stream = stream;
  26343. this.context = context;
  26344. this.buffer = 0;
  26345. this.bufferLength = 0;
  26346. const numComps = context.numComps;
  26347. this.tmpCompsBuf = new Float32Array(numComps);
  26348. const csNumComps = context.colorSpace.numComps;
  26349. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  26350. }
  26351. get hasData() {
  26352. if (this.stream.end) {
  26353. return this.stream.pos < this.stream.end;
  26354. }
  26355. if (this.bufferLength > 0) {
  26356. return true;
  26357. }
  26358. const nextByte = this.stream.getByte();
  26359. if (nextByte < 0) {
  26360. return false;
  26361. }
  26362. this.buffer = nextByte;
  26363. this.bufferLength = 8;
  26364. return true;
  26365. }
  26366. readBits(n) {
  26367. let buffer = this.buffer;
  26368. let bufferLength = this.bufferLength;
  26369. if (n === 32) {
  26370. if (bufferLength === 0) {
  26371. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  26372. }
  26373. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  26374. const nextByte = this.stream.getByte();
  26375. this.buffer = nextByte & (1 << bufferLength) - 1;
  26376. return (buffer << 8 - bufferLength | (nextByte & 0xff) >> bufferLength) >>> 0;
  26377. }
  26378. if (n === 8 && bufferLength === 0) {
  26379. return this.stream.getByte();
  26380. }
  26381. while (bufferLength < n) {
  26382. buffer = buffer << 8 | this.stream.getByte();
  26383. bufferLength += 8;
  26384. }
  26385. bufferLength -= n;
  26386. this.bufferLength = bufferLength;
  26387. this.buffer = buffer & (1 << bufferLength) - 1;
  26388. return buffer >> bufferLength;
  26389. }
  26390. align() {
  26391. this.buffer = 0;
  26392. this.bufferLength = 0;
  26393. }
  26394. readFlag() {
  26395. return this.readBits(this.context.bitsPerFlag);
  26396. }
  26397. readCoordinate() {
  26398. const bitsPerCoordinate = this.context.bitsPerCoordinate;
  26399. const xi = this.readBits(bitsPerCoordinate);
  26400. const yi = this.readBits(bitsPerCoordinate);
  26401. const decode = this.context.decode;
  26402. const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  26403. return [xi * scale * (decode[1] - decode[0]) + decode[0], yi * scale * (decode[3] - decode[2]) + decode[2]];
  26404. }
  26405. readComponents() {
  26406. const numComps = this.context.numComps;
  26407. const bitsPerComponent = this.context.bitsPerComponent;
  26408. const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  26409. const decode = this.context.decode;
  26410. const components = this.tmpCompsBuf;
  26411. for (let i = 0, j = 4; i < numComps; i++, j += 2) {
  26412. const ci = this.readBits(bitsPerComponent);
  26413. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  26414. }
  26415. const color = this.tmpCsCompsBuf;
  26416. if (this.context.colorFn) {
  26417. this.context.colorFn(components, 0, color, 0);
  26418. }
  26419. return this.context.colorSpace.getRgb(color, 0);
  26420. }
  26421. }
  26422. let bCache = Object.create(null);
  26423. function buildB(count) {
  26424. const lut = [];
  26425. for (let i = 0; i <= count; i++) {
  26426. const t = i / count,
  26427. t_ = 1 - t;
  26428. lut.push(new Float32Array([t_ ** 3, 3 * t * t_ ** 2, 3 * t ** 2 * t_, t ** 3]));
  26429. }
  26430. return lut;
  26431. }
  26432. function getB(count) {
  26433. return bCache[count] ||= buildB(count);
  26434. }
  26435. function clearPatternCaches() {
  26436. bCache = Object.create(null);
  26437. }
  26438. class MeshShading extends BaseShading {
  26439. static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  26440. static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  26441. static TRIANGLE_DENSITY = 20;
  26442. constructor(stream, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
  26443. super();
  26444. if (!(stream instanceof BaseStream)) {
  26445. throw new FormatError("Mesh data is not a stream");
  26446. }
  26447. const dict = stream.dict;
  26448. this.shadingType = dict.get("ShadingType");
  26449. const bbox = dict.getArray("BBox");
  26450. this.bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
  26451. const cs = ColorSpace.parse({
  26452. cs: dict.getRaw("CS") || dict.getRaw("ColorSpace"),
  26453. xref,
  26454. resources,
  26455. pdfFunctionFactory,
  26456. localColorSpaceCache
  26457. });
  26458. this.background = dict.has("Background") ? cs.getRgb(dict.get("Background"), 0) : null;
  26459. const fnObj = dict.getRaw("Function");
  26460. const fn = fnObj ? pdfFunctionFactory.createFromArray(fnObj) : null;
  26461. this.coords = [];
  26462. this.colors = [];
  26463. this.figures = [];
  26464. const decodeContext = {
  26465. bitsPerCoordinate: dict.get("BitsPerCoordinate"),
  26466. bitsPerComponent: dict.get("BitsPerComponent"),
  26467. bitsPerFlag: dict.get("BitsPerFlag"),
  26468. decode: dict.getArray("Decode"),
  26469. colorFn: fn,
  26470. colorSpace: cs,
  26471. numComps: fn ? 1 : cs.numComps
  26472. };
  26473. const reader = new MeshStreamReader(stream, decodeContext);
  26474. let patchMesh = false;
  26475. switch (this.shadingType) {
  26476. case ShadingType.FREE_FORM_MESH:
  26477. this._decodeType4Shading(reader);
  26478. break;
  26479. case ShadingType.LATTICE_FORM_MESH:
  26480. const verticesPerRow = dict.get("VerticesPerRow") | 0;
  26481. if (verticesPerRow < 2) {
  26482. throw new FormatError("Invalid VerticesPerRow");
  26483. }
  26484. this._decodeType5Shading(reader, verticesPerRow);
  26485. break;
  26486. case ShadingType.COONS_PATCH_MESH:
  26487. this._decodeType6Shading(reader);
  26488. patchMesh = true;
  26489. break;
  26490. case ShadingType.TENSOR_PATCH_MESH:
  26491. this._decodeType7Shading(reader);
  26492. patchMesh = true;
  26493. break;
  26494. default:
  26495. unreachable("Unsupported mesh type.");
  26496. break;
  26497. }
  26498. if (patchMesh) {
  26499. this._updateBounds();
  26500. for (let i = 0, ii = this.figures.length; i < ii; i++) {
  26501. this._buildFigureFromPatch(i);
  26502. }
  26503. }
  26504. this._updateBounds();
  26505. this._packData();
  26506. }
  26507. _decodeType4Shading(reader) {
  26508. const coords = this.coords;
  26509. const colors = this.colors;
  26510. const operators = [];
  26511. const ps = [];
  26512. let verticesLeft = 0;
  26513. while (reader.hasData) {
  26514. const f = reader.readFlag();
  26515. const coord = reader.readCoordinate();
  26516. const color = reader.readComponents();
  26517. if (verticesLeft === 0) {
  26518. if (!(0 <= f && f <= 2)) {
  26519. throw new FormatError("Unknown type4 flag");
  26520. }
  26521. switch (f) {
  26522. case 0:
  26523. verticesLeft = 3;
  26524. break;
  26525. case 1:
  26526. ps.push(ps.at(-2), ps.at(-1));
  26527. verticesLeft = 1;
  26528. break;
  26529. case 2:
  26530. ps.push(ps.at(-3), ps.at(-1));
  26531. verticesLeft = 1;
  26532. break;
  26533. }
  26534. operators.push(f);
  26535. }
  26536. ps.push(coords.length);
  26537. coords.push(coord);
  26538. colors.push(color);
  26539. verticesLeft--;
  26540. reader.align();
  26541. }
  26542. this.figures.push({
  26543. type: "triangles",
  26544. coords: new Int32Array(ps),
  26545. colors: new Int32Array(ps)
  26546. });
  26547. }
  26548. _decodeType5Shading(reader, verticesPerRow) {
  26549. const coords = this.coords;
  26550. const colors = this.colors;
  26551. const ps = [];
  26552. while (reader.hasData) {
  26553. const coord = reader.readCoordinate();
  26554. const color = reader.readComponents();
  26555. ps.push(coords.length);
  26556. coords.push(coord);
  26557. colors.push(color);
  26558. }
  26559. this.figures.push({
  26560. type: "lattice",
  26561. coords: new Int32Array(ps),
  26562. colors: new Int32Array(ps),
  26563. verticesPerRow
  26564. });
  26565. }
  26566. _decodeType6Shading(reader) {
  26567. const coords = this.coords;
  26568. const colors = this.colors;
  26569. const ps = new Int32Array(16);
  26570. const cs = new Int32Array(4);
  26571. while (reader.hasData) {
  26572. const f = reader.readFlag();
  26573. if (!(0 <= f && f <= 3)) {
  26574. throw new FormatError("Unknown type6 flag");
  26575. }
  26576. const pi = coords.length;
  26577. for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  26578. coords.push(reader.readCoordinate());
  26579. }
  26580. const ci = colors.length;
  26581. for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  26582. colors.push(reader.readComponents());
  26583. }
  26584. let tmp1, tmp2, tmp3, tmp4;
  26585. switch (f) {
  26586. case 0:
  26587. ps[12] = pi + 3;
  26588. ps[13] = pi + 4;
  26589. ps[14] = pi + 5;
  26590. ps[15] = pi + 6;
  26591. ps[8] = pi + 2;
  26592. ps[11] = pi + 7;
  26593. ps[4] = pi + 1;
  26594. ps[7] = pi + 8;
  26595. ps[0] = pi;
  26596. ps[1] = pi + 11;
  26597. ps[2] = pi + 10;
  26598. ps[3] = pi + 9;
  26599. cs[2] = ci + 1;
  26600. cs[3] = ci + 2;
  26601. cs[0] = ci;
  26602. cs[1] = ci + 3;
  26603. break;
  26604. case 1:
  26605. tmp1 = ps[12];
  26606. tmp2 = ps[13];
  26607. tmp3 = ps[14];
  26608. tmp4 = ps[15];
  26609. ps[12] = tmp4;
  26610. ps[13] = pi + 0;
  26611. ps[14] = pi + 1;
  26612. ps[15] = pi + 2;
  26613. ps[8] = tmp3;
  26614. ps[11] = pi + 3;
  26615. ps[4] = tmp2;
  26616. ps[7] = pi + 4;
  26617. ps[0] = tmp1;
  26618. ps[1] = pi + 7;
  26619. ps[2] = pi + 6;
  26620. ps[3] = pi + 5;
  26621. tmp1 = cs[2];
  26622. tmp2 = cs[3];
  26623. cs[2] = tmp2;
  26624. cs[3] = ci;
  26625. cs[0] = tmp1;
  26626. cs[1] = ci + 1;
  26627. break;
  26628. case 2:
  26629. tmp1 = ps[15];
  26630. tmp2 = ps[11];
  26631. ps[12] = ps[3];
  26632. ps[13] = pi + 0;
  26633. ps[14] = pi + 1;
  26634. ps[15] = pi + 2;
  26635. ps[8] = ps[7];
  26636. ps[11] = pi + 3;
  26637. ps[4] = tmp2;
  26638. ps[7] = pi + 4;
  26639. ps[0] = tmp1;
  26640. ps[1] = pi + 7;
  26641. ps[2] = pi + 6;
  26642. ps[3] = pi + 5;
  26643. tmp1 = cs[3];
  26644. cs[2] = cs[1];
  26645. cs[3] = ci;
  26646. cs[0] = tmp1;
  26647. cs[1] = ci + 1;
  26648. break;
  26649. case 3:
  26650. ps[12] = ps[0];
  26651. ps[13] = pi + 0;
  26652. ps[14] = pi + 1;
  26653. ps[15] = pi + 2;
  26654. ps[8] = ps[1];
  26655. ps[11] = pi + 3;
  26656. ps[4] = ps[2];
  26657. ps[7] = pi + 4;
  26658. ps[0] = ps[3];
  26659. ps[1] = pi + 7;
  26660. ps[2] = pi + 6;
  26661. ps[3] = pi + 5;
  26662. cs[2] = cs[0];
  26663. cs[3] = ci;
  26664. cs[0] = cs[1];
  26665. cs[1] = ci + 1;
  26666. break;
  26667. }
  26668. ps[5] = coords.length;
  26669. coords.push([(-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, (-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]);
  26670. ps[6] = coords.length;
  26671. coords.push([(-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, (-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]);
  26672. ps[9] = coords.length;
  26673. coords.push([(-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, (-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]);
  26674. ps[10] = coords.length;
  26675. coords.push([(-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, (-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]);
  26676. this.figures.push({
  26677. type: "patch",
  26678. coords: new Int32Array(ps),
  26679. colors: new Int32Array(cs)
  26680. });
  26681. }
  26682. }
  26683. _decodeType7Shading(reader) {
  26684. const coords = this.coords;
  26685. const colors = this.colors;
  26686. const ps = new Int32Array(16);
  26687. const cs = new Int32Array(4);
  26688. while (reader.hasData) {
  26689. const f = reader.readFlag();
  26690. if (!(0 <= f && f <= 3)) {
  26691. throw new FormatError("Unknown type7 flag");
  26692. }
  26693. const pi = coords.length;
  26694. for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  26695. coords.push(reader.readCoordinate());
  26696. }
  26697. const ci = colors.length;
  26698. for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  26699. colors.push(reader.readComponents());
  26700. }
  26701. let tmp1, tmp2, tmp3, tmp4;
  26702. switch (f) {
  26703. case 0:
  26704. ps[12] = pi + 3;
  26705. ps[13] = pi + 4;
  26706. ps[14] = pi + 5;
  26707. ps[15] = pi + 6;
  26708. ps[8] = pi + 2;
  26709. ps[9] = pi + 13;
  26710. ps[10] = pi + 14;
  26711. ps[11] = pi + 7;
  26712. ps[4] = pi + 1;
  26713. ps[5] = pi + 12;
  26714. ps[6] = pi + 15;
  26715. ps[7] = pi + 8;
  26716. ps[0] = pi;
  26717. ps[1] = pi + 11;
  26718. ps[2] = pi + 10;
  26719. ps[3] = pi + 9;
  26720. cs[2] = ci + 1;
  26721. cs[3] = ci + 2;
  26722. cs[0] = ci;
  26723. cs[1] = ci + 3;
  26724. break;
  26725. case 1:
  26726. tmp1 = ps[12];
  26727. tmp2 = ps[13];
  26728. tmp3 = ps[14];
  26729. tmp4 = ps[15];
  26730. ps[12] = tmp4;
  26731. ps[13] = pi + 0;
  26732. ps[14] = pi + 1;
  26733. ps[15] = pi + 2;
  26734. ps[8] = tmp3;
  26735. ps[9] = pi + 9;
  26736. ps[10] = pi + 10;
  26737. ps[11] = pi + 3;
  26738. ps[4] = tmp2;
  26739. ps[5] = pi + 8;
  26740. ps[6] = pi + 11;
  26741. ps[7] = pi + 4;
  26742. ps[0] = tmp1;
  26743. ps[1] = pi + 7;
  26744. ps[2] = pi + 6;
  26745. ps[3] = pi + 5;
  26746. tmp1 = cs[2];
  26747. tmp2 = cs[3];
  26748. cs[2] = tmp2;
  26749. cs[3] = ci;
  26750. cs[0] = tmp1;
  26751. cs[1] = ci + 1;
  26752. break;
  26753. case 2:
  26754. tmp1 = ps[15];
  26755. tmp2 = ps[11];
  26756. ps[12] = ps[3];
  26757. ps[13] = pi + 0;
  26758. ps[14] = pi + 1;
  26759. ps[15] = pi + 2;
  26760. ps[8] = ps[7];
  26761. ps[9] = pi + 9;
  26762. ps[10] = pi + 10;
  26763. ps[11] = pi + 3;
  26764. ps[4] = tmp2;
  26765. ps[5] = pi + 8;
  26766. ps[6] = pi + 11;
  26767. ps[7] = pi + 4;
  26768. ps[0] = tmp1;
  26769. ps[1] = pi + 7;
  26770. ps[2] = pi + 6;
  26771. ps[3] = pi + 5;
  26772. tmp1 = cs[3];
  26773. cs[2] = cs[1];
  26774. cs[3] = ci;
  26775. cs[0] = tmp1;
  26776. cs[1] = ci + 1;
  26777. break;
  26778. case 3:
  26779. ps[12] = ps[0];
  26780. ps[13] = pi + 0;
  26781. ps[14] = pi + 1;
  26782. ps[15] = pi + 2;
  26783. ps[8] = ps[1];
  26784. ps[9] = pi + 9;
  26785. ps[10] = pi + 10;
  26786. ps[11] = pi + 3;
  26787. ps[4] = ps[2];
  26788. ps[5] = pi + 8;
  26789. ps[6] = pi + 11;
  26790. ps[7] = pi + 4;
  26791. ps[0] = ps[3];
  26792. ps[1] = pi + 7;
  26793. ps[2] = pi + 6;
  26794. ps[3] = pi + 5;
  26795. cs[2] = cs[0];
  26796. cs[3] = ci;
  26797. cs[0] = cs[1];
  26798. cs[1] = ci + 1;
  26799. break;
  26800. }
  26801. this.figures.push({
  26802. type: "patch",
  26803. coords: new Int32Array(ps),
  26804. colors: new Int32Array(cs)
  26805. });
  26806. }
  26807. }
  26808. _buildFigureFromPatch(index) {
  26809. const figure = this.figures[index];
  26810. assert(figure.type === "patch", "Unexpected patch mesh figure");
  26811. const coords = this.coords,
  26812. colors = this.colors;
  26813. const pi = figure.coords;
  26814. const ci = figure.colors;
  26815. const figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  26816. const figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  26817. const figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  26818. const figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  26819. let splitXBy = Math.ceil((figureMaxX - figureMinX) * MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0]));
  26820. splitXBy = Math.max(MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  26821. let splitYBy = Math.ceil((figureMaxY - figureMinY) * MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1]));
  26822. splitYBy = Math.max(MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  26823. const verticesPerRow = splitXBy + 1;
  26824. const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  26825. const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  26826. let k = 0;
  26827. const cl = new Uint8Array(3),
  26828. cr = new Uint8Array(3);
  26829. const c0 = colors[ci[0]],
  26830. c1 = colors[ci[1]],
  26831. c2 = colors[ci[2]],
  26832. c3 = colors[ci[3]];
  26833. const bRow = getB(splitYBy),
  26834. bCol = getB(splitXBy);
  26835. for (let row = 0; row <= splitYBy; row++) {
  26836. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  26837. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  26838. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  26839. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  26840. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  26841. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  26842. for (let col = 0; col <= splitXBy; col++, k++) {
  26843. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  26844. continue;
  26845. }
  26846. let x = 0,
  26847. y = 0;
  26848. let q = 0;
  26849. for (let i = 0; i <= 3; i++) {
  26850. for (let j = 0; j <= 3; j++, q++) {
  26851. const m = bRow[row][i] * bCol[col][j];
  26852. x += coords[pi[q]][0] * m;
  26853. y += coords[pi[q]][1] * m;
  26854. }
  26855. }
  26856. figureCoords[k] = coords.length;
  26857. coords.push([x, y]);
  26858. figureColors[k] = colors.length;
  26859. const newColor = new Uint8Array(3);
  26860. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  26861. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  26862. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  26863. colors.push(newColor);
  26864. }
  26865. }
  26866. figureCoords[0] = pi[0];
  26867. figureColors[0] = ci[0];
  26868. figureCoords[splitXBy] = pi[3];
  26869. figureColors[splitXBy] = ci[1];
  26870. figureCoords[verticesPerRow * splitYBy] = pi[12];
  26871. figureColors[verticesPerRow * splitYBy] = ci[2];
  26872. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  26873. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  26874. this.figures[index] = {
  26875. type: "lattice",
  26876. coords: figureCoords,
  26877. colors: figureColors,
  26878. verticesPerRow
  26879. };
  26880. }
  26881. _updateBounds() {
  26882. let minX = this.coords[0][0],
  26883. minY = this.coords[0][1],
  26884. maxX = minX,
  26885. maxY = minY;
  26886. for (let i = 1, ii = this.coords.length; i < ii; i++) {
  26887. const x = this.coords[i][0],
  26888. y = this.coords[i][1];
  26889. minX = minX > x ? x : minX;
  26890. minY = minY > y ? y : minY;
  26891. maxX = maxX < x ? x : maxX;
  26892. maxY = maxY < y ? y : maxY;
  26893. }
  26894. this.bounds = [minX, minY, maxX, maxY];
  26895. }
  26896. _packData() {
  26897. let i, ii, j, jj;
  26898. const coords = this.coords;
  26899. const coordsPacked = new Float32Array(coords.length * 2);
  26900. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  26901. const xy = coords[i];
  26902. coordsPacked[j++] = xy[0];
  26903. coordsPacked[j++] = xy[1];
  26904. }
  26905. this.coords = coordsPacked;
  26906. const colors = this.colors;
  26907. const colorsPacked = new Uint8Array(colors.length * 3);
  26908. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  26909. const c = colors[i];
  26910. colorsPacked[j++] = c[0];
  26911. colorsPacked[j++] = c[1];
  26912. colorsPacked[j++] = c[2];
  26913. }
  26914. this.colors = colorsPacked;
  26915. const figures = this.figures;
  26916. for (i = 0, ii = figures.length; i < ii; i++) {
  26917. const figure = figures[i],
  26918. ps = figure.coords,
  26919. cs = figure.colors;
  26920. for (j = 0, jj = ps.length; j < jj; j++) {
  26921. ps[j] *= 2;
  26922. cs[j] *= 3;
  26923. }
  26924. }
  26925. }
  26926. getIR() {
  26927. return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, this.bounds, this.bbox, this.background];
  26928. }
  26929. }
  26930. class DummyShading extends BaseShading {
  26931. getIR() {
  26932. return ["Dummy"];
  26933. }
  26934. }
  26935. function getTilingPatternIR(operatorList, dict, color) {
  26936. const matrix = dict.getArray("Matrix");
  26937. const bbox = Util.normalizeRect(dict.getArray("BBox"));
  26938. const xstep = dict.get("XStep");
  26939. const ystep = dict.get("YStep");
  26940. const paintType = dict.get("PaintType");
  26941. const tilingType = dict.get("TilingType");
  26942. if (bbox[2] - bbox[0] === 0 || bbox[3] - bbox[1] === 0) {
  26943. throw new FormatError(`Invalid getTilingPatternIR /BBox array: [${bbox}].`);
  26944. }
  26945. return ["TilingPattern", color, operatorList, matrix, bbox, xstep, ystep, paintType, tilingType];
  26946. }
  26947. ;// CONCATENATED MODULE: ./src/core/calibri_factors.js
  26948. const CalibriBoldFactors = [1.3877, 1, 1, 1, 0.97801, 0.92482, 0.89552, 0.91133, 0.81988, 0.97566, 0.98152, 0.93548, 0.93548, 1.2798, 0.85284, 0.92794, 1, 0.96134, 1.54657, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.82845, 0.82845, 0.85284, 0.85284, 0.85284, 0.75859, 0.92138, 0.83908, 0.7762, 0.73293, 0.87289, 0.73133, 0.7514, 0.81921, 0.87356, 0.95958, 0.59526, 0.75727, 0.69225, 1.04924, 0.9121, 0.86943, 0.79795, 0.88198, 0.77958, 0.70864, 0.81055, 0.90399, 0.88653, 0.96017, 0.82577, 0.77892, 0.78257, 0.97507, 1.54657, 0.97507, 0.85284, 0.89552, 0.90176, 0.88762, 0.8785, 0.75241, 0.8785, 0.90518, 0.95015, 0.77618, 0.8785, 0.88401, 0.91916, 0.86304, 0.88401, 0.91488, 0.8785, 0.8801, 0.8785, 0.8785, 0.91343, 0.7173, 1.04106, 0.8785, 0.85075, 0.95794, 0.82616, 0.85162, 0.79492, 0.88331, 1.69808, 0.88331, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.7801, 0.89552, 1.24487, 1.13254, 1.12401, 0.96839, 0.85284, 0.68787, 0.70645, 0.85592, 0.90747, 1.01466, 1.0088, 0.90323, 1, 1.07463, 1, 0.91056, 0.75806, 1.19118, 0.96839, 0.78864, 0.82845, 0.84133, 0.75859, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.77539, 0.73293, 0.73133, 0.73133, 0.73133, 0.73133, 0.95958, 0.95958, 0.95958, 0.95958, 0.88506, 0.9121, 0.86943, 0.86943, 0.86943, 0.86943, 0.86943, 0.85284, 0.87508, 0.90399, 0.90399, 0.90399, 0.90399, 0.77892, 0.79795, 0.90807, 0.88762, 0.88762, 0.88762, 0.88762, 0.88762, 0.88762, 0.8715, 0.75241, 0.90518, 0.90518, 0.90518, 0.90518, 0.88401, 0.88401, 0.88401, 0.88401, 0.8785, 0.8785, 0.8801, 0.8801, 0.8801, 0.8801, 0.8801, 0.90747, 0.89049, 0.8785, 0.8785, 0.8785, 0.8785, 0.85162, 0.8785, 0.85162, 0.83908, 0.88762, 0.83908, 0.88762, 0.83908, 0.88762, 0.73293, 0.75241, 0.73293, 0.75241, 0.73293, 0.75241, 0.73293, 0.75241, 0.87289, 0.83016, 0.88506, 0.93125, 0.73133, 0.90518, 0.73133, 0.90518, 0.73133, 0.90518, 0.73133, 0.90518, 0.73133, 0.90518, 0.81921, 0.77618, 0.81921, 0.77618, 0.81921, 0.77618, 1, 1, 0.87356, 0.8785, 0.91075, 0.89608, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.76229, 0.90167, 0.59526, 0.91916, 1, 1, 0.86304, 0.69225, 0.88401, 1, 1, 0.70424, 0.79468, 0.91926, 0.88175, 0.70823, 0.94903, 0.9121, 0.8785, 1, 1, 0.9121, 0.8785, 0.87802, 0.88656, 0.8785, 0.86943, 0.8801, 0.86943, 0.8801, 0.86943, 0.8801, 0.87402, 0.89291, 0.77958, 0.91343, 1, 1, 0.77958, 0.91343, 0.70864, 0.7173, 0.70864, 0.7173, 0.70864, 0.7173, 0.70864, 0.7173, 1, 1, 0.81055, 0.75841, 0.81055, 1.06452, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.90399, 0.8785, 0.96017, 0.95794, 0.77892, 0.85162, 0.77892, 0.78257, 0.79492, 0.78257, 0.79492, 0.78257, 0.79492, 0.9297, 0.56892, 0.83908, 0.88762, 0.77539, 0.8715, 0.87508, 0.89049, 1, 1, 0.81055, 1.04106, 1.20528, 1.20528, 1, 1.15543, 0.70674, 0.98387, 0.94721, 1.33431, 1.45894, 0.95161, 1.06303, 0.83908, 0.80352, 0.57184, 0.6965, 0.56289, 0.82001, 0.56029, 0.81235, 1.02988, 0.83908, 0.7762, 0.68156, 0.80367, 0.73133, 0.78257, 0.87356, 0.86943, 0.95958, 0.75727, 0.89019, 1.04924, 0.9121, 0.7648, 0.86943, 0.87356, 0.79795, 0.78275, 0.81055, 0.77892, 0.9762, 0.82577, 0.99819, 0.84896, 0.95958, 0.77892, 0.96108, 1.01407, 0.89049, 1.02988, 0.94211, 0.96108, 0.8936, 0.84021, 0.87842, 0.96399, 0.79109, 0.89049, 1.00813, 1.02988, 0.86077, 0.87445, 0.92099, 0.84723, 0.86513, 0.8801, 0.75638, 0.85714, 0.78216, 0.79586, 0.87965, 0.94211, 0.97747, 0.78287, 0.97926, 0.84971, 1.02988, 0.94211, 0.8801, 0.94211, 0.84971, 0.73133, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90264, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90518, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90548, 1, 1, 1, 1, 1, 1, 0.96017, 0.95794, 0.96017, 0.95794, 0.96017, 0.95794, 0.77892, 0.85162, 1, 1, 0.89552, 0.90527, 1, 0.90363, 0.92794, 0.92794, 0.92794, 0.92794, 0.87012, 0.87012, 0.87012, 0.89552, 0.89552, 1.42259, 0.71143, 1.06152, 1, 1, 1.03372, 1.03372, 0.97171, 1.4956, 2.2807, 0.93835, 0.83406, 0.91133, 0.84107, 0.91133, 1, 1, 1, 0.72021, 1, 1.23108, 0.83489, 0.88525, 0.88525, 0.81499, 0.90527, 1.81055, 0.90527, 1.81055, 1.31006, 1.53711, 0.94434, 1.08696, 1, 0.95018, 0.77192, 0.85284, 0.90747, 1.17534, 0.69825, 0.9716, 1.37077, 0.90747, 0.90747, 0.85356, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.08004, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90727, 0.90727, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26949. const CalibriBoldMetrics = {
  26950. lineHeight: 1.2207,
  26951. lineGap: 0.2207
  26952. };
  26953. const CalibriBoldItalicFactors = [1.3877, 1, 1, 1, 0.97801, 0.92482, 0.89552, 0.91133, 0.81988, 0.97566, 0.98152, 0.93548, 0.93548, 1.2798, 0.85284, 0.92794, 1, 0.96134, 1.56239, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.82845, 0.82845, 0.85284, 0.85284, 0.85284, 0.75859, 0.92138, 0.83908, 0.7762, 0.71805, 0.87289, 0.73133, 0.7514, 0.81921, 0.87356, 0.95958, 0.59526, 0.75727, 0.69225, 1.04924, 0.90872, 0.85938, 0.79795, 0.87068, 0.77958, 0.69766, 0.81055, 0.90399, 0.88653, 0.96068, 0.82577, 0.77892, 0.78257, 0.97507, 1.529, 0.97507, 0.85284, 0.89552, 0.90176, 0.94908, 0.86411, 0.74012, 0.86411, 0.88323, 0.95015, 0.86411, 0.86331, 0.88401, 0.91916, 0.86304, 0.88401, 0.9039, 0.86331, 0.86331, 0.86411, 0.86411, 0.90464, 0.70852, 1.04106, 0.86331, 0.84372, 0.95794, 0.82616, 0.84548, 0.79492, 0.88331, 1.69808, 0.88331, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.7801, 0.89552, 1.24487, 1.13254, 1.19129, 0.96839, 0.85284, 0.68787, 0.70645, 0.85592, 0.90747, 1.01466, 1.0088, 0.90323, 1, 1.07463, 1, 0.91056, 0.75806, 1.19118, 0.96839, 0.78864, 0.82845, 0.84133, 0.75859, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.83908, 0.77539, 0.71805, 0.73133, 0.73133, 0.73133, 0.73133, 0.95958, 0.95958, 0.95958, 0.95958, 0.88506, 0.90872, 0.85938, 0.85938, 0.85938, 0.85938, 0.85938, 0.85284, 0.87068, 0.90399, 0.90399, 0.90399, 0.90399, 0.77892, 0.79795, 0.90807, 0.94908, 0.94908, 0.94908, 0.94908, 0.94908, 0.94908, 0.85887, 0.74012, 0.88323, 0.88323, 0.88323, 0.88323, 0.88401, 0.88401, 0.88401, 0.88401, 0.8785, 0.86331, 0.86331, 0.86331, 0.86331, 0.86331, 0.86331, 0.90747, 0.89049, 0.86331, 0.86331, 0.86331, 0.86331, 0.84548, 0.86411, 0.84548, 0.83908, 0.94908, 0.83908, 0.94908, 0.83908, 0.94908, 0.71805, 0.74012, 0.71805, 0.74012, 0.71805, 0.74012, 0.71805, 0.74012, 0.87289, 0.79538, 0.88506, 0.92726, 0.73133, 0.88323, 0.73133, 0.88323, 0.73133, 0.88323, 0.73133, 0.88323, 0.73133, 0.88323, 0.81921, 0.86411, 0.81921, 0.86411, 0.81921, 0.86411, 1, 1, 0.87356, 0.86331, 0.91075, 0.8777, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.95958, 0.88401, 0.76467, 0.90167, 0.59526, 0.91916, 1, 1, 0.86304, 0.69225, 0.88401, 1, 1, 0.70424, 0.77312, 0.91926, 0.88175, 0.70823, 0.94903, 0.90872, 0.86331, 1, 1, 0.90872, 0.86331, 0.86906, 0.88116, 0.86331, 0.85938, 0.86331, 0.85938, 0.86331, 0.85938, 0.86331, 0.87402, 0.86549, 0.77958, 0.90464, 1, 1, 0.77958, 0.90464, 0.69766, 0.70852, 0.69766, 0.70852, 0.69766, 0.70852, 0.69766, 0.70852, 1, 1, 0.81055, 0.75841, 0.81055, 1.06452, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.90399, 0.86331, 0.96068, 0.95794, 0.77892, 0.84548, 0.77892, 0.78257, 0.79492, 0.78257, 0.79492, 0.78257, 0.79492, 0.9297, 0.56892, 0.83908, 0.94908, 0.77539, 0.85887, 0.87068, 0.89049, 1, 1, 0.81055, 1.04106, 1.20528, 1.20528, 1, 1.15543, 0.70088, 0.98387, 0.94721, 1.33431, 1.45894, 0.95161, 1.48387, 0.83908, 0.80352, 0.57118, 0.6965, 0.56347, 0.79179, 0.55853, 0.80346, 1.02988, 0.83908, 0.7762, 0.67174, 0.86036, 0.73133, 0.78257, 0.87356, 0.86441, 0.95958, 0.75727, 0.89019, 1.04924, 0.90872, 0.74889, 0.85938, 0.87891, 0.79795, 0.7957, 0.81055, 0.77892, 0.97447, 0.82577, 0.97466, 0.87179, 0.95958, 0.77892, 0.94252, 0.95612, 0.8753, 1.02988, 0.92733, 0.94252, 0.87411, 0.84021, 0.8728, 0.95612, 0.74081, 0.8753, 1.02189, 1.02988, 0.84814, 0.87445, 0.91822, 0.84723, 0.85668, 0.86331, 0.81344, 0.87581, 0.76422, 0.82046, 0.96057, 0.92733, 0.99375, 0.78022, 0.95452, 0.86015, 1.02988, 0.92733, 0.86331, 0.92733, 0.86015, 0.73133, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90631, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.88323, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.85174, 1, 1, 1, 1, 1, 1, 0.96068, 0.95794, 0.96068, 0.95794, 0.96068, 0.95794, 0.77892, 0.84548, 1, 1, 0.89552, 0.90527, 1, 0.90363, 0.92794, 0.92794, 0.92794, 0.89807, 0.87012, 0.87012, 0.87012, 0.89552, 0.89552, 1.42259, 0.71094, 1.06152, 1, 1, 1.03372, 1.03372, 0.97171, 1.4956, 2.2807, 0.92972, 0.83406, 0.91133, 0.83326, 0.91133, 1, 1, 1, 0.72021, 1, 1.23108, 0.83489, 0.88525, 0.88525, 0.81499, 0.90616, 1.81055, 0.90527, 1.81055, 1.3107, 1.53711, 0.94434, 1.08696, 1, 0.95018, 0.77192, 0.85284, 0.90747, 1.17534, 0.69825, 0.9716, 1.37077, 0.90747, 0.90747, 0.85356, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.08004, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90727, 0.90727, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26954. const CalibriBoldItalicMetrics = {
  26955. lineHeight: 1.2207,
  26956. lineGap: 0.2207
  26957. };
  26958. const CalibriItalicFactors = [1.3877, 1, 1, 1, 1.17223, 1.1293, 0.89552, 0.91133, 0.80395, 1.02269, 1.15601, 0.91056, 0.91056, 1.2798, 0.85284, 0.89807, 1, 0.90861, 1.39543, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.96309, 0.96309, 0.85284, 0.85284, 0.85284, 0.83319, 0.88071, 0.8675, 0.81552, 0.72346, 0.85193, 0.73206, 0.7522, 0.81105, 0.86275, 0.90685, 0.6377, 0.77892, 0.75593, 1.02638, 0.89249, 0.84118, 0.77452, 0.85374, 0.75186, 0.67789, 0.79776, 0.88844, 0.85066, 0.94309, 0.77818, 0.7306, 0.76659, 1.10369, 1.38313, 1.10369, 1.06139, 0.89552, 0.8739, 0.9245, 0.9245, 0.83203, 0.9245, 0.85865, 1.09842, 0.9245, 0.9245, 1.03297, 1.07692, 0.90918, 1.03297, 0.94959, 0.9245, 0.92274, 0.9245, 0.9245, 1.02933, 0.77832, 1.20562, 0.9245, 0.8916, 0.98986, 0.86621, 0.89453, 0.79004, 0.94152, 1.77256, 0.94152, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.91729, 0.89552, 1.17889, 1.13254, 1.16359, 0.92098, 0.85284, 0.68787, 0.71353, 0.84737, 0.90747, 1.0088, 1.0044, 0.87683, 1, 1.09091, 1, 0.92229, 0.739, 1.15642, 0.92098, 0.76288, 0.80504, 0.80972, 0.75859, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.76318, 0.72346, 0.73206, 0.73206, 0.73206, 0.73206, 0.90685, 0.90685, 0.90685, 0.90685, 0.86477, 0.89249, 0.84118, 0.84118, 0.84118, 0.84118, 0.84118, 0.85284, 0.84557, 0.88844, 0.88844, 0.88844, 0.88844, 0.7306, 0.77452, 0.86331, 0.9245, 0.9245, 0.9245, 0.9245, 0.9245, 0.9245, 0.84843, 0.83203, 0.85865, 0.85865, 0.85865, 0.85865, 0.82601, 0.82601, 0.82601, 0.82601, 0.94469, 0.9245, 0.92274, 0.92274, 0.92274, 0.92274, 0.92274, 0.90747, 0.86651, 0.9245, 0.9245, 0.9245, 0.9245, 0.89453, 0.9245, 0.89453, 0.8675, 0.9245, 0.8675, 0.9245, 0.8675, 0.9245, 0.72346, 0.83203, 0.72346, 0.83203, 0.72346, 0.83203, 0.72346, 0.83203, 0.85193, 0.8875, 0.86477, 0.99034, 0.73206, 0.85865, 0.73206, 0.85865, 0.73206, 0.85865, 0.73206, 0.85865, 0.73206, 0.85865, 0.81105, 0.9245, 0.81105, 0.9245, 0.81105, 0.9245, 1, 1, 0.86275, 0.9245, 0.90872, 0.93591, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 1.03297, 0.90685, 0.82601, 0.77896, 1.05611, 0.6377, 1.07692, 1, 1, 0.90918, 0.75593, 1.03297, 1, 1, 0.76032, 0.9375, 0.98156, 0.93407, 0.77261, 1.11429, 0.89249, 0.9245, 1, 1, 0.89249, 0.9245, 0.92534, 0.86698, 0.9245, 0.84118, 0.92274, 0.84118, 0.92274, 0.84118, 0.92274, 0.8667, 0.86291, 0.75186, 1.02933, 1, 1, 0.75186, 1.02933, 0.67789, 0.77832, 0.67789, 0.77832, 0.67789, 0.77832, 0.67789, 0.77832, 1, 1, 0.79776, 0.97655, 0.79776, 1.23023, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.88844, 0.9245, 0.94309, 0.98986, 0.7306, 0.89453, 0.7306, 0.76659, 0.79004, 0.76659, 0.79004, 0.76659, 0.79004, 1.09231, 0.54873, 0.8675, 0.9245, 0.76318, 0.84843, 0.84557, 0.86651, 1, 1, 0.79776, 1.20562, 1.18622, 1.18622, 1, 1.1437, 0.67009, 0.96334, 0.93695, 1.35191, 1.40909, 0.95161, 1.48387, 0.8675, 0.90861, 0.6192, 0.7363, 0.64824, 0.82411, 0.56321, 0.85696, 1.23516, 0.8675, 0.81552, 0.7286, 0.84134, 0.73206, 0.76659, 0.86275, 0.84369, 0.90685, 0.77892, 0.85871, 1.02638, 0.89249, 0.75828, 0.84118, 0.85984, 0.77452, 0.76466, 0.79776, 0.7306, 0.90782, 0.77818, 0.903, 0.87291, 0.90685, 0.7306, 0.99058, 1.03667, 0.94635, 1.23516, 0.9849, 0.99058, 0.92393, 0.8916, 0.942, 1.03667, 0.75026, 0.94635, 1.0297, 1.23516, 0.90918, 0.94048, 0.98217, 0.89746, 0.84153, 0.92274, 0.82507, 0.88832, 0.84438, 0.88178, 1.03525, 0.9849, 1.00225, 0.78086, 0.97248, 0.89404, 1.23516, 0.9849, 0.92274, 0.9849, 0.89404, 0.73206, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.89693, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.85865, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.90933, 1, 1, 1, 1, 1, 1, 0.94309, 0.98986, 0.94309, 0.98986, 0.94309, 0.98986, 0.7306, 0.89453, 1, 1, 0.89552, 0.90527, 1, 0.90186, 1.12308, 1.12308, 1.12308, 1.12308, 1.2566, 1.2566, 1.2566, 0.89552, 0.89552, 1.42259, 0.68994, 1.03809, 1, 1, 1.0176, 1.0176, 1.11523, 1.4956, 2.01462, 0.97858, 0.82616, 0.91133, 0.83437, 0.91133, 1, 1, 1, 0.70508, 1, 1.23108, 0.79801, 0.84426, 0.84426, 0.774, 0.90572, 1.81055, 0.90749, 1.81055, 1.28809, 1.55469, 0.94434, 1.07806, 1, 0.97094, 0.7589, 0.85284, 0.90747, 1.19658, 0.69825, 0.97622, 1.33512, 0.90747, 0.90747, 0.85284, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.0336, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05859, 1.05859, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26959. const CalibriItalicMetrics = {
  26960. lineHeight: 1.2207,
  26961. lineGap: 0.2207
  26962. };
  26963. const CalibriRegularFactors = [1.3877, 1, 1, 1, 1.17223, 1.1293, 0.89552, 0.91133, 0.80395, 1.02269, 1.15601, 0.91056, 0.91056, 1.2798, 0.85284, 0.89807, 1, 0.90861, 1.39016, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.91133, 0.96309, 0.96309, 0.85284, 0.85284, 0.85284, 0.83319, 0.88071, 0.8675, 0.81552, 0.73834, 0.85193, 0.73206, 0.7522, 0.81105, 0.86275, 0.90685, 0.6377, 0.77892, 0.75593, 1.02638, 0.89385, 0.85122, 0.77452, 0.86503, 0.75186, 0.68887, 0.79776, 0.88844, 0.85066, 0.94258, 0.77818, 0.7306, 0.76659, 1.10369, 1.39016, 1.10369, 1.06139, 0.89552, 0.8739, 0.86128, 0.94469, 0.8457, 0.94469, 0.89464, 1.09842, 0.84636, 0.94469, 1.03297, 1.07692, 0.90918, 1.03297, 0.95897, 0.94469, 0.9482, 0.94469, 0.94469, 1.04692, 0.78223, 1.20562, 0.94469, 0.90332, 0.98986, 0.86621, 0.90527, 0.79004, 0.94152, 1.77256, 0.94152, 0.85284, 0.97801, 0.89552, 0.91133, 0.89552, 0.91133, 1.91729, 0.89552, 1.17889, 1.13254, 1.08707, 0.92098, 0.85284, 0.68787, 0.71353, 0.84737, 0.90747, 1.0088, 1.0044, 0.87683, 1, 1.09091, 1, 0.92229, 0.739, 1.15642, 0.92098, 0.76288, 0.80504, 0.80972, 0.75859, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.8675, 0.76318, 0.73834, 0.73206, 0.73206, 0.73206, 0.73206, 0.90685, 0.90685, 0.90685, 0.90685, 0.86477, 0.89385, 0.85122, 0.85122, 0.85122, 0.85122, 0.85122, 0.85284, 0.85311, 0.88844, 0.88844, 0.88844, 0.88844, 0.7306, 0.77452, 0.86331, 0.86128, 0.86128, 0.86128, 0.86128, 0.86128, 0.86128, 0.8693, 0.8457, 0.89464, 0.89464, 0.89464, 0.89464, 0.82601, 0.82601, 0.82601, 0.82601, 0.94469, 0.94469, 0.9482, 0.9482, 0.9482, 0.9482, 0.9482, 0.90747, 0.86651, 0.94469, 0.94469, 0.94469, 0.94469, 0.90527, 0.94469, 0.90527, 0.8675, 0.86128, 0.8675, 0.86128, 0.8675, 0.86128, 0.73834, 0.8457, 0.73834, 0.8457, 0.73834, 0.8457, 0.73834, 0.8457, 0.85193, 0.92454, 0.86477, 0.9921, 0.73206, 0.89464, 0.73206, 0.89464, 0.73206, 0.89464, 0.73206, 0.89464, 0.73206, 0.89464, 0.81105, 0.84636, 0.81105, 0.84636, 0.81105, 0.84636, 1, 1, 0.86275, 0.94469, 0.90872, 0.95786, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 0.82601, 0.90685, 1.03297, 0.90685, 0.82601, 0.77741, 1.05611, 0.6377, 1.07692, 1, 1, 0.90918, 0.75593, 1.03297, 1, 1, 0.76032, 0.90452, 0.98156, 1.11842, 0.77261, 1.11429, 0.89385, 0.94469, 1, 1, 0.89385, 0.94469, 0.95877, 0.86901, 0.94469, 0.85122, 0.9482, 0.85122, 0.9482, 0.85122, 0.9482, 0.8667, 0.90016, 0.75186, 1.04692, 1, 1, 0.75186, 1.04692, 0.68887, 0.78223, 0.68887, 0.78223, 0.68887, 0.78223, 0.68887, 0.78223, 1, 1, 0.79776, 0.92188, 0.79776, 1.23023, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.88844, 0.94469, 0.94258, 0.98986, 0.7306, 0.90527, 0.7306, 0.76659, 0.79004, 0.76659, 0.79004, 0.76659, 0.79004, 1.09231, 0.54873, 0.8675, 0.86128, 0.76318, 0.8693, 0.85311, 0.86651, 1, 1, 0.79776, 1.20562, 1.18622, 1.18622, 1, 1.1437, 0.67742, 0.96334, 0.93695, 1.35191, 1.40909, 0.95161, 1.48387, 0.86686, 0.90861, 0.62267, 0.74359, 0.65649, 0.85498, 0.56963, 0.88254, 1.23516, 0.8675, 0.81552, 0.75443, 0.84503, 0.73206, 0.76659, 0.86275, 0.85122, 0.90685, 0.77892, 0.85746, 1.02638, 0.89385, 0.75657, 0.85122, 0.86275, 0.77452, 0.74171, 0.79776, 0.7306, 0.95165, 0.77818, 0.89772, 0.88831, 0.90685, 0.7306, 0.98142, 1.02191, 0.96576, 1.23516, 0.99018, 0.98142, 0.9236, 0.89258, 0.94035, 1.02191, 0.78848, 0.96576, 0.9561, 1.23516, 0.90918, 0.92578, 0.95424, 0.89746, 0.83969, 0.9482, 0.80113, 0.89442, 0.85208, 0.86155, 0.98022, 0.99018, 1.00452, 0.81209, 0.99247, 0.89181, 1.23516, 0.99018, 0.9482, 0.99018, 0.89181, 0.73206, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.88844, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.89464, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.96766, 1, 1, 1, 1, 1, 1, 0.94258, 0.98986, 0.94258, 0.98986, 0.94258, 0.98986, 0.7306, 0.90527, 1, 1, 0.89552, 0.90527, 1, 0.90186, 1.12308, 1.12308, 1.12308, 1.12308, 1.2566, 1.2566, 1.2566, 0.89552, 0.89552, 1.42259, 0.69043, 1.03809, 1, 1, 1.0176, 1.0176, 1.11523, 1.4956, 2.01462, 0.99331, 0.82616, 0.91133, 0.84286, 0.91133, 1, 1, 1, 0.70508, 1, 1.23108, 0.79801, 0.84426, 0.84426, 0.774, 0.90527, 1.81055, 0.90527, 1.81055, 1.28809, 1.55469, 0.94434, 1.07806, 1, 0.97094, 0.7589, 0.85284, 0.90747, 1.19658, 0.69825, 0.97622, 1.33512, 0.90747, 0.90747, 0.85356, 0.90747, 0.90747, 1.44947, 0.85284, 0.8941, 0.8941, 0.70572, 0.8, 0.70572, 0.70572, 0.70572, 0.70572, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99862, 0.99862, 1, 1, 1, 1, 1, 1.0336, 0.91027, 1, 1, 1, 0.99862, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05859, 1.05859, 1, 1, 1, 1.07185, 0.99413, 0.96334, 1.08065, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26964. const CalibriRegularMetrics = {
  26965. lineHeight: 1.2207,
  26966. lineGap: 0.2207
  26967. };
  26968. ;// CONCATENATED MODULE: ./src/core/helvetica_factors.js
  26969. const HelveticaBoldFactors = [0.76116, 1, 1, 1.0006, 0.99998, 0.99974, 0.99973, 0.99973, 0.99982, 0.99977, 1.00087, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.00003, 1.00003, 1.00003, 1.00026, 0.9999, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 0.99973, 0.99977, 1.00026, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 0.99998, 1.0006, 0.99998, 1.00003, 0.99973, 0.99998, 0.99973, 1.00026, 0.99973, 1.00026, 0.99973, 0.99998, 1.00026, 1.00026, 1.0006, 1.0006, 0.99973, 1.0006, 0.99982, 1.00026, 1.00026, 1.00026, 1.00026, 0.99959, 0.99973, 0.99998, 1.00026, 0.99973, 1.00022, 0.99973, 0.99973, 1, 0.99959, 1.00077, 0.99959, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.00077, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.99973, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.06409, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 0.99973, 1.00026, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 1.03374, 0.99977, 1.00026, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.00042, 0.99973, 0.99973, 1.0006, 0.99977, 0.99973, 0.99973, 1.00026, 1.0006, 1.00026, 1.0006, 1.00026, 1.03828, 1.00026, 0.99999, 1.00026, 1.0006, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.9993, 0.9998, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1, 1.00016, 0.99977, 0.99959, 0.99977, 0.99959, 0.99977, 0.99959, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00026, 0.99998, 1.00026, 0.8121, 1.00026, 0.99998, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.00016, 1.00022, 1.00001, 0.99973, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 1.0006, 0.99973, 0.99977, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 0.99973, 1.00026, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 1.00034, 0.99977, 1, 0.99997, 1.00026, 1.00078, 1.00036, 0.99973, 1.00013, 1.0006, 0.99977, 0.99977, 0.99988, 0.85148, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 0.99977, 1.00001, 0.99999, 0.99977, 1.00069, 1.00022, 0.99977, 1.00001, 0.99984, 1.00026, 1.00001, 1.00024, 1.00001, 0.9999, 1, 1.0006, 1.00001, 1.00041, 0.99962, 1.00026, 1.0006, 0.99995, 1.00041, 0.99942, 0.99973, 0.99927, 1.00082, 0.99902, 1.00026, 1.00087, 1.0006, 1.00069, 0.99973, 0.99867, 0.99973, 0.9993, 1.00026, 1.00049, 1.00056, 1, 0.99988, 0.99935, 0.99995, 0.99954, 1.00055, 0.99945, 1.00032, 1.0006, 0.99995, 1.00026, 0.99995, 1.00032, 1.00001, 1.00008, 0.99971, 1.00019, 0.9994, 1.00001, 1.0006, 1.00044, 0.99973, 1.00023, 1.00047, 1, 0.99942, 0.99561, 0.99989, 1.00035, 0.99977, 1.00035, 0.99977, 1.00019, 0.99944, 1.00001, 1.00021, 0.99926, 1.00035, 1.00035, 0.99942, 1.00048, 0.99999, 0.99977, 1.00022, 1.00035, 1.00001, 0.99977, 1.00026, 0.99989, 1.00057, 1.00001, 0.99936, 1.00052, 1.00012, 0.99996, 1.00043, 1, 1.00035, 0.9994, 0.99976, 1.00035, 0.99973, 1.00052, 1.00041, 1.00119, 1.00037, 0.99973, 1.00002, 0.99986, 1.00041, 1.00041, 0.99902, 0.9996, 1.00034, 0.99999, 1.00026, 0.99999, 1.00026, 0.99973, 1.00052, 0.99973, 1, 0.99973, 1.00041, 1.00075, 0.9994, 1.0003, 0.99999, 1, 1.00041, 0.99955, 1, 0.99915, 0.99973, 0.99973, 1.00026, 1.00119, 0.99955, 0.99973, 1.0006, 0.99911, 1.0006, 1.00026, 0.99972, 1.00026, 0.99902, 1.00041, 0.99973, 0.99999, 1, 1, 1.00038, 1.0005, 1.00016, 1.00022, 1.00016, 1.00022, 1.00016, 1.00022, 1.00001, 0.99973, 1, 1, 0.99973, 1, 1, 0.99955, 1.0006, 1.0006, 1.0006, 1.0006, 1, 1, 1, 0.99973, 0.99973, 0.99972, 1, 1, 1.00106, 0.99999, 0.99998, 0.99998, 0.99999, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1.00023, 0.99973, 0.99971, 1.00047, 1.00023, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1, 1, 1, 1, 1, 1, 1, 0.99972, 1, 1.20985, 1.39713, 1.00003, 1.00031, 1.00015, 1, 0.99561, 1.00027, 1.00031, 1.00031, 0.99915, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.99972, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 0.99998, 0.99998, 0.99998, 0.99998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26970. const HelveticaBoldMetrics = {
  26971. lineHeight: 1.2,
  26972. lineGap: 0.2
  26973. };
  26974. const HelveticaBoldItalicFactors = [0.76116, 1, 1, 1.0006, 0.99998, 0.99974, 0.99973, 0.99973, 0.99982, 0.99977, 1.00087, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.00003, 1.00003, 1.00003, 1.00026, 0.9999, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 0.99973, 0.99977, 1.00026, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 0.99998, 1.0006, 0.99998, 1.00003, 0.99973, 0.99998, 0.99973, 1.00026, 0.99973, 1.00026, 0.99973, 0.99998, 1.00026, 1.00026, 1.0006, 1.0006, 0.99973, 1.0006, 0.99982, 1.00026, 1.00026, 1.00026, 1.00026, 0.99959, 0.99973, 0.99998, 1.00026, 0.99973, 1.00022, 0.99973, 0.99973, 1, 0.99959, 1.00077, 0.99959, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.00077, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.99973, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 0.99977, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 1.06409, 1.00026, 1.00026, 1.00026, 1.00026, 1.00026, 0.99973, 1.00026, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 1.0044, 0.99977, 1.00026, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 0.99971, 0.99973, 0.99973, 1.0006, 0.99977, 0.99973, 0.99973, 1.00026, 1.0006, 1.00026, 1.0006, 1.00026, 1.01011, 1.00026, 0.99999, 1.00026, 1.0006, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.9993, 0.9998, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1.00022, 1.00026, 1, 1.00016, 0.99977, 0.99959, 0.99977, 0.99959, 0.99977, 0.99959, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00026, 0.99998, 1.00026, 0.8121, 1.00026, 0.99998, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 0.99977, 1.00026, 1.00016, 1.00022, 1.00001, 0.99973, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 1.0006, 0.99973, 0.99977, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 0.99973, 1.00026, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99977, 1, 1, 1.00026, 0.99969, 0.99972, 0.99981, 0.9998, 1.0006, 0.99977, 0.99977, 1.00022, 0.91155, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 0.99977, 1.00001, 0.99999, 0.99977, 0.99966, 1.00022, 1.00032, 1.00001, 0.99944, 1.00026, 1.00001, 0.99968, 1.00001, 1.00047, 1, 1.0006, 1.00001, 0.99981, 1.00101, 1.00026, 1.0006, 0.99948, 0.99981, 1.00064, 0.99973, 0.99942, 1.00101, 1.00061, 1.00026, 1.00069, 1.0006, 1.00014, 0.99973, 1.01322, 0.99973, 1.00065, 1.00026, 1.00012, 0.99923, 1, 1.00064, 1.00076, 0.99948, 1.00055, 1.00063, 1.00007, 0.99943, 1.0006, 0.99948, 1.00026, 0.99948, 0.99943, 1.00001, 1.00001, 1.00029, 1.00038, 1.00035, 1.00001, 1.0006, 1.0006, 0.99973, 0.99978, 1.00001, 1.00057, 0.99989, 0.99967, 0.99964, 0.99967, 0.99977, 0.99999, 0.99977, 1.00038, 0.99977, 1.00001, 0.99973, 1.00066, 0.99967, 0.99967, 1.00041, 0.99998, 0.99999, 0.99977, 1.00022, 0.99967, 1.00001, 0.99977, 1.00026, 0.99964, 1.00031, 1.00001, 0.99999, 0.99999, 1, 1.00023, 1, 1, 0.99999, 1.00035, 1.00001, 0.99999, 0.99973, 0.99977, 0.99999, 1.00058, 0.99973, 0.99973, 0.99955, 0.9995, 1.00026, 1.00026, 1.00032, 0.99989, 1.00034, 0.99999, 1.00026, 1.00026, 1.00026, 0.99973, 0.45998, 0.99973, 1.00026, 0.99973, 1.00001, 0.99999, 0.99982, 0.99994, 0.99996, 1, 1.00042, 1.00044, 1.00029, 1.00023, 0.99973, 0.99973, 1.00026, 0.99949, 1.00002, 0.99973, 1.0006, 1.0006, 1.0006, 0.99975, 1.00026, 1.00026, 1.00032, 0.98685, 0.99973, 1.00026, 1, 1, 0.99966, 1.00044, 1.00016, 1.00022, 1.00016, 1.00022, 1.00016, 1.00022, 1.00001, 0.99973, 1, 1, 0.99973, 1, 1, 0.99955, 1.0006, 1.0006, 1.0006, 1.0006, 1, 1, 1, 0.99973, 0.99973, 0.99972, 1, 1, 1.00106, 0.99999, 0.99998, 0.99998, 0.99999, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1, 0.99973, 0.99971, 0.99978, 1, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1.00098, 1, 1, 1, 1.00049, 1, 1, 0.99972, 1, 1.20985, 1.39713, 1.00003, 1.00031, 1.00015, 1, 0.99561, 1.00027, 1.00031, 1.00031, 0.99915, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.99972, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 0.99998, 0.99998, 0.99998, 0.99998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26975. const HelveticaBoldItalicMetrics = {
  26976. lineHeight: 1.35,
  26977. lineGap: 0.2
  26978. };
  26979. const HelveticaItalicFactors = [0.76116, 1, 1, 1.0006, 1.0006, 1.00006, 0.99973, 0.99973, 0.99982, 1.00001, 1.00043, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1, 1.00003, 1.00003, 1.00003, 0.99973, 0.99987, 1.00001, 1.00001, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 1, 1.00001, 0.99973, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 1.0006, 1.0006, 1.0006, 0.99949, 0.99973, 0.99998, 0.99973, 0.99973, 1, 0.99973, 0.99973, 1.0006, 0.99973, 0.99973, 0.99924, 0.99924, 1, 0.99924, 0.99999, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.0006, 0.99973, 1, 0.99977, 1, 1, 1, 1.00005, 1.0009, 1.00005, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.0009, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.9998, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 1, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.06409, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 1, 0.99973, 1, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1.0288, 0.99977, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 0.99924, 1.0006, 1.0006, 0.99946, 1.00034, 1, 0.99924, 1.00001, 1, 1, 0.99973, 0.99924, 0.99973, 0.99924, 0.99973, 1.06311, 0.99973, 1.00024, 0.99973, 0.99924, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.00041, 0.9998, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1, 1.00016, 0.99977, 0.99998, 0.99977, 0.99998, 0.99977, 0.99998, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00026, 1.0006, 1.00026, 0.89547, 1.00026, 1.0006, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.00016, 0.99977, 1.00001, 1, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 0.99924, 0.99973, 1.00001, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 1, 1.00026, 1.0006, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 1.00001, 1, 1.00054, 0.99977, 1.00084, 1.00007, 0.99973, 1.00013, 0.99924, 1.00001, 1.00001, 0.99945, 0.91221, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 1.00001, 1.00001, 0.99999, 0.99977, 0.99933, 1.00022, 1.00054, 1.00001, 1.00065, 1.00026, 1.00001, 1.0001, 1.00001, 1.00052, 1, 1.0006, 1.00001, 0.99945, 0.99897, 0.99968, 0.99924, 1.00036, 0.99945, 0.99949, 1, 1.0006, 0.99897, 0.99918, 0.99968, 0.99911, 0.99924, 1, 0.99962, 1.01487, 1, 1.0005, 0.99973, 1.00012, 1.00043, 1, 0.99995, 0.99994, 1.00036, 0.99947, 1.00019, 1.00063, 1.00025, 0.99924, 1.00036, 0.99973, 1.00036, 1.00025, 1.00001, 1.00001, 1.00027, 1.0001, 1.00068, 1.00001, 1.0006, 1.0006, 1, 1.00008, 0.99957, 0.99972, 0.9994, 0.99954, 0.99975, 1.00051, 1.00001, 1.00019, 1.00001, 1.0001, 0.99986, 1.00001, 1.00001, 1.00038, 0.99954, 0.99954, 0.9994, 1.00066, 0.99999, 0.99977, 1.00022, 1.00054, 1.00001, 0.99977, 1.00026, 0.99975, 1.0001, 1.00001, 0.99993, 0.9995, 0.99955, 1.00016, 0.99978, 0.99974, 1.00019, 1.00022, 0.99955, 1.00053, 0.99973, 1.00089, 1.00005, 0.99967, 1.00048, 0.99973, 1.00002, 1.00034, 0.99973, 0.99973, 0.99964, 1.00006, 1.00066, 0.99947, 0.99973, 0.98894, 0.99973, 1, 0.44898, 1, 0.99946, 1, 1.00039, 1.00082, 0.99991, 0.99991, 0.99985, 1.00022, 1.00023, 1.00061, 1.00006, 0.99966, 0.99973, 0.99973, 0.99973, 1.00019, 1.0008, 1, 0.99924, 0.99924, 0.99924, 0.99983, 1.00044, 0.99973, 0.99964, 0.98332, 1, 0.99973, 1, 1, 0.99962, 0.99895, 1.00016, 0.99977, 1.00016, 0.99977, 1.00016, 0.99977, 1.00001, 1, 1, 1, 0.99973, 1, 1, 0.99955, 0.99924, 0.99924, 0.99924, 0.99924, 0.99998, 0.99998, 0.99998, 0.99973, 0.99973, 0.99972, 1, 1, 1.00267, 0.99999, 0.99998, 0.99998, 1, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1.00023, 0.99973, 1.00423, 0.99925, 0.99999, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1.00049, 1, 1.00245, 1, 1, 1, 1, 0.96329, 1, 1.20985, 1.39713, 1.00003, 0.8254, 1.00015, 1, 1.00035, 1.00027, 1.00031, 1.00031, 1.00003, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.95317, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 0.99998, 0.99998, 0.99998, 0.99998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26980. const HelveticaItalicMetrics = {
  26981. lineHeight: 1.35,
  26982. lineGap: 0.2
  26983. };
  26984. const HelveticaRegularFactors = [0.76116, 1, 1, 1.0006, 1.0006, 1.00006, 0.99973, 0.99973, 0.99982, 1.00001, 1.00043, 0.99998, 0.99998, 0.99959, 1.00003, 1.0006, 0.99998, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1, 1.00003, 1.00003, 1.00003, 0.99973, 0.99987, 1.00001, 1.00001, 0.99977, 0.99977, 1.00001, 1.00026, 1.00022, 0.99977, 1.0006, 1, 1.00001, 0.99973, 0.99999, 0.99977, 1.00022, 1.00001, 1.00022, 0.99977, 1.00001, 1.00026, 0.99977, 1.00001, 1.00016, 1.00001, 1.00001, 1.00026, 1.0006, 1.0006, 1.0006, 0.99949, 0.99973, 0.99998, 0.99973, 0.99973, 1, 0.99973, 0.99973, 1.0006, 0.99973, 0.99973, 0.99924, 0.99924, 1, 0.99924, 0.99999, 0.99973, 0.99973, 0.99973, 0.99973, 0.99998, 1, 1.0006, 0.99973, 1, 0.99977, 1, 1, 1, 1.00005, 1.0009, 1.00005, 1.00003, 0.99998, 0.99973, 0.99973, 0.99973, 0.99973, 1.0009, 0.99973, 0.99998, 1.00025, 0.99968, 0.99973, 1.00003, 1.00025, 0.60299, 1.00024, 1.06409, 1, 1, 0.99998, 1, 0.9998, 1.0006, 0.99998, 1, 0.99936, 0.99973, 1.00002, 1.00002, 1.00002, 1.00026, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1.00001, 1, 0.99977, 1.00001, 1.00001, 1.00001, 1.00001, 1.0006, 1.0006, 1.0006, 1.0006, 0.99977, 0.99977, 1.00022, 1.00022, 1.00022, 1.00022, 1.00022, 1.00003, 1.00022, 0.99977, 0.99977, 0.99977, 0.99977, 1.00001, 1.00001, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99982, 1, 0.99973, 0.99973, 0.99973, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 0.99973, 1.06409, 1.00026, 0.99973, 0.99973, 0.99973, 0.99973, 1, 0.99973, 1, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1, 0.99977, 1.04596, 0.99977, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00001, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 1.0006, 0.99924, 1.0006, 1.0006, 1.00019, 1.00034, 1, 0.99924, 1.00001, 1, 1, 0.99973, 0.99924, 0.99973, 0.99924, 0.99973, 1.02572, 0.99973, 1.00005, 0.99973, 0.99924, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99999, 0.9998, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1.00022, 0.99973, 1, 1.00016, 0.99977, 0.99998, 0.99977, 0.99998, 0.99977, 0.99998, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00001, 1, 1.00026, 1.0006, 1.00026, 0.84533, 1.00026, 1.0006, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 0.99977, 0.99973, 1.00016, 0.99977, 1.00001, 1, 1.00001, 1.00026, 1, 1.00026, 1, 1.00026, 1, 0.99924, 0.99973, 1.00001, 0.99973, 1, 0.99982, 1.00022, 1.00026, 1.00001, 1, 1.00026, 1.0006, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99998, 0.99928, 1, 0.99977, 1.00013, 1.00055, 0.99947, 0.99945, 0.99941, 0.99924, 1.00001, 1.00001, 1.0004, 0.91621, 1.00001, 1.00026, 0.99977, 1.00022, 1.0006, 1.00001, 1.00005, 0.99999, 0.99977, 1.00015, 1.00022, 0.99977, 1.00001, 0.99973, 1.00026, 1.00001, 1.00019, 1.00001, 0.99946, 1, 1.0006, 1.00001, 0.99978, 1.00045, 0.99973, 0.99924, 1.00023, 0.99978, 0.99966, 1, 1.00065, 1.00045, 1.00019, 0.99973, 0.99973, 0.99924, 1, 1, 0.96499, 1, 1.00055, 0.99973, 1.00008, 1.00027, 1, 0.9997, 0.99995, 1.00023, 0.99933, 1.00019, 1.00015, 1.00031, 0.99924, 1.00023, 0.99973, 1.00023, 1.00031, 1.00001, 0.99928, 1.00029, 1.00092, 1.00035, 1.00001, 1.0006, 1.0006, 1, 0.99988, 0.99975, 1, 1.00082, 0.99561, 0.9996, 1.00035, 1.00001, 0.99962, 1.00001, 1.00092, 0.99964, 1.00001, 0.99963, 0.99999, 1.00035, 1.00035, 1.00082, 0.99962, 0.99999, 0.99977, 1.00022, 1.00035, 1.00001, 0.99977, 1.00026, 0.9996, 0.99967, 1.00001, 1.00034, 1.00074, 1.00054, 1.00053, 1.00063, 0.99971, 0.99962, 1.00035, 0.99975, 0.99977, 0.99973, 1.00043, 0.99953, 1.0007, 0.99915, 0.99973, 1.00008, 0.99892, 1.00073, 1.00073, 1.00114, 0.99915, 1.00073, 0.99955, 0.99973, 1.00092, 0.99973, 1, 0.99998, 1, 1.0003, 1, 1.00043, 1.00001, 0.99969, 1.0003, 1, 1.00035, 1.00001, 0.9995, 1, 1.00092, 0.99973, 0.99973, 0.99973, 1.0007, 0.9995, 1, 0.99924, 1.0006, 0.99924, 0.99972, 1.00062, 0.99973, 1.00114, 1.00073, 1, 0.99955, 1, 1, 1.00047, 0.99968, 1.00016, 0.99977, 1.00016, 0.99977, 1.00016, 0.99977, 1.00001, 1, 1, 1, 0.99973, 1, 1, 0.99955, 0.99924, 0.99924, 0.99924, 0.99924, 0.99998, 0.99998, 0.99998, 0.99973, 0.99973, 0.99972, 1, 1, 1.00267, 0.99999, 0.99998, 0.99998, 1, 0.99998, 1.66475, 1, 0.99973, 0.99973, 1.00023, 0.99973, 0.99971, 0.99925, 1.00023, 1, 0.99991, 0.99984, 1.00002, 1.00002, 1.00002, 1.00002, 1, 1, 1, 1, 1, 1, 1, 0.96329, 1, 1.20985, 1.39713, 1.00003, 0.8254, 1.00015, 1, 1.00035, 1.00027, 1.00031, 1.00031, 0.99915, 1.00031, 1.00031, 0.99999, 1.00003, 0.99999, 0.99999, 1.41144, 1.6, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.41144, 1.40579, 1.40579, 1.36625, 0.99999, 1, 0.99861, 0.99861, 1, 1.00026, 1.00026, 1.00026, 1.00026, 0.95317, 0.99999, 0.99999, 0.99999, 0.99999, 1.40483, 1, 0.99977, 1.00054, 1, 1, 0.99953, 0.99962, 1.00042, 0.9995, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  26985. const HelveticaRegularMetrics = {
  26986. lineHeight: 1.2,
  26987. lineGap: 0.2
  26988. };
  26989. ;// CONCATENATED MODULE: ./src/core/liberationsans_widths.js
  26990. const LiberationSansBoldWidths = [365, 0, 333, 278, 333, 474, 556, 556, 889, 722, 238, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 333, 584, 584, 584, 611, 975, 722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 333, 278, 333, 584, 556, 333, 556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611, 611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584, 333, 556, 556, 556, 556, 280, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 556, 278, 333, 333, 365, 556, 834, 834, 834, 611, 722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 556, 556, 556, 556, 556, 278, 278, 278, 278, 611, 611, 611, 611, 611, 611, 611, 549, 611, 611, 611, 611, 611, 556, 611, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 719, 722, 611, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 611, 778, 611, 778, 611, 778, 611, 722, 611, 722, 611, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 785, 556, 556, 278, 722, 556, 556, 611, 278, 611, 278, 611, 385, 611, 479, 611, 278, 722, 611, 722, 611, 722, 611, 708, 723, 611, 778, 611, 778, 611, 778, 611, 1000, 944, 722, 389, 722, 389, 722, 389, 667, 556, 667, 556, 667, 556, 667, 556, 611, 333, 611, 479, 611, 333, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 944, 778, 667, 556, 667, 611, 500, 611, 500, 611, 500, 278, 556, 722, 556, 1000, 889, 778, 611, 667, 556, 611, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 465, 722, 333, 853, 906, 474, 825, 927, 838, 278, 722, 722, 601, 719, 667, 611, 722, 778, 278, 722, 667, 833, 722, 644, 778, 722, 667, 600, 611, 667, 821, 667, 809, 802, 278, 667, 615, 451, 611, 278, 582, 615, 610, 556, 606, 475, 460, 611, 541, 278, 558, 556, 612, 556, 445, 611, 766, 619, 520, 684, 446, 582, 715, 576, 753, 845, 278, 582, 611, 582, 845, 667, 669, 885, 567, 711, 667, 278, 276, 556, 1094, 1062, 875, 610, 722, 622, 719, 722, 719, 722, 567, 712, 667, 904, 626, 719, 719, 610, 702, 833, 722, 778, 719, 667, 722, 611, 622, 854, 667, 730, 703, 1005, 1019, 870, 979, 719, 711, 1031, 719, 556, 618, 615, 417, 635, 556, 709, 497, 615, 615, 500, 635, 740, 604, 611, 604, 611, 556, 490, 556, 875, 556, 615, 581, 833, 844, 729, 854, 615, 552, 854, 583, 556, 556, 611, 417, 552, 556, 278, 281, 278, 969, 906, 611, 500, 615, 556, 604, 778, 611, 487, 447, 944, 778, 944, 778, 944, 778, 667, 556, 333, 333, 556, 1000, 1000, 552, 278, 278, 278, 278, 500, 500, 500, 556, 556, 350, 1000, 1000, 240, 479, 333, 333, 604, 333, 167, 396, 556, 556, 1094, 556, 885, 489, 1115, 1000, 768, 600, 834, 834, 834, 834, 1000, 500, 1000, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 722, 274, 549, 549, 583, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 611, 611, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 333, 333, 333, 333, 333, 333, 333, 333];
  26991. const LiberationSansBoldMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
  26992. const LiberationSansBoldItalicWidths = [365, 0, 333, 278, 333, 474, 556, 556, 889, 722, 238, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 333, 333, 584, 584, 584, 611, 975, 722, 722, 722, 722, 667, 611, 778, 722, 278, 556, 722, 611, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 333, 278, 333, 584, 556, 333, 556, 611, 556, 611, 556, 333, 611, 611, 278, 278, 556, 278, 889, 611, 611, 611, 611, 389, 556, 333, 611, 556, 778, 556, 556, 500, 389, 280, 389, 584, 333, 556, 556, 556, 556, 280, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 556, 278, 333, 333, 365, 556, 834, 834, 834, 611, 722, 722, 722, 722, 722, 722, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 556, 556, 556, 556, 556, 278, 278, 278, 278, 611, 611, 611, 611, 611, 611, 611, 549, 611, 611, 611, 611, 611, 556, 611, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 740, 722, 611, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 611, 778, 611, 778, 611, 778, 611, 722, 611, 722, 611, 278, 278, 278, 278, 278, 278, 278, 278, 278, 278, 782, 556, 556, 278, 722, 556, 556, 611, 278, 611, 278, 611, 396, 611, 479, 611, 278, 722, 611, 722, 611, 722, 611, 708, 723, 611, 778, 611, 778, 611, 778, 611, 1000, 944, 722, 389, 722, 389, 722, 389, 667, 556, 667, 556, 667, 556, 667, 556, 611, 333, 611, 479, 611, 333, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 722, 611, 944, 778, 667, 556, 667, 611, 500, 611, 500, 611, 500, 278, 556, 722, 556, 1000, 889, 778, 611, 667, 556, 611, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 722, 333, 854, 906, 473, 844, 930, 847, 278, 722, 722, 610, 671, 667, 611, 722, 778, 278, 722, 667, 833, 722, 657, 778, 718, 667, 590, 611, 667, 822, 667, 829, 781, 278, 667, 620, 479, 611, 278, 591, 620, 621, 556, 610, 479, 492, 611, 558, 278, 566, 556, 603, 556, 450, 611, 712, 605, 532, 664, 409, 591, 704, 578, 773, 834, 278, 591, 611, 591, 834, 667, 667, 886, 614, 719, 667, 278, 278, 556, 1094, 1042, 854, 622, 719, 677, 719, 722, 708, 722, 614, 722, 667, 927, 643, 719, 719, 615, 687, 833, 722, 778, 719, 667, 722, 611, 677, 781, 667, 729, 708, 979, 989, 854, 1000, 708, 719, 1042, 729, 556, 619, 604, 534, 618, 556, 736, 510, 611, 611, 507, 622, 740, 604, 611, 611, 611, 556, 889, 556, 885, 556, 646, 583, 889, 935, 707, 854, 594, 552, 865, 589, 556, 556, 611, 469, 563, 556, 278, 278, 278, 969, 906, 611, 507, 619, 556, 611, 778, 611, 575, 467, 944, 778, 944, 778, 944, 778, 667, 556, 333, 333, 556, 1000, 1000, 552, 278, 278, 278, 278, 500, 500, 500, 556, 556, 350, 1000, 1000, 240, 479, 333, 333, 604, 333, 167, 396, 556, 556, 1104, 556, 885, 516, 1146, 1000, 768, 600, 834, 834, 834, 834, 999, 500, 1000, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 722, 274, 549, 549, 583, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 611, 611, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 333, 333, 333, 333, 333, 333, 333, 333];
  26993. const LiberationSansBoldItalicMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
  26994. const LiberationSansItalicWidths = [365, 0, 333, 278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584, 333, 556, 556, 556, 556, 260, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 537, 278, 333, 333, 365, 556, 834, 834, 834, 611, 667, 667, 667, 667, 667, 667, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 500, 556, 556, 556, 556, 278, 278, 278, 278, 556, 556, 556, 556, 556, 556, 556, 549, 611, 556, 556, 556, 556, 500, 556, 500, 667, 556, 667, 556, 667, 556, 722, 500, 722, 500, 722, 500, 722, 500, 722, 625, 722, 556, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 556, 778, 556, 778, 556, 778, 556, 722, 556, 722, 556, 278, 278, 278, 278, 278, 278, 278, 222, 278, 278, 733, 444, 500, 222, 667, 500, 500, 556, 222, 556, 222, 556, 281, 556, 400, 556, 222, 722, 556, 722, 556, 722, 556, 615, 723, 556, 778, 556, 778, 556, 778, 556, 1000, 944, 722, 333, 722, 333, 722, 333, 667, 500, 667, 500, 667, 500, 667, 500, 611, 278, 611, 354, 611, 278, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 944, 722, 667, 500, 667, 611, 500, 611, 500, 611, 500, 222, 556, 667, 556, 1000, 889, 778, 611, 667, 500, 611, 278, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 667, 278, 789, 846, 389, 794, 865, 775, 222, 667, 667, 570, 671, 667, 611, 722, 778, 278, 667, 667, 833, 722, 648, 778, 725, 667, 600, 611, 667, 837, 667, 831, 761, 278, 667, 570, 439, 555, 222, 550, 570, 571, 500, 556, 439, 463, 555, 542, 222, 500, 492, 548, 500, 447, 556, 670, 573, 486, 603, 374, 550, 652, 546, 728, 779, 222, 550, 556, 550, 779, 667, 667, 843, 544, 708, 667, 278, 278, 500, 1066, 982, 844, 589, 715, 639, 724, 667, 651, 667, 544, 704, 667, 917, 614, 715, 715, 589, 686, 833, 722, 778, 725, 667, 722, 611, 639, 795, 667, 727, 673, 920, 923, 805, 886, 651, 694, 1022, 682, 556, 562, 522, 493, 553, 556, 688, 465, 556, 556, 472, 564, 686, 550, 556, 556, 556, 500, 833, 500, 835, 500, 572, 518, 830, 851, 621, 736, 526, 492, 752, 534, 556, 556, 556, 378, 496, 500, 222, 222, 222, 910, 828, 556, 472, 565, 500, 556, 778, 556, 492, 339, 944, 722, 944, 722, 944, 722, 667, 500, 333, 333, 556, 1000, 1000, 552, 222, 222, 222, 222, 333, 333, 333, 556, 556, 350, 1000, 1000, 188, 354, 333, 333, 500, 333, 167, 365, 556, 556, 1094, 556, 885, 323, 1083, 1000, 768, 600, 834, 834, 834, 834, 1000, 500, 998, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 719, 274, 549, 549, 584, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 500, 500, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 294, 294, 324, 324, 316, 328, 398, 285];
  26995. const LiberationSansItalicMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
  26996. const LiberationSansRegularWidths = [365, 0, 333, 278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584, 333, 556, 556, 556, 556, 260, 556, 333, 737, 370, 556, 584, 737, 552, 400, 549, 333, 333, 333, 576, 537, 278, 333, 333, 365, 556, 834, 834, 834, 611, 667, 667, 667, 667, 667, 667, 1000, 722, 667, 667, 667, 667, 278, 278, 278, 278, 722, 722, 778, 778, 778, 778, 778, 584, 778, 722, 722, 722, 722, 667, 667, 611, 556, 556, 556, 556, 556, 556, 889, 500, 556, 556, 556, 556, 278, 278, 278, 278, 556, 556, 556, 556, 556, 556, 556, 549, 611, 556, 556, 556, 556, 500, 556, 500, 667, 556, 667, 556, 667, 556, 722, 500, 722, 500, 722, 500, 722, 500, 722, 615, 722, 556, 667, 556, 667, 556, 667, 556, 667, 556, 667, 556, 778, 556, 778, 556, 778, 556, 778, 556, 722, 556, 722, 556, 278, 278, 278, 278, 278, 278, 278, 222, 278, 278, 735, 444, 500, 222, 667, 500, 500, 556, 222, 556, 222, 556, 292, 556, 334, 556, 222, 722, 556, 722, 556, 722, 556, 604, 723, 556, 778, 556, 778, 556, 778, 556, 1000, 944, 722, 333, 722, 333, 722, 333, 667, 500, 667, 500, 667, 500, 667, 500, 611, 278, 611, 375, 611, 278, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 722, 556, 944, 722, 667, 500, 667, 611, 500, 611, 500, 611, 500, 222, 556, 667, 556, 1000, 889, 778, 611, 667, 500, 611, 278, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 667, 278, 784, 838, 384, 774, 855, 752, 222, 667, 667, 551, 668, 667, 611, 722, 778, 278, 667, 668, 833, 722, 650, 778, 722, 667, 618, 611, 667, 798, 667, 835, 748, 278, 667, 578, 446, 556, 222, 547, 578, 575, 500, 557, 446, 441, 556, 556, 222, 500, 500, 576, 500, 448, 556, 690, 569, 482, 617, 395, 547, 648, 525, 713, 781, 222, 547, 556, 547, 781, 667, 667, 865, 542, 719, 667, 278, 278, 500, 1057, 1010, 854, 583, 722, 635, 719, 667, 656, 667, 542, 677, 667, 923, 604, 719, 719, 583, 656, 833, 722, 778, 719, 667, 722, 611, 635, 760, 667, 740, 667, 917, 938, 792, 885, 656, 719, 1010, 722, 556, 573, 531, 365, 583, 556, 669, 458, 559, 559, 438, 583, 688, 552, 556, 542, 556, 500, 458, 500, 823, 500, 573, 521, 802, 823, 625, 719, 521, 510, 750, 542, 556, 556, 556, 365, 510, 500, 222, 278, 222, 906, 812, 556, 438, 559, 500, 552, 778, 556, 489, 411, 944, 722, 944, 722, 944, 722, 667, 500, 333, 333, 556, 1000, 1000, 552, 222, 222, 222, 222, 333, 333, 333, 556, 556, 350, 1000, 1000, 188, 354, 333, 333, 500, 333, 167, 365, 556, 556, 1094, 556, 885, 323, 1073, 1000, 768, 600, 834, 834, 834, 834, 1000, 500, 1000, 500, 1000, 500, 500, 494, 612, 823, 713, 584, 549, 713, 979, 719, 274, 549, 549, 583, 549, 549, 604, 584, 604, 604, 708, 625, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 708, 729, 604, 604, 354, 354, 1000, 990, 990, 990, 990, 494, 604, 604, 604, 604, 354, 1021, 1052, 917, 750, 750, 531, 656, 594, 510, 500, 750, 750, 500, 500, 333, 333, 333, 333, 333, 333, 333, 333, 222, 222, 294, 294, 324, 324, 316, 328, 398, 285];
  26997. const LiberationSansRegularMapping = [-1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 402, 506, 507, 508, 509, 510, 511, 536, 537, 538, 539, 710, 711, 713, 728, 729, 730, 731, 732, 733, 900, 901, 902, 903, 904, 905, 906, 908, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1138, 1139, 1168, 1169, 7808, 7809, 7810, 7811, 7812, 7813, 7922, 7923, 8208, 8209, 8211, 8212, 8213, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8224, 8225, 8226, 8230, 8240, 8242, 8243, 8249, 8250, 8252, 8254, 8260, 8319, 8355, 8356, 8359, 8364, 8453, 8467, 8470, 8482, 8486, 8494, 8539, 8540, 8541, 8542, 8592, 8593, 8594, 8595, 8596, 8597, 8616, 8706, 8710, 8719, 8721, 8722, 8730, 8734, 8735, 8745, 8747, 8776, 8800, 8801, 8804, 8805, 8962, 8976, 8992, 8993, 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9600, 9604, 9608, 9612, 9616, 9617, 9618, 9619, 9632, 9633, 9642, 9643, 9644, 9650, 9658, 9660, 9668, 9674, 9675, 9679, 9688, 9689, 9702, 9786, 9787, 9788, 9792, 9794, 9824, 9827, 9829, 9830, 9834, 9835, 9836, 61441, 61442, 61445, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1];
  26998. ;// CONCATENATED MODULE: ./src/core/myriadpro_factors.js
  26999. const MyriadProBoldFactors = [1.36898, 1, 1, 0.72706, 0.80479, 0.83734, 0.98894, 0.99793, 0.9897, 0.93884, 0.86209, 0.94292, 0.94292, 1.16661, 1.02058, 0.93582, 0.96694, 0.93582, 1.19137, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.99793, 0.78076, 0.78076, 1.02058, 1.02058, 1.02058, 0.72851, 0.78966, 0.90838, 0.83637, 0.82391, 0.96376, 0.80061, 0.86275, 0.8768, 0.95407, 1.0258, 0.73901, 0.85022, 0.83655, 1.0156, 0.95546, 0.92179, 0.87107, 0.92179, 0.82114, 0.8096, 0.89713, 0.94438, 0.95353, 0.94083, 0.91905, 0.90406, 0.9446, 0.94292, 1.18777, 0.94292, 1.02058, 0.89903, 0.90088, 0.94938, 0.97898, 0.81093, 0.97571, 0.94938, 1.024, 0.9577, 0.95933, 0.98621, 1.0474, 0.97455, 0.98981, 0.9672, 0.95933, 0.9446, 0.97898, 0.97407, 0.97646, 0.78036, 1.10208, 0.95442, 0.95298, 0.97579, 0.9332, 0.94039, 0.938, 0.80687, 1.01149, 0.80687, 1.02058, 0.80479, 0.99793, 0.99793, 0.99793, 0.99793, 1.01149, 1.00872, 0.90088, 0.91882, 1.0213, 0.8361, 1.02058, 0.62295, 0.54324, 0.89022, 1.08595, 1, 1, 0.90088, 1, 0.97455, 0.93582, 0.90088, 1, 1.05686, 0.8361, 0.99642, 0.99642, 0.99642, 0.72851, 0.90838, 0.90838, 0.90838, 0.90838, 0.90838, 0.90838, 0.868, 0.82391, 0.80061, 0.80061, 0.80061, 0.80061, 1.0258, 1.0258, 1.0258, 1.0258, 0.97484, 0.95546, 0.92179, 0.92179, 0.92179, 0.92179, 0.92179, 1.02058, 0.92179, 0.94438, 0.94438, 0.94438, 0.94438, 0.90406, 0.86958, 0.98225, 0.94938, 0.94938, 0.94938, 0.94938, 0.94938, 0.94938, 0.9031, 0.81093, 0.94938, 0.94938, 0.94938, 0.94938, 0.98621, 0.98621, 0.98621, 0.98621, 0.93969, 0.95933, 0.9446, 0.9446, 0.9446, 0.9446, 0.9446, 1.08595, 0.9446, 0.95442, 0.95442, 0.95442, 0.95442, 0.94039, 0.97898, 0.94039, 0.90838, 0.94938, 0.90838, 0.94938, 0.90838, 0.94938, 0.82391, 0.81093, 0.82391, 0.81093, 0.82391, 0.81093, 0.82391, 0.81093, 0.96376, 0.84313, 0.97484, 0.97571, 0.80061, 0.94938, 0.80061, 0.94938, 0.80061, 0.94938, 0.80061, 0.94938, 0.80061, 0.94938, 0.8768, 0.9577, 0.8768, 0.9577, 0.8768, 0.9577, 1, 1, 0.95407, 0.95933, 0.97069, 0.95933, 1.0258, 0.98621, 1.0258, 0.98621, 1.0258, 0.98621, 1.0258, 0.98621, 1.0258, 0.98621, 0.887, 1.01591, 0.73901, 1.0474, 1, 1, 0.97455, 0.83655, 0.98981, 1, 1, 0.83655, 0.73977, 0.83655, 0.73903, 0.84638, 1.033, 0.95546, 0.95933, 1, 1, 0.95546, 0.95933, 0.8271, 0.95417, 0.95933, 0.92179, 0.9446, 0.92179, 0.9446, 0.92179, 0.9446, 0.936, 0.91964, 0.82114, 0.97646, 1, 1, 0.82114, 0.97646, 0.8096, 0.78036, 0.8096, 0.78036, 1, 1, 0.8096, 0.78036, 1, 1, 0.89713, 0.77452, 0.89713, 1.10208, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94438, 0.95442, 0.94083, 0.97579, 0.90406, 0.94039, 0.90406, 0.9446, 0.938, 0.9446, 0.938, 0.9446, 0.938, 1, 0.99793, 0.90838, 0.94938, 0.868, 0.9031, 0.92179, 0.9446, 1, 1, 0.89713, 1.10208, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90989, 0.9358, 0.91945, 0.83181, 0.75261, 0.87992, 0.82976, 0.96034, 0.83689, 0.97268, 1.0078, 0.90838, 0.83637, 0.8019, 0.90157, 0.80061, 0.9446, 0.95407, 0.92436, 1.0258, 0.85022, 0.97153, 1.0156, 0.95546, 0.89192, 0.92179, 0.92361, 0.87107, 0.96318, 0.89713, 0.93704, 0.95638, 0.91905, 0.91709, 0.92796, 1.0258, 0.93704, 0.94836, 1.0373, 0.95933, 1.0078, 0.95871, 0.94836, 0.96174, 0.92601, 0.9498, 0.98607, 0.95776, 0.95933, 1.05453, 1.0078, 0.98275, 0.9314, 0.95617, 0.91701, 1.05993, 0.9446, 0.78367, 0.9553, 1, 0.86832, 1.0128, 0.95871, 0.99394, 0.87548, 0.96361, 0.86774, 1.0078, 0.95871, 0.9446, 0.95871, 0.86774, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.94083, 0.97579, 0.94083, 0.97579, 0.94083, 0.97579, 0.90406, 0.94039, 0.96694, 1, 0.89903, 1, 1, 1, 0.93582, 0.93582, 0.93582, 1, 0.908, 0.908, 0.918, 0.94219, 0.94219, 0.96544, 1, 1.285, 1, 1, 0.81079, 0.81079, 1, 1, 0.74854, 1, 1, 1, 1, 0.99793, 1, 1, 1, 0.65, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.17173, 1, 0.80535, 0.76169, 1.02058, 1.0732, 1.05486, 1, 1, 1.30692, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.16161, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27000. const MyriadProBoldMetrics = {
  27001. lineHeight: 1.2,
  27002. lineGap: 0.2
  27003. };
  27004. const MyriadProBoldItalicFactors = [1.36898, 1, 1, 0.66227, 0.80779, 0.81625, 0.97276, 0.97276, 0.97733, 0.92222, 0.83266, 0.94292, 0.94292, 1.16148, 1.02058, 0.93582, 0.96694, 0.93582, 1.17337, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.97276, 0.78076, 0.78076, 1.02058, 1.02058, 1.02058, 0.71541, 0.76813, 0.85576, 0.80591, 0.80729, 0.94299, 0.77512, 0.83655, 0.86523, 0.92222, 0.98621, 0.71743, 0.81698, 0.79726, 0.98558, 0.92222, 0.90637, 0.83809, 0.90637, 0.80729, 0.76463, 0.86275, 0.90699, 0.91605, 0.9154, 0.85308, 0.85458, 0.90531, 0.94292, 1.21296, 0.94292, 1.02058, 0.89903, 1.18616, 0.99613, 0.91677, 0.78216, 0.91677, 0.90083, 0.98796, 0.9135, 0.92168, 0.95381, 0.98981, 0.95298, 0.95381, 0.93459, 0.92168, 0.91513, 0.92004, 0.91677, 0.95077, 0.748, 1.04502, 0.91677, 0.92061, 0.94236, 0.89544, 0.89364, 0.9, 0.80687, 0.8578, 0.80687, 1.02058, 0.80779, 0.97276, 0.97276, 0.97276, 0.97276, 0.8578, 0.99973, 1.18616, 0.91339, 1.08074, 0.82891, 1.02058, 0.55509, 0.71526, 0.89022, 1.08595, 1, 1, 1.18616, 1, 0.96736, 0.93582, 1.18616, 1, 1.04864, 0.82711, 0.99043, 0.99043, 0.99043, 0.71541, 0.85576, 0.85576, 0.85576, 0.85576, 0.85576, 0.85576, 0.845, 0.80729, 0.77512, 0.77512, 0.77512, 0.77512, 0.98621, 0.98621, 0.98621, 0.98621, 0.95961, 0.92222, 0.90637, 0.90637, 0.90637, 0.90637, 0.90637, 1.02058, 0.90251, 0.90699, 0.90699, 0.90699, 0.90699, 0.85458, 0.83659, 0.94951, 0.99613, 0.99613, 0.99613, 0.99613, 0.99613, 0.99613, 0.85811, 0.78216, 0.90083, 0.90083, 0.90083, 0.90083, 0.95381, 0.95381, 0.95381, 0.95381, 0.9135, 0.92168, 0.91513, 0.91513, 0.91513, 0.91513, 0.91513, 1.08595, 0.91677, 0.91677, 0.91677, 0.91677, 0.91677, 0.89364, 0.92332, 0.89364, 0.85576, 0.99613, 0.85576, 0.99613, 0.85576, 0.99613, 0.80729, 0.78216, 0.80729, 0.78216, 0.80729, 0.78216, 0.80729, 0.78216, 0.94299, 0.76783, 0.95961, 0.91677, 0.77512, 0.90083, 0.77512, 0.90083, 0.77512, 0.90083, 0.77512, 0.90083, 0.77512, 0.90083, 0.86523, 0.9135, 0.86523, 0.9135, 0.86523, 0.9135, 1, 1, 0.92222, 0.92168, 0.92222, 0.92168, 0.98621, 0.95381, 0.98621, 0.95381, 0.98621, 0.95381, 0.98621, 0.95381, 0.98621, 0.95381, 0.86036, 0.97096, 0.71743, 0.98981, 1, 1, 0.95298, 0.79726, 0.95381, 1, 1, 0.79726, 0.6894, 0.79726, 0.74321, 0.81691, 1.0006, 0.92222, 0.92168, 1, 1, 0.92222, 0.92168, 0.79464, 0.92098, 0.92168, 0.90637, 0.91513, 0.90637, 0.91513, 0.90637, 0.91513, 0.909, 0.87514, 0.80729, 0.95077, 1, 1, 0.80729, 0.95077, 0.76463, 0.748, 0.76463, 0.748, 1, 1, 0.76463, 0.748, 1, 1, 0.86275, 0.72651, 0.86275, 1.04502, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.90699, 0.91677, 0.9154, 0.94236, 0.85458, 0.89364, 0.85458, 0.90531, 0.9, 0.90531, 0.9, 0.90531, 0.9, 1, 0.97276, 0.85576, 0.99613, 0.845, 0.85811, 0.90251, 0.91677, 1, 1, 0.86275, 1.04502, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.18616, 1.00899, 1.30628, 0.85576, 0.80178, 0.66862, 0.7927, 0.69323, 0.88127, 0.72459, 0.89711, 0.95381, 0.85576, 0.80591, 0.7805, 0.94729, 0.77512, 0.90531, 0.92222, 0.90637, 0.98621, 0.81698, 0.92655, 0.98558, 0.92222, 0.85359, 0.90637, 0.90976, 0.83809, 0.94523, 0.86275, 0.83509, 0.93157, 0.85308, 0.83392, 0.92346, 0.98621, 0.83509, 0.92886, 0.91324, 0.92168, 0.95381, 0.90646, 0.92886, 0.90557, 0.86847, 0.90276, 0.91324, 0.86842, 0.92168, 0.99531, 0.95381, 0.9224, 0.85408, 0.92699, 0.86847, 1.0051, 0.91513, 0.80487, 0.93481, 1, 0.88159, 1.05214, 0.90646, 0.97355, 0.81539, 0.89398, 0.85923, 0.95381, 0.90646, 0.91513, 0.90646, 0.85923, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9154, 0.94236, 0.9154, 0.94236, 0.9154, 0.94236, 0.85458, 0.89364, 0.96694, 1, 0.89903, 1, 1, 1, 0.91782, 0.91782, 0.91782, 1, 0.896, 0.896, 0.896, 0.9332, 0.9332, 0.95973, 1, 1.26, 1, 1, 0.80479, 0.80178, 1, 1, 0.85633, 1, 1, 1, 1, 0.97276, 1, 1, 1, 0.698, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.14542, 1, 0.79199, 0.78694, 1.02058, 1.03493, 1.05486, 1, 1, 1.23026, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.20006, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27005. const MyriadProBoldItalicMetrics = {
  27006. lineHeight: 1.2,
  27007. lineGap: 0.2
  27008. };
  27009. const MyriadProItalicFactors = [1.36898, 1, 1, 0.65507, 0.84943, 0.85639, 0.88465, 0.88465, 0.86936, 0.88307, 0.86948, 0.85283, 0.85283, 1.06383, 1.02058, 0.75945, 0.9219, 0.75945, 1.17337, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.88465, 0.75945, 0.75945, 1.02058, 1.02058, 1.02058, 0.69046, 0.70926, 0.85158, 0.77812, 0.76852, 0.89591, 0.70466, 0.76125, 0.80094, 0.86822, 0.83864, 0.728, 0.77212, 0.79475, 0.93637, 0.87514, 0.8588, 0.76013, 0.8588, 0.72421, 0.69866, 0.77598, 0.85991, 0.80811, 0.87832, 0.78112, 0.77512, 0.8562, 1.0222, 1.18417, 1.0222, 1.27014, 0.89903, 1.15012, 0.93859, 0.94399, 0.846, 0.94399, 0.81453, 1.0186, 0.94219, 0.96017, 1.03075, 1.02175, 0.912, 1.03075, 0.96998, 0.96017, 0.93859, 0.94399, 0.94399, 0.95493, 0.746, 1.12658, 0.94578, 0.91, 0.979, 0.882, 0.882, 0.83, 0.85034, 0.83537, 0.85034, 1.02058, 0.70869, 0.88465, 0.88465, 0.88465, 0.88465, 0.83537, 0.90083, 1.15012, 0.9161, 0.94565, 0.73541, 1.02058, 0.53609, 0.69353, 0.79519, 1.08595, 1, 1, 1.15012, 1, 0.91974, 0.75945, 1.15012, 1, 0.9446, 0.73361, 0.9005, 0.9005, 0.9005, 0.62864, 0.85158, 0.85158, 0.85158, 0.85158, 0.85158, 0.85158, 0.773, 0.76852, 0.70466, 0.70466, 0.70466, 0.70466, 0.83864, 0.83864, 0.83864, 0.83864, 0.90561, 0.87514, 0.8588, 0.8588, 0.8588, 0.8588, 0.8588, 1.02058, 0.85751, 0.85991, 0.85991, 0.85991, 0.85991, 0.77512, 0.76013, 0.88075, 0.93859, 0.93859, 0.93859, 0.93859, 0.93859, 0.93859, 0.8075, 0.846, 0.81453, 0.81453, 0.81453, 0.81453, 0.82424, 0.82424, 0.82424, 0.82424, 0.9278, 0.96017, 0.93859, 0.93859, 0.93859, 0.93859, 0.93859, 1.08595, 0.8562, 0.94578, 0.94578, 0.94578, 0.94578, 0.882, 0.94578, 0.882, 0.85158, 0.93859, 0.85158, 0.93859, 0.85158, 0.93859, 0.76852, 0.846, 0.76852, 0.846, 0.76852, 0.846, 0.76852, 0.846, 0.89591, 0.8544, 0.90561, 0.94399, 0.70466, 0.81453, 0.70466, 0.81453, 0.70466, 0.81453, 0.70466, 0.81453, 0.70466, 0.81453, 0.80094, 0.94219, 0.80094, 0.94219, 0.80094, 0.94219, 1, 1, 0.86822, 0.96017, 0.86822, 0.96017, 0.83864, 0.82424, 0.83864, 0.82424, 0.83864, 0.82424, 0.83864, 1.03075, 0.83864, 0.82424, 0.81402, 1.02738, 0.728, 1.02175, 1, 1, 0.912, 0.79475, 1.03075, 1, 1, 0.79475, 0.83911, 0.79475, 0.66266, 0.80553, 1.06676, 0.87514, 0.96017, 1, 1, 0.87514, 0.96017, 0.86865, 0.87396, 0.96017, 0.8588, 0.93859, 0.8588, 0.93859, 0.8588, 0.93859, 0.867, 0.84759, 0.72421, 0.95493, 1, 1, 0.72421, 0.95493, 0.69866, 0.746, 0.69866, 0.746, 1, 1, 0.69866, 0.746, 1, 1, 0.77598, 0.88417, 0.77598, 1.12658, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.85991, 0.94578, 0.87832, 0.979, 0.77512, 0.882, 0.77512, 0.8562, 0.83, 0.8562, 0.83, 0.8562, 0.83, 1, 0.88465, 0.85158, 0.93859, 0.773, 0.8075, 0.85751, 0.8562, 1, 1, 0.77598, 1.12658, 1.15012, 1.15012, 1.15012, 1.15012, 1.15012, 1.15313, 1.15012, 1.15012, 1.15012, 1.08106, 1.03901, 0.85158, 0.77025, 0.62264, 0.7646, 0.65351, 0.86026, 0.69461, 0.89947, 1.03075, 0.85158, 0.77812, 0.76449, 0.88836, 0.70466, 0.8562, 0.86822, 0.8588, 0.83864, 0.77212, 0.85308, 0.93637, 0.87514, 0.82352, 0.8588, 0.85701, 0.76013, 0.89058, 0.77598, 0.8156, 0.82565, 0.78112, 0.77899, 0.89386, 0.83864, 0.8156, 0.9486, 0.92388, 0.96186, 1.03075, 0.91123, 0.9486, 0.93298, 0.878, 0.93942, 0.92388, 0.84596, 0.96186, 0.95119, 1.03075, 0.922, 0.88787, 0.95829, 0.88, 0.93559, 0.93859, 0.78815, 0.93758, 1, 0.89217, 1.03737, 0.91123, 0.93969, 0.77487, 0.85769, 0.86799, 1.03075, 0.91123, 0.93859, 0.91123, 0.86799, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.87832, 0.979, 0.87832, 0.979, 0.87832, 0.979, 0.77512, 0.882, 0.9219, 1, 0.89903, 1, 1, 1, 0.87321, 0.87321, 0.87321, 1, 1.027, 1.027, 1.027, 0.86847, 0.86847, 0.79121, 1, 1.124, 1, 1, 0.73572, 0.73572, 1, 1, 0.85034, 1, 1, 1, 1, 0.88465, 1, 1, 1, 0.669, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.04828, 1, 0.74948, 0.75187, 1.02058, 0.98391, 1.02119, 1, 1, 1.06233, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05233, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27010. const MyriadProItalicMetrics = {
  27011. lineHeight: 1.2,
  27012. lineGap: 0.2
  27013. };
  27014. const MyriadProRegularFactors = [1.36898, 1, 1, 0.76305, 0.82784, 0.94935, 0.89364, 0.92241, 0.89073, 0.90706, 0.98472, 0.85283, 0.85283, 1.0664, 1.02058, 0.74505, 0.9219, 0.74505, 1.23456, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.92241, 0.74505, 0.74505, 1.02058, 1.02058, 1.02058, 0.73002, 0.72601, 0.91755, 0.8126, 0.80314, 0.92222, 0.73764, 0.79726, 0.83051, 0.90284, 0.86023, 0.74, 0.8126, 0.84869, 0.96518, 0.91115, 0.8858, 0.79761, 0.8858, 0.74498, 0.73914, 0.81363, 0.89591, 0.83659, 0.89633, 0.85608, 0.8111, 0.90531, 1.0222, 1.22736, 1.0222, 1.27014, 0.89903, 0.90088, 0.86667, 1.0231, 0.896, 1.01411, 0.90083, 1.05099, 1.00512, 0.99793, 1.05326, 1.09377, 0.938, 1.06226, 1.00119, 0.99793, 0.98714, 1.0231, 1.01231, 0.98196, 0.792, 1.19137, 0.99074, 0.962, 1.01915, 0.926, 0.942, 0.856, 0.85034, 0.92006, 0.85034, 1.02058, 0.69067, 0.92241, 0.92241, 0.92241, 0.92241, 0.92006, 0.9332, 0.90088, 0.91882, 0.93484, 0.75339, 1.02058, 0.56866, 0.54324, 0.79519, 1.08595, 1, 1, 0.90088, 1, 0.95325, 0.74505, 0.90088, 1, 0.97198, 0.75339, 0.91009, 0.91009, 0.91009, 0.66466, 0.91755, 0.91755, 0.91755, 0.91755, 0.91755, 0.91755, 0.788, 0.80314, 0.73764, 0.73764, 0.73764, 0.73764, 0.86023, 0.86023, 0.86023, 0.86023, 0.92915, 0.91115, 0.8858, 0.8858, 0.8858, 0.8858, 0.8858, 1.02058, 0.8858, 0.89591, 0.89591, 0.89591, 0.89591, 0.8111, 0.79611, 0.89713, 0.86667, 0.86667, 0.86667, 0.86667, 0.86667, 0.86667, 0.86936, 0.896, 0.90083, 0.90083, 0.90083, 0.90083, 0.84224, 0.84224, 0.84224, 0.84224, 0.97276, 0.99793, 0.98714, 0.98714, 0.98714, 0.98714, 0.98714, 1.08595, 0.89876, 0.99074, 0.99074, 0.99074, 0.99074, 0.942, 1.0231, 0.942, 0.91755, 0.86667, 0.91755, 0.86667, 0.91755, 0.86667, 0.80314, 0.896, 0.80314, 0.896, 0.80314, 0.896, 0.80314, 0.896, 0.92222, 0.93372, 0.92915, 1.01411, 0.73764, 0.90083, 0.73764, 0.90083, 0.73764, 0.90083, 0.73764, 0.90083, 0.73764, 0.90083, 0.83051, 1.00512, 0.83051, 1.00512, 0.83051, 1.00512, 1, 1, 0.90284, 0.99793, 0.90976, 0.99793, 0.86023, 0.84224, 0.86023, 0.84224, 0.86023, 0.84224, 0.86023, 1.05326, 0.86023, 0.84224, 0.82873, 1.07469, 0.74, 1.09377, 1, 1, 0.938, 0.84869, 1.06226, 1, 1, 0.84869, 0.83704, 0.84869, 0.81441, 0.85588, 1.08927, 0.91115, 0.99793, 1, 1, 0.91115, 0.99793, 0.91887, 0.90991, 0.99793, 0.8858, 0.98714, 0.8858, 0.98714, 0.8858, 0.98714, 0.894, 0.91434, 0.74498, 0.98196, 1, 1, 0.74498, 0.98196, 0.73914, 0.792, 0.73914, 0.792, 1, 1, 0.73914, 0.792, 1, 1, 0.81363, 0.904, 0.81363, 1.19137, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89591, 0.99074, 0.89633, 1.01915, 0.8111, 0.942, 0.8111, 0.90531, 0.856, 0.90531, 0.856, 0.90531, 0.856, 1, 0.92241, 0.91755, 0.86667, 0.788, 0.86936, 0.8858, 0.89876, 1, 1, 0.81363, 1.19137, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90088, 0.90388, 1.03901, 0.92138, 0.78105, 0.7154, 0.86169, 0.80513, 0.94007, 0.82528, 0.98612, 1.06226, 0.91755, 0.8126, 0.81884, 0.92819, 0.73764, 0.90531, 0.90284, 0.8858, 0.86023, 0.8126, 0.91172, 0.96518, 0.91115, 0.83089, 0.8858, 0.87791, 0.79761, 0.89297, 0.81363, 0.88157, 0.89992, 0.85608, 0.81992, 0.94307, 0.86023, 0.88157, 0.95308, 0.98699, 0.99793, 1.06226, 0.95817, 0.95308, 0.97358, 0.928, 0.98088, 0.98699, 0.92761, 0.99793, 0.96017, 1.06226, 0.986, 0.944, 0.95978, 0.938, 0.96705, 0.98714, 0.80442, 0.98972, 1, 0.89762, 1.04552, 0.95817, 0.99007, 0.87064, 0.91879, 0.88888, 1.06226, 0.95817, 0.98714, 0.95817, 0.88888, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.89633, 1.01915, 0.89633, 1.01915, 0.89633, 1.01915, 0.8111, 0.942, 0.9219, 1, 0.89903, 1, 1, 1, 0.93173, 0.93173, 0.93173, 1, 1.06304, 1.06304, 1.06904, 0.89903, 0.89903, 0.80549, 1, 1.156, 1, 1, 0.76575, 0.76575, 1, 1, 0.72458, 1, 1, 1, 1, 0.92241, 1, 1, 1, 0.619, 1, 1.36145, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.07257, 1, 0.74705, 0.71119, 1.02058, 1.024, 1.02119, 1, 1, 1.1536, 1.08595, 1.08595, 1, 1.08595, 1.08595, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.05638, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27015. const MyriadProRegularMetrics = {
  27016. lineHeight: 1.2,
  27017. lineGap: 0.2
  27018. };
  27019. ;// CONCATENATED MODULE: ./src/core/segoeui_factors.js
  27020. const SegoeuiBoldFactors = [1.76738, 1, 1, 0.99297, 0.9824, 1.04016, 1.06497, 1.03424, 0.97529, 1.17647, 1.23203, 1.1085, 1.1085, 1.16939, 1.2107, 0.9754, 1.21408, 0.9754, 1.59578, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 1.03424, 0.81378, 0.81378, 1.2107, 1.2107, 1.2107, 0.71703, 0.97847, 0.97363, 0.88776, 0.8641, 1.02096, 0.79795, 0.85132, 0.914, 1.06085, 1.1406, 0.8007, 0.89858, 0.83693, 1.14889, 1.09398, 0.97489, 0.92094, 0.97489, 0.90399, 0.84041, 0.95923, 1.00135, 1, 1.06467, 0.98243, 0.90996, 0.99361, 1.1085, 1.56942, 1.1085, 1.2107, 0.74627, 0.94282, 0.96752, 1.01519, 0.86304, 1.01359, 0.97278, 1.15103, 1.01359, 0.98561, 1.02285, 1.02285, 1.00527, 1.02285, 1.0302, 0.99041, 1.0008, 1.01519, 1.01359, 1.02258, 0.79104, 1.16862, 0.99041, 0.97454, 1.02511, 0.99298, 0.96752, 0.95801, 0.94856, 1.16579, 0.94856, 1.2107, 0.9824, 1.03424, 1.03424, 1, 1.03424, 1.16579, 0.8727, 1.3871, 1.18622, 1.10818, 1.04478, 1.2107, 1.18622, 0.75155, 0.94994, 1.28826, 1.21408, 1.21408, 0.91056, 1, 0.91572, 0.9754, 0.64663, 1.18328, 1.24866, 1.04478, 1.14169, 1.15749, 1.17389, 0.71703, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.93506, 0.8641, 0.79795, 0.79795, 0.79795, 0.79795, 1.1406, 1.1406, 1.1406, 1.1406, 1.02096, 1.09398, 0.97426, 0.97426, 0.97426, 0.97426, 0.97426, 1.2107, 0.97489, 1.00135, 1.00135, 1.00135, 1.00135, 0.90996, 0.92094, 1.02798, 0.96752, 0.96752, 0.96752, 0.96752, 0.96752, 0.96752, 0.93136, 0.86304, 0.97278, 0.97278, 0.97278, 0.97278, 1.02285, 1.02285, 1.02285, 1.02285, 0.97122, 0.99041, 1, 1, 1, 1, 1, 1.28826, 1.0008, 0.99041, 0.99041, 0.99041, 0.99041, 0.96752, 1.01519, 0.96752, 0.97363, 0.96752, 0.97363, 0.96752, 0.97363, 0.96752, 0.8641, 0.86304, 0.8641, 0.86304, 0.8641, 0.86304, 0.8641, 0.86304, 1.02096, 1.03057, 1.02096, 1.03517, 0.79795, 0.97278, 0.79795, 0.97278, 0.79795, 0.97278, 0.79795, 0.97278, 0.79795, 0.97278, 0.914, 1.01359, 0.914, 1.01359, 0.914, 1.01359, 1, 1, 1.06085, 0.98561, 1.06085, 1.00879, 1.1406, 1.02285, 1.1406, 1.02285, 1.1406, 1.02285, 1.1406, 1.02285, 1.1406, 1.02285, 0.97138, 1.08692, 0.8007, 1.02285, 1, 1, 1.00527, 0.83693, 1.02285, 1, 1, 0.83693, 0.9455, 0.83693, 0.90418, 0.83693, 1.13005, 1.09398, 0.99041, 1, 1, 1.09398, 0.99041, 0.96692, 1.09251, 0.99041, 0.97489, 1.0008, 0.97489, 1.0008, 0.97489, 1.0008, 0.93994, 0.97931, 0.90399, 1.02258, 1, 1, 0.90399, 1.02258, 0.84041, 0.79104, 0.84041, 0.79104, 0.84041, 0.79104, 0.84041, 0.79104, 1, 1, 0.95923, 1.07034, 0.95923, 1.16862, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.00135, 0.99041, 1.06467, 1.02511, 0.90996, 0.96752, 0.90996, 0.99361, 0.95801, 0.99361, 0.95801, 0.99361, 0.95801, 1.07733, 1.03424, 0.97363, 0.96752, 0.93506, 0.93136, 0.97489, 1.0008, 1, 1, 0.95923, 1.16862, 1.15103, 1.15103, 1.01173, 1.03959, 0.75953, 0.81378, 0.79912, 1.15103, 1.21994, 0.95161, 0.87815, 1.01149, 0.81525, 0.7676, 0.98167, 1.01134, 1.02546, 0.84097, 1.03089, 1.18102, 0.97363, 0.88776, 0.85134, 0.97826, 0.79795, 0.99361, 1.06085, 0.97489, 1.1406, 0.89858, 1.0388, 1.14889, 1.09398, 0.86039, 0.97489, 1.0595, 0.92094, 0.94793, 0.95923, 0.90996, 0.99346, 0.98243, 1.02112, 0.95493, 1.1406, 0.90996, 1.03574, 1.02597, 1.0008, 1.18102, 1.06628, 1.03574, 1.0192, 1.01932, 1.00886, 0.97531, 1.0106, 1.0008, 1.13189, 1.18102, 1.02277, 0.98683, 1.0016, 0.99561, 1.07237, 1.0008, 0.90434, 0.99921, 0.93803, 0.8965, 1.23085, 1.06628, 1.04983, 0.96268, 1.0499, 0.98439, 1.18102, 1.06628, 1.0008, 1.06628, 0.98439, 0.79795, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.09466, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.97278, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.02065, 1, 1, 1, 1, 1, 1, 1.06467, 1.02511, 1.06467, 1.02511, 1.06467, 1.02511, 0.90996, 0.96752, 1, 1.21408, 0.89903, 1, 1, 0.75155, 1.04394, 1.04394, 1.04394, 1.04394, 0.98633, 0.98633, 0.98633, 0.73047, 0.73047, 1.20642, 0.91211, 1.25635, 1.222, 1.02956, 1.03372, 1.03372, 0.96039, 1.24633, 1, 1.12454, 0.93503, 1.03424, 1.19687, 1.03424, 1, 1, 1, 0.771, 1, 1, 1.15749, 1.15749, 1.15749, 1.10948, 0.86279, 0.94434, 0.86279, 0.94434, 0.86182, 1, 1, 1.16897, 1, 0.96085, 0.90137, 1.2107, 1.18416, 1.13973, 0.69825, 0.9716, 2.10339, 1.29004, 1.29004, 1.21172, 1.29004, 1.29004, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.18874, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.09193, 1.09193, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27021. const SegoeuiBoldMetrics = {
  27022. lineHeight: 1.33008,
  27023. lineGap: 0
  27024. };
  27025. const SegoeuiBoldItalicFactors = [1.76738, 1, 1, 0.98946, 1.03959, 1.04016, 1.02809, 1.036, 0.97639, 1.10953, 1.23203, 1.11144, 1.11144, 1.16939, 1.21237, 0.9754, 1.21261, 0.9754, 1.59754, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 1.036, 0.81378, 0.81378, 1.21237, 1.21237, 1.21237, 0.73541, 0.97847, 0.97363, 0.89723, 0.87897, 1.0426, 0.79429, 0.85292, 0.91149, 1.05815, 1.1406, 0.79631, 0.90128, 0.83853, 1.04396, 1.10615, 0.97552, 0.94436, 0.97552, 0.88641, 0.80527, 0.96083, 1.00135, 1, 1.06777, 0.9817, 0.91142, 0.99361, 1.11144, 1.57293, 1.11144, 1.21237, 0.74627, 1.31818, 1.06585, 0.97042, 0.83055, 0.97042, 0.93503, 1.1261, 0.97042, 0.97922, 1.14236, 0.94552, 1.01054, 1.14236, 1.02471, 0.97922, 0.94165, 0.97042, 0.97042, 1.0276, 0.78929, 1.1261, 0.97922, 0.95874, 1.02197, 0.98507, 0.96752, 0.97168, 0.95107, 1.16579, 0.95107, 1.21237, 1.03959, 1.036, 1.036, 1, 1.036, 1.16579, 0.87357, 1.31818, 1.18754, 1.26781, 1.05356, 1.21237, 1.18622, 0.79487, 0.94994, 1.29004, 1.24047, 1.24047, 1.31818, 1, 0.91484, 0.9754, 1.31818, 1.1349, 1.24866, 1.05356, 1.13934, 1.15574, 1.17389, 0.73541, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.97363, 0.94385, 0.87897, 0.79429, 0.79429, 0.79429, 0.79429, 1.1406, 1.1406, 1.1406, 1.1406, 1.0426, 1.10615, 0.97552, 0.97552, 0.97552, 0.97552, 0.97552, 1.21237, 0.97552, 1.00135, 1.00135, 1.00135, 1.00135, 0.91142, 0.94436, 0.98721, 1.06585, 1.06585, 1.06585, 1.06585, 1.06585, 1.06585, 0.96705, 0.83055, 0.93503, 0.93503, 0.93503, 0.93503, 1.14236, 1.14236, 1.14236, 1.14236, 0.93125, 0.97922, 0.94165, 0.94165, 0.94165, 0.94165, 0.94165, 1.29004, 0.94165, 0.97922, 0.97922, 0.97922, 0.97922, 0.96752, 0.97042, 0.96752, 0.97363, 1.06585, 0.97363, 1.06585, 0.97363, 1.06585, 0.87897, 0.83055, 0.87897, 0.83055, 0.87897, 0.83055, 0.87897, 0.83055, 1.0426, 1.0033, 1.0426, 0.97042, 0.79429, 0.93503, 0.79429, 0.93503, 0.79429, 0.93503, 0.79429, 0.93503, 0.79429, 0.93503, 0.91149, 0.97042, 0.91149, 0.97042, 0.91149, 0.97042, 1, 1, 1.05815, 0.97922, 1.05815, 0.97922, 1.1406, 1.14236, 1.1406, 1.14236, 1.1406, 1.14236, 1.1406, 1.14236, 1.1406, 1.14236, 0.97441, 1.04302, 0.79631, 1.01582, 1, 1, 1.01054, 0.83853, 1.14236, 1, 1, 0.83853, 1.09125, 0.83853, 0.90418, 0.83853, 1.19508, 1.10615, 0.97922, 1, 1, 1.10615, 0.97922, 1.01034, 1.10466, 0.97922, 0.97552, 0.94165, 0.97552, 0.94165, 0.97552, 0.94165, 0.91602, 0.91981, 0.88641, 1.0276, 1, 1, 0.88641, 1.0276, 0.80527, 0.78929, 0.80527, 0.78929, 0.80527, 0.78929, 0.80527, 0.78929, 1, 1, 0.96083, 1.05403, 0.95923, 1.16862, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.00135, 0.97922, 1.06777, 1.02197, 0.91142, 0.96752, 0.91142, 0.99361, 0.97168, 0.99361, 0.97168, 0.99361, 0.97168, 1.23199, 1.036, 0.97363, 1.06585, 0.94385, 0.96705, 0.97552, 0.94165, 1, 1, 0.96083, 1.1261, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 1.31818, 0.95161, 1.27126, 1.00811, 0.83284, 0.77702, 0.99137, 0.95253, 1.0347, 0.86142, 1.07205, 1.14236, 0.97363, 0.89723, 0.86869, 1.09818, 0.79429, 0.99361, 1.05815, 0.97552, 1.1406, 0.90128, 1.06662, 1.04396, 1.10615, 0.84918, 0.97552, 1.04694, 0.94436, 0.98015, 0.96083, 0.91142, 1.00356, 0.9817, 1.01945, 0.98999, 1.1406, 0.91142, 1.04961, 0.9898, 1.00639, 1.14236, 1.07514, 1.04961, 0.99607, 1.02897, 1.008, 0.9898, 0.95134, 1.00639, 1.11121, 1.14236, 1.00518, 0.97981, 1.02186, 1, 1.08578, 0.94165, 0.99314, 0.98387, 0.93028, 0.93377, 1.35125, 1.07514, 1.10687, 0.93491, 1.04232, 1.00351, 1.14236, 1.07514, 0.94165, 1.07514, 1.00351, 0.79429, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.09097, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.93503, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.96609, 1, 1, 1, 1, 1, 1, 1.06777, 1.02197, 1.06777, 1.02197, 1.06777, 1.02197, 0.91142, 0.96752, 1, 1.21261, 0.89903, 1, 1, 0.75155, 1.04745, 1.04745, 1.04745, 1.04394, 0.98633, 0.98633, 0.98633, 0.72959, 0.72959, 1.20502, 0.91406, 1.26514, 1.222, 1.02956, 1.03372, 1.03372, 0.96039, 1.24633, 1, 1.09125, 0.93327, 1.03336, 1.16541, 1.036, 1, 1, 1, 0.771, 1, 1, 1.15574, 1.15574, 1.15574, 1.15574, 0.86364, 0.94434, 0.86279, 0.94434, 0.86224, 1, 1, 1.16798, 1, 0.96085, 0.90068, 1.21237, 1.18416, 1.13904, 0.69825, 0.9716, 2.10339, 1.29004, 1.29004, 1.21339, 1.29004, 1.29004, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.18775, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.13269, 1.13269, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27026. const SegoeuiBoldItalicMetrics = {
  27027. lineHeight: 1.33008,
  27028. lineGap: 0
  27029. };
  27030. const SegoeuiItalicFactors = [1.76738, 1, 1, 0.98946, 1.14763, 1.05365, 1.06234, 0.96927, 0.92586, 1.15373, 1.18414, 0.91349, 0.91349, 1.07403, 1.17308, 0.78383, 1.20088, 0.78383, 1.42531, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.78383, 0.78383, 1.17308, 1.17308, 1.17308, 0.77349, 0.94565, 0.94729, 0.85944, 0.88506, 0.9858, 0.74817, 0.80016, 0.88449, 0.98039, 0.95782, 0.69238, 0.89898, 0.83231, 0.98183, 1.03989, 0.96924, 0.86237, 0.96924, 0.80595, 0.74524, 0.86091, 0.95402, 0.94143, 0.98448, 0.8858, 0.83089, 0.93285, 1.0949, 1.39016, 1.0949, 1.45994, 0.74627, 1.04839, 0.97454, 0.97454, 0.87207, 0.97454, 0.87533, 1.06151, 0.97454, 1.00176, 1.16484, 1.08132, 0.98047, 1.16484, 1.02989, 1.01054, 0.96225, 0.97454, 0.97454, 1.06598, 0.79004, 1.16344, 1.00351, 0.94629, 0.9973, 0.91016, 0.96777, 0.9043, 0.91082, 0.92481, 0.91082, 1.17308, 0.95748, 0.96927, 0.96927, 1, 0.96927, 0.92481, 0.80597, 1.04839, 1.23393, 1.1781, 0.9245, 1.17308, 1.20808, 0.63218, 0.94261, 1.24822, 1.09971, 1.09971, 1.04839, 1, 0.85273, 0.78032, 1.04839, 1.09971, 1.22326, 0.9245, 1.09836, 1.13525, 1.15222, 0.70424, 0.94729, 0.94729, 0.94729, 0.94729, 0.94729, 0.94729, 0.85498, 0.88506, 0.74817, 0.74817, 0.74817, 0.74817, 0.95782, 0.95782, 0.95782, 0.95782, 0.9858, 1.03989, 0.96924, 0.96924, 0.96924, 0.96924, 0.96924, 1.17308, 0.96924, 0.95402, 0.95402, 0.95402, 0.95402, 0.83089, 0.86237, 0.88409, 0.97454, 0.97454, 0.97454, 0.97454, 0.97454, 0.97454, 0.92916, 0.87207, 0.87533, 0.87533, 0.87533, 0.87533, 0.93146, 0.93146, 0.93146, 0.93146, 0.93854, 1.01054, 0.96225, 0.96225, 0.96225, 0.96225, 0.96225, 1.24822, 0.8761, 1.00351, 1.00351, 1.00351, 1.00351, 0.96777, 0.97454, 0.96777, 0.94729, 0.97454, 0.94729, 0.97454, 0.94729, 0.97454, 0.88506, 0.87207, 0.88506, 0.87207, 0.88506, 0.87207, 0.88506, 0.87207, 0.9858, 0.95391, 0.9858, 0.97454, 0.74817, 0.87533, 0.74817, 0.87533, 0.74817, 0.87533, 0.74817, 0.87533, 0.74817, 0.87533, 0.88449, 0.97454, 0.88449, 0.97454, 0.88449, 0.97454, 1, 1, 0.98039, 1.00176, 0.98039, 1.00176, 0.95782, 0.93146, 0.95782, 0.93146, 0.95782, 0.93146, 0.95782, 1.16484, 0.95782, 0.93146, 0.84421, 1.12761, 0.69238, 1.08132, 1, 1, 0.98047, 0.83231, 1.16484, 1, 1, 0.84723, 1.04861, 0.84723, 0.78755, 0.83231, 1.23736, 1.03989, 1.01054, 1, 1, 1.03989, 1.01054, 0.9857, 1.03849, 1.01054, 0.96924, 0.96225, 0.96924, 0.96225, 0.96924, 0.96225, 0.92383, 0.90171, 0.80595, 1.06598, 1, 1, 0.80595, 1.06598, 0.74524, 0.79004, 0.74524, 0.79004, 0.74524, 0.79004, 0.74524, 0.79004, 1, 1, 0.86091, 1.02759, 0.85771, 1.16344, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.95402, 1.00351, 0.98448, 0.9973, 0.83089, 0.96777, 0.83089, 0.93285, 0.9043, 0.93285, 0.9043, 0.93285, 0.9043, 1.31868, 0.96927, 0.94729, 0.97454, 0.85498, 0.92916, 0.96924, 0.8761, 1, 1, 0.86091, 1.16344, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 1.04839, 0.81965, 0.81965, 0.94729, 0.78032, 0.71022, 0.90883, 0.84171, 0.99877, 0.77596, 1.05734, 1.2, 0.94729, 0.85944, 0.82791, 0.9607, 0.74817, 0.93285, 0.98039, 0.96924, 0.95782, 0.89898, 0.98316, 0.98183, 1.03989, 0.78614, 0.96924, 0.97642, 0.86237, 0.86075, 0.86091, 0.83089, 0.90082, 0.8858, 0.97296, 1.01284, 0.95782, 0.83089, 1.0976, 1.04, 1.03342, 1.2, 1.0675, 1.0976, 0.98205, 1.03809, 1.05097, 1.04, 0.95364, 1.03342, 1.05401, 1.2, 1.02148, 1.0119, 1.04724, 1.0127, 1.02732, 0.96225, 0.8965, 0.97783, 0.93574, 0.94818, 1.30679, 1.0675, 1.11826, 0.99821, 1.0557, 1.0326, 1.2, 1.0675, 0.96225, 1.0675, 1.0326, 0.74817, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.03754, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.87533, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.98705, 1, 1, 1, 1, 1, 1, 0.98448, 0.9973, 0.98448, 0.9973, 0.98448, 0.9973, 0.83089, 0.96777, 1, 1.20088, 0.89903, 1, 1, 0.75155, 0.94945, 0.94945, 0.94945, 0.94945, 1.12317, 1.12317, 1.12317, 0.67603, 0.67603, 1.15621, 0.73584, 1.21191, 1.22135, 1.06483, 0.94868, 0.94868, 0.95996, 1.24633, 1, 1.07497, 0.87709, 0.96927, 1.01473, 0.96927, 1, 1, 1, 0.77295, 1, 1, 1.09836, 1.09836, 1.09836, 1.01522, 0.86321, 0.94434, 0.8649, 0.94434, 0.86182, 1, 1, 1.083, 1, 0.91578, 0.86438, 1.17308, 1.18416, 1.14589, 0.69825, 0.97622, 1.96791, 1.24822, 1.24822, 1.17308, 1.24822, 1.24822, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.17984, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.10742, 1.10742, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27031. const SegoeuiItalicMetrics = {
  27032. lineHeight: 1.33008,
  27033. lineGap: 0
  27034. };
  27035. const SegoeuiRegularFactors = [1.76738, 1, 1, 0.98594, 1.02285, 1.10454, 1.06234, 0.96927, 0.92037, 1.19985, 1.2046, 0.90616, 0.90616, 1.07152, 1.1714, 0.78032, 1.20088, 0.78032, 1.40246, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.96927, 0.78032, 0.78032, 1.1714, 1.1714, 1.1714, 0.80597, 0.94084, 0.96706, 0.85944, 0.85734, 0.97093, 0.75842, 0.79936, 0.88198, 0.9831, 0.95782, 0.71387, 0.86969, 0.84636, 1.07796, 1.03584, 0.96924, 0.83968, 0.96924, 0.82826, 0.79649, 0.85771, 0.95132, 0.93119, 0.98965, 0.88433, 0.8287, 0.93365, 1.08612, 1.3638, 1.08612, 1.45786, 0.74627, 0.80499, 0.91484, 1.05707, 0.92383, 1.05882, 0.9403, 1.12654, 1.05882, 1.01756, 1.09011, 1.09011, 0.99414, 1.09011, 1.034, 1.01756, 1.05356, 1.05707, 1.05882, 1.04399, 0.84863, 1.21968, 1.01756, 0.95801, 1.00068, 0.91797, 0.96777, 0.9043, 0.90351, 0.92105, 0.90351, 1.1714, 0.85337, 0.96927, 0.96927, 0.99912, 0.96927, 0.92105, 0.80597, 1.2434, 1.20808, 1.05937, 0.90957, 1.1714, 1.20808, 0.75155, 0.94261, 1.24644, 1.09971, 1.09971, 0.84751, 1, 0.85273, 0.78032, 0.61584, 1.05425, 1.17914, 0.90957, 1.08665, 1.11593, 1.14169, 0.73381, 0.96706, 0.96706, 0.96706, 0.96706, 0.96706, 0.96706, 0.86035, 0.85734, 0.75842, 0.75842, 0.75842, 0.75842, 0.95782, 0.95782, 0.95782, 0.95782, 0.97093, 1.03584, 0.96924, 0.96924, 0.96924, 0.96924, 0.96924, 1.1714, 0.96924, 0.95132, 0.95132, 0.95132, 0.95132, 0.8287, 0.83968, 0.89049, 0.91484, 0.91484, 0.91484, 0.91484, 0.91484, 0.91484, 0.93575, 0.92383, 0.9403, 0.9403, 0.9403, 0.9403, 0.8717, 0.8717, 0.8717, 0.8717, 1.00527, 1.01756, 1.05356, 1.05356, 1.05356, 1.05356, 1.05356, 1.24644, 0.95923, 1.01756, 1.01756, 1.01756, 1.01756, 0.96777, 1.05707, 0.96777, 0.96706, 0.91484, 0.96706, 0.91484, 0.96706, 0.91484, 0.85734, 0.92383, 0.85734, 0.92383, 0.85734, 0.92383, 0.85734, 0.92383, 0.97093, 1.0969, 0.97093, 1.05882, 0.75842, 0.9403, 0.75842, 0.9403, 0.75842, 0.9403, 0.75842, 0.9403, 0.75842, 0.9403, 0.88198, 1.05882, 0.88198, 1.05882, 0.88198, 1.05882, 1, 1, 0.9831, 1.01756, 0.9831, 1.01756, 0.95782, 0.8717, 0.95782, 0.8717, 0.95782, 0.8717, 0.95782, 1.09011, 0.95782, 0.8717, 0.84784, 1.11551, 0.71387, 1.09011, 1, 1, 0.99414, 0.84636, 1.09011, 1, 1, 0.84636, 1.0536, 0.84636, 0.94298, 0.84636, 1.23297, 1.03584, 1.01756, 1, 1, 1.03584, 1.01756, 1.00323, 1.03444, 1.01756, 0.96924, 1.05356, 0.96924, 1.05356, 0.96924, 1.05356, 0.93066, 0.98293, 0.82826, 1.04399, 1, 1, 0.82826, 1.04399, 0.79649, 0.84863, 0.79649, 0.84863, 0.79649, 0.84863, 0.79649, 0.84863, 1, 1, 0.85771, 1.17318, 0.85771, 1.21968, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.95132, 1.01756, 0.98965, 1.00068, 0.8287, 0.96777, 0.8287, 0.93365, 0.9043, 0.93365, 0.9043, 0.93365, 0.9043, 1.08571, 0.96927, 0.96706, 0.91484, 0.86035, 0.93575, 0.96924, 0.95923, 1, 1, 0.85771, 1.21968, 1.11437, 1.11437, 0.93109, 0.91202, 0.60411, 0.84164, 0.55572, 1.01173, 0.97361, 0.81818, 0.81818, 0.96635, 0.78032, 0.72727, 0.92366, 0.98601, 1.03405, 0.77968, 1.09799, 1.2, 0.96706, 0.85944, 0.85638, 0.96491, 0.75842, 0.93365, 0.9831, 0.96924, 0.95782, 0.86969, 0.94152, 1.07796, 1.03584, 0.78437, 0.96924, 0.98715, 0.83968, 0.83491, 0.85771, 0.8287, 0.94492, 0.88433, 0.9287, 1.0098, 0.95782, 0.8287, 1.0625, 0.98248, 1.03424, 1.2, 1.01071, 1.0625, 0.95246, 1.03809, 1.04912, 0.98248, 1.00221, 1.03424, 1.05443, 1.2, 1.04785, 0.99609, 1.00169, 1.05176, 0.99346, 1.05356, 0.9087, 1.03004, 0.95542, 0.93117, 1.23362, 1.01071, 1.07831, 1.02512, 1.05205, 1.03502, 1.2, 1.01071, 1.05356, 1.01071, 1.03502, 0.75842, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.03719, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9403, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.04021, 1, 1, 1, 1, 1, 1, 0.98965, 1.00068, 0.98965, 1.00068, 0.98965, 1.00068, 0.8287, 0.96777, 1, 1.20088, 0.89903, 1, 1, 0.75155, 1.03077, 1.03077, 1.03077, 1.03077, 1.13196, 1.13196, 1.13196, 0.67428, 0.67428, 1.16039, 0.73291, 1.20996, 1.22135, 1.06483, 0.94868, 0.94868, 0.95996, 1.24633, 1, 1.07497, 0.87796, 0.96927, 1.01518, 0.96927, 1, 1, 1, 0.77295, 1, 1, 1.10539, 1.10539, 1.11358, 1.06967, 0.86279, 0.94434, 0.86279, 0.94434, 0.86182, 1, 1, 1.083, 1, 0.91578, 0.86507, 1.1714, 1.18416, 1.14589, 0.69825, 0.97622, 1.9697, 1.24822, 1.24822, 1.17238, 1.24822, 1.24822, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.42603, 1, 0.99862, 0.99862, 1, 0.87025, 0.87025, 0.87025, 0.87025, 1.18083, 1.42603, 1, 1.42603, 1.42603, 0.99862, 1, 1, 1, 1, 1, 1.2886, 1.04315, 1.15296, 1.34163, 1, 1, 1, 1.10938, 1.10938, 1, 1, 1, 1.05425, 1.09971, 1.09971, 1.09971, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
  27036. const SegoeuiRegularMetrics = {
  27037. lineHeight: 1.33008,
  27038. lineGap: 0
  27039. };
  27040. ;// CONCATENATED MODULE: ./src/core/xfa_fonts.js
  27041. const getXFAFontMap = getLookupTableFactory(function (t) {
  27042. t["MyriadPro-Regular"] = t["PdfJS-Fallback-Regular"] = {
  27043. name: "LiberationSans-Regular",
  27044. factors: MyriadProRegularFactors,
  27045. baseWidths: LiberationSansRegularWidths,
  27046. baseMapping: LiberationSansRegularMapping,
  27047. metrics: MyriadProRegularMetrics
  27048. };
  27049. t["MyriadPro-Bold"] = t["PdfJS-Fallback-Bold"] = {
  27050. name: "LiberationSans-Bold",
  27051. factors: MyriadProBoldFactors,
  27052. baseWidths: LiberationSansBoldWidths,
  27053. baseMapping: LiberationSansBoldMapping,
  27054. metrics: MyriadProBoldMetrics
  27055. };
  27056. t["MyriadPro-It"] = t["MyriadPro-Italic"] = t["PdfJS-Fallback-Italic"] = {
  27057. name: "LiberationSans-Italic",
  27058. factors: MyriadProItalicFactors,
  27059. baseWidths: LiberationSansItalicWidths,
  27060. baseMapping: LiberationSansItalicMapping,
  27061. metrics: MyriadProItalicMetrics
  27062. };
  27063. t["MyriadPro-BoldIt"] = t["MyriadPro-BoldItalic"] = t["PdfJS-Fallback-BoldItalic"] = {
  27064. name: "LiberationSans-BoldItalic",
  27065. factors: MyriadProBoldItalicFactors,
  27066. baseWidths: LiberationSansBoldItalicWidths,
  27067. baseMapping: LiberationSansBoldItalicMapping,
  27068. metrics: MyriadProBoldItalicMetrics
  27069. };
  27070. t.ArialMT = t.Arial = t["Arial-Regular"] = {
  27071. name: "LiberationSans-Regular",
  27072. baseWidths: LiberationSansRegularWidths,
  27073. baseMapping: LiberationSansRegularMapping
  27074. };
  27075. t["Arial-BoldMT"] = t["Arial-Bold"] = {
  27076. name: "LiberationSans-Bold",
  27077. baseWidths: LiberationSansBoldWidths,
  27078. baseMapping: LiberationSansBoldMapping
  27079. };
  27080. t["Arial-ItalicMT"] = t["Arial-Italic"] = {
  27081. name: "LiberationSans-Italic",
  27082. baseWidths: LiberationSansItalicWidths,
  27083. baseMapping: LiberationSansItalicMapping
  27084. };
  27085. t["Arial-BoldItalicMT"] = t["Arial-BoldItalic"] = {
  27086. name: "LiberationSans-BoldItalic",
  27087. baseWidths: LiberationSansBoldItalicWidths,
  27088. baseMapping: LiberationSansBoldItalicMapping
  27089. };
  27090. t["Calibri-Regular"] = {
  27091. name: "LiberationSans-Regular",
  27092. factors: CalibriRegularFactors,
  27093. baseWidths: LiberationSansRegularWidths,
  27094. baseMapping: LiberationSansRegularMapping,
  27095. metrics: CalibriRegularMetrics
  27096. };
  27097. t["Calibri-Bold"] = {
  27098. name: "LiberationSans-Bold",
  27099. factors: CalibriBoldFactors,
  27100. baseWidths: LiberationSansBoldWidths,
  27101. baseMapping: LiberationSansBoldMapping,
  27102. metrics: CalibriBoldMetrics
  27103. };
  27104. t["Calibri-Italic"] = {
  27105. name: "LiberationSans-Italic",
  27106. factors: CalibriItalicFactors,
  27107. baseWidths: LiberationSansItalicWidths,
  27108. baseMapping: LiberationSansItalicMapping,
  27109. metrics: CalibriItalicMetrics
  27110. };
  27111. t["Calibri-BoldItalic"] = {
  27112. name: "LiberationSans-BoldItalic",
  27113. factors: CalibriBoldItalicFactors,
  27114. baseWidths: LiberationSansBoldItalicWidths,
  27115. baseMapping: LiberationSansBoldItalicMapping,
  27116. metrics: CalibriBoldItalicMetrics
  27117. };
  27118. t["Segoeui-Regular"] = {
  27119. name: "LiberationSans-Regular",
  27120. factors: SegoeuiRegularFactors,
  27121. baseWidths: LiberationSansRegularWidths,
  27122. baseMapping: LiberationSansRegularMapping,
  27123. metrics: SegoeuiRegularMetrics
  27124. };
  27125. t["Segoeui-Bold"] = {
  27126. name: "LiberationSans-Bold",
  27127. factors: SegoeuiBoldFactors,
  27128. baseWidths: LiberationSansBoldWidths,
  27129. baseMapping: LiberationSansBoldMapping,
  27130. metrics: SegoeuiBoldMetrics
  27131. };
  27132. t["Segoeui-Italic"] = {
  27133. name: "LiberationSans-Italic",
  27134. factors: SegoeuiItalicFactors,
  27135. baseWidths: LiberationSansItalicWidths,
  27136. baseMapping: LiberationSansItalicMapping,
  27137. metrics: SegoeuiItalicMetrics
  27138. };
  27139. t["Segoeui-BoldItalic"] = {
  27140. name: "LiberationSans-BoldItalic",
  27141. factors: SegoeuiBoldItalicFactors,
  27142. baseWidths: LiberationSansBoldItalicWidths,
  27143. baseMapping: LiberationSansBoldItalicMapping,
  27144. metrics: SegoeuiBoldItalicMetrics
  27145. };
  27146. t["Helvetica-Regular"] = t.Helvetica = {
  27147. name: "LiberationSans-Regular",
  27148. factors: HelveticaRegularFactors,
  27149. baseWidths: LiberationSansRegularWidths,
  27150. baseMapping: LiberationSansRegularMapping,
  27151. metrics: HelveticaRegularMetrics
  27152. };
  27153. t["Helvetica-Bold"] = {
  27154. name: "LiberationSans-Bold",
  27155. factors: HelveticaBoldFactors,
  27156. baseWidths: LiberationSansBoldWidths,
  27157. baseMapping: LiberationSansBoldMapping,
  27158. metrics: HelveticaBoldMetrics
  27159. };
  27160. t["Helvetica-Italic"] = {
  27161. name: "LiberationSans-Italic",
  27162. factors: HelveticaItalicFactors,
  27163. baseWidths: LiberationSansItalicWidths,
  27164. baseMapping: LiberationSansItalicMapping,
  27165. metrics: HelveticaItalicMetrics
  27166. };
  27167. t["Helvetica-BoldItalic"] = {
  27168. name: "LiberationSans-BoldItalic",
  27169. factors: HelveticaBoldItalicFactors,
  27170. baseWidths: LiberationSansBoldItalicWidths,
  27171. baseMapping: LiberationSansBoldItalicMapping,
  27172. metrics: HelveticaBoldItalicMetrics
  27173. };
  27174. });
  27175. function getXfaFontName(name) {
  27176. const fontName = normalizeFontName(name);
  27177. const fontMap = getXFAFontMap();
  27178. return fontMap[fontName];
  27179. }
  27180. function getXfaFontWidths(name) {
  27181. const info = getXfaFontName(name);
  27182. if (!info) {
  27183. return null;
  27184. }
  27185. const {
  27186. baseWidths,
  27187. baseMapping,
  27188. factors
  27189. } = info;
  27190. const rescaledBaseWidths = !factors ? baseWidths : baseWidths.map((w, i) => w * factors[i]);
  27191. let currentCode = -2;
  27192. let currentArray;
  27193. const newWidths = [];
  27194. for (const [unicode, glyphIndex] of baseMapping.map((charUnicode, index) => [charUnicode, index]).sort(([unicode1], [unicode2]) => unicode1 - unicode2)) {
  27195. if (unicode === -1) {
  27196. continue;
  27197. }
  27198. if (unicode === currentCode + 1) {
  27199. currentArray.push(rescaledBaseWidths[glyphIndex]);
  27200. currentCode += 1;
  27201. } else {
  27202. currentCode = unicode;
  27203. currentArray = [rescaledBaseWidths[glyphIndex]];
  27204. newWidths.push(unicode, currentArray);
  27205. }
  27206. }
  27207. return newWidths;
  27208. }
  27209. function getXfaFontDict(name) {
  27210. const widths = getXfaFontWidths(name);
  27211. const dict = new Dict(null);
  27212. dict.set("BaseFont", Name.get(name));
  27213. dict.set("Type", Name.get("Font"));
  27214. dict.set("Subtype", Name.get("CIDFontType2"));
  27215. dict.set("Encoding", Name.get("Identity-H"));
  27216. dict.set("CIDToGIDMap", Name.get("Identity"));
  27217. dict.set("W", widths);
  27218. dict.set("FirstChar", widths[0]);
  27219. dict.set("LastChar", widths.at(-2) + widths.at(-1).length - 1);
  27220. const descriptor = new Dict(null);
  27221. dict.set("FontDescriptor", descriptor);
  27222. const systemInfo = new Dict(null);
  27223. systemInfo.set("Ordering", "Identity");
  27224. systemInfo.set("Registry", "Adobe");
  27225. systemInfo.set("Supplement", 0);
  27226. dict.set("CIDSystemInfo", systemInfo);
  27227. return dict;
  27228. }
  27229. ;// CONCATENATED MODULE: ./src/core/ps_parser.js
  27230. class PostScriptParser {
  27231. constructor(lexer) {
  27232. this.lexer = lexer;
  27233. this.operators = [];
  27234. this.token = null;
  27235. this.prev = null;
  27236. }
  27237. nextToken() {
  27238. this.prev = this.token;
  27239. this.token = this.lexer.getToken();
  27240. }
  27241. accept(type) {
  27242. if (this.token.type === type) {
  27243. this.nextToken();
  27244. return true;
  27245. }
  27246. return false;
  27247. }
  27248. expect(type) {
  27249. if (this.accept(type)) {
  27250. return true;
  27251. }
  27252. throw new FormatError(`Unexpected symbol: found ${this.token.type} expected ${type}.`);
  27253. }
  27254. parse() {
  27255. this.nextToken();
  27256. this.expect(PostScriptTokenTypes.LBRACE);
  27257. this.parseBlock();
  27258. this.expect(PostScriptTokenTypes.RBRACE);
  27259. return this.operators;
  27260. }
  27261. parseBlock() {
  27262. while (true) {
  27263. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  27264. this.operators.push(this.prev.value);
  27265. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  27266. this.operators.push(this.prev.value);
  27267. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  27268. this.parseCondition();
  27269. } else {
  27270. return;
  27271. }
  27272. }
  27273. }
  27274. parseCondition() {
  27275. const conditionLocation = this.operators.length;
  27276. this.operators.push(null, null);
  27277. this.parseBlock();
  27278. this.expect(PostScriptTokenTypes.RBRACE);
  27279. if (this.accept(PostScriptTokenTypes.IF)) {
  27280. this.operators[conditionLocation] = this.operators.length;
  27281. this.operators[conditionLocation + 1] = "jz";
  27282. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  27283. const jumpLocation = this.operators.length;
  27284. this.operators.push(null, null);
  27285. const endOfTrue = this.operators.length;
  27286. this.parseBlock();
  27287. this.expect(PostScriptTokenTypes.RBRACE);
  27288. this.expect(PostScriptTokenTypes.IFELSE);
  27289. this.operators[jumpLocation] = this.operators.length;
  27290. this.operators[jumpLocation + 1] = "j";
  27291. this.operators[conditionLocation] = endOfTrue;
  27292. this.operators[conditionLocation + 1] = "jz";
  27293. } else {
  27294. throw new FormatError("PS Function: error parsing conditional.");
  27295. }
  27296. }
  27297. }
  27298. const PostScriptTokenTypes = {
  27299. LBRACE: 0,
  27300. RBRACE: 1,
  27301. NUMBER: 2,
  27302. OPERATOR: 3,
  27303. IF: 4,
  27304. IFELSE: 5
  27305. };
  27306. class PostScriptToken {
  27307. static get opCache() {
  27308. return shadow(this, "opCache", Object.create(null));
  27309. }
  27310. constructor(type, value) {
  27311. this.type = type;
  27312. this.value = value;
  27313. }
  27314. static getOperator(op) {
  27315. return PostScriptToken.opCache[op] ||= new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  27316. }
  27317. static get LBRACE() {
  27318. return shadow(this, "LBRACE", new PostScriptToken(PostScriptTokenTypes.LBRACE, "{"));
  27319. }
  27320. static get RBRACE() {
  27321. return shadow(this, "RBRACE", new PostScriptToken(PostScriptTokenTypes.RBRACE, "}"));
  27322. }
  27323. static get IF() {
  27324. return shadow(this, "IF", new PostScriptToken(PostScriptTokenTypes.IF, "IF"));
  27325. }
  27326. static get IFELSE() {
  27327. return shadow(this, "IFELSE", new PostScriptToken(PostScriptTokenTypes.IFELSE, "IFELSE"));
  27328. }
  27329. }
  27330. class PostScriptLexer {
  27331. constructor(stream) {
  27332. this.stream = stream;
  27333. this.nextChar();
  27334. this.strBuf = [];
  27335. }
  27336. nextChar() {
  27337. return this.currentChar = this.stream.getByte();
  27338. }
  27339. getToken() {
  27340. let comment = false;
  27341. let ch = this.currentChar;
  27342. while (true) {
  27343. if (ch < 0) {
  27344. return EOF;
  27345. }
  27346. if (comment) {
  27347. if (ch === 0x0a || ch === 0x0d) {
  27348. comment = false;
  27349. }
  27350. } else if (ch === 0x25) {
  27351. comment = true;
  27352. } else if (!isWhiteSpace(ch)) {
  27353. break;
  27354. }
  27355. ch = this.nextChar();
  27356. }
  27357. switch (ch | 0) {
  27358. case 0x30:
  27359. case 0x31:
  27360. case 0x32:
  27361. case 0x33:
  27362. case 0x34:
  27363. case 0x35:
  27364. case 0x36:
  27365. case 0x37:
  27366. case 0x38:
  27367. case 0x39:
  27368. case 0x2b:
  27369. case 0x2d:
  27370. case 0x2e:
  27371. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  27372. case 0x7b:
  27373. this.nextChar();
  27374. return PostScriptToken.LBRACE;
  27375. case 0x7d:
  27376. this.nextChar();
  27377. return PostScriptToken.RBRACE;
  27378. }
  27379. const strBuf = this.strBuf;
  27380. strBuf.length = 0;
  27381. strBuf[0] = String.fromCharCode(ch);
  27382. while ((ch = this.nextChar()) >= 0 && (ch >= 0x41 && ch <= 0x5a || ch >= 0x61 && ch <= 0x7a)) {
  27383. strBuf.push(String.fromCharCode(ch));
  27384. }
  27385. const str = strBuf.join("");
  27386. switch (str.toLowerCase()) {
  27387. case "if":
  27388. return PostScriptToken.IF;
  27389. case "ifelse":
  27390. return PostScriptToken.IFELSE;
  27391. default:
  27392. return PostScriptToken.getOperator(str);
  27393. }
  27394. }
  27395. getNumber() {
  27396. let ch = this.currentChar;
  27397. const strBuf = this.strBuf;
  27398. strBuf.length = 0;
  27399. strBuf[0] = String.fromCharCode(ch);
  27400. while ((ch = this.nextChar()) >= 0) {
  27401. if (ch >= 0x30 && ch <= 0x39 || ch === 0x2d || ch === 0x2e) {
  27402. strBuf.push(String.fromCharCode(ch));
  27403. } else {
  27404. break;
  27405. }
  27406. }
  27407. const value = parseFloat(strBuf.join(""));
  27408. if (isNaN(value)) {
  27409. throw new FormatError(`Invalid floating point number: ${value}`);
  27410. }
  27411. return value;
  27412. }
  27413. }
  27414. ;// CONCATENATED MODULE: ./src/core/image_utils.js
  27415. class BaseLocalCache {
  27416. constructor(options) {
  27417. if (this.constructor === BaseLocalCache) {
  27418. unreachable("Cannot initialize BaseLocalCache.");
  27419. }
  27420. this._onlyRefs = options?.onlyRefs === true;
  27421. if (!this._onlyRefs) {
  27422. this._nameRefMap = new Map();
  27423. this._imageMap = new Map();
  27424. }
  27425. this._imageCache = new RefSetCache();
  27426. }
  27427. getByName(name) {
  27428. if (this._onlyRefs) {
  27429. unreachable("Should not call `getByName` method.");
  27430. }
  27431. const ref = this._nameRefMap.get(name);
  27432. if (ref) {
  27433. return this.getByRef(ref);
  27434. }
  27435. return this._imageMap.get(name) || null;
  27436. }
  27437. getByRef(ref) {
  27438. return this._imageCache.get(ref) || null;
  27439. }
  27440. set(name, ref, data) {
  27441. unreachable("Abstract method `set` called.");
  27442. }
  27443. }
  27444. class LocalImageCache extends BaseLocalCache {
  27445. set(name, ref = null, data) {
  27446. if (typeof name !== "string") {
  27447. throw new Error('LocalImageCache.set - expected "name" argument.');
  27448. }
  27449. if (ref) {
  27450. if (this._imageCache.has(ref)) {
  27451. return;
  27452. }
  27453. this._nameRefMap.set(name, ref);
  27454. this._imageCache.put(ref, data);
  27455. return;
  27456. }
  27457. if (this._imageMap.has(name)) {
  27458. return;
  27459. }
  27460. this._imageMap.set(name, data);
  27461. }
  27462. }
  27463. class LocalColorSpaceCache extends BaseLocalCache {
  27464. set(name = null, ref = null, data) {
  27465. if (typeof name !== "string" && !ref) {
  27466. throw new Error('LocalColorSpaceCache.set - expected "name" and/or "ref" argument.');
  27467. }
  27468. if (ref) {
  27469. if (this._imageCache.has(ref)) {
  27470. return;
  27471. }
  27472. if (name !== null) {
  27473. this._nameRefMap.set(name, ref);
  27474. }
  27475. this._imageCache.put(ref, data);
  27476. return;
  27477. }
  27478. if (this._imageMap.has(name)) {
  27479. return;
  27480. }
  27481. this._imageMap.set(name, data);
  27482. }
  27483. }
  27484. class LocalFunctionCache extends BaseLocalCache {
  27485. constructor(options) {
  27486. super({
  27487. onlyRefs: true
  27488. });
  27489. }
  27490. set(name = null, ref, data) {
  27491. if (!ref) {
  27492. throw new Error('LocalFunctionCache.set - expected "ref" argument.');
  27493. }
  27494. if (this._imageCache.has(ref)) {
  27495. return;
  27496. }
  27497. this._imageCache.put(ref, data);
  27498. }
  27499. }
  27500. class LocalGStateCache extends BaseLocalCache {
  27501. set(name, ref = null, data) {
  27502. if (typeof name !== "string") {
  27503. throw new Error('LocalGStateCache.set - expected "name" argument.');
  27504. }
  27505. if (ref) {
  27506. if (this._imageCache.has(ref)) {
  27507. return;
  27508. }
  27509. this._nameRefMap.set(name, ref);
  27510. this._imageCache.put(ref, data);
  27511. return;
  27512. }
  27513. if (this._imageMap.has(name)) {
  27514. return;
  27515. }
  27516. this._imageMap.set(name, data);
  27517. }
  27518. }
  27519. class LocalTilingPatternCache extends BaseLocalCache {
  27520. constructor(options) {
  27521. super({
  27522. onlyRefs: true
  27523. });
  27524. }
  27525. set(name = null, ref, data) {
  27526. if (!ref) {
  27527. throw new Error('LocalTilingPatternCache.set - expected "ref" argument.');
  27528. }
  27529. if (this._imageCache.has(ref)) {
  27530. return;
  27531. }
  27532. this._imageCache.put(ref, data);
  27533. }
  27534. }
  27535. class RegionalImageCache extends BaseLocalCache {
  27536. constructor(options) {
  27537. super({
  27538. onlyRefs: true
  27539. });
  27540. }
  27541. set(name = null, ref, data) {
  27542. if (!ref) {
  27543. throw new Error('RegionalImageCache.set - expected "ref" argument.');
  27544. }
  27545. if (this._imageCache.has(ref)) {
  27546. return;
  27547. }
  27548. this._imageCache.put(ref, data);
  27549. }
  27550. }
  27551. class GlobalImageCache {
  27552. static NUM_PAGES_THRESHOLD = 2;
  27553. static MIN_IMAGES_TO_CACHE = 10;
  27554. static MAX_BYTE_SIZE = 5 * MAX_IMAGE_SIZE_TO_CACHE;
  27555. constructor() {
  27556. this._refCache = new RefSetCache();
  27557. this._imageCache = new RefSetCache();
  27558. }
  27559. get _byteSize() {
  27560. let byteSize = 0;
  27561. for (const imageData of this._imageCache) {
  27562. byteSize += imageData.byteSize;
  27563. }
  27564. return byteSize;
  27565. }
  27566. get _cacheLimitReached() {
  27567. if (this._imageCache.size < GlobalImageCache.MIN_IMAGES_TO_CACHE) {
  27568. return false;
  27569. }
  27570. if (this._byteSize < GlobalImageCache.MAX_BYTE_SIZE) {
  27571. return false;
  27572. }
  27573. return true;
  27574. }
  27575. shouldCache(ref, pageIndex) {
  27576. let pageIndexSet = this._refCache.get(ref);
  27577. if (!pageIndexSet) {
  27578. pageIndexSet = new Set();
  27579. this._refCache.put(ref, pageIndexSet);
  27580. }
  27581. pageIndexSet.add(pageIndex);
  27582. if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
  27583. return false;
  27584. }
  27585. if (!this._imageCache.has(ref) && this._cacheLimitReached) {
  27586. return false;
  27587. }
  27588. return true;
  27589. }
  27590. addByteSize(ref, byteSize) {
  27591. const imageData = this._imageCache.get(ref);
  27592. if (!imageData) {
  27593. return;
  27594. }
  27595. if (imageData.byteSize) {
  27596. return;
  27597. }
  27598. imageData.byteSize = byteSize;
  27599. }
  27600. getData(ref, pageIndex) {
  27601. const pageIndexSet = this._refCache.get(ref);
  27602. if (!pageIndexSet) {
  27603. return null;
  27604. }
  27605. if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
  27606. return null;
  27607. }
  27608. const imageData = this._imageCache.get(ref);
  27609. if (!imageData) {
  27610. return null;
  27611. }
  27612. pageIndexSet.add(pageIndex);
  27613. return imageData;
  27614. }
  27615. setData(ref, data) {
  27616. if (!this._refCache.has(ref)) {
  27617. throw new Error('GlobalImageCache.setData - expected "shouldCache" to have been called.');
  27618. }
  27619. if (this._imageCache.has(ref)) {
  27620. return;
  27621. }
  27622. if (this._cacheLimitReached) {
  27623. warn("GlobalImageCache.setData - cache limit reached.");
  27624. return;
  27625. }
  27626. this._imageCache.put(ref, data);
  27627. }
  27628. clear(onlyData = false) {
  27629. if (!onlyData) {
  27630. this._refCache.clear();
  27631. }
  27632. this._imageCache.clear();
  27633. }
  27634. }
  27635. ;// CONCATENATED MODULE: ./src/core/function.js
  27636. class PDFFunctionFactory {
  27637. constructor({
  27638. xref,
  27639. isEvalSupported = true
  27640. }) {
  27641. this.xref = xref;
  27642. this.isEvalSupported = isEvalSupported !== false;
  27643. }
  27644. create(fn) {
  27645. const cachedFunction = this.getCached(fn);
  27646. if (cachedFunction) {
  27647. return cachedFunction;
  27648. }
  27649. const parsedFunction = PDFFunction.parse({
  27650. xref: this.xref,
  27651. isEvalSupported: this.isEvalSupported,
  27652. fn: fn instanceof Ref ? this.xref.fetch(fn) : fn
  27653. });
  27654. this._cache(fn, parsedFunction);
  27655. return parsedFunction;
  27656. }
  27657. createFromArray(fnObj) {
  27658. const cachedFunction = this.getCached(fnObj);
  27659. if (cachedFunction) {
  27660. return cachedFunction;
  27661. }
  27662. const parsedFunction = PDFFunction.parseArray({
  27663. xref: this.xref,
  27664. isEvalSupported: this.isEvalSupported,
  27665. fnObj: fnObj instanceof Ref ? this.xref.fetch(fnObj) : fnObj
  27666. });
  27667. this._cache(fnObj, parsedFunction);
  27668. return parsedFunction;
  27669. }
  27670. getCached(cacheKey) {
  27671. let fnRef;
  27672. if (cacheKey instanceof Ref) {
  27673. fnRef = cacheKey;
  27674. } else if (cacheKey instanceof Dict) {
  27675. fnRef = cacheKey.objId;
  27676. } else if (cacheKey instanceof BaseStream) {
  27677. fnRef = cacheKey.dict?.objId;
  27678. }
  27679. if (fnRef) {
  27680. const localFunction = this._localFunctionCache.getByRef(fnRef);
  27681. if (localFunction) {
  27682. return localFunction;
  27683. }
  27684. }
  27685. return null;
  27686. }
  27687. _cache(cacheKey, parsedFunction) {
  27688. if (!parsedFunction) {
  27689. throw new Error('PDFFunctionFactory._cache - expected "parsedFunction" argument.');
  27690. }
  27691. let fnRef;
  27692. if (cacheKey instanceof Ref) {
  27693. fnRef = cacheKey;
  27694. } else if (cacheKey instanceof Dict) {
  27695. fnRef = cacheKey.objId;
  27696. } else if (cacheKey instanceof BaseStream) {
  27697. fnRef = cacheKey.dict?.objId;
  27698. }
  27699. if (fnRef) {
  27700. this._localFunctionCache.set(null, fnRef, parsedFunction);
  27701. }
  27702. }
  27703. get _localFunctionCache() {
  27704. return shadow(this, "_localFunctionCache", new LocalFunctionCache());
  27705. }
  27706. }
  27707. function toNumberArray(arr) {
  27708. if (!Array.isArray(arr)) {
  27709. return null;
  27710. }
  27711. const length = arr.length;
  27712. for (let i = 0; i < length; i++) {
  27713. if (typeof arr[i] !== "number") {
  27714. const result = new Array(length);
  27715. for (let j = 0; j < length; j++) {
  27716. result[j] = +arr[j];
  27717. }
  27718. return result;
  27719. }
  27720. }
  27721. return arr;
  27722. }
  27723. class PDFFunction {
  27724. static getSampleArray(size, outputSize, bps, stream) {
  27725. let i, ii;
  27726. let length = 1;
  27727. for (i = 0, ii = size.length; i < ii; i++) {
  27728. length *= size[i];
  27729. }
  27730. length *= outputSize;
  27731. const array = new Array(length);
  27732. let codeSize = 0;
  27733. let codeBuf = 0;
  27734. const sampleMul = 1.0 / (2.0 ** bps - 1);
  27735. const strBytes = stream.getBytes((length * bps + 7) / 8);
  27736. let strIdx = 0;
  27737. for (i = 0; i < length; i++) {
  27738. while (codeSize < bps) {
  27739. codeBuf <<= 8;
  27740. codeBuf |= strBytes[strIdx++];
  27741. codeSize += 8;
  27742. }
  27743. codeSize -= bps;
  27744. array[i] = (codeBuf >> codeSize) * sampleMul;
  27745. codeBuf &= (1 << codeSize) - 1;
  27746. }
  27747. return array;
  27748. }
  27749. static parse({
  27750. xref,
  27751. isEvalSupported,
  27752. fn
  27753. }) {
  27754. const dict = fn.dict || fn;
  27755. const typeNum = dict.get("FunctionType");
  27756. switch (typeNum) {
  27757. case 0:
  27758. return this.constructSampled({
  27759. xref,
  27760. isEvalSupported,
  27761. fn,
  27762. dict
  27763. });
  27764. case 1:
  27765. break;
  27766. case 2:
  27767. return this.constructInterpolated({
  27768. xref,
  27769. isEvalSupported,
  27770. dict
  27771. });
  27772. case 3:
  27773. return this.constructStiched({
  27774. xref,
  27775. isEvalSupported,
  27776. dict
  27777. });
  27778. case 4:
  27779. return this.constructPostScript({
  27780. xref,
  27781. isEvalSupported,
  27782. fn,
  27783. dict
  27784. });
  27785. }
  27786. throw new FormatError("Unknown type of function");
  27787. }
  27788. static parseArray({
  27789. xref,
  27790. isEvalSupported,
  27791. fnObj
  27792. }) {
  27793. if (!Array.isArray(fnObj)) {
  27794. return this.parse({
  27795. xref,
  27796. isEvalSupported,
  27797. fn: fnObj
  27798. });
  27799. }
  27800. const fnArray = [];
  27801. for (const fn of fnObj) {
  27802. fnArray.push(this.parse({
  27803. xref,
  27804. isEvalSupported,
  27805. fn: xref.fetchIfRef(fn)
  27806. }));
  27807. }
  27808. return function (src, srcOffset, dest, destOffset) {
  27809. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  27810. fnArray[i](src, srcOffset, dest, destOffset + i);
  27811. }
  27812. };
  27813. }
  27814. static constructSampled({
  27815. xref,
  27816. isEvalSupported,
  27817. fn,
  27818. dict
  27819. }) {
  27820. function toMultiArray(arr) {
  27821. const inputLength = arr.length;
  27822. const out = [];
  27823. let index = 0;
  27824. for (let i = 0; i < inputLength; i += 2) {
  27825. out[index++] = [arr[i], arr[i + 1]];
  27826. }
  27827. return out;
  27828. }
  27829. function interpolate(x, xmin, xmax, ymin, ymax) {
  27830. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  27831. }
  27832. let domain = toNumberArray(dict.getArray("Domain"));
  27833. let range = toNumberArray(dict.getArray("Range"));
  27834. if (!domain || !range) {
  27835. throw new FormatError("No domain or range");
  27836. }
  27837. const inputSize = domain.length / 2;
  27838. const outputSize = range.length / 2;
  27839. domain = toMultiArray(domain);
  27840. range = toMultiArray(range);
  27841. const size = toNumberArray(dict.getArray("Size"));
  27842. const bps = dict.get("BitsPerSample");
  27843. const order = dict.get("Order") || 1;
  27844. if (order !== 1) {
  27845. info("No support for cubic spline interpolation: " + order);
  27846. }
  27847. let encode = toNumberArray(dict.getArray("Encode"));
  27848. if (!encode) {
  27849. encode = [];
  27850. for (let i = 0; i < inputSize; ++i) {
  27851. encode.push([0, size[i] - 1]);
  27852. }
  27853. } else {
  27854. encode = toMultiArray(encode);
  27855. }
  27856. let decode = toNumberArray(dict.getArray("Decode"));
  27857. decode = !decode ? range : toMultiArray(decode);
  27858. const samples = this.getSampleArray(size, outputSize, bps, fn);
  27859. return function constructSampledFn(src, srcOffset, dest, destOffset) {
  27860. const cubeVertices = 1 << inputSize;
  27861. const cubeN = new Float64Array(cubeVertices);
  27862. const cubeVertex = new Uint32Array(cubeVertices);
  27863. let i, j;
  27864. for (j = 0; j < cubeVertices; j++) {
  27865. cubeN[j] = 1;
  27866. }
  27867. let k = outputSize,
  27868. pos = 1;
  27869. for (i = 0; i < inputSize; ++i) {
  27870. const domain_2i = domain[i][0];
  27871. const domain_2i_1 = domain[i][1];
  27872. const xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  27873. let e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  27874. const size_i = size[i];
  27875. e = Math.min(Math.max(e, 0), size_i - 1);
  27876. const e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  27877. const n0 = e0 + 1 - e;
  27878. const n1 = e - e0;
  27879. const offset0 = e0 * k;
  27880. const offset1 = offset0 + k;
  27881. for (j = 0; j < cubeVertices; j++) {
  27882. if (j & pos) {
  27883. cubeN[j] *= n1;
  27884. cubeVertex[j] += offset1;
  27885. } else {
  27886. cubeN[j] *= n0;
  27887. cubeVertex[j] += offset0;
  27888. }
  27889. }
  27890. k *= size_i;
  27891. pos <<= 1;
  27892. }
  27893. for (j = 0; j < outputSize; ++j) {
  27894. let rj = 0;
  27895. for (i = 0; i < cubeVertices; i++) {
  27896. rj += samples[cubeVertex[i] + j] * cubeN[i];
  27897. }
  27898. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  27899. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  27900. }
  27901. };
  27902. }
  27903. static constructInterpolated({
  27904. xref,
  27905. isEvalSupported,
  27906. dict
  27907. }) {
  27908. const c0 = toNumberArray(dict.getArray("C0")) || [0];
  27909. const c1 = toNumberArray(dict.getArray("C1")) || [1];
  27910. const n = dict.get("N");
  27911. const diff = [];
  27912. for (let i = 0, ii = c0.length; i < ii; ++i) {
  27913. diff.push(c1[i] - c0[i]);
  27914. }
  27915. const length = diff.length;
  27916. return function constructInterpolatedFn(src, srcOffset, dest, destOffset) {
  27917. const x = n === 1 ? src[srcOffset] : src[srcOffset] ** n;
  27918. for (let j = 0; j < length; ++j) {
  27919. dest[destOffset + j] = c0[j] + x * diff[j];
  27920. }
  27921. };
  27922. }
  27923. static constructStiched({
  27924. xref,
  27925. isEvalSupported,
  27926. dict
  27927. }) {
  27928. const domain = toNumberArray(dict.getArray("Domain"));
  27929. if (!domain) {
  27930. throw new FormatError("No domain");
  27931. }
  27932. const inputSize = domain.length / 2;
  27933. if (inputSize !== 1) {
  27934. throw new FormatError("Bad domain for stiched function");
  27935. }
  27936. const fns = [];
  27937. for (const fn of dict.get("Functions")) {
  27938. fns.push(this.parse({
  27939. xref,
  27940. isEvalSupported,
  27941. fn: xref.fetchIfRef(fn)
  27942. }));
  27943. }
  27944. const bounds = toNumberArray(dict.getArray("Bounds"));
  27945. const encode = toNumberArray(dict.getArray("Encode"));
  27946. const tmpBuf = new Float32Array(1);
  27947. return function constructStichedFn(src, srcOffset, dest, destOffset) {
  27948. const clip = function constructStichedFromIRClip(v, min, max) {
  27949. if (v > max) {
  27950. v = max;
  27951. } else if (v < min) {
  27952. v = min;
  27953. }
  27954. return v;
  27955. };
  27956. const v = clip(src[srcOffset], domain[0], domain[1]);
  27957. const length = bounds.length;
  27958. let i;
  27959. for (i = 0; i < length; ++i) {
  27960. if (v < bounds[i]) {
  27961. break;
  27962. }
  27963. }
  27964. let dmin = domain[0];
  27965. if (i > 0) {
  27966. dmin = bounds[i - 1];
  27967. }
  27968. let dmax = domain[1];
  27969. if (i < bounds.length) {
  27970. dmax = bounds[i];
  27971. }
  27972. const rmin = encode[2 * i];
  27973. const rmax = encode[2 * i + 1];
  27974. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  27975. fns[i](tmpBuf, 0, dest, destOffset);
  27976. };
  27977. }
  27978. static constructPostScript({
  27979. xref,
  27980. isEvalSupported,
  27981. fn,
  27982. dict
  27983. }) {
  27984. const domain = toNumberArray(dict.getArray("Domain"));
  27985. const range = toNumberArray(dict.getArray("Range"));
  27986. if (!domain) {
  27987. throw new FormatError("No domain.");
  27988. }
  27989. if (!range) {
  27990. throw new FormatError("No range.");
  27991. }
  27992. const lexer = new PostScriptLexer(fn);
  27993. const parser = new PostScriptParser(lexer);
  27994. const code = parser.parse();
  27995. if (isEvalSupported && FeatureTest.isEvalSupported) {
  27996. const compiled = new PostScriptCompiler().compile(code, domain, range);
  27997. if (compiled) {
  27998. return new Function("src", "srcOffset", "dest", "destOffset", compiled);
  27999. }
  28000. }
  28001. info("Unable to compile PS function");
  28002. const numOutputs = range.length >> 1;
  28003. const numInputs = domain.length >> 1;
  28004. const evaluator = new PostScriptEvaluator(code);
  28005. const cache = Object.create(null);
  28006. const MAX_CACHE_SIZE = 2048 * 4;
  28007. let cache_available = MAX_CACHE_SIZE;
  28008. const tmpBuf = new Float32Array(numInputs);
  28009. return function constructPostScriptFn(src, srcOffset, dest, destOffset) {
  28010. let i, value;
  28011. let key = "";
  28012. const input = tmpBuf;
  28013. for (i = 0; i < numInputs; i++) {
  28014. value = src[srcOffset + i];
  28015. input[i] = value;
  28016. key += value + "_";
  28017. }
  28018. const cachedValue = cache[key];
  28019. if (cachedValue !== undefined) {
  28020. dest.set(cachedValue, destOffset);
  28021. return;
  28022. }
  28023. const output = new Float32Array(numOutputs);
  28024. const stack = evaluator.execute(input);
  28025. const stackIndex = stack.length - numOutputs;
  28026. for (i = 0; i < numOutputs; i++) {
  28027. value = stack[stackIndex + i];
  28028. let bound = range[i * 2];
  28029. if (value < bound) {
  28030. value = bound;
  28031. } else {
  28032. bound = range[i * 2 + 1];
  28033. if (value > bound) {
  28034. value = bound;
  28035. }
  28036. }
  28037. output[i] = value;
  28038. }
  28039. if (cache_available > 0) {
  28040. cache_available--;
  28041. cache[key] = output;
  28042. }
  28043. dest.set(output, destOffset);
  28044. };
  28045. }
  28046. }
  28047. function isPDFFunction(v) {
  28048. let fnDict;
  28049. if (v instanceof Dict) {
  28050. fnDict = v;
  28051. } else if (v instanceof BaseStream) {
  28052. fnDict = v.dict;
  28053. } else {
  28054. return false;
  28055. }
  28056. return fnDict.has("FunctionType");
  28057. }
  28058. class PostScriptStack {
  28059. static MAX_STACK_SIZE = 100;
  28060. constructor(initialStack) {
  28061. this.stack = initialStack ? Array.from(initialStack) : [];
  28062. }
  28063. push(value) {
  28064. if (this.stack.length >= PostScriptStack.MAX_STACK_SIZE) {
  28065. throw new Error("PostScript function stack overflow.");
  28066. }
  28067. this.stack.push(value);
  28068. }
  28069. pop() {
  28070. if (this.stack.length <= 0) {
  28071. throw new Error("PostScript function stack underflow.");
  28072. }
  28073. return this.stack.pop();
  28074. }
  28075. copy(n) {
  28076. if (this.stack.length + n >= PostScriptStack.MAX_STACK_SIZE) {
  28077. throw new Error("PostScript function stack overflow.");
  28078. }
  28079. const stack = this.stack;
  28080. for (let i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  28081. stack.push(stack[i]);
  28082. }
  28083. }
  28084. index(n) {
  28085. this.push(this.stack[this.stack.length - n - 1]);
  28086. }
  28087. roll(n, p) {
  28088. const stack = this.stack;
  28089. const l = stack.length - n;
  28090. const r = stack.length - 1;
  28091. const c = l + (p - Math.floor(p / n) * n);
  28092. for (let i = l, j = r; i < j; i++, j--) {
  28093. const t = stack[i];
  28094. stack[i] = stack[j];
  28095. stack[j] = t;
  28096. }
  28097. for (let i = l, j = c - 1; i < j; i++, j--) {
  28098. const t = stack[i];
  28099. stack[i] = stack[j];
  28100. stack[j] = t;
  28101. }
  28102. for (let i = c, j = r; i < j; i++, j--) {
  28103. const t = stack[i];
  28104. stack[i] = stack[j];
  28105. stack[j] = t;
  28106. }
  28107. }
  28108. }
  28109. class PostScriptEvaluator {
  28110. constructor(operators) {
  28111. this.operators = operators;
  28112. }
  28113. execute(initialStack) {
  28114. const stack = new PostScriptStack(initialStack);
  28115. let counter = 0;
  28116. const operators = this.operators;
  28117. const length = operators.length;
  28118. let operator, a, b;
  28119. while (counter < length) {
  28120. operator = operators[counter++];
  28121. if (typeof operator === "number") {
  28122. stack.push(operator);
  28123. continue;
  28124. }
  28125. switch (operator) {
  28126. case "jz":
  28127. b = stack.pop();
  28128. a = stack.pop();
  28129. if (!a) {
  28130. counter = b;
  28131. }
  28132. break;
  28133. case "j":
  28134. a = stack.pop();
  28135. counter = a;
  28136. break;
  28137. case "abs":
  28138. a = stack.pop();
  28139. stack.push(Math.abs(a));
  28140. break;
  28141. case "add":
  28142. b = stack.pop();
  28143. a = stack.pop();
  28144. stack.push(a + b);
  28145. break;
  28146. case "and":
  28147. b = stack.pop();
  28148. a = stack.pop();
  28149. if (typeof a === "boolean" && typeof b === "boolean") {
  28150. stack.push(a && b);
  28151. } else {
  28152. stack.push(a & b);
  28153. }
  28154. break;
  28155. case "atan":
  28156. b = stack.pop();
  28157. a = stack.pop();
  28158. a = Math.atan2(a, b) / Math.PI * 180;
  28159. if (a < 0) {
  28160. a += 360;
  28161. }
  28162. stack.push(a);
  28163. break;
  28164. case "bitshift":
  28165. b = stack.pop();
  28166. a = stack.pop();
  28167. if (a > 0) {
  28168. stack.push(a << b);
  28169. } else {
  28170. stack.push(a >> b);
  28171. }
  28172. break;
  28173. case "ceiling":
  28174. a = stack.pop();
  28175. stack.push(Math.ceil(a));
  28176. break;
  28177. case "copy":
  28178. a = stack.pop();
  28179. stack.copy(a);
  28180. break;
  28181. case "cos":
  28182. a = stack.pop();
  28183. stack.push(Math.cos(a % 360 / 180 * Math.PI));
  28184. break;
  28185. case "cvi":
  28186. a = stack.pop() | 0;
  28187. stack.push(a);
  28188. break;
  28189. case "cvr":
  28190. break;
  28191. case "div":
  28192. b = stack.pop();
  28193. a = stack.pop();
  28194. stack.push(a / b);
  28195. break;
  28196. case "dup":
  28197. stack.copy(1);
  28198. break;
  28199. case "eq":
  28200. b = stack.pop();
  28201. a = stack.pop();
  28202. stack.push(a === b);
  28203. break;
  28204. case "exch":
  28205. stack.roll(2, 1);
  28206. break;
  28207. case "exp":
  28208. b = stack.pop();
  28209. a = stack.pop();
  28210. stack.push(a ** b);
  28211. break;
  28212. case "false":
  28213. stack.push(false);
  28214. break;
  28215. case "floor":
  28216. a = stack.pop();
  28217. stack.push(Math.floor(a));
  28218. break;
  28219. case "ge":
  28220. b = stack.pop();
  28221. a = stack.pop();
  28222. stack.push(a >= b);
  28223. break;
  28224. case "gt":
  28225. b = stack.pop();
  28226. a = stack.pop();
  28227. stack.push(a > b);
  28228. break;
  28229. case "idiv":
  28230. b = stack.pop();
  28231. a = stack.pop();
  28232. stack.push(a / b | 0);
  28233. break;
  28234. case "index":
  28235. a = stack.pop();
  28236. stack.index(a);
  28237. break;
  28238. case "le":
  28239. b = stack.pop();
  28240. a = stack.pop();
  28241. stack.push(a <= b);
  28242. break;
  28243. case "ln":
  28244. a = stack.pop();
  28245. stack.push(Math.log(a));
  28246. break;
  28247. case "log":
  28248. a = stack.pop();
  28249. stack.push(Math.log10(a));
  28250. break;
  28251. case "lt":
  28252. b = stack.pop();
  28253. a = stack.pop();
  28254. stack.push(a < b);
  28255. break;
  28256. case "mod":
  28257. b = stack.pop();
  28258. a = stack.pop();
  28259. stack.push(a % b);
  28260. break;
  28261. case "mul":
  28262. b = stack.pop();
  28263. a = stack.pop();
  28264. stack.push(a * b);
  28265. break;
  28266. case "ne":
  28267. b = stack.pop();
  28268. a = stack.pop();
  28269. stack.push(a !== b);
  28270. break;
  28271. case "neg":
  28272. a = stack.pop();
  28273. stack.push(-a);
  28274. break;
  28275. case "not":
  28276. a = stack.pop();
  28277. if (typeof a === "boolean") {
  28278. stack.push(!a);
  28279. } else {
  28280. stack.push(~a);
  28281. }
  28282. break;
  28283. case "or":
  28284. b = stack.pop();
  28285. a = stack.pop();
  28286. if (typeof a === "boolean" && typeof b === "boolean") {
  28287. stack.push(a || b);
  28288. } else {
  28289. stack.push(a | b);
  28290. }
  28291. break;
  28292. case "pop":
  28293. stack.pop();
  28294. break;
  28295. case "roll":
  28296. b = stack.pop();
  28297. a = stack.pop();
  28298. stack.roll(a, b);
  28299. break;
  28300. case "round":
  28301. a = stack.pop();
  28302. stack.push(Math.round(a));
  28303. break;
  28304. case "sin":
  28305. a = stack.pop();
  28306. stack.push(Math.sin(a % 360 / 180 * Math.PI));
  28307. break;
  28308. case "sqrt":
  28309. a = stack.pop();
  28310. stack.push(Math.sqrt(a));
  28311. break;
  28312. case "sub":
  28313. b = stack.pop();
  28314. a = stack.pop();
  28315. stack.push(a - b);
  28316. break;
  28317. case "true":
  28318. stack.push(true);
  28319. break;
  28320. case "truncate":
  28321. a = stack.pop();
  28322. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  28323. stack.push(a);
  28324. break;
  28325. case "xor":
  28326. b = stack.pop();
  28327. a = stack.pop();
  28328. if (typeof a === "boolean" && typeof b === "boolean") {
  28329. stack.push(a !== b);
  28330. } else {
  28331. stack.push(a ^ b);
  28332. }
  28333. break;
  28334. default:
  28335. throw new FormatError(`Unknown operator ${operator}`);
  28336. }
  28337. }
  28338. return stack.stack;
  28339. }
  28340. }
  28341. class AstNode {
  28342. constructor(type) {
  28343. this.type = type;
  28344. }
  28345. visit(visitor) {
  28346. unreachable("abstract method");
  28347. }
  28348. }
  28349. class AstArgument extends AstNode {
  28350. constructor(index, min, max) {
  28351. super("args");
  28352. this.index = index;
  28353. this.min = min;
  28354. this.max = max;
  28355. }
  28356. visit(visitor) {
  28357. visitor.visitArgument(this);
  28358. }
  28359. }
  28360. class AstLiteral extends AstNode {
  28361. constructor(number) {
  28362. super("literal");
  28363. this.number = number;
  28364. this.min = number;
  28365. this.max = number;
  28366. }
  28367. visit(visitor) {
  28368. visitor.visitLiteral(this);
  28369. }
  28370. }
  28371. class AstBinaryOperation extends AstNode {
  28372. constructor(op, arg1, arg2, min, max) {
  28373. super("binary");
  28374. this.op = op;
  28375. this.arg1 = arg1;
  28376. this.arg2 = arg2;
  28377. this.min = min;
  28378. this.max = max;
  28379. }
  28380. visit(visitor) {
  28381. visitor.visitBinaryOperation(this);
  28382. }
  28383. }
  28384. class AstMin extends AstNode {
  28385. constructor(arg, max) {
  28386. super("max");
  28387. this.arg = arg;
  28388. this.min = arg.min;
  28389. this.max = max;
  28390. }
  28391. visit(visitor) {
  28392. visitor.visitMin(this);
  28393. }
  28394. }
  28395. class AstVariable extends AstNode {
  28396. constructor(index, min, max) {
  28397. super("var");
  28398. this.index = index;
  28399. this.min = min;
  28400. this.max = max;
  28401. }
  28402. visit(visitor) {
  28403. visitor.visitVariable(this);
  28404. }
  28405. }
  28406. class AstVariableDefinition extends AstNode {
  28407. constructor(variable, arg) {
  28408. super("definition");
  28409. this.variable = variable;
  28410. this.arg = arg;
  28411. }
  28412. visit(visitor) {
  28413. visitor.visitVariableDefinition(this);
  28414. }
  28415. }
  28416. class ExpressionBuilderVisitor {
  28417. constructor() {
  28418. this.parts = [];
  28419. }
  28420. visitArgument(arg) {
  28421. this.parts.push("Math.max(", arg.min, ", Math.min(", arg.max, ", src[srcOffset + ", arg.index, "]))");
  28422. }
  28423. visitVariable(variable) {
  28424. this.parts.push("v", variable.index);
  28425. }
  28426. visitLiteral(literal) {
  28427. this.parts.push(literal.number);
  28428. }
  28429. visitBinaryOperation(operation) {
  28430. this.parts.push("(");
  28431. operation.arg1.visit(this);
  28432. this.parts.push(" ", operation.op, " ");
  28433. operation.arg2.visit(this);
  28434. this.parts.push(")");
  28435. }
  28436. visitVariableDefinition(definition) {
  28437. this.parts.push("var ");
  28438. definition.variable.visit(this);
  28439. this.parts.push(" = ");
  28440. definition.arg.visit(this);
  28441. this.parts.push(";");
  28442. }
  28443. visitMin(max) {
  28444. this.parts.push("Math.min(");
  28445. max.arg.visit(this);
  28446. this.parts.push(", ", max.max, ")");
  28447. }
  28448. toString() {
  28449. return this.parts.join("");
  28450. }
  28451. }
  28452. function buildAddOperation(num1, num2) {
  28453. if (num2.type === "literal" && num2.number === 0) {
  28454. return num1;
  28455. }
  28456. if (num1.type === "literal" && num1.number === 0) {
  28457. return num2;
  28458. }
  28459. if (num2.type === "literal" && num1.type === "literal") {
  28460. return new AstLiteral(num1.number + num2.number);
  28461. }
  28462. return new AstBinaryOperation("+", num1, num2, num1.min + num2.min, num1.max + num2.max);
  28463. }
  28464. function buildMulOperation(num1, num2) {
  28465. if (num2.type === "literal") {
  28466. if (num2.number === 0) {
  28467. return new AstLiteral(0);
  28468. } else if (num2.number === 1) {
  28469. return num1;
  28470. } else if (num1.type === "literal") {
  28471. return new AstLiteral(num1.number * num2.number);
  28472. }
  28473. }
  28474. if (num1.type === "literal") {
  28475. if (num1.number === 0) {
  28476. return new AstLiteral(0);
  28477. } else if (num1.number === 1) {
  28478. return num2;
  28479. }
  28480. }
  28481. const min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  28482. const max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  28483. return new AstBinaryOperation("*", num1, num2, min, max);
  28484. }
  28485. function buildSubOperation(num1, num2) {
  28486. if (num2.type === "literal") {
  28487. if (num2.number === 0) {
  28488. return num1;
  28489. } else if (num1.type === "literal") {
  28490. return new AstLiteral(num1.number - num2.number);
  28491. }
  28492. }
  28493. if (num2.type === "binary" && num2.op === "-" && num1.type === "literal" && num1.number === 1 && num2.arg1.type === "literal" && num2.arg1.number === 1) {
  28494. return num2.arg2;
  28495. }
  28496. return new AstBinaryOperation("-", num1, num2, num1.min - num2.max, num1.max - num2.min);
  28497. }
  28498. function buildMinOperation(num1, max) {
  28499. if (num1.min >= max) {
  28500. return new AstLiteral(max);
  28501. } else if (num1.max <= max) {
  28502. return num1;
  28503. }
  28504. return new AstMin(num1, max);
  28505. }
  28506. class PostScriptCompiler {
  28507. compile(code, domain, range) {
  28508. const stack = [];
  28509. const instructions = [];
  28510. const inputSize = domain.length >> 1,
  28511. outputSize = range.length >> 1;
  28512. let lastRegister = 0;
  28513. let n, j;
  28514. let num1, num2, ast1, ast2, tmpVar, item;
  28515. for (let i = 0; i < inputSize; i++) {
  28516. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  28517. }
  28518. for (let i = 0, ii = code.length; i < ii; i++) {
  28519. item = code[i];
  28520. if (typeof item === "number") {
  28521. stack.push(new AstLiteral(item));
  28522. continue;
  28523. }
  28524. switch (item) {
  28525. case "add":
  28526. if (stack.length < 2) {
  28527. return null;
  28528. }
  28529. num2 = stack.pop();
  28530. num1 = stack.pop();
  28531. stack.push(buildAddOperation(num1, num2));
  28532. break;
  28533. case "cvr":
  28534. if (stack.length < 1) {
  28535. return null;
  28536. }
  28537. break;
  28538. case "mul":
  28539. if (stack.length < 2) {
  28540. return null;
  28541. }
  28542. num2 = stack.pop();
  28543. num1 = stack.pop();
  28544. stack.push(buildMulOperation(num1, num2));
  28545. break;
  28546. case "sub":
  28547. if (stack.length < 2) {
  28548. return null;
  28549. }
  28550. num2 = stack.pop();
  28551. num1 = stack.pop();
  28552. stack.push(buildSubOperation(num1, num2));
  28553. break;
  28554. case "exch":
  28555. if (stack.length < 2) {
  28556. return null;
  28557. }
  28558. ast1 = stack.pop();
  28559. ast2 = stack.pop();
  28560. stack.push(ast1, ast2);
  28561. break;
  28562. case "pop":
  28563. if (stack.length < 1) {
  28564. return null;
  28565. }
  28566. stack.pop();
  28567. break;
  28568. case "index":
  28569. if (stack.length < 1) {
  28570. return null;
  28571. }
  28572. num1 = stack.pop();
  28573. if (num1.type !== "literal") {
  28574. return null;
  28575. }
  28576. n = num1.number;
  28577. if (n < 0 || !Number.isInteger(n) || stack.length < n) {
  28578. return null;
  28579. }
  28580. ast1 = stack[stack.length - n - 1];
  28581. if (ast1.type === "literal" || ast1.type === "var") {
  28582. stack.push(ast1);
  28583. break;
  28584. }
  28585. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  28586. stack[stack.length - n - 1] = tmpVar;
  28587. stack.push(tmpVar);
  28588. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  28589. break;
  28590. case "dup":
  28591. if (stack.length < 1) {
  28592. return null;
  28593. }
  28594. 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]) {
  28595. num1 = stack.pop();
  28596. stack.push(buildMinOperation(num1, code[i + 1]));
  28597. i += 6;
  28598. break;
  28599. }
  28600. ast1 = stack.at(-1);
  28601. if (ast1.type === "literal" || ast1.type === "var") {
  28602. stack.push(ast1);
  28603. break;
  28604. }
  28605. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  28606. stack[stack.length - 1] = tmpVar;
  28607. stack.push(tmpVar);
  28608. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  28609. break;
  28610. case "roll":
  28611. if (stack.length < 2) {
  28612. return null;
  28613. }
  28614. num2 = stack.pop();
  28615. num1 = stack.pop();
  28616. if (num2.type !== "literal" || num1.type !== "literal") {
  28617. return null;
  28618. }
  28619. j = num2.number;
  28620. n = num1.number;
  28621. if (n <= 0 || !Number.isInteger(n) || !Number.isInteger(j) || stack.length < n) {
  28622. return null;
  28623. }
  28624. j = (j % n + n) % n;
  28625. if (j === 0) {
  28626. break;
  28627. }
  28628. stack.push(...stack.splice(stack.length - n, n - j));
  28629. break;
  28630. default:
  28631. return null;
  28632. }
  28633. }
  28634. if (stack.length !== outputSize) {
  28635. return null;
  28636. }
  28637. const result = [];
  28638. for (const instruction of instructions) {
  28639. const statementBuilder = new ExpressionBuilderVisitor();
  28640. instruction.visit(statementBuilder);
  28641. result.push(statementBuilder.toString());
  28642. }
  28643. for (let i = 0, ii = stack.length; i < ii; i++) {
  28644. const expr = stack[i],
  28645. statementBuilder = new ExpressionBuilderVisitor();
  28646. expr.visit(statementBuilder);
  28647. const min = range[i * 2],
  28648. max = range[i * 2 + 1];
  28649. const out = [statementBuilder.toString()];
  28650. if (min > expr.min) {
  28651. out.unshift("Math.max(", min, ", ");
  28652. out.push(")");
  28653. }
  28654. if (max < expr.max) {
  28655. out.unshift("Math.min(", max, ", ");
  28656. out.push(")");
  28657. }
  28658. out.unshift("dest[destOffset + ", i, "] = ");
  28659. out.push(";");
  28660. result.push(out.join(""));
  28661. }
  28662. return result.join("\n");
  28663. }
  28664. }
  28665. ;// CONCATENATED MODULE: ./src/core/bidi.js
  28666. const baseTypes = ["BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "S", "B", "S", "WS", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "B", "B", "B", "S", "WS", "ON", "ON", "ET", "ET", "ET", "ON", "ON", "ON", "ON", "ON", "ES", "CS", "ES", "CS", "CS", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "CS", "ON", "ON", "ON", "ON", "ON", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "ON", "ON", "ON", "ON", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "ON", "ON", "ON", "BN", "BN", "BN", "BN", "BN", "BN", "B", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "BN", "CS", "ON", "ET", "ET", "ET", "ET", "ON", "ON", "ON", "ON", "L", "ON", "ON", "BN", "ON", "ON", "ET", "ET", "EN", "EN", "ON", "L", "ON", "ON", "ON", "EN", "L", "ON", "ON", "ON", "ON", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "L", "ON", "L", "L", "L", "L", "L", "L", "L", "L"];
  28667. const arabicTypes = ["AN", "AN", "AN", "AN", "AN", "AN", "ON", "ON", "AL", "ET", "ET", "AL", "CS", "AL", "ON", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "AN", "ET", "AN", "AN", "AL", "AL", "AL", "NSM", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "AL", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AN", "ON", "NSM", "NSM", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "NSM", "NSM", "ON", "NSM", "NSM", "NSM", "NSM", "AL", "AL", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "EN", "AL", "AL", "AL", "AL", "AL", "AL"];
  28668. function isOdd(i) {
  28669. return (i & 1) !== 0;
  28670. }
  28671. function isEven(i) {
  28672. return (i & 1) === 0;
  28673. }
  28674. function findUnequal(arr, start, value) {
  28675. let j, jj;
  28676. for (j = start, jj = arr.length; j < jj; ++j) {
  28677. if (arr[j] !== value) {
  28678. return j;
  28679. }
  28680. }
  28681. return j;
  28682. }
  28683. function setValues(arr, start, end, value) {
  28684. for (let j = start; j < end; ++j) {
  28685. arr[j] = value;
  28686. }
  28687. }
  28688. function reverseValues(arr, start, end) {
  28689. for (let i = start, j = end - 1; i < j; ++i, --j) {
  28690. const temp = arr[i];
  28691. arr[i] = arr[j];
  28692. arr[j] = temp;
  28693. }
  28694. }
  28695. function createBidiText(str, isLTR, vertical = false) {
  28696. let dir = "ltr";
  28697. if (vertical) {
  28698. dir = "ttb";
  28699. } else if (!isLTR) {
  28700. dir = "rtl";
  28701. }
  28702. return {
  28703. str,
  28704. dir
  28705. };
  28706. }
  28707. const chars = [];
  28708. const types = [];
  28709. function bidi(str, startLevel = -1, vertical = false) {
  28710. let isLTR = true;
  28711. const strLength = str.length;
  28712. if (strLength === 0 || vertical) {
  28713. return createBidiText(str, isLTR, vertical);
  28714. }
  28715. chars.length = strLength;
  28716. types.length = strLength;
  28717. let numBidi = 0;
  28718. let i, ii;
  28719. for (i = 0; i < strLength; ++i) {
  28720. chars[i] = str.charAt(i);
  28721. const charCode = str.charCodeAt(i);
  28722. let charType = "L";
  28723. if (charCode <= 0x00ff) {
  28724. charType = baseTypes[charCode];
  28725. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  28726. charType = "R";
  28727. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  28728. charType = arabicTypes[charCode & 0xff];
  28729. if (!charType) {
  28730. warn("Bidi: invalid Unicode character " + charCode.toString(16));
  28731. }
  28732. } else if (0x0700 <= charCode && charCode <= 0x08ac || 0xfb50 <= charCode && charCode <= 0xfdff || 0xfe70 <= charCode && charCode <= 0xfeff) {
  28733. charType = "AL";
  28734. }
  28735. if (charType === "R" || charType === "AL" || charType === "AN") {
  28736. numBidi++;
  28737. }
  28738. types[i] = charType;
  28739. }
  28740. if (numBidi === 0) {
  28741. isLTR = true;
  28742. return createBidiText(str, isLTR);
  28743. }
  28744. if (startLevel === -1) {
  28745. if (numBidi / strLength < 0.3 && strLength > 4) {
  28746. isLTR = true;
  28747. startLevel = 0;
  28748. } else {
  28749. isLTR = false;
  28750. startLevel = 1;
  28751. }
  28752. }
  28753. const levels = [];
  28754. for (i = 0; i < strLength; ++i) {
  28755. levels[i] = startLevel;
  28756. }
  28757. const e = isOdd(startLevel) ? "R" : "L";
  28758. const sor = e;
  28759. const eor = sor;
  28760. let lastType = sor;
  28761. for (i = 0; i < strLength; ++i) {
  28762. if (types[i] === "NSM") {
  28763. types[i] = lastType;
  28764. } else {
  28765. lastType = types[i];
  28766. }
  28767. }
  28768. lastType = sor;
  28769. let t;
  28770. for (i = 0; i < strLength; ++i) {
  28771. t = types[i];
  28772. if (t === "EN") {
  28773. types[i] = lastType === "AL" ? "AN" : "EN";
  28774. } else if (t === "R" || t === "L" || t === "AL") {
  28775. lastType = t;
  28776. }
  28777. }
  28778. for (i = 0; i < strLength; ++i) {
  28779. t = types[i];
  28780. if (t === "AL") {
  28781. types[i] = "R";
  28782. }
  28783. }
  28784. for (i = 1; i < strLength - 1; ++i) {
  28785. if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
  28786. types[i] = "EN";
  28787. }
  28788. if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
  28789. types[i] = types[i - 1];
  28790. }
  28791. }
  28792. for (i = 0; i < strLength; ++i) {
  28793. if (types[i] === "EN") {
  28794. for (let j = i - 1; j >= 0; --j) {
  28795. if (types[j] !== "ET") {
  28796. break;
  28797. }
  28798. types[j] = "EN";
  28799. }
  28800. for (let j = i + 1; j < strLength; ++j) {
  28801. if (types[j] !== "ET") {
  28802. break;
  28803. }
  28804. types[j] = "EN";
  28805. }
  28806. }
  28807. }
  28808. for (i = 0; i < strLength; ++i) {
  28809. t = types[i];
  28810. if (t === "WS" || t === "ES" || t === "ET" || t === "CS") {
  28811. types[i] = "ON";
  28812. }
  28813. }
  28814. lastType = sor;
  28815. for (i = 0; i < strLength; ++i) {
  28816. t = types[i];
  28817. if (t === "EN") {
  28818. types[i] = lastType === "L" ? "L" : "EN";
  28819. } else if (t === "R" || t === "L") {
  28820. lastType = t;
  28821. }
  28822. }
  28823. for (i = 0; i < strLength; ++i) {
  28824. if (types[i] === "ON") {
  28825. const end = findUnequal(types, i + 1, "ON");
  28826. let before = sor;
  28827. if (i > 0) {
  28828. before = types[i - 1];
  28829. }
  28830. let after = eor;
  28831. if (end + 1 < strLength) {
  28832. after = types[end + 1];
  28833. }
  28834. if (before !== "L") {
  28835. before = "R";
  28836. }
  28837. if (after !== "L") {
  28838. after = "R";
  28839. }
  28840. if (before === after) {
  28841. setValues(types, i, end, before);
  28842. }
  28843. i = end - 1;
  28844. }
  28845. }
  28846. for (i = 0; i < strLength; ++i) {
  28847. if (types[i] === "ON") {
  28848. types[i] = e;
  28849. }
  28850. }
  28851. for (i = 0; i < strLength; ++i) {
  28852. t = types[i];
  28853. if (isEven(levels[i])) {
  28854. if (t === "R") {
  28855. levels[i] += 1;
  28856. } else if (t === "AN" || t === "EN") {
  28857. levels[i] += 2;
  28858. }
  28859. } else if (t === "L" || t === "AN" || t === "EN") {
  28860. levels[i] += 1;
  28861. }
  28862. }
  28863. let highestLevel = -1;
  28864. let lowestOddLevel = 99;
  28865. let level;
  28866. for (i = 0, ii = levels.length; i < ii; ++i) {
  28867. level = levels[i];
  28868. if (highestLevel < level) {
  28869. highestLevel = level;
  28870. }
  28871. if (lowestOddLevel > level && isOdd(level)) {
  28872. lowestOddLevel = level;
  28873. }
  28874. }
  28875. for (level = highestLevel; level >= lowestOddLevel; --level) {
  28876. let start = -1;
  28877. for (i = 0, ii = levels.length; i < ii; ++i) {
  28878. if (levels[i] < level) {
  28879. if (start >= 0) {
  28880. reverseValues(chars, start, i);
  28881. start = -1;
  28882. }
  28883. } else if (start < 0) {
  28884. start = i;
  28885. }
  28886. }
  28887. if (start >= 0) {
  28888. reverseValues(chars, start, levels.length);
  28889. }
  28890. }
  28891. for (i = 0, ii = chars.length; i < ii; ++i) {
  28892. const ch = chars[i];
  28893. if (ch === "<" || ch === ">") {
  28894. chars[i] = "";
  28895. }
  28896. }
  28897. return createBidiText(chars.join(""), isLTR);
  28898. }
  28899. ;// CONCATENATED MODULE: ./src/core/font_substitutions.js
  28900. const NORMAL = {
  28901. style: "normal",
  28902. weight: "normal"
  28903. };
  28904. const BOLD = {
  28905. style: "normal",
  28906. weight: "bold"
  28907. };
  28908. const ITALIC = {
  28909. style: "italic",
  28910. weight: "normal"
  28911. };
  28912. const BOLDITALIC = {
  28913. style: "italic",
  28914. weight: "bold"
  28915. };
  28916. const substitutionMap = new Map([["Times-Roman", {
  28917. local: ["Times New Roman", "Times-Roman", "Times", "Liberation Serif", "Nimbus Roman", "Nimbus Roman L", "Tinos", "Thorndale", "TeX Gyre Termes", "FreeSerif", "DejaVu Serif", "Bitstream Vera Serif", "Ubuntu"],
  28918. style: NORMAL,
  28919. ultimate: "serif"
  28920. }], ["Times-Bold", {
  28921. alias: "Times-Roman",
  28922. style: BOLD,
  28923. ultimate: "serif"
  28924. }], ["Times-Italic", {
  28925. alias: "Times-Roman",
  28926. style: ITALIC,
  28927. ultimate: "serif"
  28928. }], ["Times-BoldItalic", {
  28929. alias: "Times-Roman",
  28930. style: BOLDITALIC,
  28931. ultimate: "serif"
  28932. }], ["Helvetica", {
  28933. local: ["Helvetica", "Helvetica Neue", "Arial", "Arial Nova", "Liberation Sans", "Arimo", "Nimbus Sans", "Nimbus Sans L", "A030", "TeX Gyre Heros", "FreeSans", "DejaVu Sans", "Albany", "Bitstream Vera Sans", "Arial Unicode MS", "Microsoft Sans Serif", "Apple Symbols", "Cantarell"],
  28934. path: "LiberationSans-Regular.ttf",
  28935. style: NORMAL,
  28936. ultimate: "sans-serif"
  28937. }], ["Helvetica-Bold", {
  28938. alias: "Helvetica",
  28939. path: "LiberationSans-Bold.ttf",
  28940. style: BOLD,
  28941. ultimate: "sans-serif"
  28942. }], ["Helvetica-Oblique", {
  28943. alias: "Helvetica",
  28944. path: "LiberationSans-Italic.ttf",
  28945. style: ITALIC,
  28946. ultimate: "sans-serif"
  28947. }], ["Helvetica-BoldOblique", {
  28948. alias: "Helvetica",
  28949. path: "LiberationSans-BoldItalic.ttf",
  28950. style: BOLDITALIC,
  28951. ultimate: "sans-serif"
  28952. }], ["Courier", {
  28953. local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono"],
  28954. style: NORMAL,
  28955. ultimate: "monospace"
  28956. }], ["Courier-Bold", {
  28957. alias: "Courier",
  28958. style: BOLD,
  28959. ultimate: "monospace"
  28960. }], ["Courier-Oblique", {
  28961. alias: "Courier",
  28962. style: ITALIC,
  28963. ultimate: "monospace"
  28964. }], ["Courier-BoldOblique", {
  28965. alias: "Courier",
  28966. style: BOLDITALIC,
  28967. ultimate: "monospace"
  28968. }], ["ArialBlack", {
  28969. local: ["Arial Black"],
  28970. style: {
  28971. style: "normal",
  28972. weight: "900"
  28973. },
  28974. fallback: "Helvetica-Bold"
  28975. }], ["ArialBlack-Bold", {
  28976. alias: "ArialBlack"
  28977. }], ["ArialBlack-Italic", {
  28978. alias: "ArialBlack",
  28979. style: {
  28980. style: "italic",
  28981. weight: "900"
  28982. },
  28983. fallback: "Helvetica-BoldOblique"
  28984. }], ["ArialBlack-BoldItalic", {
  28985. alias: "ArialBlack-Italic"
  28986. }], ["ArialNarrow", {
  28987. local: ["Arial Narrow", "Liberation Sans Narrow", "Helvetica Condensed", "Nimbus Sans Narrow", "TeX Gyre Heros Cn"],
  28988. style: NORMAL,
  28989. fallback: "Helvetica"
  28990. }], ["ArialNarrow-Bold", {
  28991. alias: "ArialNarrow",
  28992. style: BOLD,
  28993. fallback: "Helvetica-Bold"
  28994. }], ["ArialNarrow-Italic", {
  28995. alias: "ArialNarrow",
  28996. style: ITALIC,
  28997. fallback: "Helvetica-Oblique"
  28998. }], ["ArialNarrow-BoldItalic", {
  28999. alias: "ArialNarrow",
  29000. style: BOLDITALIC,
  29001. fallback: "Helvetica-BoldOblique"
  29002. }], ["Calibri", {
  29003. local: ["Calibri", "Carlito"],
  29004. style: NORMAL,
  29005. fallback: "Helvetica"
  29006. }], ["Calibri-Bold", {
  29007. alias: "Calibri",
  29008. style: BOLD,
  29009. fallback: "Helvetica-Bold"
  29010. }], ["Calibri-Italic", {
  29011. alias: "Calibri",
  29012. style: ITALIC,
  29013. fallback: "Helvetica-Oblique"
  29014. }], ["Calibri-BoldItalic", {
  29015. alias: "Calibri",
  29016. style: BOLDITALIC,
  29017. fallback: "Helvetica-BoldOblique"
  29018. }], ["Wingdings", {
  29019. local: ["Wingdings", "URW Dingbats"],
  29020. style: NORMAL
  29021. }], ["Wingdings-Regular", {
  29022. alias: "Wingdings"
  29023. }], ["Wingdings-Bold", {
  29024. alias: "Wingdings"
  29025. }]]);
  29026. const fontAliases = new Map([["Arial-Black", "ArialBlack"]]);
  29027. function getStyleToAppend(style) {
  29028. switch (style) {
  29029. case BOLD:
  29030. return "Bold";
  29031. case ITALIC:
  29032. return "Italic";
  29033. case BOLDITALIC:
  29034. return "Bold Italic";
  29035. default:
  29036. if (style?.weight === "bold") {
  29037. return "Bold";
  29038. }
  29039. if (style?.style === "italic") {
  29040. return "Italic";
  29041. }
  29042. }
  29043. return "";
  29044. }
  29045. function generateFont({
  29046. alias,
  29047. local,
  29048. path,
  29049. fallback,
  29050. style,
  29051. ultimate
  29052. }, src, localFontPath, useFallback = true, usePath = true, append = "") {
  29053. const result = {
  29054. style: null,
  29055. ultimate: null
  29056. };
  29057. if (local) {
  29058. const extra = append ? ` ${append}` : "";
  29059. for (const name of local) {
  29060. src.push(`local(${name}${extra})`);
  29061. }
  29062. }
  29063. if (alias) {
  29064. const substitution = substitutionMap.get(alias);
  29065. const aliasAppend = append || getStyleToAppend(style);
  29066. Object.assign(result, generateFont(substitution, src, localFontPath, useFallback && !fallback, usePath && !path, aliasAppend));
  29067. }
  29068. if (style) {
  29069. result.style = style;
  29070. }
  29071. if (ultimate) {
  29072. result.ultimate = ultimate;
  29073. }
  29074. if (useFallback && fallback) {
  29075. const fallbackInfo = substitutionMap.get(fallback);
  29076. const {
  29077. ultimate: fallbackUltimate
  29078. } = generateFont(fallbackInfo, src, localFontPath, useFallback, usePath && !path, append);
  29079. result.ultimate ||= fallbackUltimate;
  29080. }
  29081. if (usePath && path && localFontPath) {
  29082. src.push(`url(${localFontPath}${path})`);
  29083. }
  29084. return result;
  29085. }
  29086. function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFontName, standardFontName) {
  29087. if (baseFontName.startsWith("InvalidPDFjsFont_")) {
  29088. return null;
  29089. }
  29090. baseFontName = normalizeFontName(baseFontName);
  29091. const key = baseFontName;
  29092. let substitutionInfo = systemFontCache.get(key);
  29093. if (substitutionInfo) {
  29094. return substitutionInfo;
  29095. }
  29096. let substitution = substitutionMap.get(baseFontName);
  29097. if (!substitution) {
  29098. for (const [alias, subst] of fontAliases) {
  29099. if (baseFontName.startsWith(alias)) {
  29100. baseFontName = `${subst}${baseFontName.substring(alias.length)}`;
  29101. substitution = substitutionMap.get(baseFontName);
  29102. break;
  29103. }
  29104. }
  29105. }
  29106. let mustAddBaseFont = false;
  29107. if (!substitution) {
  29108. substitution = substitutionMap.get(standardFontName);
  29109. mustAddBaseFont = true;
  29110. }
  29111. const loadedName = `${idFactory.getDocId()}_s${idFactory.createFontId()}`;
  29112. if (!substitution) {
  29113. if (!validateFontName(baseFontName)) {
  29114. systemFontCache.set(key, null);
  29115. return null;
  29116. }
  29117. const bold = /bold/gi.test(baseFontName);
  29118. const italic = /oblique|italic/gi.test(baseFontName);
  29119. const style = bold && italic && BOLDITALIC || bold && BOLD || italic && ITALIC || NORMAL;
  29120. substitutionInfo = {
  29121. css: loadedName,
  29122. guessFallback: true,
  29123. loadedName,
  29124. baseFontName,
  29125. src: `local(${baseFontName})`,
  29126. style
  29127. };
  29128. systemFontCache.set(key, substitutionInfo);
  29129. return substitutionInfo;
  29130. }
  29131. const src = [];
  29132. if (mustAddBaseFont && validateFontName(baseFontName)) {
  29133. src.push(`local(${baseFontName})`);
  29134. }
  29135. const {
  29136. style,
  29137. ultimate
  29138. } = generateFont(substitution, src, localFontPath);
  29139. const guessFallback = ultimate === null;
  29140. const fallback = guessFallback ? "" : `,${ultimate}`;
  29141. substitutionInfo = {
  29142. css: `${loadedName}${fallback}`,
  29143. guessFallback,
  29144. loadedName,
  29145. baseFontName,
  29146. src: src.join(","),
  29147. style
  29148. };
  29149. systemFontCache.set(key, substitutionInfo);
  29150. return substitutionInfo;
  29151. }
  29152. ;// CONCATENATED MODULE: ./src/core/image_resizer.js
  29153. const MIN_IMAGE_DIM = 2048;
  29154. const MAX_IMAGE_DIM = 65537;
  29155. const MAX_ERROR = 128;
  29156. class ImageResizer {
  29157. constructor(imgData, isMask) {
  29158. this._imgData = imgData;
  29159. this._isMask = isMask;
  29160. }
  29161. static needsToBeResized(width, height) {
  29162. if (width <= this._goodSquareLength && height <= this._goodSquareLength) {
  29163. return false;
  29164. }
  29165. const {
  29166. MAX_DIM
  29167. } = this;
  29168. if (width > MAX_DIM || height > MAX_DIM) {
  29169. return true;
  29170. }
  29171. const area = width * height;
  29172. if (this._hasMaxArea) {
  29173. return area > this.MAX_AREA;
  29174. }
  29175. if (area < this._goodSquareLength ** 2) {
  29176. return false;
  29177. }
  29178. if (this._areGoodDims(width, height)) {
  29179. this._goodSquareLength = Math.max(this._goodSquareLength, Math.floor(Math.sqrt(width * height)));
  29180. return false;
  29181. }
  29182. this._goodSquareLength = this._guessMax(this._goodSquareLength, MAX_DIM, MAX_ERROR, 0);
  29183. const maxArea = this.MAX_AREA = this._goodSquareLength ** 2;
  29184. return area > maxArea;
  29185. }
  29186. static get MAX_DIM() {
  29187. return shadow(this, "MAX_DIM", this._guessMax(MIN_IMAGE_DIM, MAX_IMAGE_DIM, 0, 1));
  29188. }
  29189. static get MAX_AREA() {
  29190. this._hasMaxArea = true;
  29191. return shadow(this, "MAX_AREA", this._guessMax(ImageResizer._goodSquareLength, this.MAX_DIM, MAX_ERROR, 0) ** 2);
  29192. }
  29193. static set MAX_AREA(area) {
  29194. if (area >= 0) {
  29195. this._hasMaxArea = true;
  29196. shadow(this, "MAX_AREA", area);
  29197. }
  29198. }
  29199. static setMaxArea(area) {
  29200. if (!this._hasMaxArea) {
  29201. this.MAX_AREA = area >> 2;
  29202. }
  29203. }
  29204. static _areGoodDims(width, height) {
  29205. try {
  29206. const canvas = new OffscreenCanvas(width, height);
  29207. const ctx = canvas.getContext("2d");
  29208. ctx.fillRect(0, 0, 1, 1);
  29209. const opacity = ctx.getImageData(0, 0, 1, 1).data[3];
  29210. canvas.width = canvas.height = 1;
  29211. return opacity !== 0;
  29212. } catch {
  29213. return false;
  29214. }
  29215. }
  29216. static _guessMax(start, end, tolerance, defaultHeight) {
  29217. while (start + tolerance + 1 < end) {
  29218. const middle = Math.floor((start + end) / 2);
  29219. const height = defaultHeight || middle;
  29220. if (this._areGoodDims(middle, height)) {
  29221. start = middle;
  29222. } else {
  29223. end = middle;
  29224. }
  29225. }
  29226. return start;
  29227. }
  29228. static async createImage(imgData, isMask = false) {
  29229. return new ImageResizer(imgData, isMask)._createImage();
  29230. }
  29231. async _createImage() {
  29232. const data = this._encodeBMP();
  29233. const blob = new Blob([data.buffer], {
  29234. type: "image/bmp"
  29235. });
  29236. const bitmapPromise = createImageBitmap(blob);
  29237. const {
  29238. MAX_AREA,
  29239. MAX_DIM
  29240. } = ImageResizer;
  29241. const {
  29242. _imgData: imgData
  29243. } = this;
  29244. const {
  29245. width,
  29246. height
  29247. } = imgData;
  29248. const minFactor = Math.max(width / MAX_DIM, height / MAX_DIM, Math.sqrt(width * height / MAX_AREA));
  29249. const firstFactor = Math.max(minFactor, 2);
  29250. const factor = Math.round(10 * (minFactor + 1.25)) / 10 / firstFactor;
  29251. const N = Math.floor(Math.log2(factor));
  29252. const steps = new Array(N + 2).fill(2);
  29253. steps[0] = firstFactor;
  29254. steps.splice(-1, 1, factor / (1 << N));
  29255. let newWidth = width;
  29256. let newHeight = height;
  29257. let bitmap = await bitmapPromise;
  29258. for (const step of steps) {
  29259. const prevWidth = newWidth;
  29260. const prevHeight = newHeight;
  29261. newWidth = Math.floor(newWidth / step) - 1;
  29262. newHeight = Math.floor(newHeight / step) - 1;
  29263. const canvas = new OffscreenCanvas(newWidth, newHeight);
  29264. const ctx = canvas.getContext("2d");
  29265. ctx.drawImage(bitmap, 0, 0, prevWidth, prevHeight, 0, 0, newWidth, newHeight);
  29266. bitmap = canvas.transferToImageBitmap();
  29267. }
  29268. imgData.data = null;
  29269. imgData.bitmap = bitmap;
  29270. imgData.width = newWidth;
  29271. imgData.height = newHeight;
  29272. return imgData;
  29273. }
  29274. _encodeBMP() {
  29275. const {
  29276. width,
  29277. height,
  29278. kind
  29279. } = this._imgData;
  29280. let data = this._imgData.data;
  29281. let bitPerPixel;
  29282. let colorTable = new Uint8Array(0);
  29283. let maskTable = colorTable;
  29284. let compression = 0;
  29285. switch (kind) {
  29286. case ImageKind.GRAYSCALE_1BPP:
  29287. {
  29288. bitPerPixel = 1;
  29289. colorTable = new Uint8Array(this._isMask ? [255, 255, 255, 255, 0, 0, 0, 0] : [0, 0, 0, 0, 255, 255, 255, 255]);
  29290. const rowLen = width + 7 >> 3;
  29291. const rowSize = rowLen + 3 & -4;
  29292. if (rowLen !== rowSize) {
  29293. const newData = new Uint8Array(rowSize * height);
  29294. let k = 0;
  29295. for (let i = 0, ii = height * rowLen; i < ii; i += rowLen, k += rowSize) {
  29296. newData.set(data.subarray(i, i + rowLen), k);
  29297. }
  29298. data = newData;
  29299. }
  29300. break;
  29301. }
  29302. case ImageKind.RGB_24BPP:
  29303. {
  29304. bitPerPixel = 24;
  29305. if (width & 3) {
  29306. const rowLen = 3 * width;
  29307. const rowSize = rowLen + 3 & -4;
  29308. const extraLen = rowSize - rowLen;
  29309. const newData = new Uint8Array(rowSize * height);
  29310. let k = 0;
  29311. for (let i = 0, ii = height * rowLen; i < ii; i += rowLen) {
  29312. const row = data.subarray(i, i + rowLen);
  29313. for (let j = 0; j < rowLen; j += 3) {
  29314. newData[k++] = row[j + 2];
  29315. newData[k++] = row[j + 1];
  29316. newData[k++] = row[j];
  29317. }
  29318. k += extraLen;
  29319. }
  29320. data = newData;
  29321. } else {
  29322. for (let i = 0, ii = data.length; i < ii; i += 3) {
  29323. const tmp = data[i];
  29324. data[i] = data[i + 2];
  29325. data[i + 2] = tmp;
  29326. }
  29327. }
  29328. break;
  29329. }
  29330. case ImageKind.RGBA_32BPP:
  29331. bitPerPixel = 32;
  29332. compression = 3;
  29333. maskTable = new Uint8Array(4 + 4 + 4 + 4 + 52);
  29334. const view = new DataView(maskTable.buffer);
  29335. if (FeatureTest.isLittleEndian) {
  29336. view.setUint32(0, 0x000000ff, true);
  29337. view.setUint32(4, 0x0000ff00, true);
  29338. view.setUint32(8, 0x00ff0000, true);
  29339. view.setUint32(12, 0xff000000, true);
  29340. } else {
  29341. view.setUint32(0, 0xff000000, true);
  29342. view.setUint32(4, 0x00ff0000, true);
  29343. view.setUint32(8, 0x0000ff00, true);
  29344. view.setUint32(12, 0x000000ff, true);
  29345. }
  29346. break;
  29347. default:
  29348. throw new Error("invalid format");
  29349. }
  29350. let i = 0;
  29351. const headerLength = 40 + maskTable.length;
  29352. const fileLength = 14 + headerLength + colorTable.length + data.length;
  29353. const bmpData = new Uint8Array(fileLength);
  29354. const view = new DataView(bmpData.buffer);
  29355. view.setUint16(i, 0x4d42, true);
  29356. i += 2;
  29357. view.setUint32(i, fileLength, true);
  29358. i += 4;
  29359. view.setUint32(i, 0, true);
  29360. i += 4;
  29361. view.setUint32(i, 14 + headerLength + colorTable.length, true);
  29362. i += 4;
  29363. view.setUint32(i, headerLength, true);
  29364. i += 4;
  29365. view.setInt32(i, width, true);
  29366. i += 4;
  29367. view.setInt32(i, -height, true);
  29368. i += 4;
  29369. view.setUint16(i, 1, true);
  29370. i += 2;
  29371. view.setUint16(i, bitPerPixel, true);
  29372. i += 2;
  29373. view.setUint32(i, compression, true);
  29374. i += 4;
  29375. view.setUint32(i, 0, true);
  29376. i += 4;
  29377. view.setInt32(i, 0, true);
  29378. i += 4;
  29379. view.setInt32(i, 0, true);
  29380. i += 4;
  29381. view.setUint32(i, colorTable.length / 4, true);
  29382. i += 4;
  29383. view.setUint32(i, 0, true);
  29384. i += 4;
  29385. bmpData.set(maskTable, i);
  29386. i += maskTable.length;
  29387. bmpData.set(colorTable, i);
  29388. i += colorTable.length;
  29389. bmpData.set(data, i);
  29390. return bmpData;
  29391. }
  29392. }
  29393. ImageResizer._goodSquareLength = MIN_IMAGE_DIM;
  29394. ;// CONCATENATED MODULE: ./src/shared/murmurhash3.js
  29395. const SEED = 0xc3d2e1f0;
  29396. const MASK_HIGH = 0xffff0000;
  29397. const MASK_LOW = 0xffff;
  29398. class MurmurHash3_64 {
  29399. constructor(seed) {
  29400. this.h1 = seed ? seed & 0xffffffff : SEED;
  29401. this.h2 = seed ? seed & 0xffffffff : SEED;
  29402. }
  29403. update(input) {
  29404. let data, length;
  29405. if (typeof input === "string") {
  29406. data = new Uint8Array(input.length * 2);
  29407. length = 0;
  29408. for (let i = 0, ii = input.length; i < ii; i++) {
  29409. const code = input.charCodeAt(i);
  29410. if (code <= 0xff) {
  29411. data[length++] = code;
  29412. } else {
  29413. data[length++] = code >>> 8;
  29414. data[length++] = code & 0xff;
  29415. }
  29416. }
  29417. } else if (isArrayBuffer(input)) {
  29418. data = input.slice();
  29419. length = data.byteLength;
  29420. } else {
  29421. throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
  29422. }
  29423. const blockCounts = length >> 2;
  29424. const tailLength = length - blockCounts * 4;
  29425. const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
  29426. let k1 = 0,
  29427. k2 = 0;
  29428. let h1 = this.h1,
  29429. h2 = this.h2;
  29430. const C1 = 0xcc9e2d51,
  29431. C2 = 0x1b873593;
  29432. const C1_LOW = C1 & MASK_LOW,
  29433. C2_LOW = C2 & MASK_LOW;
  29434. for (let i = 0; i < blockCounts; i++) {
  29435. if (i & 1) {
  29436. k1 = dataUint32[i];
  29437. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  29438. k1 = k1 << 15 | k1 >>> 17;
  29439. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  29440. h1 ^= k1;
  29441. h1 = h1 << 13 | h1 >>> 19;
  29442. h1 = h1 * 5 + 0xe6546b64;
  29443. } else {
  29444. k2 = dataUint32[i];
  29445. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  29446. k2 = k2 << 15 | k2 >>> 17;
  29447. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  29448. h2 ^= k2;
  29449. h2 = h2 << 13 | h2 >>> 19;
  29450. h2 = h2 * 5 + 0xe6546b64;
  29451. }
  29452. }
  29453. k1 = 0;
  29454. switch (tailLength) {
  29455. case 3:
  29456. k1 ^= data[blockCounts * 4 + 2] << 16;
  29457. case 2:
  29458. k1 ^= data[blockCounts * 4 + 1] << 8;
  29459. case 1:
  29460. k1 ^= data[blockCounts * 4];
  29461. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  29462. k1 = k1 << 15 | k1 >>> 17;
  29463. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  29464. if (blockCounts & 1) {
  29465. h1 ^= k1;
  29466. } else {
  29467. h2 ^= k1;
  29468. }
  29469. }
  29470. this.h1 = h1;
  29471. this.h2 = h2;
  29472. }
  29473. hexdigest() {
  29474. let h1 = this.h1,
  29475. h2 = this.h2;
  29476. h1 ^= h2 >>> 1;
  29477. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  29478. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  29479. h1 ^= h2 >>> 1;
  29480. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  29481. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  29482. h1 ^= h2 >>> 1;
  29483. return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  29484. }
  29485. }
  29486. ;// CONCATENATED MODULE: ./src/core/operator_list.js
  29487. function addState(parentState, pattern, checkFn, iterateFn, processFn) {
  29488. let state = parentState;
  29489. for (let i = 0, ii = pattern.length - 1; i < ii; i++) {
  29490. const item = pattern[i];
  29491. state = state[item] ||= [];
  29492. }
  29493. state[pattern.at(-1)] = {
  29494. checkFn,
  29495. iterateFn,
  29496. processFn
  29497. };
  29498. }
  29499. const InitialState = [];
  29500. addState(InitialState, [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore], null, function iterateInlineImageGroup(context, i) {
  29501. const fnArray = context.fnArray;
  29502. const iFirstSave = context.iCurr - 3;
  29503. const pos = (i - iFirstSave) % 4;
  29504. switch (pos) {
  29505. case 0:
  29506. return fnArray[i] === OPS.save;
  29507. case 1:
  29508. return fnArray[i] === OPS.transform;
  29509. case 2:
  29510. return fnArray[i] === OPS.paintInlineImageXObject;
  29511. case 3:
  29512. return fnArray[i] === OPS.restore;
  29513. }
  29514. throw new Error(`iterateInlineImageGroup - invalid pos: ${pos}`);
  29515. }, function foundInlineImageGroup(context, i) {
  29516. const MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  29517. const MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  29518. const MAX_WIDTH = 1000;
  29519. const IMAGE_PADDING = 1;
  29520. const fnArray = context.fnArray,
  29521. argsArray = context.argsArray;
  29522. const curr = context.iCurr;
  29523. const iFirstSave = curr - 3;
  29524. const iFirstTransform = curr - 2;
  29525. const iFirstPIIXO = curr - 1;
  29526. const count = Math.min(Math.floor((i - iFirstSave) / 4), MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  29527. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  29528. return i - (i - iFirstSave) % 4;
  29529. }
  29530. let maxX = 0;
  29531. const map = [];
  29532. let maxLineHeight = 0;
  29533. let currentX = IMAGE_PADDING,
  29534. currentY = IMAGE_PADDING;
  29535. for (let q = 0; q < count; q++) {
  29536. const transform = argsArray[iFirstTransform + (q << 2)];
  29537. const img = argsArray[iFirstPIIXO + (q << 2)][0];
  29538. if (currentX + img.width > MAX_WIDTH) {
  29539. maxX = Math.max(maxX, currentX);
  29540. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  29541. currentX = 0;
  29542. maxLineHeight = 0;
  29543. }
  29544. map.push({
  29545. transform,
  29546. x: currentX,
  29547. y: currentY,
  29548. w: img.width,
  29549. h: img.height
  29550. });
  29551. currentX += img.width + 2 * IMAGE_PADDING;
  29552. maxLineHeight = Math.max(maxLineHeight, img.height);
  29553. }
  29554. const imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  29555. const imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  29556. const imgData = new Uint8Array(imgWidth * imgHeight * 4);
  29557. const imgRowSize = imgWidth << 2;
  29558. for (let q = 0; q < count; q++) {
  29559. const data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  29560. const rowSize = map[q].w << 2;
  29561. let dataOffset = 0;
  29562. let offset = map[q].x + map[q].y * imgWidth << 2;
  29563. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  29564. for (let k = 0, kk = map[q].h; k < kk; k++) {
  29565. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  29566. dataOffset += rowSize;
  29567. offset += imgRowSize;
  29568. }
  29569. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  29570. while (offset >= 0) {
  29571. data[offset - 4] = data[offset];
  29572. data[offset - 3] = data[offset + 1];
  29573. data[offset - 2] = data[offset + 2];
  29574. data[offset - 1] = data[offset + 3];
  29575. data[offset + rowSize] = data[offset + rowSize - 4];
  29576. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  29577. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  29578. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  29579. offset -= imgRowSize;
  29580. }
  29581. }
  29582. const img = {
  29583. width: imgWidth,
  29584. height: imgHeight
  29585. };
  29586. if (context.isOffscreenCanvasSupported) {
  29587. const canvas = new OffscreenCanvas(imgWidth, imgHeight);
  29588. const ctx = canvas.getContext("2d");
  29589. ctx.putImageData(new ImageData(new Uint8ClampedArray(imgData.buffer), imgWidth, imgHeight), 0, 0);
  29590. img.bitmap = canvas.transferToImageBitmap();
  29591. img.data = null;
  29592. } else {
  29593. img.kind = ImageKind.RGBA_32BPP;
  29594. img.data = imgData;
  29595. }
  29596. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  29597. argsArray.splice(iFirstSave, count * 4, [img, map]);
  29598. return iFirstSave + 1;
  29599. });
  29600. addState(InitialState, [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore], null, function iterateImageMaskGroup(context, i) {
  29601. const fnArray = context.fnArray;
  29602. const iFirstSave = context.iCurr - 3;
  29603. const pos = (i - iFirstSave) % 4;
  29604. switch (pos) {
  29605. case 0:
  29606. return fnArray[i] === OPS.save;
  29607. case 1:
  29608. return fnArray[i] === OPS.transform;
  29609. case 2:
  29610. return fnArray[i] === OPS.paintImageMaskXObject;
  29611. case 3:
  29612. return fnArray[i] === OPS.restore;
  29613. }
  29614. throw new Error(`iterateImageMaskGroup - invalid pos: ${pos}`);
  29615. }, function foundImageMaskGroup(context, i) {
  29616. const MIN_IMAGES_IN_MASKS_BLOCK = 10;
  29617. const MAX_IMAGES_IN_MASKS_BLOCK = 100;
  29618. const MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  29619. const fnArray = context.fnArray,
  29620. argsArray = context.argsArray;
  29621. const curr = context.iCurr;
  29622. const iFirstSave = curr - 3;
  29623. const iFirstTransform = curr - 2;
  29624. const iFirstPIMXO = curr - 1;
  29625. let count = Math.floor((i - iFirstSave) / 4);
  29626. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  29627. return i - (i - iFirstSave) % 4;
  29628. }
  29629. let isSameImage = false;
  29630. let iTransform, transformArgs;
  29631. const firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  29632. const firstTransformArg0 = argsArray[iFirstTransform][0],
  29633. firstTransformArg1 = argsArray[iFirstTransform][1],
  29634. firstTransformArg2 = argsArray[iFirstTransform][2],
  29635. firstTransformArg3 = argsArray[iFirstTransform][3];
  29636. if (firstTransformArg1 === firstTransformArg2) {
  29637. isSameImage = true;
  29638. iTransform = iFirstTransform + 4;
  29639. let iPIMXO = iFirstPIMXO + 4;
  29640. for (let q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  29641. transformArgs = argsArray[iTransform];
  29642. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== firstTransformArg1 || transformArgs[2] !== firstTransformArg2 || transformArgs[3] !== firstTransformArg3) {
  29643. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  29644. isSameImage = false;
  29645. } else {
  29646. count = q;
  29647. }
  29648. break;
  29649. }
  29650. }
  29651. }
  29652. if (isSameImage) {
  29653. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  29654. const positions = new Float32Array(count * 2);
  29655. iTransform = iFirstTransform;
  29656. for (let q = 0; q < count; q++, iTransform += 4) {
  29657. transformArgs = argsArray[iTransform];
  29658. positions[q << 1] = transformArgs[4];
  29659. positions[(q << 1) + 1] = transformArgs[5];
  29660. }
  29661. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  29662. argsArray.splice(iFirstSave, count * 4, [firstPIMXOArg0, firstTransformArg0, firstTransformArg1, firstTransformArg2, firstTransformArg3, positions]);
  29663. } else {
  29664. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  29665. const images = [];
  29666. for (let q = 0; q < count; q++) {
  29667. transformArgs = argsArray[iFirstTransform + (q << 2)];
  29668. const maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  29669. images.push({
  29670. data: maskParams.data,
  29671. width: maskParams.width,
  29672. height: maskParams.height,
  29673. interpolate: maskParams.interpolate,
  29674. count: maskParams.count,
  29675. transform: transformArgs
  29676. });
  29677. }
  29678. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  29679. argsArray.splice(iFirstSave, count * 4, [images]);
  29680. }
  29681. return iFirstSave + 1;
  29682. });
  29683. addState(InitialState, [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore], function (context) {
  29684. const argsArray = context.argsArray;
  29685. const iFirstTransform = context.iCurr - 2;
  29686. return argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0;
  29687. }, function iterateImageGroup(context, i) {
  29688. const fnArray = context.fnArray,
  29689. argsArray = context.argsArray;
  29690. const iFirstSave = context.iCurr - 3;
  29691. const pos = (i - iFirstSave) % 4;
  29692. switch (pos) {
  29693. case 0:
  29694. return fnArray[i] === OPS.save;
  29695. case 1:
  29696. if (fnArray[i] !== OPS.transform) {
  29697. return false;
  29698. }
  29699. const iFirstTransform = context.iCurr - 2;
  29700. const firstTransformArg0 = argsArray[iFirstTransform][0];
  29701. const firstTransformArg3 = argsArray[iFirstTransform][3];
  29702. if (argsArray[i][0] !== firstTransformArg0 || argsArray[i][1] !== 0 || argsArray[i][2] !== 0 || argsArray[i][3] !== firstTransformArg3) {
  29703. return false;
  29704. }
  29705. return true;
  29706. case 2:
  29707. if (fnArray[i] !== OPS.paintImageXObject) {
  29708. return false;
  29709. }
  29710. const iFirstPIXO = context.iCurr - 1;
  29711. const firstPIXOArg0 = argsArray[iFirstPIXO][0];
  29712. if (argsArray[i][0] !== firstPIXOArg0) {
  29713. return false;
  29714. }
  29715. return true;
  29716. case 3:
  29717. return fnArray[i] === OPS.restore;
  29718. }
  29719. throw new Error(`iterateImageGroup - invalid pos: ${pos}`);
  29720. }, function (context, i) {
  29721. const MIN_IMAGES_IN_BLOCK = 3;
  29722. const MAX_IMAGES_IN_BLOCK = 1000;
  29723. const fnArray = context.fnArray,
  29724. argsArray = context.argsArray;
  29725. const curr = context.iCurr;
  29726. const iFirstSave = curr - 3;
  29727. const iFirstTransform = curr - 2;
  29728. const iFirstPIXO = curr - 1;
  29729. const firstPIXOArg0 = argsArray[iFirstPIXO][0];
  29730. const firstTransformArg0 = argsArray[iFirstTransform][0];
  29731. const firstTransformArg3 = argsArray[iFirstTransform][3];
  29732. const count = Math.min(Math.floor((i - iFirstSave) / 4), MAX_IMAGES_IN_BLOCK);
  29733. if (count < MIN_IMAGES_IN_BLOCK) {
  29734. return i - (i - iFirstSave) % 4;
  29735. }
  29736. const positions = new Float32Array(count * 2);
  29737. let iTransform = iFirstTransform;
  29738. for (let q = 0; q < count; q++, iTransform += 4) {
  29739. const transformArgs = argsArray[iTransform];
  29740. positions[q << 1] = transformArgs[4];
  29741. positions[(q << 1) + 1] = transformArgs[5];
  29742. }
  29743. const args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3, positions];
  29744. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  29745. argsArray.splice(iFirstSave, count * 4, args);
  29746. return iFirstSave + 1;
  29747. });
  29748. addState(InitialState, [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText], null, function iterateShowTextGroup(context, i) {
  29749. const fnArray = context.fnArray,
  29750. argsArray = context.argsArray;
  29751. const iFirstSave = context.iCurr - 4;
  29752. const pos = (i - iFirstSave) % 5;
  29753. switch (pos) {
  29754. case 0:
  29755. return fnArray[i] === OPS.beginText;
  29756. case 1:
  29757. return fnArray[i] === OPS.setFont;
  29758. case 2:
  29759. return fnArray[i] === OPS.setTextMatrix;
  29760. case 3:
  29761. if (fnArray[i] !== OPS.showText) {
  29762. return false;
  29763. }
  29764. const iFirstSetFont = context.iCurr - 3;
  29765. const firstSetFontArg0 = argsArray[iFirstSetFont][0];
  29766. const firstSetFontArg1 = argsArray[iFirstSetFont][1];
  29767. if (argsArray[i][0] !== firstSetFontArg0 || argsArray[i][1] !== firstSetFontArg1) {
  29768. return false;
  29769. }
  29770. return true;
  29771. case 4:
  29772. return fnArray[i] === OPS.endText;
  29773. }
  29774. throw new Error(`iterateShowTextGroup - invalid pos: ${pos}`);
  29775. }, function (context, i) {
  29776. const MIN_CHARS_IN_BLOCK = 3;
  29777. const MAX_CHARS_IN_BLOCK = 1000;
  29778. const fnArray = context.fnArray,
  29779. argsArray = context.argsArray;
  29780. const curr = context.iCurr;
  29781. const iFirstBeginText = curr - 4;
  29782. const iFirstSetFont = curr - 3;
  29783. const iFirstSetTextMatrix = curr - 2;
  29784. const iFirstShowText = curr - 1;
  29785. const iFirstEndText = curr;
  29786. const firstSetFontArg0 = argsArray[iFirstSetFont][0];
  29787. const firstSetFontArg1 = argsArray[iFirstSetFont][1];
  29788. let count = Math.min(Math.floor((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  29789. if (count < MIN_CHARS_IN_BLOCK) {
  29790. return i - (i - iFirstBeginText) % 5;
  29791. }
  29792. let iFirst = iFirstBeginText;
  29793. 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) {
  29794. count++;
  29795. iFirst -= 5;
  29796. }
  29797. let iEndText = iFirst + 4;
  29798. for (let q = 1; q < count; q++) {
  29799. fnArray.splice(iEndText, 3);
  29800. argsArray.splice(iEndText, 3);
  29801. iEndText += 2;
  29802. }
  29803. return iEndText + 1;
  29804. });
  29805. class NullOptimizer {
  29806. constructor(queue) {
  29807. this.queue = queue;
  29808. }
  29809. _optimize() {}
  29810. push(fn, args) {
  29811. this.queue.fnArray.push(fn);
  29812. this.queue.argsArray.push(args);
  29813. this._optimize();
  29814. }
  29815. flush() {}
  29816. reset() {}
  29817. }
  29818. class QueueOptimizer extends NullOptimizer {
  29819. constructor(queue) {
  29820. super(queue);
  29821. this.state = null;
  29822. this.context = {
  29823. iCurr: 0,
  29824. fnArray: queue.fnArray,
  29825. argsArray: queue.argsArray,
  29826. isOffscreenCanvasSupported: false
  29827. };
  29828. this.match = null;
  29829. this.lastProcessed = 0;
  29830. }
  29831. set isOffscreenCanvasSupported(value) {
  29832. this.context.isOffscreenCanvasSupported = value;
  29833. }
  29834. _optimize() {
  29835. const fnArray = this.queue.fnArray;
  29836. let i = this.lastProcessed,
  29837. ii = fnArray.length;
  29838. let state = this.state;
  29839. let match = this.match;
  29840. if (!state && !match && i + 1 === ii && !InitialState[fnArray[i]]) {
  29841. this.lastProcessed = ii;
  29842. return;
  29843. }
  29844. const context = this.context;
  29845. while (i < ii) {
  29846. if (match) {
  29847. const iterate = (0, match.iterateFn)(context, i);
  29848. if (iterate) {
  29849. i++;
  29850. continue;
  29851. }
  29852. i = (0, match.processFn)(context, i + 1);
  29853. ii = fnArray.length;
  29854. match = null;
  29855. state = null;
  29856. if (i >= ii) {
  29857. break;
  29858. }
  29859. }
  29860. state = (state || InitialState)[fnArray[i]];
  29861. if (!state || Array.isArray(state)) {
  29862. i++;
  29863. continue;
  29864. }
  29865. context.iCurr = i;
  29866. i++;
  29867. if (state.checkFn && !(0, state.checkFn)(context)) {
  29868. state = null;
  29869. continue;
  29870. }
  29871. match = state;
  29872. state = null;
  29873. }
  29874. this.state = state;
  29875. this.match = match;
  29876. this.lastProcessed = i;
  29877. }
  29878. flush() {
  29879. while (this.match) {
  29880. const length = this.queue.fnArray.length;
  29881. this.lastProcessed = (0, this.match.processFn)(this.context, length);
  29882. this.match = null;
  29883. this.state = null;
  29884. this._optimize();
  29885. }
  29886. }
  29887. reset() {
  29888. this.state = null;
  29889. this.match = null;
  29890. this.lastProcessed = 0;
  29891. }
  29892. }
  29893. class OperatorList {
  29894. static CHUNK_SIZE = 1000;
  29895. static CHUNK_SIZE_ABOUT = this.CHUNK_SIZE - 5;
  29896. constructor(intent = 0, streamSink) {
  29897. this._streamSink = streamSink;
  29898. this.fnArray = [];
  29899. this.argsArray = [];
  29900. this.optimizer = streamSink && !(intent & RenderingIntentFlag.OPLIST) ? new QueueOptimizer(this) : new NullOptimizer(this);
  29901. this.dependencies = new Set();
  29902. this._totalLength = 0;
  29903. this.weight = 0;
  29904. this._resolved = streamSink ? null : Promise.resolve();
  29905. }
  29906. set isOffscreenCanvasSupported(value) {
  29907. this.optimizer.isOffscreenCanvasSupported = value;
  29908. }
  29909. get length() {
  29910. return this.argsArray.length;
  29911. }
  29912. get ready() {
  29913. return this._resolved || this._streamSink.ready;
  29914. }
  29915. get totalLength() {
  29916. return this._totalLength + this.length;
  29917. }
  29918. addOp(fn, args) {
  29919. this.optimizer.push(fn, args);
  29920. this.weight++;
  29921. if (this._streamSink) {
  29922. if (this.weight >= OperatorList.CHUNK_SIZE) {
  29923. this.flush();
  29924. } else if (this.weight >= OperatorList.CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  29925. this.flush();
  29926. }
  29927. }
  29928. }
  29929. addImageOps(fn, args, optionalContent) {
  29930. if (optionalContent !== undefined) {
  29931. this.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
  29932. }
  29933. this.addOp(fn, args);
  29934. if (optionalContent !== undefined) {
  29935. this.addOp(OPS.endMarkedContent, []);
  29936. }
  29937. }
  29938. addDependency(dependency) {
  29939. if (this.dependencies.has(dependency)) {
  29940. return;
  29941. }
  29942. this.dependencies.add(dependency);
  29943. this.addOp(OPS.dependency, [dependency]);
  29944. }
  29945. addDependencies(dependencies) {
  29946. for (const dependency of dependencies) {
  29947. this.addDependency(dependency);
  29948. }
  29949. }
  29950. addOpList(opList) {
  29951. if (!(opList instanceof OperatorList)) {
  29952. warn('addOpList - ignoring invalid "opList" parameter.');
  29953. return;
  29954. }
  29955. for (const dependency of opList.dependencies) {
  29956. this.dependencies.add(dependency);
  29957. }
  29958. for (let i = 0, ii = opList.length; i < ii; i++) {
  29959. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  29960. }
  29961. }
  29962. getIR() {
  29963. return {
  29964. fnArray: this.fnArray,
  29965. argsArray: this.argsArray,
  29966. length: this.length
  29967. };
  29968. }
  29969. get _transfers() {
  29970. const transfers = [];
  29971. const {
  29972. fnArray,
  29973. argsArray,
  29974. length
  29975. } = this;
  29976. for (let i = 0; i < length; i++) {
  29977. switch (fnArray[i]) {
  29978. case OPS.paintInlineImageXObject:
  29979. case OPS.paintInlineImageXObjectGroup:
  29980. case OPS.paintImageMaskXObject:
  29981. const arg = argsArray[i][0];
  29982. if (!arg.cached && arg.data?.buffer instanceof ArrayBuffer) {
  29983. transfers.push(arg.data.buffer);
  29984. }
  29985. break;
  29986. }
  29987. }
  29988. return transfers;
  29989. }
  29990. flush(lastChunk = false, separateAnnots = null) {
  29991. this.optimizer.flush();
  29992. const length = this.length;
  29993. this._totalLength += length;
  29994. this._streamSink.enqueue({
  29995. fnArray: this.fnArray,
  29996. argsArray: this.argsArray,
  29997. lastChunk,
  29998. separateAnnots,
  29999. length
  30000. }, 1, this._transfers);
  30001. this.dependencies.clear();
  30002. this.fnArray.length = 0;
  30003. this.argsArray.length = 0;
  30004. this.weight = 0;
  30005. this.optimizer.reset();
  30006. }
  30007. }
  30008. ;// CONCATENATED MODULE: ./src/core/image.js
  30009. function decodeAndClamp(value, addend, coefficient, max) {
  30010. value = addend + value * coefficient;
  30011. if (value < 0) {
  30012. value = 0;
  30013. } else if (value > max) {
  30014. value = max;
  30015. }
  30016. return value;
  30017. }
  30018. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  30019. const length = w2 * h2;
  30020. let dest;
  30021. if (bpc <= 8) {
  30022. dest = new Uint8Array(length);
  30023. } else if (bpc <= 16) {
  30024. dest = new Uint16Array(length);
  30025. } else {
  30026. dest = new Uint32Array(length);
  30027. }
  30028. const xRatio = w1 / w2;
  30029. const yRatio = h1 / h2;
  30030. let i,
  30031. j,
  30032. py,
  30033. newIndex = 0,
  30034. oldIndex;
  30035. const xScaled = new Uint16Array(w2);
  30036. const w1Scanline = w1;
  30037. for (i = 0; i < w2; i++) {
  30038. xScaled[i] = Math.floor(i * xRatio);
  30039. }
  30040. for (i = 0; i < h2; i++) {
  30041. py = Math.floor(i * yRatio) * w1Scanline;
  30042. for (j = 0; j < w2; j++) {
  30043. oldIndex = py + xScaled[j];
  30044. dest[newIndex++] = src[oldIndex];
  30045. }
  30046. }
  30047. return dest;
  30048. }
  30049. class PDFImage {
  30050. constructor({
  30051. xref,
  30052. res,
  30053. image,
  30054. isInline = false,
  30055. smask = null,
  30056. mask = null,
  30057. isMask = false,
  30058. pdfFunctionFactory,
  30059. localColorSpaceCache
  30060. }) {
  30061. this.image = image;
  30062. const dict = image.dict;
  30063. const filter = dict.get("F", "Filter");
  30064. let filterName;
  30065. if (filter instanceof Name) {
  30066. filterName = filter.name;
  30067. } else if (Array.isArray(filter)) {
  30068. const filterZero = xref.fetchIfRef(filter[0]);
  30069. if (filterZero instanceof Name) {
  30070. filterName = filterZero.name;
  30071. }
  30072. }
  30073. switch (filterName) {
  30074. case "JPXDecode":
  30075. const jpxImage = new JpxImage();
  30076. jpxImage.parseImageProperties(image.stream);
  30077. image.stream.reset();
  30078. image.width = jpxImage.width;
  30079. image.height = jpxImage.height;
  30080. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30081. image.numComps = jpxImage.componentsCount;
  30082. break;
  30083. case "JBIG2Decode":
  30084. image.bitsPerComponent = 1;
  30085. image.numComps = 1;
  30086. break;
  30087. }
  30088. let width = dict.get("W", "Width");
  30089. let height = dict.get("H", "Height");
  30090. if (Number.isInteger(image.width) && image.width > 0 && Number.isInteger(image.height) && image.height > 0 && (image.width !== width || image.height !== height)) {
  30091. warn("PDFImage - using the Width/Height of the image data, " + "rather than the image dictionary.");
  30092. width = image.width;
  30093. height = image.height;
  30094. }
  30095. if (width < 1 || height < 1) {
  30096. throw new FormatError(`Invalid image width: ${width} or height: ${height}`);
  30097. }
  30098. this.width = width;
  30099. this.height = height;
  30100. this.interpolate = dict.get("I", "Interpolate");
  30101. this.imageMask = dict.get("IM", "ImageMask") || false;
  30102. this.matte = dict.get("Matte") || false;
  30103. let bitsPerComponent = image.bitsPerComponent;
  30104. if (!bitsPerComponent) {
  30105. bitsPerComponent = dict.get("BPC", "BitsPerComponent");
  30106. if (!bitsPerComponent) {
  30107. if (this.imageMask) {
  30108. bitsPerComponent = 1;
  30109. } else {
  30110. throw new FormatError(`Bits per component missing in image: ${this.imageMask}`);
  30111. }
  30112. }
  30113. }
  30114. this.bpc = bitsPerComponent;
  30115. if (!this.imageMask) {
  30116. let colorSpace = dict.getRaw("CS") || dict.getRaw("ColorSpace");
  30117. if (!colorSpace) {
  30118. info("JPX images (which do not require color spaces)");
  30119. switch (image.numComps) {
  30120. case 1:
  30121. colorSpace = Name.get("DeviceGray");
  30122. break;
  30123. case 3:
  30124. colorSpace = Name.get("DeviceRGB");
  30125. break;
  30126. case 4:
  30127. colorSpace = Name.get("DeviceCMYK");
  30128. break;
  30129. default:
  30130. throw new Error(`JPX images with ${image.numComps} color components not supported.`);
  30131. }
  30132. }
  30133. this.colorSpace = ColorSpace.parse({
  30134. cs: colorSpace,
  30135. xref,
  30136. resources: isInline ? res : null,
  30137. pdfFunctionFactory,
  30138. localColorSpaceCache
  30139. });
  30140. this.numComps = this.colorSpace.numComps;
  30141. }
  30142. this.decode = dict.getArray("D", "Decode");
  30143. this.needsDecode = false;
  30144. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode, bitsPerComponent) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  30145. this.needsDecode = true;
  30146. const max = (1 << bitsPerComponent) - 1;
  30147. this.decodeCoefficients = [];
  30148. this.decodeAddends = [];
  30149. const isIndexed = this.colorSpace?.name === "Indexed";
  30150. for (let i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30151. const dmin = this.decode[i];
  30152. const dmax = this.decode[i + 1];
  30153. this.decodeCoefficients[j] = isIndexed ? (dmax - dmin) / max : dmax - dmin;
  30154. this.decodeAddends[j] = isIndexed ? dmin : max * dmin;
  30155. }
  30156. }
  30157. if (smask) {
  30158. this.smask = new PDFImage({
  30159. xref,
  30160. res,
  30161. image: smask,
  30162. isInline,
  30163. pdfFunctionFactory,
  30164. localColorSpaceCache
  30165. });
  30166. } else if (mask) {
  30167. if (mask instanceof BaseStream) {
  30168. const maskDict = mask.dict,
  30169. imageMask = maskDict.get("IM", "ImageMask");
  30170. if (!imageMask) {
  30171. warn("Ignoring /Mask in image without /ImageMask.");
  30172. } else {
  30173. this.mask = new PDFImage({
  30174. xref,
  30175. res,
  30176. image: mask,
  30177. isInline,
  30178. isMask: true,
  30179. pdfFunctionFactory,
  30180. localColorSpaceCache
  30181. });
  30182. }
  30183. } else {
  30184. this.mask = mask;
  30185. }
  30186. }
  30187. }
  30188. static async buildImage({
  30189. xref,
  30190. res,
  30191. image,
  30192. isInline = false,
  30193. pdfFunctionFactory,
  30194. localColorSpaceCache
  30195. }) {
  30196. const imageData = image;
  30197. let smaskData = null;
  30198. let maskData = null;
  30199. const smask = image.dict.get("SMask");
  30200. const mask = image.dict.get("Mask");
  30201. if (smask) {
  30202. if (smask instanceof BaseStream) {
  30203. smaskData = smask;
  30204. } else {
  30205. warn("Unsupported /SMask format.");
  30206. }
  30207. } else if (mask) {
  30208. if (mask instanceof BaseStream || Array.isArray(mask)) {
  30209. maskData = mask;
  30210. } else {
  30211. warn("Unsupported /Mask format.");
  30212. }
  30213. }
  30214. return new PDFImage({
  30215. xref,
  30216. res,
  30217. image: imageData,
  30218. isInline,
  30219. smask: smaskData,
  30220. mask: maskData,
  30221. pdfFunctionFactory,
  30222. localColorSpaceCache
  30223. });
  30224. }
  30225. static createRawMask({
  30226. imgArray,
  30227. width,
  30228. height,
  30229. imageIsFromDecodeStream,
  30230. inverseDecode,
  30231. interpolate
  30232. }) {
  30233. const computedLength = (width + 7 >> 3) * height;
  30234. const actualLength = imgArray.byteLength;
  30235. const haveFullData = computedLength === actualLength;
  30236. let data, i;
  30237. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30238. data = imgArray;
  30239. } else if (!inverseDecode) {
  30240. data = new Uint8Array(imgArray);
  30241. } else {
  30242. data = new Uint8Array(computedLength);
  30243. data.set(imgArray);
  30244. data.fill(0xff, actualLength);
  30245. }
  30246. if (inverseDecode) {
  30247. for (i = 0; i < actualLength; i++) {
  30248. data[i] ^= 0xff;
  30249. }
  30250. }
  30251. return {
  30252. data,
  30253. width,
  30254. height,
  30255. interpolate
  30256. };
  30257. }
  30258. static async createMask({
  30259. imgArray,
  30260. width,
  30261. height,
  30262. imageIsFromDecodeStream,
  30263. inverseDecode,
  30264. interpolate,
  30265. isOffscreenCanvasSupported = false
  30266. }) {
  30267. const isSingleOpaquePixel = width === 1 && height === 1 && inverseDecode === (imgArray.length === 0 || !!(imgArray[0] & 128));
  30268. if (isSingleOpaquePixel) {
  30269. return {
  30270. isSingleOpaquePixel
  30271. };
  30272. }
  30273. if (isOffscreenCanvasSupported) {
  30274. if (ImageResizer.needsToBeResized(width, height)) {
  30275. const data = new Uint8ClampedArray(width * height * 4);
  30276. convertBlackAndWhiteToRGBA({
  30277. src: imgArray,
  30278. dest: data,
  30279. width,
  30280. height,
  30281. nonBlackColor: 0,
  30282. inverseDecode
  30283. });
  30284. return ImageResizer.createImage({
  30285. kind: ImageKind.RGBA_32BPP,
  30286. data,
  30287. width,
  30288. height,
  30289. interpolate
  30290. });
  30291. }
  30292. const canvas = new OffscreenCanvas(width, height);
  30293. const ctx = canvas.getContext("2d");
  30294. const imgData = ctx.createImageData(width, height);
  30295. convertBlackAndWhiteToRGBA({
  30296. src: imgArray,
  30297. dest: imgData.data,
  30298. width,
  30299. height,
  30300. nonBlackColor: 0,
  30301. inverseDecode
  30302. });
  30303. ctx.putImageData(imgData, 0, 0);
  30304. const bitmap = canvas.transferToImageBitmap();
  30305. return {
  30306. data: null,
  30307. width,
  30308. height,
  30309. interpolate,
  30310. bitmap
  30311. };
  30312. }
  30313. return this.createRawMask({
  30314. imgArray,
  30315. width,
  30316. height,
  30317. inverseDecode,
  30318. imageIsFromDecodeStream,
  30319. interpolate
  30320. });
  30321. }
  30322. get drawWidth() {
  30323. return Math.max(this.width, this.smask?.width || 0, this.mask?.width || 0);
  30324. }
  30325. get drawHeight() {
  30326. return Math.max(this.height, this.smask?.height || 0, this.mask?.height || 0);
  30327. }
  30328. decodeBuffer(buffer) {
  30329. const bpc = this.bpc;
  30330. const numComps = this.numComps;
  30331. const decodeAddends = this.decodeAddends;
  30332. const decodeCoefficients = this.decodeCoefficients;
  30333. const max = (1 << bpc) - 1;
  30334. let i, ii;
  30335. if (bpc === 1) {
  30336. for (i = 0, ii = buffer.length; i < ii; i++) {
  30337. buffer[i] = +!buffer[i];
  30338. }
  30339. return;
  30340. }
  30341. let index = 0;
  30342. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30343. for (let j = 0; j < numComps; j++) {
  30344. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  30345. index++;
  30346. }
  30347. }
  30348. }
  30349. getComponents(buffer) {
  30350. const bpc = this.bpc;
  30351. if (bpc === 8) {
  30352. return buffer;
  30353. }
  30354. const width = this.width;
  30355. const height = this.height;
  30356. const numComps = this.numComps;
  30357. const length = width * height * numComps;
  30358. let bufferPos = 0;
  30359. let output;
  30360. if (bpc <= 8) {
  30361. output = new Uint8Array(length);
  30362. } else if (bpc <= 16) {
  30363. output = new Uint16Array(length);
  30364. } else {
  30365. output = new Uint32Array(length);
  30366. }
  30367. const rowComps = width * numComps;
  30368. const max = (1 << bpc) - 1;
  30369. let i = 0,
  30370. ii,
  30371. buf;
  30372. if (bpc === 1) {
  30373. let mask, loop1End, loop2End;
  30374. for (let j = 0; j < height; j++) {
  30375. loop1End = i + (rowComps & ~7);
  30376. loop2End = i + rowComps;
  30377. while (i < loop1End) {
  30378. buf = buffer[bufferPos++];
  30379. output[i] = buf >> 7 & 1;
  30380. output[i + 1] = buf >> 6 & 1;
  30381. output[i + 2] = buf >> 5 & 1;
  30382. output[i + 3] = buf >> 4 & 1;
  30383. output[i + 4] = buf >> 3 & 1;
  30384. output[i + 5] = buf >> 2 & 1;
  30385. output[i + 6] = buf >> 1 & 1;
  30386. output[i + 7] = buf & 1;
  30387. i += 8;
  30388. }
  30389. if (i < loop2End) {
  30390. buf = buffer[bufferPos++];
  30391. mask = 128;
  30392. while (i < loop2End) {
  30393. output[i++] = +!!(buf & mask);
  30394. mask >>= 1;
  30395. }
  30396. }
  30397. }
  30398. } else {
  30399. let bits = 0;
  30400. buf = 0;
  30401. for (i = 0, ii = length; i < ii; ++i) {
  30402. if (i % rowComps === 0) {
  30403. buf = 0;
  30404. bits = 0;
  30405. }
  30406. while (bits < bpc) {
  30407. buf = buf << 8 | buffer[bufferPos++];
  30408. bits += 8;
  30409. }
  30410. const remainingBits = bits - bpc;
  30411. let value = buf >> remainingBits;
  30412. if (value < 0) {
  30413. value = 0;
  30414. } else if (value > max) {
  30415. value = max;
  30416. }
  30417. output[i] = value;
  30418. buf &= (1 << remainingBits) - 1;
  30419. bits = remainingBits;
  30420. }
  30421. }
  30422. return output;
  30423. }
  30424. fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  30425. const smask = this.smask;
  30426. const mask = this.mask;
  30427. let alphaBuf, sw, sh, i, ii, j;
  30428. if (smask) {
  30429. sw = smask.width;
  30430. sh = smask.height;
  30431. alphaBuf = new Uint8ClampedArray(sw * sh);
  30432. smask.fillGrayBuffer(alphaBuf);
  30433. if (sw !== width || sh !== height) {
  30434. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  30435. }
  30436. } else if (mask) {
  30437. if (mask instanceof PDFImage) {
  30438. sw = mask.width;
  30439. sh = mask.height;
  30440. alphaBuf = new Uint8ClampedArray(sw * sh);
  30441. mask.numComps = 1;
  30442. mask.fillGrayBuffer(alphaBuf);
  30443. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30444. alphaBuf[i] = 255 - alphaBuf[i];
  30445. }
  30446. if (sw !== width || sh !== height) {
  30447. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  30448. }
  30449. } else if (Array.isArray(mask)) {
  30450. alphaBuf = new Uint8ClampedArray(width * height);
  30451. const numComps = this.numComps;
  30452. for (i = 0, ii = width * height; i < ii; ++i) {
  30453. let opacity = 0;
  30454. const imageOffset = i * numComps;
  30455. for (j = 0; j < numComps; ++j) {
  30456. const color = image[imageOffset + j];
  30457. const maskOffset = j * 2;
  30458. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30459. opacity = 255;
  30460. break;
  30461. }
  30462. }
  30463. alphaBuf[i] = opacity;
  30464. }
  30465. } else {
  30466. throw new FormatError("Unknown mask format.");
  30467. }
  30468. }
  30469. if (alphaBuf) {
  30470. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30471. rgbaBuf[j] = alphaBuf[i];
  30472. }
  30473. } else {
  30474. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30475. rgbaBuf[j] = 255;
  30476. }
  30477. }
  30478. }
  30479. undoPreblend(buffer, width, height) {
  30480. const matte = this.smask?.matte;
  30481. if (!matte) {
  30482. return;
  30483. }
  30484. const matteRgb = this.colorSpace.getRgb(matte, 0);
  30485. const matteR = matteRgb[0];
  30486. const matteG = matteRgb[1];
  30487. const matteB = matteRgb[2];
  30488. const length = width * height * 4;
  30489. for (let i = 0; i < length; i += 4) {
  30490. const alpha = buffer[i + 3];
  30491. if (alpha === 0) {
  30492. buffer[i] = 255;
  30493. buffer[i + 1] = 255;
  30494. buffer[i + 2] = 255;
  30495. continue;
  30496. }
  30497. const k = 255 / alpha;
  30498. buffer[i] = (buffer[i] - matteR) * k + matteR;
  30499. buffer[i + 1] = (buffer[i + 1] - matteG) * k + matteG;
  30500. buffer[i + 2] = (buffer[i + 2] - matteB) * k + matteB;
  30501. }
  30502. }
  30503. async createImageData(forceRGBA = false, isOffscreenCanvasSupported = false) {
  30504. const drawWidth = this.drawWidth;
  30505. const drawHeight = this.drawHeight;
  30506. const imgData = {
  30507. width: drawWidth,
  30508. height: drawHeight,
  30509. interpolate: this.interpolate,
  30510. kind: 0,
  30511. data: null
  30512. };
  30513. const numComps = this.numComps;
  30514. const originalWidth = this.width;
  30515. const originalHeight = this.height;
  30516. const bpc = this.bpc;
  30517. const rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  30518. const mustBeResized = isOffscreenCanvasSupported && ImageResizer.needsToBeResized(drawWidth, drawHeight);
  30519. if (!forceRGBA) {
  30520. let kind;
  30521. if (this.colorSpace.name === "DeviceGray" && bpc === 1) {
  30522. kind = ImageKind.GRAYSCALE_1BPP;
  30523. } else if (this.colorSpace.name === "DeviceRGB" && bpc === 8 && !this.needsDecode) {
  30524. kind = ImageKind.RGB_24BPP;
  30525. }
  30526. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  30527. const data = this.getImageBytes(originalHeight * rowBytes, {});
  30528. if (isOffscreenCanvasSupported) {
  30529. if (mustBeResized) {
  30530. return ImageResizer.createImage({
  30531. data,
  30532. kind,
  30533. width: drawWidth,
  30534. height: drawHeight,
  30535. interpolate: this.interpolate
  30536. }, this.needsDecode);
  30537. }
  30538. return this.createBitmap(kind, originalWidth, originalHeight, data);
  30539. }
  30540. imgData.kind = kind;
  30541. imgData.data = data;
  30542. if (this.needsDecode) {
  30543. assert(kind === ImageKind.GRAYSCALE_1BPP, "PDFImage.createImageData: The image must be grayscale.");
  30544. const buffer = imgData.data;
  30545. for (let i = 0, ii = buffer.length; i < ii; i++) {
  30546. buffer[i] ^= 0xff;
  30547. }
  30548. }
  30549. return imgData;
  30550. }
  30551. if (this.image instanceof JpegStream && !this.smask && !this.mask && !this.needsDecode) {
  30552. let imageLength = originalHeight * rowBytes;
  30553. if (isOffscreenCanvasSupported && !mustBeResized) {
  30554. let isHandled = false;
  30555. switch (this.colorSpace.name) {
  30556. case "DeviceGray":
  30557. imageLength *= 4;
  30558. isHandled = true;
  30559. break;
  30560. case "DeviceRGB":
  30561. imageLength = imageLength / 3 * 4;
  30562. isHandled = true;
  30563. break;
  30564. case "DeviceCMYK":
  30565. isHandled = true;
  30566. break;
  30567. }
  30568. if (isHandled) {
  30569. const rgba = this.getImageBytes(imageLength, {
  30570. drawWidth,
  30571. drawHeight,
  30572. forceRGBA: true
  30573. });
  30574. return this.createBitmap(ImageKind.RGBA_32BPP, drawWidth, drawHeight, rgba);
  30575. }
  30576. } else {
  30577. switch (this.colorSpace.name) {
  30578. case "DeviceGray":
  30579. imageLength *= 3;
  30580. case "DeviceRGB":
  30581. case "DeviceCMYK":
  30582. imgData.kind = ImageKind.RGB_24BPP;
  30583. imgData.data = this.getImageBytes(imageLength, {
  30584. drawWidth,
  30585. drawHeight,
  30586. forceRGB: true
  30587. });
  30588. if (mustBeResized) {
  30589. return ImageResizer.createImage(imgData);
  30590. }
  30591. return imgData;
  30592. }
  30593. }
  30594. }
  30595. }
  30596. const imgArray = this.getImageBytes(originalHeight * rowBytes, {
  30597. internal: true
  30598. });
  30599. const actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  30600. const comps = this.getComponents(imgArray);
  30601. let alpha01, maybeUndoPreblend;
  30602. let canvas, ctx, canvasImgData, data;
  30603. if (isOffscreenCanvasSupported && !mustBeResized) {
  30604. canvas = new OffscreenCanvas(drawWidth, drawHeight);
  30605. ctx = canvas.getContext("2d");
  30606. canvasImgData = ctx.createImageData(drawWidth, drawHeight);
  30607. data = canvasImgData.data;
  30608. }
  30609. imgData.kind = ImageKind.RGBA_32BPP;
  30610. if (!forceRGBA && !this.smask && !this.mask) {
  30611. if (!isOffscreenCanvasSupported || mustBeResized) {
  30612. imgData.kind = ImageKind.RGB_24BPP;
  30613. data = new Uint8ClampedArray(drawWidth * drawHeight * 3);
  30614. alpha01 = 0;
  30615. } else {
  30616. const arr = new Uint32Array(data.buffer);
  30617. arr.fill(FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff);
  30618. alpha01 = 1;
  30619. }
  30620. maybeUndoPreblend = false;
  30621. } else {
  30622. if (!isOffscreenCanvasSupported || mustBeResized) {
  30623. data = new Uint8ClampedArray(drawWidth * drawHeight * 4);
  30624. }
  30625. alpha01 = 1;
  30626. maybeUndoPreblend = true;
  30627. this.fillOpacity(data, drawWidth, drawHeight, actualHeight, comps);
  30628. }
  30629. if (this.needsDecode) {
  30630. this.decodeBuffer(comps);
  30631. }
  30632. this.colorSpace.fillRgb(data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  30633. if (maybeUndoPreblend) {
  30634. this.undoPreblend(data, drawWidth, actualHeight);
  30635. }
  30636. if (isOffscreenCanvasSupported && !mustBeResized) {
  30637. ctx.putImageData(canvasImgData, 0, 0);
  30638. const bitmap = canvas.transferToImageBitmap();
  30639. return {
  30640. data: null,
  30641. width: drawWidth,
  30642. height: drawHeight,
  30643. bitmap,
  30644. interpolate: this.interpolate
  30645. };
  30646. }
  30647. imgData.data = data;
  30648. if (mustBeResized) {
  30649. return ImageResizer.createImage(imgData);
  30650. }
  30651. return imgData;
  30652. }
  30653. fillGrayBuffer(buffer) {
  30654. const numComps = this.numComps;
  30655. if (numComps !== 1) {
  30656. throw new FormatError(`Reading gray scale from a color image: ${numComps}`);
  30657. }
  30658. const width = this.width;
  30659. const height = this.height;
  30660. const bpc = this.bpc;
  30661. const rowBytes = width * numComps * bpc + 7 >> 3;
  30662. const imgArray = this.getImageBytes(height * rowBytes, {
  30663. internal: true
  30664. });
  30665. const comps = this.getComponents(imgArray);
  30666. let i, length;
  30667. if (bpc === 1) {
  30668. length = width * height;
  30669. if (this.needsDecode) {
  30670. for (i = 0; i < length; ++i) {
  30671. buffer[i] = comps[i] - 1 & 255;
  30672. }
  30673. } else {
  30674. for (i = 0; i < length; ++i) {
  30675. buffer[i] = -comps[i] & 255;
  30676. }
  30677. }
  30678. return;
  30679. }
  30680. if (this.needsDecode) {
  30681. this.decodeBuffer(comps);
  30682. }
  30683. length = width * height;
  30684. const scale = 255 / ((1 << bpc) - 1);
  30685. for (i = 0; i < length; ++i) {
  30686. buffer[i] = scale * comps[i];
  30687. }
  30688. }
  30689. createBitmap(kind, width, height, src) {
  30690. const canvas = new OffscreenCanvas(width, height);
  30691. const ctx = canvas.getContext("2d");
  30692. let imgData;
  30693. if (kind === ImageKind.RGBA_32BPP) {
  30694. imgData = new ImageData(src, width, height);
  30695. } else {
  30696. imgData = ctx.createImageData(width, height);
  30697. convertToRGBA({
  30698. kind,
  30699. src,
  30700. dest: new Uint32Array(imgData.data.buffer),
  30701. width,
  30702. height,
  30703. inverseDecode: this.needsDecode
  30704. });
  30705. }
  30706. ctx.putImageData(imgData, 0, 0);
  30707. const bitmap = canvas.transferToImageBitmap();
  30708. return {
  30709. data: null,
  30710. width,
  30711. height,
  30712. bitmap,
  30713. interpolate: this.interpolate
  30714. };
  30715. }
  30716. getImageBytes(length, {
  30717. drawWidth,
  30718. drawHeight,
  30719. forceRGBA = false,
  30720. forceRGB = false,
  30721. internal = false
  30722. }) {
  30723. this.image.reset();
  30724. this.image.drawWidth = drawWidth || this.width;
  30725. this.image.drawHeight = drawHeight || this.height;
  30726. this.image.forceRGBA = !!forceRGBA;
  30727. this.image.forceRGB = !!forceRGB;
  30728. const imageBytes = this.image.getBytes(length);
  30729. if (internal || this.image instanceof DecodeStream) {
  30730. return imageBytes;
  30731. }
  30732. assert(imageBytes instanceof Uint8Array, 'PDFImage.getImageBytes: Unsupported "imageBytes" type.');
  30733. return new Uint8Array(imageBytes);
  30734. }
  30735. }
  30736. ;// CONCATENATED MODULE: ./src/core/evaluator.js
  30737. const DefaultPartialEvaluatorOptions = Object.freeze({
  30738. maxImageSize: -1,
  30739. disableFontFace: false,
  30740. ignoreErrors: false,
  30741. isEvalSupported: true,
  30742. isOffscreenCanvasSupported: false,
  30743. canvasMaxAreaInBytes: -1,
  30744. fontExtraProperties: false,
  30745. useSystemFonts: true,
  30746. cMapUrl: null,
  30747. standardFontDataUrl: null
  30748. });
  30749. const PatternType = {
  30750. TILING: 1,
  30751. SHADING: 2
  30752. };
  30753. const TEXT_CHUNK_BATCH_SIZE = 10;
  30754. const deferred = Promise.resolve();
  30755. function normalizeBlendMode(value, parsingArray = false) {
  30756. if (Array.isArray(value)) {
  30757. for (const val of value) {
  30758. const maybeBM = normalizeBlendMode(val, true);
  30759. if (maybeBM) {
  30760. return maybeBM;
  30761. }
  30762. }
  30763. warn(`Unsupported blend mode Array: ${value}`);
  30764. return "source-over";
  30765. }
  30766. if (!(value instanceof Name)) {
  30767. if (parsingArray) {
  30768. return null;
  30769. }
  30770. return "source-over";
  30771. }
  30772. switch (value.name) {
  30773. case "Normal":
  30774. case "Compatible":
  30775. return "source-over";
  30776. case "Multiply":
  30777. return "multiply";
  30778. case "Screen":
  30779. return "screen";
  30780. case "Overlay":
  30781. return "overlay";
  30782. case "Darken":
  30783. return "darken";
  30784. case "Lighten":
  30785. return "lighten";
  30786. case "ColorDodge":
  30787. return "color-dodge";
  30788. case "ColorBurn":
  30789. return "color-burn";
  30790. case "HardLight":
  30791. return "hard-light";
  30792. case "SoftLight":
  30793. return "soft-light";
  30794. case "Difference":
  30795. return "difference";
  30796. case "Exclusion":
  30797. return "exclusion";
  30798. case "Hue":
  30799. return "hue";
  30800. case "Saturation":
  30801. return "saturation";
  30802. case "Color":
  30803. return "color";
  30804. case "Luminosity":
  30805. return "luminosity";
  30806. }
  30807. if (parsingArray) {
  30808. return null;
  30809. }
  30810. warn(`Unsupported blend mode: ${value.name}`);
  30811. return "source-over";
  30812. }
  30813. function incrementCachedImageMaskCount(data) {
  30814. if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
  30815. data.args[0].count++;
  30816. }
  30817. }
  30818. class TimeSlotManager {
  30819. static TIME_SLOT_DURATION_MS = 20;
  30820. static CHECK_TIME_EVERY = 100;
  30821. constructor() {
  30822. this.reset();
  30823. }
  30824. check() {
  30825. if (++this.checked < TimeSlotManager.CHECK_TIME_EVERY) {
  30826. return false;
  30827. }
  30828. this.checked = 0;
  30829. return this.endTime <= Date.now();
  30830. }
  30831. reset() {
  30832. this.endTime = Date.now() + TimeSlotManager.TIME_SLOT_DURATION_MS;
  30833. this.checked = 0;
  30834. }
  30835. }
  30836. class PartialEvaluator {
  30837. constructor({
  30838. xref,
  30839. handler,
  30840. pageIndex,
  30841. idFactory,
  30842. fontCache,
  30843. builtInCMapCache,
  30844. standardFontDataCache,
  30845. globalImageCache,
  30846. systemFontCache,
  30847. options = null
  30848. }) {
  30849. this.xref = xref;
  30850. this.handler = handler;
  30851. this.pageIndex = pageIndex;
  30852. this.idFactory = idFactory;
  30853. this.fontCache = fontCache;
  30854. this.builtInCMapCache = builtInCMapCache;
  30855. this.standardFontDataCache = standardFontDataCache;
  30856. this.globalImageCache = globalImageCache;
  30857. this.systemFontCache = systemFontCache;
  30858. this.options = options || DefaultPartialEvaluatorOptions;
  30859. this.parsingType3Font = false;
  30860. this._regionalImageCache = new RegionalImageCache();
  30861. this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
  30862. ImageResizer.setMaxArea(this.options.canvasMaxAreaInBytes);
  30863. }
  30864. get _pdfFunctionFactory() {
  30865. const pdfFunctionFactory = new PDFFunctionFactory({
  30866. xref: this.xref,
  30867. isEvalSupported: this.options.isEvalSupported
  30868. });
  30869. return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory);
  30870. }
  30871. clone(newOptions = null) {
  30872. const newEvaluator = Object.create(this);
  30873. newEvaluator.options = Object.assign(Object.create(null), this.options, newOptions);
  30874. return newEvaluator;
  30875. }
  30876. hasBlendModes(resources, nonBlendModesSet) {
  30877. if (!(resources instanceof Dict)) {
  30878. return false;
  30879. }
  30880. if (resources.objId && nonBlendModesSet.has(resources.objId)) {
  30881. return false;
  30882. }
  30883. const processed = new RefSet(nonBlendModesSet);
  30884. if (resources.objId) {
  30885. processed.put(resources.objId);
  30886. }
  30887. const nodes = [resources],
  30888. xref = this.xref;
  30889. while (nodes.length) {
  30890. const node = nodes.shift();
  30891. const graphicStates = node.get("ExtGState");
  30892. if (graphicStates instanceof Dict) {
  30893. for (let graphicState of graphicStates.getRawValues()) {
  30894. if (graphicState instanceof Ref) {
  30895. if (processed.has(graphicState)) {
  30896. continue;
  30897. }
  30898. try {
  30899. graphicState = xref.fetch(graphicState);
  30900. } catch (ex) {
  30901. processed.put(graphicState);
  30902. info(`hasBlendModes - ignoring ExtGState: "${ex}".`);
  30903. continue;
  30904. }
  30905. }
  30906. if (!(graphicState instanceof Dict)) {
  30907. continue;
  30908. }
  30909. if (graphicState.objId) {
  30910. processed.put(graphicState.objId);
  30911. }
  30912. const bm = graphicState.get("BM");
  30913. if (bm instanceof Name) {
  30914. if (bm.name !== "Normal") {
  30915. return true;
  30916. }
  30917. continue;
  30918. }
  30919. if (bm !== undefined && Array.isArray(bm)) {
  30920. for (const element of bm) {
  30921. if (element instanceof Name && element.name !== "Normal") {
  30922. return true;
  30923. }
  30924. }
  30925. }
  30926. }
  30927. }
  30928. const xObjects = node.get("XObject");
  30929. if (!(xObjects instanceof Dict)) {
  30930. continue;
  30931. }
  30932. for (let xObject of xObjects.getRawValues()) {
  30933. if (xObject instanceof Ref) {
  30934. if (processed.has(xObject)) {
  30935. continue;
  30936. }
  30937. try {
  30938. xObject = xref.fetch(xObject);
  30939. } catch (ex) {
  30940. processed.put(xObject);
  30941. info(`hasBlendModes - ignoring XObject: "${ex}".`);
  30942. continue;
  30943. }
  30944. }
  30945. if (!(xObject instanceof BaseStream)) {
  30946. continue;
  30947. }
  30948. if (xObject.dict.objId) {
  30949. processed.put(xObject.dict.objId);
  30950. }
  30951. const xResources = xObject.dict.get("Resources");
  30952. if (!(xResources instanceof Dict)) {
  30953. continue;
  30954. }
  30955. if (xResources.objId && processed.has(xResources.objId)) {
  30956. continue;
  30957. }
  30958. nodes.push(xResources);
  30959. if (xResources.objId) {
  30960. processed.put(xResources.objId);
  30961. }
  30962. }
  30963. }
  30964. for (const ref of processed) {
  30965. nonBlendModesSet.put(ref);
  30966. }
  30967. return false;
  30968. }
  30969. async fetchBuiltInCMap(name) {
  30970. const cachedData = this.builtInCMapCache.get(name);
  30971. if (cachedData) {
  30972. return cachedData;
  30973. }
  30974. let data;
  30975. if (this.options.cMapUrl !== null) {
  30976. const url = `${this.options.cMapUrl}${name}.bcmap`;
  30977. const response = await fetch(url);
  30978. if (!response.ok) {
  30979. throw new Error(`fetchBuiltInCMap: failed to fetch file "${url}" with "${response.statusText}".`);
  30980. }
  30981. data = {
  30982. cMapData: new Uint8Array(await response.arrayBuffer()),
  30983. compressionType: CMapCompressionType.BINARY
  30984. };
  30985. } else {
  30986. data = await this.handler.sendWithPromise("FetchBuiltInCMap", {
  30987. name
  30988. });
  30989. }
  30990. if (data.compressionType !== CMapCompressionType.NONE) {
  30991. this.builtInCMapCache.set(name, data);
  30992. }
  30993. return data;
  30994. }
  30995. async fetchStandardFontData(name) {
  30996. const cachedData = this.standardFontDataCache.get(name);
  30997. if (cachedData) {
  30998. return new Stream(cachedData);
  30999. }
  31000. if (this.options.useSystemFonts && name !== "Symbol" && name !== "ZapfDingbats") {
  31001. return null;
  31002. }
  31003. const standardFontNameToFileName = getFontNameToFileMap(),
  31004. filename = standardFontNameToFileName[name];
  31005. let data;
  31006. if (this.options.standardFontDataUrl !== null) {
  31007. const url = `${this.options.standardFontDataUrl}${filename}`;
  31008. const response = await fetch(url);
  31009. if (!response.ok) {
  31010. warn(`fetchStandardFontData: failed to fetch file "${url}" with "${response.statusText}".`);
  31011. } else {
  31012. data = new Uint8Array(await response.arrayBuffer());
  31013. }
  31014. } else {
  31015. try {
  31016. data = await this.handler.sendWithPromise("FetchStandardFontData", {
  31017. filename
  31018. });
  31019. } catch (e) {
  31020. warn(`fetchStandardFontData: failed to fetch file "${filename}" with "${e}".`);
  31021. }
  31022. }
  31023. if (!data) {
  31024. return null;
  31025. }
  31026. this.standardFontDataCache.set(name, data);
  31027. return new Stream(data);
  31028. }
  31029. async buildFormXObject(resources, xobj, smask, operatorList, task, initialState, localColorSpaceCache) {
  31030. const dict = xobj.dict;
  31031. const matrix = dict.getArray("Matrix");
  31032. let bbox = dict.getArray("BBox");
  31033. bbox = Array.isArray(bbox) && bbox.length === 4 ? Util.normalizeRect(bbox) : null;
  31034. let optionalContent, groupOptions;
  31035. if (dict.has("OC")) {
  31036. optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources);
  31037. }
  31038. if (optionalContent !== undefined) {
  31039. operatorList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
  31040. }
  31041. const group = dict.get("Group");
  31042. if (group) {
  31043. groupOptions = {
  31044. matrix,
  31045. bbox,
  31046. smask,
  31047. isolated: false,
  31048. knockout: false
  31049. };
  31050. const groupSubtype = group.get("S");
  31051. let colorSpace = null;
  31052. if (isName(groupSubtype, "Transparency")) {
  31053. groupOptions.isolated = group.get("I") || false;
  31054. groupOptions.knockout = group.get("K") || false;
  31055. if (group.has("CS")) {
  31056. const cs = group.getRaw("CS");
  31057. const cachedColorSpace = ColorSpace.getCached(cs, this.xref, localColorSpaceCache);
  31058. if (cachedColorSpace) {
  31059. colorSpace = cachedColorSpace;
  31060. } else {
  31061. colorSpace = await this.parseColorSpace({
  31062. cs,
  31063. resources,
  31064. localColorSpaceCache
  31065. });
  31066. }
  31067. }
  31068. }
  31069. if (smask?.backdrop) {
  31070. colorSpace ||= ColorSpace.singletons.rgb;
  31071. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  31072. }
  31073. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  31074. }
  31075. const args = group ? [matrix, null] : [matrix, bbox];
  31076. operatorList.addOp(OPS.paintFormXObjectBegin, args);
  31077. return this.getOperatorList({
  31078. stream: xobj,
  31079. task,
  31080. resources: dict.get("Resources") || resources,
  31081. operatorList,
  31082. initialState
  31083. }).then(function () {
  31084. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  31085. if (group) {
  31086. operatorList.addOp(OPS.endGroup, [groupOptions]);
  31087. }
  31088. if (optionalContent !== undefined) {
  31089. operatorList.addOp(OPS.endMarkedContent, []);
  31090. }
  31091. });
  31092. }
  31093. _sendImgData(objId, imgData, cacheGlobally = false) {
  31094. const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null;
  31095. if (this.parsingType3Font || cacheGlobally) {
  31096. return this.handler.send("commonobj", [objId, "Image", imgData], transfers);
  31097. }
  31098. return this.handler.send("obj", [objId, this.pageIndex, "Image", imgData], transfers);
  31099. }
  31100. async buildPaintImageXObject({
  31101. resources,
  31102. image,
  31103. isInline = false,
  31104. operatorList,
  31105. cacheKey,
  31106. localImageCache,
  31107. localColorSpaceCache
  31108. }) {
  31109. const dict = image.dict;
  31110. const imageRef = dict.objId;
  31111. const w = dict.get("W", "Width");
  31112. const h = dict.get("H", "Height");
  31113. if (!(w && typeof w === "number") || !(h && typeof h === "number")) {
  31114. warn("Image dimensions are missing, or not numbers.");
  31115. return;
  31116. }
  31117. const maxImageSize = this.options.maxImageSize;
  31118. if (maxImageSize !== -1 && w * h > maxImageSize) {
  31119. const msg = "Image exceeded maximum allowed size and was removed.";
  31120. if (this.options.ignoreErrors) {
  31121. warn(msg);
  31122. return;
  31123. }
  31124. throw new Error(msg);
  31125. }
  31126. let optionalContent;
  31127. if (dict.has("OC")) {
  31128. optionalContent = await this.parseMarkedContentProps(dict.get("OC"), resources);
  31129. }
  31130. const imageMask = dict.get("IM", "ImageMask") || false;
  31131. let imgData, args;
  31132. if (imageMask) {
  31133. const interpolate = dict.get("I", "Interpolate");
  31134. const bitStrideLength = w + 7 >> 3;
  31135. const imgArray = image.getBytes(bitStrideLength * h);
  31136. const decode = dict.getArray("D", "Decode");
  31137. if (this.parsingType3Font) {
  31138. imgData = PDFImage.createRawMask({
  31139. imgArray,
  31140. width: w,
  31141. height: h,
  31142. imageIsFromDecodeStream: image instanceof DecodeStream,
  31143. inverseDecode: decode?.[0] > 0,
  31144. interpolate
  31145. });
  31146. imgData.cached = !!cacheKey;
  31147. args = [imgData];
  31148. operatorList.addImageOps(OPS.paintImageMaskXObject, args, optionalContent);
  31149. if (cacheKey) {
  31150. const cacheData = {
  31151. fn: OPS.paintImageMaskXObject,
  31152. args,
  31153. optionalContent
  31154. };
  31155. localImageCache.set(cacheKey, imageRef, cacheData);
  31156. if (imageRef) {
  31157. this._regionalImageCache.set(null, imageRef, cacheData);
  31158. }
  31159. }
  31160. return;
  31161. }
  31162. imgData = await PDFImage.createMask({
  31163. imgArray,
  31164. width: w,
  31165. height: h,
  31166. imageIsFromDecodeStream: image instanceof DecodeStream,
  31167. inverseDecode: decode?.[0] > 0,
  31168. interpolate,
  31169. isOffscreenCanvasSupported: this.options.isOffscreenCanvasSupported
  31170. });
  31171. if (imgData.isSingleOpaquePixel) {
  31172. operatorList.addImageOps(OPS.paintSolidColorImageMask, [], optionalContent);
  31173. if (cacheKey) {
  31174. const cacheData = {
  31175. fn: OPS.paintSolidColorImageMask,
  31176. args: [],
  31177. optionalContent
  31178. };
  31179. localImageCache.set(cacheKey, imageRef, cacheData);
  31180. if (imageRef) {
  31181. this._regionalImageCache.set(null, imageRef, cacheData);
  31182. }
  31183. }
  31184. return;
  31185. }
  31186. const objId = `mask_${this.idFactory.createObjId()}`;
  31187. operatorList.addDependency(objId);
  31188. imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
  31189. this._sendImgData(objId, imgData);
  31190. args = [{
  31191. data: objId,
  31192. width: imgData.width,
  31193. height: imgData.height,
  31194. interpolate: imgData.interpolate,
  31195. count: 1
  31196. }];
  31197. operatorList.addImageOps(OPS.paintImageMaskXObject, args, optionalContent);
  31198. if (cacheKey) {
  31199. const cacheData = {
  31200. fn: OPS.paintImageMaskXObject,
  31201. args,
  31202. optionalContent
  31203. };
  31204. localImageCache.set(cacheKey, imageRef, cacheData);
  31205. if (imageRef) {
  31206. this._regionalImageCache.set(null, imageRef, cacheData);
  31207. }
  31208. }
  31209. return;
  31210. }
  31211. const SMALL_IMAGE_DIMENSIONS = 200;
  31212. if (isInline && !dict.has("SMask") && !dict.has("Mask") && w + h < SMALL_IMAGE_DIMENSIONS) {
  31213. const imageObj = new PDFImage({
  31214. xref: this.xref,
  31215. res: resources,
  31216. image,
  31217. isInline,
  31218. pdfFunctionFactory: this._pdfFunctionFactory,
  31219. localColorSpaceCache
  31220. });
  31221. imgData = await imageObj.createImageData(true, false);
  31222. operatorList.isOffscreenCanvasSupported = this.options.isOffscreenCanvasSupported;
  31223. operatorList.addImageOps(OPS.paintInlineImageXObject, [imgData], optionalContent);
  31224. return;
  31225. }
  31226. let objId = `img_${this.idFactory.createObjId()}`,
  31227. cacheGlobally = false;
  31228. if (this.parsingType3Font) {
  31229. objId = `${this.idFactory.getDocId()}_type3_${objId}`;
  31230. } else if (cacheKey && imageRef) {
  31231. cacheGlobally = this.globalImageCache.shouldCache(imageRef, this.pageIndex);
  31232. if (cacheGlobally) {
  31233. assert(!isInline, "Cannot cache an inline image globally.");
  31234. objId = `${this.idFactory.getDocId()}_${objId}`;
  31235. }
  31236. }
  31237. operatorList.addDependency(objId);
  31238. args = [objId, w, h];
  31239. operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
  31240. if (cacheGlobally && w * h > 250000) {
  31241. const localLength = await this.handler.sendWithPromise("commonobj", [objId, "CopyLocalImage", {
  31242. imageRef
  31243. }]);
  31244. if (localLength) {
  31245. this.globalImageCache.setData(imageRef, {
  31246. objId,
  31247. fn: OPS.paintImageXObject,
  31248. args,
  31249. optionalContent,
  31250. byteSize: 0
  31251. });
  31252. this.globalImageCache.addByteSize(imageRef, localLength);
  31253. return;
  31254. }
  31255. }
  31256. PDFImage.buildImage({
  31257. xref: this.xref,
  31258. res: resources,
  31259. image,
  31260. isInline,
  31261. pdfFunctionFactory: this._pdfFunctionFactory,
  31262. localColorSpaceCache
  31263. }).then(async imageObj => {
  31264. imgData = await imageObj.createImageData(false, this.options.isOffscreenCanvasSupported);
  31265. imgData.dataLen = imgData.bitmap ? imgData.width * imgData.height * 4 : imgData.data.length;
  31266. imgData.ref = imageRef;
  31267. if (cacheGlobally) {
  31268. this.globalImageCache.addByteSize(imageRef, imgData.dataLen);
  31269. }
  31270. return this._sendImgData(objId, imgData, cacheGlobally);
  31271. }).catch(reason => {
  31272. warn(`Unable to decode image "${objId}": "${reason}".`);
  31273. return this._sendImgData(objId, null, cacheGlobally);
  31274. });
  31275. if (cacheKey) {
  31276. const cacheData = {
  31277. fn: OPS.paintImageXObject,
  31278. args,
  31279. optionalContent
  31280. };
  31281. localImageCache.set(cacheKey, imageRef, cacheData);
  31282. if (imageRef) {
  31283. this._regionalImageCache.set(null, imageRef, cacheData);
  31284. if (cacheGlobally) {
  31285. this.globalImageCache.setData(imageRef, {
  31286. objId,
  31287. fn: OPS.paintImageXObject,
  31288. args,
  31289. optionalContent,
  31290. byteSize: 0
  31291. });
  31292. }
  31293. }
  31294. }
  31295. }
  31296. handleSMask(smask, resources, operatorList, task, stateManager, localColorSpaceCache) {
  31297. const smaskContent = smask.get("G");
  31298. const smaskOptions = {
  31299. subtype: smask.get("S").name,
  31300. backdrop: smask.get("BC")
  31301. };
  31302. const transferObj = smask.get("TR");
  31303. if (isPDFFunction(transferObj)) {
  31304. const transferFn = this._pdfFunctionFactory.create(transferObj);
  31305. const transferMap = new Uint8Array(256);
  31306. const tmp = new Float32Array(1);
  31307. for (let i = 0; i < 256; i++) {
  31308. tmp[0] = i / 255;
  31309. transferFn(tmp, 0, tmp, 0);
  31310. transferMap[i] = tmp[0] * 255 | 0;
  31311. }
  31312. smaskOptions.transferMap = transferMap;
  31313. }
  31314. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone(), localColorSpaceCache);
  31315. }
  31316. handleTransferFunction(tr) {
  31317. let transferArray;
  31318. if (Array.isArray(tr)) {
  31319. transferArray = tr;
  31320. } else if (isPDFFunction(tr)) {
  31321. transferArray = [tr];
  31322. } else {
  31323. return null;
  31324. }
  31325. const transferMaps = [];
  31326. let numFns = 0,
  31327. numEffectfulFns = 0;
  31328. for (const entry of transferArray) {
  31329. const transferObj = this.xref.fetchIfRef(entry);
  31330. numFns++;
  31331. if (isName(transferObj, "Identity")) {
  31332. transferMaps.push(null);
  31333. continue;
  31334. } else if (!isPDFFunction(transferObj)) {
  31335. return null;
  31336. }
  31337. const transferFn = this._pdfFunctionFactory.create(transferObj);
  31338. const transferMap = new Uint8Array(256),
  31339. tmp = new Float32Array(1);
  31340. for (let j = 0; j < 256; j++) {
  31341. tmp[0] = j / 255;
  31342. transferFn(tmp, 0, tmp, 0);
  31343. transferMap[j] = tmp[0] * 255 | 0;
  31344. }
  31345. transferMaps.push(transferMap);
  31346. numEffectfulFns++;
  31347. }
  31348. if (!(numFns === 1 || numFns === 4)) {
  31349. return null;
  31350. }
  31351. if (numEffectfulFns === 0) {
  31352. return null;
  31353. }
  31354. return transferMaps;
  31355. }
  31356. handleTilingType(fn, color, resources, pattern, patternDict, operatorList, task, localTilingPatternCache) {
  31357. const tilingOpList = new OperatorList();
  31358. const patternResources = Dict.merge({
  31359. xref: this.xref,
  31360. dictArray: [patternDict.get("Resources"), resources]
  31361. });
  31362. return this.getOperatorList({
  31363. stream: pattern,
  31364. task,
  31365. resources: patternResources,
  31366. operatorList: tilingOpList
  31367. }).then(function () {
  31368. const operatorListIR = tilingOpList.getIR();
  31369. const tilingPatternIR = getTilingPatternIR(operatorListIR, patternDict, color);
  31370. operatorList.addDependencies(tilingOpList.dependencies);
  31371. operatorList.addOp(fn, tilingPatternIR);
  31372. if (patternDict.objId) {
  31373. localTilingPatternCache.set(null, patternDict.objId, {
  31374. operatorListIR,
  31375. dict: patternDict
  31376. });
  31377. }
  31378. }).catch(reason => {
  31379. if (reason instanceof AbortException) {
  31380. return;
  31381. }
  31382. if (this.options.ignoreErrors) {
  31383. warn(`handleTilingType - ignoring pattern: "${reason}".`);
  31384. return;
  31385. }
  31386. throw reason;
  31387. });
  31388. }
  31389. handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) {
  31390. const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
  31391. return this.loadFont(fontName, fontRef, resources, fallbackFontDict, cssFontInfo).then(translated => {
  31392. if (!translated.font.isType3Font) {
  31393. return translated;
  31394. }
  31395. return translated.loadType3Data(this, resources, task).then(function () {
  31396. operatorList.addDependencies(translated.type3Dependencies);
  31397. return translated;
  31398. }).catch(reason => {
  31399. return new TranslatedFont({
  31400. loadedName: "g_font_error",
  31401. font: new ErrorFont(`Type3 font load error: ${reason}`),
  31402. dict: translated.font,
  31403. evaluatorOptions: this.options
  31404. });
  31405. });
  31406. }).then(translated => {
  31407. state.font = translated.font;
  31408. translated.send(this.handler);
  31409. return translated.loadedName;
  31410. });
  31411. }
  31412. handleText(chars, state) {
  31413. const font = state.font;
  31414. const glyphs = font.charsToGlyphs(chars);
  31415. if (font.data) {
  31416. const isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  31417. if (isAddToPathSet || state.fillColorSpace.name === "Pattern" || font.disableFontFace || this.options.disableFontFace) {
  31418. PartialEvaluator.buildFontPaths(font, glyphs, this.handler, this.options);
  31419. }
  31420. }
  31421. return glyphs;
  31422. }
  31423. ensureStateFont(state) {
  31424. if (state.font) {
  31425. return;
  31426. }
  31427. const reason = new FormatError("Missing setFont (Tf) operator before text rendering operator.");
  31428. if (this.options.ignoreErrors) {
  31429. warn(`ensureStateFont: "${reason}".`);
  31430. return;
  31431. }
  31432. throw reason;
  31433. }
  31434. async setGState({
  31435. resources,
  31436. gState,
  31437. operatorList,
  31438. cacheKey,
  31439. task,
  31440. stateManager,
  31441. localGStateCache,
  31442. localColorSpaceCache
  31443. }) {
  31444. const gStateRef = gState.objId;
  31445. let isSimpleGState = true;
  31446. const gStateObj = [];
  31447. let promise = Promise.resolve();
  31448. for (const key of gState.getKeys()) {
  31449. const value = gState.get(key);
  31450. switch (key) {
  31451. case "Type":
  31452. break;
  31453. case "LW":
  31454. case "LC":
  31455. case "LJ":
  31456. case "ML":
  31457. case "D":
  31458. case "RI":
  31459. case "FL":
  31460. case "CA":
  31461. case "ca":
  31462. gStateObj.push([key, value]);
  31463. break;
  31464. case "Font":
  31465. isSimpleGState = false;
  31466. promise = promise.then(() => {
  31467. return this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  31468. operatorList.addDependency(loadedName);
  31469. gStateObj.push([key, [loadedName, value[1]]]);
  31470. });
  31471. });
  31472. break;
  31473. case "BM":
  31474. gStateObj.push([key, normalizeBlendMode(value)]);
  31475. break;
  31476. case "SMask":
  31477. if (isName(value, "None")) {
  31478. gStateObj.push([key, false]);
  31479. break;
  31480. }
  31481. if (value instanceof Dict) {
  31482. isSimpleGState = false;
  31483. promise = promise.then(() => {
  31484. return this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache);
  31485. });
  31486. gStateObj.push([key, true]);
  31487. } else {
  31488. warn("Unsupported SMask type");
  31489. }
  31490. break;
  31491. case "TR":
  31492. const transferMaps = this.handleTransferFunction(value);
  31493. gStateObj.push([key, transferMaps]);
  31494. break;
  31495. case "OP":
  31496. case "op":
  31497. case "OPM":
  31498. case "BG":
  31499. case "BG2":
  31500. case "UCR":
  31501. case "UCR2":
  31502. case "TR2":
  31503. case "HT":
  31504. case "SM":
  31505. case "SA":
  31506. case "AIS":
  31507. case "TK":
  31508. info("graphic state operator " + key);
  31509. break;
  31510. default:
  31511. info("Unknown graphic state operator " + key);
  31512. break;
  31513. }
  31514. }
  31515. return promise.then(function () {
  31516. if (gStateObj.length > 0) {
  31517. operatorList.addOp(OPS.setGState, [gStateObj]);
  31518. }
  31519. if (isSimpleGState) {
  31520. localGStateCache.set(cacheKey, gStateRef, gStateObj);
  31521. }
  31522. });
  31523. }
  31524. loadFont(fontName, font, resources, fallbackFontDict = null, cssFontInfo = null) {
  31525. const errorFont = async () => {
  31526. return new TranslatedFont({
  31527. loadedName: "g_font_error",
  31528. font: new ErrorFont(`Font "${fontName}" is not available.`),
  31529. dict: font,
  31530. evaluatorOptions: this.options
  31531. });
  31532. };
  31533. let fontRef;
  31534. if (font) {
  31535. if (font instanceof Ref) {
  31536. fontRef = font;
  31537. }
  31538. } else {
  31539. const fontRes = resources.get("Font");
  31540. if (fontRes) {
  31541. fontRef = fontRes.getRaw(fontName);
  31542. }
  31543. }
  31544. if (fontRef) {
  31545. if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
  31546. return errorFont();
  31547. }
  31548. if (this.fontCache.has(fontRef)) {
  31549. return this.fontCache.get(fontRef);
  31550. }
  31551. font = this.xref.fetchIfRef(fontRef);
  31552. }
  31553. if (!(font instanceof Dict)) {
  31554. if (!this.options.ignoreErrors && !this.parsingType3Font) {
  31555. warn(`Font "${fontName}" is not available.`);
  31556. return errorFont();
  31557. }
  31558. warn(`Font "${fontName}" is not available -- attempting to fallback to a default font.`);
  31559. font = fallbackFontDict || PartialEvaluator.fallbackFontDict;
  31560. }
  31561. if (font.cacheKey && this.fontCache.has(font.cacheKey)) {
  31562. return this.fontCache.get(font.cacheKey);
  31563. }
  31564. const fontCapability = new PromiseCapability();
  31565. let preEvaluatedFont;
  31566. try {
  31567. preEvaluatedFont = this.preEvaluateFont(font);
  31568. preEvaluatedFont.cssFontInfo = cssFontInfo;
  31569. } catch (reason) {
  31570. warn(`loadFont - preEvaluateFont failed: "${reason}".`);
  31571. return errorFont();
  31572. }
  31573. const {
  31574. descriptor,
  31575. hash
  31576. } = preEvaluatedFont;
  31577. const fontRefIsRef = fontRef instanceof Ref;
  31578. let fontID;
  31579. if (hash && descriptor instanceof Dict) {
  31580. const fontAliases = descriptor.fontAliases ||= Object.create(null);
  31581. if (fontAliases[hash]) {
  31582. const aliasFontRef = fontAliases[hash].aliasRef;
  31583. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  31584. this.fontCache.putAlias(fontRef, aliasFontRef);
  31585. return this.fontCache.get(fontRef);
  31586. }
  31587. } else {
  31588. fontAliases[hash] = {
  31589. fontID: this.idFactory.createFontId()
  31590. };
  31591. }
  31592. if (fontRefIsRef) {
  31593. fontAliases[hash].aliasRef = fontRef;
  31594. }
  31595. fontID = fontAliases[hash].fontID;
  31596. } else {
  31597. fontID = this.idFactory.createFontId();
  31598. }
  31599. assert(fontID?.startsWith("f"), 'The "fontID" must be (correctly) defined.');
  31600. if (fontRefIsRef) {
  31601. this.fontCache.put(fontRef, fontCapability.promise);
  31602. } else {
  31603. font.cacheKey = `cacheKey_${fontID}`;
  31604. this.fontCache.put(font.cacheKey, fontCapability.promise);
  31605. }
  31606. font.loadedName = `${this.idFactory.getDocId()}_${fontID}`;
  31607. this.translateFont(preEvaluatedFont).then(translatedFont => {
  31608. fontCapability.resolve(new TranslatedFont({
  31609. loadedName: font.loadedName,
  31610. font: translatedFont,
  31611. dict: font,
  31612. evaluatorOptions: this.options
  31613. }));
  31614. }).catch(reason => {
  31615. warn(`loadFont - translateFont failed: "${reason}".`);
  31616. fontCapability.resolve(new TranslatedFont({
  31617. loadedName: font.loadedName,
  31618. font: new ErrorFont(reason instanceof Error ? reason.message : reason),
  31619. dict: font,
  31620. evaluatorOptions: this.options
  31621. }));
  31622. });
  31623. return fontCapability.promise;
  31624. }
  31625. buildPath(operatorList, fn, args, parsingText = false) {
  31626. const lastIndex = operatorList.length - 1;
  31627. if (!args) {
  31628. args = [];
  31629. }
  31630. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  31631. if (parsingText) {
  31632. warn(`Encountered path operator "${fn}" inside of a text object.`);
  31633. operatorList.addOp(OPS.save, null);
  31634. }
  31635. let minMax;
  31636. switch (fn) {
  31637. case OPS.rectangle:
  31638. const x = args[0] + args[2];
  31639. const y = args[1] + args[3];
  31640. minMax = [Math.min(args[0], x), Math.max(args[0], x), Math.min(args[1], y), Math.max(args[1], y)];
  31641. break;
  31642. case OPS.moveTo:
  31643. case OPS.lineTo:
  31644. minMax = [args[0], args[0], args[1], args[1]];
  31645. break;
  31646. default:
  31647. minMax = [Infinity, -Infinity, Infinity, -Infinity];
  31648. break;
  31649. }
  31650. operatorList.addOp(OPS.constructPath, [[fn], args, minMax]);
  31651. if (parsingText) {
  31652. operatorList.addOp(OPS.restore, null);
  31653. }
  31654. } else {
  31655. const opArgs = operatorList.argsArray[lastIndex];
  31656. opArgs[0].push(fn);
  31657. opArgs[1].push(...args);
  31658. const minMax = opArgs[2];
  31659. switch (fn) {
  31660. case OPS.rectangle:
  31661. const x = args[0] + args[2];
  31662. const y = args[1] + args[3];
  31663. minMax[0] = Math.min(minMax[0], args[0], x);
  31664. minMax[1] = Math.max(minMax[1], args[0], x);
  31665. minMax[2] = Math.min(minMax[2], args[1], y);
  31666. minMax[3] = Math.max(minMax[3], args[1], y);
  31667. break;
  31668. case OPS.moveTo:
  31669. case OPS.lineTo:
  31670. minMax[0] = Math.min(minMax[0], args[0]);
  31671. minMax[1] = Math.max(minMax[1], args[0]);
  31672. minMax[2] = Math.min(minMax[2], args[1]);
  31673. minMax[3] = Math.max(minMax[3], args[1]);
  31674. break;
  31675. }
  31676. }
  31677. }
  31678. parseColorSpace({
  31679. cs,
  31680. resources,
  31681. localColorSpaceCache
  31682. }) {
  31683. return ColorSpace.parseAsync({
  31684. cs,
  31685. xref: this.xref,
  31686. resources,
  31687. pdfFunctionFactory: this._pdfFunctionFactory,
  31688. localColorSpaceCache
  31689. }).catch(reason => {
  31690. if (reason instanceof AbortException) {
  31691. return null;
  31692. }
  31693. if (this.options.ignoreErrors) {
  31694. warn(`parseColorSpace - ignoring ColorSpace: "${reason}".`);
  31695. return null;
  31696. }
  31697. throw reason;
  31698. });
  31699. }
  31700. parseShading({
  31701. shading,
  31702. resources,
  31703. localColorSpaceCache,
  31704. localShadingPatternCache
  31705. }) {
  31706. let id = localShadingPatternCache.get(shading);
  31707. if (!id) {
  31708. var shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, localColorSpaceCache);
  31709. const patternIR = shadingFill.getIR();
  31710. id = `pattern_${this.idFactory.createObjId()}`;
  31711. if (this.parsingType3Font) {
  31712. id = `${this.idFactory.getDocId()}_type3_${id}`;
  31713. }
  31714. localShadingPatternCache.set(shading, id);
  31715. if (this.parsingType3Font) {
  31716. this.handler.send("commonobj", [id, "Pattern", patternIR]);
  31717. } else {
  31718. this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]);
  31719. }
  31720. }
  31721. return id;
  31722. }
  31723. handleColorN(operatorList, fn, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache) {
  31724. const patternName = args.pop();
  31725. if (patternName instanceof Name) {
  31726. const rawPattern = patterns.getRaw(patternName.name);
  31727. const localTilingPattern = rawPattern instanceof Ref && localTilingPatternCache.getByRef(rawPattern);
  31728. if (localTilingPattern) {
  31729. try {
  31730. const color = cs.base ? cs.base.getRgb(args, 0) : null;
  31731. const tilingPatternIR = getTilingPatternIR(localTilingPattern.operatorListIR, localTilingPattern.dict, color);
  31732. operatorList.addOp(fn, tilingPatternIR);
  31733. return undefined;
  31734. } catch {}
  31735. }
  31736. const pattern = this.xref.fetchIfRef(rawPattern);
  31737. if (pattern) {
  31738. const dict = pattern instanceof BaseStream ? pattern.dict : pattern;
  31739. const typeNum = dict.get("PatternType");
  31740. if (typeNum === PatternType.TILING) {
  31741. const color = cs.base ? cs.base.getRgb(args, 0) : null;
  31742. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task, localTilingPatternCache);
  31743. } else if (typeNum === PatternType.SHADING) {
  31744. const shading = dict.get("Shading");
  31745. const matrix = dict.getArray("Matrix");
  31746. const objId = this.parseShading({
  31747. shading,
  31748. resources,
  31749. localColorSpaceCache,
  31750. localShadingPatternCache
  31751. });
  31752. operatorList.addOp(fn, ["Shading", objId, matrix]);
  31753. return undefined;
  31754. }
  31755. throw new FormatError(`Unknown PatternType: ${typeNum}`);
  31756. }
  31757. }
  31758. throw new FormatError(`Unknown PatternName: ${patternName}`);
  31759. }
  31760. _parseVisibilityExpression(array, nestingCounter, currentResult) {
  31761. const MAX_NESTING = 10;
  31762. if (++nestingCounter > MAX_NESTING) {
  31763. warn("Visibility expression is too deeply nested");
  31764. return;
  31765. }
  31766. const length = array.length;
  31767. const operator = this.xref.fetchIfRef(array[0]);
  31768. if (length < 2 || !(operator instanceof Name)) {
  31769. warn("Invalid visibility expression");
  31770. return;
  31771. }
  31772. switch (operator.name) {
  31773. case "And":
  31774. case "Or":
  31775. case "Not":
  31776. currentResult.push(operator.name);
  31777. break;
  31778. default:
  31779. warn(`Invalid operator ${operator.name} in visibility expression`);
  31780. return;
  31781. }
  31782. for (let i = 1; i < length; i++) {
  31783. const raw = array[i];
  31784. const object = this.xref.fetchIfRef(raw);
  31785. if (Array.isArray(object)) {
  31786. const nestedResult = [];
  31787. currentResult.push(nestedResult);
  31788. this._parseVisibilityExpression(object, nestingCounter, nestedResult);
  31789. } else if (raw instanceof Ref) {
  31790. currentResult.push(raw.toString());
  31791. }
  31792. }
  31793. }
  31794. async parseMarkedContentProps(contentProperties, resources) {
  31795. let optionalContent;
  31796. if (contentProperties instanceof Name) {
  31797. const properties = resources.get("Properties");
  31798. optionalContent = properties.get(contentProperties.name);
  31799. } else if (contentProperties instanceof Dict) {
  31800. optionalContent = contentProperties;
  31801. } else {
  31802. throw new FormatError("Optional content properties malformed.");
  31803. }
  31804. const optionalContentType = optionalContent.get("Type")?.name;
  31805. if (optionalContentType === "OCG") {
  31806. return {
  31807. type: optionalContentType,
  31808. id: optionalContent.objId
  31809. };
  31810. } else if (optionalContentType === "OCMD") {
  31811. const expression = optionalContent.get("VE");
  31812. if (Array.isArray(expression)) {
  31813. const result = [];
  31814. this._parseVisibilityExpression(expression, 0, result);
  31815. if (result.length > 0) {
  31816. return {
  31817. type: "OCMD",
  31818. expression: result
  31819. };
  31820. }
  31821. }
  31822. const optionalContentGroups = optionalContent.get("OCGs");
  31823. if (Array.isArray(optionalContentGroups) || optionalContentGroups instanceof Dict) {
  31824. const groupIds = [];
  31825. if (Array.isArray(optionalContentGroups)) {
  31826. for (const ocg of optionalContentGroups) {
  31827. groupIds.push(ocg.toString());
  31828. }
  31829. } else {
  31830. groupIds.push(optionalContentGroups.objId);
  31831. }
  31832. return {
  31833. type: optionalContentType,
  31834. ids: groupIds,
  31835. policy: optionalContent.get("P") instanceof Name ? optionalContent.get("P").name : null,
  31836. expression: null
  31837. };
  31838. } else if (optionalContentGroups instanceof Ref) {
  31839. return {
  31840. type: optionalContentType,
  31841. id: optionalContentGroups.toString()
  31842. };
  31843. }
  31844. }
  31845. return null;
  31846. }
  31847. getOperatorList({
  31848. stream,
  31849. task,
  31850. resources,
  31851. operatorList,
  31852. initialState = null,
  31853. fallbackFontDict = null
  31854. }) {
  31855. resources ||= Dict.empty;
  31856. initialState ||= new EvalState();
  31857. if (!operatorList) {
  31858. throw new Error('getOperatorList: missing "operatorList" parameter');
  31859. }
  31860. const self = this;
  31861. const xref = this.xref;
  31862. let parsingText = false;
  31863. const localImageCache = new LocalImageCache();
  31864. const localColorSpaceCache = new LocalColorSpaceCache();
  31865. const localGStateCache = new LocalGStateCache();
  31866. const localTilingPatternCache = new LocalTilingPatternCache();
  31867. const localShadingPatternCache = new Map();
  31868. const xobjs = resources.get("XObject") || Dict.empty;
  31869. const patterns = resources.get("Pattern") || Dict.empty;
  31870. const stateManager = new StateManager(initialState);
  31871. const preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  31872. const timeSlotManager = new TimeSlotManager();
  31873. function closePendingRestoreOPS(argument) {
  31874. for (let i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  31875. operatorList.addOp(OPS.restore, []);
  31876. }
  31877. }
  31878. return new Promise(function promiseBody(resolve, reject) {
  31879. const next = function (promise) {
  31880. Promise.all([promise, operatorList.ready]).then(function () {
  31881. try {
  31882. promiseBody(resolve, reject);
  31883. } catch (ex) {
  31884. reject(ex);
  31885. }
  31886. }, reject);
  31887. };
  31888. task.ensureNotTerminated();
  31889. timeSlotManager.reset();
  31890. const operation = {};
  31891. let stop, i, ii, cs, name, isValidName;
  31892. while (!(stop = timeSlotManager.check())) {
  31893. operation.args = null;
  31894. if (!preprocessor.read(operation)) {
  31895. break;
  31896. }
  31897. let args = operation.args;
  31898. let fn = operation.fn;
  31899. switch (fn | 0) {
  31900. case OPS.paintXObject:
  31901. isValidName = args[0] instanceof Name;
  31902. name = args[0].name;
  31903. if (isValidName) {
  31904. const localImage = localImageCache.getByName(name);
  31905. if (localImage) {
  31906. operatorList.addImageOps(localImage.fn, localImage.args, localImage.optionalContent);
  31907. incrementCachedImageMaskCount(localImage);
  31908. args = null;
  31909. continue;
  31910. }
  31911. }
  31912. next(new Promise(function (resolveXObject, rejectXObject) {
  31913. if (!isValidName) {
  31914. throw new FormatError("XObject must be referred to by name.");
  31915. }
  31916. let xobj = xobjs.getRaw(name);
  31917. if (xobj instanceof Ref) {
  31918. const localImage = localImageCache.getByRef(xobj) || self._regionalImageCache.getByRef(xobj);
  31919. if (localImage) {
  31920. operatorList.addImageOps(localImage.fn, localImage.args, localImage.optionalContent);
  31921. incrementCachedImageMaskCount(localImage);
  31922. resolveXObject();
  31923. return;
  31924. }
  31925. const globalImage = self.globalImageCache.getData(xobj, self.pageIndex);
  31926. if (globalImage) {
  31927. operatorList.addDependency(globalImage.objId);
  31928. operatorList.addImageOps(globalImage.fn, globalImage.args, globalImage.optionalContent);
  31929. resolveXObject();
  31930. return;
  31931. }
  31932. xobj = xref.fetch(xobj);
  31933. }
  31934. if (!(xobj instanceof BaseStream)) {
  31935. throw new FormatError("XObject should be a stream");
  31936. }
  31937. const type = xobj.dict.get("Subtype");
  31938. if (!(type instanceof Name)) {
  31939. throw new FormatError("XObject should have a Name subtype");
  31940. }
  31941. if (type.name === "Form") {
  31942. stateManager.save();
  31943. self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone(), localColorSpaceCache).then(function () {
  31944. stateManager.restore();
  31945. resolveXObject();
  31946. }, rejectXObject);
  31947. return;
  31948. } else if (type.name === "Image") {
  31949. self.buildPaintImageXObject({
  31950. resources,
  31951. image: xobj,
  31952. operatorList,
  31953. cacheKey: name,
  31954. localImageCache,
  31955. localColorSpaceCache
  31956. }).then(resolveXObject, rejectXObject);
  31957. return;
  31958. } else if (type.name === "PS") {
  31959. info("Ignored XObject subtype PS");
  31960. } else {
  31961. throw new FormatError(`Unhandled XObject subtype ${type.name}`);
  31962. }
  31963. resolveXObject();
  31964. }).catch(function (reason) {
  31965. if (reason instanceof AbortException) {
  31966. return;
  31967. }
  31968. if (self.options.ignoreErrors) {
  31969. warn(`getOperatorList - ignoring XObject: "${reason}".`);
  31970. return;
  31971. }
  31972. throw reason;
  31973. }));
  31974. return;
  31975. case OPS.setFont:
  31976. var fontSize = args[1];
  31977. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state, fallbackFontDict).then(function (loadedName) {
  31978. operatorList.addDependency(loadedName);
  31979. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  31980. }));
  31981. return;
  31982. case OPS.beginText:
  31983. parsingText = true;
  31984. break;
  31985. case OPS.endText:
  31986. parsingText = false;
  31987. break;
  31988. case OPS.endInlineImage:
  31989. var cacheKey = args[0].cacheKey;
  31990. if (cacheKey) {
  31991. const localImage = localImageCache.getByName(cacheKey);
  31992. if (localImage) {
  31993. operatorList.addImageOps(localImage.fn, localImage.args, localImage.optionalContent);
  31994. incrementCachedImageMaskCount(localImage);
  31995. args = null;
  31996. continue;
  31997. }
  31998. }
  31999. next(self.buildPaintImageXObject({
  32000. resources,
  32001. image: args[0],
  32002. isInline: true,
  32003. operatorList,
  32004. cacheKey,
  32005. localImageCache,
  32006. localColorSpaceCache
  32007. }));
  32008. return;
  32009. case OPS.showText:
  32010. if (!stateManager.state.font) {
  32011. self.ensureStateFont(stateManager.state);
  32012. continue;
  32013. }
  32014. args[0] = self.handleText(args[0], stateManager.state);
  32015. break;
  32016. case OPS.showSpacedText:
  32017. if (!stateManager.state.font) {
  32018. self.ensureStateFont(stateManager.state);
  32019. continue;
  32020. }
  32021. var combinedGlyphs = [];
  32022. var state = stateManager.state;
  32023. for (const arrItem of args[0]) {
  32024. if (typeof arrItem === "string") {
  32025. combinedGlyphs.push(...self.handleText(arrItem, state));
  32026. } else if (typeof arrItem === "number") {
  32027. combinedGlyphs.push(arrItem);
  32028. }
  32029. }
  32030. args[0] = combinedGlyphs;
  32031. fn = OPS.showText;
  32032. break;
  32033. case OPS.nextLineShowText:
  32034. if (!stateManager.state.font) {
  32035. self.ensureStateFont(stateManager.state);
  32036. continue;
  32037. }
  32038. operatorList.addOp(OPS.nextLine);
  32039. args[0] = self.handleText(args[0], stateManager.state);
  32040. fn = OPS.showText;
  32041. break;
  32042. case OPS.nextLineSetSpacingShowText:
  32043. if (!stateManager.state.font) {
  32044. self.ensureStateFont(stateManager.state);
  32045. continue;
  32046. }
  32047. operatorList.addOp(OPS.nextLine);
  32048. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  32049. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  32050. args[0] = self.handleText(args[0], stateManager.state);
  32051. fn = OPS.showText;
  32052. break;
  32053. case OPS.setTextRenderingMode:
  32054. stateManager.state.textRenderingMode = args[0];
  32055. break;
  32056. case OPS.setFillColorSpace:
  32057. {
  32058. const cachedColorSpace = ColorSpace.getCached(args[0], xref, localColorSpaceCache);
  32059. if (cachedColorSpace) {
  32060. stateManager.state.fillColorSpace = cachedColorSpace;
  32061. continue;
  32062. }
  32063. next(self.parseColorSpace({
  32064. cs: args[0],
  32065. resources,
  32066. localColorSpaceCache
  32067. }).then(function (colorSpace) {
  32068. if (colorSpace) {
  32069. stateManager.state.fillColorSpace = colorSpace;
  32070. }
  32071. }));
  32072. return;
  32073. }
  32074. case OPS.setStrokeColorSpace:
  32075. {
  32076. const cachedColorSpace = ColorSpace.getCached(args[0], xref, localColorSpaceCache);
  32077. if (cachedColorSpace) {
  32078. stateManager.state.strokeColorSpace = cachedColorSpace;
  32079. continue;
  32080. }
  32081. next(self.parseColorSpace({
  32082. cs: args[0],
  32083. resources,
  32084. localColorSpaceCache
  32085. }).then(function (colorSpace) {
  32086. if (colorSpace) {
  32087. stateManager.state.strokeColorSpace = colorSpace;
  32088. }
  32089. }));
  32090. return;
  32091. }
  32092. case OPS.setFillColor:
  32093. cs = stateManager.state.fillColorSpace;
  32094. args = cs.getRgb(args, 0);
  32095. fn = OPS.setFillRGBColor;
  32096. break;
  32097. case OPS.setStrokeColor:
  32098. cs = stateManager.state.strokeColorSpace;
  32099. args = cs.getRgb(args, 0);
  32100. fn = OPS.setStrokeRGBColor;
  32101. break;
  32102. case OPS.setFillGray:
  32103. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  32104. args = ColorSpace.singletons.gray.getRgb(args, 0);
  32105. fn = OPS.setFillRGBColor;
  32106. break;
  32107. case OPS.setStrokeGray:
  32108. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  32109. args = ColorSpace.singletons.gray.getRgb(args, 0);
  32110. fn = OPS.setStrokeRGBColor;
  32111. break;
  32112. case OPS.setFillCMYKColor:
  32113. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  32114. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  32115. fn = OPS.setFillRGBColor;
  32116. break;
  32117. case OPS.setStrokeCMYKColor:
  32118. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  32119. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  32120. fn = OPS.setStrokeRGBColor;
  32121. break;
  32122. case OPS.setFillRGBColor:
  32123. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  32124. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  32125. break;
  32126. case OPS.setStrokeRGBColor:
  32127. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  32128. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  32129. break;
  32130. case OPS.setFillColorN:
  32131. cs = stateManager.state.fillColorSpace;
  32132. if (cs.name === "Pattern") {
  32133. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache));
  32134. return;
  32135. }
  32136. args = cs.getRgb(args, 0);
  32137. fn = OPS.setFillRGBColor;
  32138. break;
  32139. case OPS.setStrokeColorN:
  32140. cs = stateManager.state.strokeColorSpace;
  32141. if (cs.name === "Pattern") {
  32142. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, localColorSpaceCache, localTilingPatternCache, localShadingPatternCache));
  32143. return;
  32144. }
  32145. args = cs.getRgb(args, 0);
  32146. fn = OPS.setStrokeRGBColor;
  32147. break;
  32148. case OPS.shadingFill:
  32149. var shadingRes = resources.get("Shading");
  32150. if (!shadingRes) {
  32151. throw new FormatError("No shading resource found");
  32152. }
  32153. var shading = shadingRes.get(args[0].name);
  32154. if (!shading) {
  32155. throw new FormatError("No shading object found");
  32156. }
  32157. const patternId = self.parseShading({
  32158. shading,
  32159. resources,
  32160. localColorSpaceCache,
  32161. localShadingPatternCache
  32162. });
  32163. args = [patternId];
  32164. fn = OPS.shadingFill;
  32165. break;
  32166. case OPS.setGState:
  32167. isValidName = args[0] instanceof Name;
  32168. name = args[0].name;
  32169. if (isValidName) {
  32170. const localGStateObj = localGStateCache.getByName(name);
  32171. if (localGStateObj) {
  32172. if (localGStateObj.length > 0) {
  32173. operatorList.addOp(OPS.setGState, [localGStateObj]);
  32174. }
  32175. args = null;
  32176. continue;
  32177. }
  32178. }
  32179. next(new Promise(function (resolveGState, rejectGState) {
  32180. if (!isValidName) {
  32181. throw new FormatError("GState must be referred to by name.");
  32182. }
  32183. const extGState = resources.get("ExtGState");
  32184. if (!(extGState instanceof Dict)) {
  32185. throw new FormatError("ExtGState should be a dictionary.");
  32186. }
  32187. const gState = extGState.get(name);
  32188. if (!(gState instanceof Dict)) {
  32189. throw new FormatError("GState should be a dictionary.");
  32190. }
  32191. self.setGState({
  32192. resources,
  32193. gState,
  32194. operatorList,
  32195. cacheKey: name,
  32196. task,
  32197. stateManager,
  32198. localGStateCache,
  32199. localColorSpaceCache
  32200. }).then(resolveGState, rejectGState);
  32201. }).catch(function (reason) {
  32202. if (reason instanceof AbortException) {
  32203. return;
  32204. }
  32205. if (self.options.ignoreErrors) {
  32206. warn(`getOperatorList - ignoring ExtGState: "${reason}".`);
  32207. return;
  32208. }
  32209. throw reason;
  32210. }));
  32211. return;
  32212. case OPS.moveTo:
  32213. case OPS.lineTo:
  32214. case OPS.curveTo:
  32215. case OPS.curveTo2:
  32216. case OPS.curveTo3:
  32217. case OPS.closePath:
  32218. case OPS.rectangle:
  32219. self.buildPath(operatorList, fn, args, parsingText);
  32220. continue;
  32221. case OPS.markPoint:
  32222. case OPS.markPointProps:
  32223. case OPS.beginCompat:
  32224. case OPS.endCompat:
  32225. continue;
  32226. case OPS.beginMarkedContentProps:
  32227. if (!(args[0] instanceof Name)) {
  32228. warn(`Expected name for beginMarkedContentProps arg0=${args[0]}`);
  32229. continue;
  32230. }
  32231. if (args[0].name === "OC") {
  32232. next(self.parseMarkedContentProps(args[1], resources).then(data => {
  32233. operatorList.addOp(OPS.beginMarkedContentProps, ["OC", data]);
  32234. }).catch(reason => {
  32235. if (reason instanceof AbortException) {
  32236. return;
  32237. }
  32238. if (self.options.ignoreErrors) {
  32239. warn(`getOperatorList - ignoring beginMarkedContentProps: "${reason}".`);
  32240. return;
  32241. }
  32242. throw reason;
  32243. }));
  32244. return;
  32245. }
  32246. args = [args[0].name, args[1] instanceof Dict ? args[1].get("MCID") : null];
  32247. break;
  32248. case OPS.beginMarkedContent:
  32249. case OPS.endMarkedContent:
  32250. default:
  32251. if (args !== null) {
  32252. for (i = 0, ii = args.length; i < ii; i++) {
  32253. if (args[i] instanceof Dict) {
  32254. break;
  32255. }
  32256. }
  32257. if (i < ii) {
  32258. warn("getOperatorList - ignoring operator: " + fn);
  32259. continue;
  32260. }
  32261. }
  32262. }
  32263. operatorList.addOp(fn, args);
  32264. }
  32265. if (stop) {
  32266. next(deferred);
  32267. return;
  32268. }
  32269. closePendingRestoreOPS();
  32270. resolve();
  32271. }).catch(reason => {
  32272. if (reason instanceof AbortException) {
  32273. return;
  32274. }
  32275. if (this.options.ignoreErrors) {
  32276. warn(`getOperatorList - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
  32277. closePendingRestoreOPS();
  32278. return;
  32279. }
  32280. throw reason;
  32281. });
  32282. }
  32283. getTextContent({
  32284. stream,
  32285. task,
  32286. resources,
  32287. stateManager = null,
  32288. includeMarkedContent = false,
  32289. sink,
  32290. seenStyles = new Set(),
  32291. viewBox,
  32292. markedContentData = null,
  32293. disableNormalization = false
  32294. }) {
  32295. resources ||= Dict.empty;
  32296. stateManager ||= new StateManager(new TextState());
  32297. if (includeMarkedContent) {
  32298. markedContentData ||= {
  32299. level: 0
  32300. };
  32301. }
  32302. const textContent = {
  32303. items: [],
  32304. styles: Object.create(null)
  32305. };
  32306. const textContentItem = {
  32307. initialized: false,
  32308. str: [],
  32309. totalWidth: 0,
  32310. totalHeight: 0,
  32311. width: 0,
  32312. height: 0,
  32313. vertical: false,
  32314. prevTransform: null,
  32315. textAdvanceScale: 0,
  32316. spaceInFlowMin: 0,
  32317. spaceInFlowMax: 0,
  32318. trackingSpaceMin: Infinity,
  32319. negativeSpaceMax: -Infinity,
  32320. notASpace: -Infinity,
  32321. transform: null,
  32322. fontName: null,
  32323. hasEOL: false
  32324. };
  32325. const twoLastChars = [" ", " "];
  32326. let twoLastCharsPos = 0;
  32327. function saveLastChar(char) {
  32328. const nextPos = (twoLastCharsPos + 1) % 2;
  32329. const ret = twoLastChars[twoLastCharsPos] !== " " && twoLastChars[nextPos] === " ";
  32330. twoLastChars[twoLastCharsPos] = char;
  32331. twoLastCharsPos = nextPos;
  32332. return ret;
  32333. }
  32334. function shouldAddWhitepsace() {
  32335. return twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " ";
  32336. }
  32337. function resetLastChars() {
  32338. twoLastChars[0] = twoLastChars[1] = " ";
  32339. twoLastCharsPos = 0;
  32340. }
  32341. const TRACKING_SPACE_FACTOR = 0.102;
  32342. const NOT_A_SPACE_FACTOR = 0.03;
  32343. const NEGATIVE_SPACE_FACTOR = -0.2;
  32344. const SPACE_IN_FLOW_MIN_FACTOR = 0.102;
  32345. const SPACE_IN_FLOW_MAX_FACTOR = 0.6;
  32346. const VERTICAL_SHIFT_RATIO = 0.25;
  32347. const self = this;
  32348. const xref = this.xref;
  32349. const showSpacedTextBuffer = [];
  32350. let xobjs = null;
  32351. const emptyXObjectCache = new LocalImageCache();
  32352. const emptyGStateCache = new LocalGStateCache();
  32353. const preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  32354. let textState;
  32355. function pushWhitespace({
  32356. width = 0,
  32357. height = 0,
  32358. transform = textContentItem.prevTransform,
  32359. fontName = textContentItem.fontName
  32360. }) {
  32361. textContent.items.push({
  32362. str: " ",
  32363. dir: "ltr",
  32364. width,
  32365. height,
  32366. transform,
  32367. fontName,
  32368. hasEOL: false
  32369. });
  32370. }
  32371. function getCurrentTextTransform() {
  32372. const font = textState.font;
  32373. const tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise];
  32374. if (font.isType3Font && (textState.fontSize <= 1 || font.isCharBBox) && !isArrayEqual(textState.fontMatrix, FONT_IDENTITY_MATRIX)) {
  32375. const glyphHeight = font.bbox[3] - font.bbox[1];
  32376. if (glyphHeight > 0) {
  32377. tsm[3] *= glyphHeight * textState.fontMatrix[3];
  32378. }
  32379. }
  32380. return Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  32381. }
  32382. function ensureTextContentItem() {
  32383. if (textContentItem.initialized) {
  32384. return textContentItem;
  32385. }
  32386. const {
  32387. font,
  32388. loadedName
  32389. } = textState;
  32390. if (!seenStyles.has(loadedName)) {
  32391. seenStyles.add(loadedName);
  32392. textContent.styles[loadedName] = {
  32393. fontFamily: font.fallbackName,
  32394. ascent: font.ascent,
  32395. descent: font.descent,
  32396. vertical: font.vertical
  32397. };
  32398. if (self.options.fontExtraProperties && font.systemFontInfo) {
  32399. const style = textContent.styles[loadedName];
  32400. style.fontSubstitution = font.systemFontInfo.css;
  32401. style.fontSubstitutionLoadedName = font.systemFontInfo.loadedName;
  32402. }
  32403. }
  32404. textContentItem.fontName = loadedName;
  32405. const trm = textContentItem.transform = getCurrentTextTransform();
  32406. if (!font.vertical) {
  32407. textContentItem.width = textContentItem.totalWidth = 0;
  32408. textContentItem.height = textContentItem.totalHeight = Math.hypot(trm[2], trm[3]);
  32409. textContentItem.vertical = false;
  32410. } else {
  32411. textContentItem.width = textContentItem.totalWidth = Math.hypot(trm[0], trm[1]);
  32412. textContentItem.height = textContentItem.totalHeight = 0;
  32413. textContentItem.vertical = true;
  32414. }
  32415. const scaleLineX = Math.hypot(textState.textLineMatrix[0], textState.textLineMatrix[1]);
  32416. const scaleCtmX = Math.hypot(textState.ctm[0], textState.ctm[1]);
  32417. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  32418. const {
  32419. fontSize
  32420. } = textState;
  32421. textContentItem.trackingSpaceMin = fontSize * TRACKING_SPACE_FACTOR;
  32422. textContentItem.notASpace = fontSize * NOT_A_SPACE_FACTOR;
  32423. textContentItem.negativeSpaceMax = fontSize * NEGATIVE_SPACE_FACTOR;
  32424. textContentItem.spaceInFlowMin = fontSize * SPACE_IN_FLOW_MIN_FACTOR;
  32425. textContentItem.spaceInFlowMax = fontSize * SPACE_IN_FLOW_MAX_FACTOR;
  32426. textContentItem.hasEOL = false;
  32427. textContentItem.initialized = true;
  32428. return textContentItem;
  32429. }
  32430. function updateAdvanceScale() {
  32431. if (!textContentItem.initialized) {
  32432. return;
  32433. }
  32434. const scaleLineX = Math.hypot(textState.textLineMatrix[0], textState.textLineMatrix[1]);
  32435. const scaleCtmX = Math.hypot(textState.ctm[0], textState.ctm[1]);
  32436. const scaleFactor = scaleCtmX * scaleLineX;
  32437. if (scaleFactor === textContentItem.textAdvanceScale) {
  32438. return;
  32439. }
  32440. if (!textContentItem.vertical) {
  32441. textContentItem.totalWidth += textContentItem.width * textContentItem.textAdvanceScale;
  32442. textContentItem.width = 0;
  32443. } else {
  32444. textContentItem.totalHeight += textContentItem.height * textContentItem.textAdvanceScale;
  32445. textContentItem.height = 0;
  32446. }
  32447. textContentItem.textAdvanceScale = scaleFactor;
  32448. }
  32449. function runBidiTransform(textChunk) {
  32450. let text = textChunk.str.join("");
  32451. if (!disableNormalization) {
  32452. text = normalizeUnicode(text);
  32453. }
  32454. const bidiResult = bidi(text, -1, textChunk.vertical);
  32455. return {
  32456. str: bidiResult.str,
  32457. dir: bidiResult.dir,
  32458. width: Math.abs(textChunk.totalWidth),
  32459. height: Math.abs(textChunk.totalHeight),
  32460. transform: textChunk.transform,
  32461. fontName: textChunk.fontName,
  32462. hasEOL: textChunk.hasEOL
  32463. };
  32464. }
  32465. function handleSetFont(fontName, fontRef) {
  32466. return self.loadFont(fontName, fontRef, resources).then(function (translated) {
  32467. if (!translated.font.isType3Font) {
  32468. return translated;
  32469. }
  32470. return translated.loadType3Data(self, resources, task).catch(function () {}).then(function () {
  32471. return translated;
  32472. });
  32473. }).then(function (translated) {
  32474. textState.loadedName = translated.loadedName;
  32475. textState.font = translated.font;
  32476. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  32477. });
  32478. }
  32479. function applyInverseRotation(x, y, matrix) {
  32480. const scale = Math.hypot(matrix[0], matrix[1]);
  32481. return [(matrix[0] * x + matrix[1] * y) / scale, (matrix[2] * x + matrix[3] * y) / scale];
  32482. }
  32483. function compareWithLastPosition(glyphWidth) {
  32484. const currentTransform = getCurrentTextTransform();
  32485. let posX = currentTransform[4];
  32486. let posY = currentTransform[5];
  32487. if (textState.font?.vertical) {
  32488. if (posX < viewBox[0] || posX > viewBox[2] || posY + glyphWidth < viewBox[1] || posY > viewBox[3]) {
  32489. return false;
  32490. }
  32491. } else if (posX + glyphWidth < viewBox[0] || posX > viewBox[2] || posY < viewBox[1] || posY > viewBox[3]) {
  32492. return false;
  32493. }
  32494. if (!textState.font || !textContentItem.prevTransform) {
  32495. return true;
  32496. }
  32497. let lastPosX = textContentItem.prevTransform[4];
  32498. let lastPosY = textContentItem.prevTransform[5];
  32499. if (lastPosX === posX && lastPosY === posY) {
  32500. return true;
  32501. }
  32502. let rotate = -1;
  32503. if (currentTransform[0] && currentTransform[1] === 0 && currentTransform[2] === 0) {
  32504. rotate = currentTransform[0] > 0 ? 0 : 180;
  32505. } else if (currentTransform[1] && currentTransform[0] === 0 && currentTransform[3] === 0) {
  32506. rotate = currentTransform[1] > 0 ? 90 : 270;
  32507. }
  32508. switch (rotate) {
  32509. case 0:
  32510. break;
  32511. case 90:
  32512. [posX, posY] = [posY, posX];
  32513. [lastPosX, lastPosY] = [lastPosY, lastPosX];
  32514. break;
  32515. case 180:
  32516. [posX, posY, lastPosX, lastPosY] = [-posX, -posY, -lastPosX, -lastPosY];
  32517. break;
  32518. case 270:
  32519. [posX, posY] = [-posY, -posX];
  32520. [lastPosX, lastPosY] = [-lastPosY, -lastPosX];
  32521. break;
  32522. default:
  32523. [posX, posY] = applyInverseRotation(posX, posY, currentTransform);
  32524. [lastPosX, lastPosY] = applyInverseRotation(lastPosX, lastPosY, textContentItem.prevTransform);
  32525. }
  32526. if (textState.font.vertical) {
  32527. const advanceY = (lastPosY - posY) / textContentItem.textAdvanceScale;
  32528. const advanceX = posX - lastPosX;
  32529. const textOrientation = Math.sign(textContentItem.height);
  32530. if (advanceY < textOrientation * textContentItem.negativeSpaceMax) {
  32531. if (Math.abs(advanceX) > 0.5 * textContentItem.width) {
  32532. appendEOL();
  32533. return true;
  32534. }
  32535. resetLastChars();
  32536. flushTextContentItem();
  32537. return true;
  32538. }
  32539. if (Math.abs(advanceX) > textContentItem.width) {
  32540. appendEOL();
  32541. return true;
  32542. }
  32543. if (advanceY <= textOrientation * textContentItem.notASpace) {
  32544. resetLastChars();
  32545. }
  32546. if (advanceY <= textOrientation * textContentItem.trackingSpaceMin) {
  32547. if (shouldAddWhitepsace()) {
  32548. resetLastChars();
  32549. flushTextContentItem();
  32550. pushWhitespace({
  32551. height: Math.abs(advanceY)
  32552. });
  32553. } else {
  32554. textContentItem.height += advanceY;
  32555. }
  32556. } else if (!addFakeSpaces(advanceY, textContentItem.prevTransform, textOrientation)) {
  32557. if (textContentItem.str.length === 0) {
  32558. resetLastChars();
  32559. pushWhitespace({
  32560. height: Math.abs(advanceY)
  32561. });
  32562. } else {
  32563. textContentItem.height += advanceY;
  32564. }
  32565. }
  32566. if (Math.abs(advanceX) > textContentItem.width * VERTICAL_SHIFT_RATIO) {
  32567. flushTextContentItem();
  32568. }
  32569. return true;
  32570. }
  32571. const advanceX = (posX - lastPosX) / textContentItem.textAdvanceScale;
  32572. const advanceY = posY - lastPosY;
  32573. const textOrientation = Math.sign(textContentItem.width);
  32574. if (advanceX < textOrientation * textContentItem.negativeSpaceMax) {
  32575. if (Math.abs(advanceY) > 0.5 * textContentItem.height) {
  32576. appendEOL();
  32577. return true;
  32578. }
  32579. resetLastChars();
  32580. flushTextContentItem();
  32581. return true;
  32582. }
  32583. if (Math.abs(advanceY) > textContentItem.height) {
  32584. appendEOL();
  32585. return true;
  32586. }
  32587. if (advanceX <= textOrientation * textContentItem.notASpace) {
  32588. resetLastChars();
  32589. }
  32590. if (advanceX <= textOrientation * textContentItem.trackingSpaceMin) {
  32591. if (shouldAddWhitepsace()) {
  32592. resetLastChars();
  32593. flushTextContentItem();
  32594. pushWhitespace({
  32595. width: Math.abs(advanceX)
  32596. });
  32597. } else {
  32598. textContentItem.width += advanceX;
  32599. }
  32600. } else if (!addFakeSpaces(advanceX, textContentItem.prevTransform, textOrientation)) {
  32601. if (textContentItem.str.length === 0) {
  32602. resetLastChars();
  32603. pushWhitespace({
  32604. width: Math.abs(advanceX)
  32605. });
  32606. } else {
  32607. textContentItem.width += advanceX;
  32608. }
  32609. }
  32610. if (Math.abs(advanceY) > textContentItem.height * VERTICAL_SHIFT_RATIO) {
  32611. flushTextContentItem();
  32612. }
  32613. return true;
  32614. }
  32615. function buildTextContentItem({
  32616. chars,
  32617. extraSpacing
  32618. }) {
  32619. const font = textState.font;
  32620. if (!chars) {
  32621. const charSpacing = textState.charSpacing + extraSpacing;
  32622. if (charSpacing) {
  32623. if (!font.vertical) {
  32624. textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
  32625. } else {
  32626. textState.translateTextMatrix(0, -charSpacing);
  32627. }
  32628. }
  32629. return;
  32630. }
  32631. const glyphs = font.charsToGlyphs(chars);
  32632. const scale = textState.fontMatrix[0] * textState.fontSize;
  32633. for (let i = 0, ii = glyphs.length; i < ii; i++) {
  32634. const glyph = glyphs[i];
  32635. const {
  32636. category
  32637. } = glyph;
  32638. if (category.isInvisibleFormatMark) {
  32639. continue;
  32640. }
  32641. let charSpacing = textState.charSpacing + (i + 1 === ii ? extraSpacing : 0);
  32642. let glyphWidth = glyph.width;
  32643. if (font.vertical) {
  32644. glyphWidth = glyph.vmetric ? glyph.vmetric[0] : -glyphWidth;
  32645. }
  32646. let scaledDim = glyphWidth * scale;
  32647. if (category.isWhitespace) {
  32648. if (!font.vertical) {
  32649. charSpacing += scaledDim + textState.wordSpacing;
  32650. textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
  32651. } else {
  32652. charSpacing += -scaledDim + textState.wordSpacing;
  32653. textState.translateTextMatrix(0, -charSpacing);
  32654. }
  32655. saveLastChar(" ");
  32656. continue;
  32657. }
  32658. if (!category.isZeroWidthDiacritic && !compareWithLastPosition(scaledDim)) {
  32659. if (!font.vertical) {
  32660. textState.translateTextMatrix(scaledDim * textState.textHScale, 0);
  32661. } else {
  32662. textState.translateTextMatrix(0, scaledDim);
  32663. }
  32664. continue;
  32665. }
  32666. const textChunk = ensureTextContentItem();
  32667. if (category.isZeroWidthDiacritic) {
  32668. scaledDim = 0;
  32669. }
  32670. if (!font.vertical) {
  32671. scaledDim *= textState.textHScale;
  32672. textState.translateTextMatrix(scaledDim, 0);
  32673. textChunk.width += scaledDim;
  32674. } else {
  32675. textState.translateTextMatrix(0, scaledDim);
  32676. scaledDim = Math.abs(scaledDim);
  32677. textChunk.height += scaledDim;
  32678. }
  32679. if (scaledDim) {
  32680. textChunk.prevTransform = getCurrentTextTransform();
  32681. }
  32682. const glyphUnicode = glyph.unicode;
  32683. if (saveLastChar(glyphUnicode)) {
  32684. textChunk.str.push(" ");
  32685. }
  32686. textChunk.str.push(glyphUnicode);
  32687. if (charSpacing) {
  32688. if (!font.vertical) {
  32689. textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
  32690. } else {
  32691. textState.translateTextMatrix(0, -charSpacing);
  32692. }
  32693. }
  32694. }
  32695. }
  32696. function appendEOL() {
  32697. resetLastChars();
  32698. if (textContentItem.initialized) {
  32699. textContentItem.hasEOL = true;
  32700. flushTextContentItem();
  32701. } else {
  32702. textContent.items.push({
  32703. str: "",
  32704. dir: "ltr",
  32705. width: 0,
  32706. height: 0,
  32707. transform: getCurrentTextTransform(),
  32708. fontName: textState.loadedName,
  32709. hasEOL: true
  32710. });
  32711. }
  32712. }
  32713. function addFakeSpaces(width, transf, textOrientation) {
  32714. if (textOrientation * textContentItem.spaceInFlowMin <= width && width <= textOrientation * textContentItem.spaceInFlowMax) {
  32715. if (textContentItem.initialized) {
  32716. resetLastChars();
  32717. textContentItem.str.push(" ");
  32718. }
  32719. return false;
  32720. }
  32721. const fontName = textContentItem.fontName;
  32722. let height = 0;
  32723. if (textContentItem.vertical) {
  32724. height = width;
  32725. width = 0;
  32726. }
  32727. flushTextContentItem();
  32728. resetLastChars();
  32729. pushWhitespace({
  32730. width: Math.abs(width),
  32731. height: Math.abs(height),
  32732. transform: transf || getCurrentTextTransform(),
  32733. fontName
  32734. });
  32735. return true;
  32736. }
  32737. function flushTextContentItem() {
  32738. if (!textContentItem.initialized || !textContentItem.str) {
  32739. return;
  32740. }
  32741. if (!textContentItem.vertical) {
  32742. textContentItem.totalWidth += textContentItem.width * textContentItem.textAdvanceScale;
  32743. } else {
  32744. textContentItem.totalHeight += textContentItem.height * textContentItem.textAdvanceScale;
  32745. }
  32746. textContent.items.push(runBidiTransform(textContentItem));
  32747. textContentItem.initialized = false;
  32748. textContentItem.str.length = 0;
  32749. }
  32750. function enqueueChunk(batch = false) {
  32751. const length = textContent.items.length;
  32752. if (length === 0) {
  32753. return;
  32754. }
  32755. if (batch && length < TEXT_CHUNK_BATCH_SIZE) {
  32756. return;
  32757. }
  32758. sink.enqueue(textContent, length);
  32759. textContent.items = [];
  32760. textContent.styles = Object.create(null);
  32761. }
  32762. const timeSlotManager = new TimeSlotManager();
  32763. return new Promise(function promiseBody(resolve, reject) {
  32764. const next = function (promise) {
  32765. enqueueChunk(true);
  32766. Promise.all([promise, sink.ready]).then(function () {
  32767. try {
  32768. promiseBody(resolve, reject);
  32769. } catch (ex) {
  32770. reject(ex);
  32771. }
  32772. }, reject);
  32773. };
  32774. task.ensureNotTerminated();
  32775. timeSlotManager.reset();
  32776. const operation = {};
  32777. let stop,
  32778. args = [];
  32779. while (!(stop = timeSlotManager.check())) {
  32780. args.length = 0;
  32781. operation.args = args;
  32782. if (!preprocessor.read(operation)) {
  32783. break;
  32784. }
  32785. const previousState = textState;
  32786. textState = stateManager.state;
  32787. const fn = operation.fn;
  32788. args = operation.args;
  32789. switch (fn | 0) {
  32790. case OPS.setFont:
  32791. var fontNameArg = args[0].name,
  32792. fontSizeArg = args[1];
  32793. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  32794. break;
  32795. }
  32796. flushTextContentItem();
  32797. textState.fontName = fontNameArg;
  32798. textState.fontSize = fontSizeArg;
  32799. next(handleSetFont(fontNameArg, null));
  32800. return;
  32801. case OPS.setTextRise:
  32802. textState.textRise = args[0];
  32803. break;
  32804. case OPS.setHScale:
  32805. textState.textHScale = args[0] / 100;
  32806. break;
  32807. case OPS.setLeading:
  32808. textState.leading = args[0];
  32809. break;
  32810. case OPS.moveText:
  32811. textState.translateTextLineMatrix(args[0], args[1]);
  32812. textState.textMatrix = textState.textLineMatrix.slice();
  32813. break;
  32814. case OPS.setLeadingMoveText:
  32815. textState.leading = -args[1];
  32816. textState.translateTextLineMatrix(args[0], args[1]);
  32817. textState.textMatrix = textState.textLineMatrix.slice();
  32818. break;
  32819. case OPS.nextLine:
  32820. textState.carriageReturn();
  32821. break;
  32822. case OPS.setTextMatrix:
  32823. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  32824. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  32825. updateAdvanceScale();
  32826. break;
  32827. case OPS.setCharSpacing:
  32828. textState.charSpacing = args[0];
  32829. break;
  32830. case OPS.setWordSpacing:
  32831. textState.wordSpacing = args[0];
  32832. break;
  32833. case OPS.beginText:
  32834. textState.textMatrix = IDENTITY_MATRIX.slice();
  32835. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  32836. break;
  32837. case OPS.showSpacedText:
  32838. if (!stateManager.state.font) {
  32839. self.ensureStateFont(stateManager.state);
  32840. continue;
  32841. }
  32842. const spaceFactor = (textState.font.vertical ? 1 : -1) * textState.fontSize / 1000;
  32843. const elements = args[0];
  32844. for (let i = 0, ii = elements.length; i < ii; i++) {
  32845. const item = elements[i];
  32846. if (typeof item === "string") {
  32847. showSpacedTextBuffer.push(item);
  32848. } else if (typeof item === "number" && item !== 0) {
  32849. const str = showSpacedTextBuffer.join("");
  32850. showSpacedTextBuffer.length = 0;
  32851. buildTextContentItem({
  32852. chars: str,
  32853. extraSpacing: item * spaceFactor
  32854. });
  32855. }
  32856. }
  32857. if (showSpacedTextBuffer.length > 0) {
  32858. const str = showSpacedTextBuffer.join("");
  32859. showSpacedTextBuffer.length = 0;
  32860. buildTextContentItem({
  32861. chars: str,
  32862. extraSpacing: 0
  32863. });
  32864. }
  32865. break;
  32866. case OPS.showText:
  32867. if (!stateManager.state.font) {
  32868. self.ensureStateFont(stateManager.state);
  32869. continue;
  32870. }
  32871. buildTextContentItem({
  32872. chars: args[0],
  32873. extraSpacing: 0
  32874. });
  32875. break;
  32876. case OPS.nextLineShowText:
  32877. if (!stateManager.state.font) {
  32878. self.ensureStateFont(stateManager.state);
  32879. continue;
  32880. }
  32881. textState.carriageReturn();
  32882. buildTextContentItem({
  32883. chars: args[0],
  32884. extraSpacing: 0
  32885. });
  32886. break;
  32887. case OPS.nextLineSetSpacingShowText:
  32888. if (!stateManager.state.font) {
  32889. self.ensureStateFont(stateManager.state);
  32890. continue;
  32891. }
  32892. textState.wordSpacing = args[0];
  32893. textState.charSpacing = args[1];
  32894. textState.carriageReturn();
  32895. buildTextContentItem({
  32896. chars: args[2],
  32897. extraSpacing: 0
  32898. });
  32899. break;
  32900. case OPS.paintXObject:
  32901. flushTextContentItem();
  32902. if (!xobjs) {
  32903. xobjs = resources.get("XObject") || Dict.empty;
  32904. }
  32905. var isValidName = args[0] instanceof Name;
  32906. var name = args[0].name;
  32907. if (isValidName && emptyXObjectCache.getByName(name)) {
  32908. break;
  32909. }
  32910. next(new Promise(function (resolveXObject, rejectXObject) {
  32911. if (!isValidName) {
  32912. throw new FormatError("XObject must be referred to by name.");
  32913. }
  32914. let xobj = xobjs.getRaw(name);
  32915. if (xobj instanceof Ref) {
  32916. if (emptyXObjectCache.getByRef(xobj)) {
  32917. resolveXObject();
  32918. return;
  32919. }
  32920. const globalImage = self.globalImageCache.getData(xobj, self.pageIndex);
  32921. if (globalImage) {
  32922. resolveXObject();
  32923. return;
  32924. }
  32925. xobj = xref.fetch(xobj);
  32926. }
  32927. if (!(xobj instanceof BaseStream)) {
  32928. throw new FormatError("XObject should be a stream");
  32929. }
  32930. const type = xobj.dict.get("Subtype");
  32931. if (!(type instanceof Name)) {
  32932. throw new FormatError("XObject should have a Name subtype");
  32933. }
  32934. if (type.name !== "Form") {
  32935. emptyXObjectCache.set(name, xobj.dict.objId, true);
  32936. resolveXObject();
  32937. return;
  32938. }
  32939. const currentState = stateManager.state.clone();
  32940. const xObjStateManager = new StateManager(currentState);
  32941. const matrix = xobj.dict.getArray("Matrix");
  32942. if (Array.isArray(matrix) && matrix.length === 6) {
  32943. xObjStateManager.transform(matrix);
  32944. }
  32945. enqueueChunk();
  32946. const sinkWrapper = {
  32947. enqueueInvoked: false,
  32948. enqueue(chunk, size) {
  32949. this.enqueueInvoked = true;
  32950. sink.enqueue(chunk, size);
  32951. },
  32952. get desiredSize() {
  32953. return sink.desiredSize;
  32954. },
  32955. get ready() {
  32956. return sink.ready;
  32957. }
  32958. };
  32959. self.getTextContent({
  32960. stream: xobj,
  32961. task,
  32962. resources: xobj.dict.get("Resources") || resources,
  32963. stateManager: xObjStateManager,
  32964. includeMarkedContent,
  32965. sink: sinkWrapper,
  32966. seenStyles,
  32967. viewBox,
  32968. markedContentData,
  32969. disableNormalization
  32970. }).then(function () {
  32971. if (!sinkWrapper.enqueueInvoked) {
  32972. emptyXObjectCache.set(name, xobj.dict.objId, true);
  32973. }
  32974. resolveXObject();
  32975. }, rejectXObject);
  32976. }).catch(function (reason) {
  32977. if (reason instanceof AbortException) {
  32978. return;
  32979. }
  32980. if (self.options.ignoreErrors) {
  32981. warn(`getTextContent - ignoring XObject: "${reason}".`);
  32982. return;
  32983. }
  32984. throw reason;
  32985. }));
  32986. return;
  32987. case OPS.setGState:
  32988. isValidName = args[0] instanceof Name;
  32989. name = args[0].name;
  32990. if (isValidName && emptyGStateCache.getByName(name)) {
  32991. break;
  32992. }
  32993. next(new Promise(function (resolveGState, rejectGState) {
  32994. if (!isValidName) {
  32995. throw new FormatError("GState must be referred to by name.");
  32996. }
  32997. const extGState = resources.get("ExtGState");
  32998. if (!(extGState instanceof Dict)) {
  32999. throw new FormatError("ExtGState should be a dictionary.");
  33000. }
  33001. const gState = extGState.get(name);
  33002. if (!(gState instanceof Dict)) {
  33003. throw new FormatError("GState should be a dictionary.");
  33004. }
  33005. const gStateFont = gState.get("Font");
  33006. if (!gStateFont) {
  33007. emptyGStateCache.set(name, gState.objId, true);
  33008. resolveGState();
  33009. return;
  33010. }
  33011. flushTextContentItem();
  33012. textState.fontName = null;
  33013. textState.fontSize = gStateFont[1];
  33014. handleSetFont(null, gStateFont[0]).then(resolveGState, rejectGState);
  33015. }).catch(function (reason) {
  33016. if (reason instanceof AbortException) {
  33017. return;
  33018. }
  33019. if (self.options.ignoreErrors) {
  33020. warn(`getTextContent - ignoring ExtGState: "${reason}".`);
  33021. return;
  33022. }
  33023. throw reason;
  33024. }));
  33025. return;
  33026. case OPS.beginMarkedContent:
  33027. flushTextContentItem();
  33028. if (includeMarkedContent) {
  33029. markedContentData.level++;
  33030. textContent.items.push({
  33031. type: "beginMarkedContent",
  33032. tag: args[0] instanceof Name ? args[0].name : null
  33033. });
  33034. }
  33035. break;
  33036. case OPS.beginMarkedContentProps:
  33037. flushTextContentItem();
  33038. if (includeMarkedContent) {
  33039. markedContentData.level++;
  33040. let mcid = null;
  33041. if (args[1] instanceof Dict) {
  33042. mcid = args[1].get("MCID");
  33043. }
  33044. textContent.items.push({
  33045. type: "beginMarkedContentProps",
  33046. id: Number.isInteger(mcid) ? `${self.idFactory.getPageObjId()}_mc${mcid}` : null,
  33047. tag: args[0] instanceof Name ? args[0].name : null
  33048. });
  33049. }
  33050. break;
  33051. case OPS.endMarkedContent:
  33052. flushTextContentItem();
  33053. if (includeMarkedContent) {
  33054. if (markedContentData.level === 0) {
  33055. break;
  33056. }
  33057. markedContentData.level--;
  33058. textContent.items.push({
  33059. type: "endMarkedContent"
  33060. });
  33061. }
  33062. break;
  33063. case OPS.restore:
  33064. if (previousState && (previousState.font !== textState.font || previousState.fontSize !== textState.fontSize || previousState.fontName !== textState.fontName)) {
  33065. flushTextContentItem();
  33066. }
  33067. break;
  33068. }
  33069. if (textContent.items.length >= sink.desiredSize) {
  33070. stop = true;
  33071. break;
  33072. }
  33073. }
  33074. if (stop) {
  33075. next(deferred);
  33076. return;
  33077. }
  33078. flushTextContentItem();
  33079. enqueueChunk();
  33080. resolve();
  33081. }).catch(reason => {
  33082. if (reason instanceof AbortException) {
  33083. return;
  33084. }
  33085. if (this.options.ignoreErrors) {
  33086. warn(`getTextContent - ignoring errors during "${task.name}" ` + `task: "${reason}".`);
  33087. flushTextContentItem();
  33088. enqueueChunk();
  33089. return;
  33090. }
  33091. throw reason;
  33092. });
  33093. }
  33094. extractDataStructures(dict, baseDict, properties) {
  33095. const xref = this.xref;
  33096. let cidToGidBytes;
  33097. const toUnicodePromise = this.readToUnicode(properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode"));
  33098. if (properties.composite) {
  33099. const cidSystemInfo = dict.get("CIDSystemInfo");
  33100. if (cidSystemInfo instanceof Dict) {
  33101. properties.cidSystemInfo = {
  33102. registry: stringToPDFString(cidSystemInfo.get("Registry")),
  33103. ordering: stringToPDFString(cidSystemInfo.get("Ordering")),
  33104. supplement: cidSystemInfo.get("Supplement")
  33105. };
  33106. }
  33107. try {
  33108. const cidToGidMap = dict.get("CIDToGIDMap");
  33109. if (cidToGidMap instanceof BaseStream) {
  33110. cidToGidBytes = cidToGidMap.getBytes();
  33111. }
  33112. } catch (ex) {
  33113. if (!this.options.ignoreErrors) {
  33114. throw ex;
  33115. }
  33116. warn(`extractDataStructures - ignoring CIDToGIDMap data: "${ex}".`);
  33117. }
  33118. }
  33119. const differences = [];
  33120. let baseEncodingName = null;
  33121. let encoding;
  33122. if (dict.has("Encoding")) {
  33123. encoding = dict.get("Encoding");
  33124. if (encoding instanceof Dict) {
  33125. baseEncodingName = encoding.get("BaseEncoding");
  33126. baseEncodingName = baseEncodingName instanceof Name ? baseEncodingName.name : null;
  33127. if (encoding.has("Differences")) {
  33128. const diffEncoding = encoding.get("Differences");
  33129. let index = 0;
  33130. for (const entry of diffEncoding) {
  33131. const data = xref.fetchIfRef(entry);
  33132. if (typeof data === "number") {
  33133. index = data;
  33134. } else if (data instanceof Name) {
  33135. differences[index++] = data.name;
  33136. } else {
  33137. throw new FormatError(`Invalid entry in 'Differences' array: ${data}`);
  33138. }
  33139. }
  33140. }
  33141. } else if (encoding instanceof Name) {
  33142. baseEncodingName = encoding.name;
  33143. } else {
  33144. const msg = "Encoding is not a Name nor a Dict";
  33145. if (!this.options.ignoreErrors) {
  33146. throw new FormatError(msg);
  33147. }
  33148. warn(msg);
  33149. }
  33150. if (baseEncodingName !== "MacRomanEncoding" && baseEncodingName !== "MacExpertEncoding" && baseEncodingName !== "WinAnsiEncoding") {
  33151. baseEncodingName = null;
  33152. }
  33153. }
  33154. const nonEmbeddedFont = !properties.file || properties.isInternalFont,
  33155. isSymbolsFontName = getSymbolsFonts()[properties.name];
  33156. if (baseEncodingName && nonEmbeddedFont && isSymbolsFontName) {
  33157. baseEncodingName = null;
  33158. }
  33159. if (baseEncodingName) {
  33160. properties.defaultEncoding = getEncoding(baseEncodingName);
  33161. } else {
  33162. const isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  33163. const isNonsymbolicFont = !!(properties.flags & FontFlags.Nonsymbolic);
  33164. encoding = StandardEncoding;
  33165. if (properties.type === "TrueType" && !isNonsymbolicFont) {
  33166. encoding = WinAnsiEncoding;
  33167. }
  33168. if (isSymbolicFont || isSymbolsFontName) {
  33169. encoding = MacRomanEncoding;
  33170. if (nonEmbeddedFont) {
  33171. if (/Symbol/i.test(properties.name)) {
  33172. encoding = SymbolSetEncoding;
  33173. } else if (/Dingbats/i.test(properties.name)) {
  33174. encoding = ZapfDingbatsEncoding;
  33175. } else if (/Wingdings/i.test(properties.name)) {
  33176. encoding = WinAnsiEncoding;
  33177. }
  33178. }
  33179. }
  33180. properties.defaultEncoding = encoding;
  33181. }
  33182. properties.differences = differences;
  33183. properties.baseEncodingName = baseEncodingName;
  33184. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  33185. properties.dict = dict;
  33186. return toUnicodePromise.then(readToUnicode => {
  33187. properties.toUnicode = readToUnicode;
  33188. return this.buildToUnicode(properties);
  33189. }).then(builtToUnicode => {
  33190. properties.toUnicode = builtToUnicode;
  33191. if (cidToGidBytes) {
  33192. properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode);
  33193. }
  33194. return properties;
  33195. });
  33196. }
  33197. _simpleFontToUnicode(properties, forceGlyphs = false) {
  33198. assert(!properties.composite, "Must be a simple font.");
  33199. const toUnicode = [];
  33200. const encoding = properties.defaultEncoding.slice();
  33201. const baseEncodingName = properties.baseEncodingName;
  33202. const differences = properties.differences;
  33203. for (const charcode in differences) {
  33204. const glyphName = differences[charcode];
  33205. if (glyphName === ".notdef") {
  33206. continue;
  33207. }
  33208. encoding[charcode] = glyphName;
  33209. }
  33210. const glyphsUnicodeMap = getGlyphsUnicode();
  33211. for (const charcode in encoding) {
  33212. let glyphName = encoding[charcode];
  33213. if (glyphName === "") {
  33214. continue;
  33215. }
  33216. let unicode = glyphsUnicodeMap[glyphName];
  33217. if (unicode !== undefined) {
  33218. toUnicode[charcode] = String.fromCharCode(unicode);
  33219. continue;
  33220. }
  33221. let code = 0;
  33222. switch (glyphName[0]) {
  33223. case "G":
  33224. if (glyphName.length === 3) {
  33225. code = parseInt(glyphName.substring(1), 16);
  33226. }
  33227. break;
  33228. case "g":
  33229. if (glyphName.length === 5) {
  33230. code = parseInt(glyphName.substring(1), 16);
  33231. }
  33232. break;
  33233. case "C":
  33234. case "c":
  33235. if (glyphName.length >= 3 && glyphName.length <= 4) {
  33236. const codeStr = glyphName.substring(1);
  33237. if (forceGlyphs) {
  33238. code = parseInt(codeStr, 16);
  33239. break;
  33240. }
  33241. code = +codeStr;
  33242. if (Number.isNaN(code) && Number.isInteger(parseInt(codeStr, 16))) {
  33243. return this._simpleFontToUnicode(properties, true);
  33244. }
  33245. }
  33246. break;
  33247. case "u":
  33248. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  33249. if (unicode !== -1) {
  33250. code = unicode;
  33251. }
  33252. break;
  33253. default:
  33254. switch (glyphName) {
  33255. case "f_h":
  33256. case "f_t":
  33257. case "T_h":
  33258. toUnicode[charcode] = glyphName.replaceAll("_", "");
  33259. continue;
  33260. }
  33261. break;
  33262. }
  33263. if (code > 0 && code <= 0x10ffff && Number.isInteger(code)) {
  33264. if (baseEncodingName && code === +charcode) {
  33265. const baseEncoding = getEncoding(baseEncodingName);
  33266. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  33267. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  33268. continue;
  33269. }
  33270. }
  33271. toUnicode[charcode] = String.fromCodePoint(code);
  33272. }
  33273. }
  33274. return toUnicode;
  33275. }
  33276. async buildToUnicode(properties) {
  33277. properties.hasIncludedToUnicodeMap = properties.toUnicode?.length > 0;
  33278. if (properties.hasIncludedToUnicodeMap) {
  33279. if (!properties.composite && properties.hasEncoding) {
  33280. properties.fallbackToUnicode = this._simpleFontToUnicode(properties);
  33281. }
  33282. return properties.toUnicode;
  33283. }
  33284. if (!properties.composite) {
  33285. return new ToUnicodeMap(this._simpleFontToUnicode(properties));
  33286. }
  33287. 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"))) {
  33288. const {
  33289. registry,
  33290. ordering
  33291. } = properties.cidSystemInfo;
  33292. const ucs2CMapName = Name.get(`${registry}-${ordering}-UCS2`);
  33293. const ucs2CMap = await CMapFactory.create({
  33294. encoding: ucs2CMapName,
  33295. fetchBuiltInCMap: this._fetchBuiltInCMapBound,
  33296. useCMap: null
  33297. });
  33298. const toUnicode = [],
  33299. buf = [];
  33300. properties.cMap.forEach(function (charcode, cid) {
  33301. if (cid > 0xffff) {
  33302. throw new FormatError("Max size of CID is 65,535");
  33303. }
  33304. const ucs2 = ucs2CMap.lookup(cid);
  33305. if (ucs2) {
  33306. buf.length = 0;
  33307. for (let i = 0, ii = ucs2.length; i < ii; i += 2) {
  33308. buf.push((ucs2.charCodeAt(i) << 8) + ucs2.charCodeAt(i + 1));
  33309. }
  33310. toUnicode[charcode] = String.fromCharCode(...buf);
  33311. }
  33312. });
  33313. return new ToUnicodeMap(toUnicode);
  33314. }
  33315. return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
  33316. }
  33317. readToUnicode(cmapObj) {
  33318. if (!cmapObj) {
  33319. return Promise.resolve(null);
  33320. }
  33321. if (cmapObj instanceof Name) {
  33322. return CMapFactory.create({
  33323. encoding: cmapObj,
  33324. fetchBuiltInCMap: this._fetchBuiltInCMapBound,
  33325. useCMap: null
  33326. }).then(function (cmap) {
  33327. if (cmap instanceof IdentityCMap) {
  33328. return new IdentityToUnicodeMap(0, 0xffff);
  33329. }
  33330. return new ToUnicodeMap(cmap.getMap());
  33331. });
  33332. } else if (cmapObj instanceof BaseStream) {
  33333. return CMapFactory.create({
  33334. encoding: cmapObj,
  33335. fetchBuiltInCMap: this._fetchBuiltInCMapBound,
  33336. useCMap: null
  33337. }).then(function (cmap) {
  33338. if (cmap instanceof IdentityCMap) {
  33339. return new IdentityToUnicodeMap(0, 0xffff);
  33340. }
  33341. const map = new Array(cmap.length);
  33342. cmap.forEach(function (charCode, token) {
  33343. if (typeof token === "number") {
  33344. map[charCode] = String.fromCodePoint(token);
  33345. return;
  33346. }
  33347. const str = [];
  33348. for (let k = 0; k < token.length; k += 2) {
  33349. const w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  33350. if ((w1 & 0xf800) !== 0xd800) {
  33351. str.push(w1);
  33352. continue;
  33353. }
  33354. k += 2;
  33355. const w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  33356. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  33357. }
  33358. map[charCode] = String.fromCodePoint(...str);
  33359. });
  33360. return new ToUnicodeMap(map);
  33361. }, reason => {
  33362. if (reason instanceof AbortException) {
  33363. return null;
  33364. }
  33365. if (this.options.ignoreErrors) {
  33366. warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`);
  33367. return null;
  33368. }
  33369. throw reason;
  33370. });
  33371. }
  33372. return Promise.resolve(null);
  33373. }
  33374. readCidToGidMap(glyphsData, toUnicode) {
  33375. const result = [];
  33376. for (let j = 0, jj = glyphsData.length; j < jj; j++) {
  33377. const glyphID = glyphsData[j++] << 8 | glyphsData[j];
  33378. const code = j >> 1;
  33379. if (glyphID === 0 && !toUnicode.has(code)) {
  33380. continue;
  33381. }
  33382. result[code] = glyphID;
  33383. }
  33384. return result;
  33385. }
  33386. extractWidths(dict, descriptor, properties) {
  33387. const xref = this.xref;
  33388. let glyphsWidths = [];
  33389. let defaultWidth = 0;
  33390. const glyphsVMetrics = [];
  33391. let defaultVMetrics;
  33392. let i, ii, j, jj, start, code, widths;
  33393. if (properties.composite) {
  33394. defaultWidth = dict.has("DW") ? dict.get("DW") : 1000;
  33395. widths = dict.get("W");
  33396. if (widths) {
  33397. for (i = 0, ii = widths.length; i < ii; i++) {
  33398. start = xref.fetchIfRef(widths[i++]);
  33399. code = xref.fetchIfRef(widths[i]);
  33400. if (Array.isArray(code)) {
  33401. for (j = 0, jj = code.length; j < jj; j++) {
  33402. glyphsWidths[start++] = xref.fetchIfRef(code[j]);
  33403. }
  33404. } else {
  33405. const width = xref.fetchIfRef(widths[++i]);
  33406. for (j = start; j <= code; j++) {
  33407. glyphsWidths[j] = width;
  33408. }
  33409. }
  33410. }
  33411. }
  33412. if (properties.vertical) {
  33413. let vmetrics = dict.getArray("DW2") || [880, -1000];
  33414. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  33415. vmetrics = dict.get("W2");
  33416. if (vmetrics) {
  33417. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  33418. start = xref.fetchIfRef(vmetrics[i++]);
  33419. code = xref.fetchIfRef(vmetrics[i]);
  33420. if (Array.isArray(code)) {
  33421. for (j = 0, jj = code.length; j < jj; j++) {
  33422. glyphsVMetrics[start++] = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])];
  33423. }
  33424. } else {
  33425. const vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])];
  33426. for (j = start; j <= code; j++) {
  33427. glyphsVMetrics[j] = vmetric;
  33428. }
  33429. }
  33430. }
  33431. }
  33432. }
  33433. } else {
  33434. const firstChar = properties.firstChar;
  33435. widths = dict.get("Widths");
  33436. if (widths) {
  33437. j = firstChar;
  33438. for (i = 0, ii = widths.length; i < ii; i++) {
  33439. glyphsWidths[j++] = xref.fetchIfRef(widths[i]);
  33440. }
  33441. defaultWidth = parseFloat(descriptor.get("MissingWidth")) || 0;
  33442. } else {
  33443. const baseFontName = dict.get("BaseFont");
  33444. if (baseFontName instanceof Name) {
  33445. const metrics = this.getBaseFontMetrics(baseFontName.name);
  33446. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  33447. defaultWidth = metrics.defaultWidth;
  33448. }
  33449. }
  33450. }
  33451. let isMonospace = true;
  33452. let firstWidth = defaultWidth;
  33453. for (const glyph in glyphsWidths) {
  33454. const glyphWidth = glyphsWidths[glyph];
  33455. if (!glyphWidth) {
  33456. continue;
  33457. }
  33458. if (!firstWidth) {
  33459. firstWidth = glyphWidth;
  33460. continue;
  33461. }
  33462. if (firstWidth !== glyphWidth) {
  33463. isMonospace = false;
  33464. break;
  33465. }
  33466. }
  33467. if (isMonospace) {
  33468. properties.flags |= FontFlags.FixedPitch;
  33469. } else {
  33470. properties.flags &= ~FontFlags.FixedPitch;
  33471. }
  33472. properties.defaultWidth = defaultWidth;
  33473. properties.widths = glyphsWidths;
  33474. properties.defaultVMetrics = defaultVMetrics;
  33475. properties.vmetrics = glyphsVMetrics;
  33476. }
  33477. isSerifFont(baseFontName) {
  33478. const fontNameWoStyle = baseFontName.split("-")[0];
  33479. return fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle);
  33480. }
  33481. getBaseFontMetrics(name) {
  33482. let defaultWidth = 0;
  33483. let widths = Object.create(null);
  33484. let monospace = false;
  33485. const stdFontMap = getStdFontMap();
  33486. let lookupName = stdFontMap[name] || name;
  33487. const Metrics = getMetrics();
  33488. if (!(lookupName in Metrics)) {
  33489. lookupName = this.isSerifFont(name) ? "Times-Roman" : "Helvetica";
  33490. }
  33491. const glyphWidths = Metrics[lookupName];
  33492. if (typeof glyphWidths === "number") {
  33493. defaultWidth = glyphWidths;
  33494. monospace = true;
  33495. } else {
  33496. widths = glyphWidths();
  33497. }
  33498. return {
  33499. defaultWidth,
  33500. monospace,
  33501. widths
  33502. };
  33503. }
  33504. buildCharCodeToWidth(widthsByGlyphName, properties) {
  33505. const widths = Object.create(null);
  33506. const differences = properties.differences;
  33507. const encoding = properties.defaultEncoding;
  33508. for (let charCode = 0; charCode < 256; charCode++) {
  33509. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  33510. widths[charCode] = widthsByGlyphName[differences[charCode]];
  33511. continue;
  33512. }
  33513. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  33514. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  33515. continue;
  33516. }
  33517. }
  33518. return widths;
  33519. }
  33520. preEvaluateFont(dict) {
  33521. const baseDict = dict;
  33522. let type = dict.get("Subtype");
  33523. if (!(type instanceof Name)) {
  33524. throw new FormatError("invalid font Subtype");
  33525. }
  33526. let composite = false;
  33527. let hash, toUnicode;
  33528. if (type.name === "Type0") {
  33529. const df = dict.get("DescendantFonts");
  33530. if (!df) {
  33531. throw new FormatError("Descendant fonts are not specified");
  33532. }
  33533. dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;
  33534. if (!(dict instanceof Dict)) {
  33535. throw new FormatError("Descendant font is not a dictionary.");
  33536. }
  33537. type = dict.get("Subtype");
  33538. if (!(type instanceof Name)) {
  33539. throw new FormatError("invalid font Subtype");
  33540. }
  33541. composite = true;
  33542. }
  33543. const firstChar = dict.get("FirstChar") || 0,
  33544. lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
  33545. const descriptor = dict.get("FontDescriptor");
  33546. if (descriptor) {
  33547. hash = new MurmurHash3_64();
  33548. const encoding = baseDict.getRaw("Encoding");
  33549. if (encoding instanceof Name) {
  33550. hash.update(encoding.name);
  33551. } else if (encoding instanceof Ref) {
  33552. hash.update(encoding.toString());
  33553. } else if (encoding instanceof Dict) {
  33554. for (const entry of encoding.getRawValues()) {
  33555. if (entry instanceof Name) {
  33556. hash.update(entry.name);
  33557. } else if (entry instanceof Ref) {
  33558. hash.update(entry.toString());
  33559. } else if (Array.isArray(entry)) {
  33560. const diffLength = entry.length,
  33561. diffBuf = new Array(diffLength);
  33562. for (let j = 0; j < diffLength; j++) {
  33563. const diffEntry = entry[j];
  33564. if (diffEntry instanceof Name) {
  33565. diffBuf[j] = diffEntry.name;
  33566. } else if (typeof diffEntry === "number" || diffEntry instanceof Ref) {
  33567. diffBuf[j] = diffEntry.toString();
  33568. }
  33569. }
  33570. hash.update(diffBuf.join());
  33571. }
  33572. }
  33573. }
  33574. hash.update(`${firstChar}-${lastChar}`);
  33575. toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
  33576. if (toUnicode instanceof BaseStream) {
  33577. const stream = toUnicode.str || toUnicode;
  33578. const uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  33579. hash.update(uint8array);
  33580. } else if (toUnicode instanceof Name) {
  33581. hash.update(toUnicode.name);
  33582. }
  33583. const widths = dict.get("Widths") || baseDict.get("Widths");
  33584. if (Array.isArray(widths)) {
  33585. const widthsBuf = [];
  33586. for (const entry of widths) {
  33587. if (typeof entry === "number" || entry instanceof Ref) {
  33588. widthsBuf.push(entry.toString());
  33589. }
  33590. }
  33591. hash.update(widthsBuf.join());
  33592. }
  33593. if (composite) {
  33594. hash.update("compositeFont");
  33595. const compositeWidths = dict.get("W") || baseDict.get("W");
  33596. if (Array.isArray(compositeWidths)) {
  33597. const widthsBuf = [];
  33598. for (const entry of compositeWidths) {
  33599. if (typeof entry === "number" || entry instanceof Ref) {
  33600. widthsBuf.push(entry.toString());
  33601. } else if (Array.isArray(entry)) {
  33602. const subWidthsBuf = [];
  33603. for (const element of entry) {
  33604. if (typeof element === "number" || element instanceof Ref) {
  33605. subWidthsBuf.push(element.toString());
  33606. }
  33607. }
  33608. widthsBuf.push(`[${subWidthsBuf.join()}]`);
  33609. }
  33610. }
  33611. hash.update(widthsBuf.join());
  33612. }
  33613. const cidToGidMap = dict.getRaw("CIDToGIDMap") || baseDict.getRaw("CIDToGIDMap");
  33614. if (cidToGidMap instanceof Name) {
  33615. hash.update(cidToGidMap.name);
  33616. } else if (cidToGidMap instanceof Ref) {
  33617. hash.update(cidToGidMap.toString());
  33618. } else if (cidToGidMap instanceof BaseStream) {
  33619. hash.update(cidToGidMap.peekBytes());
  33620. }
  33621. }
  33622. }
  33623. return {
  33624. descriptor,
  33625. dict,
  33626. baseDict,
  33627. composite,
  33628. type: type.name,
  33629. firstChar,
  33630. lastChar,
  33631. toUnicode,
  33632. hash: hash ? hash.hexdigest() : ""
  33633. };
  33634. }
  33635. async translateFont({
  33636. descriptor,
  33637. dict,
  33638. baseDict,
  33639. composite,
  33640. type,
  33641. firstChar,
  33642. lastChar,
  33643. toUnicode,
  33644. cssFontInfo
  33645. }) {
  33646. const isType3Font = type === "Type3";
  33647. let properties;
  33648. if (!descriptor) {
  33649. if (isType3Font) {
  33650. descriptor = new Dict(null);
  33651. descriptor.set("FontName", Name.get(type));
  33652. descriptor.set("FontBBox", dict.getArray("FontBBox") || [0, 0, 0, 0]);
  33653. } else {
  33654. let baseFontName = dict.get("BaseFont");
  33655. if (!(baseFontName instanceof Name)) {
  33656. throw new FormatError("Base font is not specified");
  33657. }
  33658. baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-");
  33659. const metrics = this.getBaseFontMetrics(baseFontName);
  33660. const fontNameWoStyle = baseFontName.split("-")[0];
  33661. const flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  33662. properties = {
  33663. type,
  33664. name: baseFontName,
  33665. loadedName: baseDict.loadedName,
  33666. systemFontInfo: null,
  33667. widths: metrics.widths,
  33668. defaultWidth: metrics.defaultWidth,
  33669. isSimulatedFlags: true,
  33670. flags,
  33671. firstChar,
  33672. lastChar,
  33673. toUnicode,
  33674. xHeight: 0,
  33675. capHeight: 0,
  33676. italicAngle: 0,
  33677. isType3Font
  33678. };
  33679. const widths = dict.get("Widths");
  33680. const standardFontName = getStandardFontName(baseFontName);
  33681. let file = null;
  33682. if (standardFontName) {
  33683. file = await this.fetchStandardFontData(standardFontName);
  33684. properties.isInternalFont = !!file;
  33685. }
  33686. if (!properties.isInternalFont && this.options.useSystemFonts) {
  33687. properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName);
  33688. }
  33689. return this.extractDataStructures(dict, dict, properties).then(newProperties => {
  33690. if (widths) {
  33691. const glyphWidths = [];
  33692. let j = firstChar;
  33693. for (const width of widths) {
  33694. glyphWidths[j++] = this.xref.fetchIfRef(width);
  33695. }
  33696. newProperties.widths = glyphWidths;
  33697. } else {
  33698. newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties);
  33699. }
  33700. return new Font(baseFontName, file, newProperties);
  33701. });
  33702. }
  33703. }
  33704. let fontName = descriptor.get("FontName");
  33705. let baseFont = dict.get("BaseFont");
  33706. if (typeof fontName === "string") {
  33707. fontName = Name.get(fontName);
  33708. }
  33709. if (typeof baseFont === "string") {
  33710. baseFont = Name.get(baseFont);
  33711. }
  33712. const fontNameStr = fontName?.name;
  33713. const baseFontStr = baseFont?.name;
  33714. if (!isType3Font && fontNameStr !== baseFontStr) {
  33715. info(`The FontDescriptor's FontName is "${fontNameStr}" but ` + `should be the same as the Font's BaseFont "${baseFontStr}".`);
  33716. if (fontNameStr && baseFontStr && (baseFontStr.startsWith(fontNameStr) || !isKnownFontName(fontNameStr) && isKnownFontName(baseFontStr))) {
  33717. fontName = null;
  33718. }
  33719. }
  33720. fontName ||= baseFont;
  33721. if (!(fontName instanceof Name)) {
  33722. throw new FormatError("invalid font name");
  33723. }
  33724. let fontFile, subtype, length1, length2, length3;
  33725. try {
  33726. fontFile = descriptor.get("FontFile", "FontFile2", "FontFile3");
  33727. } catch (ex) {
  33728. if (!this.options.ignoreErrors) {
  33729. throw ex;
  33730. }
  33731. warn(`translateFont - fetching "${fontName.name}" font file: "${ex}".`);
  33732. fontFile = new NullStream();
  33733. }
  33734. let isInternalFont = false;
  33735. let glyphScaleFactors = null;
  33736. let systemFontInfo = null;
  33737. if (fontFile) {
  33738. if (fontFile.dict) {
  33739. const subtypeEntry = fontFile.dict.get("Subtype");
  33740. if (subtypeEntry instanceof Name) {
  33741. subtype = subtypeEntry.name;
  33742. }
  33743. length1 = fontFile.dict.get("Length1");
  33744. length2 = fontFile.dict.get("Length2");
  33745. length3 = fontFile.dict.get("Length3");
  33746. }
  33747. } else if (cssFontInfo) {
  33748. const standardFontName = getXfaFontName(fontName.name);
  33749. if (standardFontName) {
  33750. cssFontInfo.fontFamily = `${cssFontInfo.fontFamily}-PdfJS-XFA`;
  33751. cssFontInfo.metrics = standardFontName.metrics || null;
  33752. glyphScaleFactors = standardFontName.factors || null;
  33753. fontFile = await this.fetchStandardFontData(standardFontName.name);
  33754. isInternalFont = !!fontFile;
  33755. baseDict = dict = getXfaFontDict(fontName.name);
  33756. composite = true;
  33757. }
  33758. } else if (!isType3Font) {
  33759. const standardFontName = getStandardFontName(fontName.name);
  33760. if (standardFontName) {
  33761. fontFile = await this.fetchStandardFontData(standardFontName);
  33762. isInternalFont = !!fontFile;
  33763. }
  33764. if (!isInternalFont && this.options.useSystemFonts) {
  33765. systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName);
  33766. }
  33767. }
  33768. properties = {
  33769. type,
  33770. name: fontName.name,
  33771. subtype,
  33772. file: fontFile,
  33773. length1,
  33774. length2,
  33775. length3,
  33776. isInternalFont,
  33777. loadedName: baseDict.loadedName,
  33778. composite,
  33779. fixedPitch: false,
  33780. fontMatrix: dict.getArray("FontMatrix") || FONT_IDENTITY_MATRIX,
  33781. firstChar,
  33782. lastChar,
  33783. toUnicode,
  33784. bbox: descriptor.getArray("FontBBox") || dict.getArray("FontBBox"),
  33785. ascent: descriptor.get("Ascent"),
  33786. descent: descriptor.get("Descent"),
  33787. xHeight: descriptor.get("XHeight") || 0,
  33788. capHeight: descriptor.get("CapHeight") || 0,
  33789. flags: descriptor.get("Flags"),
  33790. italicAngle: descriptor.get("ItalicAngle") || 0,
  33791. isType3Font,
  33792. cssFontInfo,
  33793. scaleFactors: glyphScaleFactors,
  33794. systemFontInfo
  33795. };
  33796. if (composite) {
  33797. const cidEncoding = baseDict.get("Encoding");
  33798. if (cidEncoding instanceof Name) {
  33799. properties.cidEncoding = cidEncoding.name;
  33800. }
  33801. const cMap = await CMapFactory.create({
  33802. encoding: cidEncoding,
  33803. fetchBuiltInCMap: this._fetchBuiltInCMapBound,
  33804. useCMap: null
  33805. });
  33806. properties.cMap = cMap;
  33807. properties.vertical = properties.cMap.vertical;
  33808. }
  33809. return this.extractDataStructures(dict, baseDict, properties).then(newProperties => {
  33810. this.extractWidths(dict, descriptor, newProperties);
  33811. return new Font(fontName.name, fontFile, newProperties);
  33812. });
  33813. }
  33814. static buildFontPaths(font, glyphs, handler, evaluatorOptions) {
  33815. function buildPath(fontChar) {
  33816. const glyphName = `${font.loadedName}_path_${fontChar}`;
  33817. try {
  33818. if (font.renderer.hasBuiltPath(fontChar)) {
  33819. return;
  33820. }
  33821. handler.send("commonobj", [glyphName, "FontPath", font.renderer.getPathJs(fontChar)]);
  33822. } catch (reason) {
  33823. if (evaluatorOptions.ignoreErrors) {
  33824. warn(`buildFontPaths - ignoring ${glyphName} glyph: "${reason}".`);
  33825. return;
  33826. }
  33827. throw reason;
  33828. }
  33829. }
  33830. for (const glyph of glyphs) {
  33831. buildPath(glyph.fontChar);
  33832. const accent = glyph.accent;
  33833. if (accent?.fontChar) {
  33834. buildPath(accent.fontChar);
  33835. }
  33836. }
  33837. }
  33838. static get fallbackFontDict() {
  33839. const dict = new Dict();
  33840. dict.set("BaseFont", Name.get("Helvetica"));
  33841. dict.set("Type", Name.get("FallbackType"));
  33842. dict.set("Subtype", Name.get("FallbackType"));
  33843. dict.set("Encoding", Name.get("WinAnsiEncoding"));
  33844. return shadow(this, "fallbackFontDict", dict);
  33845. }
  33846. }
  33847. class TranslatedFont {
  33848. constructor({
  33849. loadedName,
  33850. font,
  33851. dict,
  33852. evaluatorOptions
  33853. }) {
  33854. this.loadedName = loadedName;
  33855. this.font = font;
  33856. this.dict = dict;
  33857. this._evaluatorOptions = evaluatorOptions || DefaultPartialEvaluatorOptions;
  33858. this.type3Loaded = null;
  33859. this.type3Dependencies = font.isType3Font ? new Set() : null;
  33860. this.sent = false;
  33861. }
  33862. send(handler) {
  33863. if (this.sent) {
  33864. return;
  33865. }
  33866. this.sent = true;
  33867. handler.send("commonobj", [this.loadedName, "Font", this.font.exportData(this._evaluatorOptions.fontExtraProperties)]);
  33868. }
  33869. fallback(handler) {
  33870. if (!this.font.data) {
  33871. return;
  33872. }
  33873. this.font.disableFontFace = true;
  33874. PartialEvaluator.buildFontPaths(this.font, this.font.glyphCacheValues, handler, this._evaluatorOptions);
  33875. }
  33876. loadType3Data(evaluator, resources, task) {
  33877. if (this.type3Loaded) {
  33878. return this.type3Loaded;
  33879. }
  33880. if (!this.font.isType3Font) {
  33881. throw new Error("Must be a Type3 font.");
  33882. }
  33883. const type3Evaluator = evaluator.clone({
  33884. ignoreErrors: false
  33885. });
  33886. type3Evaluator.parsingType3Font = true;
  33887. const type3FontRefs = new RefSet(evaluator.type3FontRefs);
  33888. if (this.dict.objId && !type3FontRefs.has(this.dict.objId)) {
  33889. type3FontRefs.put(this.dict.objId);
  33890. }
  33891. type3Evaluator.type3FontRefs = type3FontRefs;
  33892. const translatedFont = this.font,
  33893. type3Dependencies = this.type3Dependencies;
  33894. let loadCharProcsPromise = Promise.resolve();
  33895. const charProcs = this.dict.get("CharProcs");
  33896. const fontResources = this.dict.get("Resources") || resources;
  33897. const charProcOperatorList = Object.create(null);
  33898. const fontBBox = Util.normalizeRect(translatedFont.bbox || [0, 0, 0, 0]),
  33899. width = fontBBox[2] - fontBBox[0],
  33900. height = fontBBox[3] - fontBBox[1];
  33901. const fontBBoxSize = Math.hypot(width, height);
  33902. for (const key of charProcs.getKeys()) {
  33903. loadCharProcsPromise = loadCharProcsPromise.then(() => {
  33904. const glyphStream = charProcs.get(key);
  33905. const operatorList = new OperatorList();
  33906. return type3Evaluator.getOperatorList({
  33907. stream: glyphStream,
  33908. task,
  33909. resources: fontResources,
  33910. operatorList
  33911. }).then(() => {
  33912. if (operatorList.fnArray[0] === OPS.setCharWidthAndBounds) {
  33913. this._removeType3ColorOperators(operatorList, fontBBoxSize);
  33914. }
  33915. charProcOperatorList[key] = operatorList.getIR();
  33916. for (const dependency of operatorList.dependencies) {
  33917. type3Dependencies.add(dependency);
  33918. }
  33919. }).catch(function (reason) {
  33920. warn(`Type3 font resource "${key}" is not available.`);
  33921. const dummyOperatorList = new OperatorList();
  33922. charProcOperatorList[key] = dummyOperatorList.getIR();
  33923. });
  33924. });
  33925. }
  33926. this.type3Loaded = loadCharProcsPromise.then(() => {
  33927. translatedFont.charProcOperatorList = charProcOperatorList;
  33928. if (this._bbox) {
  33929. translatedFont.isCharBBox = true;
  33930. translatedFont.bbox = this._bbox;
  33931. }
  33932. });
  33933. return this.type3Loaded;
  33934. }
  33935. _removeType3ColorOperators(operatorList, fontBBoxSize = NaN) {
  33936. const charBBox = Util.normalizeRect(operatorList.argsArray[0].slice(2)),
  33937. width = charBBox[2] - charBBox[0],
  33938. height = charBBox[3] - charBBox[1];
  33939. const charBBoxSize = Math.hypot(width, height);
  33940. if (width === 0 || height === 0) {
  33941. operatorList.fnArray.splice(0, 1);
  33942. operatorList.argsArray.splice(0, 1);
  33943. } else if (fontBBoxSize === 0 || Math.round(charBBoxSize / fontBBoxSize) >= 10) {
  33944. if (!this._bbox) {
  33945. this._bbox = [Infinity, Infinity, -Infinity, -Infinity];
  33946. }
  33947. this._bbox[0] = Math.min(this._bbox[0], charBBox[0]);
  33948. this._bbox[1] = Math.min(this._bbox[1], charBBox[1]);
  33949. this._bbox[2] = Math.max(this._bbox[2], charBBox[2]);
  33950. this._bbox[3] = Math.max(this._bbox[3], charBBox[3]);
  33951. }
  33952. let i = 0,
  33953. ii = operatorList.length;
  33954. while (i < ii) {
  33955. switch (operatorList.fnArray[i]) {
  33956. case OPS.setCharWidthAndBounds:
  33957. break;
  33958. case OPS.setStrokeColorSpace:
  33959. case OPS.setFillColorSpace:
  33960. case OPS.setStrokeColor:
  33961. case OPS.setStrokeColorN:
  33962. case OPS.setFillColor:
  33963. case OPS.setFillColorN:
  33964. case OPS.setStrokeGray:
  33965. case OPS.setFillGray:
  33966. case OPS.setStrokeRGBColor:
  33967. case OPS.setFillRGBColor:
  33968. case OPS.setStrokeCMYKColor:
  33969. case OPS.setFillCMYKColor:
  33970. case OPS.shadingFill:
  33971. case OPS.setRenderingIntent:
  33972. operatorList.fnArray.splice(i, 1);
  33973. operatorList.argsArray.splice(i, 1);
  33974. ii--;
  33975. continue;
  33976. case OPS.setGState:
  33977. const [gStateObj] = operatorList.argsArray[i];
  33978. let j = 0,
  33979. jj = gStateObj.length;
  33980. while (j < jj) {
  33981. const [gStateKey] = gStateObj[j];
  33982. switch (gStateKey) {
  33983. case "TR":
  33984. case "TR2":
  33985. case "HT":
  33986. case "BG":
  33987. case "BG2":
  33988. case "UCR":
  33989. case "UCR2":
  33990. gStateObj.splice(j, 1);
  33991. jj--;
  33992. continue;
  33993. }
  33994. j++;
  33995. }
  33996. break;
  33997. }
  33998. i++;
  33999. }
  34000. }
  34001. }
  34002. class StateManager {
  34003. constructor(initialState = new EvalState()) {
  34004. this.state = initialState;
  34005. this.stateStack = [];
  34006. }
  34007. save() {
  34008. const old = this.state;
  34009. this.stateStack.push(this.state);
  34010. this.state = old.clone();
  34011. }
  34012. restore() {
  34013. const prev = this.stateStack.pop();
  34014. if (prev) {
  34015. this.state = prev;
  34016. }
  34017. }
  34018. transform(args) {
  34019. this.state.ctm = Util.transform(this.state.ctm, args);
  34020. }
  34021. }
  34022. class TextState {
  34023. constructor() {
  34024. this.ctm = new Float32Array(IDENTITY_MATRIX);
  34025. this.fontName = null;
  34026. this.fontSize = 0;
  34027. this.loadedName = null;
  34028. this.font = null;
  34029. this.fontMatrix = FONT_IDENTITY_MATRIX;
  34030. this.textMatrix = IDENTITY_MATRIX.slice();
  34031. this.textLineMatrix = IDENTITY_MATRIX.slice();
  34032. this.charSpacing = 0;
  34033. this.wordSpacing = 0;
  34034. this.leading = 0;
  34035. this.textHScale = 1;
  34036. this.textRise = 0;
  34037. }
  34038. setTextMatrix(a, b, c, d, e, f) {
  34039. const m = this.textMatrix;
  34040. m[0] = a;
  34041. m[1] = b;
  34042. m[2] = c;
  34043. m[3] = d;
  34044. m[4] = e;
  34045. m[5] = f;
  34046. }
  34047. setTextLineMatrix(a, b, c, d, e, f) {
  34048. const m = this.textLineMatrix;
  34049. m[0] = a;
  34050. m[1] = b;
  34051. m[2] = c;
  34052. m[3] = d;
  34053. m[4] = e;
  34054. m[5] = f;
  34055. }
  34056. translateTextMatrix(x, y) {
  34057. const m = this.textMatrix;
  34058. m[4] = m[0] * x + m[2] * y + m[4];
  34059. m[5] = m[1] * x + m[3] * y + m[5];
  34060. }
  34061. translateTextLineMatrix(x, y) {
  34062. const m = this.textLineMatrix;
  34063. m[4] = m[0] * x + m[2] * y + m[4];
  34064. m[5] = m[1] * x + m[3] * y + m[5];
  34065. }
  34066. carriageReturn() {
  34067. this.translateTextLineMatrix(0, -this.leading);
  34068. this.textMatrix = this.textLineMatrix.slice();
  34069. }
  34070. clone() {
  34071. const clone = Object.create(this);
  34072. clone.textMatrix = this.textMatrix.slice();
  34073. clone.textLineMatrix = this.textLineMatrix.slice();
  34074. clone.fontMatrix = this.fontMatrix.slice();
  34075. return clone;
  34076. }
  34077. }
  34078. class EvalState {
  34079. constructor() {
  34080. this.ctm = new Float32Array(IDENTITY_MATRIX);
  34081. this.font = null;
  34082. this.textRenderingMode = TextRenderingMode.FILL;
  34083. this.fillColorSpace = ColorSpace.singletons.gray;
  34084. this.strokeColorSpace = ColorSpace.singletons.gray;
  34085. }
  34086. clone() {
  34087. return Object.create(this);
  34088. }
  34089. }
  34090. class EvaluatorPreprocessor {
  34091. static get opMap() {
  34092. return shadow(this, "opMap", {
  34093. w: {
  34094. id: OPS.setLineWidth,
  34095. numArgs: 1,
  34096. variableArgs: false
  34097. },
  34098. J: {
  34099. id: OPS.setLineCap,
  34100. numArgs: 1,
  34101. variableArgs: false
  34102. },
  34103. j: {
  34104. id: OPS.setLineJoin,
  34105. numArgs: 1,
  34106. variableArgs: false
  34107. },
  34108. M: {
  34109. id: OPS.setMiterLimit,
  34110. numArgs: 1,
  34111. variableArgs: false
  34112. },
  34113. d: {
  34114. id: OPS.setDash,
  34115. numArgs: 2,
  34116. variableArgs: false
  34117. },
  34118. ri: {
  34119. id: OPS.setRenderingIntent,
  34120. numArgs: 1,
  34121. variableArgs: false
  34122. },
  34123. i: {
  34124. id: OPS.setFlatness,
  34125. numArgs: 1,
  34126. variableArgs: false
  34127. },
  34128. gs: {
  34129. id: OPS.setGState,
  34130. numArgs: 1,
  34131. variableArgs: false
  34132. },
  34133. q: {
  34134. id: OPS.save,
  34135. numArgs: 0,
  34136. variableArgs: false
  34137. },
  34138. Q: {
  34139. id: OPS.restore,
  34140. numArgs: 0,
  34141. variableArgs: false
  34142. },
  34143. cm: {
  34144. id: OPS.transform,
  34145. numArgs: 6,
  34146. variableArgs: false
  34147. },
  34148. m: {
  34149. id: OPS.moveTo,
  34150. numArgs: 2,
  34151. variableArgs: false
  34152. },
  34153. l: {
  34154. id: OPS.lineTo,
  34155. numArgs: 2,
  34156. variableArgs: false
  34157. },
  34158. c: {
  34159. id: OPS.curveTo,
  34160. numArgs: 6,
  34161. variableArgs: false
  34162. },
  34163. v: {
  34164. id: OPS.curveTo2,
  34165. numArgs: 4,
  34166. variableArgs: false
  34167. },
  34168. y: {
  34169. id: OPS.curveTo3,
  34170. numArgs: 4,
  34171. variableArgs: false
  34172. },
  34173. h: {
  34174. id: OPS.closePath,
  34175. numArgs: 0,
  34176. variableArgs: false
  34177. },
  34178. re: {
  34179. id: OPS.rectangle,
  34180. numArgs: 4,
  34181. variableArgs: false
  34182. },
  34183. S: {
  34184. id: OPS.stroke,
  34185. numArgs: 0,
  34186. variableArgs: false
  34187. },
  34188. s: {
  34189. id: OPS.closeStroke,
  34190. numArgs: 0,
  34191. variableArgs: false
  34192. },
  34193. f: {
  34194. id: OPS.fill,
  34195. numArgs: 0,
  34196. variableArgs: false
  34197. },
  34198. F: {
  34199. id: OPS.fill,
  34200. numArgs: 0,
  34201. variableArgs: false
  34202. },
  34203. "f*": {
  34204. id: OPS.eoFill,
  34205. numArgs: 0,
  34206. variableArgs: false
  34207. },
  34208. B: {
  34209. id: OPS.fillStroke,
  34210. numArgs: 0,
  34211. variableArgs: false
  34212. },
  34213. "B*": {
  34214. id: OPS.eoFillStroke,
  34215. numArgs: 0,
  34216. variableArgs: false
  34217. },
  34218. b: {
  34219. id: OPS.closeFillStroke,
  34220. numArgs: 0,
  34221. variableArgs: false
  34222. },
  34223. "b*": {
  34224. id: OPS.closeEOFillStroke,
  34225. numArgs: 0,
  34226. variableArgs: false
  34227. },
  34228. n: {
  34229. id: OPS.endPath,
  34230. numArgs: 0,
  34231. variableArgs: false
  34232. },
  34233. W: {
  34234. id: OPS.clip,
  34235. numArgs: 0,
  34236. variableArgs: false
  34237. },
  34238. "W*": {
  34239. id: OPS.eoClip,
  34240. numArgs: 0,
  34241. variableArgs: false
  34242. },
  34243. BT: {
  34244. id: OPS.beginText,
  34245. numArgs: 0,
  34246. variableArgs: false
  34247. },
  34248. ET: {
  34249. id: OPS.endText,
  34250. numArgs: 0,
  34251. variableArgs: false
  34252. },
  34253. Tc: {
  34254. id: OPS.setCharSpacing,
  34255. numArgs: 1,
  34256. variableArgs: false
  34257. },
  34258. Tw: {
  34259. id: OPS.setWordSpacing,
  34260. numArgs: 1,
  34261. variableArgs: false
  34262. },
  34263. Tz: {
  34264. id: OPS.setHScale,
  34265. numArgs: 1,
  34266. variableArgs: false
  34267. },
  34268. TL: {
  34269. id: OPS.setLeading,
  34270. numArgs: 1,
  34271. variableArgs: false
  34272. },
  34273. Tf: {
  34274. id: OPS.setFont,
  34275. numArgs: 2,
  34276. variableArgs: false
  34277. },
  34278. Tr: {
  34279. id: OPS.setTextRenderingMode,
  34280. numArgs: 1,
  34281. variableArgs: false
  34282. },
  34283. Ts: {
  34284. id: OPS.setTextRise,
  34285. numArgs: 1,
  34286. variableArgs: false
  34287. },
  34288. Td: {
  34289. id: OPS.moveText,
  34290. numArgs: 2,
  34291. variableArgs: false
  34292. },
  34293. TD: {
  34294. id: OPS.setLeadingMoveText,
  34295. numArgs: 2,
  34296. variableArgs: false
  34297. },
  34298. Tm: {
  34299. id: OPS.setTextMatrix,
  34300. numArgs: 6,
  34301. variableArgs: false
  34302. },
  34303. "T*": {
  34304. id: OPS.nextLine,
  34305. numArgs: 0,
  34306. variableArgs: false
  34307. },
  34308. Tj: {
  34309. id: OPS.showText,
  34310. numArgs: 1,
  34311. variableArgs: false
  34312. },
  34313. TJ: {
  34314. id: OPS.showSpacedText,
  34315. numArgs: 1,
  34316. variableArgs: false
  34317. },
  34318. "'": {
  34319. id: OPS.nextLineShowText,
  34320. numArgs: 1,
  34321. variableArgs: false
  34322. },
  34323. '"': {
  34324. id: OPS.nextLineSetSpacingShowText,
  34325. numArgs: 3,
  34326. variableArgs: false
  34327. },
  34328. d0: {
  34329. id: OPS.setCharWidth,
  34330. numArgs: 2,
  34331. variableArgs: false
  34332. },
  34333. d1: {
  34334. id: OPS.setCharWidthAndBounds,
  34335. numArgs: 6,
  34336. variableArgs: false
  34337. },
  34338. CS: {
  34339. id: OPS.setStrokeColorSpace,
  34340. numArgs: 1,
  34341. variableArgs: false
  34342. },
  34343. cs: {
  34344. id: OPS.setFillColorSpace,
  34345. numArgs: 1,
  34346. variableArgs: false
  34347. },
  34348. SC: {
  34349. id: OPS.setStrokeColor,
  34350. numArgs: 4,
  34351. variableArgs: true
  34352. },
  34353. SCN: {
  34354. id: OPS.setStrokeColorN,
  34355. numArgs: 33,
  34356. variableArgs: true
  34357. },
  34358. sc: {
  34359. id: OPS.setFillColor,
  34360. numArgs: 4,
  34361. variableArgs: true
  34362. },
  34363. scn: {
  34364. id: OPS.setFillColorN,
  34365. numArgs: 33,
  34366. variableArgs: true
  34367. },
  34368. G: {
  34369. id: OPS.setStrokeGray,
  34370. numArgs: 1,
  34371. variableArgs: false
  34372. },
  34373. g: {
  34374. id: OPS.setFillGray,
  34375. numArgs: 1,
  34376. variableArgs: false
  34377. },
  34378. RG: {
  34379. id: OPS.setStrokeRGBColor,
  34380. numArgs: 3,
  34381. variableArgs: false
  34382. },
  34383. rg: {
  34384. id: OPS.setFillRGBColor,
  34385. numArgs: 3,
  34386. variableArgs: false
  34387. },
  34388. K: {
  34389. id: OPS.setStrokeCMYKColor,
  34390. numArgs: 4,
  34391. variableArgs: false
  34392. },
  34393. k: {
  34394. id: OPS.setFillCMYKColor,
  34395. numArgs: 4,
  34396. variableArgs: false
  34397. },
  34398. sh: {
  34399. id: OPS.shadingFill,
  34400. numArgs: 1,
  34401. variableArgs: false
  34402. },
  34403. BI: {
  34404. id: OPS.beginInlineImage,
  34405. numArgs: 0,
  34406. variableArgs: false
  34407. },
  34408. ID: {
  34409. id: OPS.beginImageData,
  34410. numArgs: 0,
  34411. variableArgs: false
  34412. },
  34413. EI: {
  34414. id: OPS.endInlineImage,
  34415. numArgs: 1,
  34416. variableArgs: false
  34417. },
  34418. Do: {
  34419. id: OPS.paintXObject,
  34420. numArgs: 1,
  34421. variableArgs: false
  34422. },
  34423. MP: {
  34424. id: OPS.markPoint,
  34425. numArgs: 1,
  34426. variableArgs: false
  34427. },
  34428. DP: {
  34429. id: OPS.markPointProps,
  34430. numArgs: 2,
  34431. variableArgs: false
  34432. },
  34433. BMC: {
  34434. id: OPS.beginMarkedContent,
  34435. numArgs: 1,
  34436. variableArgs: false
  34437. },
  34438. BDC: {
  34439. id: OPS.beginMarkedContentProps,
  34440. numArgs: 2,
  34441. variableArgs: false
  34442. },
  34443. EMC: {
  34444. id: OPS.endMarkedContent,
  34445. numArgs: 0,
  34446. variableArgs: false
  34447. },
  34448. BX: {
  34449. id: OPS.beginCompat,
  34450. numArgs: 0,
  34451. variableArgs: false
  34452. },
  34453. EX: {
  34454. id: OPS.endCompat,
  34455. numArgs: 0,
  34456. variableArgs: false
  34457. },
  34458. BM: null,
  34459. BD: null,
  34460. true: null,
  34461. fa: null,
  34462. fal: null,
  34463. fals: null,
  34464. false: null,
  34465. nu: null,
  34466. nul: null,
  34467. null: null
  34468. });
  34469. }
  34470. static MAX_INVALID_PATH_OPS = 10;
  34471. constructor(stream, xref, stateManager = new StateManager()) {
  34472. this.parser = new Parser({
  34473. lexer: new Lexer(stream, EvaluatorPreprocessor.opMap),
  34474. xref
  34475. });
  34476. this.stateManager = stateManager;
  34477. this.nonProcessedArgs = [];
  34478. this._isPathOp = false;
  34479. this._numInvalidPathOPS = 0;
  34480. }
  34481. get savedStatesDepth() {
  34482. return this.stateManager.stateStack.length;
  34483. }
  34484. read(operation) {
  34485. let args = operation.args;
  34486. while (true) {
  34487. const obj = this.parser.getObj();
  34488. if (obj instanceof Cmd) {
  34489. const cmd = obj.cmd;
  34490. const opSpec = EvaluatorPreprocessor.opMap[cmd];
  34491. if (!opSpec) {
  34492. warn(`Unknown command "${cmd}".`);
  34493. continue;
  34494. }
  34495. const fn = opSpec.id;
  34496. const numArgs = opSpec.numArgs;
  34497. let argsLength = args !== null ? args.length : 0;
  34498. if (!this._isPathOp) {
  34499. this._numInvalidPathOPS = 0;
  34500. }
  34501. this._isPathOp = fn >= OPS.moveTo && fn <= OPS.endPath;
  34502. if (!opSpec.variableArgs) {
  34503. if (argsLength !== numArgs) {
  34504. const nonProcessedArgs = this.nonProcessedArgs;
  34505. while (argsLength > numArgs) {
  34506. nonProcessedArgs.push(args.shift());
  34507. argsLength--;
  34508. }
  34509. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  34510. if (args === null) {
  34511. args = [];
  34512. }
  34513. args.unshift(nonProcessedArgs.pop());
  34514. argsLength++;
  34515. }
  34516. }
  34517. if (argsLength < numArgs) {
  34518. const partialMsg = `command ${cmd}: expected ${numArgs} args, ` + `but received ${argsLength} args.`;
  34519. if (this._isPathOp && ++this._numInvalidPathOPS > EvaluatorPreprocessor.MAX_INVALID_PATH_OPS) {
  34520. throw new FormatError(`Invalid ${partialMsg}`);
  34521. }
  34522. warn(`Skipping ${partialMsg}`);
  34523. if (args !== null) {
  34524. args.length = 0;
  34525. }
  34526. continue;
  34527. }
  34528. } else if (argsLength > numArgs) {
  34529. info(`Command ${cmd}: expected [0, ${numArgs}] args, ` + `but received ${argsLength} args.`);
  34530. }
  34531. this.preprocessCommand(fn, args);
  34532. operation.fn = fn;
  34533. operation.args = args;
  34534. return true;
  34535. }
  34536. if (obj === EOF) {
  34537. return false;
  34538. }
  34539. if (obj !== null) {
  34540. if (args === null) {
  34541. args = [];
  34542. }
  34543. args.push(obj);
  34544. if (args.length > 33) {
  34545. throw new FormatError("Too many arguments");
  34546. }
  34547. }
  34548. }
  34549. }
  34550. preprocessCommand(fn, args) {
  34551. switch (fn | 0) {
  34552. case OPS.save:
  34553. this.stateManager.save();
  34554. break;
  34555. case OPS.restore:
  34556. this.stateManager.restore();
  34557. break;
  34558. case OPS.transform:
  34559. this.stateManager.transform(args);
  34560. break;
  34561. }
  34562. }
  34563. }
  34564. ;// CONCATENATED MODULE: ./src/core/default_appearance.js
  34565. class DefaultAppearanceEvaluator extends EvaluatorPreprocessor {
  34566. constructor(str) {
  34567. super(new StringStream(str));
  34568. }
  34569. parse() {
  34570. const operation = {
  34571. fn: 0,
  34572. args: []
  34573. };
  34574. const result = {
  34575. fontSize: 0,
  34576. fontName: "",
  34577. fontColor: new Uint8ClampedArray(3)
  34578. };
  34579. try {
  34580. while (true) {
  34581. operation.args.length = 0;
  34582. if (!this.read(operation)) {
  34583. break;
  34584. }
  34585. if (this.savedStatesDepth !== 0) {
  34586. continue;
  34587. }
  34588. const {
  34589. fn,
  34590. args
  34591. } = operation;
  34592. switch (fn | 0) {
  34593. case OPS.setFont:
  34594. const [fontName, fontSize] = args;
  34595. if (fontName instanceof Name) {
  34596. result.fontName = fontName.name;
  34597. }
  34598. if (typeof fontSize === "number" && fontSize > 0) {
  34599. result.fontSize = fontSize;
  34600. }
  34601. break;
  34602. case OPS.setFillRGBColor:
  34603. ColorSpace.singletons.rgb.getRgbItem(args, 0, result.fontColor, 0);
  34604. break;
  34605. case OPS.setFillGray:
  34606. ColorSpace.singletons.gray.getRgbItem(args, 0, result.fontColor, 0);
  34607. break;
  34608. case OPS.setFillCMYKColor:
  34609. ColorSpace.singletons.cmyk.getRgbItem(args, 0, result.fontColor, 0);
  34610. break;
  34611. }
  34612. }
  34613. } catch (reason) {
  34614. warn(`parseDefaultAppearance - ignoring errors: "${reason}".`);
  34615. }
  34616. return result;
  34617. }
  34618. }
  34619. function parseDefaultAppearance(str) {
  34620. return new DefaultAppearanceEvaluator(str).parse();
  34621. }
  34622. class AppearanceStreamEvaluator extends EvaluatorPreprocessor {
  34623. constructor(stream, evaluatorOptions, xref) {
  34624. super(stream);
  34625. this.stream = stream;
  34626. this.evaluatorOptions = evaluatorOptions;
  34627. this.xref = xref;
  34628. this.resources = stream.dict?.get("Resources");
  34629. }
  34630. parse() {
  34631. const operation = {
  34632. fn: 0,
  34633. args: []
  34634. };
  34635. let result = {
  34636. scaleFactor: 1,
  34637. fontSize: 0,
  34638. fontName: "",
  34639. fontColor: new Uint8ClampedArray(3),
  34640. fillColorSpace: ColorSpace.singletons.gray
  34641. };
  34642. let breakLoop = false;
  34643. const stack = [];
  34644. try {
  34645. while (true) {
  34646. operation.args.length = 0;
  34647. if (breakLoop || !this.read(operation)) {
  34648. break;
  34649. }
  34650. const {
  34651. fn,
  34652. args
  34653. } = operation;
  34654. switch (fn | 0) {
  34655. case OPS.save:
  34656. stack.push({
  34657. scaleFactor: result.scaleFactor,
  34658. fontSize: result.fontSize,
  34659. fontName: result.fontName,
  34660. fontColor: result.fontColor.slice(),
  34661. fillColorSpace: result.fillColorSpace
  34662. });
  34663. break;
  34664. case OPS.restore:
  34665. result = stack.pop() || result;
  34666. break;
  34667. case OPS.setTextMatrix:
  34668. result.scaleFactor *= Math.hypot(args[0], args[1]);
  34669. break;
  34670. case OPS.setFont:
  34671. const [fontName, fontSize] = args;
  34672. if (fontName instanceof Name) {
  34673. result.fontName = fontName.name;
  34674. }
  34675. if (typeof fontSize === "number" && fontSize > 0) {
  34676. result.fontSize = fontSize * result.scaleFactor;
  34677. }
  34678. break;
  34679. case OPS.setFillColorSpace:
  34680. result.fillColorSpace = ColorSpace.parse({
  34681. cs: args[0],
  34682. xref: this.xref,
  34683. resources: this.resources,
  34684. pdfFunctionFactory: this._pdfFunctionFactory,
  34685. localColorSpaceCache: this._localColorSpaceCache
  34686. });
  34687. break;
  34688. case OPS.setFillColor:
  34689. const cs = result.fillColorSpace;
  34690. cs.getRgbItem(args, 0, result.fontColor, 0);
  34691. break;
  34692. case OPS.setFillRGBColor:
  34693. ColorSpace.singletons.rgb.getRgbItem(args, 0, result.fontColor, 0);
  34694. break;
  34695. case OPS.setFillGray:
  34696. ColorSpace.singletons.gray.getRgbItem(args, 0, result.fontColor, 0);
  34697. break;
  34698. case OPS.setFillCMYKColor:
  34699. ColorSpace.singletons.cmyk.getRgbItem(args, 0, result.fontColor, 0);
  34700. break;
  34701. case OPS.showText:
  34702. case OPS.showSpacedText:
  34703. case OPS.nextLineShowText:
  34704. case OPS.nextLineSetSpacingShowText:
  34705. breakLoop = true;
  34706. break;
  34707. }
  34708. }
  34709. } catch (reason) {
  34710. warn(`parseAppearanceStream - ignoring errors: "${reason}".`);
  34711. }
  34712. this.stream.reset();
  34713. delete result.scaleFactor;
  34714. delete result.fillColorSpace;
  34715. return result;
  34716. }
  34717. get _localColorSpaceCache() {
  34718. return shadow(this, "_localColorSpaceCache", new LocalColorSpaceCache());
  34719. }
  34720. get _pdfFunctionFactory() {
  34721. const pdfFunctionFactory = new PDFFunctionFactory({
  34722. xref: this.xref,
  34723. isEvalSupported: this.evaluatorOptions.isEvalSupported
  34724. });
  34725. return shadow(this, "_pdfFunctionFactory", pdfFunctionFactory);
  34726. }
  34727. }
  34728. function parseAppearanceStream(stream, evaluatorOptions, xref) {
  34729. return new AppearanceStreamEvaluator(stream, evaluatorOptions, xref).parse();
  34730. }
  34731. function getPdfColor(color, isFill) {
  34732. if (color[0] === color[1] && color[1] === color[2]) {
  34733. const gray = color[0] / 255;
  34734. return `${numberToString(gray)} ${isFill ? "g" : "G"}`;
  34735. }
  34736. return Array.from(color, c => numberToString(c / 255)).join(" ") + ` ${isFill ? "rg" : "RG"}`;
  34737. }
  34738. function createDefaultAppearance({
  34739. fontSize,
  34740. fontName,
  34741. fontColor
  34742. }) {
  34743. return `/${escapePDFName(fontName)} ${fontSize} Tf ${getPdfColor(fontColor, true)}`;
  34744. }
  34745. class FakeUnicodeFont {
  34746. constructor(xref, fontFamily) {
  34747. this.xref = xref;
  34748. this.widths = null;
  34749. this.firstChar = Infinity;
  34750. this.lastChar = -Infinity;
  34751. this.fontFamily = fontFamily;
  34752. const canvas = new OffscreenCanvas(1, 1);
  34753. this.ctxMeasure = canvas.getContext("2d");
  34754. if (!FakeUnicodeFont._fontNameId) {
  34755. FakeUnicodeFont._fontNameId = 1;
  34756. }
  34757. this.fontName = Name.get(`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`);
  34758. }
  34759. get toUnicodeRef() {
  34760. if (!FakeUnicodeFont._toUnicodeRef) {
  34761. const toUnicode = `/CIDInit /ProcSet findresource begin
  34762. 12 dict begin
  34763. begincmap
  34764. /CIDSystemInfo
  34765. << /Registry (Adobe)
  34766. /Ordering (UCS) /Supplement 0 >> def
  34767. /CMapName /Adobe-Identity-UCS def
  34768. /CMapType 2 def
  34769. 1 begincodespacerange
  34770. <0000> <FFFF>
  34771. endcodespacerange
  34772. 1 beginbfrange
  34773. <0000> <FFFF> <0000>
  34774. endbfrange
  34775. endcmap CMapName currentdict /CMap defineresource pop end end`;
  34776. const toUnicodeStream = FakeUnicodeFont.toUnicodeStream = new StringStream(toUnicode);
  34777. const toUnicodeDict = new Dict(this.xref);
  34778. toUnicodeStream.dict = toUnicodeDict;
  34779. toUnicodeDict.set("Length", toUnicode.length);
  34780. FakeUnicodeFont._toUnicodeRef = this.xref.getNewPersistentRef(toUnicodeStream);
  34781. }
  34782. return FakeUnicodeFont._toUnicodeRef;
  34783. }
  34784. get fontDescriptorRef() {
  34785. if (!FakeUnicodeFont._fontDescriptorRef) {
  34786. const fontDescriptor = new Dict(this.xref);
  34787. fontDescriptor.set("Type", Name.get("FontDescriptor"));
  34788. fontDescriptor.set("FontName", this.fontName);
  34789. fontDescriptor.set("FontFamily", "MyriadPro Regular");
  34790. fontDescriptor.set("FontBBox", [0, 0, 0, 0]);
  34791. fontDescriptor.set("FontStretch", Name.get("Normal"));
  34792. fontDescriptor.set("FontWeight", 400);
  34793. fontDescriptor.set("ItalicAngle", 0);
  34794. FakeUnicodeFont._fontDescriptorRef = this.xref.getNewPersistentRef(fontDescriptor);
  34795. }
  34796. return FakeUnicodeFont._fontDescriptorRef;
  34797. }
  34798. get descendantFontRef() {
  34799. const descendantFont = new Dict(this.xref);
  34800. descendantFont.set("BaseFont", this.fontName);
  34801. descendantFont.set("Type", Name.get("Font"));
  34802. descendantFont.set("Subtype", Name.get("CIDFontType0"));
  34803. descendantFont.set("CIDToGIDMap", Name.get("Identity"));
  34804. descendantFont.set("FirstChar", this.firstChar);
  34805. descendantFont.set("LastChar", this.lastChar);
  34806. descendantFont.set("FontDescriptor", this.fontDescriptorRef);
  34807. descendantFont.set("DW", 1000);
  34808. const widths = [];
  34809. const chars = [...this.widths.entries()].sort();
  34810. let currentChar = null;
  34811. let currentWidths = null;
  34812. for (const [char, width] of chars) {
  34813. if (!currentChar) {
  34814. currentChar = char;
  34815. currentWidths = [width];
  34816. continue;
  34817. }
  34818. if (char === currentChar + currentWidths.length) {
  34819. currentWidths.push(width);
  34820. } else {
  34821. widths.push(currentChar, currentWidths);
  34822. currentChar = char;
  34823. currentWidths = [width];
  34824. }
  34825. }
  34826. if (currentChar) {
  34827. widths.push(currentChar, currentWidths);
  34828. }
  34829. descendantFont.set("W", widths);
  34830. const cidSystemInfo = new Dict(this.xref);
  34831. cidSystemInfo.set("Ordering", "Identity");
  34832. cidSystemInfo.set("Registry", "Adobe");
  34833. cidSystemInfo.set("Supplement", 0);
  34834. descendantFont.set("CIDSystemInfo", cidSystemInfo);
  34835. return this.xref.getNewPersistentRef(descendantFont);
  34836. }
  34837. get baseFontRef() {
  34838. const baseFont = new Dict(this.xref);
  34839. baseFont.set("BaseFont", this.fontName);
  34840. baseFont.set("Type", Name.get("Font"));
  34841. baseFont.set("Subtype", Name.get("Type0"));
  34842. baseFont.set("Encoding", Name.get("Identity-H"));
  34843. baseFont.set("DescendantFonts", [this.descendantFontRef]);
  34844. baseFont.set("ToUnicode", this.toUnicodeRef);
  34845. return this.xref.getNewPersistentRef(baseFont);
  34846. }
  34847. get resources() {
  34848. const resources = new Dict(this.xref);
  34849. const font = new Dict(this.xref);
  34850. font.set(this.fontName.name, this.baseFontRef);
  34851. resources.set("Font", font);
  34852. return resources;
  34853. }
  34854. _createContext() {
  34855. this.widths = new Map();
  34856. this.ctxMeasure.font = `1000px ${this.fontFamily}`;
  34857. return this.ctxMeasure;
  34858. }
  34859. createFontResources(text) {
  34860. const ctx = this._createContext();
  34861. for (const line of text.split(/\r\n?|\n/)) {
  34862. for (const char of line.split("")) {
  34863. const code = char.charCodeAt(0);
  34864. if (this.widths.has(code)) {
  34865. continue;
  34866. }
  34867. const metrics = ctx.measureText(char);
  34868. const width = Math.ceil(metrics.width);
  34869. this.widths.set(code, width);
  34870. this.firstChar = Math.min(code, this.firstChar);
  34871. this.lastChar = Math.max(code, this.lastChar);
  34872. }
  34873. }
  34874. return this.resources;
  34875. }
  34876. createAppearance(text, rect, rotation, fontSize, bgColor, strokeAlpha) {
  34877. const ctx = this._createContext();
  34878. const lines = [];
  34879. let maxWidth = -Infinity;
  34880. for (const line of text.split(/\r\n?|\n/)) {
  34881. lines.push(line);
  34882. const lineWidth = ctx.measureText(line).width;
  34883. maxWidth = Math.max(maxWidth, lineWidth);
  34884. for (const char of line.split("")) {
  34885. const code = char.charCodeAt(0);
  34886. let width = this.widths.get(code);
  34887. if (width === undefined) {
  34888. const metrics = ctx.measureText(char);
  34889. width = Math.ceil(metrics.width);
  34890. this.widths.set(code, width);
  34891. this.firstChar = Math.min(code, this.firstChar);
  34892. this.lastChar = Math.max(code, this.lastChar);
  34893. }
  34894. }
  34895. }
  34896. maxWidth *= fontSize / 1000;
  34897. const [x1, y1, x2, y2] = rect;
  34898. let w = x2 - x1;
  34899. let h = y2 - y1;
  34900. if (rotation % 180 !== 0) {
  34901. [w, h] = [h, w];
  34902. }
  34903. let hscale = 1;
  34904. if (maxWidth > w) {
  34905. hscale = w / maxWidth;
  34906. }
  34907. let vscale = 1;
  34908. const lineHeight = LINE_FACTOR * fontSize;
  34909. const lineDescent = LINE_DESCENT_FACTOR * fontSize;
  34910. const maxHeight = lineHeight * lines.length;
  34911. if (maxHeight > h) {
  34912. vscale = h / maxHeight;
  34913. }
  34914. const fscale = Math.min(hscale, vscale);
  34915. const newFontSize = fontSize * fscale;
  34916. const buffer = ["q", `0 0 ${numberToString(w)} ${numberToString(h)} re W n`, `BT`, `1 0 0 1 0 ${numberToString(h + lineDescent)} Tm 0 Tc ${getPdfColor(bgColor, true)}`, `/${this.fontName.name} ${numberToString(newFontSize)} Tf`];
  34917. const {
  34918. resources
  34919. } = this;
  34920. strokeAlpha = typeof strokeAlpha === "number" && strokeAlpha >= 0 && strokeAlpha <= 1 ? strokeAlpha : 1;
  34921. if (strokeAlpha !== 1) {
  34922. buffer.push("/R0 gs");
  34923. const extGState = new Dict(this.xref);
  34924. const r0 = new Dict(this.xref);
  34925. r0.set("ca", strokeAlpha);
  34926. r0.set("CA", strokeAlpha);
  34927. r0.set("Type", Name.get("ExtGState"));
  34928. extGState.set("R0", r0);
  34929. resources.set("ExtGState", extGState);
  34930. }
  34931. const vShift = numberToString(lineHeight);
  34932. for (const line of lines) {
  34933. buffer.push(`0 -${vShift} Td <${stringToUTF16HexString(line)}> Tj`);
  34934. }
  34935. buffer.push("ET", "Q");
  34936. const appearance = buffer.join("\n");
  34937. const appearanceStreamDict = new Dict(this.xref);
  34938. appearanceStreamDict.set("Subtype", Name.get("Form"));
  34939. appearanceStreamDict.set("Type", Name.get("XObject"));
  34940. appearanceStreamDict.set("BBox", [0, 0, w, h]);
  34941. appearanceStreamDict.set("Length", appearance.length);
  34942. appearanceStreamDict.set("Resources", resources);
  34943. if (rotation) {
  34944. const matrix = getRotationMatrix(rotation, w, h);
  34945. appearanceStreamDict.set("Matrix", matrix);
  34946. }
  34947. const ap = new StringStream(appearance);
  34948. ap.dict = appearanceStreamDict;
  34949. return ap;
  34950. }
  34951. }
  34952. ;// CONCATENATED MODULE: ./src/core/name_number_tree.js
  34953. class NameOrNumberTree {
  34954. constructor(root, xref, type) {
  34955. if (this.constructor === NameOrNumberTree) {
  34956. unreachable("Cannot initialize NameOrNumberTree.");
  34957. }
  34958. this.root = root;
  34959. this.xref = xref;
  34960. this._type = type;
  34961. }
  34962. getAll() {
  34963. const map = new Map();
  34964. if (!this.root) {
  34965. return map;
  34966. }
  34967. const xref = this.xref;
  34968. const processed = new RefSet();
  34969. processed.put(this.root);
  34970. const queue = [this.root];
  34971. while (queue.length > 0) {
  34972. const obj = xref.fetchIfRef(queue.shift());
  34973. if (!(obj instanceof Dict)) {
  34974. continue;
  34975. }
  34976. if (obj.has("Kids")) {
  34977. const kids = obj.get("Kids");
  34978. if (!Array.isArray(kids)) {
  34979. continue;
  34980. }
  34981. for (const kid of kids) {
  34982. if (processed.has(kid)) {
  34983. throw new FormatError(`Duplicate entry in "${this._type}" tree.`);
  34984. }
  34985. queue.push(kid);
  34986. processed.put(kid);
  34987. }
  34988. continue;
  34989. }
  34990. const entries = obj.get(this._type);
  34991. if (!Array.isArray(entries)) {
  34992. continue;
  34993. }
  34994. for (let i = 0, ii = entries.length; i < ii; i += 2) {
  34995. map.set(xref.fetchIfRef(entries[i]), xref.fetchIfRef(entries[i + 1]));
  34996. }
  34997. }
  34998. return map;
  34999. }
  35000. get(key) {
  35001. if (!this.root) {
  35002. return null;
  35003. }
  35004. const xref = this.xref;
  35005. let kidsOrEntries = xref.fetchIfRef(this.root);
  35006. let loopCount = 0;
  35007. const MAX_LEVELS = 10;
  35008. while (kidsOrEntries.has("Kids")) {
  35009. if (++loopCount > MAX_LEVELS) {
  35010. warn(`Search depth limit reached for "${this._type}" tree.`);
  35011. return null;
  35012. }
  35013. const kids = kidsOrEntries.get("Kids");
  35014. if (!Array.isArray(kids)) {
  35015. return null;
  35016. }
  35017. let l = 0,
  35018. r = kids.length - 1;
  35019. while (l <= r) {
  35020. const m = l + r >> 1;
  35021. const kid = xref.fetchIfRef(kids[m]);
  35022. const limits = kid.get("Limits");
  35023. if (key < xref.fetchIfRef(limits[0])) {
  35024. r = m - 1;
  35025. } else if (key > xref.fetchIfRef(limits[1])) {
  35026. l = m + 1;
  35027. } else {
  35028. kidsOrEntries = kid;
  35029. break;
  35030. }
  35031. }
  35032. if (l > r) {
  35033. return null;
  35034. }
  35035. }
  35036. const entries = kidsOrEntries.get(this._type);
  35037. if (Array.isArray(entries)) {
  35038. let l = 0,
  35039. r = entries.length - 2;
  35040. while (l <= r) {
  35041. const tmp = l + r >> 1,
  35042. m = tmp + (tmp & 1);
  35043. const currentKey = xref.fetchIfRef(entries[m]);
  35044. if (key < currentKey) {
  35045. r = m - 2;
  35046. } else if (key > currentKey) {
  35047. l = m + 2;
  35048. } else {
  35049. return xref.fetchIfRef(entries[m + 1]);
  35050. }
  35051. }
  35052. }
  35053. return null;
  35054. }
  35055. }
  35056. class NameTree extends NameOrNumberTree {
  35057. constructor(root, xref) {
  35058. super(root, xref, "Names");
  35059. }
  35060. }
  35061. class NumberTree extends NameOrNumberTree {
  35062. constructor(root, xref) {
  35063. super(root, xref, "Nums");
  35064. }
  35065. }
  35066. ;// CONCATENATED MODULE: ./src/core/cleanup_helper.js
  35067. function clearGlobalCaches() {
  35068. clearPatternCaches();
  35069. clearPrimitiveCaches();
  35070. clearUnicodeCaches();
  35071. }
  35072. ;// CONCATENATED MODULE: ./src/core/file_spec.js
  35073. function pickPlatformItem(dict) {
  35074. if (dict.has("UF")) {
  35075. return dict.get("UF");
  35076. } else if (dict.has("F")) {
  35077. return dict.get("F");
  35078. } else if (dict.has("Unix")) {
  35079. return dict.get("Unix");
  35080. } else if (dict.has("Mac")) {
  35081. return dict.get("Mac");
  35082. } else if (dict.has("DOS")) {
  35083. return dict.get("DOS");
  35084. }
  35085. return null;
  35086. }
  35087. class FileSpec {
  35088. constructor(root, xref) {
  35089. if (!(root instanceof Dict)) {
  35090. return;
  35091. }
  35092. this.xref = xref;
  35093. this.root = root;
  35094. if (root.has("FS")) {
  35095. this.fs = root.get("FS");
  35096. }
  35097. this.description = root.has("Desc") ? stringToPDFString(root.get("Desc")) : "";
  35098. if (root.has("RF")) {
  35099. warn("Related file specifications are not supported");
  35100. }
  35101. this.contentAvailable = true;
  35102. if (!root.has("EF")) {
  35103. this.contentAvailable = false;
  35104. warn("Non-embedded file specifications are not supported");
  35105. }
  35106. }
  35107. get filename() {
  35108. if (!this._filename && this.root) {
  35109. const filename = pickPlatformItem(this.root) || "unnamed";
  35110. this._filename = stringToPDFString(filename).replaceAll("\\\\", "\\").replaceAll("\\/", "/").replaceAll("\\", "/");
  35111. }
  35112. return this._filename;
  35113. }
  35114. get content() {
  35115. if (!this.contentAvailable) {
  35116. return null;
  35117. }
  35118. if (!this.contentRef && this.root) {
  35119. this.contentRef = pickPlatformItem(this.root.get("EF"));
  35120. }
  35121. let content = null;
  35122. if (this.contentRef) {
  35123. const fileObj = this.xref.fetchIfRef(this.contentRef);
  35124. if (fileObj instanceof BaseStream) {
  35125. content = fileObj.getBytes();
  35126. } else {
  35127. warn("Embedded file specification points to non-existing/invalid content");
  35128. }
  35129. } else {
  35130. warn("Embedded file specification does not have a content");
  35131. }
  35132. return content;
  35133. }
  35134. get serializable() {
  35135. return {
  35136. filename: this.filename,
  35137. content: this.content
  35138. };
  35139. }
  35140. }
  35141. ;// CONCATENATED MODULE: ./src/core/xml_parser.js
  35142. const XMLParserErrorCode = {
  35143. NoError: 0,
  35144. EndOfDocument: -1,
  35145. UnterminatedCdat: -2,
  35146. UnterminatedXmlDeclaration: -3,
  35147. UnterminatedDoctypeDeclaration: -4,
  35148. UnterminatedComment: -5,
  35149. MalformedElement: -6,
  35150. OutOfMemory: -7,
  35151. UnterminatedAttributeValue: -8,
  35152. UnterminatedElement: -9,
  35153. ElementNeverBegun: -10
  35154. };
  35155. function isWhitespace(s, index) {
  35156. const ch = s[index];
  35157. return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
  35158. }
  35159. function isWhitespaceString(s) {
  35160. for (let i = 0, ii = s.length; i < ii; i++) {
  35161. if (!isWhitespace(s, i)) {
  35162. return false;
  35163. }
  35164. }
  35165. return true;
  35166. }
  35167. class XMLParserBase {
  35168. _resolveEntities(s) {
  35169. return s.replaceAll(/&([^;]+);/g, (all, entity) => {
  35170. if (entity.substring(0, 2) === "#x") {
  35171. return String.fromCodePoint(parseInt(entity.substring(2), 16));
  35172. } else if (entity.substring(0, 1) === "#") {
  35173. return String.fromCodePoint(parseInt(entity.substring(1), 10));
  35174. }
  35175. switch (entity) {
  35176. case "lt":
  35177. return "<";
  35178. case "gt":
  35179. return ">";
  35180. case "amp":
  35181. return "&";
  35182. case "quot":
  35183. return '"';
  35184. case "apos":
  35185. return "'";
  35186. }
  35187. return this.onResolveEntity(entity);
  35188. });
  35189. }
  35190. _parseContent(s, start) {
  35191. const attributes = [];
  35192. let pos = start;
  35193. function skipWs() {
  35194. while (pos < s.length && isWhitespace(s, pos)) {
  35195. ++pos;
  35196. }
  35197. }
  35198. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  35199. ++pos;
  35200. }
  35201. const name = s.substring(start, pos);
  35202. skipWs();
  35203. while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
  35204. skipWs();
  35205. let attrName = "",
  35206. attrValue = "";
  35207. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
  35208. attrName += s[pos];
  35209. ++pos;
  35210. }
  35211. skipWs();
  35212. if (s[pos] !== "=") {
  35213. return null;
  35214. }
  35215. ++pos;
  35216. skipWs();
  35217. const attrEndChar = s[pos];
  35218. if (attrEndChar !== '"' && attrEndChar !== "'") {
  35219. return null;
  35220. }
  35221. const attrEndIndex = s.indexOf(attrEndChar, ++pos);
  35222. if (attrEndIndex < 0) {
  35223. return null;
  35224. }
  35225. attrValue = s.substring(pos, attrEndIndex);
  35226. attributes.push({
  35227. name: attrName,
  35228. value: this._resolveEntities(attrValue)
  35229. });
  35230. pos = attrEndIndex + 1;
  35231. skipWs();
  35232. }
  35233. return {
  35234. name,
  35235. attributes,
  35236. parsed: pos - start
  35237. };
  35238. }
  35239. _parseProcessingInstruction(s, start) {
  35240. let pos = start;
  35241. function skipWs() {
  35242. while (pos < s.length && isWhitespace(s, pos)) {
  35243. ++pos;
  35244. }
  35245. }
  35246. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "?" && s[pos] !== "/") {
  35247. ++pos;
  35248. }
  35249. const name = s.substring(start, pos);
  35250. skipWs();
  35251. const attrStart = pos;
  35252. while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
  35253. ++pos;
  35254. }
  35255. const value = s.substring(attrStart, pos);
  35256. return {
  35257. name,
  35258. value,
  35259. parsed: pos - start
  35260. };
  35261. }
  35262. parseXml(s) {
  35263. let i = 0;
  35264. while (i < s.length) {
  35265. const ch = s[i];
  35266. let j = i;
  35267. if (ch === "<") {
  35268. ++j;
  35269. const ch2 = s[j];
  35270. let q;
  35271. switch (ch2) {
  35272. case "/":
  35273. ++j;
  35274. q = s.indexOf(">", j);
  35275. if (q < 0) {
  35276. this.onError(XMLParserErrorCode.UnterminatedElement);
  35277. return;
  35278. }
  35279. this.onEndElement(s.substring(j, q));
  35280. j = q + 1;
  35281. break;
  35282. case "?":
  35283. ++j;
  35284. const pi = this._parseProcessingInstruction(s, j);
  35285. if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
  35286. this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
  35287. return;
  35288. }
  35289. this.onPi(pi.name, pi.value);
  35290. j += pi.parsed + 2;
  35291. break;
  35292. case "!":
  35293. if (s.substring(j + 1, j + 3) === "--") {
  35294. q = s.indexOf("-->", j + 3);
  35295. if (q < 0) {
  35296. this.onError(XMLParserErrorCode.UnterminatedComment);
  35297. return;
  35298. }
  35299. this.onComment(s.substring(j + 3, q));
  35300. j = q + 3;
  35301. } else if (s.substring(j + 1, j + 8) === "[CDATA[") {
  35302. q = s.indexOf("]]>", j + 8);
  35303. if (q < 0) {
  35304. this.onError(XMLParserErrorCode.UnterminatedCdat);
  35305. return;
  35306. }
  35307. this.onCdata(s.substring(j + 8, q));
  35308. j = q + 3;
  35309. } else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
  35310. const q2 = s.indexOf("[", j + 8);
  35311. let complexDoctype = false;
  35312. q = s.indexOf(">", j + 8);
  35313. if (q < 0) {
  35314. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  35315. return;
  35316. }
  35317. if (q2 > 0 && q > q2) {
  35318. q = s.indexOf("]>", j + 8);
  35319. if (q < 0) {
  35320. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  35321. return;
  35322. }
  35323. complexDoctype = true;
  35324. }
  35325. const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
  35326. this.onDoctype(doctypeContent);
  35327. j = q + (complexDoctype ? 2 : 1);
  35328. } else {
  35329. this.onError(XMLParserErrorCode.MalformedElement);
  35330. return;
  35331. }
  35332. break;
  35333. default:
  35334. const content = this._parseContent(s, j);
  35335. if (content === null) {
  35336. this.onError(XMLParserErrorCode.MalformedElement);
  35337. return;
  35338. }
  35339. let isClosed = false;
  35340. if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
  35341. isClosed = true;
  35342. } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
  35343. this.onError(XMLParserErrorCode.UnterminatedElement);
  35344. return;
  35345. }
  35346. this.onBeginElement(content.name, content.attributes, isClosed);
  35347. j += content.parsed + (isClosed ? 2 : 1);
  35348. break;
  35349. }
  35350. } else {
  35351. while (j < s.length && s[j] !== "<") {
  35352. j++;
  35353. }
  35354. const text = s.substring(i, j);
  35355. this.onText(this._resolveEntities(text));
  35356. }
  35357. i = j;
  35358. }
  35359. }
  35360. onResolveEntity(name) {
  35361. return `&${name};`;
  35362. }
  35363. onPi(name, value) {}
  35364. onComment(text) {}
  35365. onCdata(text) {}
  35366. onDoctype(doctypeContent) {}
  35367. onText(text) {}
  35368. onBeginElement(name, attributes, isEmpty) {}
  35369. onEndElement(name) {}
  35370. onError(code) {}
  35371. }
  35372. class SimpleDOMNode {
  35373. constructor(nodeName, nodeValue) {
  35374. this.nodeName = nodeName;
  35375. this.nodeValue = nodeValue;
  35376. Object.defineProperty(this, "parentNode", {
  35377. value: null,
  35378. writable: true
  35379. });
  35380. }
  35381. get firstChild() {
  35382. return this.childNodes?.[0];
  35383. }
  35384. get nextSibling() {
  35385. const childNodes = this.parentNode.childNodes;
  35386. if (!childNodes) {
  35387. return undefined;
  35388. }
  35389. const index = childNodes.indexOf(this);
  35390. if (index === -1) {
  35391. return undefined;
  35392. }
  35393. return childNodes[index + 1];
  35394. }
  35395. get textContent() {
  35396. if (!this.childNodes) {
  35397. return this.nodeValue || "";
  35398. }
  35399. return this.childNodes.map(function (child) {
  35400. return child.textContent;
  35401. }).join("");
  35402. }
  35403. get children() {
  35404. return this.childNodes || [];
  35405. }
  35406. hasChildNodes() {
  35407. return this.childNodes?.length > 0;
  35408. }
  35409. searchNode(paths, pos) {
  35410. if (pos >= paths.length) {
  35411. return this;
  35412. }
  35413. const component = paths[pos];
  35414. if (component.name.startsWith("#") && pos < paths.length - 1) {
  35415. return this.searchNode(paths, pos + 1);
  35416. }
  35417. const stack = [];
  35418. let node = this;
  35419. while (true) {
  35420. if (component.name === node.nodeName) {
  35421. if (component.pos === 0) {
  35422. const res = node.searchNode(paths, pos + 1);
  35423. if (res !== null) {
  35424. return res;
  35425. }
  35426. } else if (stack.length === 0) {
  35427. return null;
  35428. } else {
  35429. const [parent] = stack.pop();
  35430. let siblingPos = 0;
  35431. for (const child of parent.childNodes) {
  35432. if (component.name === child.nodeName) {
  35433. if (siblingPos === component.pos) {
  35434. return child.searchNode(paths, pos + 1);
  35435. }
  35436. siblingPos++;
  35437. }
  35438. }
  35439. return node.searchNode(paths, pos + 1);
  35440. }
  35441. }
  35442. if (node.childNodes?.length > 0) {
  35443. stack.push([node, 0]);
  35444. node = node.childNodes[0];
  35445. } else if (stack.length === 0) {
  35446. return null;
  35447. } else {
  35448. while (stack.length !== 0) {
  35449. const [parent, currentPos] = stack.pop();
  35450. const newPos = currentPos + 1;
  35451. if (newPos < parent.childNodes.length) {
  35452. stack.push([parent, newPos]);
  35453. node = parent.childNodes[newPos];
  35454. break;
  35455. }
  35456. }
  35457. if (stack.length === 0) {
  35458. return null;
  35459. }
  35460. }
  35461. }
  35462. }
  35463. dump(buffer) {
  35464. if (this.nodeName === "#text") {
  35465. buffer.push(encodeToXmlString(this.nodeValue));
  35466. return;
  35467. }
  35468. buffer.push(`<${this.nodeName}`);
  35469. if (this.attributes) {
  35470. for (const attribute of this.attributes) {
  35471. buffer.push(` ${attribute.name}="${encodeToXmlString(attribute.value)}"`);
  35472. }
  35473. }
  35474. if (this.hasChildNodes()) {
  35475. buffer.push(">");
  35476. for (const child of this.childNodes) {
  35477. child.dump(buffer);
  35478. }
  35479. buffer.push(`</${this.nodeName}>`);
  35480. } else if (this.nodeValue) {
  35481. buffer.push(`>${encodeToXmlString(this.nodeValue)}</${this.nodeName}>`);
  35482. } else {
  35483. buffer.push("/>");
  35484. }
  35485. }
  35486. }
  35487. class SimpleXMLParser extends XMLParserBase {
  35488. constructor({
  35489. hasAttributes = false,
  35490. lowerCaseName = false
  35491. }) {
  35492. super();
  35493. this._currentFragment = null;
  35494. this._stack = null;
  35495. this._errorCode = XMLParserErrorCode.NoError;
  35496. this._hasAttributes = hasAttributes;
  35497. this._lowerCaseName = lowerCaseName;
  35498. }
  35499. parseFromString(data) {
  35500. this._currentFragment = [];
  35501. this._stack = [];
  35502. this._errorCode = XMLParserErrorCode.NoError;
  35503. this.parseXml(data);
  35504. if (this._errorCode !== XMLParserErrorCode.NoError) {
  35505. return undefined;
  35506. }
  35507. const [documentElement] = this._currentFragment;
  35508. if (!documentElement) {
  35509. return undefined;
  35510. }
  35511. return {
  35512. documentElement
  35513. };
  35514. }
  35515. onText(text) {
  35516. if (isWhitespaceString(text)) {
  35517. return;
  35518. }
  35519. const node = new SimpleDOMNode("#text", text);
  35520. this._currentFragment.push(node);
  35521. }
  35522. onCdata(text) {
  35523. const node = new SimpleDOMNode("#text", text);
  35524. this._currentFragment.push(node);
  35525. }
  35526. onBeginElement(name, attributes, isEmpty) {
  35527. if (this._lowerCaseName) {
  35528. name = name.toLowerCase();
  35529. }
  35530. const node = new SimpleDOMNode(name);
  35531. node.childNodes = [];
  35532. if (this._hasAttributes) {
  35533. node.attributes = attributes;
  35534. }
  35535. this._currentFragment.push(node);
  35536. if (isEmpty) {
  35537. return;
  35538. }
  35539. this._stack.push(this._currentFragment);
  35540. this._currentFragment = node.childNodes;
  35541. }
  35542. onEndElement(name) {
  35543. this._currentFragment = this._stack.pop() || [];
  35544. const lastElement = this._currentFragment.at(-1);
  35545. if (!lastElement) {
  35546. return null;
  35547. }
  35548. for (const childNode of lastElement.childNodes) {
  35549. childNode.parentNode = lastElement;
  35550. }
  35551. return lastElement;
  35552. }
  35553. onError(code) {
  35554. this._errorCode = code;
  35555. }
  35556. }
  35557. ;// CONCATENATED MODULE: ./src/core/metadata_parser.js
  35558. class MetadataParser {
  35559. constructor(data) {
  35560. data = this._repair(data);
  35561. const parser = new SimpleXMLParser({
  35562. lowerCaseName: true
  35563. });
  35564. const xmlDocument = parser.parseFromString(data);
  35565. this._metadataMap = new Map();
  35566. this._data = data;
  35567. if (xmlDocument) {
  35568. this._parse(xmlDocument);
  35569. }
  35570. }
  35571. _repair(data) {
  35572. return data.replace(/^[^<]+/, "").replaceAll(/>\\376\\377([^<]+)/g, function (all, codes) {
  35573. const bytes = codes.replaceAll(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  35574. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  35575. }).replaceAll(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
  35576. switch (name) {
  35577. case "amp":
  35578. return "&";
  35579. case "apos":
  35580. return "'";
  35581. case "gt":
  35582. return ">";
  35583. case "lt":
  35584. return "<";
  35585. case "quot":
  35586. return '"';
  35587. }
  35588. throw new Error(`_repair: ${name} isn't defined.`);
  35589. });
  35590. const charBuf = [">"];
  35591. for (let i = 0, ii = bytes.length; i < ii; i += 2) {
  35592. const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  35593. if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
  35594. charBuf.push(String.fromCharCode(code));
  35595. } else {
  35596. charBuf.push("&#x" + (0x10000 + code).toString(16).substring(1) + ";");
  35597. }
  35598. }
  35599. return charBuf.join("");
  35600. });
  35601. }
  35602. _getSequence(entry) {
  35603. const name = entry.nodeName;
  35604. if (name !== "rdf:bag" && name !== "rdf:seq" && name !== "rdf:alt") {
  35605. return null;
  35606. }
  35607. return entry.childNodes.filter(node => node.nodeName === "rdf:li");
  35608. }
  35609. _parseArray(entry) {
  35610. if (!entry.hasChildNodes()) {
  35611. return;
  35612. }
  35613. const [seqNode] = entry.childNodes;
  35614. const sequence = this._getSequence(seqNode) || [];
  35615. this._metadataMap.set(entry.nodeName, sequence.map(node => node.textContent.trim()));
  35616. }
  35617. _parse(xmlDocument) {
  35618. let rdf = xmlDocument.documentElement;
  35619. if (rdf.nodeName !== "rdf:rdf") {
  35620. rdf = rdf.firstChild;
  35621. while (rdf && rdf.nodeName !== "rdf:rdf") {
  35622. rdf = rdf.nextSibling;
  35623. }
  35624. }
  35625. if (!rdf || rdf.nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
  35626. return;
  35627. }
  35628. for (const desc of rdf.childNodes) {
  35629. if (desc.nodeName !== "rdf:description") {
  35630. continue;
  35631. }
  35632. for (const entry of desc.childNodes) {
  35633. const name = entry.nodeName;
  35634. switch (name) {
  35635. case "#text":
  35636. continue;
  35637. case "dc:creator":
  35638. case "dc:subject":
  35639. this._parseArray(entry);
  35640. continue;
  35641. }
  35642. this._metadataMap.set(name, entry.textContent.trim());
  35643. }
  35644. }
  35645. }
  35646. get serializable() {
  35647. return {
  35648. parsedData: this._metadataMap,
  35649. rawData: this._data
  35650. };
  35651. }
  35652. }
  35653. ;// CONCATENATED MODULE: ./src/core/decrypt_stream.js
  35654. const chunkSize = 512;
  35655. class DecryptStream extends DecodeStream {
  35656. constructor(str, maybeLength, decrypt) {
  35657. super(maybeLength);
  35658. this.str = str;
  35659. this.dict = str.dict;
  35660. this.decrypt = decrypt;
  35661. this.nextChunk = null;
  35662. this.initialized = false;
  35663. }
  35664. readBlock() {
  35665. let chunk;
  35666. if (this.initialized) {
  35667. chunk = this.nextChunk;
  35668. } else {
  35669. chunk = this.str.getBytes(chunkSize);
  35670. this.initialized = true;
  35671. }
  35672. if (!chunk || chunk.length === 0) {
  35673. this.eof = true;
  35674. return;
  35675. }
  35676. this.nextChunk = this.str.getBytes(chunkSize);
  35677. const hasMoreData = this.nextChunk?.length > 0;
  35678. const decrypt = this.decrypt;
  35679. chunk = decrypt(chunk, !hasMoreData);
  35680. const bufferLength = this.bufferLength,
  35681. newLength = bufferLength + chunk.length,
  35682. buffer = this.ensureBuffer(newLength);
  35683. buffer.set(chunk, bufferLength);
  35684. this.bufferLength = newLength;
  35685. }
  35686. }
  35687. ;// CONCATENATED MODULE: ./src/core/crypto.js
  35688. class ARCFourCipher {
  35689. constructor(key) {
  35690. this.a = 0;
  35691. this.b = 0;
  35692. const s = new Uint8Array(256);
  35693. const keyLength = key.length;
  35694. for (let i = 0; i < 256; ++i) {
  35695. s[i] = i;
  35696. }
  35697. for (let i = 0, j = 0; i < 256; ++i) {
  35698. const tmp = s[i];
  35699. j = j + tmp + key[i % keyLength] & 0xff;
  35700. s[i] = s[j];
  35701. s[j] = tmp;
  35702. }
  35703. this.s = s;
  35704. }
  35705. encryptBlock(data) {
  35706. let a = this.a,
  35707. b = this.b;
  35708. const s = this.s;
  35709. const n = data.length;
  35710. const output = new Uint8Array(n);
  35711. for (let i = 0; i < n; ++i) {
  35712. a = a + 1 & 0xff;
  35713. const tmp = s[a];
  35714. b = b + tmp & 0xff;
  35715. const tmp2 = s[b];
  35716. s[a] = tmp2;
  35717. s[b] = tmp;
  35718. output[i] = data[i] ^ s[tmp + tmp2 & 0xff];
  35719. }
  35720. this.a = a;
  35721. this.b = b;
  35722. return output;
  35723. }
  35724. decryptBlock(data) {
  35725. return this.encryptBlock(data);
  35726. }
  35727. encrypt(data) {
  35728. return this.encryptBlock(data);
  35729. }
  35730. }
  35731. const calculateMD5 = function calculateMD5Closure() {
  35732. const r = new Uint8Array([7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  35733. const k = new Int32Array([-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632, 643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651, -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649, -145523070, -1120210379, 718787259, -343485551]);
  35734. function hash(data, offset, length) {
  35735. let h0 = 1732584193,
  35736. h1 = -271733879,
  35737. h2 = -1732584194,
  35738. h3 = 271733878;
  35739. const paddedLength = length + 72 & ~63;
  35740. const padded = new Uint8Array(paddedLength);
  35741. let i, j;
  35742. for (i = 0; i < length; ++i) {
  35743. padded[i] = data[offset++];
  35744. }
  35745. padded[i++] = 0x80;
  35746. const n = paddedLength - 8;
  35747. while (i < n) {
  35748. padded[i++] = 0;
  35749. }
  35750. padded[i++] = length << 3 & 0xff;
  35751. padded[i++] = length >> 5 & 0xff;
  35752. padded[i++] = length >> 13 & 0xff;
  35753. padded[i++] = length >> 21 & 0xff;
  35754. padded[i++] = length >>> 29 & 0xff;
  35755. padded[i++] = 0;
  35756. padded[i++] = 0;
  35757. padded[i++] = 0;
  35758. const w = new Int32Array(16);
  35759. for (i = 0; i < paddedLength;) {
  35760. for (j = 0; j < 16; ++j, i += 4) {
  35761. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  35762. }
  35763. let a = h0,
  35764. b = h1,
  35765. c = h2,
  35766. d = h3,
  35767. f,
  35768. g;
  35769. for (j = 0; j < 64; ++j) {
  35770. if (j < 16) {
  35771. f = b & c | ~b & d;
  35772. g = j;
  35773. } else if (j < 32) {
  35774. f = d & b | ~d & c;
  35775. g = 5 * j + 1 & 15;
  35776. } else if (j < 48) {
  35777. f = b ^ c ^ d;
  35778. g = 3 * j + 5 & 15;
  35779. } else {
  35780. f = c ^ (b | ~d);
  35781. g = 7 * j & 15;
  35782. }
  35783. const tmp = d,
  35784. rotateArg = a + f + k[j] + w[g] | 0,
  35785. rotate = r[j];
  35786. d = c;
  35787. c = b;
  35788. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  35789. a = tmp;
  35790. }
  35791. h0 = h0 + a | 0;
  35792. h1 = h1 + b | 0;
  35793. h2 = h2 + c | 0;
  35794. h3 = h3 + d | 0;
  35795. }
  35796. return new Uint8Array([h0 & 0xFF, h0 >> 8 & 0xFF, h0 >> 16 & 0xFF, h0 >>> 24 & 0xFF, h1 & 0xFF, h1 >> 8 & 0xFF, h1 >> 16 & 0xFF, h1 >>> 24 & 0xFF, h2 & 0xFF, h2 >> 8 & 0xFF, h2 >> 16 & 0xFF, h2 >>> 24 & 0xFF, h3 & 0xFF, h3 >> 8 & 0xFF, h3 >> 16 & 0xFF, h3 >>> 24 & 0xFF]);
  35797. }
  35798. return hash;
  35799. }();
  35800. class Word64 {
  35801. constructor(highInteger, lowInteger) {
  35802. this.high = highInteger | 0;
  35803. this.low = lowInteger | 0;
  35804. }
  35805. and(word) {
  35806. this.high &= word.high;
  35807. this.low &= word.low;
  35808. }
  35809. xor(word) {
  35810. this.high ^= word.high;
  35811. this.low ^= word.low;
  35812. }
  35813. or(word) {
  35814. this.high |= word.high;
  35815. this.low |= word.low;
  35816. }
  35817. shiftRight(places) {
  35818. if (places >= 32) {
  35819. this.low = this.high >>> places - 32 | 0;
  35820. this.high = 0;
  35821. } else {
  35822. this.low = this.low >>> places | this.high << 32 - places;
  35823. this.high = this.high >>> places | 0;
  35824. }
  35825. }
  35826. shiftLeft(places) {
  35827. if (places >= 32) {
  35828. this.high = this.low << places - 32;
  35829. this.low = 0;
  35830. } else {
  35831. this.high = this.high << places | this.low >>> 32 - places;
  35832. this.low <<= places;
  35833. }
  35834. }
  35835. rotateRight(places) {
  35836. let low, high;
  35837. if (places & 32) {
  35838. high = this.low;
  35839. low = this.high;
  35840. } else {
  35841. low = this.low;
  35842. high = this.high;
  35843. }
  35844. places &= 31;
  35845. this.low = low >>> places | high << 32 - places;
  35846. this.high = high >>> places | low << 32 - places;
  35847. }
  35848. not() {
  35849. this.high = ~this.high;
  35850. this.low = ~this.low;
  35851. }
  35852. add(word) {
  35853. const lowAdd = (this.low >>> 0) + (word.low >>> 0);
  35854. let highAdd = (this.high >>> 0) + (word.high >>> 0);
  35855. if (lowAdd > 0xffffffff) {
  35856. highAdd += 1;
  35857. }
  35858. this.low = lowAdd | 0;
  35859. this.high = highAdd | 0;
  35860. }
  35861. copyTo(bytes, offset) {
  35862. bytes[offset] = this.high >>> 24 & 0xff;
  35863. bytes[offset + 1] = this.high >> 16 & 0xff;
  35864. bytes[offset + 2] = this.high >> 8 & 0xff;
  35865. bytes[offset + 3] = this.high & 0xff;
  35866. bytes[offset + 4] = this.low >>> 24 & 0xff;
  35867. bytes[offset + 5] = this.low >> 16 & 0xff;
  35868. bytes[offset + 6] = this.low >> 8 & 0xff;
  35869. bytes[offset + 7] = this.low & 0xff;
  35870. }
  35871. assign(word) {
  35872. this.high = word.high;
  35873. this.low = word.low;
  35874. }
  35875. }
  35876. const calculateSHA256 = function calculateSHA256Closure() {
  35877. function rotr(x, n) {
  35878. return x >>> n | x << 32 - n;
  35879. }
  35880. function ch(x, y, z) {
  35881. return x & y ^ ~x & z;
  35882. }
  35883. function maj(x, y, z) {
  35884. return x & y ^ x & z ^ y & z;
  35885. }
  35886. function sigma(x) {
  35887. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  35888. }
  35889. function sigmaPrime(x) {
  35890. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  35891. }
  35892. function littleSigma(x) {
  35893. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  35894. }
  35895. function littleSigmaPrime(x) {
  35896. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  35897. }
  35898. const k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  35899. function hash(data, offset, length) {
  35900. let h0 = 0x6a09e667,
  35901. h1 = 0xbb67ae85,
  35902. h2 = 0x3c6ef372,
  35903. h3 = 0xa54ff53a,
  35904. h4 = 0x510e527f,
  35905. h5 = 0x9b05688c,
  35906. h6 = 0x1f83d9ab,
  35907. h7 = 0x5be0cd19;
  35908. const paddedLength = Math.ceil((length + 9) / 64) * 64;
  35909. const padded = new Uint8Array(paddedLength);
  35910. let i, j;
  35911. for (i = 0; i < length; ++i) {
  35912. padded[i] = data[offset++];
  35913. }
  35914. padded[i++] = 0x80;
  35915. const n = paddedLength - 8;
  35916. while (i < n) {
  35917. padded[i++] = 0;
  35918. }
  35919. padded[i++] = 0;
  35920. padded[i++] = 0;
  35921. padded[i++] = 0;
  35922. padded[i++] = length >>> 29 & 0xff;
  35923. padded[i++] = length >> 21 & 0xff;
  35924. padded[i++] = length >> 13 & 0xff;
  35925. padded[i++] = length >> 5 & 0xff;
  35926. padded[i++] = length << 3 & 0xff;
  35927. const w = new Uint32Array(64);
  35928. for (i = 0; i < paddedLength;) {
  35929. for (j = 0; j < 16; ++j) {
  35930. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  35931. i += 4;
  35932. }
  35933. for (j = 16; j < 64; ++j) {
  35934. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  35935. }
  35936. let a = h0,
  35937. b = h1,
  35938. c = h2,
  35939. d = h3,
  35940. e = h4,
  35941. f = h5,
  35942. g = h6,
  35943. h = h7,
  35944. t1,
  35945. t2;
  35946. for (j = 0; j < 64; ++j) {
  35947. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  35948. t2 = sigma(a) + maj(a, b, c);
  35949. h = g;
  35950. g = f;
  35951. f = e;
  35952. e = d + t1 | 0;
  35953. d = c;
  35954. c = b;
  35955. b = a;
  35956. a = t1 + t2 | 0;
  35957. }
  35958. h0 = h0 + a | 0;
  35959. h1 = h1 + b | 0;
  35960. h2 = h2 + c | 0;
  35961. h3 = h3 + d | 0;
  35962. h4 = h4 + e | 0;
  35963. h5 = h5 + f | 0;
  35964. h6 = h6 + g | 0;
  35965. h7 = h7 + h | 0;
  35966. }
  35967. return new Uint8Array([h0 >> 24 & 0xFF, h0 >> 16 & 0xFF, h0 >> 8 & 0xFF, h0 & 0xFF, h1 >> 24 & 0xFF, h1 >> 16 & 0xFF, h1 >> 8 & 0xFF, h1 & 0xFF, h2 >> 24 & 0xFF, h2 >> 16 & 0xFF, h2 >> 8 & 0xFF, h2 & 0xFF, h3 >> 24 & 0xFF, h3 >> 16 & 0xFF, h3 >> 8 & 0xFF, h3 & 0xFF, h4 >> 24 & 0xFF, h4 >> 16 & 0xFF, h4 >> 8 & 0xFF, h4 & 0xFF, h5 >> 24 & 0xFF, h5 >> 16 & 0xFF, h5 >> 8 & 0xFF, h5 & 0xFF, h6 >> 24 & 0xFF, h6 >> 16 & 0xFF, h6 >> 8 & 0xFF, h6 & 0xFF, h7 >> 24 & 0xFF, h7 >> 16 & 0xFF, h7 >> 8 & 0xFF, h7 & 0xFF]);
  35968. }
  35969. return hash;
  35970. }();
  35971. const calculateSHA512 = function calculateSHA512Closure() {
  35972. function ch(result, x, y, z, tmp) {
  35973. result.assign(x);
  35974. result.and(y);
  35975. tmp.assign(x);
  35976. tmp.not();
  35977. tmp.and(z);
  35978. result.xor(tmp);
  35979. }
  35980. function maj(result, x, y, z, tmp) {
  35981. result.assign(x);
  35982. result.and(y);
  35983. tmp.assign(x);
  35984. tmp.and(z);
  35985. result.xor(tmp);
  35986. tmp.assign(y);
  35987. tmp.and(z);
  35988. result.xor(tmp);
  35989. }
  35990. function sigma(result, x, tmp) {
  35991. result.assign(x);
  35992. result.rotateRight(28);
  35993. tmp.assign(x);
  35994. tmp.rotateRight(34);
  35995. result.xor(tmp);
  35996. tmp.assign(x);
  35997. tmp.rotateRight(39);
  35998. result.xor(tmp);
  35999. }
  36000. function sigmaPrime(result, x, tmp) {
  36001. result.assign(x);
  36002. result.rotateRight(14);
  36003. tmp.assign(x);
  36004. tmp.rotateRight(18);
  36005. result.xor(tmp);
  36006. tmp.assign(x);
  36007. tmp.rotateRight(41);
  36008. result.xor(tmp);
  36009. }
  36010. function littleSigma(result, x, tmp) {
  36011. result.assign(x);
  36012. result.rotateRight(1);
  36013. tmp.assign(x);
  36014. tmp.rotateRight(8);
  36015. result.xor(tmp);
  36016. tmp.assign(x);
  36017. tmp.shiftRight(7);
  36018. result.xor(tmp);
  36019. }
  36020. function littleSigmaPrime(result, x, tmp) {
  36021. result.assign(x);
  36022. result.rotateRight(19);
  36023. tmp.assign(x);
  36024. tmp.rotateRight(61);
  36025. result.xor(tmp);
  36026. tmp.assign(x);
  36027. tmp.shiftRight(6);
  36028. result.xor(tmp);
  36029. }
  36030. const k = [new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd), new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc), new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019), new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118), new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe), new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2), new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1), new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694), new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3), new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65), new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483), new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5), new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210), new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4), new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725), new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70), new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926), new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df), new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8), new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b), new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001), new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30), new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910), new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8), new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53), new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8), new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb), new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3), new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60), new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec), new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9), new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b), new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207), new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178), new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6), new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b), new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493), new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c), new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a), new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  36031. function hash(data, offset, length, mode384 = false) {
  36032. let h0, h1, h2, h3, h4, h5, h6, h7;
  36033. if (!mode384) {
  36034. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  36035. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  36036. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  36037. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  36038. h4 = new Word64(0x510e527f, 0xade682d1);
  36039. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  36040. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  36041. h7 = new Word64(0x5be0cd19, 0x137e2179);
  36042. } else {
  36043. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  36044. h1 = new Word64(0x629a292a, 0x367cd507);
  36045. h2 = new Word64(0x9159015a, 0x3070dd17);
  36046. h3 = new Word64(0x152fecd8, 0xf70e5939);
  36047. h4 = new Word64(0x67332667, 0xffc00b31);
  36048. h5 = new Word64(0x8eb44a87, 0x68581511);
  36049. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  36050. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  36051. }
  36052. const paddedLength = Math.ceil((length + 17) / 128) * 128;
  36053. const padded = new Uint8Array(paddedLength);
  36054. let i, j;
  36055. for (i = 0; i < length; ++i) {
  36056. padded[i] = data[offset++];
  36057. }
  36058. padded[i++] = 0x80;
  36059. const n = paddedLength - 16;
  36060. while (i < n) {
  36061. padded[i++] = 0;
  36062. }
  36063. padded[i++] = 0;
  36064. padded[i++] = 0;
  36065. padded[i++] = 0;
  36066. padded[i++] = 0;
  36067. padded[i++] = 0;
  36068. padded[i++] = 0;
  36069. padded[i++] = 0;
  36070. padded[i++] = 0;
  36071. padded[i++] = 0;
  36072. padded[i++] = 0;
  36073. padded[i++] = 0;
  36074. padded[i++] = length >>> 29 & 0xff;
  36075. padded[i++] = length >> 21 & 0xff;
  36076. padded[i++] = length >> 13 & 0xff;
  36077. padded[i++] = length >> 5 & 0xff;
  36078. padded[i++] = length << 3 & 0xff;
  36079. const w = new Array(80);
  36080. for (i = 0; i < 80; i++) {
  36081. w[i] = new Word64(0, 0);
  36082. }
  36083. let a = new Word64(0, 0),
  36084. b = new Word64(0, 0),
  36085. c = new Word64(0, 0);
  36086. let d = new Word64(0, 0),
  36087. e = new Word64(0, 0),
  36088. f = new Word64(0, 0);
  36089. let g = new Word64(0, 0),
  36090. h = new Word64(0, 0);
  36091. const t1 = new Word64(0, 0),
  36092. t2 = new Word64(0, 0);
  36093. const tmp1 = new Word64(0, 0),
  36094. tmp2 = new Word64(0, 0);
  36095. let tmp3;
  36096. for (i = 0; i < paddedLength;) {
  36097. for (j = 0; j < 16; ++j) {
  36098. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  36099. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  36100. i += 8;
  36101. }
  36102. for (j = 16; j < 80; ++j) {
  36103. tmp3 = w[j];
  36104. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  36105. tmp3.add(w[j - 7]);
  36106. littleSigma(tmp1, w[j - 15], tmp2);
  36107. tmp3.add(tmp1);
  36108. tmp3.add(w[j - 16]);
  36109. }
  36110. a.assign(h0);
  36111. b.assign(h1);
  36112. c.assign(h2);
  36113. d.assign(h3);
  36114. e.assign(h4);
  36115. f.assign(h5);
  36116. g.assign(h6);
  36117. h.assign(h7);
  36118. for (j = 0; j < 80; ++j) {
  36119. t1.assign(h);
  36120. sigmaPrime(tmp1, e, tmp2);
  36121. t1.add(tmp1);
  36122. ch(tmp1, e, f, g, tmp2);
  36123. t1.add(tmp1);
  36124. t1.add(k[j]);
  36125. t1.add(w[j]);
  36126. sigma(t2, a, tmp2);
  36127. maj(tmp1, a, b, c, tmp2);
  36128. t2.add(tmp1);
  36129. tmp3 = h;
  36130. h = g;
  36131. g = f;
  36132. f = e;
  36133. d.add(t1);
  36134. e = d;
  36135. d = c;
  36136. c = b;
  36137. b = a;
  36138. tmp3.assign(t1);
  36139. tmp3.add(t2);
  36140. a = tmp3;
  36141. }
  36142. h0.add(a);
  36143. h1.add(b);
  36144. h2.add(c);
  36145. h3.add(d);
  36146. h4.add(e);
  36147. h5.add(f);
  36148. h6.add(g);
  36149. h7.add(h);
  36150. }
  36151. let result;
  36152. if (!mode384) {
  36153. result = new Uint8Array(64);
  36154. h0.copyTo(result, 0);
  36155. h1.copyTo(result, 8);
  36156. h2.copyTo(result, 16);
  36157. h3.copyTo(result, 24);
  36158. h4.copyTo(result, 32);
  36159. h5.copyTo(result, 40);
  36160. h6.copyTo(result, 48);
  36161. h7.copyTo(result, 56);
  36162. } else {
  36163. result = new Uint8Array(48);
  36164. h0.copyTo(result, 0);
  36165. h1.copyTo(result, 8);
  36166. h2.copyTo(result, 16);
  36167. h3.copyTo(result, 24);
  36168. h4.copyTo(result, 32);
  36169. h5.copyTo(result, 40);
  36170. }
  36171. return result;
  36172. }
  36173. return hash;
  36174. }();
  36175. function calculateSHA384(data, offset, length) {
  36176. return calculateSHA512(data, offset, length, true);
  36177. }
  36178. class NullCipher {
  36179. decryptBlock(data) {
  36180. return data;
  36181. }
  36182. encrypt(data) {
  36183. return data;
  36184. }
  36185. }
  36186. class AESBaseCipher {
  36187. constructor() {
  36188. if (this.constructor === AESBaseCipher) {
  36189. unreachable("Cannot initialize AESBaseCipher.");
  36190. }
  36191. this._s = new Uint8Array([0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16]);
  36192. this._inv_s = new Uint8Array([0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d]);
  36193. this._mix = new Uint32Array([0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb, 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381, 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf, 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66, 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28, 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012, 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec, 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e, 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd, 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7, 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89, 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b, 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815, 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f, 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa, 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8, 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36, 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c, 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742, 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea, 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4, 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e, 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360, 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502, 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87, 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd, 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3, 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621, 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f, 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55, 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26, 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844, 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba, 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480, 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce, 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67, 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929, 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713, 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed, 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f, 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  36194. this._mixCol = new Uint8Array(256);
  36195. for (let i = 0; i < 256; i++) {
  36196. this._mixCol[i] = i < 128 ? i << 1 : i << 1 ^ 0x1b;
  36197. }
  36198. this.buffer = new Uint8Array(16);
  36199. this.bufferPosition = 0;
  36200. }
  36201. _expandKey(cipherKey) {
  36202. unreachable("Cannot call `_expandKey` on the base class");
  36203. }
  36204. _decrypt(input, key) {
  36205. let t, u, v;
  36206. const state = new Uint8Array(16);
  36207. state.set(input);
  36208. for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
  36209. state[j] ^= key[k];
  36210. }
  36211. for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
  36212. t = state[13];
  36213. state[13] = state[9];
  36214. state[9] = state[5];
  36215. state[5] = state[1];
  36216. state[1] = t;
  36217. t = state[14];
  36218. u = state[10];
  36219. state[14] = state[6];
  36220. state[10] = state[2];
  36221. state[6] = t;
  36222. state[2] = u;
  36223. t = state[15];
  36224. u = state[11];
  36225. v = state[7];
  36226. state[15] = state[3];
  36227. state[11] = t;
  36228. state[7] = u;
  36229. state[3] = v;
  36230. for (let j = 0; j < 16; ++j) {
  36231. state[j] = this._inv_s[state[j]];
  36232. }
  36233. for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
  36234. state[j] ^= key[k];
  36235. }
  36236. for (let j = 0; j < 16; j += 4) {
  36237. const s0 = this._mix[state[j]];
  36238. const s1 = this._mix[state[j + 1]];
  36239. const s2 = this._mix[state[j + 2]];
  36240. const s3 = this._mix[state[j + 3]];
  36241. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  36242. state[j] = t >>> 24 & 0xff;
  36243. state[j + 1] = t >> 16 & 0xff;
  36244. state[j + 2] = t >> 8 & 0xff;
  36245. state[j + 3] = t & 0xff;
  36246. }
  36247. }
  36248. t = state[13];
  36249. state[13] = state[9];
  36250. state[9] = state[5];
  36251. state[5] = state[1];
  36252. state[1] = t;
  36253. t = state[14];
  36254. u = state[10];
  36255. state[14] = state[6];
  36256. state[10] = state[2];
  36257. state[6] = t;
  36258. state[2] = u;
  36259. t = state[15];
  36260. u = state[11];
  36261. v = state[7];
  36262. state[15] = state[3];
  36263. state[11] = t;
  36264. state[7] = u;
  36265. state[3] = v;
  36266. for (let j = 0; j < 16; ++j) {
  36267. state[j] = this._inv_s[state[j]];
  36268. state[j] ^= key[j];
  36269. }
  36270. return state;
  36271. }
  36272. _encrypt(input, key) {
  36273. const s = this._s;
  36274. let t, u, v;
  36275. const state = new Uint8Array(16);
  36276. state.set(input);
  36277. for (let j = 0; j < 16; ++j) {
  36278. state[j] ^= key[j];
  36279. }
  36280. for (let i = 1; i < this._cyclesOfRepetition; i++) {
  36281. for (let j = 0; j < 16; ++j) {
  36282. state[j] = s[state[j]];
  36283. }
  36284. v = state[1];
  36285. state[1] = state[5];
  36286. state[5] = state[9];
  36287. state[9] = state[13];
  36288. state[13] = v;
  36289. v = state[2];
  36290. u = state[6];
  36291. state[2] = state[10];
  36292. state[6] = state[14];
  36293. state[10] = v;
  36294. state[14] = u;
  36295. v = state[3];
  36296. u = state[7];
  36297. t = state[11];
  36298. state[3] = state[15];
  36299. state[7] = v;
  36300. state[11] = u;
  36301. state[15] = t;
  36302. for (let j = 0; j < 16; j += 4) {
  36303. const s0 = state[j + 0];
  36304. const s1 = state[j + 1];
  36305. const s2 = state[j + 2];
  36306. const s3 = state[j + 3];
  36307. t = s0 ^ s1 ^ s2 ^ s3;
  36308. state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
  36309. state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
  36310. state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
  36311. state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
  36312. }
  36313. for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
  36314. state[j] ^= key[k];
  36315. }
  36316. }
  36317. for (let j = 0; j < 16; ++j) {
  36318. state[j] = s[state[j]];
  36319. }
  36320. v = state[1];
  36321. state[1] = state[5];
  36322. state[5] = state[9];
  36323. state[9] = state[13];
  36324. state[13] = v;
  36325. v = state[2];
  36326. u = state[6];
  36327. state[2] = state[10];
  36328. state[6] = state[14];
  36329. state[10] = v;
  36330. state[14] = u;
  36331. v = state[3];
  36332. u = state[7];
  36333. t = state[11];
  36334. state[3] = state[15];
  36335. state[7] = v;
  36336. state[11] = u;
  36337. state[15] = t;
  36338. for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
  36339. state[j] ^= key[k];
  36340. }
  36341. return state;
  36342. }
  36343. _decryptBlock2(data, finalize) {
  36344. const sourceLength = data.length;
  36345. let buffer = this.buffer,
  36346. bufferLength = this.bufferPosition;
  36347. const result = [];
  36348. let iv = this.iv;
  36349. for (let i = 0; i < sourceLength; ++i) {
  36350. buffer[bufferLength] = data[i];
  36351. ++bufferLength;
  36352. if (bufferLength < 16) {
  36353. continue;
  36354. }
  36355. const plain = this._decrypt(buffer, this._key);
  36356. for (let j = 0; j < 16; ++j) {
  36357. plain[j] ^= iv[j];
  36358. }
  36359. iv = buffer;
  36360. result.push(plain);
  36361. buffer = new Uint8Array(16);
  36362. bufferLength = 0;
  36363. }
  36364. this.buffer = buffer;
  36365. this.bufferLength = bufferLength;
  36366. this.iv = iv;
  36367. if (result.length === 0) {
  36368. return new Uint8Array(0);
  36369. }
  36370. let outputLength = 16 * result.length;
  36371. if (finalize) {
  36372. const lastBlock = result.at(-1);
  36373. let psLen = lastBlock[15];
  36374. if (psLen <= 16) {
  36375. for (let i = 15, ii = 16 - psLen; i >= ii; --i) {
  36376. if (lastBlock[i] !== psLen) {
  36377. psLen = 0;
  36378. break;
  36379. }
  36380. }
  36381. outputLength -= psLen;
  36382. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  36383. }
  36384. }
  36385. const output = new Uint8Array(outputLength);
  36386. for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36387. output.set(result[i], j);
  36388. }
  36389. return output;
  36390. }
  36391. decryptBlock(data, finalize, iv = null) {
  36392. const sourceLength = data.length;
  36393. const buffer = this.buffer;
  36394. let bufferLength = this.bufferPosition;
  36395. if (iv) {
  36396. this.iv = iv;
  36397. } else {
  36398. for (let i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  36399. buffer[bufferLength] = data[i];
  36400. }
  36401. if (bufferLength < 16) {
  36402. this.bufferLength = bufferLength;
  36403. return new Uint8Array(0);
  36404. }
  36405. this.iv = buffer;
  36406. data = data.subarray(16);
  36407. }
  36408. this.buffer = new Uint8Array(16);
  36409. this.bufferLength = 0;
  36410. this.decryptBlock = this._decryptBlock2;
  36411. return this.decryptBlock(data, finalize);
  36412. }
  36413. encrypt(data, iv) {
  36414. const sourceLength = data.length;
  36415. let buffer = this.buffer,
  36416. bufferLength = this.bufferPosition;
  36417. const result = [];
  36418. if (!iv) {
  36419. iv = new Uint8Array(16);
  36420. }
  36421. for (let i = 0; i < sourceLength; ++i) {
  36422. buffer[bufferLength] = data[i];
  36423. ++bufferLength;
  36424. if (bufferLength < 16) {
  36425. continue;
  36426. }
  36427. for (let j = 0; j < 16; ++j) {
  36428. buffer[j] ^= iv[j];
  36429. }
  36430. const cipher = this._encrypt(buffer, this._key);
  36431. iv = cipher;
  36432. result.push(cipher);
  36433. buffer = new Uint8Array(16);
  36434. bufferLength = 0;
  36435. }
  36436. this.buffer = buffer;
  36437. this.bufferLength = bufferLength;
  36438. this.iv = iv;
  36439. if (result.length === 0) {
  36440. return new Uint8Array(0);
  36441. }
  36442. const outputLength = 16 * result.length;
  36443. const output = new Uint8Array(outputLength);
  36444. for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36445. output.set(result[i], j);
  36446. }
  36447. return output;
  36448. }
  36449. }
  36450. class AES128Cipher extends AESBaseCipher {
  36451. constructor(key) {
  36452. super();
  36453. this._cyclesOfRepetition = 10;
  36454. this._keySize = 160;
  36455. this._rcon = new Uint8Array([0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d]);
  36456. this._key = this._expandKey(key);
  36457. }
  36458. _expandKey(cipherKey) {
  36459. const b = 176;
  36460. const s = this._s;
  36461. const rcon = this._rcon;
  36462. const result = new Uint8Array(b);
  36463. result.set(cipherKey);
  36464. for (let j = 16, i = 1; j < b; ++i) {
  36465. let t1 = result[j - 3];
  36466. let t2 = result[j - 2];
  36467. let t3 = result[j - 1];
  36468. let t4 = result[j - 4];
  36469. t1 = s[t1];
  36470. t2 = s[t2];
  36471. t3 = s[t3];
  36472. t4 = s[t4];
  36473. t1 ^= rcon[i];
  36474. for (let n = 0; n < 4; ++n) {
  36475. result[j] = t1 ^= result[j - 16];
  36476. j++;
  36477. result[j] = t2 ^= result[j - 16];
  36478. j++;
  36479. result[j] = t3 ^= result[j - 16];
  36480. j++;
  36481. result[j] = t4 ^= result[j - 16];
  36482. j++;
  36483. }
  36484. }
  36485. return result;
  36486. }
  36487. }
  36488. class AES256Cipher extends AESBaseCipher {
  36489. constructor(key) {
  36490. super();
  36491. this._cyclesOfRepetition = 14;
  36492. this._keySize = 224;
  36493. this._key = this._expandKey(key);
  36494. }
  36495. _expandKey(cipherKey) {
  36496. const b = 240;
  36497. const s = this._s;
  36498. const result = new Uint8Array(b);
  36499. result.set(cipherKey);
  36500. let r = 1;
  36501. let t1, t2, t3, t4;
  36502. for (let j = 32, i = 1; j < b; ++i) {
  36503. if (j % 32 === 16) {
  36504. t1 = s[t1];
  36505. t2 = s[t2];
  36506. t3 = s[t3];
  36507. t4 = s[t4];
  36508. } else if (j % 32 === 0) {
  36509. t1 = result[j - 3];
  36510. t2 = result[j - 2];
  36511. t3 = result[j - 1];
  36512. t4 = result[j - 4];
  36513. t1 = s[t1];
  36514. t2 = s[t2];
  36515. t3 = s[t3];
  36516. t4 = s[t4];
  36517. t1 ^= r;
  36518. if ((r <<= 1) >= 256) {
  36519. r = (r ^ 0x1b) & 0xff;
  36520. }
  36521. }
  36522. for (let n = 0; n < 4; ++n) {
  36523. result[j] = t1 ^= result[j - 32];
  36524. j++;
  36525. result[j] = t2 ^= result[j - 32];
  36526. j++;
  36527. result[j] = t3 ^= result[j - 32];
  36528. j++;
  36529. result[j] = t4 ^= result[j - 32];
  36530. j++;
  36531. }
  36532. }
  36533. return result;
  36534. }
  36535. }
  36536. class PDF17 {
  36537. checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  36538. const hashData = new Uint8Array(password.length + 56);
  36539. hashData.set(password, 0);
  36540. hashData.set(ownerValidationSalt, password.length);
  36541. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  36542. const result = calculateSHA256(hashData, 0, hashData.length);
  36543. return isArrayEqual(result, ownerPassword);
  36544. }
  36545. checkUserPassword(password, userValidationSalt, userPassword) {
  36546. const hashData = new Uint8Array(password.length + 8);
  36547. hashData.set(password, 0);
  36548. hashData.set(userValidationSalt, password.length);
  36549. const result = calculateSHA256(hashData, 0, hashData.length);
  36550. return isArrayEqual(result, userPassword);
  36551. }
  36552. getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  36553. const hashData = new Uint8Array(password.length + 56);
  36554. hashData.set(password, 0);
  36555. hashData.set(ownerKeySalt, password.length);
  36556. hashData.set(userBytes, password.length + ownerKeySalt.length);
  36557. const key = calculateSHA256(hashData, 0, hashData.length);
  36558. const cipher = new AES256Cipher(key);
  36559. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  36560. }
  36561. getUserKey(password, userKeySalt, userEncryption) {
  36562. const hashData = new Uint8Array(password.length + 8);
  36563. hashData.set(password, 0);
  36564. hashData.set(userKeySalt, password.length);
  36565. const key = calculateSHA256(hashData, 0, hashData.length);
  36566. const cipher = new AES256Cipher(key);
  36567. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  36568. }
  36569. }
  36570. class PDF20 {
  36571. _hash(password, input, userBytes) {
  36572. let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  36573. let e = [0];
  36574. let i = 0;
  36575. while (i < 64 || e.at(-1) > i - 32) {
  36576. const combinedLength = password.length + k.length + userBytes.length,
  36577. combinedArray = new Uint8Array(combinedLength);
  36578. let writeOffset = 0;
  36579. combinedArray.set(password, writeOffset);
  36580. writeOffset += password.length;
  36581. combinedArray.set(k, writeOffset);
  36582. writeOffset += k.length;
  36583. combinedArray.set(userBytes, writeOffset);
  36584. const k1 = new Uint8Array(combinedLength * 64);
  36585. for (let j = 0, pos = 0; j < 64; j++, pos += combinedLength) {
  36586. k1.set(combinedArray, pos);
  36587. }
  36588. const cipher = new AES128Cipher(k.subarray(0, 16));
  36589. e = cipher.encrypt(k1, k.subarray(16, 32));
  36590. const remainder = e.slice(0, 16).reduce((a, b) => a + b, 0) % 3;
  36591. if (remainder === 0) {
  36592. k = calculateSHA256(e, 0, e.length);
  36593. } else if (remainder === 1) {
  36594. k = calculateSHA384(e, 0, e.length);
  36595. } else if (remainder === 2) {
  36596. k = calculateSHA512(e, 0, e.length);
  36597. }
  36598. i++;
  36599. }
  36600. return k.subarray(0, 32);
  36601. }
  36602. checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  36603. const hashData = new Uint8Array(password.length + 56);
  36604. hashData.set(password, 0);
  36605. hashData.set(ownerValidationSalt, password.length);
  36606. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  36607. const result = this._hash(password, hashData, userBytes);
  36608. return isArrayEqual(result, ownerPassword);
  36609. }
  36610. checkUserPassword(password, userValidationSalt, userPassword) {
  36611. const hashData = new Uint8Array(password.length + 8);
  36612. hashData.set(password, 0);
  36613. hashData.set(userValidationSalt, password.length);
  36614. const result = this._hash(password, hashData, []);
  36615. return isArrayEqual(result, userPassword);
  36616. }
  36617. getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  36618. const hashData = new Uint8Array(password.length + 56);
  36619. hashData.set(password, 0);
  36620. hashData.set(ownerKeySalt, password.length);
  36621. hashData.set(userBytes, password.length + ownerKeySalt.length);
  36622. const key = this._hash(password, hashData, userBytes);
  36623. const cipher = new AES256Cipher(key);
  36624. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  36625. }
  36626. getUserKey(password, userKeySalt, userEncryption) {
  36627. const hashData = new Uint8Array(password.length + 8);
  36628. hashData.set(password, 0);
  36629. hashData.set(userKeySalt, password.length);
  36630. const key = this._hash(password, hashData, []);
  36631. const cipher = new AES256Cipher(key);
  36632. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  36633. }
  36634. }
  36635. class CipherTransform {
  36636. constructor(stringCipherConstructor, streamCipherConstructor) {
  36637. this.StringCipherConstructor = stringCipherConstructor;
  36638. this.StreamCipherConstructor = streamCipherConstructor;
  36639. }
  36640. createStream(stream, length) {
  36641. const cipher = new this.StreamCipherConstructor();
  36642. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  36643. return cipher.decryptBlock(data, finalize);
  36644. });
  36645. }
  36646. decryptString(s) {
  36647. const cipher = new this.StringCipherConstructor();
  36648. let data = stringToBytes(s);
  36649. data = cipher.decryptBlock(data, true);
  36650. return bytesToString(data);
  36651. }
  36652. encryptString(s) {
  36653. const cipher = new this.StringCipherConstructor();
  36654. if (cipher instanceof AESBaseCipher) {
  36655. const strLen = s.length;
  36656. const pad = 16 - strLen % 16;
  36657. s += String.fromCharCode(pad).repeat(pad);
  36658. const iv = new Uint8Array(16);
  36659. if (typeof crypto !== "undefined") {
  36660. crypto.getRandomValues(iv);
  36661. } else {
  36662. for (let i = 0; i < 16; i++) {
  36663. iv[i] = Math.floor(256 * Math.random());
  36664. }
  36665. }
  36666. let data = stringToBytes(s);
  36667. data = cipher.encrypt(data, iv);
  36668. const buf = new Uint8Array(16 + data.length);
  36669. buf.set(iv);
  36670. buf.set(data, 16);
  36671. return bytesToString(buf);
  36672. }
  36673. let data = stringToBytes(s);
  36674. data = cipher.encrypt(data);
  36675. return bytesToString(data);
  36676. }
  36677. }
  36678. class CipherTransformFactory {
  36679. static #defaultPasswordBytes = new Uint8Array([0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a]);
  36680. #createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  36681. if (password) {
  36682. const passwordLength = Math.min(127, password.length);
  36683. password = password.subarray(0, passwordLength);
  36684. } else {
  36685. password = [];
  36686. }
  36687. const pdfAlgorithm = revision === 6 ? new PDF20() : new PDF17();
  36688. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  36689. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  36690. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  36691. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  36692. }
  36693. return null;
  36694. }
  36695. #prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  36696. const hashDataSize = 40 + ownerPassword.length + fileId.length;
  36697. const hashData = new Uint8Array(hashDataSize);
  36698. let i = 0,
  36699. j,
  36700. n;
  36701. if (password) {
  36702. n = Math.min(32, password.length);
  36703. for (; i < n; ++i) {
  36704. hashData[i] = password[i];
  36705. }
  36706. }
  36707. j = 0;
  36708. while (i < 32) {
  36709. hashData[i++] = CipherTransformFactory.#defaultPasswordBytes[j++];
  36710. }
  36711. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  36712. hashData[i++] = ownerPassword[j];
  36713. }
  36714. hashData[i++] = flags & 0xff;
  36715. hashData[i++] = flags >> 8 & 0xff;
  36716. hashData[i++] = flags >> 16 & 0xff;
  36717. hashData[i++] = flags >>> 24 & 0xff;
  36718. for (j = 0, n = fileId.length; j < n; ++j) {
  36719. hashData[i++] = fileId[j];
  36720. }
  36721. if (revision >= 4 && !encryptMetadata) {
  36722. hashData[i++] = 0xff;
  36723. hashData[i++] = 0xff;
  36724. hashData[i++] = 0xff;
  36725. hashData[i++] = 0xff;
  36726. }
  36727. let hash = calculateMD5(hashData, 0, i);
  36728. const keyLengthInBytes = keyLength >> 3;
  36729. if (revision >= 3) {
  36730. for (j = 0; j < 50; ++j) {
  36731. hash = calculateMD5(hash, 0, keyLengthInBytes);
  36732. }
  36733. }
  36734. const encryptionKey = hash.subarray(0, keyLengthInBytes);
  36735. let cipher, checkData;
  36736. if (revision >= 3) {
  36737. for (i = 0; i < 32; ++i) {
  36738. hashData[i] = CipherTransformFactory.#defaultPasswordBytes[i];
  36739. }
  36740. for (j = 0, n = fileId.length; j < n; ++j) {
  36741. hashData[i++] = fileId[j];
  36742. }
  36743. cipher = new ARCFourCipher(encryptionKey);
  36744. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  36745. n = encryptionKey.length;
  36746. const derivedKey = new Uint8Array(n);
  36747. for (j = 1; j <= 19; ++j) {
  36748. for (let k = 0; k < n; ++k) {
  36749. derivedKey[k] = encryptionKey[k] ^ j;
  36750. }
  36751. cipher = new ARCFourCipher(derivedKey);
  36752. checkData = cipher.encryptBlock(checkData);
  36753. }
  36754. for (j = 0, n = checkData.length; j < n; ++j) {
  36755. if (userPassword[j] !== checkData[j]) {
  36756. return null;
  36757. }
  36758. }
  36759. } else {
  36760. cipher = new ARCFourCipher(encryptionKey);
  36761. checkData = cipher.encryptBlock(CipherTransformFactory.#defaultPasswordBytes);
  36762. for (j = 0, n = checkData.length; j < n; ++j) {
  36763. if (userPassword[j] !== checkData[j]) {
  36764. return null;
  36765. }
  36766. }
  36767. }
  36768. return encryptionKey;
  36769. }
  36770. #decodeUserPassword(password, ownerPassword, revision, keyLength) {
  36771. const hashData = new Uint8Array(32);
  36772. let i = 0;
  36773. const n = Math.min(32, password.length);
  36774. for (; i < n; ++i) {
  36775. hashData[i] = password[i];
  36776. }
  36777. let j = 0;
  36778. while (i < 32) {
  36779. hashData[i++] = CipherTransformFactory.#defaultPasswordBytes[j++];
  36780. }
  36781. let hash = calculateMD5(hashData, 0, i);
  36782. const keyLengthInBytes = keyLength >> 3;
  36783. if (revision >= 3) {
  36784. for (j = 0; j < 50; ++j) {
  36785. hash = calculateMD5(hash, 0, hash.length);
  36786. }
  36787. }
  36788. let cipher, userPassword;
  36789. if (revision >= 3) {
  36790. userPassword = ownerPassword;
  36791. const derivedKey = new Uint8Array(keyLengthInBytes);
  36792. for (j = 19; j >= 0; j--) {
  36793. for (let k = 0; k < keyLengthInBytes; ++k) {
  36794. derivedKey[k] = hash[k] ^ j;
  36795. }
  36796. cipher = new ARCFourCipher(derivedKey);
  36797. userPassword = cipher.encryptBlock(userPassword);
  36798. }
  36799. } else {
  36800. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  36801. userPassword = cipher.encryptBlock(ownerPassword);
  36802. }
  36803. return userPassword;
  36804. }
  36805. #buildObjectKey(num, gen, encryptionKey, isAes = false) {
  36806. const key = new Uint8Array(encryptionKey.length + 9);
  36807. const n = encryptionKey.length;
  36808. let i;
  36809. for (i = 0; i < n; ++i) {
  36810. key[i] = encryptionKey[i];
  36811. }
  36812. key[i++] = num & 0xff;
  36813. key[i++] = num >> 8 & 0xff;
  36814. key[i++] = num >> 16 & 0xff;
  36815. key[i++] = gen & 0xff;
  36816. key[i++] = gen >> 8 & 0xff;
  36817. if (isAes) {
  36818. key[i++] = 0x73;
  36819. key[i++] = 0x41;
  36820. key[i++] = 0x6c;
  36821. key[i++] = 0x54;
  36822. }
  36823. const hash = calculateMD5(key, 0, i);
  36824. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  36825. }
  36826. #buildCipherConstructor(cf, name, num, gen, key) {
  36827. if (!(name instanceof Name)) {
  36828. throw new FormatError("Invalid crypt filter name.");
  36829. }
  36830. const self = this;
  36831. const cryptFilter = cf.get(name.name);
  36832. const cfm = cryptFilter?.get("CFM");
  36833. if (!cfm || cfm.name === "None") {
  36834. return function () {
  36835. return new NullCipher();
  36836. };
  36837. }
  36838. if (cfm.name === "V2") {
  36839. return function () {
  36840. return new ARCFourCipher(self.#buildObjectKey(num, gen, key, false));
  36841. };
  36842. }
  36843. if (cfm.name === "AESV2") {
  36844. return function () {
  36845. return new AES128Cipher(self.#buildObjectKey(num, gen, key, true));
  36846. };
  36847. }
  36848. if (cfm.name === "AESV3") {
  36849. return function () {
  36850. return new AES256Cipher(key);
  36851. };
  36852. }
  36853. throw new FormatError("Unknown crypto method");
  36854. }
  36855. constructor(dict, fileId, password) {
  36856. const filter = dict.get("Filter");
  36857. if (!isName(filter, "Standard")) {
  36858. throw new FormatError("unknown encryption method");
  36859. }
  36860. this.filterName = filter.name;
  36861. this.dict = dict;
  36862. const algorithm = dict.get("V");
  36863. if (!Number.isInteger(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  36864. throw new FormatError("unsupported encryption algorithm");
  36865. }
  36866. this.algorithm = algorithm;
  36867. let keyLength = dict.get("Length");
  36868. if (!keyLength) {
  36869. if (algorithm <= 3) {
  36870. keyLength = 40;
  36871. } else {
  36872. const cfDict = dict.get("CF");
  36873. const streamCryptoName = dict.get("StmF");
  36874. if (cfDict instanceof Dict && streamCryptoName instanceof Name) {
  36875. cfDict.suppressEncryption = true;
  36876. const handlerDict = cfDict.get(streamCryptoName.name);
  36877. keyLength = handlerDict?.get("Length") || 128;
  36878. if (keyLength < 40) {
  36879. keyLength <<= 3;
  36880. }
  36881. }
  36882. }
  36883. }
  36884. if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  36885. throw new FormatError("invalid key length");
  36886. }
  36887. const ownerBytes = stringToBytes(dict.get("O")),
  36888. userBytes = stringToBytes(dict.get("U"));
  36889. const ownerPassword = ownerBytes.subarray(0, 32);
  36890. const userPassword = userBytes.subarray(0, 32);
  36891. const flags = dict.get("P");
  36892. const revision = dict.get("R");
  36893. const encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get("EncryptMetadata") !== false;
  36894. this.encryptMetadata = encryptMetadata;
  36895. const fileIdBytes = stringToBytes(fileId);
  36896. let passwordBytes;
  36897. if (password) {
  36898. if (revision === 6) {
  36899. try {
  36900. password = utf8StringToString(password);
  36901. } catch {
  36902. warn("CipherTransformFactory: Unable to convert UTF8 encoded password.");
  36903. }
  36904. }
  36905. passwordBytes = stringToBytes(password);
  36906. }
  36907. let encryptionKey;
  36908. if (algorithm !== 5) {
  36909. encryptionKey = this.#prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  36910. } else {
  36911. const ownerValidationSalt = ownerBytes.subarray(32, 40);
  36912. const ownerKeySalt = ownerBytes.subarray(40, 48);
  36913. const uBytes = userBytes.subarray(0, 48);
  36914. const userValidationSalt = userBytes.subarray(32, 40);
  36915. const userKeySalt = userBytes.subarray(40, 48);
  36916. const ownerEncryption = stringToBytes(dict.get("OE"));
  36917. const userEncryption = stringToBytes(dict.get("UE"));
  36918. const perms = stringToBytes(dict.get("Perms"));
  36919. encryptionKey = this.#createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  36920. }
  36921. if (!encryptionKey && !password) {
  36922. throw new PasswordException("No password given", PasswordResponses.NEED_PASSWORD);
  36923. } else if (!encryptionKey && password) {
  36924. const decodedPassword = this.#decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  36925. encryptionKey = this.#prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  36926. }
  36927. if (!encryptionKey) {
  36928. throw new PasswordException("Incorrect Password", PasswordResponses.INCORRECT_PASSWORD);
  36929. }
  36930. this.encryptionKey = encryptionKey;
  36931. if (algorithm >= 4) {
  36932. const cf = dict.get("CF");
  36933. if (cf instanceof Dict) {
  36934. cf.suppressEncryption = true;
  36935. }
  36936. this.cf = cf;
  36937. this.stmf = dict.get("StmF") || Name.get("Identity");
  36938. this.strf = dict.get("StrF") || Name.get("Identity");
  36939. this.eff = dict.get("EFF") || this.stmf;
  36940. }
  36941. }
  36942. createCipherTransform(num, gen) {
  36943. if (this.algorithm === 4 || this.algorithm === 5) {
  36944. return new CipherTransform(this.#buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey), this.#buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey));
  36945. }
  36946. const key = this.#buildObjectKey(num, gen, this.encryptionKey, false);
  36947. const cipherConstructor = function () {
  36948. return new ARCFourCipher(key);
  36949. };
  36950. return new CipherTransform(cipherConstructor, cipherConstructor);
  36951. }
  36952. }
  36953. ;// CONCATENATED MODULE: ./src/core/writer.js
  36954. async function writeObject(ref, obj, buffer, {
  36955. encrypt = null
  36956. }) {
  36957. const transform = encrypt?.createCipherTransform(ref.num, ref.gen);
  36958. buffer.push(`${ref.num} ${ref.gen} obj\n`);
  36959. if (obj instanceof Dict) {
  36960. await writeDict(obj, buffer, transform);
  36961. } else if (obj instanceof BaseStream) {
  36962. await writeStream(obj, buffer, transform);
  36963. } else if (Array.isArray(obj)) {
  36964. await writeArray(obj, buffer, transform);
  36965. }
  36966. buffer.push("\nendobj\n");
  36967. }
  36968. async function writeDict(dict, buffer, transform) {
  36969. buffer.push("<<");
  36970. for (const key of dict.getKeys()) {
  36971. buffer.push(` /${escapePDFName(key)} `);
  36972. await writeValue(dict.getRaw(key), buffer, transform);
  36973. }
  36974. buffer.push(">>");
  36975. }
  36976. async function writeStream(stream, buffer, transform) {
  36977. let bytes = stream.getBytes();
  36978. const {
  36979. dict
  36980. } = stream;
  36981. const [filter, params] = await Promise.all([dict.getAsync("Filter"), dict.getAsync("DecodeParms")]);
  36982. const filterZero = Array.isArray(filter) ? await dict.xref.fetchIfRefAsync(filter[0]) : filter;
  36983. const isFilterZeroFlateDecode = isName(filterZero, "FlateDecode");
  36984. const MIN_LENGTH_FOR_COMPRESSING = 256;
  36985. if (typeof CompressionStream !== "undefined" && (bytes.length >= MIN_LENGTH_FOR_COMPRESSING || isFilterZeroFlateDecode)) {
  36986. try {
  36987. const cs = new CompressionStream("deflate");
  36988. const writer = cs.writable.getWriter();
  36989. writer.write(bytes);
  36990. writer.close();
  36991. const buf = await new Response(cs.readable).arrayBuffer();
  36992. bytes = new Uint8Array(buf);
  36993. let newFilter, newParams;
  36994. if (!filter) {
  36995. newFilter = Name.get("FlateDecode");
  36996. } else if (!isFilterZeroFlateDecode) {
  36997. newFilter = Array.isArray(filter) ? [Name.get("FlateDecode"), ...filter] : [Name.get("FlateDecode"), filter];
  36998. if (params) {
  36999. newParams = Array.isArray(params) ? [null, ...params] : [null, params];
  37000. }
  37001. }
  37002. if (newFilter) {
  37003. dict.set("Filter", newFilter);
  37004. }
  37005. if (newParams) {
  37006. dict.set("DecodeParms", newParams);
  37007. }
  37008. } catch (ex) {
  37009. info(`writeStream - cannot compress data: "${ex}".`);
  37010. }
  37011. }
  37012. let string = bytesToString(bytes);
  37013. if (transform) {
  37014. string = transform.encryptString(string);
  37015. }
  37016. dict.set("Length", string.length);
  37017. await writeDict(dict, buffer, transform);
  37018. buffer.push(" stream\n", string, "\nendstream");
  37019. }
  37020. async function writeArray(array, buffer, transform) {
  37021. buffer.push("[");
  37022. let first = true;
  37023. for (const val of array) {
  37024. if (!first) {
  37025. buffer.push(" ");
  37026. } else {
  37027. first = false;
  37028. }
  37029. await writeValue(val, buffer, transform);
  37030. }
  37031. buffer.push("]");
  37032. }
  37033. async function writeValue(value, buffer, transform) {
  37034. if (value instanceof Name) {
  37035. buffer.push(`/${escapePDFName(value.name)}`);
  37036. } else if (value instanceof Ref) {
  37037. buffer.push(`${value.num} ${value.gen} R`);
  37038. } else if (Array.isArray(value)) {
  37039. await writeArray(value, buffer, transform);
  37040. } else if (typeof value === "string") {
  37041. if (transform) {
  37042. value = transform.encryptString(value);
  37043. }
  37044. buffer.push(`(${escapeString(value)})`);
  37045. } else if (typeof value === "number") {
  37046. buffer.push(numberToString(value));
  37047. } else if (typeof value === "boolean") {
  37048. buffer.push(value.toString());
  37049. } else if (value instanceof Dict) {
  37050. await writeDict(value, buffer, transform);
  37051. } else if (value instanceof BaseStream) {
  37052. await writeStream(value, buffer, transform);
  37053. } else if (value === null) {
  37054. buffer.push("null");
  37055. } else {
  37056. warn(`Unhandled value in writer: ${typeof value}, please file a bug.`);
  37057. }
  37058. }
  37059. function writeInt(number, size, offset, buffer) {
  37060. for (let i = size + offset - 1; i > offset - 1; i--) {
  37061. buffer[i] = number & 0xff;
  37062. number >>= 8;
  37063. }
  37064. return offset + size;
  37065. }
  37066. function writeString(string, offset, buffer) {
  37067. for (let i = 0, len = string.length; i < len; i++) {
  37068. buffer[offset + i] = string.charCodeAt(i) & 0xff;
  37069. }
  37070. }
  37071. function computeMD5(filesize, xrefInfo) {
  37072. const time = Math.floor(Date.now() / 1000);
  37073. const filename = xrefInfo.filename || "";
  37074. const md5Buffer = [time.toString(), filename, filesize.toString()];
  37075. let md5BufferLen = md5Buffer.reduce((a, str) => a + str.length, 0);
  37076. for (const value of Object.values(xrefInfo.info)) {
  37077. md5Buffer.push(value);
  37078. md5BufferLen += value.length;
  37079. }
  37080. const array = new Uint8Array(md5BufferLen);
  37081. let offset = 0;
  37082. for (const str of md5Buffer) {
  37083. writeString(str, offset, array);
  37084. offset += str.length;
  37085. }
  37086. return bytesToString(calculateMD5(array));
  37087. }
  37088. function writeXFADataForAcroform(str, newRefs) {
  37089. const xml = new SimpleXMLParser({
  37090. hasAttributes: true
  37091. }).parseFromString(str);
  37092. for (const {
  37093. xfa
  37094. } of newRefs) {
  37095. if (!xfa) {
  37096. continue;
  37097. }
  37098. const {
  37099. path,
  37100. value
  37101. } = xfa;
  37102. if (!path) {
  37103. continue;
  37104. }
  37105. const nodePath = parseXFAPath(path);
  37106. let node = xml.documentElement.searchNode(nodePath, 0);
  37107. if (!node && nodePath.length > 1) {
  37108. node = xml.documentElement.searchNode([nodePath.at(-1)], 0);
  37109. }
  37110. if (node) {
  37111. node.childNodes = Array.isArray(value) ? value.map(val => new SimpleDOMNode("value", val)) : [new SimpleDOMNode("#text", value)];
  37112. } else {
  37113. warn(`Node not found for path: ${path}`);
  37114. }
  37115. }
  37116. const buffer = [];
  37117. xml.documentElement.dump(buffer);
  37118. return buffer.join("");
  37119. }
  37120. async function updateAcroform({
  37121. xref,
  37122. acroForm,
  37123. acroFormRef,
  37124. hasXfa,
  37125. hasXfaDatasetsEntry,
  37126. xfaDatasetsRef,
  37127. needAppearances,
  37128. newRefs
  37129. }) {
  37130. if (hasXfa && !hasXfaDatasetsEntry && !xfaDatasetsRef) {
  37131. warn("XFA - Cannot save it");
  37132. }
  37133. if (!needAppearances && (!hasXfa || !xfaDatasetsRef || hasXfaDatasetsEntry)) {
  37134. return;
  37135. }
  37136. const dict = acroForm.clone();
  37137. if (hasXfa && !hasXfaDatasetsEntry) {
  37138. const newXfa = acroForm.get("XFA").slice();
  37139. newXfa.splice(2, 0, "datasets");
  37140. newXfa.splice(3, 0, xfaDatasetsRef);
  37141. dict.set("XFA", newXfa);
  37142. }
  37143. if (needAppearances) {
  37144. dict.set("NeedAppearances", true);
  37145. }
  37146. const buffer = [];
  37147. await writeObject(acroFormRef, dict, buffer, xref);
  37148. newRefs.push({
  37149. ref: acroFormRef,
  37150. data: buffer.join("")
  37151. });
  37152. }
  37153. function updateXFA({
  37154. xfaData,
  37155. xfaDatasetsRef,
  37156. newRefs,
  37157. xref
  37158. }) {
  37159. if (xfaData === null) {
  37160. const datasets = xref.fetchIfRef(xfaDatasetsRef);
  37161. xfaData = writeXFADataForAcroform(datasets.getString(), newRefs);
  37162. }
  37163. const encrypt = xref.encrypt;
  37164. if (encrypt) {
  37165. const transform = encrypt.createCipherTransform(xfaDatasetsRef.num, xfaDatasetsRef.gen);
  37166. xfaData = transform.encryptString(xfaData);
  37167. }
  37168. const data = `${xfaDatasetsRef.num} ${xfaDatasetsRef.gen} obj\n` + `<< /Type /EmbeddedFile /Length ${xfaData.length}>>\nstream\n` + xfaData + "\nendstream\nendobj\n";
  37169. newRefs.push({
  37170. ref: xfaDatasetsRef,
  37171. data
  37172. });
  37173. }
  37174. async function incrementalUpdate({
  37175. originalData,
  37176. xrefInfo,
  37177. newRefs,
  37178. xref = null,
  37179. hasXfa = false,
  37180. xfaDatasetsRef = null,
  37181. hasXfaDatasetsEntry = false,
  37182. needAppearances,
  37183. acroFormRef = null,
  37184. acroForm = null,
  37185. xfaData = null
  37186. }) {
  37187. await updateAcroform({
  37188. xref,
  37189. acroForm,
  37190. acroFormRef,
  37191. hasXfa,
  37192. hasXfaDatasetsEntry,
  37193. xfaDatasetsRef,
  37194. needAppearances,
  37195. newRefs
  37196. });
  37197. if (hasXfa) {
  37198. updateXFA({
  37199. xfaData,
  37200. xfaDatasetsRef,
  37201. newRefs,
  37202. xref
  37203. });
  37204. }
  37205. const newXref = new Dict(null);
  37206. const refForXrefTable = xrefInfo.newRef;
  37207. let buffer, baseOffset;
  37208. const lastByte = originalData.at(-1);
  37209. if (lastByte === 0x0a || lastByte === 0x0d) {
  37210. buffer = [];
  37211. baseOffset = originalData.length;
  37212. } else {
  37213. buffer = ["\n"];
  37214. baseOffset = originalData.length + 1;
  37215. }
  37216. newXref.set("Size", refForXrefTable.num + 1);
  37217. newXref.set("Prev", xrefInfo.startXRef);
  37218. newXref.set("Type", Name.get("XRef"));
  37219. if (xrefInfo.rootRef !== null) {
  37220. newXref.set("Root", xrefInfo.rootRef);
  37221. }
  37222. if (xrefInfo.infoRef !== null) {
  37223. newXref.set("Info", xrefInfo.infoRef);
  37224. }
  37225. if (xrefInfo.encryptRef !== null) {
  37226. newXref.set("Encrypt", xrefInfo.encryptRef);
  37227. }
  37228. newRefs.push({
  37229. ref: refForXrefTable,
  37230. data: ""
  37231. });
  37232. newRefs = newRefs.sort((a, b) => {
  37233. return a.ref.num - b.ref.num;
  37234. });
  37235. const xrefTableData = [[0, 1, 0xffff]];
  37236. const indexes = [0, 1];
  37237. let maxOffset = 0;
  37238. for (const {
  37239. ref,
  37240. data
  37241. } of newRefs) {
  37242. maxOffset = Math.max(maxOffset, baseOffset);
  37243. xrefTableData.push([1, baseOffset, Math.min(ref.gen, 0xffff)]);
  37244. baseOffset += data.length;
  37245. indexes.push(ref.num, 1);
  37246. buffer.push(data);
  37247. }
  37248. newXref.set("Index", indexes);
  37249. if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
  37250. const md5 = computeMD5(baseOffset, xrefInfo);
  37251. newXref.set("ID", [xrefInfo.fileIds[0], md5]);
  37252. }
  37253. const offsetSize = Math.ceil(Math.log2(maxOffset) / 8);
  37254. const sizes = [1, offsetSize, 2];
  37255. const structSize = sizes[0] + sizes[1] + sizes[2];
  37256. const tableLength = structSize * xrefTableData.length;
  37257. newXref.set("W", sizes);
  37258. newXref.set("Length", tableLength);
  37259. buffer.push(`${refForXrefTable.num} ${refForXrefTable.gen} obj\n`);
  37260. await writeDict(newXref, buffer, null);
  37261. buffer.push(" stream\n");
  37262. const bufferLen = buffer.reduce((a, str) => a + str.length, 0);
  37263. const footer = `\nendstream\nendobj\nstartxref\n${baseOffset}\n%%EOF\n`;
  37264. const array = new Uint8Array(originalData.length + bufferLen + tableLength + footer.length);
  37265. array.set(originalData);
  37266. let offset = originalData.length;
  37267. for (const str of buffer) {
  37268. writeString(str, offset, array);
  37269. offset += str.length;
  37270. }
  37271. for (const [type, objOffset, gen] of xrefTableData) {
  37272. offset = writeInt(type, sizes[0], offset, array);
  37273. offset = writeInt(objOffset, sizes[1], offset, array);
  37274. offset = writeInt(gen, sizes[2], offset, array);
  37275. }
  37276. writeString(footer, offset, array);
  37277. return array;
  37278. }
  37279. ;// CONCATENATED MODULE: ./src/core/struct_tree.js
  37280. const MAX_DEPTH = 40;
  37281. const StructElementType = {
  37282. PAGE_CONTENT: 1,
  37283. STREAM_CONTENT: 2,
  37284. OBJECT: 3,
  37285. ANNOTATION: 4,
  37286. ELEMENT: 5
  37287. };
  37288. class StructTreeRoot {
  37289. constructor(rootDict, rootRef) {
  37290. this.dict = rootDict;
  37291. this.ref = rootRef instanceof Ref ? rootRef : null;
  37292. this.roleMap = new Map();
  37293. this.structParentIds = null;
  37294. }
  37295. init() {
  37296. this.readRoleMap();
  37297. }
  37298. #addIdToPage(pageRef, id, type) {
  37299. if (!(pageRef instanceof Ref) || id < 0) {
  37300. return;
  37301. }
  37302. this.structParentIds ||= new RefSetCache();
  37303. let ids = this.structParentIds.get(pageRef);
  37304. if (!ids) {
  37305. ids = [];
  37306. this.structParentIds.put(pageRef, ids);
  37307. }
  37308. ids.push([id, type]);
  37309. }
  37310. addAnnotationIdToPage(pageRef, id) {
  37311. this.#addIdToPage(pageRef, id, StructElementType.ANNOTATION);
  37312. }
  37313. readRoleMap() {
  37314. const roleMapDict = this.dict.get("RoleMap");
  37315. if (!(roleMapDict instanceof Dict)) {
  37316. return;
  37317. }
  37318. roleMapDict.forEach((key, value) => {
  37319. if (!(value instanceof Name)) {
  37320. return;
  37321. }
  37322. this.roleMap.set(key, value.name);
  37323. });
  37324. }
  37325. static async canCreateStructureTree({
  37326. catalogRef,
  37327. pdfManager,
  37328. newAnnotationsByPage
  37329. }) {
  37330. if (!(catalogRef instanceof Ref)) {
  37331. warn("Cannot save the struct tree: no catalog reference.");
  37332. return false;
  37333. }
  37334. let nextKey = 0;
  37335. let hasNothingToUpdate = true;
  37336. for (const [pageIndex, elements] of newAnnotationsByPage) {
  37337. const {
  37338. ref: pageRef
  37339. } = await pdfManager.getPage(pageIndex);
  37340. if (!(pageRef instanceof Ref)) {
  37341. warn(`Cannot save the struct tree: page ${pageIndex} has no ref.`);
  37342. hasNothingToUpdate = true;
  37343. break;
  37344. }
  37345. for (const element of elements) {
  37346. if (element.accessibilityData?.type) {
  37347. element.parentTreeId = nextKey++;
  37348. hasNothingToUpdate = false;
  37349. }
  37350. }
  37351. }
  37352. if (hasNothingToUpdate) {
  37353. for (const elements of newAnnotationsByPage.values()) {
  37354. for (const element of elements) {
  37355. delete element.parentTreeId;
  37356. }
  37357. }
  37358. return false;
  37359. }
  37360. return true;
  37361. }
  37362. static async createStructureTree({
  37363. newAnnotationsByPage,
  37364. xref,
  37365. catalogRef,
  37366. pdfManager,
  37367. newRefs
  37368. }) {
  37369. const root = pdfManager.catalog.cloneDict();
  37370. const structTreeRootRef = xref.getNewTemporaryRef();
  37371. root.set("StructTreeRoot", structTreeRootRef);
  37372. const buffer = [];
  37373. await writeObject(catalogRef, root, buffer, xref);
  37374. newRefs.push({
  37375. ref: catalogRef,
  37376. data: buffer.join("")
  37377. });
  37378. const structTreeRoot = new Dict(xref);
  37379. structTreeRoot.set("Type", Name.get("StructTreeRoot"));
  37380. const parentTreeRef = xref.getNewTemporaryRef();
  37381. structTreeRoot.set("ParentTree", parentTreeRef);
  37382. const kids = [];
  37383. structTreeRoot.set("K", kids);
  37384. const parentTree = new Dict(xref);
  37385. const nums = [];
  37386. parentTree.set("Nums", nums);
  37387. const nextKey = await this.#writeKids({
  37388. newAnnotationsByPage,
  37389. structTreeRootRef,
  37390. kids,
  37391. nums,
  37392. xref,
  37393. pdfManager,
  37394. newRefs,
  37395. buffer
  37396. });
  37397. structTreeRoot.set("ParentTreeNextKey", nextKey);
  37398. buffer.length = 0;
  37399. await writeObject(parentTreeRef, parentTree, buffer, xref);
  37400. newRefs.push({
  37401. ref: parentTreeRef,
  37402. data: buffer.join("")
  37403. });
  37404. buffer.length = 0;
  37405. await writeObject(structTreeRootRef, structTreeRoot, buffer, xref);
  37406. newRefs.push({
  37407. ref: structTreeRootRef,
  37408. data: buffer.join("")
  37409. });
  37410. }
  37411. async canUpdateStructTree({
  37412. pdfManager,
  37413. xref,
  37414. newAnnotationsByPage
  37415. }) {
  37416. if (!this.ref) {
  37417. warn("Cannot update the struct tree: no root reference.");
  37418. return false;
  37419. }
  37420. let nextKey = this.dict.get("ParentTreeNextKey");
  37421. if (!Number.isInteger(nextKey) || nextKey < 0) {
  37422. warn("Cannot update the struct tree: invalid next key.");
  37423. return false;
  37424. }
  37425. const parentTree = this.dict.get("ParentTree");
  37426. if (!(parentTree instanceof Dict)) {
  37427. warn("Cannot update the struct tree: ParentTree isn't a dict.");
  37428. return false;
  37429. }
  37430. const nums = parentTree.get("Nums");
  37431. if (!Array.isArray(nums)) {
  37432. warn("Cannot update the struct tree: nums isn't an array.");
  37433. return false;
  37434. }
  37435. const numberTree = new NumberTree(parentTree, xref);
  37436. for (const pageIndex of newAnnotationsByPage.keys()) {
  37437. const {
  37438. pageDict
  37439. } = await pdfManager.getPage(pageIndex);
  37440. if (!pageDict.has("StructParents")) {
  37441. continue;
  37442. }
  37443. const id = pageDict.get("StructParents");
  37444. if (!Number.isInteger(id) || !Array.isArray(numberTree.get(id))) {
  37445. warn(`Cannot save the struct tree: page ${pageIndex} has a wrong id.`);
  37446. return false;
  37447. }
  37448. }
  37449. let hasNothingToUpdate = true;
  37450. for (const [pageIndex, elements] of newAnnotationsByPage) {
  37451. const {
  37452. pageDict
  37453. } = await pdfManager.getPage(pageIndex);
  37454. StructTreeRoot.#collectParents({
  37455. elements,
  37456. xref: this.dict.xref,
  37457. pageDict,
  37458. numberTree
  37459. });
  37460. for (const element of elements) {
  37461. if (element.accessibilityData?.type) {
  37462. element.parentTreeId = nextKey++;
  37463. hasNothingToUpdate = false;
  37464. }
  37465. }
  37466. }
  37467. if (hasNothingToUpdate) {
  37468. for (const elements of newAnnotationsByPage.values()) {
  37469. for (const element of elements) {
  37470. delete element.parentTreeId;
  37471. delete element.structTreeParent;
  37472. }
  37473. }
  37474. return false;
  37475. }
  37476. return true;
  37477. }
  37478. async updateStructureTree({
  37479. newAnnotationsByPage,
  37480. pdfManager,
  37481. newRefs
  37482. }) {
  37483. const xref = this.dict.xref;
  37484. const structTreeRoot = this.dict.clone();
  37485. const structTreeRootRef = this.ref;
  37486. let parentTreeRef = structTreeRoot.getRaw("ParentTree");
  37487. let parentTree;
  37488. if (parentTreeRef instanceof Ref) {
  37489. parentTree = xref.fetch(parentTreeRef);
  37490. } else {
  37491. parentTree = parentTreeRef;
  37492. parentTreeRef = xref.getNewTemporaryRef();
  37493. structTreeRoot.set("ParentTree", parentTreeRef);
  37494. }
  37495. parentTree = parentTree.clone();
  37496. let nums = parentTree.getRaw("Nums");
  37497. let numsRef = null;
  37498. if (nums instanceof Ref) {
  37499. numsRef = nums;
  37500. nums = xref.fetch(numsRef);
  37501. }
  37502. nums = nums.slice();
  37503. if (!numsRef) {
  37504. parentTree.set("Nums", nums);
  37505. }
  37506. let kids = structTreeRoot.getRaw("K");
  37507. let kidsRef = null;
  37508. if (kids instanceof Ref) {
  37509. kidsRef = kids;
  37510. kids = xref.fetch(kidsRef);
  37511. } else {
  37512. kidsRef = xref.getNewTemporaryRef();
  37513. structTreeRoot.set("K", kidsRef);
  37514. }
  37515. kids = Array.isArray(kids) ? kids.slice() : [kids];
  37516. const buffer = [];
  37517. const newNextkey = await StructTreeRoot.#writeKids({
  37518. newAnnotationsByPage,
  37519. structTreeRootRef,
  37520. kids,
  37521. nums,
  37522. xref,
  37523. pdfManager,
  37524. newRefs,
  37525. buffer
  37526. });
  37527. structTreeRoot.set("ParentTreeNextKey", newNextkey);
  37528. buffer.length = 0;
  37529. await writeObject(kidsRef, kids, buffer, xref);
  37530. newRefs.push({
  37531. ref: kidsRef,
  37532. data: buffer.join("")
  37533. });
  37534. if (numsRef) {
  37535. buffer.length = 0;
  37536. await writeObject(numsRef, nums, buffer, xref);
  37537. newRefs.push({
  37538. ref: numsRef,
  37539. data: buffer.join("")
  37540. });
  37541. }
  37542. buffer.length = 0;
  37543. await writeObject(parentTreeRef, parentTree, buffer, xref);
  37544. newRefs.push({
  37545. ref: parentTreeRef,
  37546. data: buffer.join("")
  37547. });
  37548. buffer.length = 0;
  37549. await writeObject(structTreeRootRef, structTreeRoot, buffer, xref);
  37550. newRefs.push({
  37551. ref: structTreeRootRef,
  37552. data: buffer.join("")
  37553. });
  37554. }
  37555. static async #writeKids({
  37556. newAnnotationsByPage,
  37557. structTreeRootRef,
  37558. kids,
  37559. nums,
  37560. xref,
  37561. pdfManager,
  37562. newRefs,
  37563. buffer
  37564. }) {
  37565. const objr = Name.get("OBJR");
  37566. let nextKey = -Infinity;
  37567. for (const [pageIndex, elements] of newAnnotationsByPage) {
  37568. const {
  37569. ref: pageRef
  37570. } = await pdfManager.getPage(pageIndex);
  37571. const isPageRef = pageRef instanceof Ref;
  37572. for (const {
  37573. accessibilityData,
  37574. ref,
  37575. parentTreeId,
  37576. structTreeParent
  37577. } of elements) {
  37578. if (!accessibilityData?.type) {
  37579. continue;
  37580. }
  37581. const {
  37582. type,
  37583. title,
  37584. lang,
  37585. alt,
  37586. expanded,
  37587. actualText
  37588. } = accessibilityData;
  37589. nextKey = Math.max(nextKey, parentTreeId);
  37590. const tagRef = xref.getNewTemporaryRef();
  37591. const tagDict = new Dict(xref);
  37592. tagDict.set("S", Name.get(type));
  37593. if (title) {
  37594. tagDict.set("T", title);
  37595. }
  37596. if (lang) {
  37597. tagDict.set("Lang", lang);
  37598. }
  37599. if (alt) {
  37600. tagDict.set("Alt", alt);
  37601. }
  37602. if (expanded) {
  37603. tagDict.set("E", expanded);
  37604. }
  37605. if (actualText) {
  37606. tagDict.set("ActualText", actualText);
  37607. }
  37608. if (structTreeParent) {
  37609. await this.#updateParentTag({
  37610. structTreeParent,
  37611. tagDict,
  37612. newTagRef: tagRef,
  37613. fallbackRef: structTreeRootRef,
  37614. xref,
  37615. newRefs,
  37616. buffer
  37617. });
  37618. } else {
  37619. tagDict.set("P", structTreeRootRef);
  37620. }
  37621. const objDict = new Dict(xref);
  37622. tagDict.set("K", objDict);
  37623. objDict.set("Type", objr);
  37624. if (isPageRef) {
  37625. objDict.set("Pg", pageRef);
  37626. }
  37627. objDict.set("Obj", ref);
  37628. buffer.length = 0;
  37629. await writeObject(tagRef, tagDict, buffer, xref);
  37630. newRefs.push({
  37631. ref: tagRef,
  37632. data: buffer.join("")
  37633. });
  37634. nums.push(parentTreeId, tagRef);
  37635. kids.push(tagRef);
  37636. }
  37637. }
  37638. return nextKey + 1;
  37639. }
  37640. static #collectParents({
  37641. elements,
  37642. xref,
  37643. pageDict,
  37644. numberTree
  37645. }) {
  37646. const idToElement = new Map();
  37647. for (const element of elements) {
  37648. if (element.structTreeParentId) {
  37649. const id = parseInt(element.structTreeParentId.split("_mc")[1], 10);
  37650. idToElement.set(id, element);
  37651. }
  37652. }
  37653. const id = pageDict.get("StructParents");
  37654. if (!Number.isInteger(id)) {
  37655. return;
  37656. }
  37657. const parentArray = numberTree.get(id);
  37658. const updateElement = (kid, pageKid, kidRef) => {
  37659. const element = idToElement.get(kid);
  37660. if (element) {
  37661. const parentRef = pageKid.getRaw("P");
  37662. const parentDict = xref.fetchIfRef(parentRef);
  37663. if (parentRef instanceof Ref && parentDict instanceof Dict) {
  37664. element.structTreeParent = {
  37665. ref: kidRef,
  37666. dict: pageKid
  37667. };
  37668. }
  37669. return true;
  37670. }
  37671. return false;
  37672. };
  37673. for (const kidRef of parentArray) {
  37674. if (!(kidRef instanceof Ref)) {
  37675. continue;
  37676. }
  37677. const pageKid = xref.fetch(kidRef);
  37678. const k = pageKid.get("K");
  37679. if (Number.isInteger(k)) {
  37680. updateElement(k, pageKid, kidRef);
  37681. continue;
  37682. }
  37683. if (!Array.isArray(k)) {
  37684. continue;
  37685. }
  37686. for (let kid of k) {
  37687. kid = xref.fetchIfRef(kid);
  37688. if (Number.isInteger(kid) && updateElement(kid, pageKid, kidRef)) {
  37689. break;
  37690. }
  37691. }
  37692. }
  37693. }
  37694. static async #updateParentTag({
  37695. structTreeParent: {
  37696. ref,
  37697. dict
  37698. },
  37699. tagDict,
  37700. newTagRef,
  37701. fallbackRef,
  37702. xref,
  37703. newRefs,
  37704. buffer
  37705. }) {
  37706. const parentRef = dict.getRaw("P");
  37707. let parentDict = xref.fetchIfRef(parentRef);
  37708. tagDict.set("P", parentRef);
  37709. let saveParentDict = false;
  37710. let parentKids;
  37711. let parentKidsRef = parentDict.getRaw("K");
  37712. if (!(parentKidsRef instanceof Ref)) {
  37713. parentKids = parentKidsRef;
  37714. parentKidsRef = xref.getNewTemporaryRef();
  37715. parentDict = parentDict.clone();
  37716. parentDict.set("K", parentKidsRef);
  37717. saveParentDict = true;
  37718. } else {
  37719. parentKids = xref.fetch(parentKidsRef);
  37720. }
  37721. if (Array.isArray(parentKids)) {
  37722. const index = parentKids.indexOf(ref);
  37723. if (index >= 0) {
  37724. parentKids = parentKids.slice();
  37725. parentKids.splice(index + 1, 0, newTagRef);
  37726. } else {
  37727. warn("Cannot update the struct tree: parent kid not found.");
  37728. tagDict.set("P", fallbackRef);
  37729. return;
  37730. }
  37731. } else if (parentKids instanceof Dict) {
  37732. parentKids = [parentKidsRef, newTagRef];
  37733. parentKidsRef = xref.getNewTemporaryRef();
  37734. parentDict.set("K", parentKidsRef);
  37735. saveParentDict = true;
  37736. }
  37737. buffer.length = 0;
  37738. await writeObject(parentKidsRef, parentKids, buffer, xref);
  37739. newRefs.push({
  37740. ref: parentKidsRef,
  37741. data: buffer.join("")
  37742. });
  37743. if (!saveParentDict) {
  37744. return;
  37745. }
  37746. buffer.length = 0;
  37747. await writeObject(parentRef, parentDict, buffer, xref);
  37748. newRefs.push({
  37749. ref: parentRef,
  37750. data: buffer.join("")
  37751. });
  37752. }
  37753. }
  37754. class StructElementNode {
  37755. constructor(tree, dict) {
  37756. this.tree = tree;
  37757. this.dict = dict;
  37758. this.kids = [];
  37759. this.parseKids();
  37760. }
  37761. get role() {
  37762. const nameObj = this.dict.get("S");
  37763. const name = nameObj instanceof Name ? nameObj.name : "";
  37764. const {
  37765. root
  37766. } = this.tree;
  37767. if (root.roleMap.has(name)) {
  37768. return root.roleMap.get(name);
  37769. }
  37770. return name;
  37771. }
  37772. parseKids() {
  37773. let pageObjId = null;
  37774. const objRef = this.dict.getRaw("Pg");
  37775. if (objRef instanceof Ref) {
  37776. pageObjId = objRef.toString();
  37777. }
  37778. const kids = this.dict.get("K");
  37779. if (Array.isArray(kids)) {
  37780. for (const kid of kids) {
  37781. const element = this.parseKid(pageObjId, kid);
  37782. if (element) {
  37783. this.kids.push(element);
  37784. }
  37785. }
  37786. } else {
  37787. const element = this.parseKid(pageObjId, kids);
  37788. if (element) {
  37789. this.kids.push(element);
  37790. }
  37791. }
  37792. }
  37793. parseKid(pageObjId, kid) {
  37794. if (Number.isInteger(kid)) {
  37795. if (this.tree.pageDict.objId !== pageObjId) {
  37796. return null;
  37797. }
  37798. return new StructElement({
  37799. type: StructElementType.PAGE_CONTENT,
  37800. mcid: kid,
  37801. pageObjId
  37802. });
  37803. }
  37804. let kidDict = null;
  37805. if (kid instanceof Ref) {
  37806. kidDict = this.dict.xref.fetch(kid);
  37807. } else if (kid instanceof Dict) {
  37808. kidDict = kid;
  37809. }
  37810. if (!kidDict) {
  37811. return null;
  37812. }
  37813. const pageRef = kidDict.getRaw("Pg");
  37814. if (pageRef instanceof Ref) {
  37815. pageObjId = pageRef.toString();
  37816. }
  37817. const type = kidDict.get("Type") instanceof Name ? kidDict.get("Type").name : null;
  37818. if (type === "MCR") {
  37819. if (this.tree.pageDict.objId !== pageObjId) {
  37820. return null;
  37821. }
  37822. const kidRef = kidDict.getRaw("Stm");
  37823. return new StructElement({
  37824. type: StructElementType.STREAM_CONTENT,
  37825. refObjId: kidRef instanceof Ref ? kidRef.toString() : null,
  37826. pageObjId,
  37827. mcid: kidDict.get("MCID")
  37828. });
  37829. }
  37830. if (type === "OBJR") {
  37831. if (this.tree.pageDict.objId !== pageObjId) {
  37832. return null;
  37833. }
  37834. const kidRef = kidDict.getRaw("Obj");
  37835. return new StructElement({
  37836. type: StructElementType.OBJECT,
  37837. refObjId: kidRef instanceof Ref ? kidRef.toString() : null,
  37838. pageObjId
  37839. });
  37840. }
  37841. return new StructElement({
  37842. type: StructElementType.ELEMENT,
  37843. dict: kidDict
  37844. });
  37845. }
  37846. }
  37847. class StructElement {
  37848. constructor({
  37849. type,
  37850. dict = null,
  37851. mcid = null,
  37852. pageObjId = null,
  37853. refObjId = null
  37854. }) {
  37855. this.type = type;
  37856. this.dict = dict;
  37857. this.mcid = mcid;
  37858. this.pageObjId = pageObjId;
  37859. this.refObjId = refObjId;
  37860. this.parentNode = null;
  37861. }
  37862. }
  37863. class StructTreePage {
  37864. constructor(structTreeRoot, pageDict) {
  37865. this.root = structTreeRoot;
  37866. this.rootDict = structTreeRoot ? structTreeRoot.dict : null;
  37867. this.pageDict = pageDict;
  37868. this.nodes = [];
  37869. }
  37870. parse(pageRef) {
  37871. if (!this.root || !this.rootDict) {
  37872. return;
  37873. }
  37874. const parentTree = this.rootDict.get("ParentTree");
  37875. if (!parentTree) {
  37876. return;
  37877. }
  37878. const id = this.pageDict.get("StructParents");
  37879. const ids = pageRef instanceof Ref && this.root.structParentIds?.get(pageRef);
  37880. if (!Number.isInteger(id) && !ids) {
  37881. return;
  37882. }
  37883. const map = new Map();
  37884. const numberTree = new NumberTree(parentTree, this.rootDict.xref);
  37885. if (Number.isInteger(id)) {
  37886. const parentArray = numberTree.get(id);
  37887. if (Array.isArray(parentArray)) {
  37888. for (const ref of parentArray) {
  37889. if (ref instanceof Ref) {
  37890. this.addNode(this.rootDict.xref.fetch(ref), map);
  37891. }
  37892. }
  37893. }
  37894. }
  37895. if (!ids) {
  37896. return;
  37897. }
  37898. for (const [elemId, type] of ids) {
  37899. const obj = numberTree.get(elemId);
  37900. if (obj) {
  37901. const elem = this.addNode(this.rootDict.xref.fetchIfRef(obj), map);
  37902. if (elem?.kids?.length === 1 && elem.kids[0].type === StructElementType.OBJECT) {
  37903. elem.kids[0].type = type;
  37904. }
  37905. }
  37906. }
  37907. }
  37908. addNode(dict, map, level = 0) {
  37909. if (level > MAX_DEPTH) {
  37910. warn("StructTree MAX_DEPTH reached.");
  37911. return null;
  37912. }
  37913. if (map.has(dict)) {
  37914. return map.get(dict);
  37915. }
  37916. const element = new StructElementNode(this, dict);
  37917. map.set(dict, element);
  37918. const parent = dict.get("P");
  37919. if (!parent || isName(parent.get("Type"), "StructTreeRoot")) {
  37920. if (!this.addTopLevelNode(dict, element)) {
  37921. map.delete(dict);
  37922. }
  37923. return element;
  37924. }
  37925. const parentNode = this.addNode(parent, map, level + 1);
  37926. if (!parentNode) {
  37927. return element;
  37928. }
  37929. let save = false;
  37930. for (const kid of parentNode.kids) {
  37931. if (kid.type === StructElementType.ELEMENT && kid.dict === dict) {
  37932. kid.parentNode = element;
  37933. save = true;
  37934. }
  37935. }
  37936. if (!save) {
  37937. map.delete(dict);
  37938. }
  37939. return element;
  37940. }
  37941. addTopLevelNode(dict, element) {
  37942. const obj = this.rootDict.get("K");
  37943. if (!obj) {
  37944. return false;
  37945. }
  37946. if (obj instanceof Dict) {
  37947. if (obj.objId !== dict.objId) {
  37948. return false;
  37949. }
  37950. this.nodes[0] = element;
  37951. return true;
  37952. }
  37953. if (!Array.isArray(obj)) {
  37954. return true;
  37955. }
  37956. let save = false;
  37957. for (let i = 0; i < obj.length; i++) {
  37958. const kidRef = obj[i];
  37959. if (kidRef?.toString() === dict.objId) {
  37960. this.nodes[i] = element;
  37961. save = true;
  37962. }
  37963. }
  37964. return save;
  37965. }
  37966. get serializable() {
  37967. function nodeToSerializable(node, parent, level = 0) {
  37968. if (level > MAX_DEPTH) {
  37969. warn("StructTree too deep to be fully serialized.");
  37970. return;
  37971. }
  37972. const obj = Object.create(null);
  37973. obj.role = node.role;
  37974. obj.children = [];
  37975. parent.children.push(obj);
  37976. const alt = node.dict.get("Alt");
  37977. if (typeof alt === "string") {
  37978. obj.alt = stringToPDFString(alt);
  37979. }
  37980. const lang = node.dict.get("Lang");
  37981. if (typeof lang === "string") {
  37982. obj.lang = stringToPDFString(lang);
  37983. }
  37984. for (const kid of node.kids) {
  37985. const kidElement = kid.type === StructElementType.ELEMENT ? kid.parentNode : null;
  37986. if (kidElement) {
  37987. nodeToSerializable(kidElement, obj, level + 1);
  37988. continue;
  37989. } else if (kid.type === StructElementType.PAGE_CONTENT || kid.type === StructElementType.STREAM_CONTENT) {
  37990. obj.children.push({
  37991. type: "content",
  37992. id: `p${kid.pageObjId}_mc${kid.mcid}`
  37993. });
  37994. } else if (kid.type === StructElementType.OBJECT) {
  37995. obj.children.push({
  37996. type: "object",
  37997. id: kid.refObjId
  37998. });
  37999. } else if (kid.type === StructElementType.ANNOTATION) {
  38000. obj.children.push({
  38001. type: "annotation",
  38002. id: `${AnnotationPrefix}${kid.refObjId}`
  38003. });
  38004. }
  38005. }
  38006. }
  38007. const root = Object.create(null);
  38008. root.children = [];
  38009. root.role = "Root";
  38010. for (const child of this.nodes) {
  38011. if (!child) {
  38012. continue;
  38013. }
  38014. nodeToSerializable(child, root);
  38015. }
  38016. return root;
  38017. }
  38018. }
  38019. ;// CONCATENATED MODULE: ./src/core/catalog.js
  38020. function fetchDestination(dest) {
  38021. if (dest instanceof Dict) {
  38022. dest = dest.get("D");
  38023. }
  38024. return Array.isArray(dest) ? dest : null;
  38025. }
  38026. function fetchRemoteDest(action) {
  38027. let dest = action.get("D");
  38028. if (dest) {
  38029. if (dest instanceof Name) {
  38030. dest = dest.name;
  38031. }
  38032. if (typeof dest === "string") {
  38033. return stringToPDFString(dest);
  38034. } else if (Array.isArray(dest)) {
  38035. return JSON.stringify(dest);
  38036. }
  38037. }
  38038. return null;
  38039. }
  38040. class Catalog {
  38041. constructor(pdfManager, xref) {
  38042. this.pdfManager = pdfManager;
  38043. this.xref = xref;
  38044. this._catDict = xref.getCatalogObj();
  38045. if (!(this._catDict instanceof Dict)) {
  38046. throw new FormatError("Catalog object is not a dictionary.");
  38047. }
  38048. this.toplevelPagesDict;
  38049. this._actualNumPages = null;
  38050. this.fontCache = new RefSetCache();
  38051. this.builtInCMapCache = new Map();
  38052. this.standardFontDataCache = new Map();
  38053. this.globalImageCache = new GlobalImageCache();
  38054. this.pageKidsCountCache = new RefSetCache();
  38055. this.pageIndexCache = new RefSetCache();
  38056. this.nonBlendModesSet = new RefSet();
  38057. this.systemFontCache = new Map();
  38058. }
  38059. cloneDict() {
  38060. return this._catDict.clone();
  38061. }
  38062. get version() {
  38063. const version = this._catDict.get("Version");
  38064. if (version instanceof Name) {
  38065. if (PDF_VERSION_REGEXP.test(version.name)) {
  38066. return shadow(this, "version", version.name);
  38067. }
  38068. warn(`Invalid PDF catalog version: ${version.name}`);
  38069. }
  38070. return shadow(this, "version", null);
  38071. }
  38072. get lang() {
  38073. const lang = this._catDict.get("Lang");
  38074. return shadow(this, "lang", typeof lang === "string" ? stringToPDFString(lang) : null);
  38075. }
  38076. get needsRendering() {
  38077. const needsRendering = this._catDict.get("NeedsRendering");
  38078. return shadow(this, "needsRendering", typeof needsRendering === "boolean" ? needsRendering : false);
  38079. }
  38080. get collection() {
  38081. let collection = null;
  38082. try {
  38083. const obj = this._catDict.get("Collection");
  38084. if (obj instanceof Dict && obj.size > 0) {
  38085. collection = obj;
  38086. }
  38087. } catch (ex) {
  38088. if (ex instanceof MissingDataException) {
  38089. throw ex;
  38090. }
  38091. info("Cannot fetch Collection entry; assuming no collection is present.");
  38092. }
  38093. return shadow(this, "collection", collection);
  38094. }
  38095. get acroForm() {
  38096. let acroForm = null;
  38097. try {
  38098. const obj = this._catDict.get("AcroForm");
  38099. if (obj instanceof Dict && obj.size > 0) {
  38100. acroForm = obj;
  38101. }
  38102. } catch (ex) {
  38103. if (ex instanceof MissingDataException) {
  38104. throw ex;
  38105. }
  38106. info("Cannot fetch AcroForm entry; assuming no forms are present.");
  38107. }
  38108. return shadow(this, "acroForm", acroForm);
  38109. }
  38110. get acroFormRef() {
  38111. const value = this._catDict.getRaw("AcroForm");
  38112. return shadow(this, "acroFormRef", value instanceof Ref ? value : null);
  38113. }
  38114. get metadata() {
  38115. const streamRef = this._catDict.getRaw("Metadata");
  38116. if (!(streamRef instanceof Ref)) {
  38117. return shadow(this, "metadata", null);
  38118. }
  38119. let metadata = null;
  38120. try {
  38121. const stream = this.xref.fetch(streamRef, !this.xref.encrypt?.encryptMetadata);
  38122. if (stream instanceof BaseStream && stream.dict instanceof Dict) {
  38123. const type = stream.dict.get("Type");
  38124. const subtype = stream.dict.get("Subtype");
  38125. if (isName(type, "Metadata") && isName(subtype, "XML")) {
  38126. const data = stringToUTF8String(stream.getString());
  38127. if (data) {
  38128. metadata = new MetadataParser(data).serializable;
  38129. }
  38130. }
  38131. }
  38132. } catch (ex) {
  38133. if (ex instanceof MissingDataException) {
  38134. throw ex;
  38135. }
  38136. info(`Skipping invalid Metadata: "${ex}".`);
  38137. }
  38138. return shadow(this, "metadata", metadata);
  38139. }
  38140. get markInfo() {
  38141. let markInfo = null;
  38142. try {
  38143. markInfo = this._readMarkInfo();
  38144. } catch (ex) {
  38145. if (ex instanceof MissingDataException) {
  38146. throw ex;
  38147. }
  38148. warn("Unable to read mark info.");
  38149. }
  38150. return shadow(this, "markInfo", markInfo);
  38151. }
  38152. _readMarkInfo() {
  38153. const obj = this._catDict.get("MarkInfo");
  38154. if (!(obj instanceof Dict)) {
  38155. return null;
  38156. }
  38157. const markInfo = {
  38158. Marked: false,
  38159. UserProperties: false,
  38160. Suspects: false
  38161. };
  38162. for (const key in markInfo) {
  38163. const value = obj.get(key);
  38164. if (typeof value === "boolean") {
  38165. markInfo[key] = value;
  38166. }
  38167. }
  38168. return markInfo;
  38169. }
  38170. get structTreeRoot() {
  38171. let structTree = null;
  38172. try {
  38173. structTree = this._readStructTreeRoot();
  38174. } catch (ex) {
  38175. if (ex instanceof MissingDataException) {
  38176. throw ex;
  38177. }
  38178. warn("Unable read to structTreeRoot info.");
  38179. }
  38180. return shadow(this, "structTreeRoot", structTree);
  38181. }
  38182. _readStructTreeRoot() {
  38183. const rawObj = this._catDict.getRaw("StructTreeRoot");
  38184. const obj = this.xref.fetchIfRef(rawObj);
  38185. if (!(obj instanceof Dict)) {
  38186. return null;
  38187. }
  38188. const root = new StructTreeRoot(obj, rawObj);
  38189. root.init();
  38190. return root;
  38191. }
  38192. get toplevelPagesDict() {
  38193. const pagesObj = this._catDict.get("Pages");
  38194. if (!(pagesObj instanceof Dict)) {
  38195. throw new FormatError("Invalid top-level pages dictionary.");
  38196. }
  38197. return shadow(this, "toplevelPagesDict", pagesObj);
  38198. }
  38199. get documentOutline() {
  38200. let obj = null;
  38201. try {
  38202. obj = this._readDocumentOutline();
  38203. } catch (ex) {
  38204. if (ex instanceof MissingDataException) {
  38205. throw ex;
  38206. }
  38207. warn("Unable to read document outline.");
  38208. }
  38209. return shadow(this, "documentOutline", obj);
  38210. }
  38211. _readDocumentOutline() {
  38212. let obj = this._catDict.get("Outlines");
  38213. if (!(obj instanceof Dict)) {
  38214. return null;
  38215. }
  38216. obj = obj.getRaw("First");
  38217. if (!(obj instanceof Ref)) {
  38218. return null;
  38219. }
  38220. const root = {
  38221. items: []
  38222. };
  38223. const queue = [{
  38224. obj,
  38225. parent: root
  38226. }];
  38227. const processed = new RefSet();
  38228. processed.put(obj);
  38229. const xref = this.xref,
  38230. blackColor = new Uint8ClampedArray(3);
  38231. while (queue.length > 0) {
  38232. const i = queue.shift();
  38233. const outlineDict = xref.fetchIfRef(i.obj);
  38234. if (outlineDict === null) {
  38235. continue;
  38236. }
  38237. if (!outlineDict.has("Title")) {
  38238. throw new FormatError("Invalid outline item encountered.");
  38239. }
  38240. const data = {
  38241. url: null,
  38242. dest: null,
  38243. action: null
  38244. };
  38245. Catalog.parseDestDictionary({
  38246. destDict: outlineDict,
  38247. resultObj: data,
  38248. docBaseUrl: this.baseUrl,
  38249. docAttachments: this.attachments
  38250. });
  38251. const title = outlineDict.get("Title");
  38252. const flags = outlineDict.get("F") || 0;
  38253. const color = outlineDict.getArray("C");
  38254. const count = outlineDict.get("Count");
  38255. let rgbColor = blackColor;
  38256. if (Array.isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  38257. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  38258. }
  38259. const outlineItem = {
  38260. action: data.action,
  38261. attachment: data.attachment,
  38262. dest: data.dest,
  38263. url: data.url,
  38264. unsafeUrl: data.unsafeUrl,
  38265. newWindow: data.newWindow,
  38266. setOCGState: data.setOCGState,
  38267. title: stringToPDFString(title),
  38268. color: rgbColor,
  38269. count: Number.isInteger(count) ? count : undefined,
  38270. bold: !!(flags & 2),
  38271. italic: !!(flags & 1),
  38272. items: []
  38273. };
  38274. i.parent.items.push(outlineItem);
  38275. obj = outlineDict.getRaw("First");
  38276. if (obj instanceof Ref && !processed.has(obj)) {
  38277. queue.push({
  38278. obj,
  38279. parent: outlineItem
  38280. });
  38281. processed.put(obj);
  38282. }
  38283. obj = outlineDict.getRaw("Next");
  38284. if (obj instanceof Ref && !processed.has(obj)) {
  38285. queue.push({
  38286. obj,
  38287. parent: i.parent
  38288. });
  38289. processed.put(obj);
  38290. }
  38291. }
  38292. return root.items.length > 0 ? root.items : null;
  38293. }
  38294. get permissions() {
  38295. let permissions = null;
  38296. try {
  38297. permissions = this._readPermissions();
  38298. } catch (ex) {
  38299. if (ex instanceof MissingDataException) {
  38300. throw ex;
  38301. }
  38302. warn("Unable to read permissions.");
  38303. }
  38304. return shadow(this, "permissions", permissions);
  38305. }
  38306. _readPermissions() {
  38307. const encrypt = this.xref.trailer.get("Encrypt");
  38308. if (!(encrypt instanceof Dict)) {
  38309. return null;
  38310. }
  38311. let flags = encrypt.get("P");
  38312. if (typeof flags !== "number") {
  38313. return null;
  38314. }
  38315. flags += 2 ** 32;
  38316. const permissions = [];
  38317. for (const key in PermissionFlag) {
  38318. const value = PermissionFlag[key];
  38319. if (flags & value) {
  38320. permissions.push(value);
  38321. }
  38322. }
  38323. return permissions;
  38324. }
  38325. get optionalContentConfig() {
  38326. let config = null;
  38327. try {
  38328. const properties = this._catDict.get("OCProperties");
  38329. if (!properties) {
  38330. return shadow(this, "optionalContentConfig", null);
  38331. }
  38332. const defaultConfig = properties.get("D");
  38333. if (!defaultConfig) {
  38334. return shadow(this, "optionalContentConfig", null);
  38335. }
  38336. const groupsData = properties.get("OCGs");
  38337. if (!Array.isArray(groupsData)) {
  38338. return shadow(this, "optionalContentConfig", null);
  38339. }
  38340. const groups = [];
  38341. const groupRefs = new RefSet();
  38342. for (const groupRef of groupsData) {
  38343. if (!(groupRef instanceof Ref) || groupRefs.has(groupRef)) {
  38344. continue;
  38345. }
  38346. groupRefs.put(groupRef);
  38347. const group = this.xref.fetch(groupRef);
  38348. groups.push({
  38349. id: groupRef.toString(),
  38350. name: typeof group.get("Name") === "string" ? stringToPDFString(group.get("Name")) : null,
  38351. intent: typeof group.get("Intent") === "string" ? stringToPDFString(group.get("Intent")) : null
  38352. });
  38353. }
  38354. config = this._readOptionalContentConfig(defaultConfig, groupRefs);
  38355. config.groups = groups;
  38356. } catch (ex) {
  38357. if (ex instanceof MissingDataException) {
  38358. throw ex;
  38359. }
  38360. warn(`Unable to read optional content config: ${ex}`);
  38361. }
  38362. return shadow(this, "optionalContentConfig", config);
  38363. }
  38364. _readOptionalContentConfig(config, contentGroupRefs) {
  38365. function parseOnOff(refs) {
  38366. const onParsed = [];
  38367. if (Array.isArray(refs)) {
  38368. for (const value of refs) {
  38369. if (!(value instanceof Ref)) {
  38370. continue;
  38371. }
  38372. if (contentGroupRefs.has(value)) {
  38373. onParsed.push(value.toString());
  38374. }
  38375. }
  38376. }
  38377. return onParsed;
  38378. }
  38379. function parseOrder(refs, nestedLevels = 0) {
  38380. if (!Array.isArray(refs)) {
  38381. return null;
  38382. }
  38383. const order = [];
  38384. for (const value of refs) {
  38385. if (value instanceof Ref && contentGroupRefs.has(value)) {
  38386. parsedOrderRefs.put(value);
  38387. order.push(value.toString());
  38388. continue;
  38389. }
  38390. const nestedOrder = parseNestedOrder(value, nestedLevels);
  38391. if (nestedOrder) {
  38392. order.push(nestedOrder);
  38393. }
  38394. }
  38395. if (nestedLevels > 0) {
  38396. return order;
  38397. }
  38398. const hiddenGroups = [];
  38399. for (const groupRef of contentGroupRefs) {
  38400. if (parsedOrderRefs.has(groupRef)) {
  38401. continue;
  38402. }
  38403. hiddenGroups.push(groupRef.toString());
  38404. }
  38405. if (hiddenGroups.length) {
  38406. order.push({
  38407. name: null,
  38408. order: hiddenGroups
  38409. });
  38410. }
  38411. return order;
  38412. }
  38413. function parseNestedOrder(ref, nestedLevels) {
  38414. if (++nestedLevels > MAX_NESTED_LEVELS) {
  38415. warn("parseNestedOrder - reached MAX_NESTED_LEVELS.");
  38416. return null;
  38417. }
  38418. const value = xref.fetchIfRef(ref);
  38419. if (!Array.isArray(value)) {
  38420. return null;
  38421. }
  38422. const nestedName = xref.fetchIfRef(value[0]);
  38423. if (typeof nestedName !== "string") {
  38424. return null;
  38425. }
  38426. const nestedOrder = parseOrder(value.slice(1), nestedLevels);
  38427. if (!nestedOrder || !nestedOrder.length) {
  38428. return null;
  38429. }
  38430. return {
  38431. name: stringToPDFString(nestedName),
  38432. order: nestedOrder
  38433. };
  38434. }
  38435. const xref = this.xref,
  38436. parsedOrderRefs = new RefSet(),
  38437. MAX_NESTED_LEVELS = 10;
  38438. return {
  38439. name: typeof config.get("Name") === "string" ? stringToPDFString(config.get("Name")) : null,
  38440. creator: typeof config.get("Creator") === "string" ? stringToPDFString(config.get("Creator")) : null,
  38441. baseState: config.get("BaseState") instanceof Name ? config.get("BaseState").name : null,
  38442. on: parseOnOff(config.get("ON")),
  38443. off: parseOnOff(config.get("OFF")),
  38444. order: parseOrder(config.get("Order")),
  38445. groups: null
  38446. };
  38447. }
  38448. setActualNumPages(num = null) {
  38449. this._actualNumPages = num;
  38450. }
  38451. get hasActualNumPages() {
  38452. return this._actualNumPages !== null;
  38453. }
  38454. get _pagesCount() {
  38455. const obj = this.toplevelPagesDict.get("Count");
  38456. if (!Number.isInteger(obj)) {
  38457. throw new FormatError("Page count in top-level pages dictionary is not an integer.");
  38458. }
  38459. return shadow(this, "_pagesCount", obj);
  38460. }
  38461. get numPages() {
  38462. return this.hasActualNumPages ? this._actualNumPages : this._pagesCount;
  38463. }
  38464. get destinations() {
  38465. const obj = this._readDests(),
  38466. dests = Object.create(null);
  38467. if (obj instanceof NameTree) {
  38468. for (const [key, value] of obj.getAll()) {
  38469. const dest = fetchDestination(value);
  38470. if (dest) {
  38471. dests[stringToPDFString(key)] = dest;
  38472. }
  38473. }
  38474. } else if (obj instanceof Dict) {
  38475. obj.forEach(function (key, value) {
  38476. const dest = fetchDestination(value);
  38477. if (dest) {
  38478. dests[key] = dest;
  38479. }
  38480. });
  38481. }
  38482. return shadow(this, "destinations", dests);
  38483. }
  38484. getDestination(id) {
  38485. const obj = this._readDests();
  38486. if (obj instanceof NameTree) {
  38487. const dest = fetchDestination(obj.get(id));
  38488. if (dest) {
  38489. return dest;
  38490. }
  38491. const allDest = this.destinations[id];
  38492. if (allDest) {
  38493. warn(`Found "${id}" at an incorrect position in the NameTree.`);
  38494. return allDest;
  38495. }
  38496. } else if (obj instanceof Dict) {
  38497. const dest = fetchDestination(obj.get(id));
  38498. if (dest) {
  38499. return dest;
  38500. }
  38501. }
  38502. return null;
  38503. }
  38504. _readDests() {
  38505. const obj = this._catDict.get("Names");
  38506. if (obj?.has("Dests")) {
  38507. return new NameTree(obj.getRaw("Dests"), this.xref);
  38508. } else if (this._catDict.has("Dests")) {
  38509. return this._catDict.get("Dests");
  38510. }
  38511. return undefined;
  38512. }
  38513. get pageLabels() {
  38514. let obj = null;
  38515. try {
  38516. obj = this._readPageLabels();
  38517. } catch (ex) {
  38518. if (ex instanceof MissingDataException) {
  38519. throw ex;
  38520. }
  38521. warn("Unable to read page labels.");
  38522. }
  38523. return shadow(this, "pageLabels", obj);
  38524. }
  38525. _readPageLabels() {
  38526. const obj = this._catDict.getRaw("PageLabels");
  38527. if (!obj) {
  38528. return null;
  38529. }
  38530. const pageLabels = new Array(this.numPages);
  38531. let style = null,
  38532. prefix = "";
  38533. const numberTree = new NumberTree(obj, this.xref);
  38534. const nums = numberTree.getAll();
  38535. let currentLabel = "",
  38536. currentIndex = 1;
  38537. for (let i = 0, ii = this.numPages; i < ii; i++) {
  38538. const labelDict = nums.get(i);
  38539. if (labelDict !== undefined) {
  38540. if (!(labelDict instanceof Dict)) {
  38541. throw new FormatError("PageLabel is not a dictionary.");
  38542. }
  38543. if (labelDict.has("Type") && !isName(labelDict.get("Type"), "PageLabel")) {
  38544. throw new FormatError("Invalid type in PageLabel dictionary.");
  38545. }
  38546. if (labelDict.has("S")) {
  38547. const s = labelDict.get("S");
  38548. if (!(s instanceof Name)) {
  38549. throw new FormatError("Invalid style in PageLabel dictionary.");
  38550. }
  38551. style = s.name;
  38552. } else {
  38553. style = null;
  38554. }
  38555. if (labelDict.has("P")) {
  38556. const p = labelDict.get("P");
  38557. if (typeof p !== "string") {
  38558. throw new FormatError("Invalid prefix in PageLabel dictionary.");
  38559. }
  38560. prefix = stringToPDFString(p);
  38561. } else {
  38562. prefix = "";
  38563. }
  38564. if (labelDict.has("St")) {
  38565. const st = labelDict.get("St");
  38566. if (!(Number.isInteger(st) && st >= 1)) {
  38567. throw new FormatError("Invalid start in PageLabel dictionary.");
  38568. }
  38569. currentIndex = st;
  38570. } else {
  38571. currentIndex = 1;
  38572. }
  38573. }
  38574. switch (style) {
  38575. case "D":
  38576. currentLabel = currentIndex;
  38577. break;
  38578. case "R":
  38579. case "r":
  38580. currentLabel = toRomanNumerals(currentIndex, style === "r");
  38581. break;
  38582. case "A":
  38583. case "a":
  38584. const LIMIT = 26;
  38585. const A_UPPER_CASE = 0x41,
  38586. A_LOWER_CASE = 0x61;
  38587. const baseCharCode = style === "a" ? A_LOWER_CASE : A_UPPER_CASE;
  38588. const letterIndex = currentIndex - 1;
  38589. const character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  38590. currentLabel = character.repeat(Math.floor(letterIndex / LIMIT) + 1);
  38591. break;
  38592. default:
  38593. if (style) {
  38594. throw new FormatError(`Invalid style "${style}" in PageLabel dictionary.`);
  38595. }
  38596. currentLabel = "";
  38597. }
  38598. pageLabels[i] = prefix + currentLabel;
  38599. currentIndex++;
  38600. }
  38601. return pageLabels;
  38602. }
  38603. get pageLayout() {
  38604. const obj = this._catDict.get("PageLayout");
  38605. let pageLayout = "";
  38606. if (obj instanceof Name) {
  38607. switch (obj.name) {
  38608. case "SinglePage":
  38609. case "OneColumn":
  38610. case "TwoColumnLeft":
  38611. case "TwoColumnRight":
  38612. case "TwoPageLeft":
  38613. case "TwoPageRight":
  38614. pageLayout = obj.name;
  38615. }
  38616. }
  38617. return shadow(this, "pageLayout", pageLayout);
  38618. }
  38619. get pageMode() {
  38620. const obj = this._catDict.get("PageMode");
  38621. let pageMode = "UseNone";
  38622. if (obj instanceof Name) {
  38623. switch (obj.name) {
  38624. case "UseNone":
  38625. case "UseOutlines":
  38626. case "UseThumbs":
  38627. case "FullScreen":
  38628. case "UseOC":
  38629. case "UseAttachments":
  38630. pageMode = obj.name;
  38631. }
  38632. }
  38633. return shadow(this, "pageMode", pageMode);
  38634. }
  38635. get viewerPreferences() {
  38636. const obj = this._catDict.get("ViewerPreferences");
  38637. if (!(obj instanceof Dict)) {
  38638. return shadow(this, "viewerPreferences", null);
  38639. }
  38640. let prefs = null;
  38641. for (const key of obj.getKeys()) {
  38642. const value = obj.get(key);
  38643. let prefValue;
  38644. switch (key) {
  38645. case "HideToolbar":
  38646. case "HideMenubar":
  38647. case "HideWindowUI":
  38648. case "FitWindow":
  38649. case "CenterWindow":
  38650. case "DisplayDocTitle":
  38651. case "PickTrayByPDFSize":
  38652. if (typeof value === "boolean") {
  38653. prefValue = value;
  38654. }
  38655. break;
  38656. case "NonFullScreenPageMode":
  38657. if (value instanceof Name) {
  38658. switch (value.name) {
  38659. case "UseNone":
  38660. case "UseOutlines":
  38661. case "UseThumbs":
  38662. case "UseOC":
  38663. prefValue = value.name;
  38664. break;
  38665. default:
  38666. prefValue = "UseNone";
  38667. }
  38668. }
  38669. break;
  38670. case "Direction":
  38671. if (value instanceof Name) {
  38672. switch (value.name) {
  38673. case "L2R":
  38674. case "R2L":
  38675. prefValue = value.name;
  38676. break;
  38677. default:
  38678. prefValue = "L2R";
  38679. }
  38680. }
  38681. break;
  38682. case "ViewArea":
  38683. case "ViewClip":
  38684. case "PrintArea":
  38685. case "PrintClip":
  38686. if (value instanceof Name) {
  38687. switch (value.name) {
  38688. case "MediaBox":
  38689. case "CropBox":
  38690. case "BleedBox":
  38691. case "TrimBox":
  38692. case "ArtBox":
  38693. prefValue = value.name;
  38694. break;
  38695. default:
  38696. prefValue = "CropBox";
  38697. }
  38698. }
  38699. break;
  38700. case "PrintScaling":
  38701. if (value instanceof Name) {
  38702. switch (value.name) {
  38703. case "None":
  38704. case "AppDefault":
  38705. prefValue = value.name;
  38706. break;
  38707. default:
  38708. prefValue = "AppDefault";
  38709. }
  38710. }
  38711. break;
  38712. case "Duplex":
  38713. if (value instanceof Name) {
  38714. switch (value.name) {
  38715. case "Simplex":
  38716. case "DuplexFlipShortEdge":
  38717. case "DuplexFlipLongEdge":
  38718. prefValue = value.name;
  38719. break;
  38720. default:
  38721. prefValue = "None";
  38722. }
  38723. }
  38724. break;
  38725. case "PrintPageRange":
  38726. if (Array.isArray(value) && value.length % 2 === 0) {
  38727. const isValid = value.every((page, i, arr) => {
  38728. return Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages;
  38729. });
  38730. if (isValid) {
  38731. prefValue = value;
  38732. }
  38733. }
  38734. break;
  38735. case "NumCopies":
  38736. if (Number.isInteger(value) && value > 0) {
  38737. prefValue = value;
  38738. }
  38739. break;
  38740. default:
  38741. warn(`Ignoring non-standard key in ViewerPreferences: ${key}.`);
  38742. continue;
  38743. }
  38744. if (prefValue === undefined) {
  38745. warn(`Bad value, for key "${key}", in ViewerPreferences: ${value}.`);
  38746. continue;
  38747. }
  38748. if (!prefs) {
  38749. prefs = Object.create(null);
  38750. }
  38751. prefs[key] = prefValue;
  38752. }
  38753. return shadow(this, "viewerPreferences", prefs);
  38754. }
  38755. get openAction() {
  38756. const obj = this._catDict.get("OpenAction");
  38757. const openAction = Object.create(null);
  38758. if (obj instanceof Dict) {
  38759. const destDict = new Dict(this.xref);
  38760. destDict.set("A", obj);
  38761. const resultObj = {
  38762. url: null,
  38763. dest: null,
  38764. action: null
  38765. };
  38766. Catalog.parseDestDictionary({
  38767. destDict,
  38768. resultObj
  38769. });
  38770. if (Array.isArray(resultObj.dest)) {
  38771. openAction.dest = resultObj.dest;
  38772. } else if (resultObj.action) {
  38773. openAction.action = resultObj.action;
  38774. }
  38775. } else if (Array.isArray(obj)) {
  38776. openAction.dest = obj;
  38777. }
  38778. return shadow(this, "openAction", objectSize(openAction) > 0 ? openAction : null);
  38779. }
  38780. get attachments() {
  38781. const obj = this._catDict.get("Names");
  38782. let attachments = null;
  38783. if (obj instanceof Dict && obj.has("EmbeddedFiles")) {
  38784. const nameTree = new NameTree(obj.getRaw("EmbeddedFiles"), this.xref);
  38785. for (const [key, value] of nameTree.getAll()) {
  38786. const fs = new FileSpec(value, this.xref);
  38787. if (!attachments) {
  38788. attachments = Object.create(null);
  38789. }
  38790. attachments[stringToPDFString(key)] = fs.serializable;
  38791. }
  38792. }
  38793. return shadow(this, "attachments", attachments);
  38794. }
  38795. get xfaImages() {
  38796. const obj = this._catDict.get("Names");
  38797. let xfaImages = null;
  38798. if (obj instanceof Dict && obj.has("XFAImages")) {
  38799. const nameTree = new NameTree(obj.getRaw("XFAImages"), this.xref);
  38800. for (const [key, value] of nameTree.getAll()) {
  38801. if (!xfaImages) {
  38802. xfaImages = new Dict(this.xref);
  38803. }
  38804. xfaImages.set(stringToPDFString(key), value);
  38805. }
  38806. }
  38807. return shadow(this, "xfaImages", xfaImages);
  38808. }
  38809. _collectJavaScript() {
  38810. const obj = this._catDict.get("Names");
  38811. let javaScript = null;
  38812. function appendIfJavaScriptDict(name, jsDict) {
  38813. if (!(jsDict instanceof Dict)) {
  38814. return;
  38815. }
  38816. if (!isName(jsDict.get("S"), "JavaScript")) {
  38817. return;
  38818. }
  38819. let js = jsDict.get("JS");
  38820. if (js instanceof BaseStream) {
  38821. js = js.getString();
  38822. } else if (typeof js !== "string") {
  38823. return;
  38824. }
  38825. js = stringToPDFString(js).replaceAll("\x00", "");
  38826. if (js) {
  38827. (javaScript ||= new Map()).set(name, js);
  38828. }
  38829. }
  38830. if (obj instanceof Dict && obj.has("JavaScript")) {
  38831. const nameTree = new NameTree(obj.getRaw("JavaScript"), this.xref);
  38832. for (const [key, value] of nameTree.getAll()) {
  38833. appendIfJavaScriptDict(stringToPDFString(key), value);
  38834. }
  38835. }
  38836. const openAction = this._catDict.get("OpenAction");
  38837. if (openAction) {
  38838. appendIfJavaScriptDict("OpenAction", openAction);
  38839. }
  38840. return javaScript;
  38841. }
  38842. get jsActions() {
  38843. const javaScript = this._collectJavaScript();
  38844. let actions = collectActions(this.xref, this._catDict, DocumentActionEventType);
  38845. if (javaScript) {
  38846. actions ||= Object.create(null);
  38847. for (const [key, val] of javaScript) {
  38848. if (key in actions) {
  38849. actions[key].push(val);
  38850. } else {
  38851. actions[key] = [val];
  38852. }
  38853. }
  38854. }
  38855. return shadow(this, "jsActions", actions);
  38856. }
  38857. async fontFallback(id, handler) {
  38858. const translatedFonts = await Promise.all(this.fontCache);
  38859. for (const translatedFont of translatedFonts) {
  38860. if (translatedFont.loadedName === id) {
  38861. translatedFont.fallback(handler);
  38862. return;
  38863. }
  38864. }
  38865. }
  38866. async cleanup(manuallyTriggered = false) {
  38867. clearGlobalCaches();
  38868. this.globalImageCache.clear(manuallyTriggered);
  38869. this.pageKidsCountCache.clear();
  38870. this.pageIndexCache.clear();
  38871. this.nonBlendModesSet.clear();
  38872. const translatedFonts = await Promise.all(this.fontCache);
  38873. for (const {
  38874. dict
  38875. } of translatedFonts) {
  38876. delete dict.cacheKey;
  38877. }
  38878. this.fontCache.clear();
  38879. this.builtInCMapCache.clear();
  38880. this.standardFontDataCache.clear();
  38881. this.systemFontCache.clear();
  38882. }
  38883. async getPageDict(pageIndex) {
  38884. const nodesToVisit = [this.toplevelPagesDict];
  38885. const visitedNodes = new RefSet();
  38886. const pagesRef = this._catDict.getRaw("Pages");
  38887. if (pagesRef instanceof Ref) {
  38888. visitedNodes.put(pagesRef);
  38889. }
  38890. const xref = this.xref,
  38891. pageKidsCountCache = this.pageKidsCountCache,
  38892. pageIndexCache = this.pageIndexCache;
  38893. let currentPageIndex = 0;
  38894. while (nodesToVisit.length) {
  38895. const currentNode = nodesToVisit.pop();
  38896. if (currentNode instanceof Ref) {
  38897. const count = pageKidsCountCache.get(currentNode);
  38898. if (count >= 0 && currentPageIndex + count <= pageIndex) {
  38899. currentPageIndex += count;
  38900. continue;
  38901. }
  38902. if (visitedNodes.has(currentNode)) {
  38903. throw new FormatError("Pages tree contains circular reference.");
  38904. }
  38905. visitedNodes.put(currentNode);
  38906. const obj = await xref.fetchAsync(currentNode);
  38907. if (obj instanceof Dict) {
  38908. let type = obj.getRaw("Type");
  38909. if (type instanceof Ref) {
  38910. type = await xref.fetchAsync(type);
  38911. }
  38912. if (isName(type, "Page") || !obj.has("Kids")) {
  38913. if (!pageKidsCountCache.has(currentNode)) {
  38914. pageKidsCountCache.put(currentNode, 1);
  38915. }
  38916. if (!pageIndexCache.has(currentNode)) {
  38917. pageIndexCache.put(currentNode, currentPageIndex);
  38918. }
  38919. if (currentPageIndex === pageIndex) {
  38920. return [obj, currentNode];
  38921. }
  38922. currentPageIndex++;
  38923. continue;
  38924. }
  38925. }
  38926. nodesToVisit.push(obj);
  38927. continue;
  38928. }
  38929. if (!(currentNode instanceof Dict)) {
  38930. throw new FormatError("Page dictionary kid reference points to wrong type of object.");
  38931. }
  38932. const {
  38933. objId
  38934. } = currentNode;
  38935. let count = currentNode.getRaw("Count");
  38936. if (count instanceof Ref) {
  38937. count = await xref.fetchAsync(count);
  38938. }
  38939. if (Number.isInteger(count) && count >= 0) {
  38940. if (objId && !pageKidsCountCache.has(objId)) {
  38941. pageKidsCountCache.put(objId, count);
  38942. }
  38943. if (currentPageIndex + count <= pageIndex) {
  38944. currentPageIndex += count;
  38945. continue;
  38946. }
  38947. }
  38948. let kids = currentNode.getRaw("Kids");
  38949. if (kids instanceof Ref) {
  38950. kids = await xref.fetchAsync(kids);
  38951. }
  38952. if (!Array.isArray(kids)) {
  38953. let type = currentNode.getRaw("Type");
  38954. if (type instanceof Ref) {
  38955. type = await xref.fetchAsync(type);
  38956. }
  38957. if (isName(type, "Page") || !currentNode.has("Kids")) {
  38958. if (currentPageIndex === pageIndex) {
  38959. return [currentNode, null];
  38960. }
  38961. currentPageIndex++;
  38962. continue;
  38963. }
  38964. throw new FormatError("Page dictionary kids object is not an array.");
  38965. }
  38966. for (let last = kids.length - 1; last >= 0; last--) {
  38967. nodesToVisit.push(kids[last]);
  38968. }
  38969. }
  38970. throw new Error(`Page index ${pageIndex} not found.`);
  38971. }
  38972. async getAllPageDicts(recoveryMode = false) {
  38973. const {
  38974. ignoreErrors
  38975. } = this.pdfManager.evaluatorOptions;
  38976. const queue = [{
  38977. currentNode: this.toplevelPagesDict,
  38978. posInKids: 0
  38979. }];
  38980. const visitedNodes = new RefSet();
  38981. const pagesRef = this._catDict.getRaw("Pages");
  38982. if (pagesRef instanceof Ref) {
  38983. visitedNodes.put(pagesRef);
  38984. }
  38985. const map = new Map(),
  38986. xref = this.xref,
  38987. pageIndexCache = this.pageIndexCache;
  38988. let pageIndex = 0;
  38989. function addPageDict(pageDict, pageRef) {
  38990. if (pageRef && !pageIndexCache.has(pageRef)) {
  38991. pageIndexCache.put(pageRef, pageIndex);
  38992. }
  38993. map.set(pageIndex++, [pageDict, pageRef]);
  38994. }
  38995. function addPageError(error) {
  38996. if (error instanceof XRefEntryException && !recoveryMode) {
  38997. throw error;
  38998. }
  38999. if (recoveryMode && ignoreErrors && pageIndex === 0) {
  39000. warn(`getAllPageDicts - Skipping invalid first page: "${error}".`);
  39001. error = Dict.empty;
  39002. }
  39003. map.set(pageIndex++, [error, null]);
  39004. }
  39005. while (queue.length > 0) {
  39006. const queueItem = queue.at(-1);
  39007. const {
  39008. currentNode,
  39009. posInKids
  39010. } = queueItem;
  39011. let kids = currentNode.getRaw("Kids");
  39012. if (kids instanceof Ref) {
  39013. try {
  39014. kids = await xref.fetchAsync(kids);
  39015. } catch (ex) {
  39016. addPageError(ex);
  39017. break;
  39018. }
  39019. }
  39020. if (!Array.isArray(kids)) {
  39021. addPageError(new FormatError("Page dictionary kids object is not an array."));
  39022. break;
  39023. }
  39024. if (posInKids >= kids.length) {
  39025. queue.pop();
  39026. continue;
  39027. }
  39028. const kidObj = kids[posInKids];
  39029. let obj;
  39030. if (kidObj instanceof Ref) {
  39031. if (visitedNodes.has(kidObj)) {
  39032. addPageError(new FormatError("Pages tree contains circular reference."));
  39033. break;
  39034. }
  39035. visitedNodes.put(kidObj);
  39036. try {
  39037. obj = await xref.fetchAsync(kidObj);
  39038. } catch (ex) {
  39039. addPageError(ex);
  39040. break;
  39041. }
  39042. } else {
  39043. obj = kidObj;
  39044. }
  39045. if (!(obj instanceof Dict)) {
  39046. addPageError(new FormatError("Page dictionary kid reference points to wrong type of object."));
  39047. break;
  39048. }
  39049. let type = obj.getRaw("Type");
  39050. if (type instanceof Ref) {
  39051. try {
  39052. type = await xref.fetchAsync(type);
  39053. } catch (ex) {
  39054. addPageError(ex);
  39055. break;
  39056. }
  39057. }
  39058. if (isName(type, "Page") || !obj.has("Kids")) {
  39059. addPageDict(obj, kidObj instanceof Ref ? kidObj : null);
  39060. } else {
  39061. queue.push({
  39062. currentNode: obj,
  39063. posInKids: 0
  39064. });
  39065. }
  39066. queueItem.posInKids++;
  39067. }
  39068. return map;
  39069. }
  39070. getPageIndex(pageRef) {
  39071. const cachedPageIndex = this.pageIndexCache.get(pageRef);
  39072. if (cachedPageIndex !== undefined) {
  39073. return Promise.resolve(cachedPageIndex);
  39074. }
  39075. const xref = this.xref;
  39076. function pagesBeforeRef(kidRef) {
  39077. let total = 0,
  39078. parentRef;
  39079. return xref.fetchAsync(kidRef).then(function (node) {
  39080. if (isRefsEqual(kidRef, pageRef) && !isDict(node, "Page") && !(node instanceof Dict && !node.has("Type") && node.has("Contents"))) {
  39081. throw new FormatError("The reference does not point to a /Page dictionary.");
  39082. }
  39083. if (!node) {
  39084. return null;
  39085. }
  39086. if (!(node instanceof Dict)) {
  39087. throw new FormatError("Node must be a dictionary.");
  39088. }
  39089. parentRef = node.getRaw("Parent");
  39090. return node.getAsync("Parent");
  39091. }).then(function (parent) {
  39092. if (!parent) {
  39093. return null;
  39094. }
  39095. if (!(parent instanceof Dict)) {
  39096. throw new FormatError("Parent must be a dictionary.");
  39097. }
  39098. return parent.getAsync("Kids");
  39099. }).then(function (kids) {
  39100. if (!kids) {
  39101. return null;
  39102. }
  39103. const kidPromises = [];
  39104. let found = false;
  39105. for (const kid of kids) {
  39106. if (!(kid instanceof Ref)) {
  39107. throw new FormatError("Kid must be a reference.");
  39108. }
  39109. if (isRefsEqual(kid, kidRef)) {
  39110. found = true;
  39111. break;
  39112. }
  39113. kidPromises.push(xref.fetchAsync(kid).then(function (obj) {
  39114. if (!(obj instanceof Dict)) {
  39115. throw new FormatError("Kid node must be a dictionary.");
  39116. }
  39117. if (obj.has("Count")) {
  39118. total += obj.get("Count");
  39119. } else {
  39120. total++;
  39121. }
  39122. }));
  39123. }
  39124. if (!found) {
  39125. throw new FormatError("Kid reference not found in parent's kids.");
  39126. }
  39127. return Promise.all(kidPromises).then(function () {
  39128. return [total, parentRef];
  39129. });
  39130. });
  39131. }
  39132. let total = 0;
  39133. const next = ref => pagesBeforeRef(ref).then(args => {
  39134. if (!args) {
  39135. this.pageIndexCache.put(pageRef, total);
  39136. return total;
  39137. }
  39138. const [count, parentRef] = args;
  39139. total += count;
  39140. return next(parentRef);
  39141. });
  39142. return next(pageRef);
  39143. }
  39144. get baseUrl() {
  39145. const uri = this._catDict.get("URI");
  39146. if (uri instanceof Dict) {
  39147. const base = uri.get("Base");
  39148. if (typeof base === "string") {
  39149. const absoluteUrl = createValidAbsoluteUrl(base, null, {
  39150. tryConvertEncoding: true
  39151. });
  39152. if (absoluteUrl) {
  39153. return shadow(this, "baseUrl", absoluteUrl.href);
  39154. }
  39155. }
  39156. }
  39157. return shadow(this, "baseUrl", this.pdfManager.docBaseUrl);
  39158. }
  39159. static parseDestDictionary({
  39160. destDict,
  39161. resultObj,
  39162. docBaseUrl = null,
  39163. docAttachments = null
  39164. }) {
  39165. if (!(destDict instanceof Dict)) {
  39166. warn("parseDestDictionary: `destDict` must be a dictionary.");
  39167. return;
  39168. }
  39169. let action = destDict.get("A"),
  39170. url,
  39171. dest;
  39172. if (!(action instanceof Dict)) {
  39173. if (destDict.has("Dest")) {
  39174. action = destDict.get("Dest");
  39175. } else {
  39176. action = destDict.get("AA");
  39177. if (action instanceof Dict) {
  39178. if (action.has("D")) {
  39179. action = action.get("D");
  39180. } else if (action.has("U")) {
  39181. action = action.get("U");
  39182. }
  39183. }
  39184. }
  39185. }
  39186. if (action instanceof Dict) {
  39187. const actionType = action.get("S");
  39188. if (!(actionType instanceof Name)) {
  39189. warn("parseDestDictionary: Invalid type in Action dictionary.");
  39190. return;
  39191. }
  39192. const actionName = actionType.name;
  39193. switch (actionName) {
  39194. case "ResetForm":
  39195. const flags = action.get("Flags");
  39196. const include = ((typeof flags === "number" ? flags : 0) & 1) === 0;
  39197. const fields = [];
  39198. const refs = [];
  39199. for (const obj of action.get("Fields") || []) {
  39200. if (obj instanceof Ref) {
  39201. refs.push(obj.toString());
  39202. } else if (typeof obj === "string") {
  39203. fields.push(stringToPDFString(obj));
  39204. }
  39205. }
  39206. resultObj.resetForm = {
  39207. fields,
  39208. refs,
  39209. include
  39210. };
  39211. break;
  39212. case "URI":
  39213. url = action.get("URI");
  39214. if (url instanceof Name) {
  39215. url = "/" + url.name;
  39216. }
  39217. break;
  39218. case "GoTo":
  39219. dest = action.get("D");
  39220. break;
  39221. case "Launch":
  39222. case "GoToR":
  39223. const urlDict = action.get("F");
  39224. if (urlDict instanceof Dict) {
  39225. url = urlDict.get("F") || null;
  39226. } else if (typeof urlDict === "string") {
  39227. url = urlDict;
  39228. }
  39229. const remoteDest = fetchRemoteDest(action);
  39230. if (remoteDest && typeof url === "string") {
  39231. url = url.split("#", 1)[0] + "#" + remoteDest;
  39232. }
  39233. const newWindow = action.get("NewWindow");
  39234. if (typeof newWindow === "boolean") {
  39235. resultObj.newWindow = newWindow;
  39236. }
  39237. break;
  39238. case "GoToE":
  39239. const target = action.get("T");
  39240. let attachment;
  39241. if (docAttachments && target instanceof Dict) {
  39242. const relationship = target.get("R");
  39243. const name = target.get("N");
  39244. if (isName(relationship, "C") && typeof name === "string") {
  39245. attachment = docAttachments[stringToPDFString(name)];
  39246. }
  39247. }
  39248. if (attachment) {
  39249. resultObj.attachment = attachment;
  39250. const attachmentDest = fetchRemoteDest(action);
  39251. if (attachmentDest) {
  39252. resultObj.attachmentDest = attachmentDest;
  39253. }
  39254. } else {
  39255. warn(`parseDestDictionary - unimplemented "GoToE" action.`);
  39256. }
  39257. break;
  39258. case "Named":
  39259. const namedAction = action.get("N");
  39260. if (namedAction instanceof Name) {
  39261. resultObj.action = namedAction.name;
  39262. }
  39263. break;
  39264. case "SetOCGState":
  39265. const state = action.get("State");
  39266. const preserveRB = action.get("PreserveRB");
  39267. if (!Array.isArray(state) || state.length === 0) {
  39268. break;
  39269. }
  39270. const stateArr = [];
  39271. for (const elem of state) {
  39272. if (elem instanceof Name) {
  39273. switch (elem.name) {
  39274. case "ON":
  39275. case "OFF":
  39276. case "Toggle":
  39277. stateArr.push(elem.name);
  39278. break;
  39279. }
  39280. } else if (elem instanceof Ref) {
  39281. stateArr.push(elem.toString());
  39282. }
  39283. }
  39284. if (stateArr.length !== state.length) {
  39285. break;
  39286. }
  39287. resultObj.setOCGState = {
  39288. state: stateArr,
  39289. preserveRB: typeof preserveRB === "boolean" ? preserveRB : true
  39290. };
  39291. break;
  39292. case "JavaScript":
  39293. const jsAction = action.get("JS");
  39294. let js;
  39295. if (jsAction instanceof BaseStream) {
  39296. js = jsAction.getString();
  39297. } else if (typeof jsAction === "string") {
  39298. js = jsAction;
  39299. }
  39300. const jsURL = js && recoverJsURL(stringToPDFString(js));
  39301. if (jsURL) {
  39302. url = jsURL.url;
  39303. resultObj.newWindow = jsURL.newWindow;
  39304. break;
  39305. }
  39306. default:
  39307. if (actionName === "JavaScript" || actionName === "SubmitForm") {
  39308. break;
  39309. }
  39310. warn(`parseDestDictionary - unsupported action: "${actionName}".`);
  39311. break;
  39312. }
  39313. } else if (destDict.has("Dest")) {
  39314. dest = destDict.get("Dest");
  39315. }
  39316. if (typeof url === "string") {
  39317. const absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl, {
  39318. addDefaultProtocol: true,
  39319. tryConvertEncoding: true
  39320. });
  39321. if (absoluteUrl) {
  39322. resultObj.url = absoluteUrl.href;
  39323. }
  39324. resultObj.unsafeUrl = url;
  39325. }
  39326. if (dest) {
  39327. if (dest instanceof Name) {
  39328. dest = dest.name;
  39329. }
  39330. if (typeof dest === "string") {
  39331. resultObj.dest = stringToPDFString(dest);
  39332. } else if (Array.isArray(dest)) {
  39333. resultObj.dest = dest;
  39334. }
  39335. }
  39336. }
  39337. }
  39338. ;// CONCATENATED MODULE: ./src/core/object_loader.js
  39339. function mayHaveChildren(value) {
  39340. return value instanceof Ref || value instanceof Dict || value instanceof BaseStream || Array.isArray(value);
  39341. }
  39342. function addChildren(node, nodesToVisit) {
  39343. if (node instanceof Dict) {
  39344. node = node.getRawValues();
  39345. } else if (node instanceof BaseStream) {
  39346. node = node.dict.getRawValues();
  39347. } else if (!Array.isArray(node)) {
  39348. return;
  39349. }
  39350. for (const rawValue of node) {
  39351. if (mayHaveChildren(rawValue)) {
  39352. nodesToVisit.push(rawValue);
  39353. }
  39354. }
  39355. }
  39356. class ObjectLoader {
  39357. constructor(dict, keys, xref) {
  39358. this.dict = dict;
  39359. this.keys = keys;
  39360. this.xref = xref;
  39361. this.refSet = null;
  39362. }
  39363. async load() {
  39364. if (this.xref.stream.isDataLoaded) {
  39365. return undefined;
  39366. }
  39367. const {
  39368. keys,
  39369. dict
  39370. } = this;
  39371. this.refSet = new RefSet();
  39372. const nodesToVisit = [];
  39373. for (const key of keys) {
  39374. const rawValue = dict.getRaw(key);
  39375. if (rawValue !== undefined) {
  39376. nodesToVisit.push(rawValue);
  39377. }
  39378. }
  39379. return this._walk(nodesToVisit);
  39380. }
  39381. async _walk(nodesToVisit) {
  39382. const nodesToRevisit = [];
  39383. const pendingRequests = [];
  39384. while (nodesToVisit.length) {
  39385. let currentNode = nodesToVisit.pop();
  39386. if (currentNode instanceof Ref) {
  39387. if (this.refSet.has(currentNode)) {
  39388. continue;
  39389. }
  39390. try {
  39391. this.refSet.put(currentNode);
  39392. currentNode = this.xref.fetch(currentNode);
  39393. } catch (ex) {
  39394. if (!(ex instanceof MissingDataException)) {
  39395. warn(`ObjectLoader._walk - requesting all data: "${ex}".`);
  39396. this.refSet = null;
  39397. const {
  39398. manager
  39399. } = this.xref.stream;
  39400. return manager.requestAllChunks();
  39401. }
  39402. nodesToRevisit.push(currentNode);
  39403. pendingRequests.push({
  39404. begin: ex.begin,
  39405. end: ex.end
  39406. });
  39407. }
  39408. }
  39409. if (currentNode instanceof BaseStream) {
  39410. const baseStreams = currentNode.getBaseStreams();
  39411. if (baseStreams) {
  39412. let foundMissingData = false;
  39413. for (const stream of baseStreams) {
  39414. if (stream.isDataLoaded) {
  39415. continue;
  39416. }
  39417. foundMissingData = true;
  39418. pendingRequests.push({
  39419. begin: stream.start,
  39420. end: stream.end
  39421. });
  39422. }
  39423. if (foundMissingData) {
  39424. nodesToRevisit.push(currentNode);
  39425. }
  39426. }
  39427. }
  39428. addChildren(currentNode, nodesToVisit);
  39429. }
  39430. if (pendingRequests.length) {
  39431. await this.xref.stream.manager.requestRanges(pendingRequests);
  39432. for (const node of nodesToRevisit) {
  39433. if (node instanceof Ref) {
  39434. this.refSet.remove(node);
  39435. }
  39436. }
  39437. return this._walk(nodesToRevisit);
  39438. }
  39439. this.refSet = null;
  39440. return undefined;
  39441. }
  39442. }
  39443. ;// CONCATENATED MODULE: ./src/core/xfa/symbol_utils.js
  39444. const $acceptWhitespace = Symbol();
  39445. const $addHTML = Symbol();
  39446. const $appendChild = Symbol();
  39447. const $childrenToHTML = Symbol();
  39448. const $clean = Symbol();
  39449. const $cleanPage = Symbol();
  39450. const $cleanup = Symbol();
  39451. const $clone = Symbol();
  39452. const $consumed = Symbol();
  39453. const $content = Symbol("content");
  39454. const $data = Symbol("data");
  39455. const $dump = Symbol();
  39456. const $extra = Symbol("extra");
  39457. const $finalize = Symbol();
  39458. const $flushHTML = Symbol();
  39459. const $getAttributeIt = Symbol();
  39460. const $getAttributes = Symbol();
  39461. const $getAvailableSpace = Symbol();
  39462. const $getChildrenByClass = Symbol();
  39463. const $getChildrenByName = Symbol();
  39464. const $getChildrenByNameIt = Symbol();
  39465. const $getDataValue = Symbol();
  39466. const $getExtra = Symbol();
  39467. const $getRealChildrenByNameIt = Symbol();
  39468. const $getChildren = Symbol();
  39469. const $getContainedChildren = Symbol();
  39470. const $getNextPage = Symbol();
  39471. const $getSubformParent = Symbol();
  39472. const $getParent = Symbol();
  39473. const $getTemplateRoot = Symbol();
  39474. const $globalData = Symbol();
  39475. const $hasSettableValue = Symbol();
  39476. const $ids = Symbol();
  39477. const $indexOf = Symbol();
  39478. const $insertAt = Symbol();
  39479. const $isCDATAXml = Symbol();
  39480. const $isBindable = Symbol();
  39481. const $isDataValue = Symbol();
  39482. const $isDescendent = Symbol();
  39483. const $isNsAgnostic = Symbol();
  39484. const $isSplittable = Symbol();
  39485. const $isThereMoreWidth = Symbol();
  39486. const $isTransparent = Symbol();
  39487. const $isUsable = Symbol();
  39488. const $lastAttribute = Symbol();
  39489. const $namespaceId = Symbol("namespaceId");
  39490. const $nodeName = Symbol("nodeName");
  39491. const $nsAttributes = Symbol();
  39492. const $onChild = Symbol();
  39493. const $onChildCheck = Symbol();
  39494. const $onText = Symbol();
  39495. const $pushGlyphs = Symbol();
  39496. const $popPara = Symbol();
  39497. const $pushPara = Symbol();
  39498. const $removeChild = Symbol();
  39499. const $root = Symbol("root");
  39500. const $resolvePrototypes = Symbol();
  39501. const $searchNode = Symbol();
  39502. const $setId = Symbol();
  39503. const $setSetAttributes = Symbol();
  39504. const $setValue = Symbol();
  39505. const $tabIndex = Symbol();
  39506. const $text = Symbol();
  39507. const $toPages = Symbol();
  39508. const $toHTML = Symbol();
  39509. const $toString = Symbol();
  39510. const $toStyle = Symbol();
  39511. const $uid = Symbol("uid");
  39512. ;// CONCATENATED MODULE: ./src/core/xfa/namespaces.js
  39513. const $buildXFAObject = Symbol();
  39514. const NamespaceIds = {
  39515. config: {
  39516. id: 0,
  39517. check: ns => ns.startsWith("http://www.xfa.org/schema/xci/")
  39518. },
  39519. connectionSet: {
  39520. id: 1,
  39521. check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-connection-set/")
  39522. },
  39523. datasets: {
  39524. id: 2,
  39525. check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-data/")
  39526. },
  39527. form: {
  39528. id: 3,
  39529. check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-form/")
  39530. },
  39531. localeSet: {
  39532. id: 4,
  39533. check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-locale-set/")
  39534. },
  39535. pdf: {
  39536. id: 5,
  39537. check: ns => ns === "http://ns.adobe.com/xdp/pdf/"
  39538. },
  39539. signature: {
  39540. id: 6,
  39541. check: ns => ns === "http://www.w3.org/2000/09/xmldsig#"
  39542. },
  39543. sourceSet: {
  39544. id: 7,
  39545. check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-source-set/")
  39546. },
  39547. stylesheet: {
  39548. id: 8,
  39549. check: ns => ns === "http://www.w3.org/1999/XSL/Transform"
  39550. },
  39551. template: {
  39552. id: 9,
  39553. check: ns => ns.startsWith("http://www.xfa.org/schema/xfa-template/")
  39554. },
  39555. xdc: {
  39556. id: 10,
  39557. check: ns => ns.startsWith("http://www.xfa.org/schema/xdc/")
  39558. },
  39559. xdp: {
  39560. id: 11,
  39561. check: ns => ns === "http://ns.adobe.com/xdp/"
  39562. },
  39563. xfdf: {
  39564. id: 12,
  39565. check: ns => ns === "http://ns.adobe.com/xfdf/"
  39566. },
  39567. xhtml: {
  39568. id: 13,
  39569. check: ns => ns === "http://www.w3.org/1999/xhtml"
  39570. },
  39571. xmpmeta: {
  39572. id: 14,
  39573. check: ns => ns === "http://ns.adobe.com/xmpmeta/"
  39574. }
  39575. };
  39576. ;// CONCATENATED MODULE: ./src/core/xfa/utils.js
  39577. const dimConverters = {
  39578. pt: x => x,
  39579. cm: x => x / 2.54 * 72,
  39580. mm: x => x / (10 * 2.54) * 72,
  39581. in: x => x * 72,
  39582. px: x => x
  39583. };
  39584. const measurementPattern = /([+-]?\d+\.?\d*)(.*)/;
  39585. function stripQuotes(str) {
  39586. if (str.startsWith("'") || str.startsWith('"')) {
  39587. return str.slice(1, -1);
  39588. }
  39589. return str;
  39590. }
  39591. function getInteger({
  39592. data,
  39593. defaultValue,
  39594. validate
  39595. }) {
  39596. if (!data) {
  39597. return defaultValue;
  39598. }
  39599. data = data.trim();
  39600. const n = parseInt(data, 10);
  39601. if (!isNaN(n) && validate(n)) {
  39602. return n;
  39603. }
  39604. return defaultValue;
  39605. }
  39606. function getFloat({
  39607. data,
  39608. defaultValue,
  39609. validate
  39610. }) {
  39611. if (!data) {
  39612. return defaultValue;
  39613. }
  39614. data = data.trim();
  39615. const n = parseFloat(data);
  39616. if (!isNaN(n) && validate(n)) {
  39617. return n;
  39618. }
  39619. return defaultValue;
  39620. }
  39621. function getKeyword({
  39622. data,
  39623. defaultValue,
  39624. validate
  39625. }) {
  39626. if (!data) {
  39627. return defaultValue;
  39628. }
  39629. data = data.trim();
  39630. if (validate(data)) {
  39631. return data;
  39632. }
  39633. return defaultValue;
  39634. }
  39635. function getStringOption(data, options) {
  39636. return getKeyword({
  39637. data,
  39638. defaultValue: options[0],
  39639. validate: k => options.includes(k)
  39640. });
  39641. }
  39642. function getMeasurement(str, def = "0") {
  39643. def ||= "0";
  39644. if (!str) {
  39645. return getMeasurement(def);
  39646. }
  39647. const match = str.trim().match(measurementPattern);
  39648. if (!match) {
  39649. return getMeasurement(def);
  39650. }
  39651. const [, valueStr, unit] = match;
  39652. const value = parseFloat(valueStr);
  39653. if (isNaN(value)) {
  39654. return getMeasurement(def);
  39655. }
  39656. if (value === 0) {
  39657. return 0;
  39658. }
  39659. const conv = dimConverters[unit];
  39660. if (conv) {
  39661. return conv(value);
  39662. }
  39663. return value;
  39664. }
  39665. function getRatio(data) {
  39666. if (!data) {
  39667. return {
  39668. num: 1,
  39669. den: 1
  39670. };
  39671. }
  39672. const ratio = data.trim().split(/\s*:\s*/).map(x => parseFloat(x)).filter(x => !isNaN(x));
  39673. if (ratio.length === 1) {
  39674. ratio.push(1);
  39675. }
  39676. if (ratio.length === 0) {
  39677. return {
  39678. num: 1,
  39679. den: 1
  39680. };
  39681. }
  39682. const [num, den] = ratio;
  39683. return {
  39684. num,
  39685. den
  39686. };
  39687. }
  39688. function getRelevant(data) {
  39689. if (!data) {
  39690. return [];
  39691. }
  39692. return data.trim().split(/\s+/).map(e => {
  39693. return {
  39694. excluded: e[0] === "-",
  39695. viewname: e.substring(1)
  39696. };
  39697. });
  39698. }
  39699. function getColor(data, def = [0, 0, 0]) {
  39700. let [r, g, b] = def;
  39701. if (!data) {
  39702. return {
  39703. r,
  39704. g,
  39705. b
  39706. };
  39707. }
  39708. const color = data.trim().split(/\s*,\s*/).map(c => Math.min(Math.max(0, parseInt(c.trim(), 10)), 255)).map(c => isNaN(c) ? 0 : c);
  39709. if (color.length < 3) {
  39710. return {
  39711. r,
  39712. g,
  39713. b
  39714. };
  39715. }
  39716. [r, g, b] = color;
  39717. return {
  39718. r,
  39719. g,
  39720. b
  39721. };
  39722. }
  39723. function getBBox(data) {
  39724. const def = -1;
  39725. if (!data) {
  39726. return {
  39727. x: def,
  39728. y: def,
  39729. width: def,
  39730. height: def
  39731. };
  39732. }
  39733. const bbox = data.trim().split(/\s*,\s*/).map(m => getMeasurement(m, "-1"));
  39734. if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) {
  39735. return {
  39736. x: def,
  39737. y: def,
  39738. width: def,
  39739. height: def
  39740. };
  39741. }
  39742. const [x, y, width, height] = bbox;
  39743. return {
  39744. x,
  39745. y,
  39746. width,
  39747. height
  39748. };
  39749. }
  39750. class HTMLResult {
  39751. static get FAILURE() {
  39752. return shadow(this, "FAILURE", new HTMLResult(false, null, null, null));
  39753. }
  39754. static get EMPTY() {
  39755. return shadow(this, "EMPTY", new HTMLResult(true, null, null, null));
  39756. }
  39757. constructor(success, html, bbox, breakNode) {
  39758. this.success = success;
  39759. this.html = html;
  39760. this.bbox = bbox;
  39761. this.breakNode = breakNode;
  39762. }
  39763. isBreak() {
  39764. return !!this.breakNode;
  39765. }
  39766. static breakNode(node) {
  39767. return new HTMLResult(false, null, null, node);
  39768. }
  39769. static success(html, bbox = null) {
  39770. return new HTMLResult(true, html, bbox, null);
  39771. }
  39772. }
  39773. ;// CONCATENATED MODULE: ./src/core/xfa/fonts.js
  39774. class FontFinder {
  39775. constructor(pdfFonts) {
  39776. this.fonts = new Map();
  39777. this.cache = new Map();
  39778. this.warned = new Set();
  39779. this.defaultFont = null;
  39780. this.add(pdfFonts);
  39781. }
  39782. add(pdfFonts, reallyMissingFonts = null) {
  39783. for (const pdfFont of pdfFonts) {
  39784. this.addPdfFont(pdfFont);
  39785. }
  39786. for (const pdfFont of this.fonts.values()) {
  39787. if (!pdfFont.regular) {
  39788. pdfFont.regular = pdfFont.italic || pdfFont.bold || pdfFont.bolditalic;
  39789. }
  39790. }
  39791. if (!reallyMissingFonts || reallyMissingFonts.size === 0) {
  39792. return;
  39793. }
  39794. const myriad = this.fonts.get("PdfJS-Fallback-PdfJS-XFA");
  39795. for (const missing of reallyMissingFonts) {
  39796. this.fonts.set(missing, myriad);
  39797. }
  39798. }
  39799. addPdfFont(pdfFont) {
  39800. const cssFontInfo = pdfFont.cssFontInfo;
  39801. const name = cssFontInfo.fontFamily;
  39802. let font = this.fonts.get(name);
  39803. if (!font) {
  39804. font = Object.create(null);
  39805. this.fonts.set(name, font);
  39806. if (!this.defaultFont) {
  39807. this.defaultFont = font;
  39808. }
  39809. }
  39810. let property = "";
  39811. const fontWeight = parseFloat(cssFontInfo.fontWeight);
  39812. if (parseFloat(cssFontInfo.italicAngle) !== 0) {
  39813. property = fontWeight >= 700 ? "bolditalic" : "italic";
  39814. } else if (fontWeight >= 700) {
  39815. property = "bold";
  39816. }
  39817. if (!property) {
  39818. if (pdfFont.name.includes("Bold") || pdfFont.psName?.includes("Bold")) {
  39819. property = "bold";
  39820. }
  39821. if (pdfFont.name.includes("Italic") || pdfFont.name.endsWith("It") || pdfFont.psName?.includes("Italic") || pdfFont.psName?.endsWith("It")) {
  39822. property += "italic";
  39823. }
  39824. }
  39825. if (!property) {
  39826. property = "regular";
  39827. }
  39828. font[property] = pdfFont;
  39829. }
  39830. getDefault() {
  39831. return this.defaultFont;
  39832. }
  39833. find(fontName, mustWarn = true) {
  39834. let font = this.fonts.get(fontName) || this.cache.get(fontName);
  39835. if (font) {
  39836. return font;
  39837. }
  39838. const pattern = /,|-|_| |bolditalic|bold|italic|regular|it/gi;
  39839. let name = fontName.replaceAll(pattern, "");
  39840. font = this.fonts.get(name);
  39841. if (font) {
  39842. this.cache.set(fontName, font);
  39843. return font;
  39844. }
  39845. name = name.toLowerCase();
  39846. const maybe = [];
  39847. for (const [family, pdfFont] of this.fonts.entries()) {
  39848. if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
  39849. maybe.push(pdfFont);
  39850. }
  39851. }
  39852. if (maybe.length === 0) {
  39853. for (const [, pdfFont] of this.fonts.entries()) {
  39854. if (pdfFont.regular.name?.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
  39855. maybe.push(pdfFont);
  39856. }
  39857. }
  39858. }
  39859. if (maybe.length === 0) {
  39860. name = name.replaceAll(/psmt|mt/gi, "");
  39861. for (const [family, pdfFont] of this.fonts.entries()) {
  39862. if (family.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
  39863. maybe.push(pdfFont);
  39864. }
  39865. }
  39866. }
  39867. if (maybe.length === 0) {
  39868. for (const pdfFont of this.fonts.values()) {
  39869. if (pdfFont.regular.name?.replaceAll(pattern, "").toLowerCase().startsWith(name)) {
  39870. maybe.push(pdfFont);
  39871. }
  39872. }
  39873. }
  39874. if (maybe.length >= 1) {
  39875. if (maybe.length !== 1 && mustWarn) {
  39876. warn(`XFA - Too many choices to guess the correct font: ${fontName}`);
  39877. }
  39878. this.cache.set(fontName, maybe[0]);
  39879. return maybe[0];
  39880. }
  39881. if (mustWarn && !this.warned.has(fontName)) {
  39882. this.warned.add(fontName);
  39883. warn(`XFA - Cannot find the font: ${fontName}`);
  39884. }
  39885. return null;
  39886. }
  39887. }
  39888. function selectFont(xfaFont, typeface) {
  39889. if (xfaFont.posture === "italic") {
  39890. if (xfaFont.weight === "bold") {
  39891. return typeface.bolditalic;
  39892. }
  39893. return typeface.italic;
  39894. } else if (xfaFont.weight === "bold") {
  39895. return typeface.bold;
  39896. }
  39897. return typeface.regular;
  39898. }
  39899. function fonts_getMetrics(xfaFont, real = false) {
  39900. let pdfFont = null;
  39901. if (xfaFont) {
  39902. const name = stripQuotes(xfaFont.typeface);
  39903. const typeface = xfaFont[$globalData].fontFinder.find(name);
  39904. pdfFont = selectFont(xfaFont, typeface);
  39905. }
  39906. if (!pdfFont) {
  39907. return {
  39908. lineHeight: 12,
  39909. lineGap: 2,
  39910. lineNoGap: 10
  39911. };
  39912. }
  39913. const size = xfaFont.size || 10;
  39914. const lineHeight = pdfFont.lineHeight ? Math.max(real ? 0 : 1.2, pdfFont.lineHeight) : 1.2;
  39915. const lineGap = pdfFont.lineGap === undefined ? 0.2 : pdfFont.lineGap;
  39916. return {
  39917. lineHeight: lineHeight * size,
  39918. lineGap: lineGap * size,
  39919. lineNoGap: Math.max(1, lineHeight - lineGap) * size
  39920. };
  39921. }
  39922. ;// CONCATENATED MODULE: ./src/core/xfa/text.js
  39923. const WIDTH_FACTOR = 1.02;
  39924. class FontInfo {
  39925. constructor(xfaFont, margin, lineHeight, fontFinder) {
  39926. this.lineHeight = lineHeight;
  39927. this.paraMargin = margin || {
  39928. top: 0,
  39929. bottom: 0,
  39930. left: 0,
  39931. right: 0
  39932. };
  39933. if (!xfaFont) {
  39934. [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
  39935. return;
  39936. }
  39937. this.xfaFont = {
  39938. typeface: xfaFont.typeface,
  39939. posture: xfaFont.posture,
  39940. weight: xfaFont.weight,
  39941. size: xfaFont.size,
  39942. letterSpacing: xfaFont.letterSpacing
  39943. };
  39944. const typeface = fontFinder.find(xfaFont.typeface);
  39945. if (!typeface) {
  39946. [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
  39947. return;
  39948. }
  39949. this.pdfFont = selectFont(xfaFont, typeface);
  39950. if (!this.pdfFont) {
  39951. [this.pdfFont, this.xfaFont] = this.defaultFont(fontFinder);
  39952. }
  39953. }
  39954. defaultFont(fontFinder) {
  39955. const font = fontFinder.find("Helvetica", false) || fontFinder.find("Myriad Pro", false) || fontFinder.find("Arial", false) || fontFinder.getDefault();
  39956. if (font?.regular) {
  39957. const pdfFont = font.regular;
  39958. const info = pdfFont.cssFontInfo;
  39959. const xfaFont = {
  39960. typeface: info.fontFamily,
  39961. posture: "normal",
  39962. weight: "normal",
  39963. size: 10,
  39964. letterSpacing: 0
  39965. };
  39966. return [pdfFont, xfaFont];
  39967. }
  39968. const xfaFont = {
  39969. typeface: "Courier",
  39970. posture: "normal",
  39971. weight: "normal",
  39972. size: 10,
  39973. letterSpacing: 0
  39974. };
  39975. return [null, xfaFont];
  39976. }
  39977. }
  39978. class FontSelector {
  39979. constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fontFinder) {
  39980. this.fontFinder = fontFinder;
  39981. this.stack = [new FontInfo(defaultXfaFont, defaultParaMargin, defaultLineHeight, fontFinder)];
  39982. }
  39983. pushData(xfaFont, margin, lineHeight) {
  39984. const lastFont = this.stack.at(-1);
  39985. for (const name of ["typeface", "posture", "weight", "size", "letterSpacing"]) {
  39986. if (!xfaFont[name]) {
  39987. xfaFont[name] = lastFont.xfaFont[name];
  39988. }
  39989. }
  39990. for (const name of ["top", "bottom", "left", "right"]) {
  39991. if (isNaN(margin[name])) {
  39992. margin[name] = lastFont.paraMargin[name];
  39993. }
  39994. }
  39995. const fontInfo = new FontInfo(xfaFont, margin, lineHeight || lastFont.lineHeight, this.fontFinder);
  39996. if (!fontInfo.pdfFont) {
  39997. fontInfo.pdfFont = lastFont.pdfFont;
  39998. }
  39999. this.stack.push(fontInfo);
  40000. }
  40001. popFont() {
  40002. this.stack.pop();
  40003. }
  40004. topFont() {
  40005. return this.stack.at(-1);
  40006. }
  40007. }
  40008. class TextMeasure {
  40009. constructor(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts) {
  40010. this.glyphs = [];
  40011. this.fontSelector = new FontSelector(defaultXfaFont, defaultParaMargin, defaultLineHeight, fonts);
  40012. this.extraHeight = 0;
  40013. }
  40014. pushData(xfaFont, margin, lineHeight) {
  40015. this.fontSelector.pushData(xfaFont, margin, lineHeight);
  40016. }
  40017. popFont(xfaFont) {
  40018. return this.fontSelector.popFont();
  40019. }
  40020. addPara() {
  40021. const lastFont = this.fontSelector.topFont();
  40022. this.extraHeight += lastFont.paraMargin.top + lastFont.paraMargin.bottom;
  40023. }
  40024. addString(str) {
  40025. if (!str) {
  40026. return;
  40027. }
  40028. const lastFont = this.fontSelector.topFont();
  40029. const fontSize = lastFont.xfaFont.size;
  40030. if (lastFont.pdfFont) {
  40031. const letterSpacing = lastFont.xfaFont.letterSpacing;
  40032. const pdfFont = lastFont.pdfFont;
  40033. const fontLineHeight = pdfFont.lineHeight || 1.2;
  40034. const lineHeight = lastFont.lineHeight || Math.max(1.2, fontLineHeight) * fontSize;
  40035. const lineGap = pdfFont.lineGap === undefined ? 0.2 : pdfFont.lineGap;
  40036. const noGap = fontLineHeight - lineGap;
  40037. const firstLineHeight = Math.max(1, noGap) * fontSize;
  40038. const scale = fontSize / 1000;
  40039. const fallbackWidth = pdfFont.defaultWidth || pdfFont.charsToGlyphs(" ")[0].width;
  40040. for (const line of str.split(/[\u2029\n]/)) {
  40041. const encodedLine = pdfFont.encodeString(line).join("");
  40042. const glyphs = pdfFont.charsToGlyphs(encodedLine);
  40043. for (const glyph of glyphs) {
  40044. const width = glyph.width || fallbackWidth;
  40045. this.glyphs.push([width * scale + letterSpacing, lineHeight, firstLineHeight, glyph.unicode, false]);
  40046. }
  40047. this.glyphs.push([0, 0, 0, "\n", true]);
  40048. }
  40049. this.glyphs.pop();
  40050. return;
  40051. }
  40052. for (const line of str.split(/[\u2029\n]/)) {
  40053. for (const char of line.split("")) {
  40054. this.glyphs.push([fontSize, 1.2 * fontSize, fontSize, char, false]);
  40055. }
  40056. this.glyphs.push([0, 0, 0, "\n", true]);
  40057. }
  40058. this.glyphs.pop();
  40059. }
  40060. compute(maxWidth) {
  40061. let lastSpacePos = -1,
  40062. lastSpaceWidth = 0,
  40063. width = 0,
  40064. height = 0,
  40065. currentLineWidth = 0,
  40066. currentLineHeight = 0;
  40067. let isBroken = false;
  40068. let isFirstLine = true;
  40069. for (let i = 0, ii = this.glyphs.length; i < ii; i++) {
  40070. const [glyphWidth, lineHeight, firstLineHeight, char, isEOL] = this.glyphs[i];
  40071. const isSpace = char === " ";
  40072. const glyphHeight = isFirstLine ? firstLineHeight : lineHeight;
  40073. if (isEOL) {
  40074. width = Math.max(width, currentLineWidth);
  40075. currentLineWidth = 0;
  40076. height += currentLineHeight;
  40077. currentLineHeight = glyphHeight;
  40078. lastSpacePos = -1;
  40079. lastSpaceWidth = 0;
  40080. isFirstLine = false;
  40081. continue;
  40082. }
  40083. if (isSpace) {
  40084. if (currentLineWidth + glyphWidth > maxWidth) {
  40085. width = Math.max(width, currentLineWidth);
  40086. currentLineWidth = 0;
  40087. height += currentLineHeight;
  40088. currentLineHeight = glyphHeight;
  40089. lastSpacePos = -1;
  40090. lastSpaceWidth = 0;
  40091. isBroken = true;
  40092. isFirstLine = false;
  40093. } else {
  40094. currentLineHeight = Math.max(glyphHeight, currentLineHeight);
  40095. lastSpaceWidth = currentLineWidth;
  40096. currentLineWidth += glyphWidth;
  40097. lastSpacePos = i;
  40098. }
  40099. continue;
  40100. }
  40101. if (currentLineWidth + glyphWidth > maxWidth) {
  40102. height += currentLineHeight;
  40103. currentLineHeight = glyphHeight;
  40104. if (lastSpacePos !== -1) {
  40105. i = lastSpacePos;
  40106. width = Math.max(width, lastSpaceWidth);
  40107. currentLineWidth = 0;
  40108. lastSpacePos = -1;
  40109. lastSpaceWidth = 0;
  40110. } else {
  40111. width = Math.max(width, currentLineWidth);
  40112. currentLineWidth = glyphWidth;
  40113. }
  40114. isBroken = true;
  40115. isFirstLine = false;
  40116. continue;
  40117. }
  40118. currentLineWidth += glyphWidth;
  40119. currentLineHeight = Math.max(glyphHeight, currentLineHeight);
  40120. }
  40121. width = Math.max(width, currentLineWidth);
  40122. height += currentLineHeight + this.extraHeight;
  40123. return {
  40124. width: WIDTH_FACTOR * width,
  40125. height,
  40126. isBroken
  40127. };
  40128. }
  40129. }
  40130. ;// CONCATENATED MODULE: ./src/core/xfa/som.js
  40131. const namePattern = /^[^.[]+/;
  40132. const indexPattern = /^[^\]]+/;
  40133. const operators = {
  40134. dot: 0,
  40135. dotDot: 1,
  40136. dotHash: 2,
  40137. dotBracket: 3,
  40138. dotParen: 4
  40139. };
  40140. const shortcuts = new Map([["$data", (root, current) => root.datasets ? root.datasets.data : root], ["$record", (root, current) => (root.datasets ? root.datasets.data : root)[$getChildren]()[0]], ["$template", (root, current) => root.template], ["$connectionSet", (root, current) => root.connectionSet], ["$form", (root, current) => root.form], ["$layout", (root, current) => root.layout], ["$host", (root, current) => root.host], ["$dataWindow", (root, current) => root.dataWindow], ["$event", (root, current) => root.event], ["!", (root, current) => root.datasets], ["$xfa", (root, current) => root], ["xfa", (root, current) => root], ["$", (root, current) => current]]);
  40141. const somCache = new WeakMap();
  40142. function parseIndex(index) {
  40143. index = index.trim();
  40144. if (index === "*") {
  40145. return Infinity;
  40146. }
  40147. return parseInt(index, 10) || 0;
  40148. }
  40149. function parseExpression(expr, dotDotAllowed, noExpr = true) {
  40150. let match = expr.match(namePattern);
  40151. if (!match) {
  40152. return null;
  40153. }
  40154. let [name] = match;
  40155. const parsed = [{
  40156. name,
  40157. cacheName: "." + name,
  40158. index: 0,
  40159. js: null,
  40160. formCalc: null,
  40161. operator: operators.dot
  40162. }];
  40163. let pos = name.length;
  40164. while (pos < expr.length) {
  40165. const spos = pos;
  40166. const char = expr.charAt(pos++);
  40167. if (char === "[") {
  40168. match = expr.slice(pos).match(indexPattern);
  40169. if (!match) {
  40170. warn("XFA - Invalid index in SOM expression");
  40171. return null;
  40172. }
  40173. parsed.at(-1).index = parseIndex(match[0]);
  40174. pos += match[0].length + 1;
  40175. continue;
  40176. }
  40177. let operator;
  40178. switch (expr.charAt(pos)) {
  40179. case ".":
  40180. if (!dotDotAllowed) {
  40181. return null;
  40182. }
  40183. pos++;
  40184. operator = operators.dotDot;
  40185. break;
  40186. case "#":
  40187. pos++;
  40188. operator = operators.dotHash;
  40189. break;
  40190. case "[":
  40191. if (noExpr) {
  40192. warn("XFA - SOM expression contains a FormCalc subexpression which is not supported for now.");
  40193. return null;
  40194. }
  40195. operator = operators.dotBracket;
  40196. break;
  40197. case "(":
  40198. if (noExpr) {
  40199. warn("XFA - SOM expression contains a JavaScript subexpression which is not supported for now.");
  40200. return null;
  40201. }
  40202. operator = operators.dotParen;
  40203. break;
  40204. default:
  40205. operator = operators.dot;
  40206. break;
  40207. }
  40208. match = expr.slice(pos).match(namePattern);
  40209. if (!match) {
  40210. break;
  40211. }
  40212. [name] = match;
  40213. pos += name.length;
  40214. parsed.push({
  40215. name,
  40216. cacheName: expr.slice(spos, pos),
  40217. operator,
  40218. index: 0,
  40219. js: null,
  40220. formCalc: null
  40221. });
  40222. }
  40223. return parsed;
  40224. }
  40225. function searchNode(root, container, expr, dotDotAllowed = true, useCache = true) {
  40226. const parsed = parseExpression(expr, dotDotAllowed);
  40227. if (!parsed) {
  40228. return null;
  40229. }
  40230. const fn = shortcuts.get(parsed[0].name);
  40231. let i = 0;
  40232. let isQualified;
  40233. if (fn) {
  40234. isQualified = true;
  40235. root = [fn(root, container)];
  40236. i = 1;
  40237. } else {
  40238. isQualified = container === null;
  40239. root = [container || root];
  40240. }
  40241. for (let ii = parsed.length; i < ii; i++) {
  40242. const {
  40243. name,
  40244. cacheName,
  40245. operator,
  40246. index
  40247. } = parsed[i];
  40248. const nodes = [];
  40249. for (const node of root) {
  40250. if (!node.isXFAObject) {
  40251. continue;
  40252. }
  40253. let children, cached;
  40254. if (useCache) {
  40255. cached = somCache.get(node);
  40256. if (!cached) {
  40257. cached = new Map();
  40258. somCache.set(node, cached);
  40259. }
  40260. children = cached.get(cacheName);
  40261. }
  40262. if (!children) {
  40263. switch (operator) {
  40264. case operators.dot:
  40265. children = node[$getChildrenByName](name, false);
  40266. break;
  40267. case operators.dotDot:
  40268. children = node[$getChildrenByName](name, true);
  40269. break;
  40270. case operators.dotHash:
  40271. children = node[$getChildrenByClass](name);
  40272. children = children.isXFAObjectArray ? children.children : [children];
  40273. break;
  40274. default:
  40275. break;
  40276. }
  40277. if (useCache) {
  40278. cached.set(cacheName, children);
  40279. }
  40280. }
  40281. if (children.length > 0) {
  40282. nodes.push(children);
  40283. }
  40284. }
  40285. if (nodes.length === 0 && !isQualified && i === 0) {
  40286. const parent = container[$getParent]();
  40287. container = parent;
  40288. if (!container) {
  40289. return null;
  40290. }
  40291. i = -1;
  40292. root = [container];
  40293. continue;
  40294. }
  40295. root = isFinite(index) ? nodes.filter(node => index < node.length).map(node => node[index]) : nodes.flat();
  40296. }
  40297. if (root.length === 0) {
  40298. return null;
  40299. }
  40300. return root;
  40301. }
  40302. function createDataNode(root, container, expr) {
  40303. const parsed = parseExpression(expr);
  40304. if (!parsed) {
  40305. return null;
  40306. }
  40307. if (parsed.some(x => x.operator === operators.dotDot)) {
  40308. return null;
  40309. }
  40310. const fn = shortcuts.get(parsed[0].name);
  40311. let i = 0;
  40312. if (fn) {
  40313. root = fn(root, container);
  40314. i = 1;
  40315. } else {
  40316. root = container || root;
  40317. }
  40318. for (let ii = parsed.length; i < ii; i++) {
  40319. const {
  40320. name,
  40321. operator,
  40322. index
  40323. } = parsed[i];
  40324. if (!isFinite(index)) {
  40325. parsed[i].index = 0;
  40326. return root.createNodes(parsed.slice(i));
  40327. }
  40328. let children;
  40329. switch (operator) {
  40330. case operators.dot:
  40331. children = root[$getChildrenByName](name, false);
  40332. break;
  40333. case operators.dotDot:
  40334. children = root[$getChildrenByName](name, true);
  40335. break;
  40336. case operators.dotHash:
  40337. children = root[$getChildrenByClass](name);
  40338. children = children.isXFAObjectArray ? children.children : [children];
  40339. break;
  40340. default:
  40341. break;
  40342. }
  40343. if (children.length === 0) {
  40344. return root.createNodes(parsed.slice(i));
  40345. }
  40346. if (index < children.length) {
  40347. const child = children[index];
  40348. if (!child.isXFAObject) {
  40349. warn(`XFA - Cannot create a node.`);
  40350. return null;
  40351. }
  40352. root = child;
  40353. } else {
  40354. parsed[i].index = index - children.length;
  40355. return root.createNodes(parsed.slice(i));
  40356. }
  40357. }
  40358. return null;
  40359. }
  40360. ;// CONCATENATED MODULE: ./src/core/xfa/xfa_object.js
  40361. const _applyPrototype = Symbol();
  40362. const _attributes = Symbol();
  40363. const _attributeNames = Symbol();
  40364. const _children = Symbol("_children");
  40365. const _cloneAttribute = Symbol();
  40366. const _dataValue = Symbol();
  40367. const _defaultValue = Symbol();
  40368. const _filteredChildrenGenerator = Symbol();
  40369. const _getPrototype = Symbol();
  40370. const _getUnsetAttributes = Symbol();
  40371. const _hasChildren = Symbol();
  40372. const _max = Symbol();
  40373. const _options = Symbol();
  40374. const _parent = Symbol("parent");
  40375. const _resolvePrototypesHelper = Symbol();
  40376. const _setAttributes = Symbol();
  40377. const _validator = Symbol();
  40378. let uid = 0;
  40379. const NS_DATASETS = NamespaceIds.datasets.id;
  40380. class XFAObject {
  40381. constructor(nsId, name, hasChildren = false) {
  40382. this[$namespaceId] = nsId;
  40383. this[$nodeName] = name;
  40384. this[_hasChildren] = hasChildren;
  40385. this[_parent] = null;
  40386. this[_children] = [];
  40387. this[$uid] = `${name}${uid++}`;
  40388. this[$globalData] = null;
  40389. }
  40390. get isXFAObject() {
  40391. return true;
  40392. }
  40393. get isXFAObjectArray() {
  40394. return false;
  40395. }
  40396. createNodes(path) {
  40397. let root = this,
  40398. node = null;
  40399. for (const {
  40400. name,
  40401. index
  40402. } of path) {
  40403. for (let i = 0, ii = isFinite(index) ? index : 0; i <= ii; i++) {
  40404. const nsId = root[$namespaceId] === NS_DATASETS ? -1 : root[$namespaceId];
  40405. node = new XmlObject(nsId, name);
  40406. root[$appendChild](node);
  40407. }
  40408. root = node;
  40409. }
  40410. return node;
  40411. }
  40412. [$onChild](child) {
  40413. if (!this[_hasChildren] || !this[$onChildCheck](child)) {
  40414. return false;
  40415. }
  40416. const name = child[$nodeName];
  40417. const node = this[name];
  40418. if (node instanceof XFAObjectArray) {
  40419. if (node.push(child)) {
  40420. this[$appendChild](child);
  40421. return true;
  40422. }
  40423. } else {
  40424. if (node !== null) {
  40425. this[$removeChild](node);
  40426. }
  40427. this[name] = child;
  40428. this[$appendChild](child);
  40429. return true;
  40430. }
  40431. let id = "";
  40432. if (this.id) {
  40433. id = ` (id: ${this.id})`;
  40434. } else if (this.name) {
  40435. id = ` (name: ${this.name} ${this.h.value})`;
  40436. }
  40437. warn(`XFA - node "${this[$nodeName]}"${id} has already enough "${name}"!`);
  40438. return false;
  40439. }
  40440. [$onChildCheck](child) {
  40441. return this.hasOwnProperty(child[$nodeName]) && child[$namespaceId] === this[$namespaceId];
  40442. }
  40443. [$isNsAgnostic]() {
  40444. return false;
  40445. }
  40446. [$acceptWhitespace]() {
  40447. return false;
  40448. }
  40449. [$isCDATAXml]() {
  40450. return false;
  40451. }
  40452. [$isBindable]() {
  40453. return false;
  40454. }
  40455. [$popPara]() {
  40456. if (this.para) {
  40457. this[$getTemplateRoot]()[$extra].paraStack.pop();
  40458. }
  40459. }
  40460. [$pushPara]() {
  40461. this[$getTemplateRoot]()[$extra].paraStack.push(this.para);
  40462. }
  40463. [$setId](ids) {
  40464. if (this.id && this[$namespaceId] === NamespaceIds.template.id) {
  40465. ids.set(this.id, this);
  40466. }
  40467. }
  40468. [$getTemplateRoot]() {
  40469. return this[$globalData].template;
  40470. }
  40471. [$isSplittable]() {
  40472. return false;
  40473. }
  40474. [$isThereMoreWidth]() {
  40475. return false;
  40476. }
  40477. [$appendChild](child) {
  40478. child[_parent] = this;
  40479. this[_children].push(child);
  40480. if (!child[$globalData] && this[$globalData]) {
  40481. child[$globalData] = this[$globalData];
  40482. }
  40483. }
  40484. [$removeChild](child) {
  40485. const i = this[_children].indexOf(child);
  40486. this[_children].splice(i, 1);
  40487. }
  40488. [$hasSettableValue]() {
  40489. return this.hasOwnProperty("value");
  40490. }
  40491. [$setValue](_) {}
  40492. [$onText](_) {}
  40493. [$finalize]() {}
  40494. [$clean](builder) {
  40495. delete this[_hasChildren];
  40496. if (this[$cleanup]) {
  40497. builder.clean(this[$cleanup]);
  40498. delete this[$cleanup];
  40499. }
  40500. }
  40501. [$indexOf](child) {
  40502. return this[_children].indexOf(child);
  40503. }
  40504. [$insertAt](i, child) {
  40505. child[_parent] = this;
  40506. this[_children].splice(i, 0, child);
  40507. if (!child[$globalData] && this[$globalData]) {
  40508. child[$globalData] = this[$globalData];
  40509. }
  40510. }
  40511. [$isTransparent]() {
  40512. return !this.name;
  40513. }
  40514. [$lastAttribute]() {
  40515. return "";
  40516. }
  40517. [$text]() {
  40518. if (this[_children].length === 0) {
  40519. return this[$content];
  40520. }
  40521. return this[_children].map(c => c[$text]()).join("");
  40522. }
  40523. get [_attributeNames]() {
  40524. const proto = Object.getPrototypeOf(this);
  40525. if (!proto._attributes) {
  40526. const attributes = proto._attributes = new Set();
  40527. for (const name of Object.getOwnPropertyNames(this)) {
  40528. if (this[name] === null || this[name] instanceof XFAObject || this[name] instanceof XFAObjectArray) {
  40529. break;
  40530. }
  40531. attributes.add(name);
  40532. }
  40533. }
  40534. return shadow(this, _attributeNames, proto._attributes);
  40535. }
  40536. [$isDescendent](parent) {
  40537. let node = this;
  40538. while (node) {
  40539. if (node === parent) {
  40540. return true;
  40541. }
  40542. node = node[$getParent]();
  40543. }
  40544. return false;
  40545. }
  40546. [$getParent]() {
  40547. return this[_parent];
  40548. }
  40549. [$getSubformParent]() {
  40550. return this[$getParent]();
  40551. }
  40552. [$getChildren](name = null) {
  40553. if (!name) {
  40554. return this[_children];
  40555. }
  40556. return this[name];
  40557. }
  40558. [$dump]() {
  40559. const dumped = Object.create(null);
  40560. if (this[$content]) {
  40561. dumped.$content = this[$content];
  40562. }
  40563. for (const name of Object.getOwnPropertyNames(this)) {
  40564. const value = this[name];
  40565. if (value === null) {
  40566. continue;
  40567. }
  40568. if (value instanceof XFAObject) {
  40569. dumped[name] = value[$dump]();
  40570. } else if (value instanceof XFAObjectArray) {
  40571. if (!value.isEmpty()) {
  40572. dumped[name] = value.dump();
  40573. }
  40574. } else {
  40575. dumped[name] = value;
  40576. }
  40577. }
  40578. return dumped;
  40579. }
  40580. [$toStyle]() {
  40581. return null;
  40582. }
  40583. [$toHTML]() {
  40584. return HTMLResult.EMPTY;
  40585. }
  40586. *[$getContainedChildren]() {
  40587. for (const node of this[$getChildren]()) {
  40588. yield node;
  40589. }
  40590. }
  40591. *[_filteredChildrenGenerator](filter, include) {
  40592. for (const node of this[$getContainedChildren]()) {
  40593. if (!filter || include === filter.has(node[$nodeName])) {
  40594. const availableSpace = this[$getAvailableSpace]();
  40595. const res = node[$toHTML](availableSpace);
  40596. if (!res.success) {
  40597. this[$extra].failingNode = node;
  40598. }
  40599. yield res;
  40600. }
  40601. }
  40602. }
  40603. [$flushHTML]() {
  40604. return null;
  40605. }
  40606. [$addHTML](html, bbox) {
  40607. this[$extra].children.push(html);
  40608. }
  40609. [$getAvailableSpace]() {}
  40610. [$childrenToHTML]({
  40611. filter = null,
  40612. include = true
  40613. }) {
  40614. if (!this[$extra].generator) {
  40615. this[$extra].generator = this[_filteredChildrenGenerator](filter, include);
  40616. } else {
  40617. const availableSpace = this[$getAvailableSpace]();
  40618. const res = this[$extra].failingNode[$toHTML](availableSpace);
  40619. if (!res.success) {
  40620. return res;
  40621. }
  40622. if (res.html) {
  40623. this[$addHTML](res.html, res.bbox);
  40624. }
  40625. delete this[$extra].failingNode;
  40626. }
  40627. while (true) {
  40628. const gen = this[$extra].generator.next();
  40629. if (gen.done) {
  40630. break;
  40631. }
  40632. const res = gen.value;
  40633. if (!res.success) {
  40634. return res;
  40635. }
  40636. if (res.html) {
  40637. this[$addHTML](res.html, res.bbox);
  40638. }
  40639. }
  40640. this[$extra].generator = null;
  40641. return HTMLResult.EMPTY;
  40642. }
  40643. [$setSetAttributes](attributes) {
  40644. this[_setAttributes] = new Set(Object.keys(attributes));
  40645. }
  40646. [_getUnsetAttributes](protoAttributes) {
  40647. const allAttr = this[_attributeNames];
  40648. const setAttr = this[_setAttributes];
  40649. return [...protoAttributes].filter(x => allAttr.has(x) && !setAttr.has(x));
  40650. }
  40651. [$resolvePrototypes](ids, ancestors = new Set()) {
  40652. for (const child of this[_children]) {
  40653. child[_resolvePrototypesHelper](ids, ancestors);
  40654. }
  40655. }
  40656. [_resolvePrototypesHelper](ids, ancestors) {
  40657. const proto = this[_getPrototype](ids, ancestors);
  40658. if (proto) {
  40659. this[_applyPrototype](proto, ids, ancestors);
  40660. } else {
  40661. this[$resolvePrototypes](ids, ancestors);
  40662. }
  40663. }
  40664. [_getPrototype](ids, ancestors) {
  40665. const {
  40666. use,
  40667. usehref
  40668. } = this;
  40669. if (!use && !usehref) {
  40670. return null;
  40671. }
  40672. let proto = null;
  40673. let somExpression = null;
  40674. let id = null;
  40675. let ref = use;
  40676. if (usehref) {
  40677. ref = usehref;
  40678. if (usehref.startsWith("#som(") && usehref.endsWith(")")) {
  40679. somExpression = usehref.slice("#som(".length, -1);
  40680. } else if (usehref.startsWith(".#som(") && usehref.endsWith(")")) {
  40681. somExpression = usehref.slice(".#som(".length, -1);
  40682. } else if (usehref.startsWith("#")) {
  40683. id = usehref.slice(1);
  40684. } else if (usehref.startsWith(".#")) {
  40685. id = usehref.slice(2);
  40686. }
  40687. } else if (use.startsWith("#")) {
  40688. id = use.slice(1);
  40689. } else {
  40690. somExpression = use;
  40691. }
  40692. this.use = this.usehref = "";
  40693. if (id) {
  40694. proto = ids.get(id);
  40695. } else {
  40696. proto = searchNode(ids.get($root), this, somExpression, true, false);
  40697. if (proto) {
  40698. proto = proto[0];
  40699. }
  40700. }
  40701. if (!proto) {
  40702. warn(`XFA - Invalid prototype reference: ${ref}.`);
  40703. return null;
  40704. }
  40705. if (proto[$nodeName] !== this[$nodeName]) {
  40706. warn(`XFA - Incompatible prototype: ${proto[$nodeName]} !== ${this[$nodeName]}.`);
  40707. return null;
  40708. }
  40709. if (ancestors.has(proto)) {
  40710. warn(`XFA - Cycle detected in prototypes use.`);
  40711. return null;
  40712. }
  40713. ancestors.add(proto);
  40714. const protoProto = proto[_getPrototype](ids, ancestors);
  40715. if (protoProto) {
  40716. proto[_applyPrototype](protoProto, ids, ancestors);
  40717. }
  40718. proto[$resolvePrototypes](ids, ancestors);
  40719. ancestors.delete(proto);
  40720. return proto;
  40721. }
  40722. [_applyPrototype](proto, ids, ancestors) {
  40723. if (ancestors.has(proto)) {
  40724. warn(`XFA - Cycle detected in prototypes use.`);
  40725. return;
  40726. }
  40727. if (!this[$content] && proto[$content]) {
  40728. this[$content] = proto[$content];
  40729. }
  40730. const newAncestors = new Set(ancestors);
  40731. newAncestors.add(proto);
  40732. for (const unsetAttrName of this[_getUnsetAttributes](proto[_setAttributes])) {
  40733. this[unsetAttrName] = proto[unsetAttrName];
  40734. if (this[_setAttributes]) {
  40735. this[_setAttributes].add(unsetAttrName);
  40736. }
  40737. }
  40738. for (const name of Object.getOwnPropertyNames(this)) {
  40739. if (this[_attributeNames].has(name)) {
  40740. continue;
  40741. }
  40742. const value = this[name];
  40743. const protoValue = proto[name];
  40744. if (value instanceof XFAObjectArray) {
  40745. for (const child of value[_children]) {
  40746. child[_resolvePrototypesHelper](ids, ancestors);
  40747. }
  40748. for (let i = value[_children].length, ii = protoValue[_children].length; i < ii; i++) {
  40749. const child = proto[_children][i][$clone]();
  40750. if (value.push(child)) {
  40751. child[_parent] = this;
  40752. this[_children].push(child);
  40753. child[_resolvePrototypesHelper](ids, ancestors);
  40754. } else {
  40755. break;
  40756. }
  40757. }
  40758. continue;
  40759. }
  40760. if (value !== null) {
  40761. value[$resolvePrototypes](ids, ancestors);
  40762. if (protoValue) {
  40763. value[_applyPrototype](protoValue, ids, ancestors);
  40764. }
  40765. continue;
  40766. }
  40767. if (protoValue !== null) {
  40768. const child = protoValue[$clone]();
  40769. child[_parent] = this;
  40770. this[name] = child;
  40771. this[_children].push(child);
  40772. child[_resolvePrototypesHelper](ids, ancestors);
  40773. }
  40774. }
  40775. }
  40776. static [_cloneAttribute](obj) {
  40777. if (Array.isArray(obj)) {
  40778. return obj.map(x => XFAObject[_cloneAttribute](x));
  40779. }
  40780. if (typeof obj === "object" && obj !== null) {
  40781. return Object.assign({}, obj);
  40782. }
  40783. return obj;
  40784. }
  40785. [$clone]() {
  40786. const clone = Object.create(Object.getPrototypeOf(this));
  40787. for (const $symbol of Object.getOwnPropertySymbols(this)) {
  40788. try {
  40789. clone[$symbol] = this[$symbol];
  40790. } catch {
  40791. shadow(clone, $symbol, this[$symbol]);
  40792. }
  40793. }
  40794. clone[$uid] = `${clone[$nodeName]}${uid++}`;
  40795. clone[_children] = [];
  40796. for (const name of Object.getOwnPropertyNames(this)) {
  40797. if (this[_attributeNames].has(name)) {
  40798. clone[name] = XFAObject[_cloneAttribute](this[name]);
  40799. continue;
  40800. }
  40801. const value = this[name];
  40802. clone[name] = value instanceof XFAObjectArray ? new XFAObjectArray(value[_max]) : null;
  40803. }
  40804. for (const child of this[_children]) {
  40805. const name = child[$nodeName];
  40806. const clonedChild = child[$clone]();
  40807. clone[_children].push(clonedChild);
  40808. clonedChild[_parent] = clone;
  40809. if (clone[name] === null) {
  40810. clone[name] = clonedChild;
  40811. } else {
  40812. clone[name][_children].push(clonedChild);
  40813. }
  40814. }
  40815. return clone;
  40816. }
  40817. [$getChildren](name = null) {
  40818. if (!name) {
  40819. return this[_children];
  40820. }
  40821. return this[_children].filter(c => c[$nodeName] === name);
  40822. }
  40823. [$getChildrenByClass](name) {
  40824. return this[name];
  40825. }
  40826. [$getChildrenByName](name, allTransparent, first = true) {
  40827. return Array.from(this[$getChildrenByNameIt](name, allTransparent, first));
  40828. }
  40829. *[$getChildrenByNameIt](name, allTransparent, first = true) {
  40830. if (name === "parent") {
  40831. yield this[_parent];
  40832. return;
  40833. }
  40834. for (const child of this[_children]) {
  40835. if (child[$nodeName] === name) {
  40836. yield child;
  40837. }
  40838. if (child.name === name) {
  40839. yield child;
  40840. }
  40841. if (allTransparent || child[$isTransparent]()) {
  40842. yield* child[$getChildrenByNameIt](name, allTransparent, false);
  40843. }
  40844. }
  40845. if (first && this[_attributeNames].has(name)) {
  40846. yield new XFAAttribute(this, name, this[name]);
  40847. }
  40848. }
  40849. }
  40850. class XFAObjectArray {
  40851. constructor(max = Infinity) {
  40852. this[_max] = max;
  40853. this[_children] = [];
  40854. }
  40855. get isXFAObject() {
  40856. return false;
  40857. }
  40858. get isXFAObjectArray() {
  40859. return true;
  40860. }
  40861. push(child) {
  40862. const len = this[_children].length;
  40863. if (len <= this[_max]) {
  40864. this[_children].push(child);
  40865. return true;
  40866. }
  40867. warn(`XFA - node "${child[$nodeName]}" accepts no more than ${this[_max]} children`);
  40868. return false;
  40869. }
  40870. isEmpty() {
  40871. return this[_children].length === 0;
  40872. }
  40873. dump() {
  40874. return this[_children].length === 1 ? this[_children][0][$dump]() : this[_children].map(x => x[$dump]());
  40875. }
  40876. [$clone]() {
  40877. const clone = new XFAObjectArray(this[_max]);
  40878. clone[_children] = this[_children].map(c => c[$clone]());
  40879. return clone;
  40880. }
  40881. get children() {
  40882. return this[_children];
  40883. }
  40884. clear() {
  40885. this[_children].length = 0;
  40886. }
  40887. }
  40888. class XFAAttribute {
  40889. constructor(node, name, value) {
  40890. this[_parent] = node;
  40891. this[$nodeName] = name;
  40892. this[$content] = value;
  40893. this[$consumed] = false;
  40894. this[$uid] = `attribute${uid++}`;
  40895. }
  40896. [$getParent]() {
  40897. return this[_parent];
  40898. }
  40899. [$isDataValue]() {
  40900. return true;
  40901. }
  40902. [$getDataValue]() {
  40903. return this[$content].trim();
  40904. }
  40905. [$setValue](value) {
  40906. value = value.value || "";
  40907. this[$content] = value.toString();
  40908. }
  40909. [$text]() {
  40910. return this[$content];
  40911. }
  40912. [$isDescendent](parent) {
  40913. return this[_parent] === parent || this[_parent][$isDescendent](parent);
  40914. }
  40915. }
  40916. class XmlObject extends XFAObject {
  40917. constructor(nsId, name, attributes = {}) {
  40918. super(nsId, name);
  40919. this[$content] = "";
  40920. this[_dataValue] = null;
  40921. if (name !== "#text") {
  40922. const map = new Map();
  40923. this[_attributes] = map;
  40924. for (const [attrName, value] of Object.entries(attributes)) {
  40925. map.set(attrName, new XFAAttribute(this, attrName, value));
  40926. }
  40927. if (attributes.hasOwnProperty($nsAttributes)) {
  40928. const dataNode = attributes[$nsAttributes].xfa.dataNode;
  40929. if (dataNode !== undefined) {
  40930. if (dataNode === "dataGroup") {
  40931. this[_dataValue] = false;
  40932. } else if (dataNode === "dataValue") {
  40933. this[_dataValue] = true;
  40934. }
  40935. }
  40936. }
  40937. }
  40938. this[$consumed] = false;
  40939. }
  40940. [$toString](buf) {
  40941. const tagName = this[$nodeName];
  40942. if (tagName === "#text") {
  40943. buf.push(encodeToXmlString(this[$content]));
  40944. return;
  40945. }
  40946. const utf8TagName = utf8StringToString(tagName);
  40947. const prefix = this[$namespaceId] === NS_DATASETS ? "xfa:" : "";
  40948. buf.push(`<${prefix}${utf8TagName}`);
  40949. for (const [name, value] of this[_attributes].entries()) {
  40950. const utf8Name = utf8StringToString(name);
  40951. buf.push(` ${utf8Name}="${encodeToXmlString(value[$content])}"`);
  40952. }
  40953. if (this[_dataValue] !== null) {
  40954. if (this[_dataValue]) {
  40955. buf.push(` xfa:dataNode="dataValue"`);
  40956. } else {
  40957. buf.push(` xfa:dataNode="dataGroup"`);
  40958. }
  40959. }
  40960. if (!this[$content] && this[_children].length === 0) {
  40961. buf.push("/>");
  40962. return;
  40963. }
  40964. buf.push(">");
  40965. if (this[$content]) {
  40966. if (typeof this[$content] === "string") {
  40967. buf.push(encodeToXmlString(this[$content]));
  40968. } else {
  40969. this[$content][$toString](buf);
  40970. }
  40971. } else {
  40972. for (const child of this[_children]) {
  40973. child[$toString](buf);
  40974. }
  40975. }
  40976. buf.push(`</${prefix}${utf8TagName}>`);
  40977. }
  40978. [$onChild](child) {
  40979. if (this[$content]) {
  40980. const node = new XmlObject(this[$namespaceId], "#text");
  40981. this[$appendChild](node);
  40982. node[$content] = this[$content];
  40983. this[$content] = "";
  40984. }
  40985. this[$appendChild](child);
  40986. return true;
  40987. }
  40988. [$onText](str) {
  40989. this[$content] += str;
  40990. }
  40991. [$finalize]() {
  40992. if (this[$content] && this[_children].length > 0) {
  40993. const node = new XmlObject(this[$namespaceId], "#text");
  40994. this[$appendChild](node);
  40995. node[$content] = this[$content];
  40996. delete this[$content];
  40997. }
  40998. }
  40999. [$toHTML]() {
  41000. if (this[$nodeName] === "#text") {
  41001. return HTMLResult.success({
  41002. name: "#text",
  41003. value: this[$content]
  41004. });
  41005. }
  41006. return HTMLResult.EMPTY;
  41007. }
  41008. [$getChildren](name = null) {
  41009. if (!name) {
  41010. return this[_children];
  41011. }
  41012. return this[_children].filter(c => c[$nodeName] === name);
  41013. }
  41014. [$getAttributes]() {
  41015. return this[_attributes];
  41016. }
  41017. [$getChildrenByClass](name) {
  41018. const value = this[_attributes].get(name);
  41019. if (value !== undefined) {
  41020. return value;
  41021. }
  41022. return this[$getChildren](name);
  41023. }
  41024. *[$getChildrenByNameIt](name, allTransparent) {
  41025. const value = this[_attributes].get(name);
  41026. if (value) {
  41027. yield value;
  41028. }
  41029. for (const child of this[_children]) {
  41030. if (child[$nodeName] === name) {
  41031. yield child;
  41032. }
  41033. if (allTransparent) {
  41034. yield* child[$getChildrenByNameIt](name, allTransparent);
  41035. }
  41036. }
  41037. }
  41038. *[$getAttributeIt](name, skipConsumed) {
  41039. const value = this[_attributes].get(name);
  41040. if (value && (!skipConsumed || !value[$consumed])) {
  41041. yield value;
  41042. }
  41043. for (const child of this[_children]) {
  41044. yield* child[$getAttributeIt](name, skipConsumed);
  41045. }
  41046. }
  41047. *[$getRealChildrenByNameIt](name, allTransparent, skipConsumed) {
  41048. for (const child of this[_children]) {
  41049. if (child[$nodeName] === name && (!skipConsumed || !child[$consumed])) {
  41050. yield child;
  41051. }
  41052. if (allTransparent) {
  41053. yield* child[$getRealChildrenByNameIt](name, allTransparent, skipConsumed);
  41054. }
  41055. }
  41056. }
  41057. [$isDataValue]() {
  41058. if (this[_dataValue] === null) {
  41059. return this[_children].length === 0 || this[_children][0][$namespaceId] === NamespaceIds.xhtml.id;
  41060. }
  41061. return this[_dataValue];
  41062. }
  41063. [$getDataValue]() {
  41064. if (this[_dataValue] === null) {
  41065. if (this[_children].length === 0) {
  41066. return this[$content].trim();
  41067. }
  41068. if (this[_children][0][$namespaceId] === NamespaceIds.xhtml.id) {
  41069. return this[_children][0][$text]().trim();
  41070. }
  41071. return null;
  41072. }
  41073. return this[$content].trim();
  41074. }
  41075. [$setValue](value) {
  41076. value = value.value || "";
  41077. this[$content] = value.toString();
  41078. }
  41079. [$dump](hasNS = false) {
  41080. const dumped = Object.create(null);
  41081. if (hasNS) {
  41082. dumped.$ns = this[$namespaceId];
  41083. }
  41084. if (this[$content]) {
  41085. dumped.$content = this[$content];
  41086. }
  41087. dumped.$name = this[$nodeName];
  41088. dumped.children = [];
  41089. for (const child of this[_children]) {
  41090. dumped.children.push(child[$dump](hasNS));
  41091. }
  41092. dumped.attributes = Object.create(null);
  41093. for (const [name, value] of this[_attributes]) {
  41094. dumped.attributes[name] = value[$content];
  41095. }
  41096. return dumped;
  41097. }
  41098. }
  41099. class ContentObject extends XFAObject {
  41100. constructor(nsId, name) {
  41101. super(nsId, name);
  41102. this[$content] = "";
  41103. }
  41104. [$onText](text) {
  41105. this[$content] += text;
  41106. }
  41107. [$finalize]() {}
  41108. }
  41109. class OptionObject extends ContentObject {
  41110. constructor(nsId, name, options) {
  41111. super(nsId, name);
  41112. this[_options] = options;
  41113. }
  41114. [$finalize]() {
  41115. this[$content] = getKeyword({
  41116. data: this[$content],
  41117. defaultValue: this[_options][0],
  41118. validate: k => this[_options].includes(k)
  41119. });
  41120. }
  41121. [$clean](builder) {
  41122. super[$clean](builder);
  41123. delete this[_options];
  41124. }
  41125. }
  41126. class StringObject extends ContentObject {
  41127. [$finalize]() {
  41128. this[$content] = this[$content].trim();
  41129. }
  41130. }
  41131. class IntegerObject extends ContentObject {
  41132. constructor(nsId, name, defaultValue, validator) {
  41133. super(nsId, name);
  41134. this[_defaultValue] = defaultValue;
  41135. this[_validator] = validator;
  41136. }
  41137. [$finalize]() {
  41138. this[$content] = getInteger({
  41139. data: this[$content],
  41140. defaultValue: this[_defaultValue],
  41141. validate: this[_validator]
  41142. });
  41143. }
  41144. [$clean](builder) {
  41145. super[$clean](builder);
  41146. delete this[_defaultValue];
  41147. delete this[_validator];
  41148. }
  41149. }
  41150. class Option01 extends IntegerObject {
  41151. constructor(nsId, name) {
  41152. super(nsId, name, 0, n => n === 1);
  41153. }
  41154. }
  41155. class Option10 extends IntegerObject {
  41156. constructor(nsId, name) {
  41157. super(nsId, name, 1, n => n === 0);
  41158. }
  41159. }
  41160. ;// CONCATENATED MODULE: ./src/core/xfa/html_utils.js
  41161. function measureToString(m) {
  41162. if (typeof m === "string") {
  41163. return "0px";
  41164. }
  41165. return Number.isInteger(m) ? `${m}px` : `${m.toFixed(2)}px`;
  41166. }
  41167. const converters = {
  41168. anchorType(node, style) {
  41169. const parent = node[$getSubformParent]();
  41170. if (!parent || parent.layout && parent.layout !== "position") {
  41171. return;
  41172. }
  41173. if (!("transform" in style)) {
  41174. style.transform = "";
  41175. }
  41176. switch (node.anchorType) {
  41177. case "bottomCenter":
  41178. style.transform += "translate(-50%, -100%)";
  41179. break;
  41180. case "bottomLeft":
  41181. style.transform += "translate(0,-100%)";
  41182. break;
  41183. case "bottomRight":
  41184. style.transform += "translate(-100%,-100%)";
  41185. break;
  41186. case "middleCenter":
  41187. style.transform += "translate(-50%,-50%)";
  41188. break;
  41189. case "middleLeft":
  41190. style.transform += "translate(0,-50%)";
  41191. break;
  41192. case "middleRight":
  41193. style.transform += "translate(-100%,-50%)";
  41194. break;
  41195. case "topCenter":
  41196. style.transform += "translate(-50%,0)";
  41197. break;
  41198. case "topRight":
  41199. style.transform += "translate(-100%,0)";
  41200. break;
  41201. }
  41202. },
  41203. dimensions(node, style) {
  41204. const parent = node[$getSubformParent]();
  41205. let width = node.w;
  41206. const height = node.h;
  41207. if (parent.layout?.includes("row")) {
  41208. const extra = parent[$extra];
  41209. const colSpan = node.colSpan;
  41210. let w;
  41211. if (colSpan === -1) {
  41212. w = extra.columnWidths.slice(extra.currentColumn).reduce((a, x) => a + x, 0);
  41213. extra.currentColumn = 0;
  41214. } else {
  41215. w = extra.columnWidths.slice(extra.currentColumn, extra.currentColumn + colSpan).reduce((a, x) => a + x, 0);
  41216. extra.currentColumn = (extra.currentColumn + node.colSpan) % extra.columnWidths.length;
  41217. }
  41218. if (!isNaN(w)) {
  41219. width = node.w = w;
  41220. }
  41221. }
  41222. style.width = width !== "" ? measureToString(width) : "auto";
  41223. style.height = height !== "" ? measureToString(height) : "auto";
  41224. },
  41225. position(node, style) {
  41226. const parent = node[$getSubformParent]();
  41227. if (parent?.layout && parent.layout !== "position") {
  41228. return;
  41229. }
  41230. style.position = "absolute";
  41231. style.left = measureToString(node.x);
  41232. style.top = measureToString(node.y);
  41233. },
  41234. rotate(node, style) {
  41235. if (node.rotate) {
  41236. if (!("transform" in style)) {
  41237. style.transform = "";
  41238. }
  41239. style.transform += `rotate(-${node.rotate}deg)`;
  41240. style.transformOrigin = "top left";
  41241. }
  41242. },
  41243. presence(node, style) {
  41244. switch (node.presence) {
  41245. case "invisible":
  41246. style.visibility = "hidden";
  41247. break;
  41248. case "hidden":
  41249. case "inactive":
  41250. style.display = "none";
  41251. break;
  41252. }
  41253. },
  41254. hAlign(node, style) {
  41255. if (node[$nodeName] === "para") {
  41256. switch (node.hAlign) {
  41257. case "justifyAll":
  41258. style.textAlign = "justify-all";
  41259. break;
  41260. case "radix":
  41261. style.textAlign = "left";
  41262. break;
  41263. default:
  41264. style.textAlign = node.hAlign;
  41265. }
  41266. } else {
  41267. switch (node.hAlign) {
  41268. case "left":
  41269. style.alignSelf = "start";
  41270. break;
  41271. case "center":
  41272. style.alignSelf = "center";
  41273. break;
  41274. case "right":
  41275. style.alignSelf = "end";
  41276. break;
  41277. }
  41278. }
  41279. },
  41280. margin(node, style) {
  41281. if (node.margin) {
  41282. style.margin = node.margin[$toStyle]().margin;
  41283. }
  41284. }
  41285. };
  41286. function setMinMaxDimensions(node, style) {
  41287. const parent = node[$getSubformParent]();
  41288. if (parent.layout === "position") {
  41289. if (node.minW > 0) {
  41290. style.minWidth = measureToString(node.minW);
  41291. }
  41292. if (node.maxW > 0) {
  41293. style.maxWidth = measureToString(node.maxW);
  41294. }
  41295. if (node.minH > 0) {
  41296. style.minHeight = measureToString(node.minH);
  41297. }
  41298. if (node.maxH > 0) {
  41299. style.maxHeight = measureToString(node.maxH);
  41300. }
  41301. }
  41302. }
  41303. function layoutText(text, xfaFont, margin, lineHeight, fontFinder, width) {
  41304. const measure = new TextMeasure(xfaFont, margin, lineHeight, fontFinder);
  41305. if (typeof text === "string") {
  41306. measure.addString(text);
  41307. } else {
  41308. text[$pushGlyphs](measure);
  41309. }
  41310. return measure.compute(width);
  41311. }
  41312. function layoutNode(node, availableSpace) {
  41313. let height = null;
  41314. let width = null;
  41315. let isBroken = false;
  41316. if ((!node.w || !node.h) && node.value) {
  41317. let marginH = 0;
  41318. let marginV = 0;
  41319. if (node.margin) {
  41320. marginH = node.margin.leftInset + node.margin.rightInset;
  41321. marginV = node.margin.topInset + node.margin.bottomInset;
  41322. }
  41323. let lineHeight = null;
  41324. let margin = null;
  41325. if (node.para) {
  41326. margin = Object.create(null);
  41327. lineHeight = node.para.lineHeight === "" ? null : node.para.lineHeight;
  41328. margin.top = node.para.spaceAbove === "" ? 0 : node.para.spaceAbove;
  41329. margin.bottom = node.para.spaceBelow === "" ? 0 : node.para.spaceBelow;
  41330. margin.left = node.para.marginLeft === "" ? 0 : node.para.marginLeft;
  41331. margin.right = node.para.marginRight === "" ? 0 : node.para.marginRight;
  41332. }
  41333. let font = node.font;
  41334. if (!font) {
  41335. const root = node[$getTemplateRoot]();
  41336. let parent = node[$getParent]();
  41337. while (parent && parent !== root) {
  41338. if (parent.font) {
  41339. font = parent.font;
  41340. break;
  41341. }
  41342. parent = parent[$getParent]();
  41343. }
  41344. }
  41345. const maxWidth = (node.w || availableSpace.width) - marginH;
  41346. const fontFinder = node[$globalData].fontFinder;
  41347. if (node.value.exData && node.value.exData[$content] && node.value.exData.contentType === "text/html") {
  41348. const res = layoutText(node.value.exData[$content], font, margin, lineHeight, fontFinder, maxWidth);
  41349. width = res.width;
  41350. height = res.height;
  41351. isBroken = res.isBroken;
  41352. } else {
  41353. const text = node.value[$text]();
  41354. if (text) {
  41355. const res = layoutText(text, font, margin, lineHeight, fontFinder, maxWidth);
  41356. width = res.width;
  41357. height = res.height;
  41358. isBroken = res.isBroken;
  41359. }
  41360. }
  41361. if (width !== null && !node.w) {
  41362. width += marginH;
  41363. }
  41364. if (height !== null && !node.h) {
  41365. height += marginV;
  41366. }
  41367. }
  41368. return {
  41369. w: width,
  41370. h: height,
  41371. isBroken
  41372. };
  41373. }
  41374. function computeBbox(node, html, availableSpace) {
  41375. let bbox;
  41376. if (node.w !== "" && node.h !== "") {
  41377. bbox = [node.x, node.y, node.w, node.h];
  41378. } else {
  41379. if (!availableSpace) {
  41380. return null;
  41381. }
  41382. let width = node.w;
  41383. if (width === "") {
  41384. if (node.maxW === 0) {
  41385. const parent = node[$getSubformParent]();
  41386. width = parent.layout === "position" && parent.w !== "" ? 0 : node.minW;
  41387. } else {
  41388. width = Math.min(node.maxW, availableSpace.width);
  41389. }
  41390. html.attributes.style.width = measureToString(width);
  41391. }
  41392. let height = node.h;
  41393. if (height === "") {
  41394. if (node.maxH === 0) {
  41395. const parent = node[$getSubformParent]();
  41396. height = parent.layout === "position" && parent.h !== "" ? 0 : node.minH;
  41397. } else {
  41398. height = Math.min(node.maxH, availableSpace.height);
  41399. }
  41400. html.attributes.style.height = measureToString(height);
  41401. }
  41402. bbox = [node.x, node.y, width, height];
  41403. }
  41404. return bbox;
  41405. }
  41406. function fixDimensions(node) {
  41407. const parent = node[$getSubformParent]();
  41408. if (parent.layout?.includes("row")) {
  41409. const extra = parent[$extra];
  41410. const colSpan = node.colSpan;
  41411. let width;
  41412. if (colSpan === -1) {
  41413. width = extra.columnWidths.slice(extra.currentColumn).reduce((a, w) => a + w, 0);
  41414. } else {
  41415. width = extra.columnWidths.slice(extra.currentColumn, extra.currentColumn + colSpan).reduce((a, w) => a + w, 0);
  41416. }
  41417. if (!isNaN(width)) {
  41418. node.w = width;
  41419. }
  41420. }
  41421. if (parent.layout && parent.layout !== "position") {
  41422. node.x = node.y = 0;
  41423. }
  41424. if (node.layout === "table") {
  41425. if (node.w === "" && Array.isArray(node.columnWidths)) {
  41426. node.w = node.columnWidths.reduce((a, x) => a + x, 0);
  41427. }
  41428. }
  41429. }
  41430. function layoutClass(node) {
  41431. switch (node.layout) {
  41432. case "position":
  41433. return "xfaPosition";
  41434. case "lr-tb":
  41435. return "xfaLrTb";
  41436. case "rl-row":
  41437. return "xfaRlRow";
  41438. case "rl-tb":
  41439. return "xfaRlTb";
  41440. case "row":
  41441. return "xfaRow";
  41442. case "table":
  41443. return "xfaTable";
  41444. case "tb":
  41445. return "xfaTb";
  41446. default:
  41447. return "xfaPosition";
  41448. }
  41449. }
  41450. function toStyle(node, ...names) {
  41451. const style = Object.create(null);
  41452. for (const name of names) {
  41453. const value = node[name];
  41454. if (value === null) {
  41455. continue;
  41456. }
  41457. if (converters.hasOwnProperty(name)) {
  41458. converters[name](node, style);
  41459. continue;
  41460. }
  41461. if (value instanceof XFAObject) {
  41462. const newStyle = value[$toStyle]();
  41463. if (newStyle) {
  41464. Object.assign(style, newStyle);
  41465. } else {
  41466. warn(`(DEBUG) - XFA - style for ${name} not implemented yet`);
  41467. }
  41468. }
  41469. }
  41470. return style;
  41471. }
  41472. function createWrapper(node, html) {
  41473. const {
  41474. attributes
  41475. } = html;
  41476. const {
  41477. style
  41478. } = attributes;
  41479. const wrapper = {
  41480. name: "div",
  41481. attributes: {
  41482. class: ["xfaWrapper"],
  41483. style: Object.create(null)
  41484. },
  41485. children: []
  41486. };
  41487. attributes.class.push("xfaWrapped");
  41488. if (node.border) {
  41489. const {
  41490. widths,
  41491. insets
  41492. } = node.border[$extra];
  41493. let width, height;
  41494. let top = insets[0];
  41495. let left = insets[3];
  41496. const insetsH = insets[0] + insets[2];
  41497. const insetsW = insets[1] + insets[3];
  41498. switch (node.border.hand) {
  41499. case "even":
  41500. top -= widths[0] / 2;
  41501. left -= widths[3] / 2;
  41502. width = `calc(100% + ${(widths[1] + widths[3]) / 2 - insetsW}px)`;
  41503. height = `calc(100% + ${(widths[0] + widths[2]) / 2 - insetsH}px)`;
  41504. break;
  41505. case "left":
  41506. top -= widths[0];
  41507. left -= widths[3];
  41508. width = `calc(100% + ${widths[1] + widths[3] - insetsW}px)`;
  41509. height = `calc(100% + ${widths[0] + widths[2] - insetsH}px)`;
  41510. break;
  41511. case "right":
  41512. width = insetsW ? `calc(100% - ${insetsW}px)` : "100%";
  41513. height = insetsH ? `calc(100% - ${insetsH}px)` : "100%";
  41514. break;
  41515. }
  41516. const classNames = ["xfaBorder"];
  41517. if (isPrintOnly(node.border)) {
  41518. classNames.push("xfaPrintOnly");
  41519. }
  41520. const border = {
  41521. name: "div",
  41522. attributes: {
  41523. class: classNames,
  41524. style: {
  41525. top: `${top}px`,
  41526. left: `${left}px`,
  41527. width,
  41528. height
  41529. }
  41530. },
  41531. children: []
  41532. };
  41533. for (const key of ["border", "borderWidth", "borderColor", "borderRadius", "borderStyle"]) {
  41534. if (style[key] !== undefined) {
  41535. border.attributes.style[key] = style[key];
  41536. delete style[key];
  41537. }
  41538. }
  41539. wrapper.children.push(border, html);
  41540. } else {
  41541. wrapper.children.push(html);
  41542. }
  41543. for (const key of ["background", "backgroundClip", "top", "left", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "transform", "transformOrigin", "visibility"]) {
  41544. if (style[key] !== undefined) {
  41545. wrapper.attributes.style[key] = style[key];
  41546. delete style[key];
  41547. }
  41548. }
  41549. wrapper.attributes.style.position = style.position === "absolute" ? "absolute" : "relative";
  41550. delete style.position;
  41551. if (style.alignSelf) {
  41552. wrapper.attributes.style.alignSelf = style.alignSelf;
  41553. delete style.alignSelf;
  41554. }
  41555. return wrapper;
  41556. }
  41557. function fixTextIndent(styles) {
  41558. const indent = getMeasurement(styles.textIndent, "0px");
  41559. if (indent >= 0) {
  41560. return;
  41561. }
  41562. const align = styles.textAlign === "right" ? "right" : "left";
  41563. const name = "padding" + (align === "left" ? "Left" : "Right");
  41564. const padding = getMeasurement(styles[name], "0px");
  41565. styles[name] = `${padding - indent}px`;
  41566. }
  41567. function setAccess(node, classNames) {
  41568. switch (node.access) {
  41569. case "nonInteractive":
  41570. classNames.push("xfaNonInteractive");
  41571. break;
  41572. case "readOnly":
  41573. classNames.push("xfaReadOnly");
  41574. break;
  41575. case "protected":
  41576. classNames.push("xfaDisabled");
  41577. break;
  41578. }
  41579. }
  41580. function isPrintOnly(node) {
  41581. return node.relevant.length > 0 && !node.relevant[0].excluded && node.relevant[0].viewname === "print";
  41582. }
  41583. function getCurrentPara(node) {
  41584. const stack = node[$getTemplateRoot]()[$extra].paraStack;
  41585. return stack.length ? stack.at(-1) : null;
  41586. }
  41587. function setPara(node, nodeStyle, value) {
  41588. if (value.attributes.class?.includes("xfaRich")) {
  41589. if (nodeStyle) {
  41590. if (node.h === "") {
  41591. nodeStyle.height = "auto";
  41592. }
  41593. if (node.w === "") {
  41594. nodeStyle.width = "auto";
  41595. }
  41596. }
  41597. const para = getCurrentPara(node);
  41598. if (para) {
  41599. const valueStyle = value.attributes.style;
  41600. valueStyle.display = "flex";
  41601. valueStyle.flexDirection = "column";
  41602. switch (para.vAlign) {
  41603. case "top":
  41604. valueStyle.justifyContent = "start";
  41605. break;
  41606. case "bottom":
  41607. valueStyle.justifyContent = "end";
  41608. break;
  41609. case "middle":
  41610. valueStyle.justifyContent = "center";
  41611. break;
  41612. }
  41613. const paraStyle = para[$toStyle]();
  41614. for (const [key, val] of Object.entries(paraStyle)) {
  41615. if (!(key in valueStyle)) {
  41616. valueStyle[key] = val;
  41617. }
  41618. }
  41619. }
  41620. }
  41621. }
  41622. function setFontFamily(xfaFont, node, fontFinder, style) {
  41623. if (!fontFinder) {
  41624. delete style.fontFamily;
  41625. return;
  41626. }
  41627. const name = stripQuotes(xfaFont.typeface);
  41628. style.fontFamily = `"${name}"`;
  41629. const typeface = fontFinder.find(name);
  41630. if (typeface) {
  41631. const {
  41632. fontFamily
  41633. } = typeface.regular.cssFontInfo;
  41634. if (fontFamily !== name) {
  41635. style.fontFamily = `"${fontFamily}"`;
  41636. }
  41637. const para = getCurrentPara(node);
  41638. if (para && para.lineHeight !== "") {
  41639. return;
  41640. }
  41641. if (style.lineHeight) {
  41642. return;
  41643. }
  41644. const pdfFont = selectFont(xfaFont, typeface);
  41645. if (pdfFont) {
  41646. style.lineHeight = Math.max(1.2, pdfFont.lineHeight);
  41647. }
  41648. }
  41649. }
  41650. function fixURL(str) {
  41651. const absoluteUrl = createValidAbsoluteUrl(str, null, {
  41652. addDefaultProtocol: true,
  41653. tryConvertEncoding: true
  41654. });
  41655. return absoluteUrl ? absoluteUrl.href : null;
  41656. }
  41657. ;// CONCATENATED MODULE: ./src/core/xfa/layout.js
  41658. function createLine(node, children) {
  41659. return {
  41660. name: "div",
  41661. attributes: {
  41662. class: [node.layout === "lr-tb" ? "xfaLr" : "xfaRl"]
  41663. },
  41664. children
  41665. };
  41666. }
  41667. function flushHTML(node) {
  41668. if (!node[$extra]) {
  41669. return null;
  41670. }
  41671. const attributes = node[$extra].attributes;
  41672. const html = {
  41673. name: "div",
  41674. attributes,
  41675. children: node[$extra].children
  41676. };
  41677. if (node[$extra].failingNode) {
  41678. const htmlFromFailing = node[$extra].failingNode[$flushHTML]();
  41679. if (htmlFromFailing) {
  41680. if (node.layout.endsWith("-tb")) {
  41681. html.children.push(createLine(node, [htmlFromFailing]));
  41682. } else {
  41683. html.children.push(htmlFromFailing);
  41684. }
  41685. }
  41686. }
  41687. if (html.children.length === 0) {
  41688. return null;
  41689. }
  41690. return html;
  41691. }
  41692. function addHTML(node, html, bbox) {
  41693. const extra = node[$extra];
  41694. const availableSpace = extra.availableSpace;
  41695. const [x, y, w, h] = bbox;
  41696. switch (node.layout) {
  41697. case "position":
  41698. {
  41699. extra.width = Math.max(extra.width, x + w);
  41700. extra.height = Math.max(extra.height, y + h);
  41701. extra.children.push(html);
  41702. break;
  41703. }
  41704. case "lr-tb":
  41705. case "rl-tb":
  41706. if (!extra.line || extra.attempt === 1) {
  41707. extra.line = createLine(node, []);
  41708. extra.children.push(extra.line);
  41709. extra.numberInLine = 0;
  41710. }
  41711. extra.numberInLine += 1;
  41712. extra.line.children.push(html);
  41713. if (extra.attempt === 0) {
  41714. extra.currentWidth += w;
  41715. extra.height = Math.max(extra.height, extra.prevHeight + h);
  41716. } else {
  41717. extra.currentWidth = w;
  41718. extra.prevHeight = extra.height;
  41719. extra.height += h;
  41720. extra.attempt = 0;
  41721. }
  41722. extra.width = Math.max(extra.width, extra.currentWidth);
  41723. break;
  41724. case "rl-row":
  41725. case "row":
  41726. {
  41727. extra.children.push(html);
  41728. extra.width += w;
  41729. extra.height = Math.max(extra.height, h);
  41730. const height = measureToString(extra.height);
  41731. for (const child of extra.children) {
  41732. child.attributes.style.height = height;
  41733. }
  41734. break;
  41735. }
  41736. case "table":
  41737. {
  41738. extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
  41739. extra.height += h;
  41740. extra.children.push(html);
  41741. break;
  41742. }
  41743. case "tb":
  41744. {
  41745. extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
  41746. extra.height += h;
  41747. extra.children.push(html);
  41748. break;
  41749. }
  41750. }
  41751. }
  41752. function getAvailableSpace(node) {
  41753. const availableSpace = node[$extra].availableSpace;
  41754. const marginV = node.margin ? node.margin.topInset + node.margin.bottomInset : 0;
  41755. const marginH = node.margin ? node.margin.leftInset + node.margin.rightInset : 0;
  41756. switch (node.layout) {
  41757. case "lr-tb":
  41758. case "rl-tb":
  41759. if (node[$extra].attempt === 0) {
  41760. return {
  41761. width: availableSpace.width - marginH - node[$extra].currentWidth,
  41762. height: availableSpace.height - marginV - node[$extra].prevHeight
  41763. };
  41764. }
  41765. return {
  41766. width: availableSpace.width - marginH,
  41767. height: availableSpace.height - marginV - node[$extra].height
  41768. };
  41769. case "rl-row":
  41770. case "row":
  41771. const width = node[$extra].columnWidths.slice(node[$extra].currentColumn).reduce((a, x) => a + x);
  41772. return {
  41773. width,
  41774. height: availableSpace.height - marginH
  41775. };
  41776. case "table":
  41777. case "tb":
  41778. return {
  41779. width: availableSpace.width - marginH,
  41780. height: availableSpace.height - marginV - node[$extra].height
  41781. };
  41782. case "position":
  41783. default:
  41784. return availableSpace;
  41785. }
  41786. }
  41787. function getTransformedBBox(node) {
  41788. let w = node.w === "" ? NaN : node.w;
  41789. let h = node.h === "" ? NaN : node.h;
  41790. let [centerX, centerY] = [0, 0];
  41791. switch (node.anchorType || "") {
  41792. case "bottomCenter":
  41793. [centerX, centerY] = [w / 2, h];
  41794. break;
  41795. case "bottomLeft":
  41796. [centerX, centerY] = [0, h];
  41797. break;
  41798. case "bottomRight":
  41799. [centerX, centerY] = [w, h];
  41800. break;
  41801. case "middleCenter":
  41802. [centerX, centerY] = [w / 2, h / 2];
  41803. break;
  41804. case "middleLeft":
  41805. [centerX, centerY] = [0, h / 2];
  41806. break;
  41807. case "middleRight":
  41808. [centerX, centerY] = [w, h / 2];
  41809. break;
  41810. case "topCenter":
  41811. [centerX, centerY] = [w / 2, 0];
  41812. break;
  41813. case "topRight":
  41814. [centerX, centerY] = [w, 0];
  41815. break;
  41816. }
  41817. let x, y;
  41818. switch (node.rotate || 0) {
  41819. case 0:
  41820. [x, y] = [-centerX, -centerY];
  41821. break;
  41822. case 90:
  41823. [x, y] = [-centerY, centerX];
  41824. [w, h] = [h, -w];
  41825. break;
  41826. case 180:
  41827. [x, y] = [centerX, centerY];
  41828. [w, h] = [-w, -h];
  41829. break;
  41830. case 270:
  41831. [x, y] = [centerY, -centerX];
  41832. [w, h] = [-h, w];
  41833. break;
  41834. }
  41835. return [node.x + x + Math.min(0, w), node.y + y + Math.min(0, h), Math.abs(w), Math.abs(h)];
  41836. }
  41837. function checkDimensions(node, space) {
  41838. if (node[$getTemplateRoot]()[$extra].firstUnsplittable === null) {
  41839. return true;
  41840. }
  41841. if (node.w === 0 || node.h === 0) {
  41842. return true;
  41843. }
  41844. const ERROR = 2;
  41845. const parent = node[$getSubformParent]();
  41846. const attempt = parent[$extra]?.attempt || 0;
  41847. const [, y, w, h] = getTransformedBBox(node);
  41848. switch (parent.layout) {
  41849. case "lr-tb":
  41850. case "rl-tb":
  41851. if (attempt === 0) {
  41852. if (!node[$getTemplateRoot]()[$extra].noLayoutFailure) {
  41853. if (node.h !== "" && Math.round(h - space.height) > ERROR) {
  41854. return false;
  41855. }
  41856. if (node.w !== "") {
  41857. if (Math.round(w - space.width) <= ERROR) {
  41858. return true;
  41859. }
  41860. if (parent[$extra].numberInLine === 0) {
  41861. return space.height > ERROR;
  41862. }
  41863. return false;
  41864. }
  41865. return space.width > ERROR;
  41866. }
  41867. if (node.w !== "") {
  41868. return Math.round(w - space.width) <= ERROR;
  41869. }
  41870. return space.width > ERROR;
  41871. }
  41872. if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
  41873. return true;
  41874. }
  41875. if (node.h !== "" && Math.round(h - space.height) > ERROR) {
  41876. return false;
  41877. }
  41878. if (node.w === "" || Math.round(w - space.width) <= ERROR) {
  41879. return space.height > ERROR;
  41880. }
  41881. if (parent[$isThereMoreWidth]()) {
  41882. return false;
  41883. }
  41884. return space.height > ERROR;
  41885. case "table":
  41886. case "tb":
  41887. if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
  41888. return true;
  41889. }
  41890. if (node.h !== "" && !node[$isSplittable]()) {
  41891. return Math.round(h - space.height) <= ERROR;
  41892. }
  41893. if (node.w === "" || Math.round(w - space.width) <= ERROR) {
  41894. return space.height > ERROR;
  41895. }
  41896. if (parent[$isThereMoreWidth]()) {
  41897. return false;
  41898. }
  41899. return space.height > ERROR;
  41900. case "position":
  41901. if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
  41902. return true;
  41903. }
  41904. if (node.h === "" || Math.round(h + y - space.height) <= ERROR) {
  41905. return true;
  41906. }
  41907. const area = node[$getTemplateRoot]()[$extra].currentContentArea;
  41908. return h + y > area.h;
  41909. case "rl-row":
  41910. case "row":
  41911. if (node[$getTemplateRoot]()[$extra].noLayoutFailure) {
  41912. return true;
  41913. }
  41914. if (node.h !== "") {
  41915. return Math.round(h - space.height) <= ERROR;
  41916. }
  41917. return true;
  41918. default:
  41919. return true;
  41920. }
  41921. }
  41922. ;// CONCATENATED MODULE: ./src/core/xfa/template.js
  41923. const TEMPLATE_NS_ID = NamespaceIds.template.id;
  41924. const SVG_NS = "http://www.w3.org/2000/svg";
  41925. const MAX_ATTEMPTS_FOR_LRTB_LAYOUT = 2;
  41926. const MAX_EMPTY_PAGES = 3;
  41927. const DEFAULT_TAB_INDEX = 5000;
  41928. const HEADING_PATTERN = /^H(\d+)$/;
  41929. const MIMES = new Set(["image/gif", "image/jpeg", "image/jpg", "image/pjpeg", "image/png", "image/apng", "image/x-png", "image/bmp", "image/x-ms-bmp", "image/tiff", "image/tif", "application/octet-stream"]);
  41930. const IMAGES_HEADERS = [[[0x42, 0x4d], "image/bmp"], [[0xff, 0xd8, 0xff], "image/jpeg"], [[0x49, 0x49, 0x2a, 0x00], "image/tiff"], [[0x4d, 0x4d, 0x00, 0x2a], "image/tiff"], [[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], "image/gif"], [[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], "image/png"]];
  41931. function getBorderDims(node) {
  41932. if (!node || !node.border) {
  41933. return {
  41934. w: 0,
  41935. h: 0
  41936. };
  41937. }
  41938. const borderExtra = node.border[$getExtra]();
  41939. if (!borderExtra) {
  41940. return {
  41941. w: 0,
  41942. h: 0
  41943. };
  41944. }
  41945. return {
  41946. w: borderExtra.widths[0] + borderExtra.widths[2] + borderExtra.insets[0] + borderExtra.insets[2],
  41947. h: borderExtra.widths[1] + borderExtra.widths[3] + borderExtra.insets[1] + borderExtra.insets[3]
  41948. };
  41949. }
  41950. function hasMargin(node) {
  41951. return node.margin && (node.margin.topInset || node.margin.rightInset || node.margin.bottomInset || node.margin.leftInset);
  41952. }
  41953. function _setValue(templateNode, value) {
  41954. if (!templateNode.value) {
  41955. const nodeValue = new Value({});
  41956. templateNode[$appendChild](nodeValue);
  41957. templateNode.value = nodeValue;
  41958. }
  41959. templateNode.value[$setValue](value);
  41960. }
  41961. function* getContainedChildren(node) {
  41962. for (const child of node[$getChildren]()) {
  41963. if (child instanceof SubformSet) {
  41964. yield* child[$getContainedChildren]();
  41965. continue;
  41966. }
  41967. yield child;
  41968. }
  41969. }
  41970. function isRequired(node) {
  41971. return node.validate?.nullTest === "error";
  41972. }
  41973. function setTabIndex(node) {
  41974. while (node) {
  41975. if (!node.traversal) {
  41976. node[$tabIndex] = node[$getParent]()[$tabIndex];
  41977. return;
  41978. }
  41979. if (node[$tabIndex]) {
  41980. return;
  41981. }
  41982. let next = null;
  41983. for (const child of node.traversal[$getChildren]()) {
  41984. if (child.operation === "next") {
  41985. next = child;
  41986. break;
  41987. }
  41988. }
  41989. if (!next || !next.ref) {
  41990. node[$tabIndex] = node[$getParent]()[$tabIndex];
  41991. return;
  41992. }
  41993. const root = node[$getTemplateRoot]();
  41994. node[$tabIndex] = ++root[$tabIndex];
  41995. const ref = root[$searchNode](next.ref, node);
  41996. if (!ref) {
  41997. return;
  41998. }
  41999. node = ref[0];
  42000. }
  42001. }
  42002. function applyAssist(obj, attributes) {
  42003. const assist = obj.assist;
  42004. if (assist) {
  42005. const assistTitle = assist[$toHTML]();
  42006. if (assistTitle) {
  42007. attributes.title = assistTitle;
  42008. }
  42009. const role = assist.role;
  42010. const match = role.match(HEADING_PATTERN);
  42011. if (match) {
  42012. const ariaRole = "heading";
  42013. const ariaLevel = match[1];
  42014. attributes.role = ariaRole;
  42015. attributes["aria-level"] = ariaLevel;
  42016. }
  42017. }
  42018. if (obj.layout === "table") {
  42019. attributes.role = "table";
  42020. } else if (obj.layout === "row") {
  42021. attributes.role = "row";
  42022. } else {
  42023. const parent = obj[$getParent]();
  42024. if (parent.layout === "row") {
  42025. attributes.role = parent.assist?.role === "TH" ? "columnheader" : "cell";
  42026. }
  42027. }
  42028. }
  42029. function ariaLabel(obj) {
  42030. if (!obj.assist) {
  42031. return null;
  42032. }
  42033. const assist = obj.assist;
  42034. if (assist.speak && assist.speak[$content] !== "") {
  42035. return assist.speak[$content];
  42036. }
  42037. if (assist.toolTip) {
  42038. return assist.toolTip[$content];
  42039. }
  42040. return null;
  42041. }
  42042. function valueToHtml(value) {
  42043. return HTMLResult.success({
  42044. name: "div",
  42045. attributes: {
  42046. class: ["xfaRich"],
  42047. style: Object.create(null)
  42048. },
  42049. children: [{
  42050. name: "span",
  42051. attributes: {
  42052. style: Object.create(null)
  42053. },
  42054. value
  42055. }]
  42056. });
  42057. }
  42058. function setFirstUnsplittable(node) {
  42059. const root = node[$getTemplateRoot]();
  42060. if (root[$extra].firstUnsplittable === null) {
  42061. root[$extra].firstUnsplittable = node;
  42062. root[$extra].noLayoutFailure = true;
  42063. }
  42064. }
  42065. function unsetFirstUnsplittable(node) {
  42066. const root = node[$getTemplateRoot]();
  42067. if (root[$extra].firstUnsplittable === node) {
  42068. root[$extra].noLayoutFailure = false;
  42069. }
  42070. }
  42071. function handleBreak(node) {
  42072. if (node[$extra]) {
  42073. return false;
  42074. }
  42075. node[$extra] = Object.create(null);
  42076. if (node.targetType === "auto") {
  42077. return false;
  42078. }
  42079. const root = node[$getTemplateRoot]();
  42080. let target = null;
  42081. if (node.target) {
  42082. target = root[$searchNode](node.target, node[$getParent]());
  42083. if (!target) {
  42084. return false;
  42085. }
  42086. target = target[0];
  42087. }
  42088. const {
  42089. currentPageArea,
  42090. currentContentArea
  42091. } = root[$extra];
  42092. if (node.targetType === "pageArea") {
  42093. if (!(target instanceof PageArea)) {
  42094. target = null;
  42095. }
  42096. if (node.startNew) {
  42097. node[$extra].target = target || currentPageArea;
  42098. return true;
  42099. } else if (target && target !== currentPageArea) {
  42100. node[$extra].target = target;
  42101. return true;
  42102. }
  42103. return false;
  42104. }
  42105. if (!(target instanceof ContentArea)) {
  42106. target = null;
  42107. }
  42108. const pageArea = target && target[$getParent]();
  42109. let index;
  42110. let nextPageArea = pageArea;
  42111. if (node.startNew) {
  42112. if (target) {
  42113. const contentAreas = pageArea.contentArea.children;
  42114. const indexForCurrent = contentAreas.indexOf(currentContentArea);
  42115. const indexForTarget = contentAreas.indexOf(target);
  42116. if (indexForCurrent !== -1 && indexForCurrent < indexForTarget) {
  42117. nextPageArea = null;
  42118. }
  42119. index = indexForTarget - 1;
  42120. } else {
  42121. index = currentPageArea.contentArea.children.indexOf(currentContentArea);
  42122. }
  42123. } else if (target && target !== currentContentArea) {
  42124. const contentAreas = pageArea.contentArea.children;
  42125. index = contentAreas.indexOf(target) - 1;
  42126. nextPageArea = pageArea === currentPageArea ? null : pageArea;
  42127. } else {
  42128. return false;
  42129. }
  42130. node[$extra].target = nextPageArea;
  42131. node[$extra].index = index;
  42132. return true;
  42133. }
  42134. function handleOverflow(node, extraNode, space) {
  42135. const root = node[$getTemplateRoot]();
  42136. const saved = root[$extra].noLayoutFailure;
  42137. const savedMethod = extraNode[$getSubformParent];
  42138. extraNode[$getSubformParent] = () => node;
  42139. root[$extra].noLayoutFailure = true;
  42140. const res = extraNode[$toHTML](space);
  42141. node[$addHTML](res.html, res.bbox);
  42142. root[$extra].noLayoutFailure = saved;
  42143. extraNode[$getSubformParent] = savedMethod;
  42144. }
  42145. class AppearanceFilter extends StringObject {
  42146. constructor(attributes) {
  42147. super(TEMPLATE_NS_ID, "appearanceFilter");
  42148. this.id = attributes.id || "";
  42149. this.type = getStringOption(attributes.type, ["optional", "required"]);
  42150. this.use = attributes.use || "";
  42151. this.usehref = attributes.usehref || "";
  42152. }
  42153. }
  42154. class Arc extends XFAObject {
  42155. constructor(attributes) {
  42156. super(TEMPLATE_NS_ID, "arc", true);
  42157. this.circular = getInteger({
  42158. data: attributes.circular,
  42159. defaultValue: 0,
  42160. validate: x => x === 1
  42161. });
  42162. this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
  42163. this.id = attributes.id || "";
  42164. this.startAngle = getFloat({
  42165. data: attributes.startAngle,
  42166. defaultValue: 0,
  42167. validate: x => true
  42168. });
  42169. this.sweepAngle = getFloat({
  42170. data: attributes.sweepAngle,
  42171. defaultValue: 360,
  42172. validate: x => true
  42173. });
  42174. this.use = attributes.use || "";
  42175. this.usehref = attributes.usehref || "";
  42176. this.edge = null;
  42177. this.fill = null;
  42178. }
  42179. [$toHTML]() {
  42180. const edge = this.edge || new Edge({});
  42181. const edgeStyle = edge[$toStyle]();
  42182. const style = Object.create(null);
  42183. if (this.fill?.presence === "visible") {
  42184. Object.assign(style, this.fill[$toStyle]());
  42185. } else {
  42186. style.fill = "transparent";
  42187. }
  42188. style.strokeWidth = measureToString(edge.presence === "visible" ? edge.thickness : 0);
  42189. style.stroke = edgeStyle.color;
  42190. let arc;
  42191. const attributes = {
  42192. xmlns: SVG_NS,
  42193. style: {
  42194. width: "100%",
  42195. height: "100%",
  42196. overflow: "visible"
  42197. }
  42198. };
  42199. if (this.sweepAngle === 360) {
  42200. arc = {
  42201. name: "ellipse",
  42202. attributes: {
  42203. xmlns: SVG_NS,
  42204. cx: "50%",
  42205. cy: "50%",
  42206. rx: "50%",
  42207. ry: "50%",
  42208. style
  42209. }
  42210. };
  42211. } else {
  42212. const startAngle = this.startAngle * Math.PI / 180;
  42213. const sweepAngle = this.sweepAngle * Math.PI / 180;
  42214. const largeArc = this.sweepAngle > 180 ? 1 : 0;
  42215. const [x1, y1, x2, y2] = [50 * (1 + Math.cos(startAngle)), 50 * (1 - Math.sin(startAngle)), 50 * (1 + Math.cos(startAngle + sweepAngle)), 50 * (1 - Math.sin(startAngle + sweepAngle))];
  42216. arc = {
  42217. name: "path",
  42218. attributes: {
  42219. xmlns: SVG_NS,
  42220. d: `M ${x1} ${y1} A 50 50 0 ${largeArc} 0 ${x2} ${y2}`,
  42221. vectorEffect: "non-scaling-stroke",
  42222. style
  42223. }
  42224. };
  42225. Object.assign(attributes, {
  42226. viewBox: "0 0 100 100",
  42227. preserveAspectRatio: "none"
  42228. });
  42229. }
  42230. const svg = {
  42231. name: "svg",
  42232. children: [arc],
  42233. attributes
  42234. };
  42235. const parent = this[$getParent]()[$getParent]();
  42236. if (hasMargin(parent)) {
  42237. return HTMLResult.success({
  42238. name: "div",
  42239. attributes: {
  42240. style: {
  42241. display: "inline",
  42242. width: "100%",
  42243. height: "100%"
  42244. }
  42245. },
  42246. children: [svg]
  42247. });
  42248. }
  42249. svg.attributes.style.position = "absolute";
  42250. return HTMLResult.success(svg);
  42251. }
  42252. }
  42253. class Area extends XFAObject {
  42254. constructor(attributes) {
  42255. super(TEMPLATE_NS_ID, "area", true);
  42256. this.colSpan = getInteger({
  42257. data: attributes.colSpan,
  42258. defaultValue: 1,
  42259. validate: n => n >= 1 || n === -1
  42260. });
  42261. this.id = attributes.id || "";
  42262. this.name = attributes.name || "";
  42263. this.relevant = getRelevant(attributes.relevant);
  42264. this.use = attributes.use || "";
  42265. this.usehref = attributes.usehref || "";
  42266. this.x = getMeasurement(attributes.x, "0pt");
  42267. this.y = getMeasurement(attributes.y, "0pt");
  42268. this.desc = null;
  42269. this.extras = null;
  42270. this.area = new XFAObjectArray();
  42271. this.draw = new XFAObjectArray();
  42272. this.exObject = new XFAObjectArray();
  42273. this.exclGroup = new XFAObjectArray();
  42274. this.field = new XFAObjectArray();
  42275. this.subform = new XFAObjectArray();
  42276. this.subformSet = new XFAObjectArray();
  42277. }
  42278. *[$getContainedChildren]() {
  42279. yield* getContainedChildren(this);
  42280. }
  42281. [$isTransparent]() {
  42282. return true;
  42283. }
  42284. [$isBindable]() {
  42285. return true;
  42286. }
  42287. [$addHTML](html, bbox) {
  42288. const [x, y, w, h] = bbox;
  42289. this[$extra].width = Math.max(this[$extra].width, x + w);
  42290. this[$extra].height = Math.max(this[$extra].height, y + h);
  42291. this[$extra].children.push(html);
  42292. }
  42293. [$getAvailableSpace]() {
  42294. return this[$extra].availableSpace;
  42295. }
  42296. [$toHTML](availableSpace) {
  42297. const style = toStyle(this, "position");
  42298. const attributes = {
  42299. style,
  42300. id: this[$uid],
  42301. class: ["xfaArea"]
  42302. };
  42303. if (isPrintOnly(this)) {
  42304. attributes.class.push("xfaPrintOnly");
  42305. }
  42306. if (this.name) {
  42307. attributes.xfaName = this.name;
  42308. }
  42309. const children = [];
  42310. this[$extra] = {
  42311. children,
  42312. width: 0,
  42313. height: 0,
  42314. availableSpace
  42315. };
  42316. const result = this[$childrenToHTML]({
  42317. filter: new Set(["area", "draw", "field", "exclGroup", "subform", "subformSet"]),
  42318. include: true
  42319. });
  42320. if (!result.success) {
  42321. if (result.isBreak()) {
  42322. return result;
  42323. }
  42324. delete this[$extra];
  42325. return HTMLResult.FAILURE;
  42326. }
  42327. style.width = measureToString(this[$extra].width);
  42328. style.height = measureToString(this[$extra].height);
  42329. const html = {
  42330. name: "div",
  42331. attributes,
  42332. children
  42333. };
  42334. const bbox = [this.x, this.y, this[$extra].width, this[$extra].height];
  42335. delete this[$extra];
  42336. return HTMLResult.success(html, bbox);
  42337. }
  42338. }
  42339. class Assist extends XFAObject {
  42340. constructor(attributes) {
  42341. super(TEMPLATE_NS_ID, "assist", true);
  42342. this.id = attributes.id || "";
  42343. this.role = attributes.role || "";
  42344. this.use = attributes.use || "";
  42345. this.usehref = attributes.usehref || "";
  42346. this.speak = null;
  42347. this.toolTip = null;
  42348. }
  42349. [$toHTML]() {
  42350. return this.toolTip?.[$content] || null;
  42351. }
  42352. }
  42353. class Barcode extends XFAObject {
  42354. constructor(attributes) {
  42355. super(TEMPLATE_NS_ID, "barcode", true);
  42356. this.charEncoding = getKeyword({
  42357. data: attributes.charEncoding ? attributes.charEncoding.toLowerCase() : "",
  42358. defaultValue: "",
  42359. validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-\d{2}/)
  42360. });
  42361. this.checksum = getStringOption(attributes.checksum, ["none", "1mod10", "1mod10_1mod11", "2mod10", "auto"]);
  42362. this.dataColumnCount = getInteger({
  42363. data: attributes.dataColumnCount,
  42364. defaultValue: -1,
  42365. validate: x => x >= 0
  42366. });
  42367. this.dataLength = getInteger({
  42368. data: attributes.dataLength,
  42369. defaultValue: -1,
  42370. validate: x => x >= 0
  42371. });
  42372. this.dataPrep = getStringOption(attributes.dataPrep, ["none", "flateCompress"]);
  42373. this.dataRowCount = getInteger({
  42374. data: attributes.dataRowCount,
  42375. defaultValue: -1,
  42376. validate: x => x >= 0
  42377. });
  42378. this.endChar = attributes.endChar || "";
  42379. this.errorCorrectionLevel = getInteger({
  42380. data: attributes.errorCorrectionLevel,
  42381. defaultValue: -1,
  42382. validate: x => x >= 0 && x <= 8
  42383. });
  42384. this.id = attributes.id || "";
  42385. this.moduleHeight = getMeasurement(attributes.moduleHeight, "5mm");
  42386. this.moduleWidth = getMeasurement(attributes.moduleWidth, "0.25mm");
  42387. this.printCheckDigit = getInteger({
  42388. data: attributes.printCheckDigit,
  42389. defaultValue: 0,
  42390. validate: x => x === 1
  42391. });
  42392. this.rowColumnRatio = getRatio(attributes.rowColumnRatio);
  42393. this.startChar = attributes.startChar || "";
  42394. this.textLocation = getStringOption(attributes.textLocation, ["below", "above", "aboveEmbedded", "belowEmbedded", "none"]);
  42395. this.truncate = getInteger({
  42396. data: attributes.truncate,
  42397. defaultValue: 0,
  42398. validate: x => x === 1
  42399. });
  42400. this.type = getStringOption(attributes.type ? attributes.type.toLowerCase() : "", ["aztec", "codabar", "code2of5industrial", "code2of5interleaved", "code2of5matrix", "code2of5standard", "code3of9", "code3of9extended", "code11", "code49", "code93", "code128", "code128a", "code128b", "code128c", "code128sscc", "datamatrix", "ean8", "ean8add2", "ean8add5", "ean13", "ean13add2", "ean13add5", "ean13pwcd", "fim", "logmars", "maxicode", "msi", "pdf417", "pdf417macro", "plessey", "postauscust2", "postauscust3", "postausreplypaid", "postausstandard", "postukrm4scc", "postusdpbc", "postusimb", "postusstandard", "postus5zip", "qrcode", "rfid", "rss14", "rss14expanded", "rss14limited", "rss14stacked", "rss14stackedomni", "rss14truncated", "telepen", "ucc128", "ucc128random", "ucc128sscc", "upca", "upcaadd2", "upcaadd5", "upcapwcd", "upce", "upceadd2", "upceadd5", "upcean2", "upcean5", "upsmaxicode"]);
  42401. this.upsMode = getStringOption(attributes.upsMode, ["usCarrier", "internationalCarrier", "secureSymbol", "standardSymbol"]);
  42402. this.use = attributes.use || "";
  42403. this.usehref = attributes.usehref || "";
  42404. this.wideNarrowRatio = getRatio(attributes.wideNarrowRatio);
  42405. this.encrypt = null;
  42406. this.extras = null;
  42407. }
  42408. }
  42409. class Bind extends XFAObject {
  42410. constructor(attributes) {
  42411. super(TEMPLATE_NS_ID, "bind", true);
  42412. this.match = getStringOption(attributes.match, ["once", "dataRef", "global", "none"]);
  42413. this.ref = attributes.ref || "";
  42414. this.picture = null;
  42415. }
  42416. }
  42417. class BindItems extends XFAObject {
  42418. constructor(attributes) {
  42419. super(TEMPLATE_NS_ID, "bindItems");
  42420. this.connection = attributes.connection || "";
  42421. this.labelRef = attributes.labelRef || "";
  42422. this.ref = attributes.ref || "";
  42423. this.valueRef = attributes.valueRef || "";
  42424. }
  42425. }
  42426. class Bookend extends XFAObject {
  42427. constructor(attributes) {
  42428. super(TEMPLATE_NS_ID, "bookend");
  42429. this.id = attributes.id || "";
  42430. this.leader = attributes.leader || "";
  42431. this.trailer = attributes.trailer || "";
  42432. this.use = attributes.use || "";
  42433. this.usehref = attributes.usehref || "";
  42434. }
  42435. }
  42436. class BooleanElement extends Option01 {
  42437. constructor(attributes) {
  42438. super(TEMPLATE_NS_ID, "boolean");
  42439. this.id = attributes.id || "";
  42440. this.name = attributes.name || "";
  42441. this.use = attributes.use || "";
  42442. this.usehref = attributes.usehref || "";
  42443. }
  42444. [$toHTML](availableSpace) {
  42445. return valueToHtml(this[$content] === 1 ? "1" : "0");
  42446. }
  42447. }
  42448. class Border extends XFAObject {
  42449. constructor(attributes) {
  42450. super(TEMPLATE_NS_ID, "border", true);
  42451. this.break = getStringOption(attributes.break, ["close", "open"]);
  42452. this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
  42453. this.id = attributes.id || "";
  42454. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  42455. this.relevant = getRelevant(attributes.relevant);
  42456. this.use = attributes.use || "";
  42457. this.usehref = attributes.usehref || "";
  42458. this.corner = new XFAObjectArray(4);
  42459. this.edge = new XFAObjectArray(4);
  42460. this.extras = null;
  42461. this.fill = null;
  42462. this.margin = null;
  42463. }
  42464. [$getExtra]() {
  42465. if (!this[$extra]) {
  42466. const edges = this.edge.children.slice();
  42467. if (edges.length < 4) {
  42468. const defaultEdge = edges.at(-1) || new Edge({});
  42469. for (let i = edges.length; i < 4; i++) {
  42470. edges.push(defaultEdge);
  42471. }
  42472. }
  42473. const widths = edges.map(edge => edge.thickness);
  42474. const insets = [0, 0, 0, 0];
  42475. if (this.margin) {
  42476. insets[0] = this.margin.topInset;
  42477. insets[1] = this.margin.rightInset;
  42478. insets[2] = this.margin.bottomInset;
  42479. insets[3] = this.margin.leftInset;
  42480. }
  42481. this[$extra] = {
  42482. widths,
  42483. insets,
  42484. edges
  42485. };
  42486. }
  42487. return this[$extra];
  42488. }
  42489. [$toStyle]() {
  42490. const {
  42491. edges
  42492. } = this[$getExtra]();
  42493. const edgeStyles = edges.map(node => {
  42494. const style = node[$toStyle]();
  42495. style.color ||= "#000000";
  42496. return style;
  42497. });
  42498. const style = Object.create(null);
  42499. if (this.margin) {
  42500. Object.assign(style, this.margin[$toStyle]());
  42501. }
  42502. if (this.fill?.presence === "visible") {
  42503. Object.assign(style, this.fill[$toStyle]());
  42504. }
  42505. if (this.corner.children.some(node => node.radius !== 0)) {
  42506. const cornerStyles = this.corner.children.map(node => node[$toStyle]());
  42507. if (cornerStyles.length === 2 || cornerStyles.length === 3) {
  42508. const last = cornerStyles.at(-1);
  42509. for (let i = cornerStyles.length; i < 4; i++) {
  42510. cornerStyles.push(last);
  42511. }
  42512. }
  42513. style.borderRadius = cornerStyles.map(s => s.radius).join(" ");
  42514. }
  42515. switch (this.presence) {
  42516. case "invisible":
  42517. case "hidden":
  42518. style.borderStyle = "";
  42519. break;
  42520. case "inactive":
  42521. style.borderStyle = "none";
  42522. break;
  42523. default:
  42524. style.borderStyle = edgeStyles.map(s => s.style).join(" ");
  42525. break;
  42526. }
  42527. style.borderWidth = edgeStyles.map(s => s.width).join(" ");
  42528. style.borderColor = edgeStyles.map(s => s.color).join(" ");
  42529. return style;
  42530. }
  42531. }
  42532. class Break extends XFAObject {
  42533. constructor(attributes) {
  42534. super(TEMPLATE_NS_ID, "break", true);
  42535. this.after = getStringOption(attributes.after, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]);
  42536. this.afterTarget = attributes.afterTarget || "";
  42537. this.before = getStringOption(attributes.before, ["auto", "contentArea", "pageArea", "pageEven", "pageOdd"]);
  42538. this.beforeTarget = attributes.beforeTarget || "";
  42539. this.bookendLeader = attributes.bookendLeader || "";
  42540. this.bookendTrailer = attributes.bookendTrailer || "";
  42541. this.id = attributes.id || "";
  42542. this.overflowLeader = attributes.overflowLeader || "";
  42543. this.overflowTarget = attributes.overflowTarget || "";
  42544. this.overflowTrailer = attributes.overflowTrailer || "";
  42545. this.startNew = getInteger({
  42546. data: attributes.startNew,
  42547. defaultValue: 0,
  42548. validate: x => x === 1
  42549. });
  42550. this.use = attributes.use || "";
  42551. this.usehref = attributes.usehref || "";
  42552. this.extras = null;
  42553. }
  42554. }
  42555. class BreakAfter extends XFAObject {
  42556. constructor(attributes) {
  42557. super(TEMPLATE_NS_ID, "breakAfter", true);
  42558. this.id = attributes.id || "";
  42559. this.leader = attributes.leader || "";
  42560. this.startNew = getInteger({
  42561. data: attributes.startNew,
  42562. defaultValue: 0,
  42563. validate: x => x === 1
  42564. });
  42565. this.target = attributes.target || "";
  42566. this.targetType = getStringOption(attributes.targetType, ["auto", "contentArea", "pageArea"]);
  42567. this.trailer = attributes.trailer || "";
  42568. this.use = attributes.use || "";
  42569. this.usehref = attributes.usehref || "";
  42570. this.script = null;
  42571. }
  42572. }
  42573. class BreakBefore extends XFAObject {
  42574. constructor(attributes) {
  42575. super(TEMPLATE_NS_ID, "breakBefore", true);
  42576. this.id = attributes.id || "";
  42577. this.leader = attributes.leader || "";
  42578. this.startNew = getInteger({
  42579. data: attributes.startNew,
  42580. defaultValue: 0,
  42581. validate: x => x === 1
  42582. });
  42583. this.target = attributes.target || "";
  42584. this.targetType = getStringOption(attributes.targetType, ["auto", "contentArea", "pageArea"]);
  42585. this.trailer = attributes.trailer || "";
  42586. this.use = attributes.use || "";
  42587. this.usehref = attributes.usehref || "";
  42588. this.script = null;
  42589. }
  42590. [$toHTML](availableSpace) {
  42591. this[$extra] = {};
  42592. return HTMLResult.FAILURE;
  42593. }
  42594. }
  42595. class Button extends XFAObject {
  42596. constructor(attributes) {
  42597. super(TEMPLATE_NS_ID, "button", true);
  42598. this.highlight = getStringOption(attributes.highlight, ["inverted", "none", "outline", "push"]);
  42599. this.id = attributes.id || "";
  42600. this.use = attributes.use || "";
  42601. this.usehref = attributes.usehref || "";
  42602. this.extras = null;
  42603. }
  42604. [$toHTML](availableSpace) {
  42605. const parent = this[$getParent]();
  42606. const grandpa = parent[$getParent]();
  42607. const htmlButton = {
  42608. name: "button",
  42609. attributes: {
  42610. id: this[$uid],
  42611. class: ["xfaButton"],
  42612. style: {}
  42613. },
  42614. children: []
  42615. };
  42616. for (const event of grandpa.event.children) {
  42617. if (event.activity !== "click" || !event.script) {
  42618. continue;
  42619. }
  42620. const jsURL = recoverJsURL(event.script[$content]);
  42621. if (!jsURL) {
  42622. continue;
  42623. }
  42624. const href = fixURL(jsURL.url);
  42625. if (!href) {
  42626. continue;
  42627. }
  42628. htmlButton.children.push({
  42629. name: "a",
  42630. attributes: {
  42631. id: "link" + this[$uid],
  42632. href,
  42633. newWindow: jsURL.newWindow,
  42634. class: ["xfaLink"],
  42635. style: {}
  42636. },
  42637. children: []
  42638. });
  42639. }
  42640. return HTMLResult.success(htmlButton);
  42641. }
  42642. }
  42643. class Calculate extends XFAObject {
  42644. constructor(attributes) {
  42645. super(TEMPLATE_NS_ID, "calculate", true);
  42646. this.id = attributes.id || "";
  42647. this.override = getStringOption(attributes.override, ["disabled", "error", "ignore", "warning"]);
  42648. this.use = attributes.use || "";
  42649. this.usehref = attributes.usehref || "";
  42650. this.extras = null;
  42651. this.message = null;
  42652. this.script = null;
  42653. }
  42654. }
  42655. class Caption extends XFAObject {
  42656. constructor(attributes) {
  42657. super(TEMPLATE_NS_ID, "caption", true);
  42658. this.id = attributes.id || "";
  42659. this.placement = getStringOption(attributes.placement, ["left", "bottom", "inline", "right", "top"]);
  42660. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  42661. this.reserve = Math.ceil(getMeasurement(attributes.reserve));
  42662. this.use = attributes.use || "";
  42663. this.usehref = attributes.usehref || "";
  42664. this.extras = null;
  42665. this.font = null;
  42666. this.margin = null;
  42667. this.para = null;
  42668. this.value = null;
  42669. }
  42670. [$setValue](value) {
  42671. _setValue(this, value);
  42672. }
  42673. [$getExtra](availableSpace) {
  42674. if (!this[$extra]) {
  42675. let {
  42676. width,
  42677. height
  42678. } = availableSpace;
  42679. switch (this.placement) {
  42680. case "left":
  42681. case "right":
  42682. case "inline":
  42683. width = this.reserve <= 0 ? width : this.reserve;
  42684. break;
  42685. case "top":
  42686. case "bottom":
  42687. height = this.reserve <= 0 ? height : this.reserve;
  42688. break;
  42689. }
  42690. this[$extra] = layoutNode(this, {
  42691. width,
  42692. height
  42693. });
  42694. }
  42695. return this[$extra];
  42696. }
  42697. [$toHTML](availableSpace) {
  42698. if (!this.value) {
  42699. return HTMLResult.EMPTY;
  42700. }
  42701. this[$pushPara]();
  42702. const value = this.value[$toHTML](availableSpace).html;
  42703. if (!value) {
  42704. this[$popPara]();
  42705. return HTMLResult.EMPTY;
  42706. }
  42707. const savedReserve = this.reserve;
  42708. if (this.reserve <= 0) {
  42709. const {
  42710. w,
  42711. h
  42712. } = this[$getExtra](availableSpace);
  42713. switch (this.placement) {
  42714. case "left":
  42715. case "right":
  42716. case "inline":
  42717. this.reserve = w;
  42718. break;
  42719. case "top":
  42720. case "bottom":
  42721. this.reserve = h;
  42722. break;
  42723. }
  42724. }
  42725. const children = [];
  42726. if (typeof value === "string") {
  42727. children.push({
  42728. name: "#text",
  42729. value
  42730. });
  42731. } else {
  42732. children.push(value);
  42733. }
  42734. const style = toStyle(this, "font", "margin", "visibility");
  42735. switch (this.placement) {
  42736. case "left":
  42737. case "right":
  42738. if (this.reserve > 0) {
  42739. style.width = measureToString(this.reserve);
  42740. }
  42741. break;
  42742. case "top":
  42743. case "bottom":
  42744. if (this.reserve > 0) {
  42745. style.height = measureToString(this.reserve);
  42746. }
  42747. break;
  42748. }
  42749. setPara(this, null, value);
  42750. this[$popPara]();
  42751. this.reserve = savedReserve;
  42752. return HTMLResult.success({
  42753. name: "div",
  42754. attributes: {
  42755. style,
  42756. class: ["xfaCaption"]
  42757. },
  42758. children
  42759. });
  42760. }
  42761. }
  42762. class Certificate extends StringObject {
  42763. constructor(attributes) {
  42764. super(TEMPLATE_NS_ID, "certificate");
  42765. this.id = attributes.id || "";
  42766. this.name = attributes.name || "";
  42767. this.use = attributes.use || "";
  42768. this.usehref = attributes.usehref || "";
  42769. }
  42770. }
  42771. class Certificates extends XFAObject {
  42772. constructor(attributes) {
  42773. super(TEMPLATE_NS_ID, "certificates", true);
  42774. this.credentialServerPolicy = getStringOption(attributes.credentialServerPolicy, ["optional", "required"]);
  42775. this.id = attributes.id || "";
  42776. this.url = attributes.url || "";
  42777. this.urlPolicy = attributes.urlPolicy || "";
  42778. this.use = attributes.use || "";
  42779. this.usehref = attributes.usehref || "";
  42780. this.encryption = null;
  42781. this.issuers = null;
  42782. this.keyUsage = null;
  42783. this.oids = null;
  42784. this.signing = null;
  42785. this.subjectDNs = null;
  42786. }
  42787. }
  42788. class CheckButton extends XFAObject {
  42789. constructor(attributes) {
  42790. super(TEMPLATE_NS_ID, "checkButton", true);
  42791. this.id = attributes.id || "";
  42792. this.mark = getStringOption(attributes.mark, ["default", "check", "circle", "cross", "diamond", "square", "star"]);
  42793. this.shape = getStringOption(attributes.shape, ["square", "round"]);
  42794. this.size = getMeasurement(attributes.size, "10pt");
  42795. this.use = attributes.use || "";
  42796. this.usehref = attributes.usehref || "";
  42797. this.border = null;
  42798. this.extras = null;
  42799. this.margin = null;
  42800. }
  42801. [$toHTML](availableSpace) {
  42802. const style = toStyle("margin");
  42803. const size = measureToString(this.size);
  42804. style.width = style.height = size;
  42805. let type;
  42806. let className;
  42807. let groupId;
  42808. const field = this[$getParent]()[$getParent]();
  42809. const items = field.items.children.length && field.items.children[0][$toHTML]().html || [];
  42810. const exportedValue = {
  42811. on: (items[0] !== undefined ? items[0] : "on").toString(),
  42812. off: (items[1] !== undefined ? items[1] : "off").toString()
  42813. };
  42814. const value = field.value?.[$text]() || "off";
  42815. const checked = value === exportedValue.on || undefined;
  42816. const container = field[$getSubformParent]();
  42817. const fieldId = field[$uid];
  42818. let dataId;
  42819. if (container instanceof ExclGroup) {
  42820. groupId = container[$uid];
  42821. type = "radio";
  42822. className = "xfaRadio";
  42823. dataId = container[$data]?.[$uid] || container[$uid];
  42824. } else {
  42825. type = "checkbox";
  42826. className = "xfaCheckbox";
  42827. dataId = field[$data]?.[$uid] || field[$uid];
  42828. }
  42829. const input = {
  42830. name: "input",
  42831. attributes: {
  42832. class: [className],
  42833. style,
  42834. fieldId,
  42835. dataId,
  42836. type,
  42837. checked,
  42838. xfaOn: exportedValue.on,
  42839. xfaOff: exportedValue.off,
  42840. "aria-label": ariaLabel(field),
  42841. "aria-required": false
  42842. }
  42843. };
  42844. if (groupId) {
  42845. input.attributes.name = groupId;
  42846. }
  42847. if (isRequired(field)) {
  42848. input.attributes["aria-required"] = true;
  42849. input.attributes.required = true;
  42850. }
  42851. return HTMLResult.success({
  42852. name: "label",
  42853. attributes: {
  42854. class: ["xfaLabel"]
  42855. },
  42856. children: [input]
  42857. });
  42858. }
  42859. }
  42860. class ChoiceList extends XFAObject {
  42861. constructor(attributes) {
  42862. super(TEMPLATE_NS_ID, "choiceList", true);
  42863. this.commitOn = getStringOption(attributes.commitOn, ["select", "exit"]);
  42864. this.id = attributes.id || "";
  42865. this.open = getStringOption(attributes.open, ["userControl", "always", "multiSelect", "onEntry"]);
  42866. this.textEntry = getInteger({
  42867. data: attributes.textEntry,
  42868. defaultValue: 0,
  42869. validate: x => x === 1
  42870. });
  42871. this.use = attributes.use || "";
  42872. this.usehref = attributes.usehref || "";
  42873. this.border = null;
  42874. this.extras = null;
  42875. this.margin = null;
  42876. }
  42877. [$toHTML](availableSpace) {
  42878. const style = toStyle(this, "border", "margin");
  42879. const ui = this[$getParent]();
  42880. const field = ui[$getParent]();
  42881. const fontSize = field.font?.size || 10;
  42882. const optionStyle = {
  42883. fontSize: `calc(${fontSize}px * var(--scale-factor))`
  42884. };
  42885. const children = [];
  42886. if (field.items.children.length > 0) {
  42887. const items = field.items;
  42888. let displayedIndex = 0;
  42889. let saveIndex = 0;
  42890. if (items.children.length === 2) {
  42891. displayedIndex = items.children[0].save;
  42892. saveIndex = 1 - displayedIndex;
  42893. }
  42894. const displayed = items.children[displayedIndex][$toHTML]().html;
  42895. const values = items.children[saveIndex][$toHTML]().html;
  42896. let selected = false;
  42897. const value = field.value?.[$text]() || "";
  42898. for (let i = 0, ii = displayed.length; i < ii; i++) {
  42899. const option = {
  42900. name: "option",
  42901. attributes: {
  42902. value: values[i] || displayed[i],
  42903. style: optionStyle
  42904. },
  42905. value: displayed[i]
  42906. };
  42907. if (values[i] === value) {
  42908. option.attributes.selected = selected = true;
  42909. }
  42910. children.push(option);
  42911. }
  42912. if (!selected) {
  42913. children.splice(0, 0, {
  42914. name: "option",
  42915. attributes: {
  42916. hidden: true,
  42917. selected: true
  42918. },
  42919. value: " "
  42920. });
  42921. }
  42922. }
  42923. const selectAttributes = {
  42924. class: ["xfaSelect"],
  42925. fieldId: field[$uid],
  42926. dataId: field[$data]?.[$uid] || field[$uid],
  42927. style,
  42928. "aria-label": ariaLabel(field),
  42929. "aria-required": false
  42930. };
  42931. if (isRequired(field)) {
  42932. selectAttributes["aria-required"] = true;
  42933. selectAttributes.required = true;
  42934. }
  42935. if (this.open === "multiSelect") {
  42936. selectAttributes.multiple = true;
  42937. }
  42938. return HTMLResult.success({
  42939. name: "label",
  42940. attributes: {
  42941. class: ["xfaLabel"]
  42942. },
  42943. children: [{
  42944. name: "select",
  42945. children,
  42946. attributes: selectAttributes
  42947. }]
  42948. });
  42949. }
  42950. }
  42951. class Color extends XFAObject {
  42952. constructor(attributes) {
  42953. super(TEMPLATE_NS_ID, "color", true);
  42954. this.cSpace = getStringOption(attributes.cSpace, ["SRGB"]);
  42955. this.id = attributes.id || "";
  42956. this.use = attributes.use || "";
  42957. this.usehref = attributes.usehref || "";
  42958. this.value = attributes.value ? getColor(attributes.value) : "";
  42959. this.extras = null;
  42960. }
  42961. [$hasSettableValue]() {
  42962. return false;
  42963. }
  42964. [$toStyle]() {
  42965. return this.value ? Util.makeHexColor(this.value.r, this.value.g, this.value.b) : null;
  42966. }
  42967. }
  42968. class Comb extends XFAObject {
  42969. constructor(attributes) {
  42970. super(TEMPLATE_NS_ID, "comb");
  42971. this.id = attributes.id || "";
  42972. this.numberOfCells = getInteger({
  42973. data: attributes.numberOfCells,
  42974. defaultValue: 0,
  42975. validate: x => x >= 0
  42976. });
  42977. this.use = attributes.use || "";
  42978. this.usehref = attributes.usehref || "";
  42979. }
  42980. }
  42981. class Connect extends XFAObject {
  42982. constructor(attributes) {
  42983. super(TEMPLATE_NS_ID, "connect", true);
  42984. this.connection = attributes.connection || "";
  42985. this.id = attributes.id || "";
  42986. this.ref = attributes.ref || "";
  42987. this.usage = getStringOption(attributes.usage, ["exportAndImport", "exportOnly", "importOnly"]);
  42988. this.use = attributes.use || "";
  42989. this.usehref = attributes.usehref || "";
  42990. this.picture = null;
  42991. }
  42992. }
  42993. class ContentArea extends XFAObject {
  42994. constructor(attributes) {
  42995. super(TEMPLATE_NS_ID, "contentArea", true);
  42996. this.h = getMeasurement(attributes.h);
  42997. this.id = attributes.id || "";
  42998. this.name = attributes.name || "";
  42999. this.relevant = getRelevant(attributes.relevant);
  43000. this.use = attributes.use || "";
  43001. this.usehref = attributes.usehref || "";
  43002. this.w = getMeasurement(attributes.w);
  43003. this.x = getMeasurement(attributes.x, "0pt");
  43004. this.y = getMeasurement(attributes.y, "0pt");
  43005. this.desc = null;
  43006. this.extras = null;
  43007. }
  43008. [$toHTML](availableSpace) {
  43009. const left = measureToString(this.x);
  43010. const top = measureToString(this.y);
  43011. const style = {
  43012. left,
  43013. top,
  43014. width: measureToString(this.w),
  43015. height: measureToString(this.h)
  43016. };
  43017. const classNames = ["xfaContentarea"];
  43018. if (isPrintOnly(this)) {
  43019. classNames.push("xfaPrintOnly");
  43020. }
  43021. return HTMLResult.success({
  43022. name: "div",
  43023. children: [],
  43024. attributes: {
  43025. style,
  43026. class: classNames,
  43027. id: this[$uid]
  43028. }
  43029. });
  43030. }
  43031. }
  43032. class Corner extends XFAObject {
  43033. constructor(attributes) {
  43034. super(TEMPLATE_NS_ID, "corner", true);
  43035. this.id = attributes.id || "";
  43036. this.inverted = getInteger({
  43037. data: attributes.inverted,
  43038. defaultValue: 0,
  43039. validate: x => x === 1
  43040. });
  43041. this.join = getStringOption(attributes.join, ["square", "round"]);
  43042. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  43043. this.radius = getMeasurement(attributes.radius);
  43044. this.stroke = getStringOption(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]);
  43045. this.thickness = getMeasurement(attributes.thickness, "0.5pt");
  43046. this.use = attributes.use || "";
  43047. this.usehref = attributes.usehref || "";
  43048. this.color = null;
  43049. this.extras = null;
  43050. }
  43051. [$toStyle]() {
  43052. const style = toStyle(this, "visibility");
  43053. style.radius = measureToString(this.join === "square" ? 0 : this.radius);
  43054. return style;
  43055. }
  43056. }
  43057. class DateElement extends ContentObject {
  43058. constructor(attributes) {
  43059. super(TEMPLATE_NS_ID, "date");
  43060. this.id = attributes.id || "";
  43061. this.name = attributes.name || "";
  43062. this.use = attributes.use || "";
  43063. this.usehref = attributes.usehref || "";
  43064. }
  43065. [$finalize]() {
  43066. const date = this[$content].trim();
  43067. this[$content] = date ? new Date(date) : null;
  43068. }
  43069. [$toHTML](availableSpace) {
  43070. return valueToHtml(this[$content] ? this[$content].toString() : "");
  43071. }
  43072. }
  43073. class DateTime extends ContentObject {
  43074. constructor(attributes) {
  43075. super(TEMPLATE_NS_ID, "dateTime");
  43076. this.id = attributes.id || "";
  43077. this.name = attributes.name || "";
  43078. this.use = attributes.use || "";
  43079. this.usehref = attributes.usehref || "";
  43080. }
  43081. [$finalize]() {
  43082. const date = this[$content].trim();
  43083. this[$content] = date ? new Date(date) : null;
  43084. }
  43085. [$toHTML](availableSpace) {
  43086. return valueToHtml(this[$content] ? this[$content].toString() : "");
  43087. }
  43088. }
  43089. class DateTimeEdit extends XFAObject {
  43090. constructor(attributes) {
  43091. super(TEMPLATE_NS_ID, "dateTimeEdit", true);
  43092. this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
  43093. this.id = attributes.id || "";
  43094. this.picker = getStringOption(attributes.picker, ["host", "none"]);
  43095. this.use = attributes.use || "";
  43096. this.usehref = attributes.usehref || "";
  43097. this.border = null;
  43098. this.comb = null;
  43099. this.extras = null;
  43100. this.margin = null;
  43101. }
  43102. [$toHTML](availableSpace) {
  43103. const style = toStyle(this, "border", "font", "margin");
  43104. const field = this[$getParent]()[$getParent]();
  43105. const html = {
  43106. name: "input",
  43107. attributes: {
  43108. type: "text",
  43109. fieldId: field[$uid],
  43110. dataId: field[$data]?.[$uid] || field[$uid],
  43111. class: ["xfaTextfield"],
  43112. style,
  43113. "aria-label": ariaLabel(field),
  43114. "aria-required": false
  43115. }
  43116. };
  43117. if (isRequired(field)) {
  43118. html.attributes["aria-required"] = true;
  43119. html.attributes.required = true;
  43120. }
  43121. return HTMLResult.success({
  43122. name: "label",
  43123. attributes: {
  43124. class: ["xfaLabel"]
  43125. },
  43126. children: [html]
  43127. });
  43128. }
  43129. }
  43130. class Decimal extends ContentObject {
  43131. constructor(attributes) {
  43132. super(TEMPLATE_NS_ID, "decimal");
  43133. this.fracDigits = getInteger({
  43134. data: attributes.fracDigits,
  43135. defaultValue: 2,
  43136. validate: x => true
  43137. });
  43138. this.id = attributes.id || "";
  43139. this.leadDigits = getInteger({
  43140. data: attributes.leadDigits,
  43141. defaultValue: -1,
  43142. validate: x => true
  43143. });
  43144. this.name = attributes.name || "";
  43145. this.use = attributes.use || "";
  43146. this.usehref = attributes.usehref || "";
  43147. }
  43148. [$finalize]() {
  43149. const number = parseFloat(this[$content].trim());
  43150. this[$content] = isNaN(number) ? null : number;
  43151. }
  43152. [$toHTML](availableSpace) {
  43153. return valueToHtml(this[$content] !== null ? this[$content].toString() : "");
  43154. }
  43155. }
  43156. class DefaultUi extends XFAObject {
  43157. constructor(attributes) {
  43158. super(TEMPLATE_NS_ID, "defaultUi", true);
  43159. this.id = attributes.id || "";
  43160. this.use = attributes.use || "";
  43161. this.usehref = attributes.usehref || "";
  43162. this.extras = null;
  43163. }
  43164. }
  43165. class Desc extends XFAObject {
  43166. constructor(attributes) {
  43167. super(TEMPLATE_NS_ID, "desc", true);
  43168. this.id = attributes.id || "";
  43169. this.use = attributes.use || "";
  43170. this.usehref = attributes.usehref || "";
  43171. this.boolean = new XFAObjectArray();
  43172. this.date = new XFAObjectArray();
  43173. this.dateTime = new XFAObjectArray();
  43174. this.decimal = new XFAObjectArray();
  43175. this.exData = new XFAObjectArray();
  43176. this.float = new XFAObjectArray();
  43177. this.image = new XFAObjectArray();
  43178. this.integer = new XFAObjectArray();
  43179. this.text = new XFAObjectArray();
  43180. this.time = new XFAObjectArray();
  43181. }
  43182. }
  43183. class DigestMethod extends OptionObject {
  43184. constructor(attributes) {
  43185. super(TEMPLATE_NS_ID, "digestMethod", ["", "SHA1", "SHA256", "SHA512", "RIPEMD160"]);
  43186. this.id = attributes.id || "";
  43187. this.use = attributes.use || "";
  43188. this.usehref = attributes.usehref || "";
  43189. }
  43190. }
  43191. class DigestMethods extends XFAObject {
  43192. constructor(attributes) {
  43193. super(TEMPLATE_NS_ID, "digestMethods", true);
  43194. this.id = attributes.id || "";
  43195. this.type = getStringOption(attributes.type, ["optional", "required"]);
  43196. this.use = attributes.use || "";
  43197. this.usehref = attributes.usehref || "";
  43198. this.digestMethod = new XFAObjectArray();
  43199. }
  43200. }
  43201. class Draw extends XFAObject {
  43202. constructor(attributes) {
  43203. super(TEMPLATE_NS_ID, "draw", true);
  43204. this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  43205. this.colSpan = getInteger({
  43206. data: attributes.colSpan,
  43207. defaultValue: 1,
  43208. validate: n => n >= 1 || n === -1
  43209. });
  43210. this.h = attributes.h ? getMeasurement(attributes.h) : "";
  43211. this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  43212. this.id = attributes.id || "";
  43213. this.locale = attributes.locale || "";
  43214. this.maxH = getMeasurement(attributes.maxH, "0pt");
  43215. this.maxW = getMeasurement(attributes.maxW, "0pt");
  43216. this.minH = getMeasurement(attributes.minH, "0pt");
  43217. this.minW = getMeasurement(attributes.minW, "0pt");
  43218. this.name = attributes.name || "";
  43219. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  43220. this.relevant = getRelevant(attributes.relevant);
  43221. this.rotate = getInteger({
  43222. data: attributes.rotate,
  43223. defaultValue: 0,
  43224. validate: x => x % 90 === 0
  43225. });
  43226. this.use = attributes.use || "";
  43227. this.usehref = attributes.usehref || "";
  43228. this.w = attributes.w ? getMeasurement(attributes.w) : "";
  43229. this.x = getMeasurement(attributes.x, "0pt");
  43230. this.y = getMeasurement(attributes.y, "0pt");
  43231. this.assist = null;
  43232. this.border = null;
  43233. this.caption = null;
  43234. this.desc = null;
  43235. this.extras = null;
  43236. this.font = null;
  43237. this.keep = null;
  43238. this.margin = null;
  43239. this.para = null;
  43240. this.traversal = null;
  43241. this.ui = null;
  43242. this.value = null;
  43243. this.setProperty = new XFAObjectArray();
  43244. }
  43245. [$setValue](value) {
  43246. _setValue(this, value);
  43247. }
  43248. [$toHTML](availableSpace) {
  43249. setTabIndex(this);
  43250. if (this.presence === "hidden" || this.presence === "inactive") {
  43251. return HTMLResult.EMPTY;
  43252. }
  43253. fixDimensions(this);
  43254. this[$pushPara]();
  43255. const savedW = this.w;
  43256. const savedH = this.h;
  43257. const {
  43258. w,
  43259. h,
  43260. isBroken
  43261. } = layoutNode(this, availableSpace);
  43262. if (w && this.w === "") {
  43263. if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) {
  43264. this[$popPara]();
  43265. return HTMLResult.FAILURE;
  43266. }
  43267. this.w = w;
  43268. }
  43269. if (h && this.h === "") {
  43270. this.h = h;
  43271. }
  43272. setFirstUnsplittable(this);
  43273. if (!checkDimensions(this, availableSpace)) {
  43274. this.w = savedW;
  43275. this.h = savedH;
  43276. this[$popPara]();
  43277. return HTMLResult.FAILURE;
  43278. }
  43279. unsetFirstUnsplittable(this);
  43280. const style = toStyle(this, "font", "hAlign", "dimensions", "position", "presence", "rotate", "anchorType", "border", "margin");
  43281. setMinMaxDimensions(this, style);
  43282. if (style.margin) {
  43283. style.padding = style.margin;
  43284. delete style.margin;
  43285. }
  43286. const classNames = ["xfaDraw"];
  43287. if (this.font) {
  43288. classNames.push("xfaFont");
  43289. }
  43290. if (isPrintOnly(this)) {
  43291. classNames.push("xfaPrintOnly");
  43292. }
  43293. const attributes = {
  43294. style,
  43295. id: this[$uid],
  43296. class: classNames
  43297. };
  43298. if (this.name) {
  43299. attributes.xfaName = this.name;
  43300. }
  43301. const html = {
  43302. name: "div",
  43303. attributes,
  43304. children: []
  43305. };
  43306. applyAssist(this, attributes);
  43307. const bbox = computeBbox(this, html, availableSpace);
  43308. const value = this.value ? this.value[$toHTML](availableSpace).html : null;
  43309. if (value === null) {
  43310. this.w = savedW;
  43311. this.h = savedH;
  43312. this[$popPara]();
  43313. return HTMLResult.success(createWrapper(this, html), bbox);
  43314. }
  43315. html.children.push(value);
  43316. setPara(this, style, value);
  43317. this.w = savedW;
  43318. this.h = savedH;
  43319. this[$popPara]();
  43320. return HTMLResult.success(createWrapper(this, html), bbox);
  43321. }
  43322. }
  43323. class Edge extends XFAObject {
  43324. constructor(attributes) {
  43325. super(TEMPLATE_NS_ID, "edge", true);
  43326. this.cap = getStringOption(attributes.cap, ["square", "butt", "round"]);
  43327. this.id = attributes.id || "";
  43328. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  43329. this.stroke = getStringOption(attributes.stroke, ["solid", "dashDot", "dashDotDot", "dashed", "dotted", "embossed", "etched", "lowered", "raised"]);
  43330. this.thickness = getMeasurement(attributes.thickness, "0.5pt");
  43331. this.use = attributes.use || "";
  43332. this.usehref = attributes.usehref || "";
  43333. this.color = null;
  43334. this.extras = null;
  43335. }
  43336. [$toStyle]() {
  43337. const style = toStyle(this, "visibility");
  43338. Object.assign(style, {
  43339. linecap: this.cap,
  43340. width: measureToString(this.thickness),
  43341. color: this.color ? this.color[$toStyle]() : "#000000",
  43342. style: ""
  43343. });
  43344. if (this.presence !== "visible") {
  43345. style.style = "none";
  43346. } else {
  43347. switch (this.stroke) {
  43348. case "solid":
  43349. style.style = "solid";
  43350. break;
  43351. case "dashDot":
  43352. style.style = "dashed";
  43353. break;
  43354. case "dashDotDot":
  43355. style.style = "dashed";
  43356. break;
  43357. case "dashed":
  43358. style.style = "dashed";
  43359. break;
  43360. case "dotted":
  43361. style.style = "dotted";
  43362. break;
  43363. case "embossed":
  43364. style.style = "ridge";
  43365. break;
  43366. case "etched":
  43367. style.style = "groove";
  43368. break;
  43369. case "lowered":
  43370. style.style = "inset";
  43371. break;
  43372. case "raised":
  43373. style.style = "outset";
  43374. break;
  43375. }
  43376. }
  43377. return style;
  43378. }
  43379. }
  43380. class Encoding extends OptionObject {
  43381. constructor(attributes) {
  43382. super(TEMPLATE_NS_ID, "encoding", ["adbe.x509.rsa_sha1", "adbe.pkcs7.detached", "adbe.pkcs7.sha1"]);
  43383. this.id = attributes.id || "";
  43384. this.use = attributes.use || "";
  43385. this.usehref = attributes.usehref || "";
  43386. }
  43387. }
  43388. class Encodings extends XFAObject {
  43389. constructor(attributes) {
  43390. super(TEMPLATE_NS_ID, "encodings", true);
  43391. this.id = attributes.id || "";
  43392. this.type = getStringOption(attributes.type, ["optional", "required"]);
  43393. this.use = attributes.use || "";
  43394. this.usehref = attributes.usehref || "";
  43395. this.encoding = new XFAObjectArray();
  43396. }
  43397. }
  43398. class Encrypt extends XFAObject {
  43399. constructor(attributes) {
  43400. super(TEMPLATE_NS_ID, "encrypt", true);
  43401. this.id = attributes.id || "";
  43402. this.use = attributes.use || "";
  43403. this.usehref = attributes.usehref || "";
  43404. this.certificate = null;
  43405. }
  43406. }
  43407. class EncryptData extends XFAObject {
  43408. constructor(attributes) {
  43409. super(TEMPLATE_NS_ID, "encryptData", true);
  43410. this.id = attributes.id || "";
  43411. this.operation = getStringOption(attributes.operation, ["encrypt", "decrypt"]);
  43412. this.target = attributes.target || "";
  43413. this.use = attributes.use || "";
  43414. this.usehref = attributes.usehref || "";
  43415. this.filter = null;
  43416. this.manifest = null;
  43417. }
  43418. }
  43419. class Encryption extends XFAObject {
  43420. constructor(attributes) {
  43421. super(TEMPLATE_NS_ID, "encryption", true);
  43422. this.id = attributes.id || "";
  43423. this.type = getStringOption(attributes.type, ["optional", "required"]);
  43424. this.use = attributes.use || "";
  43425. this.usehref = attributes.usehref || "";
  43426. this.certificate = new XFAObjectArray();
  43427. }
  43428. }
  43429. class EncryptionMethod extends OptionObject {
  43430. constructor(attributes) {
  43431. super(TEMPLATE_NS_ID, "encryptionMethod", ["", "AES256-CBC", "TRIPLEDES-CBC", "AES128-CBC", "AES192-CBC"]);
  43432. this.id = attributes.id || "";
  43433. this.use = attributes.use || "";
  43434. this.usehref = attributes.usehref || "";
  43435. }
  43436. }
  43437. class EncryptionMethods extends XFAObject {
  43438. constructor(attributes) {
  43439. super(TEMPLATE_NS_ID, "encryptionMethods", true);
  43440. this.id = attributes.id || "";
  43441. this.type = getStringOption(attributes.type, ["optional", "required"]);
  43442. this.use = attributes.use || "";
  43443. this.usehref = attributes.usehref || "";
  43444. this.encryptionMethod = new XFAObjectArray();
  43445. }
  43446. }
  43447. class Event extends XFAObject {
  43448. constructor(attributes) {
  43449. super(TEMPLATE_NS_ID, "event", true);
  43450. this.activity = getStringOption(attributes.activity, ["click", "change", "docClose", "docReady", "enter", "exit", "full", "indexChange", "initialize", "mouseDown", "mouseEnter", "mouseExit", "mouseUp", "postExecute", "postOpen", "postPrint", "postSave", "postSign", "postSubmit", "preExecute", "preOpen", "prePrint", "preSave", "preSign", "preSubmit", "ready", "validationState"]);
  43451. this.id = attributes.id || "";
  43452. this.listen = getStringOption(attributes.listen, ["refOnly", "refAndDescendents"]);
  43453. this.name = attributes.name || "";
  43454. this.ref = attributes.ref || "";
  43455. this.use = attributes.use || "";
  43456. this.usehref = attributes.usehref || "";
  43457. this.extras = null;
  43458. this.encryptData = null;
  43459. this.execute = null;
  43460. this.script = null;
  43461. this.signData = null;
  43462. this.submit = null;
  43463. }
  43464. }
  43465. class ExData extends ContentObject {
  43466. constructor(attributes) {
  43467. super(TEMPLATE_NS_ID, "exData");
  43468. this.contentType = attributes.contentType || "";
  43469. this.href = attributes.href || "";
  43470. this.id = attributes.id || "";
  43471. this.maxLength = getInteger({
  43472. data: attributes.maxLength,
  43473. defaultValue: -1,
  43474. validate: x => x >= -1
  43475. });
  43476. this.name = attributes.name || "";
  43477. this.rid = attributes.rid || "";
  43478. this.transferEncoding = getStringOption(attributes.transferEncoding, ["none", "base64", "package"]);
  43479. this.use = attributes.use || "";
  43480. this.usehref = attributes.usehref || "";
  43481. }
  43482. [$isCDATAXml]() {
  43483. return this.contentType === "text/html";
  43484. }
  43485. [$onChild](child) {
  43486. if (this.contentType === "text/html" && child[$namespaceId] === NamespaceIds.xhtml.id) {
  43487. this[$content] = child;
  43488. return true;
  43489. }
  43490. if (this.contentType === "text/xml") {
  43491. this[$content] = child;
  43492. return true;
  43493. }
  43494. return false;
  43495. }
  43496. [$toHTML](availableSpace) {
  43497. if (this.contentType !== "text/html" || !this[$content]) {
  43498. return HTMLResult.EMPTY;
  43499. }
  43500. return this[$content][$toHTML](availableSpace);
  43501. }
  43502. }
  43503. class ExObject extends XFAObject {
  43504. constructor(attributes) {
  43505. super(TEMPLATE_NS_ID, "exObject", true);
  43506. this.archive = attributes.archive || "";
  43507. this.classId = attributes.classId || "";
  43508. this.codeBase = attributes.codeBase || "";
  43509. this.codeType = attributes.codeType || "";
  43510. this.id = attributes.id || "";
  43511. this.name = attributes.name || "";
  43512. this.use = attributes.use || "";
  43513. this.usehref = attributes.usehref || "";
  43514. this.extras = null;
  43515. this.boolean = new XFAObjectArray();
  43516. this.date = new XFAObjectArray();
  43517. this.dateTime = new XFAObjectArray();
  43518. this.decimal = new XFAObjectArray();
  43519. this.exData = new XFAObjectArray();
  43520. this.exObject = new XFAObjectArray();
  43521. this.float = new XFAObjectArray();
  43522. this.image = new XFAObjectArray();
  43523. this.integer = new XFAObjectArray();
  43524. this.text = new XFAObjectArray();
  43525. this.time = new XFAObjectArray();
  43526. }
  43527. }
  43528. class ExclGroup extends XFAObject {
  43529. constructor(attributes) {
  43530. super(TEMPLATE_NS_ID, "exclGroup", true);
  43531. this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
  43532. this.accessKey = attributes.accessKey || "";
  43533. this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  43534. this.colSpan = getInteger({
  43535. data: attributes.colSpan,
  43536. defaultValue: 1,
  43537. validate: n => n >= 1 || n === -1
  43538. });
  43539. this.h = attributes.h ? getMeasurement(attributes.h) : "";
  43540. this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  43541. this.id = attributes.id || "";
  43542. this.layout = getStringOption(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]);
  43543. this.maxH = getMeasurement(attributes.maxH, "0pt");
  43544. this.maxW = getMeasurement(attributes.maxW, "0pt");
  43545. this.minH = getMeasurement(attributes.minH, "0pt");
  43546. this.minW = getMeasurement(attributes.minW, "0pt");
  43547. this.name = attributes.name || "";
  43548. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  43549. this.relevant = getRelevant(attributes.relevant);
  43550. this.use = attributes.use || "";
  43551. this.usehref = attributes.usehref || "";
  43552. this.w = attributes.w ? getMeasurement(attributes.w) : "";
  43553. this.x = getMeasurement(attributes.x, "0pt");
  43554. this.y = getMeasurement(attributes.y, "0pt");
  43555. this.assist = null;
  43556. this.bind = null;
  43557. this.border = null;
  43558. this.calculate = null;
  43559. this.caption = null;
  43560. this.desc = null;
  43561. this.extras = null;
  43562. this.margin = null;
  43563. this.para = null;
  43564. this.traversal = null;
  43565. this.validate = null;
  43566. this.connect = new XFAObjectArray();
  43567. this.event = new XFAObjectArray();
  43568. this.field = new XFAObjectArray();
  43569. this.setProperty = new XFAObjectArray();
  43570. }
  43571. [$isBindable]() {
  43572. return true;
  43573. }
  43574. [$hasSettableValue]() {
  43575. return true;
  43576. }
  43577. [$setValue](value) {
  43578. for (const field of this.field.children) {
  43579. if (!field.value) {
  43580. const nodeValue = new Value({});
  43581. field[$appendChild](nodeValue);
  43582. field.value = nodeValue;
  43583. }
  43584. field.value[$setValue](value);
  43585. }
  43586. }
  43587. [$isThereMoreWidth]() {
  43588. return this.layout.endsWith("-tb") && this[$extra].attempt === 0 && this[$extra].numberInLine > 0 || this[$getParent]()[$isThereMoreWidth]();
  43589. }
  43590. [$isSplittable]() {
  43591. const parent = this[$getSubformParent]();
  43592. if (!parent[$isSplittable]()) {
  43593. return false;
  43594. }
  43595. if (this[$extra]._isSplittable !== undefined) {
  43596. return this[$extra]._isSplittable;
  43597. }
  43598. if (this.layout === "position" || this.layout.includes("row")) {
  43599. this[$extra]._isSplittable = false;
  43600. return false;
  43601. }
  43602. if (parent.layout?.endsWith("-tb") && parent[$extra].numberInLine !== 0) {
  43603. return false;
  43604. }
  43605. this[$extra]._isSplittable = true;
  43606. return true;
  43607. }
  43608. [$flushHTML]() {
  43609. return flushHTML(this);
  43610. }
  43611. [$addHTML](html, bbox) {
  43612. addHTML(this, html, bbox);
  43613. }
  43614. [$getAvailableSpace]() {
  43615. return getAvailableSpace(this);
  43616. }
  43617. [$toHTML](availableSpace) {
  43618. setTabIndex(this);
  43619. if (this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) {
  43620. return HTMLResult.EMPTY;
  43621. }
  43622. fixDimensions(this);
  43623. const children = [];
  43624. const attributes = {
  43625. id: this[$uid],
  43626. class: []
  43627. };
  43628. setAccess(this, attributes.class);
  43629. if (!this[$extra]) {
  43630. this[$extra] = Object.create(null);
  43631. }
  43632. Object.assign(this[$extra], {
  43633. children,
  43634. attributes,
  43635. attempt: 0,
  43636. line: null,
  43637. numberInLine: 0,
  43638. availableSpace: {
  43639. width: Math.min(this.w || Infinity, availableSpace.width),
  43640. height: Math.min(this.h || Infinity, availableSpace.height)
  43641. },
  43642. width: 0,
  43643. height: 0,
  43644. prevHeight: 0,
  43645. currentWidth: 0
  43646. });
  43647. const isSplittable = this[$isSplittable]();
  43648. if (!isSplittable) {
  43649. setFirstUnsplittable(this);
  43650. }
  43651. if (!checkDimensions(this, availableSpace)) {
  43652. return HTMLResult.FAILURE;
  43653. }
  43654. const filter = new Set(["field"]);
  43655. if (this.layout.includes("row")) {
  43656. const columnWidths = this[$getSubformParent]().columnWidths;
  43657. if (Array.isArray(columnWidths) && columnWidths.length > 0) {
  43658. this[$extra].columnWidths = columnWidths;
  43659. this[$extra].currentColumn = 0;
  43660. }
  43661. }
  43662. const style = toStyle(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign");
  43663. const classNames = ["xfaExclgroup"];
  43664. const cl = layoutClass(this);
  43665. if (cl) {
  43666. classNames.push(cl);
  43667. }
  43668. if (isPrintOnly(this)) {
  43669. classNames.push("xfaPrintOnly");
  43670. }
  43671. attributes.style = style;
  43672. attributes.class = classNames;
  43673. if (this.name) {
  43674. attributes.xfaName = this.name;
  43675. }
  43676. this[$pushPara]();
  43677. const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
  43678. const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
  43679. for (; this[$extra].attempt < maxRun; this[$extra].attempt++) {
  43680. if (isLrTb && this[$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) {
  43681. this[$extra].numberInLine = 0;
  43682. }
  43683. const result = this[$childrenToHTML]({
  43684. filter,
  43685. include: true
  43686. });
  43687. if (result.success) {
  43688. break;
  43689. }
  43690. if (result.isBreak()) {
  43691. this[$popPara]();
  43692. return result;
  43693. }
  43694. if (isLrTb && this[$extra].attempt === 0 && this[$extra].numberInLine === 0 && !this[$getTemplateRoot]()[$extra].noLayoutFailure) {
  43695. this[$extra].attempt = maxRun;
  43696. break;
  43697. }
  43698. }
  43699. this[$popPara]();
  43700. if (!isSplittable) {
  43701. unsetFirstUnsplittable(this);
  43702. }
  43703. if (this[$extra].attempt === maxRun) {
  43704. if (!isSplittable) {
  43705. delete this[$extra];
  43706. }
  43707. return HTMLResult.FAILURE;
  43708. }
  43709. let marginH = 0;
  43710. let marginV = 0;
  43711. if (this.margin) {
  43712. marginH = this.margin.leftInset + this.margin.rightInset;
  43713. marginV = this.margin.topInset + this.margin.bottomInset;
  43714. }
  43715. const width = Math.max(this[$extra].width + marginH, this.w || 0);
  43716. const height = Math.max(this[$extra].height + marginV, this.h || 0);
  43717. const bbox = [this.x, this.y, width, height];
  43718. if (this.w === "") {
  43719. style.width = measureToString(width);
  43720. }
  43721. if (this.h === "") {
  43722. style.height = measureToString(height);
  43723. }
  43724. const html = {
  43725. name: "div",
  43726. attributes,
  43727. children
  43728. };
  43729. applyAssist(this, attributes);
  43730. delete this[$extra];
  43731. return HTMLResult.success(createWrapper(this, html), bbox);
  43732. }
  43733. }
  43734. class Execute extends XFAObject {
  43735. constructor(attributes) {
  43736. super(TEMPLATE_NS_ID, "execute");
  43737. this.connection = attributes.connection || "";
  43738. this.executeType = getStringOption(attributes.executeType, ["import", "remerge"]);
  43739. this.id = attributes.id || "";
  43740. this.runAt = getStringOption(attributes.runAt, ["client", "both", "server"]);
  43741. this.use = attributes.use || "";
  43742. this.usehref = attributes.usehref || "";
  43743. }
  43744. }
  43745. class Extras extends XFAObject {
  43746. constructor(attributes) {
  43747. super(TEMPLATE_NS_ID, "extras", true);
  43748. this.id = attributes.id || "";
  43749. this.name = attributes.name || "";
  43750. this.use = attributes.use || "";
  43751. this.usehref = attributes.usehref || "";
  43752. this.boolean = new XFAObjectArray();
  43753. this.date = new XFAObjectArray();
  43754. this.dateTime = new XFAObjectArray();
  43755. this.decimal = new XFAObjectArray();
  43756. this.exData = new XFAObjectArray();
  43757. this.extras = new XFAObjectArray();
  43758. this.float = new XFAObjectArray();
  43759. this.image = new XFAObjectArray();
  43760. this.integer = new XFAObjectArray();
  43761. this.text = new XFAObjectArray();
  43762. this.time = new XFAObjectArray();
  43763. }
  43764. }
  43765. class Field extends XFAObject {
  43766. constructor(attributes) {
  43767. super(TEMPLATE_NS_ID, "field", true);
  43768. this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
  43769. this.accessKey = attributes.accessKey || "";
  43770. this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  43771. this.colSpan = getInteger({
  43772. data: attributes.colSpan,
  43773. defaultValue: 1,
  43774. validate: n => n >= 1 || n === -1
  43775. });
  43776. this.h = attributes.h ? getMeasurement(attributes.h) : "";
  43777. this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  43778. this.id = attributes.id || "";
  43779. this.locale = attributes.locale || "";
  43780. this.maxH = getMeasurement(attributes.maxH, "0pt");
  43781. this.maxW = getMeasurement(attributes.maxW, "0pt");
  43782. this.minH = getMeasurement(attributes.minH, "0pt");
  43783. this.minW = getMeasurement(attributes.minW, "0pt");
  43784. this.name = attributes.name || "";
  43785. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  43786. this.relevant = getRelevant(attributes.relevant);
  43787. this.rotate = getInteger({
  43788. data: attributes.rotate,
  43789. defaultValue: 0,
  43790. validate: x => x % 90 === 0
  43791. });
  43792. this.use = attributes.use || "";
  43793. this.usehref = attributes.usehref || "";
  43794. this.w = attributes.w ? getMeasurement(attributes.w) : "";
  43795. this.x = getMeasurement(attributes.x, "0pt");
  43796. this.y = getMeasurement(attributes.y, "0pt");
  43797. this.assist = null;
  43798. this.bind = null;
  43799. this.border = null;
  43800. this.calculate = null;
  43801. this.caption = null;
  43802. this.desc = null;
  43803. this.extras = null;
  43804. this.font = null;
  43805. this.format = null;
  43806. this.items = new XFAObjectArray(2);
  43807. this.keep = null;
  43808. this.margin = null;
  43809. this.para = null;
  43810. this.traversal = null;
  43811. this.ui = null;
  43812. this.validate = null;
  43813. this.value = null;
  43814. this.bindItems = new XFAObjectArray();
  43815. this.connect = new XFAObjectArray();
  43816. this.event = new XFAObjectArray();
  43817. this.setProperty = new XFAObjectArray();
  43818. }
  43819. [$isBindable]() {
  43820. return true;
  43821. }
  43822. [$setValue](value) {
  43823. _setValue(this, value);
  43824. }
  43825. [$toHTML](availableSpace) {
  43826. setTabIndex(this);
  43827. if (!this.ui) {
  43828. this.ui = new Ui({});
  43829. this.ui[$globalData] = this[$globalData];
  43830. this[$appendChild](this.ui);
  43831. let node;
  43832. switch (this.items.children.length) {
  43833. case 0:
  43834. node = new TextEdit({});
  43835. this.ui.textEdit = node;
  43836. break;
  43837. case 1:
  43838. node = new CheckButton({});
  43839. this.ui.checkButton = node;
  43840. break;
  43841. case 2:
  43842. node = new ChoiceList({});
  43843. this.ui.choiceList = node;
  43844. break;
  43845. }
  43846. this.ui[$appendChild](node);
  43847. }
  43848. if (!this.ui || this.presence === "hidden" || this.presence === "inactive" || this.h === 0 || this.w === 0) {
  43849. return HTMLResult.EMPTY;
  43850. }
  43851. if (this.caption) {
  43852. delete this.caption[$extra];
  43853. }
  43854. this[$pushPara]();
  43855. const caption = this.caption ? this.caption[$toHTML](availableSpace).html : null;
  43856. const savedW = this.w;
  43857. const savedH = this.h;
  43858. let marginH = 0;
  43859. let marginV = 0;
  43860. if (this.margin) {
  43861. marginH = this.margin.leftInset + this.margin.rightInset;
  43862. marginV = this.margin.topInset + this.margin.bottomInset;
  43863. }
  43864. let borderDims = null;
  43865. if (this.w === "" || this.h === "") {
  43866. let width = null;
  43867. let height = null;
  43868. let uiW = 0;
  43869. let uiH = 0;
  43870. if (this.ui.checkButton) {
  43871. uiW = uiH = this.ui.checkButton.size;
  43872. } else {
  43873. const {
  43874. w,
  43875. h
  43876. } = layoutNode(this, availableSpace);
  43877. if (w !== null) {
  43878. uiW = w;
  43879. uiH = h;
  43880. } else {
  43881. uiH = fonts_getMetrics(this.font, true).lineNoGap;
  43882. }
  43883. }
  43884. borderDims = getBorderDims(this.ui[$getExtra]());
  43885. uiW += borderDims.w;
  43886. uiH += borderDims.h;
  43887. if (this.caption) {
  43888. const {
  43889. w,
  43890. h,
  43891. isBroken
  43892. } = this.caption[$getExtra](availableSpace);
  43893. if (isBroken && this[$getSubformParent]()[$isThereMoreWidth]()) {
  43894. this[$popPara]();
  43895. return HTMLResult.FAILURE;
  43896. }
  43897. width = w;
  43898. height = h;
  43899. switch (this.caption.placement) {
  43900. case "left":
  43901. case "right":
  43902. case "inline":
  43903. width += uiW;
  43904. break;
  43905. case "top":
  43906. case "bottom":
  43907. height += uiH;
  43908. break;
  43909. }
  43910. } else {
  43911. width = uiW;
  43912. height = uiH;
  43913. }
  43914. if (width && this.w === "") {
  43915. width += marginH;
  43916. this.w = Math.min(this.maxW <= 0 ? Infinity : this.maxW, this.minW + 1 < width ? width : this.minW);
  43917. }
  43918. if (height && this.h === "") {
  43919. height += marginV;
  43920. this.h = Math.min(this.maxH <= 0 ? Infinity : this.maxH, this.minH + 1 < height ? height : this.minH);
  43921. }
  43922. }
  43923. this[$popPara]();
  43924. fixDimensions(this);
  43925. setFirstUnsplittable(this);
  43926. if (!checkDimensions(this, availableSpace)) {
  43927. this.w = savedW;
  43928. this.h = savedH;
  43929. this[$popPara]();
  43930. return HTMLResult.FAILURE;
  43931. }
  43932. unsetFirstUnsplittable(this);
  43933. const style = toStyle(this, "font", "dimensions", "position", "rotate", "anchorType", "presence", "margin", "hAlign");
  43934. setMinMaxDimensions(this, style);
  43935. const classNames = ["xfaField"];
  43936. if (this.font) {
  43937. classNames.push("xfaFont");
  43938. }
  43939. if (isPrintOnly(this)) {
  43940. classNames.push("xfaPrintOnly");
  43941. }
  43942. const attributes = {
  43943. style,
  43944. id: this[$uid],
  43945. class: classNames
  43946. };
  43947. if (style.margin) {
  43948. style.padding = style.margin;
  43949. delete style.margin;
  43950. }
  43951. setAccess(this, classNames);
  43952. if (this.name) {
  43953. attributes.xfaName = this.name;
  43954. }
  43955. const children = [];
  43956. const html = {
  43957. name: "div",
  43958. attributes,
  43959. children
  43960. };
  43961. applyAssist(this, attributes);
  43962. const borderStyle = this.border ? this.border[$toStyle]() : null;
  43963. const bbox = computeBbox(this, html, availableSpace);
  43964. const ui = this.ui[$toHTML]().html;
  43965. if (!ui) {
  43966. Object.assign(style, borderStyle);
  43967. return HTMLResult.success(createWrapper(this, html), bbox);
  43968. }
  43969. if (this[$tabIndex]) {
  43970. if (ui.children?.[0]) {
  43971. ui.children[0].attributes.tabindex = this[$tabIndex];
  43972. } else {
  43973. ui.attributes.tabindex = this[$tabIndex];
  43974. }
  43975. }
  43976. if (!ui.attributes.style) {
  43977. ui.attributes.style = Object.create(null);
  43978. }
  43979. let aElement = null;
  43980. if (this.ui.button) {
  43981. if (ui.children.length === 1) {
  43982. [aElement] = ui.children.splice(0, 1);
  43983. }
  43984. Object.assign(ui.attributes.style, borderStyle);
  43985. } else {
  43986. Object.assign(style, borderStyle);
  43987. }
  43988. children.push(ui);
  43989. if (this.value) {
  43990. if (this.ui.imageEdit) {
  43991. ui.children.push(this.value[$toHTML]().html);
  43992. } else if (!this.ui.button) {
  43993. let value = "";
  43994. if (this.value.exData) {
  43995. value = this.value.exData[$text]();
  43996. } else if (this.value.text) {
  43997. value = this.value.text[$getExtra]();
  43998. } else {
  43999. const htmlValue = this.value[$toHTML]().html;
  44000. if (htmlValue !== null) {
  44001. value = htmlValue.children[0].value;
  44002. }
  44003. }
  44004. if (this.ui.textEdit && this.value.text?.maxChars) {
  44005. ui.children[0].attributes.maxLength = this.value.text.maxChars;
  44006. }
  44007. if (value) {
  44008. if (this.ui.numericEdit) {
  44009. value = parseFloat(value);
  44010. value = isNaN(value) ? "" : value.toString();
  44011. }
  44012. if (ui.children[0].name === "textarea") {
  44013. ui.children[0].attributes.textContent = value;
  44014. } else {
  44015. ui.children[0].attributes.value = value;
  44016. }
  44017. }
  44018. }
  44019. }
  44020. if (!this.ui.imageEdit && ui.children?.[0] && this.h) {
  44021. borderDims = borderDims || getBorderDims(this.ui[$getExtra]());
  44022. let captionHeight = 0;
  44023. if (this.caption && ["top", "bottom"].includes(this.caption.placement)) {
  44024. captionHeight = this.caption.reserve;
  44025. if (captionHeight <= 0) {
  44026. captionHeight = this.caption[$getExtra](availableSpace).h;
  44027. }
  44028. const inputHeight = this.h - captionHeight - marginV - borderDims.h;
  44029. ui.children[0].attributes.style.height = measureToString(inputHeight);
  44030. } else {
  44031. ui.children[0].attributes.style.height = "100%";
  44032. }
  44033. }
  44034. if (aElement) {
  44035. ui.children.push(aElement);
  44036. }
  44037. if (!caption) {
  44038. if (ui.attributes.class) {
  44039. ui.attributes.class.push("xfaLeft");
  44040. }
  44041. this.w = savedW;
  44042. this.h = savedH;
  44043. return HTMLResult.success(createWrapper(this, html), bbox);
  44044. }
  44045. if (this.ui.button) {
  44046. if (style.padding) {
  44047. delete style.padding;
  44048. }
  44049. if (caption.name === "div") {
  44050. caption.name = "span";
  44051. }
  44052. ui.children.push(caption);
  44053. return HTMLResult.success(html, bbox);
  44054. } else if (this.ui.checkButton) {
  44055. caption.attributes.class[0] = "xfaCaptionForCheckButton";
  44056. }
  44057. if (!ui.attributes.class) {
  44058. ui.attributes.class = [];
  44059. }
  44060. ui.children.splice(0, 0, caption);
  44061. switch (this.caption.placement) {
  44062. case "left":
  44063. ui.attributes.class.push("xfaLeft");
  44064. break;
  44065. case "right":
  44066. ui.attributes.class.push("xfaRight");
  44067. break;
  44068. case "top":
  44069. ui.attributes.class.push("xfaTop");
  44070. break;
  44071. case "bottom":
  44072. ui.attributes.class.push("xfaBottom");
  44073. break;
  44074. case "inline":
  44075. ui.attributes.class.push("xfaLeft");
  44076. break;
  44077. }
  44078. this.w = savedW;
  44079. this.h = savedH;
  44080. return HTMLResult.success(createWrapper(this, html), bbox);
  44081. }
  44082. }
  44083. class Fill extends XFAObject {
  44084. constructor(attributes) {
  44085. super(TEMPLATE_NS_ID, "fill", true);
  44086. this.id = attributes.id || "";
  44087. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  44088. this.use = attributes.use || "";
  44089. this.usehref = attributes.usehref || "";
  44090. this.color = null;
  44091. this.extras = null;
  44092. this.linear = null;
  44093. this.pattern = null;
  44094. this.radial = null;
  44095. this.solid = null;
  44096. this.stipple = null;
  44097. }
  44098. [$toStyle]() {
  44099. const parent = this[$getParent]();
  44100. const grandpa = parent[$getParent]();
  44101. const ggrandpa = grandpa[$getParent]();
  44102. const style = Object.create(null);
  44103. let propName = "color";
  44104. let altPropName = propName;
  44105. if (parent instanceof Border) {
  44106. propName = "background-color";
  44107. altPropName = "background";
  44108. if (ggrandpa instanceof Ui) {
  44109. style.backgroundColor = "white";
  44110. }
  44111. }
  44112. if (parent instanceof Rectangle || parent instanceof Arc) {
  44113. propName = altPropName = "fill";
  44114. style.fill = "white";
  44115. }
  44116. for (const name of Object.getOwnPropertyNames(this)) {
  44117. if (name === "extras" || name === "color") {
  44118. continue;
  44119. }
  44120. const obj = this[name];
  44121. if (!(obj instanceof XFAObject)) {
  44122. continue;
  44123. }
  44124. const color = obj[$toStyle](this.color);
  44125. if (color) {
  44126. style[color.startsWith("#") ? propName : altPropName] = color;
  44127. }
  44128. return style;
  44129. }
  44130. if (this.color?.value) {
  44131. const color = this.color[$toStyle]();
  44132. style[color.startsWith("#") ? propName : altPropName] = color;
  44133. }
  44134. return style;
  44135. }
  44136. }
  44137. class Filter extends XFAObject {
  44138. constructor(attributes) {
  44139. super(TEMPLATE_NS_ID, "filter", true);
  44140. this.addRevocationInfo = getStringOption(attributes.addRevocationInfo, ["", "required", "optional", "none"]);
  44141. this.id = attributes.id || "";
  44142. this.name = attributes.name || "";
  44143. this.use = attributes.use || "";
  44144. this.usehref = attributes.usehref || "";
  44145. this.version = getInteger({
  44146. data: this.version,
  44147. defaultValue: 5,
  44148. validate: x => x >= 1 && x <= 5
  44149. });
  44150. this.appearanceFilter = null;
  44151. this.certificates = null;
  44152. this.digestMethods = null;
  44153. this.encodings = null;
  44154. this.encryptionMethods = null;
  44155. this.handler = null;
  44156. this.lockDocument = null;
  44157. this.mdp = null;
  44158. this.reasons = null;
  44159. this.timeStamp = null;
  44160. }
  44161. }
  44162. class Float extends ContentObject {
  44163. constructor(attributes) {
  44164. super(TEMPLATE_NS_ID, "float");
  44165. this.id = attributes.id || "";
  44166. this.name = attributes.name || "";
  44167. this.use = attributes.use || "";
  44168. this.usehref = attributes.usehref || "";
  44169. }
  44170. [$finalize]() {
  44171. const number = parseFloat(this[$content].trim());
  44172. this[$content] = isNaN(number) ? null : number;
  44173. }
  44174. [$toHTML](availableSpace) {
  44175. return valueToHtml(this[$content] !== null ? this[$content].toString() : "");
  44176. }
  44177. }
  44178. class template_Font extends XFAObject {
  44179. constructor(attributes) {
  44180. super(TEMPLATE_NS_ID, "font", true);
  44181. this.baselineShift = getMeasurement(attributes.baselineShift);
  44182. this.fontHorizontalScale = getFloat({
  44183. data: attributes.fontHorizontalScale,
  44184. defaultValue: 100,
  44185. validate: x => x >= 0
  44186. });
  44187. this.fontVerticalScale = getFloat({
  44188. data: attributes.fontVerticalScale,
  44189. defaultValue: 100,
  44190. validate: x => x >= 0
  44191. });
  44192. this.id = attributes.id || "";
  44193. this.kerningMode = getStringOption(attributes.kerningMode, ["none", "pair"]);
  44194. this.letterSpacing = getMeasurement(attributes.letterSpacing, "0");
  44195. this.lineThrough = getInteger({
  44196. data: attributes.lineThrough,
  44197. defaultValue: 0,
  44198. validate: x => x === 1 || x === 2
  44199. });
  44200. this.lineThroughPeriod = getStringOption(attributes.lineThroughPeriod, ["all", "word"]);
  44201. this.overline = getInteger({
  44202. data: attributes.overline,
  44203. defaultValue: 0,
  44204. validate: x => x === 1 || x === 2
  44205. });
  44206. this.overlinePeriod = getStringOption(attributes.overlinePeriod, ["all", "word"]);
  44207. this.posture = getStringOption(attributes.posture, ["normal", "italic"]);
  44208. this.size = getMeasurement(attributes.size, "10pt");
  44209. this.typeface = attributes.typeface || "Courier";
  44210. this.underline = getInteger({
  44211. data: attributes.underline,
  44212. defaultValue: 0,
  44213. validate: x => x === 1 || x === 2
  44214. });
  44215. this.underlinePeriod = getStringOption(attributes.underlinePeriod, ["all", "word"]);
  44216. this.use = attributes.use || "";
  44217. this.usehref = attributes.usehref || "";
  44218. this.weight = getStringOption(attributes.weight, ["normal", "bold"]);
  44219. this.extras = null;
  44220. this.fill = null;
  44221. }
  44222. [$clean](builder) {
  44223. super[$clean](builder);
  44224. this[$globalData].usedTypefaces.add(this.typeface);
  44225. }
  44226. [$toStyle]() {
  44227. const style = toStyle(this, "fill");
  44228. const color = style.color;
  44229. if (color) {
  44230. if (color === "#000000") {
  44231. delete style.color;
  44232. } else if (!color.startsWith("#")) {
  44233. style.background = color;
  44234. style.backgroundClip = "text";
  44235. style.color = "transparent";
  44236. }
  44237. }
  44238. if (this.baselineShift) {
  44239. style.verticalAlign = measureToString(this.baselineShift);
  44240. }
  44241. style.fontKerning = this.kerningMode === "none" ? "none" : "normal";
  44242. style.letterSpacing = measureToString(this.letterSpacing);
  44243. if (this.lineThrough !== 0) {
  44244. style.textDecoration = "line-through";
  44245. if (this.lineThrough === 2) {
  44246. style.textDecorationStyle = "double";
  44247. }
  44248. }
  44249. if (this.overline !== 0) {
  44250. style.textDecoration = "overline";
  44251. if (this.overline === 2) {
  44252. style.textDecorationStyle = "double";
  44253. }
  44254. }
  44255. style.fontStyle = this.posture;
  44256. style.fontSize = measureToString(0.99 * this.size);
  44257. setFontFamily(this, this, this[$globalData].fontFinder, style);
  44258. if (this.underline !== 0) {
  44259. style.textDecoration = "underline";
  44260. if (this.underline === 2) {
  44261. style.textDecorationStyle = "double";
  44262. }
  44263. }
  44264. style.fontWeight = this.weight;
  44265. return style;
  44266. }
  44267. }
  44268. class Format extends XFAObject {
  44269. constructor(attributes) {
  44270. super(TEMPLATE_NS_ID, "format", true);
  44271. this.id = attributes.id || "";
  44272. this.use = attributes.use || "";
  44273. this.usehref = attributes.usehref || "";
  44274. this.extras = null;
  44275. this.picture = null;
  44276. }
  44277. }
  44278. class Handler extends StringObject {
  44279. constructor(attributes) {
  44280. super(TEMPLATE_NS_ID, "handler");
  44281. this.id = attributes.id || "";
  44282. this.type = getStringOption(attributes.type, ["optional", "required"]);
  44283. this.use = attributes.use || "";
  44284. this.usehref = attributes.usehref || "";
  44285. }
  44286. }
  44287. class Hyphenation extends XFAObject {
  44288. constructor(attributes) {
  44289. super(TEMPLATE_NS_ID, "hyphenation");
  44290. this.excludeAllCaps = getInteger({
  44291. data: attributes.excludeAllCaps,
  44292. defaultValue: 0,
  44293. validate: x => x === 1
  44294. });
  44295. this.excludeInitialCap = getInteger({
  44296. data: attributes.excludeInitialCap,
  44297. defaultValue: 0,
  44298. validate: x => x === 1
  44299. });
  44300. this.hyphenate = getInteger({
  44301. data: attributes.hyphenate,
  44302. defaultValue: 0,
  44303. validate: x => x === 1
  44304. });
  44305. this.id = attributes.id || "";
  44306. this.pushCharacterCount = getInteger({
  44307. data: attributes.pushCharacterCount,
  44308. defaultValue: 3,
  44309. validate: x => x >= 0
  44310. });
  44311. this.remainCharacterCount = getInteger({
  44312. data: attributes.remainCharacterCount,
  44313. defaultValue: 3,
  44314. validate: x => x >= 0
  44315. });
  44316. this.use = attributes.use || "";
  44317. this.usehref = attributes.usehref || "";
  44318. this.wordCharacterCount = getInteger({
  44319. data: attributes.wordCharacterCount,
  44320. defaultValue: 7,
  44321. validate: x => x >= 0
  44322. });
  44323. }
  44324. }
  44325. class Image extends StringObject {
  44326. constructor(attributes) {
  44327. super(TEMPLATE_NS_ID, "image");
  44328. this.aspect = getStringOption(attributes.aspect, ["fit", "actual", "height", "none", "width"]);
  44329. this.contentType = attributes.contentType || "";
  44330. this.href = attributes.href || "";
  44331. this.id = attributes.id || "";
  44332. this.name = attributes.name || "";
  44333. this.transferEncoding = getStringOption(attributes.transferEncoding, ["base64", "none", "package"]);
  44334. this.use = attributes.use || "";
  44335. this.usehref = attributes.usehref || "";
  44336. }
  44337. [$toHTML]() {
  44338. if (this.contentType && !MIMES.has(this.contentType.toLowerCase())) {
  44339. return HTMLResult.EMPTY;
  44340. }
  44341. let buffer = this[$globalData].images && this[$globalData].images.get(this.href);
  44342. if (!buffer && (this.href || !this[$content])) {
  44343. return HTMLResult.EMPTY;
  44344. }
  44345. if (!buffer && this.transferEncoding === "base64") {
  44346. buffer = stringToBytes(atob(this[$content]));
  44347. }
  44348. if (!buffer) {
  44349. return HTMLResult.EMPTY;
  44350. }
  44351. if (!this.contentType) {
  44352. for (const [header, type] of IMAGES_HEADERS) {
  44353. if (buffer.length > header.length && header.every((x, i) => x === buffer[i])) {
  44354. this.contentType = type;
  44355. break;
  44356. }
  44357. }
  44358. if (!this.contentType) {
  44359. return HTMLResult.EMPTY;
  44360. }
  44361. }
  44362. const blob = new Blob([buffer], {
  44363. type: this.contentType
  44364. });
  44365. let style;
  44366. switch (this.aspect) {
  44367. case "fit":
  44368. case "actual":
  44369. break;
  44370. case "height":
  44371. style = {
  44372. height: "100%",
  44373. objectFit: "fill"
  44374. };
  44375. break;
  44376. case "none":
  44377. style = {
  44378. width: "100%",
  44379. height: "100%",
  44380. objectFit: "fill"
  44381. };
  44382. break;
  44383. case "width":
  44384. style = {
  44385. width: "100%",
  44386. objectFit: "fill"
  44387. };
  44388. break;
  44389. }
  44390. const parent = this[$getParent]();
  44391. return HTMLResult.success({
  44392. name: "img",
  44393. attributes: {
  44394. class: ["xfaImage"],
  44395. style,
  44396. src: URL.createObjectURL(blob),
  44397. alt: parent ? ariaLabel(parent[$getParent]()) : null
  44398. }
  44399. });
  44400. }
  44401. }
  44402. class ImageEdit extends XFAObject {
  44403. constructor(attributes) {
  44404. super(TEMPLATE_NS_ID, "imageEdit", true);
  44405. this.data = getStringOption(attributes.data, ["link", "embed"]);
  44406. this.id = attributes.id || "";
  44407. this.use = attributes.use || "";
  44408. this.usehref = attributes.usehref || "";
  44409. this.border = null;
  44410. this.extras = null;
  44411. this.margin = null;
  44412. }
  44413. [$toHTML](availableSpace) {
  44414. if (this.data === "embed") {
  44415. return HTMLResult.success({
  44416. name: "div",
  44417. children: [],
  44418. attributes: {}
  44419. });
  44420. }
  44421. return HTMLResult.EMPTY;
  44422. }
  44423. }
  44424. class Integer extends ContentObject {
  44425. constructor(attributes) {
  44426. super(TEMPLATE_NS_ID, "integer");
  44427. this.id = attributes.id || "";
  44428. this.name = attributes.name || "";
  44429. this.use = attributes.use || "";
  44430. this.usehref = attributes.usehref || "";
  44431. }
  44432. [$finalize]() {
  44433. const number = parseInt(this[$content].trim(), 10);
  44434. this[$content] = isNaN(number) ? null : number;
  44435. }
  44436. [$toHTML](availableSpace) {
  44437. return valueToHtml(this[$content] !== null ? this[$content].toString() : "");
  44438. }
  44439. }
  44440. class Issuers extends XFAObject {
  44441. constructor(attributes) {
  44442. super(TEMPLATE_NS_ID, "issuers", true);
  44443. this.id = attributes.id || "";
  44444. this.type = getStringOption(attributes.type, ["optional", "required"]);
  44445. this.use = attributes.use || "";
  44446. this.usehref = attributes.usehref || "";
  44447. this.certificate = new XFAObjectArray();
  44448. }
  44449. }
  44450. class Items extends XFAObject {
  44451. constructor(attributes) {
  44452. super(TEMPLATE_NS_ID, "items", true);
  44453. this.id = attributes.id || "";
  44454. this.name = attributes.name || "";
  44455. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  44456. this.ref = attributes.ref || "";
  44457. this.save = getInteger({
  44458. data: attributes.save,
  44459. defaultValue: 0,
  44460. validate: x => x === 1
  44461. });
  44462. this.use = attributes.use || "";
  44463. this.usehref = attributes.usehref || "";
  44464. this.boolean = new XFAObjectArray();
  44465. this.date = new XFAObjectArray();
  44466. this.dateTime = new XFAObjectArray();
  44467. this.decimal = new XFAObjectArray();
  44468. this.exData = new XFAObjectArray();
  44469. this.float = new XFAObjectArray();
  44470. this.image = new XFAObjectArray();
  44471. this.integer = new XFAObjectArray();
  44472. this.text = new XFAObjectArray();
  44473. this.time = new XFAObjectArray();
  44474. }
  44475. [$toHTML]() {
  44476. const output = [];
  44477. for (const child of this[$getChildren]()) {
  44478. output.push(child[$text]());
  44479. }
  44480. return HTMLResult.success(output);
  44481. }
  44482. }
  44483. class Keep extends XFAObject {
  44484. constructor(attributes) {
  44485. super(TEMPLATE_NS_ID, "keep", true);
  44486. this.id = attributes.id || "";
  44487. const options = ["none", "contentArea", "pageArea"];
  44488. this.intact = getStringOption(attributes.intact, options);
  44489. this.next = getStringOption(attributes.next, options);
  44490. this.previous = getStringOption(attributes.previous, options);
  44491. this.use = attributes.use || "";
  44492. this.usehref = attributes.usehref || "";
  44493. this.extras = null;
  44494. }
  44495. }
  44496. class KeyUsage extends XFAObject {
  44497. constructor(attributes) {
  44498. super(TEMPLATE_NS_ID, "keyUsage");
  44499. const options = ["", "yes", "no"];
  44500. this.crlSign = getStringOption(attributes.crlSign, options);
  44501. this.dataEncipherment = getStringOption(attributes.dataEncipherment, options);
  44502. this.decipherOnly = getStringOption(attributes.decipherOnly, options);
  44503. this.digitalSignature = getStringOption(attributes.digitalSignature, options);
  44504. this.encipherOnly = getStringOption(attributes.encipherOnly, options);
  44505. this.id = attributes.id || "";
  44506. this.keyAgreement = getStringOption(attributes.keyAgreement, options);
  44507. this.keyCertSign = getStringOption(attributes.keyCertSign, options);
  44508. this.keyEncipherment = getStringOption(attributes.keyEncipherment, options);
  44509. this.nonRepudiation = getStringOption(attributes.nonRepudiation, options);
  44510. this.type = getStringOption(attributes.type, ["optional", "required"]);
  44511. this.use = attributes.use || "";
  44512. this.usehref = attributes.usehref || "";
  44513. }
  44514. }
  44515. class Line extends XFAObject {
  44516. constructor(attributes) {
  44517. super(TEMPLATE_NS_ID, "line", true);
  44518. this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
  44519. this.id = attributes.id || "";
  44520. this.slope = getStringOption(attributes.slope, ["\\", "/"]);
  44521. this.use = attributes.use || "";
  44522. this.usehref = attributes.usehref || "";
  44523. this.edge = null;
  44524. }
  44525. [$toHTML]() {
  44526. const parent = this[$getParent]()[$getParent]();
  44527. const edge = this.edge || new Edge({});
  44528. const edgeStyle = edge[$toStyle]();
  44529. const style = Object.create(null);
  44530. const thickness = edge.presence === "visible" ? edge.thickness : 0;
  44531. style.strokeWidth = measureToString(thickness);
  44532. style.stroke = edgeStyle.color;
  44533. let x1, y1, x2, y2;
  44534. let width = "100%";
  44535. let height = "100%";
  44536. if (parent.w <= thickness) {
  44537. [x1, y1, x2, y2] = ["50%", 0, "50%", "100%"];
  44538. width = style.strokeWidth;
  44539. } else if (parent.h <= thickness) {
  44540. [x1, y1, x2, y2] = [0, "50%", "100%", "50%"];
  44541. height = style.strokeWidth;
  44542. } else if (this.slope === "\\") {
  44543. [x1, y1, x2, y2] = [0, 0, "100%", "100%"];
  44544. } else {
  44545. [x1, y1, x2, y2] = [0, "100%", "100%", 0];
  44546. }
  44547. const line = {
  44548. name: "line",
  44549. attributes: {
  44550. xmlns: SVG_NS,
  44551. x1,
  44552. y1,
  44553. x2,
  44554. y2,
  44555. style
  44556. }
  44557. };
  44558. const svg = {
  44559. name: "svg",
  44560. children: [line],
  44561. attributes: {
  44562. xmlns: SVG_NS,
  44563. width,
  44564. height,
  44565. style: {
  44566. overflow: "visible"
  44567. }
  44568. }
  44569. };
  44570. if (hasMargin(parent)) {
  44571. return HTMLResult.success({
  44572. name: "div",
  44573. attributes: {
  44574. style: {
  44575. display: "inline",
  44576. width: "100%",
  44577. height: "100%"
  44578. }
  44579. },
  44580. children: [svg]
  44581. });
  44582. }
  44583. svg.attributes.style.position = "absolute";
  44584. return HTMLResult.success(svg);
  44585. }
  44586. }
  44587. class Linear extends XFAObject {
  44588. constructor(attributes) {
  44589. super(TEMPLATE_NS_ID, "linear", true);
  44590. this.id = attributes.id || "";
  44591. this.type = getStringOption(attributes.type, ["toRight", "toBottom", "toLeft", "toTop"]);
  44592. this.use = attributes.use || "";
  44593. this.usehref = attributes.usehref || "";
  44594. this.color = null;
  44595. this.extras = null;
  44596. }
  44597. [$toStyle](startColor) {
  44598. startColor = startColor ? startColor[$toStyle]() : "#FFFFFF";
  44599. const transf = this.type.replace(/([RBLT])/, " $1").toLowerCase();
  44600. const endColor = this.color ? this.color[$toStyle]() : "#000000";
  44601. return `linear-gradient(${transf}, ${startColor}, ${endColor})`;
  44602. }
  44603. }
  44604. class LockDocument extends ContentObject {
  44605. constructor(attributes) {
  44606. super(TEMPLATE_NS_ID, "lockDocument");
  44607. this.id = attributes.id || "";
  44608. this.type = getStringOption(attributes.type, ["optional", "required"]);
  44609. this.use = attributes.use || "";
  44610. this.usehref = attributes.usehref || "";
  44611. }
  44612. [$finalize]() {
  44613. this[$content] = getStringOption(this[$content], ["auto", "0", "1"]);
  44614. }
  44615. }
  44616. class Manifest extends XFAObject {
  44617. constructor(attributes) {
  44618. super(TEMPLATE_NS_ID, "manifest", true);
  44619. this.action = getStringOption(attributes.action, ["include", "all", "exclude"]);
  44620. this.id = attributes.id || "";
  44621. this.name = attributes.name || "";
  44622. this.use = attributes.use || "";
  44623. this.usehref = attributes.usehref || "";
  44624. this.extras = null;
  44625. this.ref = new XFAObjectArray();
  44626. }
  44627. }
  44628. class Margin extends XFAObject {
  44629. constructor(attributes) {
  44630. super(TEMPLATE_NS_ID, "margin", true);
  44631. this.bottomInset = getMeasurement(attributes.bottomInset, "0");
  44632. this.id = attributes.id || "";
  44633. this.leftInset = getMeasurement(attributes.leftInset, "0");
  44634. this.rightInset = getMeasurement(attributes.rightInset, "0");
  44635. this.topInset = getMeasurement(attributes.topInset, "0");
  44636. this.use = attributes.use || "";
  44637. this.usehref = attributes.usehref || "";
  44638. this.extras = null;
  44639. }
  44640. [$toStyle]() {
  44641. return {
  44642. margin: measureToString(this.topInset) + " " + measureToString(this.rightInset) + " " + measureToString(this.bottomInset) + " " + measureToString(this.leftInset)
  44643. };
  44644. }
  44645. }
  44646. class Mdp extends XFAObject {
  44647. constructor(attributes) {
  44648. super(TEMPLATE_NS_ID, "mdp");
  44649. this.id = attributes.id || "";
  44650. this.permissions = getInteger({
  44651. data: attributes.permissions,
  44652. defaultValue: 2,
  44653. validate: x => x === 1 || x === 3
  44654. });
  44655. this.signatureType = getStringOption(attributes.signatureType, ["filler", "author"]);
  44656. this.use = attributes.use || "";
  44657. this.usehref = attributes.usehref || "";
  44658. }
  44659. }
  44660. class Medium extends XFAObject {
  44661. constructor(attributes) {
  44662. super(TEMPLATE_NS_ID, "medium");
  44663. this.id = attributes.id || "";
  44664. this.imagingBBox = getBBox(attributes.imagingBBox);
  44665. this.long = getMeasurement(attributes.long);
  44666. this.orientation = getStringOption(attributes.orientation, ["portrait", "landscape"]);
  44667. this.short = getMeasurement(attributes.short);
  44668. this.stock = attributes.stock || "";
  44669. this.trayIn = getStringOption(attributes.trayIn, ["auto", "delegate", "pageFront"]);
  44670. this.trayOut = getStringOption(attributes.trayOut, ["auto", "delegate"]);
  44671. this.use = attributes.use || "";
  44672. this.usehref = attributes.usehref || "";
  44673. }
  44674. }
  44675. class Message extends XFAObject {
  44676. constructor(attributes) {
  44677. super(TEMPLATE_NS_ID, "message", true);
  44678. this.id = attributes.id || "";
  44679. this.use = attributes.use || "";
  44680. this.usehref = attributes.usehref || "";
  44681. this.text = new XFAObjectArray();
  44682. }
  44683. }
  44684. class NumericEdit extends XFAObject {
  44685. constructor(attributes) {
  44686. super(TEMPLATE_NS_ID, "numericEdit", true);
  44687. this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
  44688. this.id = attributes.id || "";
  44689. this.use = attributes.use || "";
  44690. this.usehref = attributes.usehref || "";
  44691. this.border = null;
  44692. this.comb = null;
  44693. this.extras = null;
  44694. this.margin = null;
  44695. }
  44696. [$toHTML](availableSpace) {
  44697. const style = toStyle(this, "border", "font", "margin");
  44698. const field = this[$getParent]()[$getParent]();
  44699. const html = {
  44700. name: "input",
  44701. attributes: {
  44702. type: "text",
  44703. fieldId: field[$uid],
  44704. dataId: field[$data]?.[$uid] || field[$uid],
  44705. class: ["xfaTextfield"],
  44706. style,
  44707. "aria-label": ariaLabel(field),
  44708. "aria-required": false
  44709. }
  44710. };
  44711. if (isRequired(field)) {
  44712. html.attributes["aria-required"] = true;
  44713. html.attributes.required = true;
  44714. }
  44715. return HTMLResult.success({
  44716. name: "label",
  44717. attributes: {
  44718. class: ["xfaLabel"]
  44719. },
  44720. children: [html]
  44721. });
  44722. }
  44723. }
  44724. class Occur extends XFAObject {
  44725. constructor(attributes) {
  44726. super(TEMPLATE_NS_ID, "occur", true);
  44727. this.id = attributes.id || "";
  44728. this.initial = attributes.initial !== "" ? getInteger({
  44729. data: attributes.initial,
  44730. defaultValue: "",
  44731. validate: x => true
  44732. }) : "";
  44733. this.max = attributes.max !== "" ? getInteger({
  44734. data: attributes.max,
  44735. defaultValue: 1,
  44736. validate: x => true
  44737. }) : "";
  44738. this.min = attributes.min !== "" ? getInteger({
  44739. data: attributes.min,
  44740. defaultValue: 1,
  44741. validate: x => true
  44742. }) : "";
  44743. this.use = attributes.use || "";
  44744. this.usehref = attributes.usehref || "";
  44745. this.extras = null;
  44746. }
  44747. [$clean]() {
  44748. const parent = this[$getParent]();
  44749. const originalMin = this.min;
  44750. if (this.min === "") {
  44751. this.min = parent instanceof PageArea || parent instanceof PageSet ? 0 : 1;
  44752. }
  44753. if (this.max === "") {
  44754. if (originalMin === "") {
  44755. this.max = parent instanceof PageArea || parent instanceof PageSet ? -1 : 1;
  44756. } else {
  44757. this.max = this.min;
  44758. }
  44759. }
  44760. if (this.max !== -1 && this.max < this.min) {
  44761. this.max = this.min;
  44762. }
  44763. if (this.initial === "") {
  44764. this.initial = parent instanceof Template ? 1 : this.min;
  44765. }
  44766. }
  44767. }
  44768. class Oid extends StringObject {
  44769. constructor(attributes) {
  44770. super(TEMPLATE_NS_ID, "oid");
  44771. this.id = attributes.id || "";
  44772. this.name = attributes.name || "";
  44773. this.use = attributes.use || "";
  44774. this.usehref = attributes.usehref || "";
  44775. }
  44776. }
  44777. class Oids extends XFAObject {
  44778. constructor(attributes) {
  44779. super(TEMPLATE_NS_ID, "oids", true);
  44780. this.id = attributes.id || "";
  44781. this.type = getStringOption(attributes.type, ["optional", "required"]);
  44782. this.use = attributes.use || "";
  44783. this.usehref = attributes.usehref || "";
  44784. this.oid = new XFAObjectArray();
  44785. }
  44786. }
  44787. class Overflow extends XFAObject {
  44788. constructor(attributes) {
  44789. super(TEMPLATE_NS_ID, "overflow");
  44790. this.id = attributes.id || "";
  44791. this.leader = attributes.leader || "";
  44792. this.target = attributes.target || "";
  44793. this.trailer = attributes.trailer || "";
  44794. this.use = attributes.use || "";
  44795. this.usehref = attributes.usehref || "";
  44796. }
  44797. [$getExtra]() {
  44798. if (!this[$extra]) {
  44799. const parent = this[$getParent]();
  44800. const root = this[$getTemplateRoot]();
  44801. const target = root[$searchNode](this.target, parent);
  44802. const leader = root[$searchNode](this.leader, parent);
  44803. const trailer = root[$searchNode](this.trailer, parent);
  44804. this[$extra] = {
  44805. target: target?.[0] || null,
  44806. leader: leader?.[0] || null,
  44807. trailer: trailer?.[0] || null,
  44808. addLeader: false,
  44809. addTrailer: false
  44810. };
  44811. }
  44812. return this[$extra];
  44813. }
  44814. }
  44815. class PageArea extends XFAObject {
  44816. constructor(attributes) {
  44817. super(TEMPLATE_NS_ID, "pageArea", true);
  44818. this.blankOrNotBlank = getStringOption(attributes.blankOrNotBlank, ["any", "blank", "notBlank"]);
  44819. this.id = attributes.id || "";
  44820. this.initialNumber = getInteger({
  44821. data: attributes.initialNumber,
  44822. defaultValue: 1,
  44823. validate: x => true
  44824. });
  44825. this.name = attributes.name || "";
  44826. this.numbered = getInteger({
  44827. data: attributes.numbered,
  44828. defaultValue: 1,
  44829. validate: x => true
  44830. });
  44831. this.oddOrEven = getStringOption(attributes.oddOrEven, ["any", "even", "odd"]);
  44832. this.pagePosition = getStringOption(attributes.pagePosition, ["any", "first", "last", "only", "rest"]);
  44833. this.relevant = getRelevant(attributes.relevant);
  44834. this.use = attributes.use || "";
  44835. this.usehref = attributes.usehref || "";
  44836. this.desc = null;
  44837. this.extras = null;
  44838. this.medium = null;
  44839. this.occur = null;
  44840. this.area = new XFAObjectArray();
  44841. this.contentArea = new XFAObjectArray();
  44842. this.draw = new XFAObjectArray();
  44843. this.exclGroup = new XFAObjectArray();
  44844. this.field = new XFAObjectArray();
  44845. this.subform = new XFAObjectArray();
  44846. }
  44847. [$isUsable]() {
  44848. if (!this[$extra]) {
  44849. this[$extra] = {
  44850. numberOfUse: 0
  44851. };
  44852. return true;
  44853. }
  44854. return !this.occur || this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max;
  44855. }
  44856. [$cleanPage]() {
  44857. delete this[$extra];
  44858. }
  44859. [$getNextPage]() {
  44860. if (!this[$extra]) {
  44861. this[$extra] = {
  44862. numberOfUse: 0
  44863. };
  44864. }
  44865. const parent = this[$getParent]();
  44866. if (parent.relation === "orderedOccurrence") {
  44867. if (this[$isUsable]()) {
  44868. this[$extra].numberOfUse += 1;
  44869. return this;
  44870. }
  44871. }
  44872. return parent[$getNextPage]();
  44873. }
  44874. [$getAvailableSpace]() {
  44875. return this[$extra].space || {
  44876. width: 0,
  44877. height: 0
  44878. };
  44879. }
  44880. [$toHTML]() {
  44881. if (!this[$extra]) {
  44882. this[$extra] = {
  44883. numberOfUse: 1
  44884. };
  44885. }
  44886. const children = [];
  44887. this[$extra].children = children;
  44888. const style = Object.create(null);
  44889. if (this.medium && this.medium.short && this.medium.long) {
  44890. style.width = measureToString(this.medium.short);
  44891. style.height = measureToString(this.medium.long);
  44892. this[$extra].space = {
  44893. width: this.medium.short,
  44894. height: this.medium.long
  44895. };
  44896. if (this.medium.orientation === "landscape") {
  44897. const x = style.width;
  44898. style.width = style.height;
  44899. style.height = x;
  44900. this[$extra].space = {
  44901. width: this.medium.long,
  44902. height: this.medium.short
  44903. };
  44904. }
  44905. } else {
  44906. warn("XFA - No medium specified in pageArea: please file a bug.");
  44907. }
  44908. this[$childrenToHTML]({
  44909. filter: new Set(["area", "draw", "field", "subform"]),
  44910. include: true
  44911. });
  44912. this[$childrenToHTML]({
  44913. filter: new Set(["contentArea"]),
  44914. include: true
  44915. });
  44916. return HTMLResult.success({
  44917. name: "div",
  44918. children,
  44919. attributes: {
  44920. class: ["xfaPage"],
  44921. id: this[$uid],
  44922. style,
  44923. xfaName: this.name
  44924. }
  44925. });
  44926. }
  44927. }
  44928. class PageSet extends XFAObject {
  44929. constructor(attributes) {
  44930. super(TEMPLATE_NS_ID, "pageSet", true);
  44931. this.duplexImposition = getStringOption(attributes.duplexImposition, ["longEdge", "shortEdge"]);
  44932. this.id = attributes.id || "";
  44933. this.name = attributes.name || "";
  44934. this.relation = getStringOption(attributes.relation, ["orderedOccurrence", "duplexPaginated", "simplexPaginated"]);
  44935. this.relevant = getRelevant(attributes.relevant);
  44936. this.use = attributes.use || "";
  44937. this.usehref = attributes.usehref || "";
  44938. this.extras = null;
  44939. this.occur = null;
  44940. this.pageArea = new XFAObjectArray();
  44941. this.pageSet = new XFAObjectArray();
  44942. }
  44943. [$cleanPage]() {
  44944. for (const page of this.pageArea.children) {
  44945. page[$cleanPage]();
  44946. }
  44947. for (const page of this.pageSet.children) {
  44948. page[$cleanPage]();
  44949. }
  44950. }
  44951. [$isUsable]() {
  44952. return !this.occur || this.occur.max === -1 || this[$extra].numberOfUse < this.occur.max;
  44953. }
  44954. [$getNextPage]() {
  44955. if (!this[$extra]) {
  44956. this[$extra] = {
  44957. numberOfUse: 1,
  44958. pageIndex: -1,
  44959. pageSetIndex: -1
  44960. };
  44961. }
  44962. if (this.relation === "orderedOccurrence") {
  44963. if (this[$extra].pageIndex + 1 < this.pageArea.children.length) {
  44964. this[$extra].pageIndex += 1;
  44965. const pageArea = this.pageArea.children[this[$extra].pageIndex];
  44966. return pageArea[$getNextPage]();
  44967. }
  44968. if (this[$extra].pageSetIndex + 1 < this.pageSet.children.length) {
  44969. this[$extra].pageSetIndex += 1;
  44970. return this.pageSet.children[this[$extra].pageSetIndex][$getNextPage]();
  44971. }
  44972. if (this[$isUsable]()) {
  44973. this[$extra].numberOfUse += 1;
  44974. this[$extra].pageIndex = -1;
  44975. this[$extra].pageSetIndex = -1;
  44976. return this[$getNextPage]();
  44977. }
  44978. const parent = this[$getParent]();
  44979. if (parent instanceof PageSet) {
  44980. return parent[$getNextPage]();
  44981. }
  44982. this[$cleanPage]();
  44983. return this[$getNextPage]();
  44984. }
  44985. const pageNumber = this[$getTemplateRoot]()[$extra].pageNumber;
  44986. const parity = pageNumber % 2 === 0 ? "even" : "odd";
  44987. const position = pageNumber === 0 ? "first" : "rest";
  44988. let page = this.pageArea.children.find(p => p.oddOrEven === parity && p.pagePosition === position);
  44989. if (page) {
  44990. return page;
  44991. }
  44992. page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === position);
  44993. if (page) {
  44994. return page;
  44995. }
  44996. page = this.pageArea.children.find(p => p.oddOrEven === "any" && p.pagePosition === "any");
  44997. if (page) {
  44998. return page;
  44999. }
  45000. return this.pageArea.children[0];
  45001. }
  45002. }
  45003. class Para extends XFAObject {
  45004. constructor(attributes) {
  45005. super(TEMPLATE_NS_ID, "para", true);
  45006. this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  45007. this.id = attributes.id || "";
  45008. this.lineHeight = attributes.lineHeight ? getMeasurement(attributes.lineHeight, "0pt") : "";
  45009. this.marginLeft = attributes.marginLeft ? getMeasurement(attributes.marginLeft, "0pt") : "";
  45010. this.marginRight = attributes.marginRight ? getMeasurement(attributes.marginRight, "0pt") : "";
  45011. this.orphans = getInteger({
  45012. data: attributes.orphans,
  45013. defaultValue: 0,
  45014. validate: x => x >= 0
  45015. });
  45016. this.preserve = attributes.preserve || "";
  45017. this.radixOffset = attributes.radixOffset ? getMeasurement(attributes.radixOffset, "0pt") : "";
  45018. this.spaceAbove = attributes.spaceAbove ? getMeasurement(attributes.spaceAbove, "0pt") : "";
  45019. this.spaceBelow = attributes.spaceBelow ? getMeasurement(attributes.spaceBelow, "0pt") : "";
  45020. this.tabDefault = attributes.tabDefault ? getMeasurement(this.tabDefault) : "";
  45021. this.tabStops = (attributes.tabStops || "").trim().split(/\s+/).map((x, i) => i % 2 === 1 ? getMeasurement(x) : x);
  45022. this.textIndent = attributes.textIndent ? getMeasurement(attributes.textIndent, "0pt") : "";
  45023. this.use = attributes.use || "";
  45024. this.usehref = attributes.usehref || "";
  45025. this.vAlign = getStringOption(attributes.vAlign, ["top", "bottom", "middle"]);
  45026. this.widows = getInteger({
  45027. data: attributes.widows,
  45028. defaultValue: 0,
  45029. validate: x => x >= 0
  45030. });
  45031. this.hyphenation = null;
  45032. }
  45033. [$toStyle]() {
  45034. const style = toStyle(this, "hAlign");
  45035. if (this.marginLeft !== "") {
  45036. style.paddingLeft = measureToString(this.marginLeft);
  45037. }
  45038. if (this.marginRight !== "") {
  45039. style.paddingight = measureToString(this.marginRight);
  45040. }
  45041. if (this.spaceAbove !== "") {
  45042. style.paddingTop = measureToString(this.spaceAbove);
  45043. }
  45044. if (this.spaceBelow !== "") {
  45045. style.paddingBottom = measureToString(this.spaceBelow);
  45046. }
  45047. if (this.textIndent !== "") {
  45048. style.textIndent = measureToString(this.textIndent);
  45049. fixTextIndent(style);
  45050. }
  45051. if (this.lineHeight > 0) {
  45052. style.lineHeight = measureToString(this.lineHeight);
  45053. }
  45054. if (this.tabDefault !== "") {
  45055. style.tabSize = measureToString(this.tabDefault);
  45056. }
  45057. if (this.tabStops.length > 0) {}
  45058. if (this.hyphenatation) {
  45059. Object.assign(style, this.hyphenatation[$toStyle]());
  45060. }
  45061. return style;
  45062. }
  45063. }
  45064. class PasswordEdit extends XFAObject {
  45065. constructor(attributes) {
  45066. super(TEMPLATE_NS_ID, "passwordEdit", true);
  45067. this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
  45068. this.id = attributes.id || "";
  45069. this.passwordChar = attributes.passwordChar || "*";
  45070. this.use = attributes.use || "";
  45071. this.usehref = attributes.usehref || "";
  45072. this.border = null;
  45073. this.extras = null;
  45074. this.margin = null;
  45075. }
  45076. }
  45077. class template_Pattern extends XFAObject {
  45078. constructor(attributes) {
  45079. super(TEMPLATE_NS_ID, "pattern", true);
  45080. this.id = attributes.id || "";
  45081. this.type = getStringOption(attributes.type, ["crossHatch", "crossDiagonal", "diagonalLeft", "diagonalRight", "horizontal", "vertical"]);
  45082. this.use = attributes.use || "";
  45083. this.usehref = attributes.usehref || "";
  45084. this.color = null;
  45085. this.extras = null;
  45086. }
  45087. [$toStyle](startColor) {
  45088. startColor = startColor ? startColor[$toStyle]() : "#FFFFFF";
  45089. const endColor = this.color ? this.color[$toStyle]() : "#000000";
  45090. const width = 5;
  45091. const cmd = "repeating-linear-gradient";
  45092. const colors = `${startColor},${startColor} ${width}px,${endColor} ${width}px,${endColor} ${2 * width}px`;
  45093. switch (this.type) {
  45094. case "crossHatch":
  45095. return `${cmd}(to top,${colors}) ${cmd}(to right,${colors})`;
  45096. case "crossDiagonal":
  45097. return `${cmd}(45deg,${colors}) ${cmd}(-45deg,${colors})`;
  45098. case "diagonalLeft":
  45099. return `${cmd}(45deg,${colors})`;
  45100. case "diagonalRight":
  45101. return `${cmd}(-45deg,${colors})`;
  45102. case "horizontal":
  45103. return `${cmd}(to top,${colors})`;
  45104. case "vertical":
  45105. return `${cmd}(to right,${colors})`;
  45106. }
  45107. return "";
  45108. }
  45109. }
  45110. class Picture extends StringObject {
  45111. constructor(attributes) {
  45112. super(TEMPLATE_NS_ID, "picture");
  45113. this.id = attributes.id || "";
  45114. this.use = attributes.use || "";
  45115. this.usehref = attributes.usehref || "";
  45116. }
  45117. }
  45118. class Proto extends XFAObject {
  45119. constructor(attributes) {
  45120. super(TEMPLATE_NS_ID, "proto", true);
  45121. this.appearanceFilter = new XFAObjectArray();
  45122. this.arc = new XFAObjectArray();
  45123. this.area = new XFAObjectArray();
  45124. this.assist = new XFAObjectArray();
  45125. this.barcode = new XFAObjectArray();
  45126. this.bindItems = new XFAObjectArray();
  45127. this.bookend = new XFAObjectArray();
  45128. this.boolean = new XFAObjectArray();
  45129. this.border = new XFAObjectArray();
  45130. this.break = new XFAObjectArray();
  45131. this.breakAfter = new XFAObjectArray();
  45132. this.breakBefore = new XFAObjectArray();
  45133. this.button = new XFAObjectArray();
  45134. this.calculate = new XFAObjectArray();
  45135. this.caption = new XFAObjectArray();
  45136. this.certificate = new XFAObjectArray();
  45137. this.certificates = new XFAObjectArray();
  45138. this.checkButton = new XFAObjectArray();
  45139. this.choiceList = new XFAObjectArray();
  45140. this.color = new XFAObjectArray();
  45141. this.comb = new XFAObjectArray();
  45142. this.connect = new XFAObjectArray();
  45143. this.contentArea = new XFAObjectArray();
  45144. this.corner = new XFAObjectArray();
  45145. this.date = new XFAObjectArray();
  45146. this.dateTime = new XFAObjectArray();
  45147. this.dateTimeEdit = new XFAObjectArray();
  45148. this.decimal = new XFAObjectArray();
  45149. this.defaultUi = new XFAObjectArray();
  45150. this.desc = new XFAObjectArray();
  45151. this.digestMethod = new XFAObjectArray();
  45152. this.digestMethods = new XFAObjectArray();
  45153. this.draw = new XFAObjectArray();
  45154. this.edge = new XFAObjectArray();
  45155. this.encoding = new XFAObjectArray();
  45156. this.encodings = new XFAObjectArray();
  45157. this.encrypt = new XFAObjectArray();
  45158. this.encryptData = new XFAObjectArray();
  45159. this.encryption = new XFAObjectArray();
  45160. this.encryptionMethod = new XFAObjectArray();
  45161. this.encryptionMethods = new XFAObjectArray();
  45162. this.event = new XFAObjectArray();
  45163. this.exData = new XFAObjectArray();
  45164. this.exObject = new XFAObjectArray();
  45165. this.exclGroup = new XFAObjectArray();
  45166. this.execute = new XFAObjectArray();
  45167. this.extras = new XFAObjectArray();
  45168. this.field = new XFAObjectArray();
  45169. this.fill = new XFAObjectArray();
  45170. this.filter = new XFAObjectArray();
  45171. this.float = new XFAObjectArray();
  45172. this.font = new XFAObjectArray();
  45173. this.format = new XFAObjectArray();
  45174. this.handler = new XFAObjectArray();
  45175. this.hyphenation = new XFAObjectArray();
  45176. this.image = new XFAObjectArray();
  45177. this.imageEdit = new XFAObjectArray();
  45178. this.integer = new XFAObjectArray();
  45179. this.issuers = new XFAObjectArray();
  45180. this.items = new XFAObjectArray();
  45181. this.keep = new XFAObjectArray();
  45182. this.keyUsage = new XFAObjectArray();
  45183. this.line = new XFAObjectArray();
  45184. this.linear = new XFAObjectArray();
  45185. this.lockDocument = new XFAObjectArray();
  45186. this.manifest = new XFAObjectArray();
  45187. this.margin = new XFAObjectArray();
  45188. this.mdp = new XFAObjectArray();
  45189. this.medium = new XFAObjectArray();
  45190. this.message = new XFAObjectArray();
  45191. this.numericEdit = new XFAObjectArray();
  45192. this.occur = new XFAObjectArray();
  45193. this.oid = new XFAObjectArray();
  45194. this.oids = new XFAObjectArray();
  45195. this.overflow = new XFAObjectArray();
  45196. this.pageArea = new XFAObjectArray();
  45197. this.pageSet = new XFAObjectArray();
  45198. this.para = new XFAObjectArray();
  45199. this.passwordEdit = new XFAObjectArray();
  45200. this.pattern = new XFAObjectArray();
  45201. this.picture = new XFAObjectArray();
  45202. this.radial = new XFAObjectArray();
  45203. this.reason = new XFAObjectArray();
  45204. this.reasons = new XFAObjectArray();
  45205. this.rectangle = new XFAObjectArray();
  45206. this.ref = new XFAObjectArray();
  45207. this.script = new XFAObjectArray();
  45208. this.setProperty = new XFAObjectArray();
  45209. this.signData = new XFAObjectArray();
  45210. this.signature = new XFAObjectArray();
  45211. this.signing = new XFAObjectArray();
  45212. this.solid = new XFAObjectArray();
  45213. this.speak = new XFAObjectArray();
  45214. this.stipple = new XFAObjectArray();
  45215. this.subform = new XFAObjectArray();
  45216. this.subformSet = new XFAObjectArray();
  45217. this.subjectDN = new XFAObjectArray();
  45218. this.subjectDNs = new XFAObjectArray();
  45219. this.submit = new XFAObjectArray();
  45220. this.text = new XFAObjectArray();
  45221. this.textEdit = new XFAObjectArray();
  45222. this.time = new XFAObjectArray();
  45223. this.timeStamp = new XFAObjectArray();
  45224. this.toolTip = new XFAObjectArray();
  45225. this.traversal = new XFAObjectArray();
  45226. this.traverse = new XFAObjectArray();
  45227. this.ui = new XFAObjectArray();
  45228. this.validate = new XFAObjectArray();
  45229. this.value = new XFAObjectArray();
  45230. this.variables = new XFAObjectArray();
  45231. }
  45232. }
  45233. class Radial extends XFAObject {
  45234. constructor(attributes) {
  45235. super(TEMPLATE_NS_ID, "radial", true);
  45236. this.id = attributes.id || "";
  45237. this.type = getStringOption(attributes.type, ["toEdge", "toCenter"]);
  45238. this.use = attributes.use || "";
  45239. this.usehref = attributes.usehref || "";
  45240. this.color = null;
  45241. this.extras = null;
  45242. }
  45243. [$toStyle](startColor) {
  45244. startColor = startColor ? startColor[$toStyle]() : "#FFFFFF";
  45245. const endColor = this.color ? this.color[$toStyle]() : "#000000";
  45246. const colors = this.type === "toEdge" ? `${startColor},${endColor}` : `${endColor},${startColor}`;
  45247. return `radial-gradient(circle at center, ${colors})`;
  45248. }
  45249. }
  45250. class Reason extends StringObject {
  45251. constructor(attributes) {
  45252. super(TEMPLATE_NS_ID, "reason");
  45253. this.id = attributes.id || "";
  45254. this.name = attributes.name || "";
  45255. this.use = attributes.use || "";
  45256. this.usehref = attributes.usehref || "";
  45257. }
  45258. }
  45259. class Reasons extends XFAObject {
  45260. constructor(attributes) {
  45261. super(TEMPLATE_NS_ID, "reasons", true);
  45262. this.id = attributes.id || "";
  45263. this.type = getStringOption(attributes.type, ["optional", "required"]);
  45264. this.use = attributes.use || "";
  45265. this.usehref = attributes.usehref || "";
  45266. this.reason = new XFAObjectArray();
  45267. }
  45268. }
  45269. class Rectangle extends XFAObject {
  45270. constructor(attributes) {
  45271. super(TEMPLATE_NS_ID, "rectangle", true);
  45272. this.hand = getStringOption(attributes.hand, ["even", "left", "right"]);
  45273. this.id = attributes.id || "";
  45274. this.use = attributes.use || "";
  45275. this.usehref = attributes.usehref || "";
  45276. this.corner = new XFAObjectArray(4);
  45277. this.edge = new XFAObjectArray(4);
  45278. this.fill = null;
  45279. }
  45280. [$toHTML]() {
  45281. const edge = this.edge.children.length ? this.edge.children[0] : new Edge({});
  45282. const edgeStyle = edge[$toStyle]();
  45283. const style = Object.create(null);
  45284. if (this.fill?.presence === "visible") {
  45285. Object.assign(style, this.fill[$toStyle]());
  45286. } else {
  45287. style.fill = "transparent";
  45288. }
  45289. style.strokeWidth = measureToString(edge.presence === "visible" ? edge.thickness : 0);
  45290. style.stroke = edgeStyle.color;
  45291. const corner = this.corner.children.length ? this.corner.children[0] : new Corner({});
  45292. const cornerStyle = corner[$toStyle]();
  45293. const rect = {
  45294. name: "rect",
  45295. attributes: {
  45296. xmlns: SVG_NS,
  45297. width: "100%",
  45298. height: "100%",
  45299. x: 0,
  45300. y: 0,
  45301. rx: cornerStyle.radius,
  45302. ry: cornerStyle.radius,
  45303. style
  45304. }
  45305. };
  45306. const svg = {
  45307. name: "svg",
  45308. children: [rect],
  45309. attributes: {
  45310. xmlns: SVG_NS,
  45311. style: {
  45312. overflow: "visible"
  45313. },
  45314. width: "100%",
  45315. height: "100%"
  45316. }
  45317. };
  45318. const parent = this[$getParent]()[$getParent]();
  45319. if (hasMargin(parent)) {
  45320. return HTMLResult.success({
  45321. name: "div",
  45322. attributes: {
  45323. style: {
  45324. display: "inline",
  45325. width: "100%",
  45326. height: "100%"
  45327. }
  45328. },
  45329. children: [svg]
  45330. });
  45331. }
  45332. svg.attributes.style.position = "absolute";
  45333. return HTMLResult.success(svg);
  45334. }
  45335. }
  45336. class RefElement extends StringObject {
  45337. constructor(attributes) {
  45338. super(TEMPLATE_NS_ID, "ref");
  45339. this.id = attributes.id || "";
  45340. this.use = attributes.use || "";
  45341. this.usehref = attributes.usehref || "";
  45342. }
  45343. }
  45344. class Script extends StringObject {
  45345. constructor(attributes) {
  45346. super(TEMPLATE_NS_ID, "script");
  45347. this.binding = attributes.binding || "";
  45348. this.contentType = attributes.contentType || "";
  45349. this.id = attributes.id || "";
  45350. this.name = attributes.name || "";
  45351. this.runAt = getStringOption(attributes.runAt, ["client", "both", "server"]);
  45352. this.use = attributes.use || "";
  45353. this.usehref = attributes.usehref || "";
  45354. }
  45355. }
  45356. class SetProperty extends XFAObject {
  45357. constructor(attributes) {
  45358. super(TEMPLATE_NS_ID, "setProperty");
  45359. this.connection = attributes.connection || "";
  45360. this.ref = attributes.ref || "";
  45361. this.target = attributes.target || "";
  45362. }
  45363. }
  45364. class SignData extends XFAObject {
  45365. constructor(attributes) {
  45366. super(TEMPLATE_NS_ID, "signData", true);
  45367. this.id = attributes.id || "";
  45368. this.operation = getStringOption(attributes.operation, ["sign", "clear", "verify"]);
  45369. this.ref = attributes.ref || "";
  45370. this.target = attributes.target || "";
  45371. this.use = attributes.use || "";
  45372. this.usehref = attributes.usehref || "";
  45373. this.filter = null;
  45374. this.manifest = null;
  45375. }
  45376. }
  45377. class Signature extends XFAObject {
  45378. constructor(attributes) {
  45379. super(TEMPLATE_NS_ID, "signature", true);
  45380. this.id = attributes.id || "";
  45381. this.type = getStringOption(attributes.type, ["PDF1.3", "PDF1.6"]);
  45382. this.use = attributes.use || "";
  45383. this.usehref = attributes.usehref || "";
  45384. this.border = null;
  45385. this.extras = null;
  45386. this.filter = null;
  45387. this.manifest = null;
  45388. this.margin = null;
  45389. }
  45390. }
  45391. class Signing extends XFAObject {
  45392. constructor(attributes) {
  45393. super(TEMPLATE_NS_ID, "signing", true);
  45394. this.id = attributes.id || "";
  45395. this.type = getStringOption(attributes.type, ["optional", "required"]);
  45396. this.use = attributes.use || "";
  45397. this.usehref = attributes.usehref || "";
  45398. this.certificate = new XFAObjectArray();
  45399. }
  45400. }
  45401. class Solid extends XFAObject {
  45402. constructor(attributes) {
  45403. super(TEMPLATE_NS_ID, "solid", true);
  45404. this.id = attributes.id || "";
  45405. this.use = attributes.use || "";
  45406. this.usehref = attributes.usehref || "";
  45407. this.extras = null;
  45408. }
  45409. [$toStyle](startColor) {
  45410. return startColor ? startColor[$toStyle]() : "#FFFFFF";
  45411. }
  45412. }
  45413. class Speak extends StringObject {
  45414. constructor(attributes) {
  45415. super(TEMPLATE_NS_ID, "speak");
  45416. this.disable = getInteger({
  45417. data: attributes.disable,
  45418. defaultValue: 0,
  45419. validate: x => x === 1
  45420. });
  45421. this.id = attributes.id || "";
  45422. this.priority = getStringOption(attributes.priority, ["custom", "caption", "name", "toolTip"]);
  45423. this.rid = attributes.rid || "";
  45424. this.use = attributes.use || "";
  45425. this.usehref = attributes.usehref || "";
  45426. }
  45427. }
  45428. class Stipple extends XFAObject {
  45429. constructor(attributes) {
  45430. super(TEMPLATE_NS_ID, "stipple", true);
  45431. this.id = attributes.id || "";
  45432. this.rate = getInteger({
  45433. data: attributes.rate,
  45434. defaultValue: 50,
  45435. validate: x => x >= 0 && x <= 100
  45436. });
  45437. this.use = attributes.use || "";
  45438. this.usehref = attributes.usehref || "";
  45439. this.color = null;
  45440. this.extras = null;
  45441. }
  45442. [$toStyle](bgColor) {
  45443. const alpha = this.rate / 100;
  45444. return Util.makeHexColor(Math.round(bgColor.value.r * (1 - alpha) + this.value.r * alpha), Math.round(bgColor.value.g * (1 - alpha) + this.value.g * alpha), Math.round(bgColor.value.b * (1 - alpha) + this.value.b * alpha));
  45445. }
  45446. }
  45447. class Subform extends XFAObject {
  45448. constructor(attributes) {
  45449. super(TEMPLATE_NS_ID, "subform", true);
  45450. this.access = getStringOption(attributes.access, ["open", "nonInteractive", "protected", "readOnly"]);
  45451. this.allowMacro = getInteger({
  45452. data: attributes.allowMacro,
  45453. defaultValue: 0,
  45454. validate: x => x === 1
  45455. });
  45456. this.anchorType = getStringOption(attributes.anchorType, ["topLeft", "bottomCenter", "bottomLeft", "bottomRight", "middleCenter", "middleLeft", "middleRight", "topCenter", "topRight"]);
  45457. this.colSpan = getInteger({
  45458. data: attributes.colSpan,
  45459. defaultValue: 1,
  45460. validate: n => n >= 1 || n === -1
  45461. });
  45462. this.columnWidths = (attributes.columnWidths || "").trim().split(/\s+/).map(x => x === "-1" ? -1 : getMeasurement(x));
  45463. this.h = attributes.h ? getMeasurement(attributes.h) : "";
  45464. this.hAlign = getStringOption(attributes.hAlign, ["left", "center", "justify", "justifyAll", "radix", "right"]);
  45465. this.id = attributes.id || "";
  45466. this.layout = getStringOption(attributes.layout, ["position", "lr-tb", "rl-row", "rl-tb", "row", "table", "tb"]);
  45467. this.locale = attributes.locale || "";
  45468. this.maxH = getMeasurement(attributes.maxH, "0pt");
  45469. this.maxW = getMeasurement(attributes.maxW, "0pt");
  45470. this.mergeMode = getStringOption(attributes.mergeMode, ["consumeData", "matchTemplate"]);
  45471. this.minH = getMeasurement(attributes.minH, "0pt");
  45472. this.minW = getMeasurement(attributes.minW, "0pt");
  45473. this.name = attributes.name || "";
  45474. this.presence = getStringOption(attributes.presence, ["visible", "hidden", "inactive", "invisible"]);
  45475. this.relevant = getRelevant(attributes.relevant);
  45476. this.restoreState = getStringOption(attributes.restoreState, ["manual", "auto"]);
  45477. this.scope = getStringOption(attributes.scope, ["name", "none"]);
  45478. this.use = attributes.use || "";
  45479. this.usehref = attributes.usehref || "";
  45480. this.w = attributes.w ? getMeasurement(attributes.w) : "";
  45481. this.x = getMeasurement(attributes.x, "0pt");
  45482. this.y = getMeasurement(attributes.y, "0pt");
  45483. this.assist = null;
  45484. this.bind = null;
  45485. this.bookend = null;
  45486. this.border = null;
  45487. this.break = null;
  45488. this.calculate = null;
  45489. this.desc = null;
  45490. this.extras = null;
  45491. this.keep = null;
  45492. this.margin = null;
  45493. this.occur = null;
  45494. this.overflow = null;
  45495. this.pageSet = null;
  45496. this.para = null;
  45497. this.traversal = null;
  45498. this.validate = null;
  45499. this.variables = null;
  45500. this.area = new XFAObjectArray();
  45501. this.breakAfter = new XFAObjectArray();
  45502. this.breakBefore = new XFAObjectArray();
  45503. this.connect = new XFAObjectArray();
  45504. this.draw = new XFAObjectArray();
  45505. this.event = new XFAObjectArray();
  45506. this.exObject = new XFAObjectArray();
  45507. this.exclGroup = new XFAObjectArray();
  45508. this.field = new XFAObjectArray();
  45509. this.proto = new XFAObjectArray();
  45510. this.setProperty = new XFAObjectArray();
  45511. this.subform = new XFAObjectArray();
  45512. this.subformSet = new XFAObjectArray();
  45513. }
  45514. [$getSubformParent]() {
  45515. const parent = this[$getParent]();
  45516. if (parent instanceof SubformSet) {
  45517. return parent[$getSubformParent]();
  45518. }
  45519. return parent;
  45520. }
  45521. [$isBindable]() {
  45522. return true;
  45523. }
  45524. [$isThereMoreWidth]() {
  45525. return this.layout.endsWith("-tb") && this[$extra].attempt === 0 && this[$extra].numberInLine > 0 || this[$getParent]()[$isThereMoreWidth]();
  45526. }
  45527. *[$getContainedChildren]() {
  45528. yield* getContainedChildren(this);
  45529. }
  45530. [$flushHTML]() {
  45531. return flushHTML(this);
  45532. }
  45533. [$addHTML](html, bbox) {
  45534. addHTML(this, html, bbox);
  45535. }
  45536. [$getAvailableSpace]() {
  45537. return getAvailableSpace(this);
  45538. }
  45539. [$isSplittable]() {
  45540. const parent = this[$getSubformParent]();
  45541. if (!parent[$isSplittable]()) {
  45542. return false;
  45543. }
  45544. if (this[$extra]._isSplittable !== undefined) {
  45545. return this[$extra]._isSplittable;
  45546. }
  45547. if (this.layout === "position" || this.layout.includes("row")) {
  45548. this[$extra]._isSplittable = false;
  45549. return false;
  45550. }
  45551. if (this.keep && this.keep.intact !== "none") {
  45552. this[$extra]._isSplittable = false;
  45553. return false;
  45554. }
  45555. if (parent.layout?.endsWith("-tb") && parent[$extra].numberInLine !== 0) {
  45556. return false;
  45557. }
  45558. this[$extra]._isSplittable = true;
  45559. return true;
  45560. }
  45561. [$toHTML](availableSpace) {
  45562. setTabIndex(this);
  45563. if (this.break) {
  45564. if (this.break.after !== "auto" || this.break.afterTarget !== "") {
  45565. const node = new BreakAfter({
  45566. targetType: this.break.after,
  45567. target: this.break.afterTarget,
  45568. startNew: this.break.startNew.toString()
  45569. });
  45570. node[$globalData] = this[$globalData];
  45571. this[$appendChild](node);
  45572. this.breakAfter.push(node);
  45573. }
  45574. if (this.break.before !== "auto" || this.break.beforeTarget !== "") {
  45575. const node = new BreakBefore({
  45576. targetType: this.break.before,
  45577. target: this.break.beforeTarget,
  45578. startNew: this.break.startNew.toString()
  45579. });
  45580. node[$globalData] = this[$globalData];
  45581. this[$appendChild](node);
  45582. this.breakBefore.push(node);
  45583. }
  45584. if (this.break.overflowTarget !== "") {
  45585. const node = new Overflow({
  45586. target: this.break.overflowTarget,
  45587. leader: this.break.overflowLeader,
  45588. trailer: this.break.overflowTrailer
  45589. });
  45590. node[$globalData] = this[$globalData];
  45591. this[$appendChild](node);
  45592. this.overflow.push(node);
  45593. }
  45594. this[$removeChild](this.break);
  45595. this.break = null;
  45596. }
  45597. if (this.presence === "hidden" || this.presence === "inactive") {
  45598. return HTMLResult.EMPTY;
  45599. }
  45600. if (this.breakBefore.children.length > 1 || this.breakAfter.children.length > 1) {
  45601. warn("XFA - Several breakBefore or breakAfter in subforms: please file a bug.");
  45602. }
  45603. if (this.breakBefore.children.length >= 1) {
  45604. const breakBefore = this.breakBefore.children[0];
  45605. if (handleBreak(breakBefore)) {
  45606. return HTMLResult.breakNode(breakBefore);
  45607. }
  45608. }
  45609. if (this[$extra]?.afterBreakAfter) {
  45610. return HTMLResult.EMPTY;
  45611. }
  45612. fixDimensions(this);
  45613. const children = [];
  45614. const attributes = {
  45615. id: this[$uid],
  45616. class: []
  45617. };
  45618. setAccess(this, attributes.class);
  45619. if (!this[$extra]) {
  45620. this[$extra] = Object.create(null);
  45621. }
  45622. Object.assign(this[$extra], {
  45623. children,
  45624. line: null,
  45625. attributes,
  45626. attempt: 0,
  45627. numberInLine: 0,
  45628. availableSpace: {
  45629. width: Math.min(this.w || Infinity, availableSpace.width),
  45630. height: Math.min(this.h || Infinity, availableSpace.height)
  45631. },
  45632. width: 0,
  45633. height: 0,
  45634. prevHeight: 0,
  45635. currentWidth: 0
  45636. });
  45637. const root = this[$getTemplateRoot]();
  45638. const savedNoLayoutFailure = root[$extra].noLayoutFailure;
  45639. const isSplittable = this[$isSplittable]();
  45640. if (!isSplittable) {
  45641. setFirstUnsplittable(this);
  45642. }
  45643. if (!checkDimensions(this, availableSpace)) {
  45644. return HTMLResult.FAILURE;
  45645. }
  45646. const filter = new Set(["area", "draw", "exclGroup", "field", "subform", "subformSet"]);
  45647. if (this.layout.includes("row")) {
  45648. const columnWidths = this[$getSubformParent]().columnWidths;
  45649. if (Array.isArray(columnWidths) && columnWidths.length > 0) {
  45650. this[$extra].columnWidths = columnWidths;
  45651. this[$extra].currentColumn = 0;
  45652. }
  45653. }
  45654. const style = toStyle(this, "anchorType", "dimensions", "position", "presence", "border", "margin", "hAlign");
  45655. const classNames = ["xfaSubform"];
  45656. const cl = layoutClass(this);
  45657. if (cl) {
  45658. classNames.push(cl);
  45659. }
  45660. attributes.style = style;
  45661. attributes.class = classNames;
  45662. if (this.name) {
  45663. attributes.xfaName = this.name;
  45664. }
  45665. if (this.overflow) {
  45666. const overflowExtra = this.overflow[$getExtra]();
  45667. if (overflowExtra.addLeader) {
  45668. overflowExtra.addLeader = false;
  45669. handleOverflow(this, overflowExtra.leader, availableSpace);
  45670. }
  45671. }
  45672. this[$pushPara]();
  45673. const isLrTb = this.layout === "lr-tb" || this.layout === "rl-tb";
  45674. const maxRun = isLrTb ? MAX_ATTEMPTS_FOR_LRTB_LAYOUT : 1;
  45675. for (; this[$extra].attempt < maxRun; this[$extra].attempt++) {
  45676. if (isLrTb && this[$extra].attempt === MAX_ATTEMPTS_FOR_LRTB_LAYOUT - 1) {
  45677. this[$extra].numberInLine = 0;
  45678. }
  45679. const result = this[$childrenToHTML]({
  45680. filter,
  45681. include: true
  45682. });
  45683. if (result.success) {
  45684. break;
  45685. }
  45686. if (result.isBreak()) {
  45687. this[$popPara]();
  45688. return result;
  45689. }
  45690. if (isLrTb && this[$extra].attempt === 0 && this[$extra].numberInLine === 0 && !root[$extra].noLayoutFailure) {
  45691. this[$extra].attempt = maxRun;
  45692. break;
  45693. }
  45694. }
  45695. this[$popPara]();
  45696. if (!isSplittable) {
  45697. unsetFirstUnsplittable(this);
  45698. }
  45699. root[$extra].noLayoutFailure = savedNoLayoutFailure;
  45700. if (this[$extra].attempt === maxRun) {
  45701. if (this.overflow) {
  45702. this[$getTemplateRoot]()[$extra].overflowNode = this.overflow;
  45703. }
  45704. if (!isSplittable) {
  45705. delete this[$extra];
  45706. }
  45707. return HTMLResult.FAILURE;
  45708. }
  45709. if (this.overflow) {
  45710. const overflowExtra = this.overflow[$getExtra]();
  45711. if (overflowExtra.addTrailer) {
  45712. overflowExtra.addTrailer = false;
  45713. handleOverflow(this, overflowExtra.trailer, availableSpace);
  45714. }
  45715. }
  45716. let marginH = 0;
  45717. let marginV = 0;
  45718. if (this.margin) {
  45719. marginH = this.margin.leftInset + this.margin.rightInset;
  45720. marginV = this.margin.topInset + this.margin.bottomInset;
  45721. }
  45722. const width = Math.max(this[$extra].width + marginH, this.w || 0);
  45723. const height = Math.max(this[$extra].height + marginV, this.h || 0);
  45724. const bbox = [this.x, this.y, width, height];
  45725. if (this.w === "") {
  45726. style.width = measureToString(width);
  45727. }
  45728. if (this.h === "") {
  45729. style.height = measureToString(height);
  45730. }
  45731. if ((style.width === "0px" || style.height === "0px") && children.length === 0) {
  45732. return HTMLResult.EMPTY;
  45733. }
  45734. const html = {
  45735. name: "div",
  45736. attributes,
  45737. children
  45738. };
  45739. applyAssist(this, attributes);
  45740. const result = HTMLResult.success(createWrapper(this, html), bbox);
  45741. if (this.breakAfter.children.length >= 1) {
  45742. const breakAfter = this.breakAfter.children[0];
  45743. if (handleBreak(breakAfter)) {
  45744. this[$extra].afterBreakAfter = result;
  45745. return HTMLResult.breakNode(breakAfter);
  45746. }
  45747. }
  45748. delete this[$extra];
  45749. return result;
  45750. }
  45751. }
  45752. class SubformSet extends XFAObject {
  45753. constructor(attributes) {
  45754. super(TEMPLATE_NS_ID, "subformSet", true);
  45755. this.id = attributes.id || "";
  45756. this.name = attributes.name || "";
  45757. this.relation = getStringOption(attributes.relation, ["ordered", "choice", "unordered"]);
  45758. this.relevant = getRelevant(attributes.relevant);
  45759. this.use = attributes.use || "";
  45760. this.usehref = attributes.usehref || "";
  45761. this.bookend = null;
  45762. this.break = null;
  45763. this.desc = null;
  45764. this.extras = null;
  45765. this.occur = null;
  45766. this.overflow = null;
  45767. this.breakAfter = new XFAObjectArray();
  45768. this.breakBefore = new XFAObjectArray();
  45769. this.subform = new XFAObjectArray();
  45770. this.subformSet = new XFAObjectArray();
  45771. }
  45772. *[$getContainedChildren]() {
  45773. yield* getContainedChildren(this);
  45774. }
  45775. [$getSubformParent]() {
  45776. let parent = this[$getParent]();
  45777. while (!(parent instanceof Subform)) {
  45778. parent = parent[$getParent]();
  45779. }
  45780. return parent;
  45781. }
  45782. [$isBindable]() {
  45783. return true;
  45784. }
  45785. }
  45786. class SubjectDN extends ContentObject {
  45787. constructor(attributes) {
  45788. super(TEMPLATE_NS_ID, "subjectDN");
  45789. this.delimiter = attributes.delimiter || ",";
  45790. this.id = attributes.id || "";
  45791. this.name = attributes.name || "";
  45792. this.use = attributes.use || "";
  45793. this.usehref = attributes.usehref || "";
  45794. }
  45795. [$finalize]() {
  45796. this[$content] = new Map(this[$content].split(this.delimiter).map(kv => {
  45797. kv = kv.split("=", 2);
  45798. kv[0] = kv[0].trim();
  45799. return kv;
  45800. }));
  45801. }
  45802. }
  45803. class SubjectDNs extends XFAObject {
  45804. constructor(attributes) {
  45805. super(TEMPLATE_NS_ID, "subjectDNs", true);
  45806. this.id = attributes.id || "";
  45807. this.type = getStringOption(attributes.type, ["optional", "required"]);
  45808. this.use = attributes.use || "";
  45809. this.usehref = attributes.usehref || "";
  45810. this.subjectDN = new XFAObjectArray();
  45811. }
  45812. }
  45813. class Submit extends XFAObject {
  45814. constructor(attributes) {
  45815. super(TEMPLATE_NS_ID, "submit", true);
  45816. this.embedPDF = getInteger({
  45817. data: attributes.embedPDF,
  45818. defaultValue: 0,
  45819. validate: x => x === 1
  45820. });
  45821. this.format = getStringOption(attributes.format, ["xdp", "formdata", "pdf", "urlencoded", "xfd", "xml"]);
  45822. this.id = attributes.id || "";
  45823. this.target = attributes.target || "";
  45824. this.textEncoding = getKeyword({
  45825. data: attributes.textEncoding ? attributes.textEncoding.toLowerCase() : "",
  45826. defaultValue: "",
  45827. validate: k => ["utf-8", "big-five", "fontspecific", "gbk", "gb-18030", "gb-2312", "ksc-5601", "none", "shift-jis", "ucs-2", "utf-16"].includes(k) || k.match(/iso-8859-\d{2}/)
  45828. });
  45829. this.use = attributes.use || "";
  45830. this.usehref = attributes.usehref || "";
  45831. this.xdpContent = attributes.xdpContent || "";
  45832. this.encrypt = null;
  45833. this.encryptData = new XFAObjectArray();
  45834. this.signData = new XFAObjectArray();
  45835. }
  45836. }
  45837. class Template extends XFAObject {
  45838. constructor(attributes) {
  45839. super(TEMPLATE_NS_ID, "template", true);
  45840. this.baseProfile = getStringOption(attributes.baseProfile, ["full", "interactiveForms"]);
  45841. this.extras = null;
  45842. this.subform = new XFAObjectArray();
  45843. }
  45844. [$finalize]() {
  45845. if (this.subform.children.length === 0) {
  45846. warn("XFA - No subforms in template node.");
  45847. }
  45848. if (this.subform.children.length >= 2) {
  45849. warn("XFA - Several subforms in template node: please file a bug.");
  45850. }
  45851. this[$tabIndex] = DEFAULT_TAB_INDEX;
  45852. }
  45853. [$isSplittable]() {
  45854. return true;
  45855. }
  45856. [$searchNode](expr, container) {
  45857. if (expr.startsWith("#")) {
  45858. return [this[$ids].get(expr.slice(1))];
  45859. }
  45860. return searchNode(this, container, expr, true, true);
  45861. }
  45862. *[$toPages]() {
  45863. if (!this.subform.children.length) {
  45864. return HTMLResult.success({
  45865. name: "div",
  45866. children: []
  45867. });
  45868. }
  45869. this[$extra] = {
  45870. overflowNode: null,
  45871. firstUnsplittable: null,
  45872. currentContentArea: null,
  45873. currentPageArea: null,
  45874. noLayoutFailure: false,
  45875. pageNumber: 1,
  45876. pagePosition: "first",
  45877. oddOrEven: "odd",
  45878. blankOrNotBlank: "nonBlank",
  45879. paraStack: []
  45880. };
  45881. const root = this.subform.children[0];
  45882. root.pageSet[$cleanPage]();
  45883. const pageAreas = root.pageSet.pageArea.children;
  45884. const mainHtml = {
  45885. name: "div",
  45886. children: []
  45887. };
  45888. let pageArea = null;
  45889. let breakBefore = null;
  45890. let breakBeforeTarget = null;
  45891. if (root.breakBefore.children.length >= 1) {
  45892. breakBefore = root.breakBefore.children[0];
  45893. breakBeforeTarget = breakBefore.target;
  45894. } else if (root.subform.children.length >= 1 && root.subform.children[0].breakBefore.children.length >= 1) {
  45895. breakBefore = root.subform.children[0].breakBefore.children[0];
  45896. breakBeforeTarget = breakBefore.target;
  45897. } else if (root.break?.beforeTarget) {
  45898. breakBefore = root.break;
  45899. breakBeforeTarget = breakBefore.beforeTarget;
  45900. } else if (root.subform.children.length >= 1 && root.subform.children[0].break?.beforeTarget) {
  45901. breakBefore = root.subform.children[0].break;
  45902. breakBeforeTarget = breakBefore.beforeTarget;
  45903. }
  45904. if (breakBefore) {
  45905. const target = this[$searchNode](breakBeforeTarget, breakBefore[$getParent]());
  45906. if (target instanceof PageArea) {
  45907. pageArea = target;
  45908. breakBefore[$extra] = {};
  45909. }
  45910. }
  45911. if (!pageArea) {
  45912. pageArea = pageAreas[0];
  45913. }
  45914. pageArea[$extra] = {
  45915. numberOfUse: 1
  45916. };
  45917. const pageAreaParent = pageArea[$getParent]();
  45918. pageAreaParent[$extra] = {
  45919. numberOfUse: 1,
  45920. pageIndex: pageAreaParent.pageArea.children.indexOf(pageArea),
  45921. pageSetIndex: 0
  45922. };
  45923. let targetPageArea;
  45924. let leader = null;
  45925. let trailer = null;
  45926. let hasSomething = true;
  45927. let hasSomethingCounter = 0;
  45928. let startIndex = 0;
  45929. while (true) {
  45930. if (!hasSomething) {
  45931. mainHtml.children.pop();
  45932. if (++hasSomethingCounter === MAX_EMPTY_PAGES) {
  45933. warn("XFA - Something goes wrong: please file a bug.");
  45934. return mainHtml;
  45935. }
  45936. } else {
  45937. hasSomethingCounter = 0;
  45938. }
  45939. targetPageArea = null;
  45940. this[$extra].currentPageArea = pageArea;
  45941. const page = pageArea[$toHTML]().html;
  45942. mainHtml.children.push(page);
  45943. if (leader) {
  45944. this[$extra].noLayoutFailure = true;
  45945. page.children.push(leader[$toHTML](pageArea[$extra].space).html);
  45946. leader = null;
  45947. }
  45948. if (trailer) {
  45949. this[$extra].noLayoutFailure = true;
  45950. page.children.push(trailer[$toHTML](pageArea[$extra].space).html);
  45951. trailer = null;
  45952. }
  45953. const contentAreas = pageArea.contentArea.children;
  45954. const htmlContentAreas = page.children.filter(node => node.attributes.class.includes("xfaContentarea"));
  45955. hasSomething = false;
  45956. this[$extra].firstUnsplittable = null;
  45957. this[$extra].noLayoutFailure = false;
  45958. const flush = index => {
  45959. const html = root[$flushHTML]();
  45960. if (html) {
  45961. hasSomething ||= html.children?.length > 0;
  45962. htmlContentAreas[index].children.push(html);
  45963. }
  45964. };
  45965. for (let i = startIndex, ii = contentAreas.length; i < ii; i++) {
  45966. const contentArea = this[$extra].currentContentArea = contentAreas[i];
  45967. const space = {
  45968. width: contentArea.w,
  45969. height: contentArea.h
  45970. };
  45971. startIndex = 0;
  45972. if (leader) {
  45973. htmlContentAreas[i].children.push(leader[$toHTML](space).html);
  45974. leader = null;
  45975. }
  45976. if (trailer) {
  45977. htmlContentAreas[i].children.push(trailer[$toHTML](space).html);
  45978. trailer = null;
  45979. }
  45980. const html = root[$toHTML](space);
  45981. if (html.success) {
  45982. if (html.html) {
  45983. hasSomething ||= html.html.children?.length > 0;
  45984. htmlContentAreas[i].children.push(html.html);
  45985. } else if (!hasSomething && mainHtml.children.length > 1) {
  45986. mainHtml.children.pop();
  45987. }
  45988. return mainHtml;
  45989. }
  45990. if (html.isBreak()) {
  45991. const node = html.breakNode;
  45992. flush(i);
  45993. if (node.targetType === "auto") {
  45994. continue;
  45995. }
  45996. if (node.leader) {
  45997. leader = this[$searchNode](node.leader, node[$getParent]());
  45998. leader = leader ? leader[0] : null;
  45999. }
  46000. if (node.trailer) {
  46001. trailer = this[$searchNode](node.trailer, node[$getParent]());
  46002. trailer = trailer ? trailer[0] : null;
  46003. }
  46004. if (node.targetType === "pageArea") {
  46005. targetPageArea = node[$extra].target;
  46006. i = Infinity;
  46007. } else if (!node[$extra].target) {
  46008. i = node[$extra].index;
  46009. } else {
  46010. targetPageArea = node[$extra].target;
  46011. startIndex = node[$extra].index + 1;
  46012. i = Infinity;
  46013. }
  46014. continue;
  46015. }
  46016. if (this[$extra].overflowNode) {
  46017. const node = this[$extra].overflowNode;
  46018. this[$extra].overflowNode = null;
  46019. const overflowExtra = node[$getExtra]();
  46020. const target = overflowExtra.target;
  46021. overflowExtra.addLeader = overflowExtra.leader !== null;
  46022. overflowExtra.addTrailer = overflowExtra.trailer !== null;
  46023. flush(i);
  46024. const currentIndex = i;
  46025. i = Infinity;
  46026. if (target instanceof PageArea) {
  46027. targetPageArea = target;
  46028. } else if (target instanceof ContentArea) {
  46029. const index = contentAreas.indexOf(target);
  46030. if (index !== -1) {
  46031. if (index > currentIndex) {
  46032. i = index - 1;
  46033. } else {
  46034. startIndex = index;
  46035. }
  46036. } else {
  46037. targetPageArea = target[$getParent]();
  46038. startIndex = targetPageArea.contentArea.children.indexOf(target);
  46039. }
  46040. }
  46041. continue;
  46042. }
  46043. flush(i);
  46044. }
  46045. this[$extra].pageNumber += 1;
  46046. if (targetPageArea) {
  46047. if (targetPageArea[$isUsable]()) {
  46048. targetPageArea[$extra].numberOfUse += 1;
  46049. } else {
  46050. targetPageArea = null;
  46051. }
  46052. }
  46053. pageArea = targetPageArea || pageArea[$getNextPage]();
  46054. yield null;
  46055. }
  46056. }
  46057. }
  46058. class Text extends ContentObject {
  46059. constructor(attributes) {
  46060. super(TEMPLATE_NS_ID, "text");
  46061. this.id = attributes.id || "";
  46062. this.maxChars = getInteger({
  46063. data: attributes.maxChars,
  46064. defaultValue: 0,
  46065. validate: x => x >= 0
  46066. });
  46067. this.name = attributes.name || "";
  46068. this.rid = attributes.rid || "";
  46069. this.use = attributes.use || "";
  46070. this.usehref = attributes.usehref || "";
  46071. }
  46072. [$acceptWhitespace]() {
  46073. return true;
  46074. }
  46075. [$onChild](child) {
  46076. if (child[$namespaceId] === NamespaceIds.xhtml.id) {
  46077. this[$content] = child;
  46078. return true;
  46079. }
  46080. warn(`XFA - Invalid content in Text: ${child[$nodeName]}.`);
  46081. return false;
  46082. }
  46083. [$onText](str) {
  46084. if (this[$content] instanceof XFAObject) {
  46085. return;
  46086. }
  46087. super[$onText](str);
  46088. }
  46089. [$finalize]() {
  46090. if (typeof this[$content] === "string") {
  46091. this[$content] = this[$content].replaceAll("\r\n", "\n");
  46092. }
  46093. }
  46094. [$getExtra]() {
  46095. if (typeof this[$content] === "string") {
  46096. return this[$content].split(/[\u2029\u2028\n]/).reduce((acc, line) => {
  46097. if (line) {
  46098. acc.push(line);
  46099. }
  46100. return acc;
  46101. }, []).join("\n");
  46102. }
  46103. return this[$content][$text]();
  46104. }
  46105. [$toHTML](availableSpace) {
  46106. if (typeof this[$content] === "string") {
  46107. const html = valueToHtml(this[$content]).html;
  46108. if (this[$content].includes("\u2029")) {
  46109. html.name = "div";
  46110. html.children = [];
  46111. this[$content].split("\u2029").map(para => para.split(/[\u2028\n]/).reduce((acc, line) => {
  46112. acc.push({
  46113. name: "span",
  46114. value: line
  46115. }, {
  46116. name: "br"
  46117. });
  46118. return acc;
  46119. }, [])).forEach(lines => {
  46120. html.children.push({
  46121. name: "p",
  46122. children: lines
  46123. });
  46124. });
  46125. } else if (/[\u2028\n]/.test(this[$content])) {
  46126. html.name = "div";
  46127. html.children = [];
  46128. this[$content].split(/[\u2028\n]/).forEach(line => {
  46129. html.children.push({
  46130. name: "span",
  46131. value: line
  46132. }, {
  46133. name: "br"
  46134. });
  46135. });
  46136. }
  46137. return HTMLResult.success(html);
  46138. }
  46139. return this[$content][$toHTML](availableSpace);
  46140. }
  46141. }
  46142. class TextEdit extends XFAObject {
  46143. constructor(attributes) {
  46144. super(TEMPLATE_NS_ID, "textEdit", true);
  46145. this.allowRichText = getInteger({
  46146. data: attributes.allowRichText,
  46147. defaultValue: 0,
  46148. validate: x => x === 1
  46149. });
  46150. this.hScrollPolicy = getStringOption(attributes.hScrollPolicy, ["auto", "off", "on"]);
  46151. this.id = attributes.id || "";
  46152. this.multiLine = getInteger({
  46153. data: attributes.multiLine,
  46154. defaultValue: "",
  46155. validate: x => x === 0 || x === 1
  46156. });
  46157. this.use = attributes.use || "";
  46158. this.usehref = attributes.usehref || "";
  46159. this.vScrollPolicy = getStringOption(attributes.vScrollPolicy, ["auto", "off", "on"]);
  46160. this.border = null;
  46161. this.comb = null;
  46162. this.extras = null;
  46163. this.margin = null;
  46164. }
  46165. [$toHTML](availableSpace) {
  46166. const style = toStyle(this, "border", "font", "margin");
  46167. let html;
  46168. const field = this[$getParent]()[$getParent]();
  46169. if (this.multiLine === "") {
  46170. this.multiLine = field instanceof Draw ? 1 : 0;
  46171. }
  46172. if (this.multiLine === 1) {
  46173. html = {
  46174. name: "textarea",
  46175. attributes: {
  46176. dataId: field[$data]?.[$uid] || field[$uid],
  46177. fieldId: field[$uid],
  46178. class: ["xfaTextfield"],
  46179. style,
  46180. "aria-label": ariaLabel(field),
  46181. "aria-required": false
  46182. }
  46183. };
  46184. } else {
  46185. html = {
  46186. name: "input",
  46187. attributes: {
  46188. type: "text",
  46189. dataId: field[$data]?.[$uid] || field[$uid],
  46190. fieldId: field[$uid],
  46191. class: ["xfaTextfield"],
  46192. style,
  46193. "aria-label": ariaLabel(field),
  46194. "aria-required": false
  46195. }
  46196. };
  46197. }
  46198. if (isRequired(field)) {
  46199. html.attributes["aria-required"] = true;
  46200. html.attributes.required = true;
  46201. }
  46202. return HTMLResult.success({
  46203. name: "label",
  46204. attributes: {
  46205. class: ["xfaLabel"]
  46206. },
  46207. children: [html]
  46208. });
  46209. }
  46210. }
  46211. class Time extends StringObject {
  46212. constructor(attributes) {
  46213. super(TEMPLATE_NS_ID, "time");
  46214. this.id = attributes.id || "";
  46215. this.name = attributes.name || "";
  46216. this.use = attributes.use || "";
  46217. this.usehref = attributes.usehref || "";
  46218. }
  46219. [$finalize]() {
  46220. const date = this[$content].trim();
  46221. this[$content] = date ? new Date(date) : null;
  46222. }
  46223. [$toHTML](availableSpace) {
  46224. return valueToHtml(this[$content] ? this[$content].toString() : "");
  46225. }
  46226. }
  46227. class TimeStamp extends XFAObject {
  46228. constructor(attributes) {
  46229. super(TEMPLATE_NS_ID, "timeStamp");
  46230. this.id = attributes.id || "";
  46231. this.server = attributes.server || "";
  46232. this.type = getStringOption(attributes.type, ["optional", "required"]);
  46233. this.use = attributes.use || "";
  46234. this.usehref = attributes.usehref || "";
  46235. }
  46236. }
  46237. class ToolTip extends StringObject {
  46238. constructor(attributes) {
  46239. super(TEMPLATE_NS_ID, "toolTip");
  46240. this.id = attributes.id || "";
  46241. this.rid = attributes.rid || "";
  46242. this.use = attributes.use || "";
  46243. this.usehref = attributes.usehref || "";
  46244. }
  46245. }
  46246. class Traversal extends XFAObject {
  46247. constructor(attributes) {
  46248. super(TEMPLATE_NS_ID, "traversal", true);
  46249. this.id = attributes.id || "";
  46250. this.use = attributes.use || "";
  46251. this.usehref = attributes.usehref || "";
  46252. this.extras = null;
  46253. this.traverse = new XFAObjectArray();
  46254. }
  46255. }
  46256. class Traverse extends XFAObject {
  46257. constructor(attributes) {
  46258. super(TEMPLATE_NS_ID, "traverse", true);
  46259. this.id = attributes.id || "";
  46260. this.operation = getStringOption(attributes.operation, ["next", "back", "down", "first", "left", "right", "up"]);
  46261. this.ref = attributes.ref || "";
  46262. this.use = attributes.use || "";
  46263. this.usehref = attributes.usehref || "";
  46264. this.extras = null;
  46265. this.script = null;
  46266. }
  46267. get name() {
  46268. return this.operation;
  46269. }
  46270. [$isTransparent]() {
  46271. return false;
  46272. }
  46273. }
  46274. class Ui extends XFAObject {
  46275. constructor(attributes) {
  46276. super(TEMPLATE_NS_ID, "ui", true);
  46277. this.id = attributes.id || "";
  46278. this.use = attributes.use || "";
  46279. this.usehref = attributes.usehref || "";
  46280. this.extras = null;
  46281. this.picture = null;
  46282. this.barcode = null;
  46283. this.button = null;
  46284. this.checkButton = null;
  46285. this.choiceList = null;
  46286. this.dateTimeEdit = null;
  46287. this.defaultUi = null;
  46288. this.imageEdit = null;
  46289. this.numericEdit = null;
  46290. this.passwordEdit = null;
  46291. this.signature = null;
  46292. this.textEdit = null;
  46293. }
  46294. [$getExtra]() {
  46295. if (this[$extra] === undefined) {
  46296. for (const name of Object.getOwnPropertyNames(this)) {
  46297. if (name === "extras" || name === "picture") {
  46298. continue;
  46299. }
  46300. const obj = this[name];
  46301. if (!(obj instanceof XFAObject)) {
  46302. continue;
  46303. }
  46304. this[$extra] = obj;
  46305. return obj;
  46306. }
  46307. this[$extra] = null;
  46308. }
  46309. return this[$extra];
  46310. }
  46311. [$toHTML](availableSpace) {
  46312. const obj = this[$getExtra]();
  46313. if (obj) {
  46314. return obj[$toHTML](availableSpace);
  46315. }
  46316. return HTMLResult.EMPTY;
  46317. }
  46318. }
  46319. class Validate extends XFAObject {
  46320. constructor(attributes) {
  46321. super(TEMPLATE_NS_ID, "validate", true);
  46322. this.formatTest = getStringOption(attributes.formatTest, ["warning", "disabled", "error"]);
  46323. this.id = attributes.id || "";
  46324. this.nullTest = getStringOption(attributes.nullTest, ["disabled", "error", "warning"]);
  46325. this.scriptTest = getStringOption(attributes.scriptTest, ["error", "disabled", "warning"]);
  46326. this.use = attributes.use || "";
  46327. this.usehref = attributes.usehref || "";
  46328. this.extras = null;
  46329. this.message = null;
  46330. this.picture = null;
  46331. this.script = null;
  46332. }
  46333. }
  46334. class Value extends XFAObject {
  46335. constructor(attributes) {
  46336. super(TEMPLATE_NS_ID, "value", true);
  46337. this.id = attributes.id || "";
  46338. this.override = getInteger({
  46339. data: attributes.override,
  46340. defaultValue: 0,
  46341. validate: x => x === 1
  46342. });
  46343. this.relevant = getRelevant(attributes.relevant);
  46344. this.use = attributes.use || "";
  46345. this.usehref = attributes.usehref || "";
  46346. this.arc = null;
  46347. this.boolean = null;
  46348. this.date = null;
  46349. this.dateTime = null;
  46350. this.decimal = null;
  46351. this.exData = null;
  46352. this.float = null;
  46353. this.image = null;
  46354. this.integer = null;
  46355. this.line = null;
  46356. this.rectangle = null;
  46357. this.text = null;
  46358. this.time = null;
  46359. }
  46360. [$setValue](value) {
  46361. const parent = this[$getParent]();
  46362. if (parent instanceof Field) {
  46363. if (parent.ui?.imageEdit) {
  46364. if (!this.image) {
  46365. this.image = new Image({});
  46366. this[$appendChild](this.image);
  46367. }
  46368. this.image[$content] = value[$content];
  46369. return;
  46370. }
  46371. }
  46372. const valueName = value[$nodeName];
  46373. if (this[valueName] !== null) {
  46374. this[valueName][$content] = value[$content];
  46375. return;
  46376. }
  46377. for (const name of Object.getOwnPropertyNames(this)) {
  46378. const obj = this[name];
  46379. if (obj instanceof XFAObject) {
  46380. this[name] = null;
  46381. this[$removeChild](obj);
  46382. }
  46383. }
  46384. this[value[$nodeName]] = value;
  46385. this[$appendChild](value);
  46386. }
  46387. [$text]() {
  46388. if (this.exData) {
  46389. if (typeof this.exData[$content] === "string") {
  46390. return this.exData[$content].trim();
  46391. }
  46392. return this.exData[$content][$text]().trim();
  46393. }
  46394. for (const name of Object.getOwnPropertyNames(this)) {
  46395. if (name === "image") {
  46396. continue;
  46397. }
  46398. const obj = this[name];
  46399. if (obj instanceof XFAObject) {
  46400. return (obj[$content] || "").toString().trim();
  46401. }
  46402. }
  46403. return null;
  46404. }
  46405. [$toHTML](availableSpace) {
  46406. for (const name of Object.getOwnPropertyNames(this)) {
  46407. const obj = this[name];
  46408. if (!(obj instanceof XFAObject)) {
  46409. continue;
  46410. }
  46411. return obj[$toHTML](availableSpace);
  46412. }
  46413. return HTMLResult.EMPTY;
  46414. }
  46415. }
  46416. class Variables extends XFAObject {
  46417. constructor(attributes) {
  46418. super(TEMPLATE_NS_ID, "variables", true);
  46419. this.id = attributes.id || "";
  46420. this.use = attributes.use || "";
  46421. this.usehref = attributes.usehref || "";
  46422. this.boolean = new XFAObjectArray();
  46423. this.date = new XFAObjectArray();
  46424. this.dateTime = new XFAObjectArray();
  46425. this.decimal = new XFAObjectArray();
  46426. this.exData = new XFAObjectArray();
  46427. this.float = new XFAObjectArray();
  46428. this.image = new XFAObjectArray();
  46429. this.integer = new XFAObjectArray();
  46430. this.manifest = new XFAObjectArray();
  46431. this.script = new XFAObjectArray();
  46432. this.text = new XFAObjectArray();
  46433. this.time = new XFAObjectArray();
  46434. }
  46435. [$isTransparent]() {
  46436. return true;
  46437. }
  46438. }
  46439. class TemplateNamespace {
  46440. static [$buildXFAObject](name, attributes) {
  46441. if (TemplateNamespace.hasOwnProperty(name)) {
  46442. const node = TemplateNamespace[name](attributes);
  46443. node[$setSetAttributes](attributes);
  46444. return node;
  46445. }
  46446. return undefined;
  46447. }
  46448. static appearanceFilter(attrs) {
  46449. return new AppearanceFilter(attrs);
  46450. }
  46451. static arc(attrs) {
  46452. return new Arc(attrs);
  46453. }
  46454. static area(attrs) {
  46455. return new Area(attrs);
  46456. }
  46457. static assist(attrs) {
  46458. return new Assist(attrs);
  46459. }
  46460. static barcode(attrs) {
  46461. return new Barcode(attrs);
  46462. }
  46463. static bind(attrs) {
  46464. return new Bind(attrs);
  46465. }
  46466. static bindItems(attrs) {
  46467. return new BindItems(attrs);
  46468. }
  46469. static bookend(attrs) {
  46470. return new Bookend(attrs);
  46471. }
  46472. static boolean(attrs) {
  46473. return new BooleanElement(attrs);
  46474. }
  46475. static border(attrs) {
  46476. return new Border(attrs);
  46477. }
  46478. static break(attrs) {
  46479. return new Break(attrs);
  46480. }
  46481. static breakAfter(attrs) {
  46482. return new BreakAfter(attrs);
  46483. }
  46484. static breakBefore(attrs) {
  46485. return new BreakBefore(attrs);
  46486. }
  46487. static button(attrs) {
  46488. return new Button(attrs);
  46489. }
  46490. static calculate(attrs) {
  46491. return new Calculate(attrs);
  46492. }
  46493. static caption(attrs) {
  46494. return new Caption(attrs);
  46495. }
  46496. static certificate(attrs) {
  46497. return new Certificate(attrs);
  46498. }
  46499. static certificates(attrs) {
  46500. return new Certificates(attrs);
  46501. }
  46502. static checkButton(attrs) {
  46503. return new CheckButton(attrs);
  46504. }
  46505. static choiceList(attrs) {
  46506. return new ChoiceList(attrs);
  46507. }
  46508. static color(attrs) {
  46509. return new Color(attrs);
  46510. }
  46511. static comb(attrs) {
  46512. return new Comb(attrs);
  46513. }
  46514. static connect(attrs) {
  46515. return new Connect(attrs);
  46516. }
  46517. static contentArea(attrs) {
  46518. return new ContentArea(attrs);
  46519. }
  46520. static corner(attrs) {
  46521. return new Corner(attrs);
  46522. }
  46523. static date(attrs) {
  46524. return new DateElement(attrs);
  46525. }
  46526. static dateTime(attrs) {
  46527. return new DateTime(attrs);
  46528. }
  46529. static dateTimeEdit(attrs) {
  46530. return new DateTimeEdit(attrs);
  46531. }
  46532. static decimal(attrs) {
  46533. return new Decimal(attrs);
  46534. }
  46535. static defaultUi(attrs) {
  46536. return new DefaultUi(attrs);
  46537. }
  46538. static desc(attrs) {
  46539. return new Desc(attrs);
  46540. }
  46541. static digestMethod(attrs) {
  46542. return new DigestMethod(attrs);
  46543. }
  46544. static digestMethods(attrs) {
  46545. return new DigestMethods(attrs);
  46546. }
  46547. static draw(attrs) {
  46548. return new Draw(attrs);
  46549. }
  46550. static edge(attrs) {
  46551. return new Edge(attrs);
  46552. }
  46553. static encoding(attrs) {
  46554. return new Encoding(attrs);
  46555. }
  46556. static encodings(attrs) {
  46557. return new Encodings(attrs);
  46558. }
  46559. static encrypt(attrs) {
  46560. return new Encrypt(attrs);
  46561. }
  46562. static encryptData(attrs) {
  46563. return new EncryptData(attrs);
  46564. }
  46565. static encryption(attrs) {
  46566. return new Encryption(attrs);
  46567. }
  46568. static encryptionMethod(attrs) {
  46569. return new EncryptionMethod(attrs);
  46570. }
  46571. static encryptionMethods(attrs) {
  46572. return new EncryptionMethods(attrs);
  46573. }
  46574. static event(attrs) {
  46575. return new Event(attrs);
  46576. }
  46577. static exData(attrs) {
  46578. return new ExData(attrs);
  46579. }
  46580. static exObject(attrs) {
  46581. return new ExObject(attrs);
  46582. }
  46583. static exclGroup(attrs) {
  46584. return new ExclGroup(attrs);
  46585. }
  46586. static execute(attrs) {
  46587. return new Execute(attrs);
  46588. }
  46589. static extras(attrs) {
  46590. return new Extras(attrs);
  46591. }
  46592. static field(attrs) {
  46593. return new Field(attrs);
  46594. }
  46595. static fill(attrs) {
  46596. return new Fill(attrs);
  46597. }
  46598. static filter(attrs) {
  46599. return new Filter(attrs);
  46600. }
  46601. static float(attrs) {
  46602. return new Float(attrs);
  46603. }
  46604. static font(attrs) {
  46605. return new template_Font(attrs);
  46606. }
  46607. static format(attrs) {
  46608. return new Format(attrs);
  46609. }
  46610. static handler(attrs) {
  46611. return new Handler(attrs);
  46612. }
  46613. static hyphenation(attrs) {
  46614. return new Hyphenation(attrs);
  46615. }
  46616. static image(attrs) {
  46617. return new Image(attrs);
  46618. }
  46619. static imageEdit(attrs) {
  46620. return new ImageEdit(attrs);
  46621. }
  46622. static integer(attrs) {
  46623. return new Integer(attrs);
  46624. }
  46625. static issuers(attrs) {
  46626. return new Issuers(attrs);
  46627. }
  46628. static items(attrs) {
  46629. return new Items(attrs);
  46630. }
  46631. static keep(attrs) {
  46632. return new Keep(attrs);
  46633. }
  46634. static keyUsage(attrs) {
  46635. return new KeyUsage(attrs);
  46636. }
  46637. static line(attrs) {
  46638. return new Line(attrs);
  46639. }
  46640. static linear(attrs) {
  46641. return new Linear(attrs);
  46642. }
  46643. static lockDocument(attrs) {
  46644. return new LockDocument(attrs);
  46645. }
  46646. static manifest(attrs) {
  46647. return new Manifest(attrs);
  46648. }
  46649. static margin(attrs) {
  46650. return new Margin(attrs);
  46651. }
  46652. static mdp(attrs) {
  46653. return new Mdp(attrs);
  46654. }
  46655. static medium(attrs) {
  46656. return new Medium(attrs);
  46657. }
  46658. static message(attrs) {
  46659. return new Message(attrs);
  46660. }
  46661. static numericEdit(attrs) {
  46662. return new NumericEdit(attrs);
  46663. }
  46664. static occur(attrs) {
  46665. return new Occur(attrs);
  46666. }
  46667. static oid(attrs) {
  46668. return new Oid(attrs);
  46669. }
  46670. static oids(attrs) {
  46671. return new Oids(attrs);
  46672. }
  46673. static overflow(attrs) {
  46674. return new Overflow(attrs);
  46675. }
  46676. static pageArea(attrs) {
  46677. return new PageArea(attrs);
  46678. }
  46679. static pageSet(attrs) {
  46680. return new PageSet(attrs);
  46681. }
  46682. static para(attrs) {
  46683. return new Para(attrs);
  46684. }
  46685. static passwordEdit(attrs) {
  46686. return new PasswordEdit(attrs);
  46687. }
  46688. static pattern(attrs) {
  46689. return new template_Pattern(attrs);
  46690. }
  46691. static picture(attrs) {
  46692. return new Picture(attrs);
  46693. }
  46694. static proto(attrs) {
  46695. return new Proto(attrs);
  46696. }
  46697. static radial(attrs) {
  46698. return new Radial(attrs);
  46699. }
  46700. static reason(attrs) {
  46701. return new Reason(attrs);
  46702. }
  46703. static reasons(attrs) {
  46704. return new Reasons(attrs);
  46705. }
  46706. static rectangle(attrs) {
  46707. return new Rectangle(attrs);
  46708. }
  46709. static ref(attrs) {
  46710. return new RefElement(attrs);
  46711. }
  46712. static script(attrs) {
  46713. return new Script(attrs);
  46714. }
  46715. static setProperty(attrs) {
  46716. return new SetProperty(attrs);
  46717. }
  46718. static signData(attrs) {
  46719. return new SignData(attrs);
  46720. }
  46721. static signature(attrs) {
  46722. return new Signature(attrs);
  46723. }
  46724. static signing(attrs) {
  46725. return new Signing(attrs);
  46726. }
  46727. static solid(attrs) {
  46728. return new Solid(attrs);
  46729. }
  46730. static speak(attrs) {
  46731. return new Speak(attrs);
  46732. }
  46733. static stipple(attrs) {
  46734. return new Stipple(attrs);
  46735. }
  46736. static subform(attrs) {
  46737. return new Subform(attrs);
  46738. }
  46739. static subformSet(attrs) {
  46740. return new SubformSet(attrs);
  46741. }
  46742. static subjectDN(attrs) {
  46743. return new SubjectDN(attrs);
  46744. }
  46745. static subjectDNs(attrs) {
  46746. return new SubjectDNs(attrs);
  46747. }
  46748. static submit(attrs) {
  46749. return new Submit(attrs);
  46750. }
  46751. static template(attrs) {
  46752. return new Template(attrs);
  46753. }
  46754. static text(attrs) {
  46755. return new Text(attrs);
  46756. }
  46757. static textEdit(attrs) {
  46758. return new TextEdit(attrs);
  46759. }
  46760. static time(attrs) {
  46761. return new Time(attrs);
  46762. }
  46763. static timeStamp(attrs) {
  46764. return new TimeStamp(attrs);
  46765. }
  46766. static toolTip(attrs) {
  46767. return new ToolTip(attrs);
  46768. }
  46769. static traversal(attrs) {
  46770. return new Traversal(attrs);
  46771. }
  46772. static traverse(attrs) {
  46773. return new Traverse(attrs);
  46774. }
  46775. static ui(attrs) {
  46776. return new Ui(attrs);
  46777. }
  46778. static validate(attrs) {
  46779. return new Validate(attrs);
  46780. }
  46781. static value(attrs) {
  46782. return new Value(attrs);
  46783. }
  46784. static variables(attrs) {
  46785. return new Variables(attrs);
  46786. }
  46787. }
  46788. ;// CONCATENATED MODULE: ./src/core/xfa/bind.js
  46789. const bind_NS_DATASETS = NamespaceIds.datasets.id;
  46790. function createText(content) {
  46791. const node = new Text({});
  46792. node[$content] = content;
  46793. return node;
  46794. }
  46795. class Binder {
  46796. constructor(root) {
  46797. this.root = root;
  46798. this.datasets = root.datasets;
  46799. this.data = root.datasets?.data || new XmlObject(NamespaceIds.datasets.id, "data");
  46800. this.emptyMerge = this.data[$getChildren]().length === 0;
  46801. this.root.form = this.form = root.template[$clone]();
  46802. }
  46803. _isConsumeData() {
  46804. return !this.emptyMerge && this._mergeMode;
  46805. }
  46806. _isMatchTemplate() {
  46807. return !this._isConsumeData();
  46808. }
  46809. bind() {
  46810. this._bindElement(this.form, this.data);
  46811. return this.form;
  46812. }
  46813. getData() {
  46814. return this.data;
  46815. }
  46816. _bindValue(formNode, data, picture) {
  46817. formNode[$data] = data;
  46818. if (formNode[$hasSettableValue]()) {
  46819. if (data[$isDataValue]()) {
  46820. const value = data[$getDataValue]();
  46821. formNode[$setValue](createText(value));
  46822. } else if (formNode instanceof Field && formNode.ui?.choiceList?.open === "multiSelect") {
  46823. const value = data[$getChildren]().map(child => child[$content].trim()).join("\n");
  46824. formNode[$setValue](createText(value));
  46825. } else if (this._isConsumeData()) {
  46826. warn(`XFA - Nodes haven't the same type.`);
  46827. }
  46828. } else if (!data[$isDataValue]() || this._isMatchTemplate()) {
  46829. this._bindElement(formNode, data);
  46830. } else {
  46831. warn(`XFA - Nodes haven't the same type.`);
  46832. }
  46833. }
  46834. _findDataByNameToConsume(name, isValue, dataNode, global) {
  46835. if (!name) {
  46836. return null;
  46837. }
  46838. let generator, match;
  46839. for (let i = 0; i < 3; i++) {
  46840. generator = dataNode[$getRealChildrenByNameIt](name, false, true);
  46841. while (true) {
  46842. match = generator.next().value;
  46843. if (!match) {
  46844. break;
  46845. }
  46846. if (isValue === match[$isDataValue]()) {
  46847. return match;
  46848. }
  46849. }
  46850. if (dataNode[$namespaceId] === NamespaceIds.datasets.id && dataNode[$nodeName] === "data") {
  46851. break;
  46852. }
  46853. dataNode = dataNode[$getParent]();
  46854. }
  46855. if (!global) {
  46856. return null;
  46857. }
  46858. generator = this.data[$getRealChildrenByNameIt](name, true, false);
  46859. match = generator.next().value;
  46860. if (match) {
  46861. return match;
  46862. }
  46863. generator = this.data[$getAttributeIt](name, true);
  46864. match = generator.next().value;
  46865. if (match?.[$isDataValue]()) {
  46866. return match;
  46867. }
  46868. return null;
  46869. }
  46870. _setProperties(formNode, dataNode) {
  46871. if (!formNode.hasOwnProperty("setProperty")) {
  46872. return;
  46873. }
  46874. for (const {
  46875. ref,
  46876. target,
  46877. connection
  46878. } of formNode.setProperty.children) {
  46879. if (connection) {
  46880. continue;
  46881. }
  46882. if (!ref) {
  46883. continue;
  46884. }
  46885. const nodes = searchNode(this.root, dataNode, ref, false, false);
  46886. if (!nodes) {
  46887. warn(`XFA - Invalid reference: ${ref}.`);
  46888. continue;
  46889. }
  46890. const [node] = nodes;
  46891. if (!node[$isDescendent](this.data)) {
  46892. warn(`XFA - Invalid node: must be a data node.`);
  46893. continue;
  46894. }
  46895. const targetNodes = searchNode(this.root, formNode, target, false, false);
  46896. if (!targetNodes) {
  46897. warn(`XFA - Invalid target: ${target}.`);
  46898. continue;
  46899. }
  46900. const [targetNode] = targetNodes;
  46901. if (!targetNode[$isDescendent](formNode)) {
  46902. warn(`XFA - Invalid target: must be a property or subproperty.`);
  46903. continue;
  46904. }
  46905. const targetParent = targetNode[$getParent]();
  46906. if (targetNode instanceof SetProperty || targetParent instanceof SetProperty) {
  46907. warn(`XFA - Invalid target: cannot be a setProperty or one of its properties.`);
  46908. continue;
  46909. }
  46910. if (targetNode instanceof BindItems || targetParent instanceof BindItems) {
  46911. warn(`XFA - Invalid target: cannot be a bindItems or one of its properties.`);
  46912. continue;
  46913. }
  46914. const content = node[$text]();
  46915. const name = targetNode[$nodeName];
  46916. if (targetNode instanceof XFAAttribute) {
  46917. const attrs = Object.create(null);
  46918. attrs[name] = content;
  46919. const obj = Reflect.construct(Object.getPrototypeOf(targetParent).constructor, [attrs]);
  46920. targetParent[name] = obj[name];
  46921. continue;
  46922. }
  46923. if (!targetNode.hasOwnProperty($content)) {
  46924. warn(`XFA - Invalid node to use in setProperty`);
  46925. continue;
  46926. }
  46927. targetNode[$data] = node;
  46928. targetNode[$content] = content;
  46929. targetNode[$finalize]();
  46930. }
  46931. }
  46932. _bindItems(formNode, dataNode) {
  46933. if (!formNode.hasOwnProperty("items") || !formNode.hasOwnProperty("bindItems") || formNode.bindItems.isEmpty()) {
  46934. return;
  46935. }
  46936. for (const item of formNode.items.children) {
  46937. formNode[$removeChild](item);
  46938. }
  46939. formNode.items.clear();
  46940. const labels = new Items({});
  46941. const values = new Items({});
  46942. formNode[$appendChild](labels);
  46943. formNode.items.push(labels);
  46944. formNode[$appendChild](values);
  46945. formNode.items.push(values);
  46946. for (const {
  46947. ref,
  46948. labelRef,
  46949. valueRef,
  46950. connection
  46951. } of formNode.bindItems.children) {
  46952. if (connection) {
  46953. continue;
  46954. }
  46955. if (!ref) {
  46956. continue;
  46957. }
  46958. const nodes = searchNode(this.root, dataNode, ref, false, false);
  46959. if (!nodes) {
  46960. warn(`XFA - Invalid reference: ${ref}.`);
  46961. continue;
  46962. }
  46963. for (const node of nodes) {
  46964. if (!node[$isDescendent](this.datasets)) {
  46965. warn(`XFA - Invalid ref (${ref}): must be a datasets child.`);
  46966. continue;
  46967. }
  46968. const labelNodes = searchNode(this.root, node, labelRef, true, false);
  46969. if (!labelNodes) {
  46970. warn(`XFA - Invalid label: ${labelRef}.`);
  46971. continue;
  46972. }
  46973. const [labelNode] = labelNodes;
  46974. if (!labelNode[$isDescendent](this.datasets)) {
  46975. warn(`XFA - Invalid label: must be a datasets child.`);
  46976. continue;
  46977. }
  46978. const valueNodes = searchNode(this.root, node, valueRef, true, false);
  46979. if (!valueNodes) {
  46980. warn(`XFA - Invalid value: ${valueRef}.`);
  46981. continue;
  46982. }
  46983. const [valueNode] = valueNodes;
  46984. if (!valueNode[$isDescendent](this.datasets)) {
  46985. warn(`XFA - Invalid value: must be a datasets child.`);
  46986. continue;
  46987. }
  46988. const label = createText(labelNode[$text]());
  46989. const value = createText(valueNode[$text]());
  46990. labels[$appendChild](label);
  46991. labels.text.push(label);
  46992. values[$appendChild](value);
  46993. values.text.push(value);
  46994. }
  46995. }
  46996. }
  46997. _bindOccurrences(formNode, matches, picture) {
  46998. let baseClone;
  46999. if (matches.length > 1) {
  47000. baseClone = formNode[$clone]();
  47001. baseClone[$removeChild](baseClone.occur);
  47002. baseClone.occur = null;
  47003. }
  47004. this._bindValue(formNode, matches[0], picture);
  47005. this._setProperties(formNode, matches[0]);
  47006. this._bindItems(formNode, matches[0]);
  47007. if (matches.length === 1) {
  47008. return;
  47009. }
  47010. const parent = formNode[$getParent]();
  47011. const name = formNode[$nodeName];
  47012. const pos = parent[$indexOf](formNode);
  47013. for (let i = 1, ii = matches.length; i < ii; i++) {
  47014. const match = matches[i];
  47015. const clone = baseClone[$clone]();
  47016. parent[name].push(clone);
  47017. parent[$insertAt](pos + i, clone);
  47018. this._bindValue(clone, match, picture);
  47019. this._setProperties(clone, match);
  47020. this._bindItems(clone, match);
  47021. }
  47022. }
  47023. _createOccurrences(formNode) {
  47024. if (!this.emptyMerge) {
  47025. return;
  47026. }
  47027. const {
  47028. occur
  47029. } = formNode;
  47030. if (!occur || occur.initial <= 1) {
  47031. return;
  47032. }
  47033. const parent = formNode[$getParent]();
  47034. const name = formNode[$nodeName];
  47035. if (!(parent[name] instanceof XFAObjectArray)) {
  47036. return;
  47037. }
  47038. let currentNumber;
  47039. if (formNode.name) {
  47040. currentNumber = parent[name].children.filter(e => e.name === formNode.name).length;
  47041. } else {
  47042. currentNumber = parent[name].children.length;
  47043. }
  47044. const pos = parent[$indexOf](formNode) + 1;
  47045. const ii = occur.initial - currentNumber;
  47046. if (ii) {
  47047. const nodeClone = formNode[$clone]();
  47048. nodeClone[$removeChild](nodeClone.occur);
  47049. nodeClone.occur = null;
  47050. parent[name].push(nodeClone);
  47051. parent[$insertAt](pos, nodeClone);
  47052. for (let i = 1; i < ii; i++) {
  47053. const clone = nodeClone[$clone]();
  47054. parent[name].push(clone);
  47055. parent[$insertAt](pos + i, clone);
  47056. }
  47057. }
  47058. }
  47059. _getOccurInfo(formNode) {
  47060. const {
  47061. name,
  47062. occur
  47063. } = formNode;
  47064. if (!occur || !name) {
  47065. return [1, 1];
  47066. }
  47067. const max = occur.max === -1 ? Infinity : occur.max;
  47068. return [occur.min, max];
  47069. }
  47070. _setAndBind(formNode, dataNode) {
  47071. this._setProperties(formNode, dataNode);
  47072. this._bindItems(formNode, dataNode);
  47073. this._bindElement(formNode, dataNode);
  47074. }
  47075. _bindElement(formNode, dataNode) {
  47076. const uselessNodes = [];
  47077. this._createOccurrences(formNode);
  47078. for (const child of formNode[$getChildren]()) {
  47079. if (child[$data]) {
  47080. continue;
  47081. }
  47082. if (this._mergeMode === undefined && child[$nodeName] === "subform") {
  47083. this._mergeMode = child.mergeMode === "consumeData";
  47084. const dataChildren = dataNode[$getChildren]();
  47085. if (dataChildren.length > 0) {
  47086. this._bindOccurrences(child, [dataChildren[0]], null);
  47087. } else if (this.emptyMerge) {
  47088. const nsId = dataNode[$namespaceId] === bind_NS_DATASETS ? -1 : dataNode[$namespaceId];
  47089. const dataChild = child[$data] = new XmlObject(nsId, child.name || "root");
  47090. dataNode[$appendChild](dataChild);
  47091. this._bindElement(child, dataChild);
  47092. }
  47093. continue;
  47094. }
  47095. if (!child[$isBindable]()) {
  47096. continue;
  47097. }
  47098. let global = false;
  47099. let picture = null;
  47100. let ref = null;
  47101. let match = null;
  47102. if (child.bind) {
  47103. switch (child.bind.match) {
  47104. case "none":
  47105. this._setAndBind(child, dataNode);
  47106. continue;
  47107. case "global":
  47108. global = true;
  47109. break;
  47110. case "dataRef":
  47111. if (!child.bind.ref) {
  47112. warn(`XFA - ref is empty in node ${child[$nodeName]}.`);
  47113. this._setAndBind(child, dataNode);
  47114. continue;
  47115. }
  47116. ref = child.bind.ref;
  47117. break;
  47118. default:
  47119. break;
  47120. }
  47121. if (child.bind.picture) {
  47122. picture = child.bind.picture[$content];
  47123. }
  47124. }
  47125. const [min, max] = this._getOccurInfo(child);
  47126. if (ref) {
  47127. match = searchNode(this.root, dataNode, ref, true, false);
  47128. if (match === null) {
  47129. match = createDataNode(this.data, dataNode, ref);
  47130. if (!match) {
  47131. continue;
  47132. }
  47133. if (this._isConsumeData()) {
  47134. match[$consumed] = true;
  47135. }
  47136. this._setAndBind(child, match);
  47137. continue;
  47138. } else {
  47139. if (this._isConsumeData()) {
  47140. match = match.filter(node => !node[$consumed]);
  47141. }
  47142. if (match.length > max) {
  47143. match = match.slice(0, max);
  47144. } else if (match.length === 0) {
  47145. match = null;
  47146. }
  47147. if (match && this._isConsumeData()) {
  47148. match.forEach(node => {
  47149. node[$consumed] = true;
  47150. });
  47151. }
  47152. }
  47153. } else {
  47154. if (!child.name) {
  47155. this._setAndBind(child, dataNode);
  47156. continue;
  47157. }
  47158. if (this._isConsumeData()) {
  47159. const matches = [];
  47160. while (matches.length < max) {
  47161. const found = this._findDataByNameToConsume(child.name, child[$hasSettableValue](), dataNode, global);
  47162. if (!found) {
  47163. break;
  47164. }
  47165. found[$consumed] = true;
  47166. matches.push(found);
  47167. }
  47168. match = matches.length > 0 ? matches : null;
  47169. } else {
  47170. match = dataNode[$getRealChildrenByNameIt](child.name, false, this.emptyMerge).next().value;
  47171. if (!match) {
  47172. if (min === 0) {
  47173. uselessNodes.push(child);
  47174. continue;
  47175. }
  47176. const nsId = dataNode[$namespaceId] === bind_NS_DATASETS ? -1 : dataNode[$namespaceId];
  47177. match = child[$data] = new XmlObject(nsId, child.name);
  47178. if (this.emptyMerge) {
  47179. match[$consumed] = true;
  47180. }
  47181. dataNode[$appendChild](match);
  47182. this._setAndBind(child, match);
  47183. continue;
  47184. }
  47185. if (this.emptyMerge) {
  47186. match[$consumed] = true;
  47187. }
  47188. match = [match];
  47189. }
  47190. }
  47191. if (match) {
  47192. this._bindOccurrences(child, match, picture);
  47193. } else if (min > 0) {
  47194. this._setAndBind(child, dataNode);
  47195. } else {
  47196. uselessNodes.push(child);
  47197. }
  47198. }
  47199. uselessNodes.forEach(node => node[$getParent]()[$removeChild](node));
  47200. }
  47201. }
  47202. ;// CONCATENATED MODULE: ./src/core/xfa/data.js
  47203. class DataHandler {
  47204. constructor(root, data) {
  47205. this.data = data;
  47206. this.dataset = root.datasets || null;
  47207. }
  47208. serialize(storage) {
  47209. const stack = [[-1, this.data[$getChildren]()]];
  47210. while (stack.length > 0) {
  47211. const last = stack.at(-1);
  47212. const [i, children] = last;
  47213. if (i + 1 === children.length) {
  47214. stack.pop();
  47215. continue;
  47216. }
  47217. const child = children[++last[0]];
  47218. const storageEntry = storage.get(child[$uid]);
  47219. if (storageEntry) {
  47220. child[$setValue](storageEntry);
  47221. } else {
  47222. const attributes = child[$getAttributes]();
  47223. for (const value of attributes.values()) {
  47224. const entry = storage.get(value[$uid]);
  47225. if (entry) {
  47226. value[$setValue](entry);
  47227. break;
  47228. }
  47229. }
  47230. }
  47231. const nodes = child[$getChildren]();
  47232. if (nodes.length > 0) {
  47233. stack.push([-1, nodes]);
  47234. }
  47235. }
  47236. const buf = [`<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">`];
  47237. if (this.dataset) {
  47238. for (const child of this.dataset[$getChildren]()) {
  47239. if (child[$nodeName] !== "data") {
  47240. child[$toString](buf);
  47241. }
  47242. }
  47243. }
  47244. this.data[$toString](buf);
  47245. buf.push("</xfa:datasets>");
  47246. return buf.join("");
  47247. }
  47248. }
  47249. ;// CONCATENATED MODULE: ./src/core/xfa/config.js
  47250. const CONFIG_NS_ID = NamespaceIds.config.id;
  47251. class Acrobat extends XFAObject {
  47252. constructor(attributes) {
  47253. super(CONFIG_NS_ID, "acrobat", true);
  47254. this.acrobat7 = null;
  47255. this.autoSave = null;
  47256. this.common = null;
  47257. this.validate = null;
  47258. this.validateApprovalSignatures = null;
  47259. this.submitUrl = new XFAObjectArray();
  47260. }
  47261. }
  47262. class Acrobat7 extends XFAObject {
  47263. constructor(attributes) {
  47264. super(CONFIG_NS_ID, "acrobat7", true);
  47265. this.dynamicRender = null;
  47266. }
  47267. }
  47268. class ADBE_JSConsole extends OptionObject {
  47269. constructor(attributes) {
  47270. super(CONFIG_NS_ID, "ADBE_JSConsole", ["delegate", "Enable", "Disable"]);
  47271. }
  47272. }
  47273. class ADBE_JSDebugger extends OptionObject {
  47274. constructor(attributes) {
  47275. super(CONFIG_NS_ID, "ADBE_JSDebugger", ["delegate", "Enable", "Disable"]);
  47276. }
  47277. }
  47278. class AddSilentPrint extends Option01 {
  47279. constructor(attributes) {
  47280. super(CONFIG_NS_ID, "addSilentPrint");
  47281. }
  47282. }
  47283. class AddViewerPreferences extends Option01 {
  47284. constructor(attributes) {
  47285. super(CONFIG_NS_ID, "addViewerPreferences");
  47286. }
  47287. }
  47288. class AdjustData extends Option10 {
  47289. constructor(attributes) {
  47290. super(CONFIG_NS_ID, "adjustData");
  47291. }
  47292. }
  47293. class AdobeExtensionLevel extends IntegerObject {
  47294. constructor(attributes) {
  47295. super(CONFIG_NS_ID, "adobeExtensionLevel", 0, n => n >= 1 && n <= 8);
  47296. }
  47297. }
  47298. class Agent extends XFAObject {
  47299. constructor(attributes) {
  47300. super(CONFIG_NS_ID, "agent", true);
  47301. this.name = attributes.name ? attributes.name.trim() : "";
  47302. this.common = new XFAObjectArray();
  47303. }
  47304. }
  47305. class AlwaysEmbed extends ContentObject {
  47306. constructor(attributes) {
  47307. super(CONFIG_NS_ID, "alwaysEmbed");
  47308. }
  47309. }
  47310. class Amd extends StringObject {
  47311. constructor(attributes) {
  47312. super(CONFIG_NS_ID, "amd");
  47313. }
  47314. }
  47315. class config_Area extends XFAObject {
  47316. constructor(attributes) {
  47317. super(CONFIG_NS_ID, "area");
  47318. this.level = getInteger({
  47319. data: attributes.level,
  47320. defaultValue: 0,
  47321. validate: n => n >= 1 && n <= 3
  47322. });
  47323. this.name = getStringOption(attributes.name, ["", "barcode", "coreinit", "deviceDriver", "font", "general", "layout", "merge", "script", "signature", "sourceSet", "templateCache"]);
  47324. }
  47325. }
  47326. class Attributes extends OptionObject {
  47327. constructor(attributes) {
  47328. super(CONFIG_NS_ID, "attributes", ["preserve", "delegate", "ignore"]);
  47329. }
  47330. }
  47331. class AutoSave extends OptionObject {
  47332. constructor(attributes) {
  47333. super(CONFIG_NS_ID, "autoSave", ["disabled", "enabled"]);
  47334. }
  47335. }
  47336. class Base extends StringObject {
  47337. constructor(attributes) {
  47338. super(CONFIG_NS_ID, "base");
  47339. }
  47340. }
  47341. class BatchOutput extends XFAObject {
  47342. constructor(attributes) {
  47343. super(CONFIG_NS_ID, "batchOutput");
  47344. this.format = getStringOption(attributes.format, ["none", "concat", "zip", "zipCompress"]);
  47345. }
  47346. }
  47347. class BehaviorOverride extends ContentObject {
  47348. constructor(attributes) {
  47349. super(CONFIG_NS_ID, "behaviorOverride");
  47350. }
  47351. [$finalize]() {
  47352. this[$content] = new Map(this[$content].trim().split(/\s+/).filter(x => x.includes(":")).map(x => x.split(":", 2)));
  47353. }
  47354. }
  47355. class Cache extends XFAObject {
  47356. constructor(attributes) {
  47357. super(CONFIG_NS_ID, "cache", true);
  47358. this.templateCache = null;
  47359. }
  47360. }
  47361. class Change extends Option01 {
  47362. constructor(attributes) {
  47363. super(CONFIG_NS_ID, "change");
  47364. }
  47365. }
  47366. class Common extends XFAObject {
  47367. constructor(attributes) {
  47368. super(CONFIG_NS_ID, "common", true);
  47369. this.data = null;
  47370. this.locale = null;
  47371. this.localeSet = null;
  47372. this.messaging = null;
  47373. this.suppressBanner = null;
  47374. this.template = null;
  47375. this.validationMessaging = null;
  47376. this.versionControl = null;
  47377. this.log = new XFAObjectArray();
  47378. }
  47379. }
  47380. class Compress extends XFAObject {
  47381. constructor(attributes) {
  47382. super(CONFIG_NS_ID, "compress");
  47383. this.scope = getStringOption(attributes.scope, ["imageOnly", "document"]);
  47384. }
  47385. }
  47386. class CompressLogicalStructure extends Option01 {
  47387. constructor(attributes) {
  47388. super(CONFIG_NS_ID, "compressLogicalStructure");
  47389. }
  47390. }
  47391. class CompressObjectStream extends Option10 {
  47392. constructor(attributes) {
  47393. super(CONFIG_NS_ID, "compressObjectStream");
  47394. }
  47395. }
  47396. class Compression extends XFAObject {
  47397. constructor(attributes) {
  47398. super(CONFIG_NS_ID, "compression", true);
  47399. this.compressLogicalStructure = null;
  47400. this.compressObjectStream = null;
  47401. this.level = null;
  47402. this.type = null;
  47403. }
  47404. }
  47405. class Config extends XFAObject {
  47406. constructor(attributes) {
  47407. super(CONFIG_NS_ID, "config", true);
  47408. this.acrobat = null;
  47409. this.present = null;
  47410. this.trace = null;
  47411. this.agent = new XFAObjectArray();
  47412. }
  47413. }
  47414. class Conformance extends OptionObject {
  47415. constructor(attributes) {
  47416. super(CONFIG_NS_ID, "conformance", ["A", "B"]);
  47417. }
  47418. }
  47419. class ContentCopy extends Option01 {
  47420. constructor(attributes) {
  47421. super(CONFIG_NS_ID, "contentCopy");
  47422. }
  47423. }
  47424. class Copies extends IntegerObject {
  47425. constructor(attributes) {
  47426. super(CONFIG_NS_ID, "copies", 1, n => n >= 1);
  47427. }
  47428. }
  47429. class Creator extends StringObject {
  47430. constructor(attributes) {
  47431. super(CONFIG_NS_ID, "creator");
  47432. }
  47433. }
  47434. class CurrentPage extends IntegerObject {
  47435. constructor(attributes) {
  47436. super(CONFIG_NS_ID, "currentPage", 0, n => n >= 0);
  47437. }
  47438. }
  47439. class Data extends XFAObject {
  47440. constructor(attributes) {
  47441. super(CONFIG_NS_ID, "data", true);
  47442. this.adjustData = null;
  47443. this.attributes = null;
  47444. this.incrementalLoad = null;
  47445. this.outputXSL = null;
  47446. this.range = null;
  47447. this.record = null;
  47448. this.startNode = null;
  47449. this.uri = null;
  47450. this.window = null;
  47451. this.xsl = null;
  47452. this.excludeNS = new XFAObjectArray();
  47453. this.transform = new XFAObjectArray();
  47454. }
  47455. }
  47456. class Debug extends XFAObject {
  47457. constructor(attributes) {
  47458. super(CONFIG_NS_ID, "debug", true);
  47459. this.uri = null;
  47460. }
  47461. }
  47462. class DefaultTypeface extends ContentObject {
  47463. constructor(attributes) {
  47464. super(CONFIG_NS_ID, "defaultTypeface");
  47465. this.writingScript = getStringOption(attributes.writingScript, ["*", "Arabic", "Cyrillic", "EastEuropeanRoman", "Greek", "Hebrew", "Japanese", "Korean", "Roman", "SimplifiedChinese", "Thai", "TraditionalChinese", "Vietnamese"]);
  47466. }
  47467. }
  47468. class Destination extends OptionObject {
  47469. constructor(attributes) {
  47470. super(CONFIG_NS_ID, "destination", ["pdf", "pcl", "ps", "webClient", "zpl"]);
  47471. }
  47472. }
  47473. class DocumentAssembly extends Option01 {
  47474. constructor(attributes) {
  47475. super(CONFIG_NS_ID, "documentAssembly");
  47476. }
  47477. }
  47478. class Driver extends XFAObject {
  47479. constructor(attributes) {
  47480. super(CONFIG_NS_ID, "driver", true);
  47481. this.name = attributes.name ? attributes.name.trim() : "";
  47482. this.fontInfo = null;
  47483. this.xdc = null;
  47484. }
  47485. }
  47486. class DuplexOption extends OptionObject {
  47487. constructor(attributes) {
  47488. super(CONFIG_NS_ID, "duplexOption", ["simplex", "duplexFlipLongEdge", "duplexFlipShortEdge"]);
  47489. }
  47490. }
  47491. class DynamicRender extends OptionObject {
  47492. constructor(attributes) {
  47493. super(CONFIG_NS_ID, "dynamicRender", ["forbidden", "required"]);
  47494. }
  47495. }
  47496. class Embed extends Option01 {
  47497. constructor(attributes) {
  47498. super(CONFIG_NS_ID, "embed");
  47499. }
  47500. }
  47501. class config_Encrypt extends Option01 {
  47502. constructor(attributes) {
  47503. super(CONFIG_NS_ID, "encrypt");
  47504. }
  47505. }
  47506. class config_Encryption extends XFAObject {
  47507. constructor(attributes) {
  47508. super(CONFIG_NS_ID, "encryption", true);
  47509. this.encrypt = null;
  47510. this.encryptionLevel = null;
  47511. this.permissions = null;
  47512. }
  47513. }
  47514. class EncryptionLevel extends OptionObject {
  47515. constructor(attributes) {
  47516. super(CONFIG_NS_ID, "encryptionLevel", ["40bit", "128bit"]);
  47517. }
  47518. }
  47519. class Enforce extends StringObject {
  47520. constructor(attributes) {
  47521. super(CONFIG_NS_ID, "enforce");
  47522. }
  47523. }
  47524. class Equate extends XFAObject {
  47525. constructor(attributes) {
  47526. super(CONFIG_NS_ID, "equate");
  47527. this.force = getInteger({
  47528. data: attributes.force,
  47529. defaultValue: 1,
  47530. validate: n => n === 0
  47531. });
  47532. this.from = attributes.from || "";
  47533. this.to = attributes.to || "";
  47534. }
  47535. }
  47536. class EquateRange extends XFAObject {
  47537. constructor(attributes) {
  47538. super(CONFIG_NS_ID, "equateRange");
  47539. this.from = attributes.from || "";
  47540. this.to = attributes.to || "";
  47541. this._unicodeRange = attributes.unicodeRange || "";
  47542. }
  47543. get unicodeRange() {
  47544. const ranges = [];
  47545. const unicodeRegex = /U\+([0-9a-fA-F]+)/;
  47546. const unicodeRange = this._unicodeRange;
  47547. for (let range of unicodeRange.split(",").map(x => x.trim()).filter(x => !!x)) {
  47548. range = range.split("-", 2).map(x => {
  47549. const found = x.match(unicodeRegex);
  47550. if (!found) {
  47551. return 0;
  47552. }
  47553. return parseInt(found[1], 16);
  47554. });
  47555. if (range.length === 1) {
  47556. range.push(range[0]);
  47557. }
  47558. ranges.push(range);
  47559. }
  47560. return shadow(this, "unicodeRange", ranges);
  47561. }
  47562. }
  47563. class Exclude extends ContentObject {
  47564. constructor(attributes) {
  47565. super(CONFIG_NS_ID, "exclude");
  47566. }
  47567. [$finalize]() {
  47568. this[$content] = this[$content].trim().split(/\s+/).filter(x => x && ["calculate", "close", "enter", "exit", "initialize", "ready", "validate"].includes(x));
  47569. }
  47570. }
  47571. class ExcludeNS extends StringObject {
  47572. constructor(attributes) {
  47573. super(CONFIG_NS_ID, "excludeNS");
  47574. }
  47575. }
  47576. class FlipLabel extends OptionObject {
  47577. constructor(attributes) {
  47578. super(CONFIG_NS_ID, "flipLabel", ["usePrinterSetting", "on", "off"]);
  47579. }
  47580. }
  47581. class config_FontInfo extends XFAObject {
  47582. constructor(attributes) {
  47583. super(CONFIG_NS_ID, "fontInfo", true);
  47584. this.embed = null;
  47585. this.map = null;
  47586. this.subsetBelow = null;
  47587. this.alwaysEmbed = new XFAObjectArray();
  47588. this.defaultTypeface = new XFAObjectArray();
  47589. this.neverEmbed = new XFAObjectArray();
  47590. }
  47591. }
  47592. class FormFieldFilling extends Option01 {
  47593. constructor(attributes) {
  47594. super(CONFIG_NS_ID, "formFieldFilling");
  47595. }
  47596. }
  47597. class GroupParent extends StringObject {
  47598. constructor(attributes) {
  47599. super(CONFIG_NS_ID, "groupParent");
  47600. }
  47601. }
  47602. class IfEmpty extends OptionObject {
  47603. constructor(attributes) {
  47604. super(CONFIG_NS_ID, "ifEmpty", ["dataValue", "dataGroup", "ignore", "remove"]);
  47605. }
  47606. }
  47607. class IncludeXDPContent extends StringObject {
  47608. constructor(attributes) {
  47609. super(CONFIG_NS_ID, "includeXDPContent");
  47610. }
  47611. }
  47612. class IncrementalLoad extends OptionObject {
  47613. constructor(attributes) {
  47614. super(CONFIG_NS_ID, "incrementalLoad", ["none", "forwardOnly"]);
  47615. }
  47616. }
  47617. class IncrementalMerge extends Option01 {
  47618. constructor(attributes) {
  47619. super(CONFIG_NS_ID, "incrementalMerge");
  47620. }
  47621. }
  47622. class Interactive extends Option01 {
  47623. constructor(attributes) {
  47624. super(CONFIG_NS_ID, "interactive");
  47625. }
  47626. }
  47627. class Jog extends OptionObject {
  47628. constructor(attributes) {
  47629. super(CONFIG_NS_ID, "jog", ["usePrinterSetting", "none", "pageSet"]);
  47630. }
  47631. }
  47632. class LabelPrinter extends XFAObject {
  47633. constructor(attributes) {
  47634. super(CONFIG_NS_ID, "labelPrinter", true);
  47635. this.name = getStringOption(attributes.name, ["zpl", "dpl", "ipl", "tcpl"]);
  47636. this.batchOutput = null;
  47637. this.flipLabel = null;
  47638. this.fontInfo = null;
  47639. this.xdc = null;
  47640. }
  47641. }
  47642. class Layout extends OptionObject {
  47643. constructor(attributes) {
  47644. super(CONFIG_NS_ID, "layout", ["paginate", "panel"]);
  47645. }
  47646. }
  47647. class Level extends IntegerObject {
  47648. constructor(attributes) {
  47649. super(CONFIG_NS_ID, "level", 0, n => n > 0);
  47650. }
  47651. }
  47652. class Linearized extends Option01 {
  47653. constructor(attributes) {
  47654. super(CONFIG_NS_ID, "linearized");
  47655. }
  47656. }
  47657. class Locale extends StringObject {
  47658. constructor(attributes) {
  47659. super(CONFIG_NS_ID, "locale");
  47660. }
  47661. }
  47662. class LocaleSet extends StringObject {
  47663. constructor(attributes) {
  47664. super(CONFIG_NS_ID, "localeSet");
  47665. }
  47666. }
  47667. class Log extends XFAObject {
  47668. constructor(attributes) {
  47669. super(CONFIG_NS_ID, "log", true);
  47670. this.mode = null;
  47671. this.threshold = null;
  47672. this.to = null;
  47673. this.uri = null;
  47674. }
  47675. }
  47676. class MapElement extends XFAObject {
  47677. constructor(attributes) {
  47678. super(CONFIG_NS_ID, "map", true);
  47679. this.equate = new XFAObjectArray();
  47680. this.equateRange = new XFAObjectArray();
  47681. }
  47682. }
  47683. class MediumInfo extends XFAObject {
  47684. constructor(attributes) {
  47685. super(CONFIG_NS_ID, "mediumInfo", true);
  47686. this.map = null;
  47687. }
  47688. }
  47689. class config_Message extends XFAObject {
  47690. constructor(attributes) {
  47691. super(CONFIG_NS_ID, "message", true);
  47692. this.msgId = null;
  47693. this.severity = null;
  47694. }
  47695. }
  47696. class Messaging extends XFAObject {
  47697. constructor(attributes) {
  47698. super(CONFIG_NS_ID, "messaging", true);
  47699. this.message = new XFAObjectArray();
  47700. }
  47701. }
  47702. class Mode extends OptionObject {
  47703. constructor(attributes) {
  47704. super(CONFIG_NS_ID, "mode", ["append", "overwrite"]);
  47705. }
  47706. }
  47707. class ModifyAnnots extends Option01 {
  47708. constructor(attributes) {
  47709. super(CONFIG_NS_ID, "modifyAnnots");
  47710. }
  47711. }
  47712. class MsgId extends IntegerObject {
  47713. constructor(attributes) {
  47714. super(CONFIG_NS_ID, "msgId", 1, n => n >= 1);
  47715. }
  47716. }
  47717. class NameAttr extends StringObject {
  47718. constructor(attributes) {
  47719. super(CONFIG_NS_ID, "nameAttr");
  47720. }
  47721. }
  47722. class NeverEmbed extends ContentObject {
  47723. constructor(attributes) {
  47724. super(CONFIG_NS_ID, "neverEmbed");
  47725. }
  47726. }
  47727. class NumberOfCopies extends IntegerObject {
  47728. constructor(attributes) {
  47729. super(CONFIG_NS_ID, "numberOfCopies", null, n => n >= 2 && n <= 5);
  47730. }
  47731. }
  47732. class OpenAction extends XFAObject {
  47733. constructor(attributes) {
  47734. super(CONFIG_NS_ID, "openAction", true);
  47735. this.destination = null;
  47736. }
  47737. }
  47738. class Output extends XFAObject {
  47739. constructor(attributes) {
  47740. super(CONFIG_NS_ID, "output", true);
  47741. this.to = null;
  47742. this.type = null;
  47743. this.uri = null;
  47744. }
  47745. }
  47746. class OutputBin extends StringObject {
  47747. constructor(attributes) {
  47748. super(CONFIG_NS_ID, "outputBin");
  47749. }
  47750. }
  47751. class OutputXSL extends XFAObject {
  47752. constructor(attributes) {
  47753. super(CONFIG_NS_ID, "outputXSL", true);
  47754. this.uri = null;
  47755. }
  47756. }
  47757. class Overprint extends OptionObject {
  47758. constructor(attributes) {
  47759. super(CONFIG_NS_ID, "overprint", ["none", "both", "draw", "field"]);
  47760. }
  47761. }
  47762. class Packets extends StringObject {
  47763. constructor(attributes) {
  47764. super(CONFIG_NS_ID, "packets");
  47765. }
  47766. [$finalize]() {
  47767. if (this[$content] === "*") {
  47768. return;
  47769. }
  47770. this[$content] = this[$content].trim().split(/\s+/).filter(x => ["config", "datasets", "template", "xfdf", "xslt"].includes(x));
  47771. }
  47772. }
  47773. class PageOffset extends XFAObject {
  47774. constructor(attributes) {
  47775. super(CONFIG_NS_ID, "pageOffset");
  47776. this.x = getInteger({
  47777. data: attributes.x,
  47778. defaultValue: "useXDCSetting",
  47779. validate: n => true
  47780. });
  47781. this.y = getInteger({
  47782. data: attributes.y,
  47783. defaultValue: "useXDCSetting",
  47784. validate: n => true
  47785. });
  47786. }
  47787. }
  47788. class PageRange extends StringObject {
  47789. constructor(attributes) {
  47790. super(CONFIG_NS_ID, "pageRange");
  47791. }
  47792. [$finalize]() {
  47793. const numbers = this[$content].trim().split(/\s+/).map(x => parseInt(x, 10));
  47794. const ranges = [];
  47795. for (let i = 0, ii = numbers.length; i < ii; i += 2) {
  47796. ranges.push(numbers.slice(i, i + 2));
  47797. }
  47798. this[$content] = ranges;
  47799. }
  47800. }
  47801. class Pagination extends OptionObject {
  47802. constructor(attributes) {
  47803. super(CONFIG_NS_ID, "pagination", ["simplex", "duplexShortEdge", "duplexLongEdge"]);
  47804. }
  47805. }
  47806. class PaginationOverride extends OptionObject {
  47807. constructor(attributes) {
  47808. super(CONFIG_NS_ID, "paginationOverride", ["none", "forceDuplex", "forceDuplexLongEdge", "forceDuplexShortEdge", "forceSimplex"]);
  47809. }
  47810. }
  47811. class Part extends IntegerObject {
  47812. constructor(attributes) {
  47813. super(CONFIG_NS_ID, "part", 1, n => false);
  47814. }
  47815. }
  47816. class Pcl extends XFAObject {
  47817. constructor(attributes) {
  47818. super(CONFIG_NS_ID, "pcl", true);
  47819. this.name = attributes.name || "";
  47820. this.batchOutput = null;
  47821. this.fontInfo = null;
  47822. this.jog = null;
  47823. this.mediumInfo = null;
  47824. this.outputBin = null;
  47825. this.pageOffset = null;
  47826. this.staple = null;
  47827. this.xdc = null;
  47828. }
  47829. }
  47830. class Pdf extends XFAObject {
  47831. constructor(attributes) {
  47832. super(CONFIG_NS_ID, "pdf", true);
  47833. this.name = attributes.name || "";
  47834. this.adobeExtensionLevel = null;
  47835. this.batchOutput = null;
  47836. this.compression = null;
  47837. this.creator = null;
  47838. this.encryption = null;
  47839. this.fontInfo = null;
  47840. this.interactive = null;
  47841. this.linearized = null;
  47842. this.openAction = null;
  47843. this.pdfa = null;
  47844. this.producer = null;
  47845. this.renderPolicy = null;
  47846. this.scriptModel = null;
  47847. this.silentPrint = null;
  47848. this.submitFormat = null;
  47849. this.tagged = null;
  47850. this.version = null;
  47851. this.viewerPreferences = null;
  47852. this.xdc = null;
  47853. }
  47854. }
  47855. class Pdfa extends XFAObject {
  47856. constructor(attributes) {
  47857. super(CONFIG_NS_ID, "pdfa", true);
  47858. this.amd = null;
  47859. this.conformance = null;
  47860. this.includeXDPContent = null;
  47861. this.part = null;
  47862. }
  47863. }
  47864. class Permissions extends XFAObject {
  47865. constructor(attributes) {
  47866. super(CONFIG_NS_ID, "permissions", true);
  47867. this.accessibleContent = null;
  47868. this.change = null;
  47869. this.contentCopy = null;
  47870. this.documentAssembly = null;
  47871. this.formFieldFilling = null;
  47872. this.modifyAnnots = null;
  47873. this.plaintextMetadata = null;
  47874. this.print = null;
  47875. this.printHighQuality = null;
  47876. }
  47877. }
  47878. class PickTrayByPDFSize extends Option01 {
  47879. constructor(attributes) {
  47880. super(CONFIG_NS_ID, "pickTrayByPDFSize");
  47881. }
  47882. }
  47883. class config_Picture extends StringObject {
  47884. constructor(attributes) {
  47885. super(CONFIG_NS_ID, "picture");
  47886. }
  47887. }
  47888. class PlaintextMetadata extends Option01 {
  47889. constructor(attributes) {
  47890. super(CONFIG_NS_ID, "plaintextMetadata");
  47891. }
  47892. }
  47893. class Presence extends OptionObject {
  47894. constructor(attributes) {
  47895. super(CONFIG_NS_ID, "presence", ["preserve", "dissolve", "dissolveStructure", "ignore", "remove"]);
  47896. }
  47897. }
  47898. class Present extends XFAObject {
  47899. constructor(attributes) {
  47900. super(CONFIG_NS_ID, "present", true);
  47901. this.behaviorOverride = null;
  47902. this.cache = null;
  47903. this.common = null;
  47904. this.copies = null;
  47905. this.destination = null;
  47906. this.incrementalMerge = null;
  47907. this.layout = null;
  47908. this.output = null;
  47909. this.overprint = null;
  47910. this.pagination = null;
  47911. this.paginationOverride = null;
  47912. this.script = null;
  47913. this.validate = null;
  47914. this.xdp = null;
  47915. this.driver = new XFAObjectArray();
  47916. this.labelPrinter = new XFAObjectArray();
  47917. this.pcl = new XFAObjectArray();
  47918. this.pdf = new XFAObjectArray();
  47919. this.ps = new XFAObjectArray();
  47920. this.submitUrl = new XFAObjectArray();
  47921. this.webClient = new XFAObjectArray();
  47922. this.zpl = new XFAObjectArray();
  47923. }
  47924. }
  47925. class Print extends Option01 {
  47926. constructor(attributes) {
  47927. super(CONFIG_NS_ID, "print");
  47928. }
  47929. }
  47930. class PrintHighQuality extends Option01 {
  47931. constructor(attributes) {
  47932. super(CONFIG_NS_ID, "printHighQuality");
  47933. }
  47934. }
  47935. class PrintScaling extends OptionObject {
  47936. constructor(attributes) {
  47937. super(CONFIG_NS_ID, "printScaling", ["appdefault", "noScaling"]);
  47938. }
  47939. }
  47940. class PrinterName extends StringObject {
  47941. constructor(attributes) {
  47942. super(CONFIG_NS_ID, "printerName");
  47943. }
  47944. }
  47945. class Producer extends StringObject {
  47946. constructor(attributes) {
  47947. super(CONFIG_NS_ID, "producer");
  47948. }
  47949. }
  47950. class Ps extends XFAObject {
  47951. constructor(attributes) {
  47952. super(CONFIG_NS_ID, "ps", true);
  47953. this.name = attributes.name || "";
  47954. this.batchOutput = null;
  47955. this.fontInfo = null;
  47956. this.jog = null;
  47957. this.mediumInfo = null;
  47958. this.outputBin = null;
  47959. this.staple = null;
  47960. this.xdc = null;
  47961. }
  47962. }
  47963. class Range extends ContentObject {
  47964. constructor(attributes) {
  47965. super(CONFIG_NS_ID, "range");
  47966. }
  47967. [$finalize]() {
  47968. this[$content] = this[$content].trim().split(/\s*,\s*/, 2).map(range => range.split("-").map(x => parseInt(x.trim(), 10))).filter(range => range.every(x => !isNaN(x))).map(range => {
  47969. if (range.length === 1) {
  47970. range.push(range[0]);
  47971. }
  47972. return range;
  47973. });
  47974. }
  47975. }
  47976. class Record extends ContentObject {
  47977. constructor(attributes) {
  47978. super(CONFIG_NS_ID, "record");
  47979. }
  47980. [$finalize]() {
  47981. this[$content] = this[$content].trim();
  47982. const n = parseInt(this[$content], 10);
  47983. if (!isNaN(n) && n >= 0) {
  47984. this[$content] = n;
  47985. }
  47986. }
  47987. }
  47988. class Relevant extends ContentObject {
  47989. constructor(attributes) {
  47990. super(CONFIG_NS_ID, "relevant");
  47991. }
  47992. [$finalize]() {
  47993. this[$content] = this[$content].trim().split(/\s+/);
  47994. }
  47995. }
  47996. class Rename extends ContentObject {
  47997. constructor(attributes) {
  47998. super(CONFIG_NS_ID, "rename");
  47999. }
  48000. [$finalize]() {
  48001. this[$content] = this[$content].trim();
  48002. if (this[$content].toLowerCase().startsWith("xml") || new RegExp("[\\p{L}_][\\p{L}\\d._\\p{M}-]*", "u").test(this[$content])) {
  48003. warn("XFA - Rename: invalid XFA name");
  48004. }
  48005. }
  48006. }
  48007. class RenderPolicy extends OptionObject {
  48008. constructor(attributes) {
  48009. super(CONFIG_NS_ID, "renderPolicy", ["server", "client"]);
  48010. }
  48011. }
  48012. class RunScripts extends OptionObject {
  48013. constructor(attributes) {
  48014. super(CONFIG_NS_ID, "runScripts", ["both", "client", "none", "server"]);
  48015. }
  48016. }
  48017. class config_Script extends XFAObject {
  48018. constructor(attributes) {
  48019. super(CONFIG_NS_ID, "script", true);
  48020. this.currentPage = null;
  48021. this.exclude = null;
  48022. this.runScripts = null;
  48023. }
  48024. }
  48025. class ScriptModel extends OptionObject {
  48026. constructor(attributes) {
  48027. super(CONFIG_NS_ID, "scriptModel", ["XFA", "none"]);
  48028. }
  48029. }
  48030. class Severity extends OptionObject {
  48031. constructor(attributes) {
  48032. super(CONFIG_NS_ID, "severity", ["ignore", "error", "information", "trace", "warning"]);
  48033. }
  48034. }
  48035. class SilentPrint extends XFAObject {
  48036. constructor(attributes) {
  48037. super(CONFIG_NS_ID, "silentPrint", true);
  48038. this.addSilentPrint = null;
  48039. this.printerName = null;
  48040. }
  48041. }
  48042. class Staple extends XFAObject {
  48043. constructor(attributes) {
  48044. super(CONFIG_NS_ID, "staple");
  48045. this.mode = getStringOption(attributes.mode, ["usePrinterSetting", "on", "off"]);
  48046. }
  48047. }
  48048. class StartNode extends StringObject {
  48049. constructor(attributes) {
  48050. super(CONFIG_NS_ID, "startNode");
  48051. }
  48052. }
  48053. class StartPage extends IntegerObject {
  48054. constructor(attributes) {
  48055. super(CONFIG_NS_ID, "startPage", 0, n => true);
  48056. }
  48057. }
  48058. class SubmitFormat extends OptionObject {
  48059. constructor(attributes) {
  48060. super(CONFIG_NS_ID, "submitFormat", ["html", "delegate", "fdf", "xml", "pdf"]);
  48061. }
  48062. }
  48063. class SubmitUrl extends StringObject {
  48064. constructor(attributes) {
  48065. super(CONFIG_NS_ID, "submitUrl");
  48066. }
  48067. }
  48068. class SubsetBelow extends IntegerObject {
  48069. constructor(attributes) {
  48070. super(CONFIG_NS_ID, "subsetBelow", 100, n => n >= 0 && n <= 100);
  48071. }
  48072. }
  48073. class SuppressBanner extends Option01 {
  48074. constructor(attributes) {
  48075. super(CONFIG_NS_ID, "suppressBanner");
  48076. }
  48077. }
  48078. class Tagged extends Option01 {
  48079. constructor(attributes) {
  48080. super(CONFIG_NS_ID, "tagged");
  48081. }
  48082. }
  48083. class config_Template extends XFAObject {
  48084. constructor(attributes) {
  48085. super(CONFIG_NS_ID, "template", true);
  48086. this.base = null;
  48087. this.relevant = null;
  48088. this.startPage = null;
  48089. this.uri = null;
  48090. this.xsl = null;
  48091. }
  48092. }
  48093. class Threshold extends OptionObject {
  48094. constructor(attributes) {
  48095. super(CONFIG_NS_ID, "threshold", ["trace", "error", "information", "warning"]);
  48096. }
  48097. }
  48098. class To extends OptionObject {
  48099. constructor(attributes) {
  48100. super(CONFIG_NS_ID, "to", ["null", "memory", "stderr", "stdout", "system", "uri"]);
  48101. }
  48102. }
  48103. class TemplateCache extends XFAObject {
  48104. constructor(attributes) {
  48105. super(CONFIG_NS_ID, "templateCache");
  48106. this.maxEntries = getInteger({
  48107. data: attributes.maxEntries,
  48108. defaultValue: 5,
  48109. validate: n => n >= 0
  48110. });
  48111. }
  48112. }
  48113. class Trace extends XFAObject {
  48114. constructor(attributes) {
  48115. super(CONFIG_NS_ID, "trace", true);
  48116. this.area = new XFAObjectArray();
  48117. }
  48118. }
  48119. class config_Transform extends XFAObject {
  48120. constructor(attributes) {
  48121. super(CONFIG_NS_ID, "transform", true);
  48122. this.groupParent = null;
  48123. this.ifEmpty = null;
  48124. this.nameAttr = null;
  48125. this.picture = null;
  48126. this.presence = null;
  48127. this.rename = null;
  48128. this.whitespace = null;
  48129. }
  48130. }
  48131. class Type extends OptionObject {
  48132. constructor(attributes) {
  48133. super(CONFIG_NS_ID, "type", ["none", "ascii85", "asciiHex", "ccittfax", "flate", "lzw", "runLength", "native", "xdp", "mergedXDP"]);
  48134. }
  48135. }
  48136. class Uri extends StringObject {
  48137. constructor(attributes) {
  48138. super(CONFIG_NS_ID, "uri");
  48139. }
  48140. }
  48141. class config_Validate extends OptionObject {
  48142. constructor(attributes) {
  48143. super(CONFIG_NS_ID, "validate", ["preSubmit", "prePrint", "preExecute", "preSave"]);
  48144. }
  48145. }
  48146. class ValidateApprovalSignatures extends ContentObject {
  48147. constructor(attributes) {
  48148. super(CONFIG_NS_ID, "validateApprovalSignatures");
  48149. }
  48150. [$finalize]() {
  48151. this[$content] = this[$content].trim().split(/\s+/).filter(x => ["docReady", "postSign"].includes(x));
  48152. }
  48153. }
  48154. class ValidationMessaging extends OptionObject {
  48155. constructor(attributes) {
  48156. super(CONFIG_NS_ID, "validationMessaging", ["allMessagesIndividually", "allMessagesTogether", "firstMessageOnly", "noMessages"]);
  48157. }
  48158. }
  48159. class Version extends OptionObject {
  48160. constructor(attributes) {
  48161. super(CONFIG_NS_ID, "version", ["1.7", "1.6", "1.5", "1.4", "1.3", "1.2"]);
  48162. }
  48163. }
  48164. class VersionControl extends XFAObject {
  48165. constructor(attributes) {
  48166. super(CONFIG_NS_ID, "VersionControl");
  48167. this.outputBelow = getStringOption(attributes.outputBelow, ["warn", "error", "update"]);
  48168. this.sourceAbove = getStringOption(attributes.sourceAbove, ["warn", "error"]);
  48169. this.sourceBelow = getStringOption(attributes.sourceBelow, ["update", "maintain"]);
  48170. }
  48171. }
  48172. class ViewerPreferences extends XFAObject {
  48173. constructor(attributes) {
  48174. super(CONFIG_NS_ID, "viewerPreferences", true);
  48175. this.ADBE_JSConsole = null;
  48176. this.ADBE_JSDebugger = null;
  48177. this.addViewerPreferences = null;
  48178. this.duplexOption = null;
  48179. this.enforce = null;
  48180. this.numberOfCopies = null;
  48181. this.pageRange = null;
  48182. this.pickTrayByPDFSize = null;
  48183. this.printScaling = null;
  48184. }
  48185. }
  48186. class WebClient extends XFAObject {
  48187. constructor(attributes) {
  48188. super(CONFIG_NS_ID, "webClient", true);
  48189. this.name = attributes.name ? attributes.name.trim() : "";
  48190. this.fontInfo = null;
  48191. this.xdc = null;
  48192. }
  48193. }
  48194. class Whitespace extends OptionObject {
  48195. constructor(attributes) {
  48196. super(CONFIG_NS_ID, "whitespace", ["preserve", "ltrim", "normalize", "rtrim", "trim"]);
  48197. }
  48198. }
  48199. class Window extends ContentObject {
  48200. constructor(attributes) {
  48201. super(CONFIG_NS_ID, "window");
  48202. }
  48203. [$finalize]() {
  48204. const pair = this[$content].trim().split(/\s*,\s*/, 2).map(x => parseInt(x, 10));
  48205. if (pair.some(x => isNaN(x))) {
  48206. this[$content] = [0, 0];
  48207. return;
  48208. }
  48209. if (pair.length === 1) {
  48210. pair.push(pair[0]);
  48211. }
  48212. this[$content] = pair;
  48213. }
  48214. }
  48215. class Xdc extends XFAObject {
  48216. constructor(attributes) {
  48217. super(CONFIG_NS_ID, "xdc", true);
  48218. this.uri = new XFAObjectArray();
  48219. this.xsl = new XFAObjectArray();
  48220. }
  48221. }
  48222. class Xdp extends XFAObject {
  48223. constructor(attributes) {
  48224. super(CONFIG_NS_ID, "xdp", true);
  48225. this.packets = null;
  48226. }
  48227. }
  48228. class Xsl extends XFAObject {
  48229. constructor(attributes) {
  48230. super(CONFIG_NS_ID, "xsl", true);
  48231. this.debug = null;
  48232. this.uri = null;
  48233. }
  48234. }
  48235. class Zpl extends XFAObject {
  48236. constructor(attributes) {
  48237. super(CONFIG_NS_ID, "zpl", true);
  48238. this.name = attributes.name ? attributes.name.trim() : "";
  48239. this.batchOutput = null;
  48240. this.flipLabel = null;
  48241. this.fontInfo = null;
  48242. this.xdc = null;
  48243. }
  48244. }
  48245. class ConfigNamespace {
  48246. static [$buildXFAObject](name, attributes) {
  48247. if (ConfigNamespace.hasOwnProperty(name)) {
  48248. return ConfigNamespace[name](attributes);
  48249. }
  48250. return undefined;
  48251. }
  48252. static acrobat(attrs) {
  48253. return new Acrobat(attrs);
  48254. }
  48255. static acrobat7(attrs) {
  48256. return new Acrobat7(attrs);
  48257. }
  48258. static ADBE_JSConsole(attrs) {
  48259. return new ADBE_JSConsole(attrs);
  48260. }
  48261. static ADBE_JSDebugger(attrs) {
  48262. return new ADBE_JSDebugger(attrs);
  48263. }
  48264. static addSilentPrint(attrs) {
  48265. return new AddSilentPrint(attrs);
  48266. }
  48267. static addViewerPreferences(attrs) {
  48268. return new AddViewerPreferences(attrs);
  48269. }
  48270. static adjustData(attrs) {
  48271. return new AdjustData(attrs);
  48272. }
  48273. static adobeExtensionLevel(attrs) {
  48274. return new AdobeExtensionLevel(attrs);
  48275. }
  48276. static agent(attrs) {
  48277. return new Agent(attrs);
  48278. }
  48279. static alwaysEmbed(attrs) {
  48280. return new AlwaysEmbed(attrs);
  48281. }
  48282. static amd(attrs) {
  48283. return new Amd(attrs);
  48284. }
  48285. static area(attrs) {
  48286. return new config_Area(attrs);
  48287. }
  48288. static attributes(attrs) {
  48289. return new Attributes(attrs);
  48290. }
  48291. static autoSave(attrs) {
  48292. return new AutoSave(attrs);
  48293. }
  48294. static base(attrs) {
  48295. return new Base(attrs);
  48296. }
  48297. static batchOutput(attrs) {
  48298. return new BatchOutput(attrs);
  48299. }
  48300. static behaviorOverride(attrs) {
  48301. return new BehaviorOverride(attrs);
  48302. }
  48303. static cache(attrs) {
  48304. return new Cache(attrs);
  48305. }
  48306. static change(attrs) {
  48307. return new Change(attrs);
  48308. }
  48309. static common(attrs) {
  48310. return new Common(attrs);
  48311. }
  48312. static compress(attrs) {
  48313. return new Compress(attrs);
  48314. }
  48315. static compressLogicalStructure(attrs) {
  48316. return new CompressLogicalStructure(attrs);
  48317. }
  48318. static compressObjectStream(attrs) {
  48319. return new CompressObjectStream(attrs);
  48320. }
  48321. static compression(attrs) {
  48322. return new Compression(attrs);
  48323. }
  48324. static config(attrs) {
  48325. return new Config(attrs);
  48326. }
  48327. static conformance(attrs) {
  48328. return new Conformance(attrs);
  48329. }
  48330. static contentCopy(attrs) {
  48331. return new ContentCopy(attrs);
  48332. }
  48333. static copies(attrs) {
  48334. return new Copies(attrs);
  48335. }
  48336. static creator(attrs) {
  48337. return new Creator(attrs);
  48338. }
  48339. static currentPage(attrs) {
  48340. return new CurrentPage(attrs);
  48341. }
  48342. static data(attrs) {
  48343. return new Data(attrs);
  48344. }
  48345. static debug(attrs) {
  48346. return new Debug(attrs);
  48347. }
  48348. static defaultTypeface(attrs) {
  48349. return new DefaultTypeface(attrs);
  48350. }
  48351. static destination(attrs) {
  48352. return new Destination(attrs);
  48353. }
  48354. static documentAssembly(attrs) {
  48355. return new DocumentAssembly(attrs);
  48356. }
  48357. static driver(attrs) {
  48358. return new Driver(attrs);
  48359. }
  48360. static duplexOption(attrs) {
  48361. return new DuplexOption(attrs);
  48362. }
  48363. static dynamicRender(attrs) {
  48364. return new DynamicRender(attrs);
  48365. }
  48366. static embed(attrs) {
  48367. return new Embed(attrs);
  48368. }
  48369. static encrypt(attrs) {
  48370. return new config_Encrypt(attrs);
  48371. }
  48372. static encryption(attrs) {
  48373. return new config_Encryption(attrs);
  48374. }
  48375. static encryptionLevel(attrs) {
  48376. return new EncryptionLevel(attrs);
  48377. }
  48378. static enforce(attrs) {
  48379. return new Enforce(attrs);
  48380. }
  48381. static equate(attrs) {
  48382. return new Equate(attrs);
  48383. }
  48384. static equateRange(attrs) {
  48385. return new EquateRange(attrs);
  48386. }
  48387. static exclude(attrs) {
  48388. return new Exclude(attrs);
  48389. }
  48390. static excludeNS(attrs) {
  48391. return new ExcludeNS(attrs);
  48392. }
  48393. static flipLabel(attrs) {
  48394. return new FlipLabel(attrs);
  48395. }
  48396. static fontInfo(attrs) {
  48397. return new config_FontInfo(attrs);
  48398. }
  48399. static formFieldFilling(attrs) {
  48400. return new FormFieldFilling(attrs);
  48401. }
  48402. static groupParent(attrs) {
  48403. return new GroupParent(attrs);
  48404. }
  48405. static ifEmpty(attrs) {
  48406. return new IfEmpty(attrs);
  48407. }
  48408. static includeXDPContent(attrs) {
  48409. return new IncludeXDPContent(attrs);
  48410. }
  48411. static incrementalLoad(attrs) {
  48412. return new IncrementalLoad(attrs);
  48413. }
  48414. static incrementalMerge(attrs) {
  48415. return new IncrementalMerge(attrs);
  48416. }
  48417. static interactive(attrs) {
  48418. return new Interactive(attrs);
  48419. }
  48420. static jog(attrs) {
  48421. return new Jog(attrs);
  48422. }
  48423. static labelPrinter(attrs) {
  48424. return new LabelPrinter(attrs);
  48425. }
  48426. static layout(attrs) {
  48427. return new Layout(attrs);
  48428. }
  48429. static level(attrs) {
  48430. return new Level(attrs);
  48431. }
  48432. static linearized(attrs) {
  48433. return new Linearized(attrs);
  48434. }
  48435. static locale(attrs) {
  48436. return new Locale(attrs);
  48437. }
  48438. static localeSet(attrs) {
  48439. return new LocaleSet(attrs);
  48440. }
  48441. static log(attrs) {
  48442. return new Log(attrs);
  48443. }
  48444. static map(attrs) {
  48445. return new MapElement(attrs);
  48446. }
  48447. static mediumInfo(attrs) {
  48448. return new MediumInfo(attrs);
  48449. }
  48450. static message(attrs) {
  48451. return new config_Message(attrs);
  48452. }
  48453. static messaging(attrs) {
  48454. return new Messaging(attrs);
  48455. }
  48456. static mode(attrs) {
  48457. return new Mode(attrs);
  48458. }
  48459. static modifyAnnots(attrs) {
  48460. return new ModifyAnnots(attrs);
  48461. }
  48462. static msgId(attrs) {
  48463. return new MsgId(attrs);
  48464. }
  48465. static nameAttr(attrs) {
  48466. return new NameAttr(attrs);
  48467. }
  48468. static neverEmbed(attrs) {
  48469. return new NeverEmbed(attrs);
  48470. }
  48471. static numberOfCopies(attrs) {
  48472. return new NumberOfCopies(attrs);
  48473. }
  48474. static openAction(attrs) {
  48475. return new OpenAction(attrs);
  48476. }
  48477. static output(attrs) {
  48478. return new Output(attrs);
  48479. }
  48480. static outputBin(attrs) {
  48481. return new OutputBin(attrs);
  48482. }
  48483. static outputXSL(attrs) {
  48484. return new OutputXSL(attrs);
  48485. }
  48486. static overprint(attrs) {
  48487. return new Overprint(attrs);
  48488. }
  48489. static packets(attrs) {
  48490. return new Packets(attrs);
  48491. }
  48492. static pageOffset(attrs) {
  48493. return new PageOffset(attrs);
  48494. }
  48495. static pageRange(attrs) {
  48496. return new PageRange(attrs);
  48497. }
  48498. static pagination(attrs) {
  48499. return new Pagination(attrs);
  48500. }
  48501. static paginationOverride(attrs) {
  48502. return new PaginationOverride(attrs);
  48503. }
  48504. static part(attrs) {
  48505. return new Part(attrs);
  48506. }
  48507. static pcl(attrs) {
  48508. return new Pcl(attrs);
  48509. }
  48510. static pdf(attrs) {
  48511. return new Pdf(attrs);
  48512. }
  48513. static pdfa(attrs) {
  48514. return new Pdfa(attrs);
  48515. }
  48516. static permissions(attrs) {
  48517. return new Permissions(attrs);
  48518. }
  48519. static pickTrayByPDFSize(attrs) {
  48520. return new PickTrayByPDFSize(attrs);
  48521. }
  48522. static picture(attrs) {
  48523. return new config_Picture(attrs);
  48524. }
  48525. static plaintextMetadata(attrs) {
  48526. return new PlaintextMetadata(attrs);
  48527. }
  48528. static presence(attrs) {
  48529. return new Presence(attrs);
  48530. }
  48531. static present(attrs) {
  48532. return new Present(attrs);
  48533. }
  48534. static print(attrs) {
  48535. return new Print(attrs);
  48536. }
  48537. static printHighQuality(attrs) {
  48538. return new PrintHighQuality(attrs);
  48539. }
  48540. static printScaling(attrs) {
  48541. return new PrintScaling(attrs);
  48542. }
  48543. static printerName(attrs) {
  48544. return new PrinterName(attrs);
  48545. }
  48546. static producer(attrs) {
  48547. return new Producer(attrs);
  48548. }
  48549. static ps(attrs) {
  48550. return new Ps(attrs);
  48551. }
  48552. static range(attrs) {
  48553. return new Range(attrs);
  48554. }
  48555. static record(attrs) {
  48556. return new Record(attrs);
  48557. }
  48558. static relevant(attrs) {
  48559. return new Relevant(attrs);
  48560. }
  48561. static rename(attrs) {
  48562. return new Rename(attrs);
  48563. }
  48564. static renderPolicy(attrs) {
  48565. return new RenderPolicy(attrs);
  48566. }
  48567. static runScripts(attrs) {
  48568. return new RunScripts(attrs);
  48569. }
  48570. static script(attrs) {
  48571. return new config_Script(attrs);
  48572. }
  48573. static scriptModel(attrs) {
  48574. return new ScriptModel(attrs);
  48575. }
  48576. static severity(attrs) {
  48577. return new Severity(attrs);
  48578. }
  48579. static silentPrint(attrs) {
  48580. return new SilentPrint(attrs);
  48581. }
  48582. static staple(attrs) {
  48583. return new Staple(attrs);
  48584. }
  48585. static startNode(attrs) {
  48586. return new StartNode(attrs);
  48587. }
  48588. static startPage(attrs) {
  48589. return new StartPage(attrs);
  48590. }
  48591. static submitFormat(attrs) {
  48592. return new SubmitFormat(attrs);
  48593. }
  48594. static submitUrl(attrs) {
  48595. return new SubmitUrl(attrs);
  48596. }
  48597. static subsetBelow(attrs) {
  48598. return new SubsetBelow(attrs);
  48599. }
  48600. static suppressBanner(attrs) {
  48601. return new SuppressBanner(attrs);
  48602. }
  48603. static tagged(attrs) {
  48604. return new Tagged(attrs);
  48605. }
  48606. static template(attrs) {
  48607. return new config_Template(attrs);
  48608. }
  48609. static templateCache(attrs) {
  48610. return new TemplateCache(attrs);
  48611. }
  48612. static threshold(attrs) {
  48613. return new Threshold(attrs);
  48614. }
  48615. static to(attrs) {
  48616. return new To(attrs);
  48617. }
  48618. static trace(attrs) {
  48619. return new Trace(attrs);
  48620. }
  48621. static transform(attrs) {
  48622. return new config_Transform(attrs);
  48623. }
  48624. static type(attrs) {
  48625. return new Type(attrs);
  48626. }
  48627. static uri(attrs) {
  48628. return new Uri(attrs);
  48629. }
  48630. static validate(attrs) {
  48631. return new config_Validate(attrs);
  48632. }
  48633. static validateApprovalSignatures(attrs) {
  48634. return new ValidateApprovalSignatures(attrs);
  48635. }
  48636. static validationMessaging(attrs) {
  48637. return new ValidationMessaging(attrs);
  48638. }
  48639. static version(attrs) {
  48640. return new Version(attrs);
  48641. }
  48642. static versionControl(attrs) {
  48643. return new VersionControl(attrs);
  48644. }
  48645. static viewerPreferences(attrs) {
  48646. return new ViewerPreferences(attrs);
  48647. }
  48648. static webClient(attrs) {
  48649. return new WebClient(attrs);
  48650. }
  48651. static whitespace(attrs) {
  48652. return new Whitespace(attrs);
  48653. }
  48654. static window(attrs) {
  48655. return new Window(attrs);
  48656. }
  48657. static xdc(attrs) {
  48658. return new Xdc(attrs);
  48659. }
  48660. static xdp(attrs) {
  48661. return new Xdp(attrs);
  48662. }
  48663. static xsl(attrs) {
  48664. return new Xsl(attrs);
  48665. }
  48666. static zpl(attrs) {
  48667. return new Zpl(attrs);
  48668. }
  48669. }
  48670. ;// CONCATENATED MODULE: ./src/core/xfa/connection_set.js
  48671. const CONNECTION_SET_NS_ID = NamespaceIds.connectionSet.id;
  48672. class ConnectionSet extends XFAObject {
  48673. constructor(attributes) {
  48674. super(CONNECTION_SET_NS_ID, "connectionSet", true);
  48675. this.wsdlConnection = new XFAObjectArray();
  48676. this.xmlConnection = new XFAObjectArray();
  48677. this.xsdConnection = new XFAObjectArray();
  48678. }
  48679. }
  48680. class EffectiveInputPolicy extends XFAObject {
  48681. constructor(attributes) {
  48682. super(CONNECTION_SET_NS_ID, "effectiveInputPolicy");
  48683. this.id = attributes.id || "";
  48684. this.name = attributes.name || "";
  48685. this.use = attributes.use || "";
  48686. this.usehref = attributes.usehref || "";
  48687. }
  48688. }
  48689. class EffectiveOutputPolicy extends XFAObject {
  48690. constructor(attributes) {
  48691. super(CONNECTION_SET_NS_ID, "effectiveOutputPolicy");
  48692. this.id = attributes.id || "";
  48693. this.name = attributes.name || "";
  48694. this.use = attributes.use || "";
  48695. this.usehref = attributes.usehref || "";
  48696. }
  48697. }
  48698. class Operation extends StringObject {
  48699. constructor(attributes) {
  48700. super(CONNECTION_SET_NS_ID, "operation");
  48701. this.id = attributes.id || "";
  48702. this.input = attributes.input || "";
  48703. this.name = attributes.name || "";
  48704. this.output = attributes.output || "";
  48705. this.use = attributes.use || "";
  48706. this.usehref = attributes.usehref || "";
  48707. }
  48708. }
  48709. class RootElement extends StringObject {
  48710. constructor(attributes) {
  48711. super(CONNECTION_SET_NS_ID, "rootElement");
  48712. this.id = attributes.id || "";
  48713. this.name = attributes.name || "";
  48714. this.use = attributes.use || "";
  48715. this.usehref = attributes.usehref || "";
  48716. }
  48717. }
  48718. class SoapAction extends StringObject {
  48719. constructor(attributes) {
  48720. super(CONNECTION_SET_NS_ID, "soapAction");
  48721. this.id = attributes.id || "";
  48722. this.name = attributes.name || "";
  48723. this.use = attributes.use || "";
  48724. this.usehref = attributes.usehref || "";
  48725. }
  48726. }
  48727. class SoapAddress extends StringObject {
  48728. constructor(attributes) {
  48729. super(CONNECTION_SET_NS_ID, "soapAddress");
  48730. this.id = attributes.id || "";
  48731. this.name = attributes.name || "";
  48732. this.use = attributes.use || "";
  48733. this.usehref = attributes.usehref || "";
  48734. }
  48735. }
  48736. class connection_set_Uri extends StringObject {
  48737. constructor(attributes) {
  48738. super(CONNECTION_SET_NS_ID, "uri");
  48739. this.id = attributes.id || "";
  48740. this.name = attributes.name || "";
  48741. this.use = attributes.use || "";
  48742. this.usehref = attributes.usehref || "";
  48743. }
  48744. }
  48745. class WsdlAddress extends StringObject {
  48746. constructor(attributes) {
  48747. super(CONNECTION_SET_NS_ID, "wsdlAddress");
  48748. this.id = attributes.id || "";
  48749. this.name = attributes.name || "";
  48750. this.use = attributes.use || "";
  48751. this.usehref = attributes.usehref || "";
  48752. }
  48753. }
  48754. class WsdlConnection extends XFAObject {
  48755. constructor(attributes) {
  48756. super(CONNECTION_SET_NS_ID, "wsdlConnection", true);
  48757. this.dataDescription = attributes.dataDescription || "";
  48758. this.name = attributes.name || "";
  48759. this.effectiveInputPolicy = null;
  48760. this.effectiveOutputPolicy = null;
  48761. this.operation = null;
  48762. this.soapAction = null;
  48763. this.soapAddress = null;
  48764. this.wsdlAddress = null;
  48765. }
  48766. }
  48767. class XmlConnection extends XFAObject {
  48768. constructor(attributes) {
  48769. super(CONNECTION_SET_NS_ID, "xmlConnection", true);
  48770. this.dataDescription = attributes.dataDescription || "";
  48771. this.name = attributes.name || "";
  48772. this.uri = null;
  48773. }
  48774. }
  48775. class XsdConnection extends XFAObject {
  48776. constructor(attributes) {
  48777. super(CONNECTION_SET_NS_ID, "xsdConnection", true);
  48778. this.dataDescription = attributes.dataDescription || "";
  48779. this.name = attributes.name || "";
  48780. this.rootElement = null;
  48781. this.uri = null;
  48782. }
  48783. }
  48784. class ConnectionSetNamespace {
  48785. static [$buildXFAObject](name, attributes) {
  48786. if (ConnectionSetNamespace.hasOwnProperty(name)) {
  48787. return ConnectionSetNamespace[name](attributes);
  48788. }
  48789. return undefined;
  48790. }
  48791. static connectionSet(attrs) {
  48792. return new ConnectionSet(attrs);
  48793. }
  48794. static effectiveInputPolicy(attrs) {
  48795. return new EffectiveInputPolicy(attrs);
  48796. }
  48797. static effectiveOutputPolicy(attrs) {
  48798. return new EffectiveOutputPolicy(attrs);
  48799. }
  48800. static operation(attrs) {
  48801. return new Operation(attrs);
  48802. }
  48803. static rootElement(attrs) {
  48804. return new RootElement(attrs);
  48805. }
  48806. static soapAction(attrs) {
  48807. return new SoapAction(attrs);
  48808. }
  48809. static soapAddress(attrs) {
  48810. return new SoapAddress(attrs);
  48811. }
  48812. static uri(attrs) {
  48813. return new connection_set_Uri(attrs);
  48814. }
  48815. static wsdlAddress(attrs) {
  48816. return new WsdlAddress(attrs);
  48817. }
  48818. static wsdlConnection(attrs) {
  48819. return new WsdlConnection(attrs);
  48820. }
  48821. static xmlConnection(attrs) {
  48822. return new XmlConnection(attrs);
  48823. }
  48824. static xsdConnection(attrs) {
  48825. return new XsdConnection(attrs);
  48826. }
  48827. }
  48828. ;// CONCATENATED MODULE: ./src/core/xfa/datasets.js
  48829. const DATASETS_NS_ID = NamespaceIds.datasets.id;
  48830. class datasets_Data extends XmlObject {
  48831. constructor(attributes) {
  48832. super(DATASETS_NS_ID, "data", attributes);
  48833. }
  48834. [$isNsAgnostic]() {
  48835. return true;
  48836. }
  48837. }
  48838. class Datasets extends XFAObject {
  48839. constructor(attributes) {
  48840. super(DATASETS_NS_ID, "datasets", true);
  48841. this.data = null;
  48842. this.Signature = null;
  48843. }
  48844. [$onChild](child) {
  48845. const name = child[$nodeName];
  48846. if (name === "data" && child[$namespaceId] === DATASETS_NS_ID || name === "Signature" && child[$namespaceId] === NamespaceIds.signature.id) {
  48847. this[name] = child;
  48848. }
  48849. this[$appendChild](child);
  48850. }
  48851. }
  48852. class DatasetsNamespace {
  48853. static [$buildXFAObject](name, attributes) {
  48854. if (DatasetsNamespace.hasOwnProperty(name)) {
  48855. return DatasetsNamespace[name](attributes);
  48856. }
  48857. return undefined;
  48858. }
  48859. static datasets(attributes) {
  48860. return new Datasets(attributes);
  48861. }
  48862. static data(attributes) {
  48863. return new datasets_Data(attributes);
  48864. }
  48865. }
  48866. ;// CONCATENATED MODULE: ./src/core/xfa/locale_set.js
  48867. const LOCALE_SET_NS_ID = NamespaceIds.localeSet.id;
  48868. class CalendarSymbols extends XFAObject {
  48869. constructor(attributes) {
  48870. super(LOCALE_SET_NS_ID, "calendarSymbols", true);
  48871. this.name = "gregorian";
  48872. this.dayNames = new XFAObjectArray(2);
  48873. this.eraNames = null;
  48874. this.meridiemNames = null;
  48875. this.monthNames = new XFAObjectArray(2);
  48876. }
  48877. }
  48878. class CurrencySymbol extends StringObject {
  48879. constructor(attributes) {
  48880. super(LOCALE_SET_NS_ID, "currencySymbol");
  48881. this.name = getStringOption(attributes.name, ["symbol", "isoname", "decimal"]);
  48882. }
  48883. }
  48884. class CurrencySymbols extends XFAObject {
  48885. constructor(attributes) {
  48886. super(LOCALE_SET_NS_ID, "currencySymbols", true);
  48887. this.currencySymbol = new XFAObjectArray(3);
  48888. }
  48889. }
  48890. class DatePattern extends StringObject {
  48891. constructor(attributes) {
  48892. super(LOCALE_SET_NS_ID, "datePattern");
  48893. this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]);
  48894. }
  48895. }
  48896. class DatePatterns extends XFAObject {
  48897. constructor(attributes) {
  48898. super(LOCALE_SET_NS_ID, "datePatterns", true);
  48899. this.datePattern = new XFAObjectArray(4);
  48900. }
  48901. }
  48902. class DateTimeSymbols extends ContentObject {
  48903. constructor(attributes) {
  48904. super(LOCALE_SET_NS_ID, "dateTimeSymbols");
  48905. }
  48906. }
  48907. class Day extends StringObject {
  48908. constructor(attributes) {
  48909. super(LOCALE_SET_NS_ID, "day");
  48910. }
  48911. }
  48912. class DayNames extends XFAObject {
  48913. constructor(attributes) {
  48914. super(LOCALE_SET_NS_ID, "dayNames", true);
  48915. this.abbr = getInteger({
  48916. data: attributes.abbr,
  48917. defaultValue: 0,
  48918. validate: x => x === 1
  48919. });
  48920. this.day = new XFAObjectArray(7);
  48921. }
  48922. }
  48923. class Era extends StringObject {
  48924. constructor(attributes) {
  48925. super(LOCALE_SET_NS_ID, "era");
  48926. }
  48927. }
  48928. class EraNames extends XFAObject {
  48929. constructor(attributes) {
  48930. super(LOCALE_SET_NS_ID, "eraNames", true);
  48931. this.era = new XFAObjectArray(2);
  48932. }
  48933. }
  48934. class locale_set_Locale extends XFAObject {
  48935. constructor(attributes) {
  48936. super(LOCALE_SET_NS_ID, "locale", true);
  48937. this.desc = attributes.desc || "";
  48938. this.name = "isoname";
  48939. this.calendarSymbols = null;
  48940. this.currencySymbols = null;
  48941. this.datePatterns = null;
  48942. this.dateTimeSymbols = null;
  48943. this.numberPatterns = null;
  48944. this.numberSymbols = null;
  48945. this.timePatterns = null;
  48946. this.typeFaces = null;
  48947. }
  48948. }
  48949. class locale_set_LocaleSet extends XFAObject {
  48950. constructor(attributes) {
  48951. super(LOCALE_SET_NS_ID, "localeSet", true);
  48952. this.locale = new XFAObjectArray();
  48953. }
  48954. }
  48955. class Meridiem extends StringObject {
  48956. constructor(attributes) {
  48957. super(LOCALE_SET_NS_ID, "meridiem");
  48958. }
  48959. }
  48960. class MeridiemNames extends XFAObject {
  48961. constructor(attributes) {
  48962. super(LOCALE_SET_NS_ID, "meridiemNames", true);
  48963. this.meridiem = new XFAObjectArray(2);
  48964. }
  48965. }
  48966. class Month extends StringObject {
  48967. constructor(attributes) {
  48968. super(LOCALE_SET_NS_ID, "month");
  48969. }
  48970. }
  48971. class MonthNames extends XFAObject {
  48972. constructor(attributes) {
  48973. super(LOCALE_SET_NS_ID, "monthNames", true);
  48974. this.abbr = getInteger({
  48975. data: attributes.abbr,
  48976. defaultValue: 0,
  48977. validate: x => x === 1
  48978. });
  48979. this.month = new XFAObjectArray(12);
  48980. }
  48981. }
  48982. class NumberPattern extends StringObject {
  48983. constructor(attributes) {
  48984. super(LOCALE_SET_NS_ID, "numberPattern");
  48985. this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]);
  48986. }
  48987. }
  48988. class NumberPatterns extends XFAObject {
  48989. constructor(attributes) {
  48990. super(LOCALE_SET_NS_ID, "numberPatterns", true);
  48991. this.numberPattern = new XFAObjectArray(4);
  48992. }
  48993. }
  48994. class NumberSymbol extends StringObject {
  48995. constructor(attributes) {
  48996. super(LOCALE_SET_NS_ID, "numberSymbol");
  48997. this.name = getStringOption(attributes.name, ["decimal", "grouping", "percent", "minus", "zero"]);
  48998. }
  48999. }
  49000. class NumberSymbols extends XFAObject {
  49001. constructor(attributes) {
  49002. super(LOCALE_SET_NS_ID, "numberSymbols", true);
  49003. this.numberSymbol = new XFAObjectArray(5);
  49004. }
  49005. }
  49006. class TimePattern extends StringObject {
  49007. constructor(attributes) {
  49008. super(LOCALE_SET_NS_ID, "timePattern");
  49009. this.name = getStringOption(attributes.name, ["full", "long", "med", "short"]);
  49010. }
  49011. }
  49012. class TimePatterns extends XFAObject {
  49013. constructor(attributes) {
  49014. super(LOCALE_SET_NS_ID, "timePatterns", true);
  49015. this.timePattern = new XFAObjectArray(4);
  49016. }
  49017. }
  49018. class TypeFace extends XFAObject {
  49019. constructor(attributes) {
  49020. super(LOCALE_SET_NS_ID, "typeFace", true);
  49021. this.name = attributes.name | "";
  49022. }
  49023. }
  49024. class TypeFaces extends XFAObject {
  49025. constructor(attributes) {
  49026. super(LOCALE_SET_NS_ID, "typeFaces", true);
  49027. this.typeFace = new XFAObjectArray();
  49028. }
  49029. }
  49030. class LocaleSetNamespace {
  49031. static [$buildXFAObject](name, attributes) {
  49032. if (LocaleSetNamespace.hasOwnProperty(name)) {
  49033. return LocaleSetNamespace[name](attributes);
  49034. }
  49035. return undefined;
  49036. }
  49037. static calendarSymbols(attrs) {
  49038. return new CalendarSymbols(attrs);
  49039. }
  49040. static currencySymbol(attrs) {
  49041. return new CurrencySymbol(attrs);
  49042. }
  49043. static currencySymbols(attrs) {
  49044. return new CurrencySymbols(attrs);
  49045. }
  49046. static datePattern(attrs) {
  49047. return new DatePattern(attrs);
  49048. }
  49049. static datePatterns(attrs) {
  49050. return new DatePatterns(attrs);
  49051. }
  49052. static dateTimeSymbols(attrs) {
  49053. return new DateTimeSymbols(attrs);
  49054. }
  49055. static day(attrs) {
  49056. return new Day(attrs);
  49057. }
  49058. static dayNames(attrs) {
  49059. return new DayNames(attrs);
  49060. }
  49061. static era(attrs) {
  49062. return new Era(attrs);
  49063. }
  49064. static eraNames(attrs) {
  49065. return new EraNames(attrs);
  49066. }
  49067. static locale(attrs) {
  49068. return new locale_set_Locale(attrs);
  49069. }
  49070. static localeSet(attrs) {
  49071. return new locale_set_LocaleSet(attrs);
  49072. }
  49073. static meridiem(attrs) {
  49074. return new Meridiem(attrs);
  49075. }
  49076. static meridiemNames(attrs) {
  49077. return new MeridiemNames(attrs);
  49078. }
  49079. static month(attrs) {
  49080. return new Month(attrs);
  49081. }
  49082. static monthNames(attrs) {
  49083. return new MonthNames(attrs);
  49084. }
  49085. static numberPattern(attrs) {
  49086. return new NumberPattern(attrs);
  49087. }
  49088. static numberPatterns(attrs) {
  49089. return new NumberPatterns(attrs);
  49090. }
  49091. static numberSymbol(attrs) {
  49092. return new NumberSymbol(attrs);
  49093. }
  49094. static numberSymbols(attrs) {
  49095. return new NumberSymbols(attrs);
  49096. }
  49097. static timePattern(attrs) {
  49098. return new TimePattern(attrs);
  49099. }
  49100. static timePatterns(attrs) {
  49101. return new TimePatterns(attrs);
  49102. }
  49103. static typeFace(attrs) {
  49104. return new TypeFace(attrs);
  49105. }
  49106. static typeFaces(attrs) {
  49107. return new TypeFaces(attrs);
  49108. }
  49109. }
  49110. ;// CONCATENATED MODULE: ./src/core/xfa/signature.js
  49111. const SIGNATURE_NS_ID = NamespaceIds.signature.id;
  49112. class signature_Signature extends XFAObject {
  49113. constructor(attributes) {
  49114. super(SIGNATURE_NS_ID, "signature", true);
  49115. }
  49116. }
  49117. class SignatureNamespace {
  49118. static [$buildXFAObject](name, attributes) {
  49119. if (SignatureNamespace.hasOwnProperty(name)) {
  49120. return SignatureNamespace[name](attributes);
  49121. }
  49122. return undefined;
  49123. }
  49124. static signature(attributes) {
  49125. return new signature_Signature(attributes);
  49126. }
  49127. }
  49128. ;// CONCATENATED MODULE: ./src/core/xfa/stylesheet.js
  49129. const STYLESHEET_NS_ID = NamespaceIds.stylesheet.id;
  49130. class Stylesheet extends XFAObject {
  49131. constructor(attributes) {
  49132. super(STYLESHEET_NS_ID, "stylesheet", true);
  49133. }
  49134. }
  49135. class StylesheetNamespace {
  49136. static [$buildXFAObject](name, attributes) {
  49137. if (StylesheetNamespace.hasOwnProperty(name)) {
  49138. return StylesheetNamespace[name](attributes);
  49139. }
  49140. return undefined;
  49141. }
  49142. static stylesheet(attributes) {
  49143. return new Stylesheet(attributes);
  49144. }
  49145. }
  49146. ;// CONCATENATED MODULE: ./src/core/xfa/xdp.js
  49147. const XDP_NS_ID = NamespaceIds.xdp.id;
  49148. class xdp_Xdp extends XFAObject {
  49149. constructor(attributes) {
  49150. super(XDP_NS_ID, "xdp", true);
  49151. this.uuid = attributes.uuid || "";
  49152. this.timeStamp = attributes.timeStamp || "";
  49153. this.config = null;
  49154. this.connectionSet = null;
  49155. this.datasets = null;
  49156. this.localeSet = null;
  49157. this.stylesheet = new XFAObjectArray();
  49158. this.template = null;
  49159. }
  49160. [$onChildCheck](child) {
  49161. const ns = NamespaceIds[child[$nodeName]];
  49162. return ns && child[$namespaceId] === ns.id;
  49163. }
  49164. }
  49165. class XdpNamespace {
  49166. static [$buildXFAObject](name, attributes) {
  49167. if (XdpNamespace.hasOwnProperty(name)) {
  49168. return XdpNamespace[name](attributes);
  49169. }
  49170. return undefined;
  49171. }
  49172. static xdp(attributes) {
  49173. return new xdp_Xdp(attributes);
  49174. }
  49175. }
  49176. ;// CONCATENATED MODULE: ./src/core/xfa/xhtml.js
  49177. const XHTML_NS_ID = NamespaceIds.xhtml.id;
  49178. const $richText = Symbol();
  49179. const VALID_STYLES = new Set(["color", "font", "font-family", "font-size", "font-stretch", "font-style", "font-weight", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", "letter-spacing", "line-height", "orphans", "page-break-after", "page-break-before", "page-break-inside", "tab-interval", "tab-stop", "text-align", "text-decoration", "text-indent", "vertical-align", "widows", "kerning-mode", "xfa-font-horizontal-scale", "xfa-font-vertical-scale", "xfa-spacerun", "xfa-tab-stops"]);
  49180. const StyleMapping = new Map([["page-break-after", "breakAfter"], ["page-break-before", "breakBefore"], ["page-break-inside", "breakInside"], ["kerning-mode", value => value === "none" ? "none" : "normal"], ["xfa-font-horizontal-scale", value => `scaleX(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`], ["xfa-font-vertical-scale", value => `scaleY(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`], ["xfa-spacerun", ""], ["xfa-tab-stops", ""], ["font-size", (value, original) => {
  49181. value = original.fontSize = getMeasurement(value);
  49182. return measureToString(0.99 * value);
  49183. }], ["letter-spacing", value => measureToString(getMeasurement(value))], ["line-height", value => measureToString(getMeasurement(value))], ["margin", value => measureToString(getMeasurement(value))], ["margin-bottom", value => measureToString(getMeasurement(value))], ["margin-left", value => measureToString(getMeasurement(value))], ["margin-right", value => measureToString(getMeasurement(value))], ["margin-top", value => measureToString(getMeasurement(value))], ["text-indent", value => measureToString(getMeasurement(value))], ["font-family", value => value], ["vertical-align", value => measureToString(getMeasurement(value))]]);
  49184. const spacesRegExp = /\s+/g;
  49185. const crlfRegExp = /[\r\n]+/g;
  49186. const crlfForRichTextRegExp = /\r\n?/g;
  49187. function mapStyle(styleStr, node, richText) {
  49188. const style = Object.create(null);
  49189. if (!styleStr) {
  49190. return style;
  49191. }
  49192. const original = Object.create(null);
  49193. for (const [key, value] of styleStr.split(";").map(s => s.split(":", 2))) {
  49194. const mapping = StyleMapping.get(key);
  49195. if (mapping === "") {
  49196. continue;
  49197. }
  49198. let newValue = value;
  49199. if (mapping) {
  49200. newValue = typeof mapping === "string" ? mapping : mapping(value, original);
  49201. }
  49202. if (key.endsWith("scale")) {
  49203. style.transform = style.transform ? `${style[key]} ${newValue}` : newValue;
  49204. } else {
  49205. style[key.replaceAll(/-([a-zA-Z])/g, (_, x) => x.toUpperCase())] = newValue;
  49206. }
  49207. }
  49208. if (style.fontFamily) {
  49209. setFontFamily({
  49210. typeface: style.fontFamily,
  49211. weight: style.fontWeight || "normal",
  49212. posture: style.fontStyle || "normal",
  49213. size: original.fontSize || 0
  49214. }, node, node[$globalData].fontFinder, style);
  49215. }
  49216. if (richText && style.verticalAlign && style.verticalAlign !== "0px" && style.fontSize) {
  49217. const SUB_SUPER_SCRIPT_FACTOR = 0.583;
  49218. const VERTICAL_FACTOR = 0.333;
  49219. const fontSize = getMeasurement(style.fontSize);
  49220. style.fontSize = measureToString(fontSize * SUB_SUPER_SCRIPT_FACTOR);
  49221. style.verticalAlign = measureToString(Math.sign(getMeasurement(style.verticalAlign)) * fontSize * VERTICAL_FACTOR);
  49222. }
  49223. if (richText && style.fontSize) {
  49224. style.fontSize = `calc(${style.fontSize} * var(--scale-factor))`;
  49225. }
  49226. fixTextIndent(style);
  49227. return style;
  49228. }
  49229. function checkStyle(node) {
  49230. if (!node.style) {
  49231. return "";
  49232. }
  49233. return node.style.trim().split(/\s*;\s*/).filter(s => !!s).map(s => s.split(/\s*:\s*/, 2)).filter(([key, value]) => {
  49234. if (key === "font-family") {
  49235. node[$globalData].usedTypefaces.add(value);
  49236. }
  49237. return VALID_STYLES.has(key);
  49238. }).map(kv => kv.join(":")).join(";");
  49239. }
  49240. const NoWhites = new Set(["body", "html"]);
  49241. class XhtmlObject extends XmlObject {
  49242. constructor(attributes, name) {
  49243. super(XHTML_NS_ID, name);
  49244. this[$richText] = false;
  49245. this.style = attributes.style || "";
  49246. }
  49247. [$clean](builder) {
  49248. super[$clean](builder);
  49249. this.style = checkStyle(this);
  49250. }
  49251. [$acceptWhitespace]() {
  49252. return !NoWhites.has(this[$nodeName]);
  49253. }
  49254. [$onText](str, richText = false) {
  49255. if (!richText) {
  49256. str = str.replaceAll(crlfRegExp, "");
  49257. if (!this.style.includes("xfa-spacerun:yes")) {
  49258. str = str.replaceAll(spacesRegExp, " ");
  49259. }
  49260. } else {
  49261. this[$richText] = true;
  49262. }
  49263. if (str) {
  49264. this[$content] += str;
  49265. }
  49266. }
  49267. [$pushGlyphs](measure, mustPop = true) {
  49268. const xfaFont = Object.create(null);
  49269. const margin = {
  49270. top: NaN,
  49271. bottom: NaN,
  49272. left: NaN,
  49273. right: NaN
  49274. };
  49275. let lineHeight = null;
  49276. for (const [key, value] of this.style.split(";").map(s => s.split(":", 2))) {
  49277. switch (key) {
  49278. case "font-family":
  49279. xfaFont.typeface = stripQuotes(value);
  49280. break;
  49281. case "font-size":
  49282. xfaFont.size = getMeasurement(value);
  49283. break;
  49284. case "font-weight":
  49285. xfaFont.weight = value;
  49286. break;
  49287. case "font-style":
  49288. xfaFont.posture = value;
  49289. break;
  49290. case "letter-spacing":
  49291. xfaFont.letterSpacing = getMeasurement(value);
  49292. break;
  49293. case "margin":
  49294. const values = value.split(/ \t/).map(x => getMeasurement(x));
  49295. switch (values.length) {
  49296. case 1:
  49297. margin.top = margin.bottom = margin.left = margin.right = values[0];
  49298. break;
  49299. case 2:
  49300. margin.top = margin.bottom = values[0];
  49301. margin.left = margin.right = values[1];
  49302. break;
  49303. case 3:
  49304. margin.top = values[0];
  49305. margin.bottom = values[2];
  49306. margin.left = margin.right = values[1];
  49307. break;
  49308. case 4:
  49309. margin.top = values[0];
  49310. margin.left = values[1];
  49311. margin.bottom = values[2];
  49312. margin.right = values[3];
  49313. break;
  49314. }
  49315. break;
  49316. case "margin-top":
  49317. margin.top = getMeasurement(value);
  49318. break;
  49319. case "margin-bottom":
  49320. margin.bottom = getMeasurement(value);
  49321. break;
  49322. case "margin-left":
  49323. margin.left = getMeasurement(value);
  49324. break;
  49325. case "margin-right":
  49326. margin.right = getMeasurement(value);
  49327. break;
  49328. case "line-height":
  49329. lineHeight = getMeasurement(value);
  49330. break;
  49331. }
  49332. }
  49333. measure.pushData(xfaFont, margin, lineHeight);
  49334. if (this[$content]) {
  49335. measure.addString(this[$content]);
  49336. } else {
  49337. for (const child of this[$getChildren]()) {
  49338. if (child[$nodeName] === "#text") {
  49339. measure.addString(child[$content]);
  49340. continue;
  49341. }
  49342. child[$pushGlyphs](measure);
  49343. }
  49344. }
  49345. if (mustPop) {
  49346. measure.popFont();
  49347. }
  49348. }
  49349. [$toHTML](availableSpace) {
  49350. const children = [];
  49351. this[$extra] = {
  49352. children
  49353. };
  49354. this[$childrenToHTML]({});
  49355. if (children.length === 0 && !this[$content]) {
  49356. return HTMLResult.EMPTY;
  49357. }
  49358. let value;
  49359. if (this[$richText]) {
  49360. value = this[$content] ? this[$content].replaceAll(crlfForRichTextRegExp, "\n") : undefined;
  49361. } else {
  49362. value = this[$content] || undefined;
  49363. }
  49364. return HTMLResult.success({
  49365. name: this[$nodeName],
  49366. attributes: {
  49367. href: this.href,
  49368. style: mapStyle(this.style, this, this[$richText])
  49369. },
  49370. children,
  49371. value
  49372. });
  49373. }
  49374. }
  49375. class A extends XhtmlObject {
  49376. constructor(attributes) {
  49377. super(attributes, "a");
  49378. this.href = fixURL(attributes.href) || "";
  49379. }
  49380. }
  49381. class B extends XhtmlObject {
  49382. constructor(attributes) {
  49383. super(attributes, "b");
  49384. }
  49385. [$pushGlyphs](measure) {
  49386. measure.pushFont({
  49387. weight: "bold"
  49388. });
  49389. super[$pushGlyphs](measure);
  49390. measure.popFont();
  49391. }
  49392. }
  49393. class Body extends XhtmlObject {
  49394. constructor(attributes) {
  49395. super(attributes, "body");
  49396. }
  49397. [$toHTML](availableSpace) {
  49398. const res = super[$toHTML](availableSpace);
  49399. const {
  49400. html
  49401. } = res;
  49402. if (!html) {
  49403. return HTMLResult.EMPTY;
  49404. }
  49405. html.name = "div";
  49406. html.attributes.class = ["xfaRich"];
  49407. return res;
  49408. }
  49409. }
  49410. class Br extends XhtmlObject {
  49411. constructor(attributes) {
  49412. super(attributes, "br");
  49413. }
  49414. [$text]() {
  49415. return "\n";
  49416. }
  49417. [$pushGlyphs](measure) {
  49418. measure.addString("\n");
  49419. }
  49420. [$toHTML](availableSpace) {
  49421. return HTMLResult.success({
  49422. name: "br"
  49423. });
  49424. }
  49425. }
  49426. class Html extends XhtmlObject {
  49427. constructor(attributes) {
  49428. super(attributes, "html");
  49429. }
  49430. [$toHTML](availableSpace) {
  49431. const children = [];
  49432. this[$extra] = {
  49433. children
  49434. };
  49435. this[$childrenToHTML]({});
  49436. if (children.length === 0) {
  49437. return HTMLResult.success({
  49438. name: "div",
  49439. attributes: {
  49440. class: ["xfaRich"],
  49441. style: {}
  49442. },
  49443. value: this[$content] || ""
  49444. });
  49445. }
  49446. if (children.length === 1) {
  49447. const child = children[0];
  49448. if (child.attributes?.class.includes("xfaRich")) {
  49449. return HTMLResult.success(child);
  49450. }
  49451. }
  49452. return HTMLResult.success({
  49453. name: "div",
  49454. attributes: {
  49455. class: ["xfaRich"],
  49456. style: {}
  49457. },
  49458. children
  49459. });
  49460. }
  49461. }
  49462. class I extends XhtmlObject {
  49463. constructor(attributes) {
  49464. super(attributes, "i");
  49465. }
  49466. [$pushGlyphs](measure) {
  49467. measure.pushFont({
  49468. posture: "italic"
  49469. });
  49470. super[$pushGlyphs](measure);
  49471. measure.popFont();
  49472. }
  49473. }
  49474. class Li extends XhtmlObject {
  49475. constructor(attributes) {
  49476. super(attributes, "li");
  49477. }
  49478. }
  49479. class Ol extends XhtmlObject {
  49480. constructor(attributes) {
  49481. super(attributes, "ol");
  49482. }
  49483. }
  49484. class P extends XhtmlObject {
  49485. constructor(attributes) {
  49486. super(attributes, "p");
  49487. }
  49488. [$pushGlyphs](measure) {
  49489. super[$pushGlyphs](measure, false);
  49490. measure.addString("\n");
  49491. measure.addPara();
  49492. measure.popFont();
  49493. }
  49494. [$text]() {
  49495. const siblings = this[$getParent]()[$getChildren]();
  49496. if (siblings.at(-1) === this) {
  49497. return super[$text]();
  49498. }
  49499. return super[$text]() + "\n";
  49500. }
  49501. }
  49502. class Span extends XhtmlObject {
  49503. constructor(attributes) {
  49504. super(attributes, "span");
  49505. }
  49506. }
  49507. class Sub extends XhtmlObject {
  49508. constructor(attributes) {
  49509. super(attributes, "sub");
  49510. }
  49511. }
  49512. class Sup extends XhtmlObject {
  49513. constructor(attributes) {
  49514. super(attributes, "sup");
  49515. }
  49516. }
  49517. class Ul extends XhtmlObject {
  49518. constructor(attributes) {
  49519. super(attributes, "ul");
  49520. }
  49521. }
  49522. class XhtmlNamespace {
  49523. static [$buildXFAObject](name, attributes) {
  49524. if (XhtmlNamespace.hasOwnProperty(name)) {
  49525. return XhtmlNamespace[name](attributes);
  49526. }
  49527. return undefined;
  49528. }
  49529. static a(attributes) {
  49530. return new A(attributes);
  49531. }
  49532. static b(attributes) {
  49533. return new B(attributes);
  49534. }
  49535. static body(attributes) {
  49536. return new Body(attributes);
  49537. }
  49538. static br(attributes) {
  49539. return new Br(attributes);
  49540. }
  49541. static html(attributes) {
  49542. return new Html(attributes);
  49543. }
  49544. static i(attributes) {
  49545. return new I(attributes);
  49546. }
  49547. static li(attributes) {
  49548. return new Li(attributes);
  49549. }
  49550. static ol(attributes) {
  49551. return new Ol(attributes);
  49552. }
  49553. static p(attributes) {
  49554. return new P(attributes);
  49555. }
  49556. static span(attributes) {
  49557. return new Span(attributes);
  49558. }
  49559. static sub(attributes) {
  49560. return new Sub(attributes);
  49561. }
  49562. static sup(attributes) {
  49563. return new Sup(attributes);
  49564. }
  49565. static ul(attributes) {
  49566. return new Ul(attributes);
  49567. }
  49568. }
  49569. ;// CONCATENATED MODULE: ./src/core/xfa/setup.js
  49570. const NamespaceSetUp = {
  49571. config: ConfigNamespace,
  49572. connection: ConnectionSetNamespace,
  49573. datasets: DatasetsNamespace,
  49574. localeSet: LocaleSetNamespace,
  49575. signature: SignatureNamespace,
  49576. stylesheet: StylesheetNamespace,
  49577. template: TemplateNamespace,
  49578. xdp: XdpNamespace,
  49579. xhtml: XhtmlNamespace
  49580. };
  49581. ;// CONCATENATED MODULE: ./src/core/xfa/unknown.js
  49582. class UnknownNamespace {
  49583. constructor(nsId) {
  49584. this.namespaceId = nsId;
  49585. }
  49586. [$buildXFAObject](name, attributes) {
  49587. return new XmlObject(this.namespaceId, name, attributes);
  49588. }
  49589. }
  49590. ;// CONCATENATED MODULE: ./src/core/xfa/builder.js
  49591. class Root extends XFAObject {
  49592. constructor(ids) {
  49593. super(-1, "root", Object.create(null));
  49594. this.element = null;
  49595. this[$ids] = ids;
  49596. }
  49597. [$onChild](child) {
  49598. this.element = child;
  49599. return true;
  49600. }
  49601. [$finalize]() {
  49602. super[$finalize]();
  49603. if (this.element.template instanceof Template) {
  49604. this[$ids].set($root, this.element);
  49605. this.element.template[$resolvePrototypes](this[$ids]);
  49606. this.element.template[$ids] = this[$ids];
  49607. }
  49608. }
  49609. }
  49610. class Empty extends XFAObject {
  49611. constructor() {
  49612. super(-1, "", Object.create(null));
  49613. }
  49614. [$onChild](_) {
  49615. return false;
  49616. }
  49617. }
  49618. class Builder {
  49619. constructor(rootNameSpace = null) {
  49620. this._namespaceStack = [];
  49621. this._nsAgnosticLevel = 0;
  49622. this._namespacePrefixes = new Map();
  49623. this._namespaces = new Map();
  49624. this._nextNsId = Math.max(...Object.values(NamespaceIds).map(({
  49625. id
  49626. }) => id));
  49627. this._currentNamespace = rootNameSpace || new UnknownNamespace(++this._nextNsId);
  49628. }
  49629. buildRoot(ids) {
  49630. return new Root(ids);
  49631. }
  49632. build({
  49633. nsPrefix,
  49634. name,
  49635. attributes,
  49636. namespace,
  49637. prefixes
  49638. }) {
  49639. const hasNamespaceDef = namespace !== null;
  49640. if (hasNamespaceDef) {
  49641. this._namespaceStack.push(this._currentNamespace);
  49642. this._currentNamespace = this._searchNamespace(namespace);
  49643. }
  49644. if (prefixes) {
  49645. this._addNamespacePrefix(prefixes);
  49646. }
  49647. if (attributes.hasOwnProperty($nsAttributes)) {
  49648. const dataTemplate = NamespaceSetUp.datasets;
  49649. const nsAttrs = attributes[$nsAttributes];
  49650. let xfaAttrs = null;
  49651. for (const [ns, attrs] of Object.entries(nsAttrs)) {
  49652. const nsToUse = this._getNamespaceToUse(ns);
  49653. if (nsToUse === dataTemplate) {
  49654. xfaAttrs = {
  49655. xfa: attrs
  49656. };
  49657. break;
  49658. }
  49659. }
  49660. if (xfaAttrs) {
  49661. attributes[$nsAttributes] = xfaAttrs;
  49662. } else {
  49663. delete attributes[$nsAttributes];
  49664. }
  49665. }
  49666. const namespaceToUse = this._getNamespaceToUse(nsPrefix);
  49667. const node = namespaceToUse?.[$buildXFAObject](name, attributes) || new Empty();
  49668. if (node[$isNsAgnostic]()) {
  49669. this._nsAgnosticLevel++;
  49670. }
  49671. if (hasNamespaceDef || prefixes || node[$isNsAgnostic]()) {
  49672. node[$cleanup] = {
  49673. hasNamespace: hasNamespaceDef,
  49674. prefixes,
  49675. nsAgnostic: node[$isNsAgnostic]()
  49676. };
  49677. }
  49678. return node;
  49679. }
  49680. isNsAgnostic() {
  49681. return this._nsAgnosticLevel > 0;
  49682. }
  49683. _searchNamespace(nsName) {
  49684. let ns = this._namespaces.get(nsName);
  49685. if (ns) {
  49686. return ns;
  49687. }
  49688. for (const [name, {
  49689. check
  49690. }] of Object.entries(NamespaceIds)) {
  49691. if (check(nsName)) {
  49692. ns = NamespaceSetUp[name];
  49693. if (ns) {
  49694. this._namespaces.set(nsName, ns);
  49695. return ns;
  49696. }
  49697. break;
  49698. }
  49699. }
  49700. ns = new UnknownNamespace(++this._nextNsId);
  49701. this._namespaces.set(nsName, ns);
  49702. return ns;
  49703. }
  49704. _addNamespacePrefix(prefixes) {
  49705. for (const {
  49706. prefix,
  49707. value
  49708. } of prefixes) {
  49709. const namespace = this._searchNamespace(value);
  49710. let prefixStack = this._namespacePrefixes.get(prefix);
  49711. if (!prefixStack) {
  49712. prefixStack = [];
  49713. this._namespacePrefixes.set(prefix, prefixStack);
  49714. }
  49715. prefixStack.push(namespace);
  49716. }
  49717. }
  49718. _getNamespaceToUse(prefix) {
  49719. if (!prefix) {
  49720. return this._currentNamespace;
  49721. }
  49722. const prefixStack = this._namespacePrefixes.get(prefix);
  49723. if (prefixStack?.length > 0) {
  49724. return prefixStack.at(-1);
  49725. }
  49726. warn(`Unknown namespace prefix: ${prefix}.`);
  49727. return null;
  49728. }
  49729. clean(data) {
  49730. const {
  49731. hasNamespace,
  49732. prefixes,
  49733. nsAgnostic
  49734. } = data;
  49735. if (hasNamespace) {
  49736. this._currentNamespace = this._namespaceStack.pop();
  49737. }
  49738. if (prefixes) {
  49739. prefixes.forEach(({
  49740. prefix
  49741. }) => {
  49742. this._namespacePrefixes.get(prefix).pop();
  49743. });
  49744. }
  49745. if (nsAgnostic) {
  49746. this._nsAgnosticLevel--;
  49747. }
  49748. }
  49749. }
  49750. ;// CONCATENATED MODULE: ./src/core/xfa/parser.js
  49751. class XFAParser extends XMLParserBase {
  49752. constructor(rootNameSpace = null, richText = false) {
  49753. super();
  49754. this._builder = new Builder(rootNameSpace);
  49755. this._stack = [];
  49756. this._globalData = {
  49757. usedTypefaces: new Set()
  49758. };
  49759. this._ids = new Map();
  49760. this._current = this._builder.buildRoot(this._ids);
  49761. this._errorCode = XMLParserErrorCode.NoError;
  49762. this._whiteRegex = /^\s+$/;
  49763. this._nbsps = /\xa0+/g;
  49764. this._richText = richText;
  49765. }
  49766. parse(data) {
  49767. this.parseXml(data);
  49768. if (this._errorCode !== XMLParserErrorCode.NoError) {
  49769. return undefined;
  49770. }
  49771. this._current[$finalize]();
  49772. return this._current.element;
  49773. }
  49774. onText(text) {
  49775. text = text.replace(this._nbsps, match => match.slice(1) + " ");
  49776. if (this._richText || this._current[$acceptWhitespace]()) {
  49777. this._current[$onText](text, this._richText);
  49778. return;
  49779. }
  49780. if (this._whiteRegex.test(text)) {
  49781. return;
  49782. }
  49783. this._current[$onText](text.trim());
  49784. }
  49785. onCdata(text) {
  49786. this._current[$onText](text);
  49787. }
  49788. _mkAttributes(attributes, tagName) {
  49789. let namespace = null;
  49790. let prefixes = null;
  49791. const attributeObj = Object.create({});
  49792. for (const {
  49793. name,
  49794. value
  49795. } of attributes) {
  49796. if (name === "xmlns") {
  49797. if (!namespace) {
  49798. namespace = value;
  49799. } else {
  49800. warn(`XFA - multiple namespace definition in <${tagName}>`);
  49801. }
  49802. } else if (name.startsWith("xmlns:")) {
  49803. const prefix = name.substring("xmlns:".length);
  49804. if (!prefixes) {
  49805. prefixes = [];
  49806. }
  49807. prefixes.push({
  49808. prefix,
  49809. value
  49810. });
  49811. } else {
  49812. const i = name.indexOf(":");
  49813. if (i === -1) {
  49814. attributeObj[name] = value;
  49815. } else {
  49816. let nsAttrs = attributeObj[$nsAttributes];
  49817. if (!nsAttrs) {
  49818. nsAttrs = attributeObj[$nsAttributes] = Object.create(null);
  49819. }
  49820. const [ns, attrName] = [name.slice(0, i), name.slice(i + 1)];
  49821. const attrs = nsAttrs[ns] ||= Object.create(null);
  49822. attrs[attrName] = value;
  49823. }
  49824. }
  49825. }
  49826. return [namespace, prefixes, attributeObj];
  49827. }
  49828. _getNameAndPrefix(name, nsAgnostic) {
  49829. const i = name.indexOf(":");
  49830. if (i === -1) {
  49831. return [name, null];
  49832. }
  49833. return [name.substring(i + 1), nsAgnostic ? "" : name.substring(0, i)];
  49834. }
  49835. onBeginElement(tagName, attributes, isEmpty) {
  49836. const [namespace, prefixes, attributesObj] = this._mkAttributes(attributes, tagName);
  49837. const [name, nsPrefix] = this._getNameAndPrefix(tagName, this._builder.isNsAgnostic());
  49838. const node = this._builder.build({
  49839. nsPrefix,
  49840. name,
  49841. attributes: attributesObj,
  49842. namespace,
  49843. prefixes
  49844. });
  49845. node[$globalData] = this._globalData;
  49846. if (isEmpty) {
  49847. node[$finalize]();
  49848. if (this._current[$onChild](node)) {
  49849. node[$setId](this._ids);
  49850. }
  49851. node[$clean](this._builder);
  49852. return;
  49853. }
  49854. this._stack.push(this._current);
  49855. this._current = node;
  49856. }
  49857. onEndElement(name) {
  49858. const node = this._current;
  49859. if (node[$isCDATAXml]() && typeof node[$content] === "string") {
  49860. const parser = new XFAParser();
  49861. parser._globalData = this._globalData;
  49862. const root = parser.parse(node[$content]);
  49863. node[$content] = null;
  49864. node[$onChild](root);
  49865. }
  49866. node[$finalize]();
  49867. this._current = this._stack.pop();
  49868. if (this._current[$onChild](node)) {
  49869. node[$setId](this._ids);
  49870. }
  49871. node[$clean](this._builder);
  49872. }
  49873. onError(code) {
  49874. this._errorCode = code;
  49875. }
  49876. }
  49877. ;// CONCATENATED MODULE: ./src/core/xfa/factory.js
  49878. class XFAFactory {
  49879. constructor(data) {
  49880. try {
  49881. this.root = new XFAParser().parse(XFAFactory._createDocument(data));
  49882. const binder = new Binder(this.root);
  49883. this.form = binder.bind();
  49884. this.dataHandler = new DataHandler(this.root, binder.getData());
  49885. this.form[$globalData].template = this.form;
  49886. } catch (e) {
  49887. warn(`XFA - an error occurred during parsing and binding: ${e}`);
  49888. }
  49889. }
  49890. isValid() {
  49891. return this.root && this.form;
  49892. }
  49893. _createPagesHelper() {
  49894. const iterator = this.form[$toPages]();
  49895. return new Promise((resolve, reject) => {
  49896. const nextIteration = () => {
  49897. try {
  49898. const value = iterator.next();
  49899. if (value.done) {
  49900. resolve(value.value);
  49901. } else {
  49902. setTimeout(nextIteration, 0);
  49903. }
  49904. } catch (e) {
  49905. reject(e);
  49906. }
  49907. };
  49908. setTimeout(nextIteration, 0);
  49909. });
  49910. }
  49911. async _createPages() {
  49912. try {
  49913. this.pages = await this._createPagesHelper();
  49914. this.dims = this.pages.children.map(c => {
  49915. const {
  49916. width,
  49917. height
  49918. } = c.attributes.style;
  49919. return [0, 0, parseInt(width), parseInt(height)];
  49920. });
  49921. } catch (e) {
  49922. warn(`XFA - an error occurred during layout: ${e}`);
  49923. }
  49924. }
  49925. getBoundingBox(pageIndex) {
  49926. return this.dims[pageIndex];
  49927. }
  49928. async getNumPages() {
  49929. if (!this.pages) {
  49930. await this._createPages();
  49931. }
  49932. return this.dims.length;
  49933. }
  49934. setImages(images) {
  49935. this.form[$globalData].images = images;
  49936. }
  49937. setFonts(fonts) {
  49938. this.form[$globalData].fontFinder = new FontFinder(fonts);
  49939. const missingFonts = [];
  49940. for (let typeface of this.form[$globalData].usedTypefaces) {
  49941. typeface = stripQuotes(typeface);
  49942. const font = this.form[$globalData].fontFinder.find(typeface);
  49943. if (!font) {
  49944. missingFonts.push(typeface);
  49945. }
  49946. }
  49947. if (missingFonts.length > 0) {
  49948. return missingFonts;
  49949. }
  49950. return null;
  49951. }
  49952. appendFonts(fonts, reallyMissingFonts) {
  49953. this.form[$globalData].fontFinder.add(fonts, reallyMissingFonts);
  49954. }
  49955. async getPages() {
  49956. if (!this.pages) {
  49957. await this._createPages();
  49958. }
  49959. const pages = this.pages;
  49960. this.pages = null;
  49961. return pages;
  49962. }
  49963. serializeData(storage) {
  49964. return this.dataHandler.serialize(storage);
  49965. }
  49966. static _createDocument(data) {
  49967. if (!data["/xdp:xdp"]) {
  49968. return data["xdp:xdp"];
  49969. }
  49970. return Object.values(data).join("");
  49971. }
  49972. static getRichTextAsHtml(rc) {
  49973. if (!rc || typeof rc !== "string") {
  49974. return null;
  49975. }
  49976. try {
  49977. let root = new XFAParser(XhtmlNamespace, true).parse(rc);
  49978. if (!["body", "xhtml"].includes(root[$nodeName])) {
  49979. const newRoot = XhtmlNamespace.body({});
  49980. newRoot[$appendChild](root);
  49981. root = newRoot;
  49982. }
  49983. const result = root[$toHTML]();
  49984. if (!result.success) {
  49985. return null;
  49986. }
  49987. const {
  49988. html
  49989. } = result;
  49990. const {
  49991. attributes
  49992. } = html;
  49993. if (attributes) {
  49994. if (attributes.class) {
  49995. attributes.class = attributes.class.filter(attr => !attr.startsWith("xfa"));
  49996. }
  49997. attributes.dir = "auto";
  49998. }
  49999. return {
  50000. html,
  50001. str: root[$text]()
  50002. };
  50003. } catch (e) {
  50004. warn(`XFA - an error occurred during parsing of rich text: ${e}`);
  50005. }
  50006. return null;
  50007. }
  50008. }
  50009. ;// CONCATENATED MODULE: ./src/core/annotation.js
  50010. class AnnotationFactory {
  50011. static createGlobals(pdfManager) {
  50012. return Promise.all([pdfManager.ensureCatalog("acroForm"), pdfManager.ensureDoc("xfaDatasets"), pdfManager.ensureCatalog("structTreeRoot"), pdfManager.ensureCatalog("baseUrl"), pdfManager.ensureCatalog("attachments")]).then(([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => {
  50013. return {
  50014. pdfManager,
  50015. acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
  50016. xfaDatasets,
  50017. structTreeRoot,
  50018. baseUrl,
  50019. attachments
  50020. };
  50021. }, reason => {
  50022. warn(`createGlobals: "${reason}".`);
  50023. return null;
  50024. });
  50025. }
  50026. static async create(xref, ref, annotationGlobals, idFactory, collectFields, pageRef) {
  50027. const pageIndex = collectFields ? await this._getPageIndex(xref, ref, annotationGlobals.pdfManager) : null;
  50028. return annotationGlobals.pdfManager.ensure(this, "_create", [xref, ref, annotationGlobals, idFactory, collectFields, pageIndex, pageRef]);
  50029. }
  50030. static _create(xref, ref, annotationGlobals, idFactory, collectFields = false, pageIndex = null, pageRef = null) {
  50031. const dict = xref.fetchIfRef(ref);
  50032. if (!(dict instanceof Dict)) {
  50033. return undefined;
  50034. }
  50035. const {
  50036. acroForm,
  50037. pdfManager
  50038. } = annotationGlobals;
  50039. const id = ref instanceof Ref ? ref.toString() : `annot_${idFactory.createObjId()}`;
  50040. let subtype = dict.get("Subtype");
  50041. subtype = subtype instanceof Name ? subtype.name : null;
  50042. const parameters = {
  50043. xref,
  50044. ref,
  50045. dict,
  50046. subtype,
  50047. id,
  50048. annotationGlobals,
  50049. collectFields,
  50050. needAppearances: !collectFields && acroForm.get("NeedAppearances") === true,
  50051. pageIndex,
  50052. evaluatorOptions: pdfManager.evaluatorOptions,
  50053. pageRef
  50054. };
  50055. switch (subtype) {
  50056. case "Link":
  50057. return new LinkAnnotation(parameters);
  50058. case "Text":
  50059. return new TextAnnotation(parameters);
  50060. case "Widget":
  50061. let fieldType = getInheritableProperty({
  50062. dict,
  50063. key: "FT"
  50064. });
  50065. fieldType = fieldType instanceof Name ? fieldType.name : null;
  50066. switch (fieldType) {
  50067. case "Tx":
  50068. return new TextWidgetAnnotation(parameters);
  50069. case "Btn":
  50070. return new ButtonWidgetAnnotation(parameters);
  50071. case "Ch":
  50072. return new ChoiceWidgetAnnotation(parameters);
  50073. case "Sig":
  50074. return new SignatureWidgetAnnotation(parameters);
  50075. }
  50076. warn(`Unimplemented widget field type "${fieldType}", ` + "falling back to base field type.");
  50077. return new WidgetAnnotation(parameters);
  50078. case "Popup":
  50079. return new PopupAnnotation(parameters);
  50080. case "FreeText":
  50081. return new FreeTextAnnotation(parameters);
  50082. case "Line":
  50083. return new LineAnnotation(parameters);
  50084. case "Square":
  50085. return new SquareAnnotation(parameters);
  50086. case "Circle":
  50087. return new CircleAnnotation(parameters);
  50088. case "PolyLine":
  50089. return new PolylineAnnotation(parameters);
  50090. case "Polygon":
  50091. return new PolygonAnnotation(parameters);
  50092. case "Caret":
  50093. return new CaretAnnotation(parameters);
  50094. case "Ink":
  50095. return new InkAnnotation(parameters);
  50096. case "Highlight":
  50097. return new HighlightAnnotation(parameters);
  50098. case "Underline":
  50099. return new UnderlineAnnotation(parameters);
  50100. case "Squiggly":
  50101. return new SquigglyAnnotation(parameters);
  50102. case "StrikeOut":
  50103. return new StrikeOutAnnotation(parameters);
  50104. case "Stamp":
  50105. return new StampAnnotation(parameters);
  50106. case "FileAttachment":
  50107. return new FileAttachmentAnnotation(parameters);
  50108. default:
  50109. if (!collectFields) {
  50110. if (!subtype) {
  50111. warn("Annotation is missing the required /Subtype.");
  50112. } else {
  50113. warn(`Unimplemented annotation type "${subtype}", ` + "falling back to base annotation.");
  50114. }
  50115. }
  50116. return new Annotation(parameters);
  50117. }
  50118. }
  50119. static async _getPageIndex(xref, ref, pdfManager) {
  50120. try {
  50121. const annotDict = await xref.fetchIfRefAsync(ref);
  50122. if (!(annotDict instanceof Dict)) {
  50123. return -1;
  50124. }
  50125. const pageRef = annotDict.getRaw("P");
  50126. if (pageRef instanceof Ref) {
  50127. try {
  50128. const pageIndex = await pdfManager.ensureCatalog("getPageIndex", [pageRef]);
  50129. return pageIndex;
  50130. } catch (ex) {
  50131. info(`_getPageIndex -- not a valid page reference: "${ex}".`);
  50132. }
  50133. }
  50134. if (annotDict.has("Kids")) {
  50135. return -1;
  50136. }
  50137. const numPages = await pdfManager.ensureDoc("numPages");
  50138. for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
  50139. const page = await pdfManager.getPage(pageIndex);
  50140. const annotations = await pdfManager.ensure(page, "annotations");
  50141. for (const annotRef of annotations) {
  50142. if (annotRef instanceof Ref && isRefsEqual(annotRef, ref)) {
  50143. return pageIndex;
  50144. }
  50145. }
  50146. }
  50147. } catch (ex) {
  50148. warn(`_getPageIndex: "${ex}".`);
  50149. }
  50150. return -1;
  50151. }
  50152. static generateImages(annotations, xref, isOffscreenCanvasSupported) {
  50153. if (!isOffscreenCanvasSupported) {
  50154. warn("generateImages: OffscreenCanvas is not supported, cannot save or print some annotations with images.");
  50155. return null;
  50156. }
  50157. let imagePromises;
  50158. for (const {
  50159. bitmapId,
  50160. bitmap
  50161. } of annotations) {
  50162. if (!bitmap) {
  50163. continue;
  50164. }
  50165. imagePromises ||= new Map();
  50166. imagePromises.set(bitmapId, StampAnnotation.createImage(bitmap, xref));
  50167. }
  50168. return imagePromises;
  50169. }
  50170. static async saveNewAnnotations(evaluator, task, annotations, imagePromises) {
  50171. const xref = evaluator.xref;
  50172. let baseFontRef;
  50173. const dependencies = [];
  50174. const promises = [];
  50175. const {
  50176. isOffscreenCanvasSupported
  50177. } = evaluator.options;
  50178. for (const annotation of annotations) {
  50179. if (annotation.deleted) {
  50180. continue;
  50181. }
  50182. switch (annotation.annotationType) {
  50183. case AnnotationEditorType.FREETEXT:
  50184. if (!baseFontRef) {
  50185. const baseFont = new Dict(xref);
  50186. baseFont.set("BaseFont", Name.get("Helvetica"));
  50187. baseFont.set("Type", Name.get("Font"));
  50188. baseFont.set("Subtype", Name.get("Type1"));
  50189. baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
  50190. const buffer = [];
  50191. baseFontRef = xref.getNewTemporaryRef();
  50192. await writeObject(baseFontRef, baseFont, buffer, xref);
  50193. dependencies.push({
  50194. ref: baseFontRef,
  50195. data: buffer.join("")
  50196. });
  50197. }
  50198. promises.push(FreeTextAnnotation.createNewAnnotation(xref, annotation, dependencies, {
  50199. evaluator,
  50200. task,
  50201. baseFontRef
  50202. }));
  50203. break;
  50204. case AnnotationEditorType.HIGHLIGHT:
  50205. promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies));
  50206. break;
  50207. case AnnotationEditorType.INK:
  50208. promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
  50209. break;
  50210. case AnnotationEditorType.STAMP:
  50211. if (!isOffscreenCanvasSupported) {
  50212. break;
  50213. }
  50214. const image = await imagePromises.get(annotation.bitmapId);
  50215. if (image.imageStream) {
  50216. const {
  50217. imageStream,
  50218. smaskStream
  50219. } = image;
  50220. const buffer = [];
  50221. if (smaskStream) {
  50222. const smaskRef = xref.getNewTemporaryRef();
  50223. await writeObject(smaskRef, smaskStream, buffer, xref);
  50224. dependencies.push({
  50225. ref: smaskRef,
  50226. data: buffer.join("")
  50227. });
  50228. imageStream.dict.set("SMask", smaskRef);
  50229. buffer.length = 0;
  50230. }
  50231. const imageRef = image.imageRef = xref.getNewTemporaryRef();
  50232. await writeObject(imageRef, imageStream, buffer, xref);
  50233. dependencies.push({
  50234. ref: imageRef,
  50235. data: buffer.join("")
  50236. });
  50237. image.imageStream = image.smaskStream = null;
  50238. }
  50239. promises.push(StampAnnotation.createNewAnnotation(xref, annotation, dependencies, {
  50240. image
  50241. }));
  50242. break;
  50243. }
  50244. }
  50245. return {
  50246. annotations: await Promise.all(promises),
  50247. dependencies
  50248. };
  50249. }
  50250. static async printNewAnnotations(annotationGlobals, evaluator, task, annotations, imagePromises) {
  50251. if (!annotations) {
  50252. return null;
  50253. }
  50254. const {
  50255. options,
  50256. xref
  50257. } = evaluator;
  50258. const promises = [];
  50259. for (const annotation of annotations) {
  50260. if (annotation.deleted) {
  50261. continue;
  50262. }
  50263. switch (annotation.annotationType) {
  50264. case AnnotationEditorType.FREETEXT:
  50265. promises.push(FreeTextAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
  50266. evaluator,
  50267. task,
  50268. evaluatorOptions: options
  50269. }));
  50270. break;
  50271. case AnnotationEditorType.HIGHLIGHT:
  50272. promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
  50273. evaluatorOptions: options
  50274. }));
  50275. break;
  50276. case AnnotationEditorType.INK:
  50277. promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
  50278. evaluatorOptions: options
  50279. }));
  50280. break;
  50281. case AnnotationEditorType.STAMP:
  50282. if (!options.isOffscreenCanvasSupported) {
  50283. break;
  50284. }
  50285. const image = await imagePromises.get(annotation.bitmapId);
  50286. if (image.imageStream) {
  50287. const {
  50288. imageStream,
  50289. smaskStream
  50290. } = image;
  50291. if (smaskStream) {
  50292. imageStream.dict.set("SMask", smaskStream);
  50293. }
  50294. image.imageRef = new JpegStream(imageStream, imageStream.length);
  50295. image.imageStream = image.smaskStream = null;
  50296. }
  50297. promises.push(StampAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
  50298. image,
  50299. evaluatorOptions: options
  50300. }));
  50301. break;
  50302. }
  50303. }
  50304. return Promise.all(promises);
  50305. }
  50306. }
  50307. function getRgbColor(color, defaultColor = new Uint8ClampedArray(3)) {
  50308. if (!Array.isArray(color)) {
  50309. return defaultColor;
  50310. }
  50311. const rgbColor = defaultColor || new Uint8ClampedArray(3);
  50312. switch (color.length) {
  50313. case 0:
  50314. return null;
  50315. case 1:
  50316. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  50317. return rgbColor;
  50318. case 3:
  50319. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  50320. return rgbColor;
  50321. case 4:
  50322. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  50323. return rgbColor;
  50324. default:
  50325. return defaultColor;
  50326. }
  50327. }
  50328. function getPdfColorArray(color) {
  50329. return Array.from(color, c => c / 255);
  50330. }
  50331. function getQuadPoints(dict, rect) {
  50332. const quadPoints = dict.getArray("QuadPoints");
  50333. if (!Array.isArray(quadPoints) || quadPoints.length === 0 || quadPoints.length % 8 > 0) {
  50334. return null;
  50335. }
  50336. const quadPointsLists = [];
  50337. for (let i = 0, ii = quadPoints.length / 8; i < ii; i++) {
  50338. let minX = Infinity,
  50339. maxX = -Infinity,
  50340. minY = Infinity,
  50341. maxY = -Infinity;
  50342. for (let j = i * 8, jj = i * 8 + 8; j < jj; j += 2) {
  50343. const x = quadPoints[j];
  50344. const y = quadPoints[j + 1];
  50345. minX = Math.min(x, minX);
  50346. maxX = Math.max(x, maxX);
  50347. minY = Math.min(y, minY);
  50348. maxY = Math.max(y, maxY);
  50349. }
  50350. if (rect !== null && (minX < rect[0] || maxX > rect[2] || minY < rect[1] || maxY > rect[3])) {
  50351. return null;
  50352. }
  50353. quadPointsLists.push([{
  50354. x: minX,
  50355. y: maxY
  50356. }, {
  50357. x: maxX,
  50358. y: maxY
  50359. }, {
  50360. x: minX,
  50361. y: minY
  50362. }, {
  50363. x: maxX,
  50364. y: minY
  50365. }]);
  50366. }
  50367. return quadPointsLists;
  50368. }
  50369. function getTransformMatrix(rect, bbox, matrix) {
  50370. const [minX, minY, maxX, maxY] = Util.getAxialAlignedBoundingBox(bbox, matrix);
  50371. if (minX === maxX || minY === maxY) {
  50372. return [1, 0, 0, 1, rect[0], rect[1]];
  50373. }
  50374. const xRatio = (rect[2] - rect[0]) / (maxX - minX);
  50375. const yRatio = (rect[3] - rect[1]) / (maxY - minY);
  50376. return [xRatio, 0, 0, yRatio, rect[0] - minX * xRatio, rect[1] - minY * yRatio];
  50377. }
  50378. class Annotation {
  50379. constructor(params) {
  50380. const {
  50381. dict,
  50382. xref,
  50383. annotationGlobals
  50384. } = params;
  50385. this.setTitle(dict.get("T"));
  50386. this.setContents(dict.get("Contents"));
  50387. this.setModificationDate(dict.get("M"));
  50388. this.setFlags(dict.get("F"));
  50389. this.setRectangle(dict.getArray("Rect"));
  50390. this.setColor(dict.getArray("C"));
  50391. this.setBorderStyle(dict);
  50392. this.setAppearance(dict);
  50393. this.setOptionalContent(dict);
  50394. const MK = dict.get("MK");
  50395. this.setBorderAndBackgroundColors(MK);
  50396. this.setRotation(MK, dict);
  50397. this.ref = params.ref instanceof Ref ? params.ref : null;
  50398. this._streams = [];
  50399. if (this.appearance) {
  50400. this._streams.push(this.appearance);
  50401. }
  50402. const isLocked = !!(this.flags & AnnotationFlag.LOCKED);
  50403. const isContentLocked = !!(this.flags & AnnotationFlag.LOCKEDCONTENTS);
  50404. if (annotationGlobals.structTreeRoot) {
  50405. let structParent = dict.get("StructParent");
  50406. structParent = Number.isInteger(structParent) && structParent >= 0 ? structParent : -1;
  50407. annotationGlobals.structTreeRoot.addAnnotationIdToPage(params.pageRef, structParent);
  50408. }
  50409. this.data = {
  50410. annotationFlags: this.flags,
  50411. borderStyle: this.borderStyle,
  50412. color: this.color,
  50413. backgroundColor: this.backgroundColor,
  50414. borderColor: this.borderColor,
  50415. rotation: this.rotation,
  50416. contentsObj: this._contents,
  50417. hasAppearance: !!this.appearance,
  50418. id: params.id,
  50419. modificationDate: this.modificationDate,
  50420. rect: this.rectangle,
  50421. subtype: params.subtype,
  50422. hasOwnCanvas: false,
  50423. noRotate: !!(this.flags & AnnotationFlag.NOROTATE),
  50424. noHTML: isLocked && isContentLocked
  50425. };
  50426. if (params.collectFields) {
  50427. const kids = dict.get("Kids");
  50428. if (Array.isArray(kids)) {
  50429. const kidIds = [];
  50430. for (const kid of kids) {
  50431. if (kid instanceof Ref) {
  50432. kidIds.push(kid.toString());
  50433. }
  50434. }
  50435. if (kidIds.length !== 0) {
  50436. this.data.kidIds = kidIds;
  50437. }
  50438. }
  50439. this.data.actions = collectActions(xref, dict, AnnotationActionEventType);
  50440. this.data.fieldName = this._constructFieldName(dict);
  50441. this.data.pageIndex = params.pageIndex;
  50442. }
  50443. this._isOffscreenCanvasSupported = params.evaluatorOptions.isOffscreenCanvasSupported;
  50444. this._fallbackFontDict = null;
  50445. this._needAppearances = false;
  50446. }
  50447. _hasFlag(flags, flag) {
  50448. return !!(flags & flag);
  50449. }
  50450. _isViewable(flags) {
  50451. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  50452. }
  50453. _isPrintable(flags) {
  50454. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE);
  50455. }
  50456. mustBeViewed(annotationStorage, _renderForms) {
  50457. const noView = annotationStorage?.get(this.data.id)?.noView;
  50458. if (noView !== undefined) {
  50459. return !noView;
  50460. }
  50461. return this.viewable && !this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
  50462. }
  50463. mustBePrinted(annotationStorage) {
  50464. const noPrint = annotationStorage?.get(this.data.id)?.noPrint;
  50465. if (noPrint !== undefined) {
  50466. return !noPrint;
  50467. }
  50468. return this.printable;
  50469. }
  50470. get viewable() {
  50471. if (this.data.quadPoints === null) {
  50472. return false;
  50473. }
  50474. if (this.flags === 0) {
  50475. return true;
  50476. }
  50477. return this._isViewable(this.flags);
  50478. }
  50479. get printable() {
  50480. if (this.data.quadPoints === null) {
  50481. return false;
  50482. }
  50483. if (this.flags === 0) {
  50484. return false;
  50485. }
  50486. return this._isPrintable(this.flags);
  50487. }
  50488. _parseStringHelper(data) {
  50489. const str = typeof data === "string" ? stringToPDFString(data) : "";
  50490. const dir = str && bidi(str).dir === "rtl" ? "rtl" : "ltr";
  50491. return {
  50492. str,
  50493. dir
  50494. };
  50495. }
  50496. setDefaultAppearance(params) {
  50497. const {
  50498. dict,
  50499. annotationGlobals
  50500. } = params;
  50501. const defaultAppearance = getInheritableProperty({
  50502. dict,
  50503. key: "DA"
  50504. }) || annotationGlobals.acroForm.get("DA");
  50505. this._defaultAppearance = typeof defaultAppearance === "string" ? defaultAppearance : "";
  50506. this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance);
  50507. }
  50508. setTitle(title) {
  50509. this._title = this._parseStringHelper(title);
  50510. }
  50511. setContents(contents) {
  50512. this._contents = this._parseStringHelper(contents);
  50513. }
  50514. setModificationDate(modificationDate) {
  50515. this.modificationDate = typeof modificationDate === "string" ? modificationDate : null;
  50516. }
  50517. setFlags(flags) {
  50518. this.flags = Number.isInteger(flags) && flags > 0 ? flags : 0;
  50519. if (this.flags & AnnotationFlag.INVISIBLE && this.constructor.name !== "Annotation") {
  50520. this.flags ^= AnnotationFlag.INVISIBLE;
  50521. }
  50522. }
  50523. hasFlag(flag) {
  50524. return this._hasFlag(this.flags, flag);
  50525. }
  50526. setRectangle(rectangle) {
  50527. this.rectangle = Array.isArray(rectangle) && rectangle.length === 4 ? Util.normalizeRect(rectangle) : [0, 0, 0, 0];
  50528. }
  50529. setColor(color) {
  50530. this.color = getRgbColor(color);
  50531. }
  50532. setLineEndings(lineEndings) {
  50533. this.lineEndings = ["None", "None"];
  50534. if (Array.isArray(lineEndings) && lineEndings.length === 2) {
  50535. for (let i = 0; i < 2; i++) {
  50536. const obj = lineEndings[i];
  50537. if (obj instanceof Name) {
  50538. switch (obj.name) {
  50539. case "None":
  50540. continue;
  50541. case "Square":
  50542. case "Circle":
  50543. case "Diamond":
  50544. case "OpenArrow":
  50545. case "ClosedArrow":
  50546. case "Butt":
  50547. case "ROpenArrow":
  50548. case "RClosedArrow":
  50549. case "Slash":
  50550. this.lineEndings[i] = obj.name;
  50551. continue;
  50552. }
  50553. }
  50554. warn(`Ignoring invalid lineEnding: ${obj}`);
  50555. }
  50556. }
  50557. }
  50558. setRotation(mk, dict) {
  50559. this.rotation = 0;
  50560. let angle = mk instanceof Dict ? mk.get("R") || 0 : dict.get("Rotate") || 0;
  50561. if (Number.isInteger(angle) && angle !== 0) {
  50562. angle %= 360;
  50563. if (angle < 0) {
  50564. angle += 360;
  50565. }
  50566. if (angle % 90 === 0) {
  50567. this.rotation = angle;
  50568. }
  50569. }
  50570. }
  50571. setBorderAndBackgroundColors(mk) {
  50572. if (mk instanceof Dict) {
  50573. this.borderColor = getRgbColor(mk.getArray("BC"), null);
  50574. this.backgroundColor = getRgbColor(mk.getArray("BG"), null);
  50575. } else {
  50576. this.borderColor = this.backgroundColor = null;
  50577. }
  50578. }
  50579. setBorderStyle(borderStyle) {
  50580. this.borderStyle = new AnnotationBorderStyle();
  50581. if (!(borderStyle instanceof Dict)) {
  50582. return;
  50583. }
  50584. if (borderStyle.has("BS")) {
  50585. const dict = borderStyle.get("BS");
  50586. if (dict instanceof Dict) {
  50587. const dictType = dict.get("Type");
  50588. if (!dictType || isName(dictType, "Border")) {
  50589. this.borderStyle.setWidth(dict.get("W"), this.rectangle);
  50590. this.borderStyle.setStyle(dict.get("S"));
  50591. this.borderStyle.setDashArray(dict.getArray("D"));
  50592. }
  50593. }
  50594. } else if (borderStyle.has("Border")) {
  50595. const array = borderStyle.getArray("Border");
  50596. if (Array.isArray(array) && array.length >= 3) {
  50597. this.borderStyle.setHorizontalCornerRadius(array[0]);
  50598. this.borderStyle.setVerticalCornerRadius(array[1]);
  50599. this.borderStyle.setWidth(array[2], this.rectangle);
  50600. if (array.length === 4) {
  50601. this.borderStyle.setDashArray(array[3], true);
  50602. }
  50603. }
  50604. } else {
  50605. this.borderStyle.setWidth(0);
  50606. }
  50607. }
  50608. setAppearance(dict) {
  50609. this.appearance = null;
  50610. const appearanceStates = dict.get("AP");
  50611. if (!(appearanceStates instanceof Dict)) {
  50612. return;
  50613. }
  50614. const normalAppearanceState = appearanceStates.get("N");
  50615. if (normalAppearanceState instanceof BaseStream) {
  50616. this.appearance = normalAppearanceState;
  50617. return;
  50618. }
  50619. if (!(normalAppearanceState instanceof Dict)) {
  50620. return;
  50621. }
  50622. const as = dict.get("AS");
  50623. if (!(as instanceof Name) || !normalAppearanceState.has(as.name)) {
  50624. return;
  50625. }
  50626. const appearance = normalAppearanceState.get(as.name);
  50627. if (appearance instanceof BaseStream) {
  50628. this.appearance = appearance;
  50629. }
  50630. }
  50631. setOptionalContent(dict) {
  50632. this.oc = null;
  50633. const oc = dict.get("OC");
  50634. if (oc instanceof Name) {
  50635. warn("setOptionalContent: Support for /Name-entry is not implemented.");
  50636. } else if (oc instanceof Dict) {
  50637. this.oc = oc;
  50638. }
  50639. }
  50640. loadResources(keys, appearance) {
  50641. return appearance.dict.getAsync("Resources").then(resources => {
  50642. if (!resources) {
  50643. return undefined;
  50644. }
  50645. const objectLoader = new ObjectLoader(resources, keys, resources.xref);
  50646. return objectLoader.load().then(function () {
  50647. return resources;
  50648. });
  50649. });
  50650. }
  50651. async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
  50652. const data = this.data;
  50653. let appearance = this.appearance;
  50654. const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
  50655. if (!appearance) {
  50656. if (!isUsingOwnCanvas) {
  50657. return {
  50658. opList: new OperatorList(),
  50659. separateForm: false,
  50660. separateCanvas: false
  50661. };
  50662. }
  50663. appearance = new StringStream("");
  50664. appearance.dict = new Dict();
  50665. }
  50666. const appearanceDict = appearance.dict;
  50667. const resources = await this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"], appearance);
  50668. const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
  50669. const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
  50670. const transform = getTransformMatrix(data.rect, bbox, matrix);
  50671. const opList = new OperatorList();
  50672. let optionalContent;
  50673. if (this.oc) {
  50674. optionalContent = await evaluator.parseMarkedContentProps(this.oc, null);
  50675. }
  50676. if (optionalContent !== undefined) {
  50677. opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
  50678. }
  50679. opList.addOp(OPS.beginAnnotation, [data.id, data.rect, transform, matrix, isUsingOwnCanvas]);
  50680. await evaluator.getOperatorList({
  50681. stream: appearance,
  50682. task,
  50683. resources,
  50684. operatorList: opList,
  50685. fallbackFontDict: this._fallbackFontDict
  50686. });
  50687. opList.addOp(OPS.endAnnotation, []);
  50688. if (optionalContent !== undefined) {
  50689. opList.addOp(OPS.endMarkedContent, []);
  50690. }
  50691. this.reset();
  50692. return {
  50693. opList,
  50694. separateForm: false,
  50695. separateCanvas: isUsingOwnCanvas
  50696. };
  50697. }
  50698. async save(evaluator, task, annotationStorage) {
  50699. return null;
  50700. }
  50701. get hasTextContent() {
  50702. return false;
  50703. }
  50704. async extractTextContent(evaluator, task, viewBox) {
  50705. if (!this.appearance) {
  50706. return;
  50707. }
  50708. const resources = await this.loadResources(["ExtGState", "Font", "Properties", "XObject"], this.appearance);
  50709. const text = [];
  50710. const buffer = [];
  50711. let firstPosition = null;
  50712. const sink = {
  50713. desiredSize: Math.Infinity,
  50714. ready: true,
  50715. enqueue(chunk, size) {
  50716. for (const item of chunk.items) {
  50717. if (item.str === undefined) {
  50718. continue;
  50719. }
  50720. firstPosition ||= item.transform.slice(-2);
  50721. buffer.push(item.str);
  50722. if (item.hasEOL) {
  50723. text.push(buffer.join(""));
  50724. buffer.length = 0;
  50725. }
  50726. }
  50727. }
  50728. };
  50729. await evaluator.getTextContent({
  50730. stream: this.appearance,
  50731. task,
  50732. resources,
  50733. includeMarkedContent: true,
  50734. sink,
  50735. viewBox
  50736. });
  50737. this.reset();
  50738. if (buffer.length) {
  50739. text.push(buffer.join(""));
  50740. }
  50741. if (text.length > 1 || text[0]) {
  50742. const appearanceDict = this.appearance.dict;
  50743. const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
  50744. const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
  50745. const rect = this.data.rect;
  50746. const transform = getTransformMatrix(rect, bbox, matrix);
  50747. transform[4] -= rect[0];
  50748. transform[5] -= rect[1];
  50749. firstPosition = Util.applyTransform(firstPosition, transform);
  50750. firstPosition = Util.applyTransform(firstPosition, matrix);
  50751. this.data.textPosition = firstPosition;
  50752. this.data.textContent = text;
  50753. }
  50754. }
  50755. getFieldObject() {
  50756. if (this.data.kidIds) {
  50757. return {
  50758. id: this.data.id,
  50759. actions: this.data.actions,
  50760. name: this.data.fieldName,
  50761. strokeColor: this.data.borderColor,
  50762. fillColor: this.data.backgroundColor,
  50763. type: "",
  50764. kidIds: this.data.kidIds,
  50765. page: this.data.pageIndex,
  50766. rotation: this.rotation
  50767. };
  50768. }
  50769. return null;
  50770. }
  50771. reset() {
  50772. for (const stream of this._streams) {
  50773. stream.reset();
  50774. }
  50775. }
  50776. _constructFieldName(dict) {
  50777. if (!dict.has("T") && !dict.has("Parent")) {
  50778. warn("Unknown field name, falling back to empty field name.");
  50779. return "";
  50780. }
  50781. if (!dict.has("Parent")) {
  50782. return stringToPDFString(dict.get("T"));
  50783. }
  50784. const fieldName = [];
  50785. if (dict.has("T")) {
  50786. fieldName.unshift(stringToPDFString(dict.get("T")));
  50787. }
  50788. let loopDict = dict;
  50789. const visited = new RefSet();
  50790. if (dict.objId) {
  50791. visited.put(dict.objId);
  50792. }
  50793. while (loopDict.has("Parent")) {
  50794. loopDict = loopDict.get("Parent");
  50795. if (!(loopDict instanceof Dict) || loopDict.objId && visited.has(loopDict.objId)) {
  50796. break;
  50797. }
  50798. if (loopDict.objId) {
  50799. visited.put(loopDict.objId);
  50800. }
  50801. if (loopDict.has("T")) {
  50802. fieldName.unshift(stringToPDFString(loopDict.get("T")));
  50803. }
  50804. }
  50805. return fieldName.join(".");
  50806. }
  50807. }
  50808. class AnnotationBorderStyle {
  50809. constructor() {
  50810. this.width = 1;
  50811. this.style = AnnotationBorderStyleType.SOLID;
  50812. this.dashArray = [3];
  50813. this.horizontalCornerRadius = 0;
  50814. this.verticalCornerRadius = 0;
  50815. }
  50816. setWidth(width, rect = [0, 0, 0, 0]) {
  50817. if (width instanceof Name) {
  50818. this.width = 0;
  50819. return;
  50820. }
  50821. if (typeof width === "number") {
  50822. if (width > 0) {
  50823. const maxWidth = (rect[2] - rect[0]) / 2;
  50824. const maxHeight = (rect[3] - rect[1]) / 2;
  50825. if (maxWidth > 0 && maxHeight > 0 && (width > maxWidth || width > maxHeight)) {
  50826. warn(`AnnotationBorderStyle.setWidth - ignoring width: ${width}`);
  50827. width = 1;
  50828. }
  50829. }
  50830. this.width = width;
  50831. }
  50832. }
  50833. setStyle(style) {
  50834. if (!(style instanceof Name)) {
  50835. return;
  50836. }
  50837. switch (style.name) {
  50838. case "S":
  50839. this.style = AnnotationBorderStyleType.SOLID;
  50840. break;
  50841. case "D":
  50842. this.style = AnnotationBorderStyleType.DASHED;
  50843. break;
  50844. case "B":
  50845. this.style = AnnotationBorderStyleType.BEVELED;
  50846. break;
  50847. case "I":
  50848. this.style = AnnotationBorderStyleType.INSET;
  50849. break;
  50850. case "U":
  50851. this.style = AnnotationBorderStyleType.UNDERLINE;
  50852. break;
  50853. default:
  50854. break;
  50855. }
  50856. }
  50857. setDashArray(dashArray, forceStyle = false) {
  50858. if (Array.isArray(dashArray) && dashArray.length > 0) {
  50859. let isValid = true;
  50860. let allZeros = true;
  50861. for (const element of dashArray) {
  50862. const validNumber = +element >= 0;
  50863. if (!validNumber) {
  50864. isValid = false;
  50865. break;
  50866. } else if (element > 0) {
  50867. allZeros = false;
  50868. }
  50869. }
  50870. if (isValid && !allZeros) {
  50871. this.dashArray = dashArray;
  50872. if (forceStyle) {
  50873. this.setStyle(Name.get("D"));
  50874. }
  50875. } else {
  50876. this.width = 0;
  50877. }
  50878. } else if (dashArray) {
  50879. this.width = 0;
  50880. }
  50881. }
  50882. setHorizontalCornerRadius(radius) {
  50883. if (Number.isInteger(radius)) {
  50884. this.horizontalCornerRadius = radius;
  50885. }
  50886. }
  50887. setVerticalCornerRadius(radius) {
  50888. if (Number.isInteger(radius)) {
  50889. this.verticalCornerRadius = radius;
  50890. }
  50891. }
  50892. }
  50893. class MarkupAnnotation extends Annotation {
  50894. constructor(params) {
  50895. super(params);
  50896. const {
  50897. dict
  50898. } = params;
  50899. if (dict.has("IRT")) {
  50900. const rawIRT = dict.getRaw("IRT");
  50901. this.data.inReplyTo = rawIRT instanceof Ref ? rawIRT.toString() : null;
  50902. const rt = dict.get("RT");
  50903. this.data.replyType = rt instanceof Name ? rt.name : AnnotationReplyType.REPLY;
  50904. }
  50905. let popupRef = null;
  50906. if (this.data.replyType === AnnotationReplyType.GROUP) {
  50907. const parent = dict.get("IRT");
  50908. this.setTitle(parent.get("T"));
  50909. this.data.titleObj = this._title;
  50910. this.setContents(parent.get("Contents"));
  50911. this.data.contentsObj = this._contents;
  50912. if (!parent.has("CreationDate")) {
  50913. this.data.creationDate = null;
  50914. } else {
  50915. this.setCreationDate(parent.get("CreationDate"));
  50916. this.data.creationDate = this.creationDate;
  50917. }
  50918. if (!parent.has("M")) {
  50919. this.data.modificationDate = null;
  50920. } else {
  50921. this.setModificationDate(parent.get("M"));
  50922. this.data.modificationDate = this.modificationDate;
  50923. }
  50924. popupRef = parent.getRaw("Popup");
  50925. if (!parent.has("C")) {
  50926. this.data.color = null;
  50927. } else {
  50928. this.setColor(parent.getArray("C"));
  50929. this.data.color = this.color;
  50930. }
  50931. } else {
  50932. this.data.titleObj = this._title;
  50933. this.setCreationDate(dict.get("CreationDate"));
  50934. this.data.creationDate = this.creationDate;
  50935. popupRef = dict.getRaw("Popup");
  50936. if (!dict.has("C")) {
  50937. this.data.color = null;
  50938. }
  50939. }
  50940. this.data.popupRef = popupRef instanceof Ref ? popupRef.toString() : null;
  50941. if (dict.has("RC")) {
  50942. this.data.richText = XFAFactory.getRichTextAsHtml(dict.get("RC"));
  50943. }
  50944. }
  50945. setCreationDate(creationDate) {
  50946. this.creationDate = typeof creationDate === "string" ? creationDate : null;
  50947. }
  50948. _setDefaultAppearance({
  50949. xref,
  50950. extra,
  50951. strokeColor,
  50952. fillColor,
  50953. blendMode,
  50954. strokeAlpha,
  50955. fillAlpha,
  50956. pointsCallback
  50957. }) {
  50958. let minX = Number.MAX_VALUE;
  50959. let minY = Number.MAX_VALUE;
  50960. let maxX = Number.MIN_VALUE;
  50961. let maxY = Number.MIN_VALUE;
  50962. const buffer = ["q"];
  50963. if (extra) {
  50964. buffer.push(extra);
  50965. }
  50966. if (strokeColor) {
  50967. buffer.push(`${strokeColor[0]} ${strokeColor[1]} ${strokeColor[2]} RG`);
  50968. }
  50969. if (fillColor) {
  50970. buffer.push(`${fillColor[0]} ${fillColor[1]} ${fillColor[2]} rg`);
  50971. }
  50972. let pointsArray = this.data.quadPoints;
  50973. if (!pointsArray) {
  50974. pointsArray = [[{
  50975. x: this.rectangle[0],
  50976. y: this.rectangle[3]
  50977. }, {
  50978. x: this.rectangle[2],
  50979. y: this.rectangle[3]
  50980. }, {
  50981. x: this.rectangle[0],
  50982. y: this.rectangle[1]
  50983. }, {
  50984. x: this.rectangle[2],
  50985. y: this.rectangle[1]
  50986. }]];
  50987. }
  50988. for (const points of pointsArray) {
  50989. const [mX, MX, mY, MY] = pointsCallback(buffer, points);
  50990. minX = Math.min(minX, mX);
  50991. maxX = Math.max(maxX, MX);
  50992. minY = Math.min(minY, mY);
  50993. maxY = Math.max(maxY, MY);
  50994. }
  50995. buffer.push("Q");
  50996. const formDict = new Dict(xref);
  50997. const appearanceStreamDict = new Dict(xref);
  50998. appearanceStreamDict.set("Subtype", Name.get("Form"));
  50999. const appearanceStream = new StringStream(buffer.join(" "));
  51000. appearanceStream.dict = appearanceStreamDict;
  51001. formDict.set("Fm0", appearanceStream);
  51002. const gsDict = new Dict(xref);
  51003. if (blendMode) {
  51004. gsDict.set("BM", Name.get(blendMode));
  51005. }
  51006. if (typeof strokeAlpha === "number") {
  51007. gsDict.set("CA", strokeAlpha);
  51008. }
  51009. if (typeof fillAlpha === "number") {
  51010. gsDict.set("ca", fillAlpha);
  51011. }
  51012. const stateDict = new Dict(xref);
  51013. stateDict.set("GS0", gsDict);
  51014. const resources = new Dict(xref);
  51015. resources.set("ExtGState", stateDict);
  51016. resources.set("XObject", formDict);
  51017. const appearanceDict = new Dict(xref);
  51018. appearanceDict.set("Resources", resources);
  51019. const bbox = this.data.rect = [minX, minY, maxX, maxY];
  51020. appearanceDict.set("BBox", bbox);
  51021. this.appearance = new StringStream("/GS0 gs /Fm0 Do");
  51022. this.appearance.dict = appearanceDict;
  51023. this._streams.push(this.appearance, appearanceStream);
  51024. }
  51025. static async createNewAnnotation(xref, annotation, dependencies, params) {
  51026. const annotationRef = annotation.ref ||= xref.getNewTemporaryRef();
  51027. const ap = await this.createNewAppearanceStream(annotation, xref, params);
  51028. const buffer = [];
  51029. let annotationDict;
  51030. if (ap) {
  51031. const apRef = xref.getNewTemporaryRef();
  51032. annotationDict = this.createNewDict(annotation, xref, {
  51033. apRef
  51034. });
  51035. await writeObject(apRef, ap, buffer, xref);
  51036. dependencies.push({
  51037. ref: apRef,
  51038. data: buffer.join("")
  51039. });
  51040. } else {
  51041. annotationDict = this.createNewDict(annotation, xref, {});
  51042. }
  51043. if (Number.isInteger(annotation.parentTreeId)) {
  51044. annotationDict.set("StructParent", annotation.parentTreeId);
  51045. }
  51046. buffer.length = 0;
  51047. await writeObject(annotationRef, annotationDict, buffer, xref);
  51048. return {
  51049. ref: annotationRef,
  51050. data: buffer.join("")
  51051. };
  51052. }
  51053. static async createNewPrintAnnotation(annotationGlobals, xref, annotation, params) {
  51054. const ap = await this.createNewAppearanceStream(annotation, xref, params);
  51055. const annotationDict = this.createNewDict(annotation, xref, {
  51056. ap
  51057. });
  51058. const newAnnotation = new this.prototype.constructor({
  51059. dict: annotationDict,
  51060. xref,
  51061. annotationGlobals,
  51062. evaluatorOptions: params.evaluatorOptions
  51063. });
  51064. if (annotation.ref) {
  51065. newAnnotation.ref = newAnnotation.refToReplace = annotation.ref;
  51066. }
  51067. return newAnnotation;
  51068. }
  51069. }
  51070. class WidgetAnnotation extends Annotation {
  51071. constructor(params) {
  51072. super(params);
  51073. const {
  51074. dict,
  51075. xref,
  51076. annotationGlobals
  51077. } = params;
  51078. const data = this.data;
  51079. this._needAppearances = params.needAppearances;
  51080. data.annotationType = AnnotationType.WIDGET;
  51081. if (data.fieldName === undefined) {
  51082. data.fieldName = this._constructFieldName(dict);
  51083. }
  51084. if (data.actions === undefined) {
  51085. data.actions = collectActions(xref, dict, AnnotationActionEventType);
  51086. }
  51087. let fieldValue = getInheritableProperty({
  51088. dict,
  51089. key: "V",
  51090. getArray: true
  51091. });
  51092. data.fieldValue = this._decodeFormValue(fieldValue);
  51093. const defaultFieldValue = getInheritableProperty({
  51094. dict,
  51095. key: "DV",
  51096. getArray: true
  51097. });
  51098. data.defaultFieldValue = this._decodeFormValue(defaultFieldValue);
  51099. if (fieldValue === undefined && annotationGlobals.xfaDatasets) {
  51100. const path = this._title.str;
  51101. if (path) {
  51102. this._hasValueFromXFA = true;
  51103. data.fieldValue = fieldValue = annotationGlobals.xfaDatasets.getValue(path);
  51104. }
  51105. }
  51106. if (fieldValue === undefined && data.defaultFieldValue !== null) {
  51107. data.fieldValue = data.defaultFieldValue;
  51108. }
  51109. data.alternativeText = stringToPDFString(dict.get("TU") || "");
  51110. this.setDefaultAppearance(params);
  51111. data.hasAppearance ||= this._needAppearances && data.fieldValue !== undefined && data.fieldValue !== null;
  51112. const fieldType = getInheritableProperty({
  51113. dict,
  51114. key: "FT"
  51115. });
  51116. data.fieldType = fieldType instanceof Name ? fieldType.name : null;
  51117. const localResources = getInheritableProperty({
  51118. dict,
  51119. key: "DR"
  51120. });
  51121. const acroFormResources = annotationGlobals.acroForm.get("DR");
  51122. const appearanceResources = this.appearance?.dict.get("Resources");
  51123. this._fieldResources = {
  51124. localResources,
  51125. acroFormResources,
  51126. appearanceResources,
  51127. mergedResources: Dict.merge({
  51128. xref,
  51129. dictArray: [localResources, appearanceResources, acroFormResources],
  51130. mergeSubDicts: true
  51131. })
  51132. };
  51133. data.fieldFlags = getInheritableProperty({
  51134. dict,
  51135. key: "Ff"
  51136. });
  51137. if (!Number.isInteger(data.fieldFlags) || data.fieldFlags < 0) {
  51138. data.fieldFlags = 0;
  51139. }
  51140. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  51141. data.required = this.hasFieldFlag(AnnotationFieldFlag.REQUIRED);
  51142. data.hidden = this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN) || this._hasFlag(data.annotationFlags, AnnotationFlag.NOVIEW);
  51143. }
  51144. _decodeFormValue(formValue) {
  51145. if (Array.isArray(formValue)) {
  51146. return formValue.filter(item => typeof item === "string").map(item => stringToPDFString(item));
  51147. } else if (formValue instanceof Name) {
  51148. return stringToPDFString(formValue.name);
  51149. } else if (typeof formValue === "string") {
  51150. return stringToPDFString(formValue);
  51151. }
  51152. return null;
  51153. }
  51154. hasFieldFlag(flag) {
  51155. return !!(this.data.fieldFlags & flag);
  51156. }
  51157. _isViewable(flags) {
  51158. return true;
  51159. }
  51160. mustBeViewed(annotationStorage, renderForms) {
  51161. if (renderForms) {
  51162. return this.viewable;
  51163. }
  51164. return super.mustBeViewed(annotationStorage, renderForms) && !this._hasFlag(this.flags, AnnotationFlag.NOVIEW);
  51165. }
  51166. getRotationMatrix(annotationStorage) {
  51167. let rotation = annotationStorage?.get(this.data.id)?.rotation;
  51168. if (rotation === undefined) {
  51169. rotation = this.rotation;
  51170. }
  51171. if (rotation === 0) {
  51172. return IDENTITY_MATRIX;
  51173. }
  51174. const width = this.data.rect[2] - this.data.rect[0];
  51175. const height = this.data.rect[3] - this.data.rect[1];
  51176. return getRotationMatrix(rotation, width, height);
  51177. }
  51178. getBorderAndBackgroundAppearances(annotationStorage) {
  51179. let rotation = annotationStorage?.get(this.data.id)?.rotation;
  51180. if (rotation === undefined) {
  51181. rotation = this.rotation;
  51182. }
  51183. if (!this.backgroundColor && !this.borderColor) {
  51184. return "";
  51185. }
  51186. const width = this.data.rect[2] - this.data.rect[0];
  51187. const height = this.data.rect[3] - this.data.rect[1];
  51188. const rect = rotation === 0 || rotation === 180 ? `0 0 ${width} ${height} re` : `0 0 ${height} ${width} re`;
  51189. let str = "";
  51190. if (this.backgroundColor) {
  51191. str = `${getPdfColor(this.backgroundColor, true)} ${rect} f `;
  51192. }
  51193. if (this.borderColor) {
  51194. const borderWidth = this.borderStyle.width || 1;
  51195. str += `${borderWidth} w ${getPdfColor(this.borderColor, false)} ${rect} S `;
  51196. }
  51197. return str;
  51198. }
  51199. async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
  51200. if (renderForms && !(this instanceof SignatureWidgetAnnotation) && !this.data.noHTML && !this.data.hasOwnCanvas) {
  51201. return {
  51202. opList: new OperatorList(),
  51203. separateForm: true,
  51204. separateCanvas: false
  51205. };
  51206. }
  51207. if (!this._hasText) {
  51208. return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
  51209. }
  51210. const content = await this._getAppearance(evaluator, task, intent, annotationStorage);
  51211. if (this.appearance && content === null) {
  51212. return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
  51213. }
  51214. const opList = new OperatorList();
  51215. if (!this._defaultAppearance || content === null) {
  51216. return {
  51217. opList,
  51218. separateForm: false,
  51219. separateCanvas: false
  51220. };
  51221. }
  51222. const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
  51223. const matrix = [1, 0, 0, 1, 0, 0];
  51224. const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
  51225. const transform = getTransformMatrix(this.data.rect, bbox, matrix);
  51226. let optionalContent;
  51227. if (this.oc) {
  51228. optionalContent = await evaluator.parseMarkedContentProps(this.oc, null);
  51229. }
  51230. if (optionalContent !== undefined) {
  51231. opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
  51232. }
  51233. opList.addOp(OPS.beginAnnotation, [this.data.id, this.data.rect, transform, this.getRotationMatrix(annotationStorage), isUsingOwnCanvas]);
  51234. const stream = new StringStream(content);
  51235. await evaluator.getOperatorList({
  51236. stream,
  51237. task,
  51238. resources: this._fieldResources.mergedResources,
  51239. operatorList: opList
  51240. });
  51241. opList.addOp(OPS.endAnnotation, []);
  51242. if (optionalContent !== undefined) {
  51243. opList.addOp(OPS.endMarkedContent, []);
  51244. }
  51245. return {
  51246. opList,
  51247. separateForm: false,
  51248. separateCanvas: isUsingOwnCanvas
  51249. };
  51250. }
  51251. _getMKDict(rotation) {
  51252. const mk = new Dict(null);
  51253. if (rotation) {
  51254. mk.set("R", rotation);
  51255. }
  51256. if (this.borderColor) {
  51257. mk.set("BC", getPdfColorArray(this.borderColor));
  51258. }
  51259. if (this.backgroundColor) {
  51260. mk.set("BG", getPdfColorArray(this.backgroundColor));
  51261. }
  51262. return mk.size > 0 ? mk : null;
  51263. }
  51264. amendSavedDict(annotationStorage, dict) {}
  51265. async save(evaluator, task, annotationStorage) {
  51266. const storageEntry = annotationStorage?.get(this.data.id);
  51267. let value = storageEntry?.value,
  51268. rotation = storageEntry?.rotation;
  51269. if (value === this.data.fieldValue || value === undefined) {
  51270. if (!this._hasValueFromXFA && rotation === undefined) {
  51271. return null;
  51272. }
  51273. value ||= this.data.fieldValue;
  51274. }
  51275. if (rotation === undefined && !this._hasValueFromXFA && Array.isArray(value) && Array.isArray(this.data.fieldValue) && value.length === this.data.fieldValue.length && value.every((x, i) => x === this.data.fieldValue[i])) {
  51276. return null;
  51277. }
  51278. if (rotation === undefined) {
  51279. rotation = this.rotation;
  51280. }
  51281. let appearance = null;
  51282. if (!this._needAppearances) {
  51283. appearance = await this._getAppearance(evaluator, task, RenderingIntentFlag.SAVE, annotationStorage);
  51284. if (appearance === null) {
  51285. return null;
  51286. }
  51287. } else {}
  51288. let needAppearances = false;
  51289. if (appearance?.needAppearances) {
  51290. needAppearances = true;
  51291. appearance = null;
  51292. }
  51293. const {
  51294. xref
  51295. } = evaluator;
  51296. const originalDict = xref.fetchIfRef(this.ref);
  51297. if (!(originalDict instanceof Dict)) {
  51298. return null;
  51299. }
  51300. const dict = new Dict(xref);
  51301. for (const key of originalDict.getKeys()) {
  51302. if (key !== "AP") {
  51303. dict.set(key, originalDict.getRaw(key));
  51304. }
  51305. }
  51306. const xfa = {
  51307. path: this.data.fieldName,
  51308. value
  51309. };
  51310. const encoder = val => {
  51311. return isAscii(val) ? val : stringToUTF16String(val, true);
  51312. };
  51313. dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
  51314. this.amendSavedDict(annotationStorage, dict);
  51315. const maybeMK = this._getMKDict(rotation);
  51316. if (maybeMK) {
  51317. dict.set("MK", maybeMK);
  51318. }
  51319. const buffer = [];
  51320. const changes = [{
  51321. ref: this.ref,
  51322. data: "",
  51323. xfa,
  51324. needAppearances
  51325. }];
  51326. if (appearance !== null) {
  51327. const newRef = xref.getNewTemporaryRef();
  51328. const AP = new Dict(xref);
  51329. dict.set("AP", AP);
  51330. AP.set("N", newRef);
  51331. const resources = this._getSaveFieldResources(xref);
  51332. const appearanceStream = new StringStream(appearance);
  51333. const appearanceDict = appearanceStream.dict = new Dict(xref);
  51334. appearanceDict.set("Subtype", Name.get("Form"));
  51335. appearanceDict.set("Resources", resources);
  51336. appearanceDict.set("BBox", [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]]);
  51337. const rotationMatrix = this.getRotationMatrix(annotationStorage);
  51338. if (rotationMatrix !== IDENTITY_MATRIX) {
  51339. appearanceDict.set("Matrix", rotationMatrix);
  51340. }
  51341. await writeObject(newRef, appearanceStream, buffer, xref);
  51342. changes.push({
  51343. ref: newRef,
  51344. data: buffer.join(""),
  51345. xfa: null,
  51346. needAppearances: false
  51347. });
  51348. buffer.length = 0;
  51349. }
  51350. dict.set("M", `D:${getModificationDate()}`);
  51351. await writeObject(this.ref, dict, buffer, xref);
  51352. changes[0].data = buffer.join("");
  51353. return changes;
  51354. }
  51355. async _getAppearance(evaluator, task, intent, annotationStorage) {
  51356. const isPassword = this.hasFieldFlag(AnnotationFieldFlag.PASSWORD);
  51357. if (isPassword) {
  51358. return null;
  51359. }
  51360. const storageEntry = annotationStorage?.get(this.data.id);
  51361. let value, rotation;
  51362. if (storageEntry) {
  51363. value = storageEntry.formattedValue || storageEntry.value;
  51364. rotation = storageEntry.rotation;
  51365. }
  51366. if (rotation === undefined && value === undefined && !this._needAppearances) {
  51367. if (!this._hasValueFromXFA || this.appearance) {
  51368. return null;
  51369. }
  51370. }
  51371. const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
  51372. if (value === undefined) {
  51373. value = this.data.fieldValue;
  51374. if (!value) {
  51375. return `/Tx BMC q ${colors}Q EMC`;
  51376. }
  51377. }
  51378. if (Array.isArray(value) && value.length === 1) {
  51379. value = value[0];
  51380. }
  51381. assert(typeof value === "string", "Expected `value` to be a string.");
  51382. value = value.trim();
  51383. if (this.data.combo) {
  51384. const option = this.data.options.find(({
  51385. exportValue
  51386. }) => value === exportValue);
  51387. value = option?.displayValue || value;
  51388. }
  51389. if (value === "") {
  51390. return `/Tx BMC q ${colors}Q EMC`;
  51391. }
  51392. if (rotation === undefined) {
  51393. rotation = this.rotation;
  51394. }
  51395. let lineCount = -1;
  51396. let lines;
  51397. if (this.data.multiLine) {
  51398. lines = value.split(/\r\n?|\n/).map(line => line.normalize("NFC"));
  51399. lineCount = lines.length;
  51400. } else {
  51401. lines = [value.replace(/\r\n?|\n/, "").normalize("NFC")];
  51402. }
  51403. const defaultPadding = 1;
  51404. const defaultHPadding = 2;
  51405. let totalHeight = this.data.rect[3] - this.data.rect[1];
  51406. let totalWidth = this.data.rect[2] - this.data.rect[0];
  51407. if (rotation === 90 || rotation === 270) {
  51408. [totalWidth, totalHeight] = [totalHeight, totalWidth];
  51409. }
  51410. if (!this._defaultAppearance) {
  51411. this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g");
  51412. }
  51413. let font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources);
  51414. let defaultAppearance, fontSize, lineHeight;
  51415. const encodedLines = [];
  51416. let encodingError = false;
  51417. for (const line of lines) {
  51418. const encodedString = font.encodeString(line);
  51419. if (encodedString.length > 1) {
  51420. encodingError = true;
  51421. }
  51422. encodedLines.push(encodedString.join(""));
  51423. }
  51424. if (encodingError && intent & RenderingIntentFlag.SAVE) {
  51425. return {
  51426. needAppearances: true
  51427. };
  51428. }
  51429. if (encodingError && this._isOffscreenCanvasSupported) {
  51430. const fontFamily = this.data.comb ? "monospace" : "sans-serif";
  51431. const fakeUnicodeFont = new FakeUnicodeFont(evaluator.xref, fontFamily);
  51432. const resources = fakeUnicodeFont.createFontResources(lines.join(""));
  51433. const newFont = resources.getRaw("Font");
  51434. if (this._fieldResources.mergedResources.has("Font")) {
  51435. const oldFont = this._fieldResources.mergedResources.get("Font");
  51436. for (const key of newFont.getKeys()) {
  51437. oldFont.set(key, newFont.getRaw(key));
  51438. }
  51439. } else {
  51440. this._fieldResources.mergedResources.set("Font", newFont);
  51441. }
  51442. const fontName = fakeUnicodeFont.fontName.name;
  51443. font = await WidgetAnnotation._getFontData(evaluator, task, {
  51444. fontName,
  51445. fontSize: 0
  51446. }, resources);
  51447. for (let i = 0, ii = encodedLines.length; i < ii; i++) {
  51448. encodedLines[i] = stringToUTF16String(lines[i]);
  51449. }
  51450. const savedDefaultAppearance = Object.assign(Object.create(null), this.data.defaultAppearanceData);
  51451. this.data.defaultAppearanceData.fontSize = 0;
  51452. this.data.defaultAppearanceData.fontName = fontName;
  51453. [defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount);
  51454. this.data.defaultAppearanceData = savedDefaultAppearance;
  51455. } else {
  51456. if (!this._isOffscreenCanvasSupported) {
  51457. warn("_getAppearance: OffscreenCanvas is not supported, annotation may not render correctly.");
  51458. }
  51459. [defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount);
  51460. }
  51461. let descent = font.descent;
  51462. if (isNaN(descent)) {
  51463. descent = BASELINE_FACTOR * lineHeight;
  51464. } else {
  51465. descent = Math.max(BASELINE_FACTOR * lineHeight, Math.abs(descent) * fontSize);
  51466. }
  51467. const defaultVPadding = Math.min(Math.floor((totalHeight - fontSize) / 2), defaultPadding);
  51468. const alignment = this.data.textAlignment;
  51469. if (this.data.multiLine) {
  51470. return this._getMultilineAppearance(defaultAppearance, encodedLines, font, fontSize, totalWidth, totalHeight, alignment, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage);
  51471. }
  51472. if (this.data.comb) {
  51473. return this._getCombAppearance(defaultAppearance, font, encodedLines[0], fontSize, totalWidth, totalHeight, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage);
  51474. }
  51475. const bottomPadding = defaultVPadding + descent;
  51476. if (alignment === 0 || alignment > 2) {
  51477. return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(defaultHPadding)} ${numberToString(bottomPadding)} Tm (${escapeString(encodedLines[0])}) Tj` + " ET Q EMC";
  51478. }
  51479. const prevInfo = {
  51480. shift: 0
  51481. };
  51482. const renderedText = this._renderText(encodedLines[0], font, fontSize, totalWidth, alignment, prevInfo, defaultHPadding, bottomPadding);
  51483. return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 0 Tm ${renderedText}` + " ET Q EMC";
  51484. }
  51485. static async _getFontData(evaluator, task, appearanceData, resources) {
  51486. const operatorList = new OperatorList();
  51487. const initialState = {
  51488. font: null,
  51489. clone() {
  51490. return this;
  51491. }
  51492. };
  51493. const {
  51494. fontName,
  51495. fontSize
  51496. } = appearanceData;
  51497. await evaluator.handleSetFont(resources, [fontName && Name.get(fontName), fontSize], null, operatorList, task, initialState, null);
  51498. return initialState.font;
  51499. }
  51500. _getTextWidth(text, font) {
  51501. return font.charsToGlyphs(text).reduce((width, glyph) => width + glyph.width, 0) / 1000;
  51502. }
  51503. _computeFontSize(height, width, text, font, lineCount) {
  51504. let {
  51505. fontSize
  51506. } = this.data.defaultAppearanceData;
  51507. let lineHeight = (fontSize || 12) * LINE_FACTOR,
  51508. numberOfLines = Math.round(height / lineHeight);
  51509. if (!fontSize) {
  51510. const roundWithTwoDigits = x => Math.floor(x * 100) / 100;
  51511. if (lineCount === -1) {
  51512. const textWidth = this._getTextWidth(text, font);
  51513. fontSize = roundWithTwoDigits(Math.min(height / LINE_FACTOR, textWidth > width ? width / textWidth : Infinity));
  51514. numberOfLines = 1;
  51515. } else {
  51516. const lines = text.split(/\r\n?|\n/);
  51517. const cachedLines = [];
  51518. for (const line of lines) {
  51519. const encoded = font.encodeString(line).join("");
  51520. const glyphs = font.charsToGlyphs(encoded);
  51521. const positions = font.getCharPositions(encoded);
  51522. cachedLines.push({
  51523. line: encoded,
  51524. glyphs,
  51525. positions
  51526. });
  51527. }
  51528. const isTooBig = fsize => {
  51529. let totalHeight = 0;
  51530. for (const cache of cachedLines) {
  51531. const chunks = this._splitLine(null, font, fsize, width, cache);
  51532. totalHeight += chunks.length * fsize;
  51533. if (totalHeight > height) {
  51534. return true;
  51535. }
  51536. }
  51537. return false;
  51538. };
  51539. numberOfLines = Math.max(numberOfLines, lineCount);
  51540. while (true) {
  51541. lineHeight = height / numberOfLines;
  51542. fontSize = roundWithTwoDigits(lineHeight / LINE_FACTOR);
  51543. if (isTooBig(fontSize)) {
  51544. numberOfLines++;
  51545. continue;
  51546. }
  51547. break;
  51548. }
  51549. }
  51550. const {
  51551. fontName,
  51552. fontColor
  51553. } = this.data.defaultAppearanceData;
  51554. this._defaultAppearance = createDefaultAppearance({
  51555. fontSize,
  51556. fontName,
  51557. fontColor
  51558. });
  51559. }
  51560. return [this._defaultAppearance, fontSize, height / numberOfLines];
  51561. }
  51562. _renderText(text, font, fontSize, totalWidth, alignment, prevInfo, hPadding, vPadding) {
  51563. let shift;
  51564. if (alignment === 1) {
  51565. const width = this._getTextWidth(text, font) * fontSize;
  51566. shift = (totalWidth - width) / 2;
  51567. } else if (alignment === 2) {
  51568. const width = this._getTextWidth(text, font) * fontSize;
  51569. shift = totalWidth - width - hPadding;
  51570. } else {
  51571. shift = hPadding;
  51572. }
  51573. const shiftStr = numberToString(shift - prevInfo.shift);
  51574. prevInfo.shift = shift;
  51575. vPadding = numberToString(vPadding);
  51576. return `${shiftStr} ${vPadding} Td (${escapeString(text)}) Tj`;
  51577. }
  51578. _getSaveFieldResources(xref) {
  51579. const {
  51580. localResources,
  51581. appearanceResources,
  51582. acroFormResources
  51583. } = this._fieldResources;
  51584. const fontName = this.data.defaultAppearanceData?.fontName;
  51585. if (!fontName) {
  51586. return localResources || Dict.empty;
  51587. }
  51588. for (const resources of [localResources, appearanceResources]) {
  51589. if (resources instanceof Dict) {
  51590. const localFont = resources.get("Font");
  51591. if (localFont instanceof Dict && localFont.has(fontName)) {
  51592. return resources;
  51593. }
  51594. }
  51595. }
  51596. if (acroFormResources instanceof Dict) {
  51597. const acroFormFont = acroFormResources.get("Font");
  51598. if (acroFormFont instanceof Dict && acroFormFont.has(fontName)) {
  51599. const subFontDict = new Dict(xref);
  51600. subFontDict.set(fontName, acroFormFont.getRaw(fontName));
  51601. const subResourcesDict = new Dict(xref);
  51602. subResourcesDict.set("Font", subFontDict);
  51603. return Dict.merge({
  51604. xref,
  51605. dictArray: [subResourcesDict, localResources],
  51606. mergeSubDicts: true
  51607. });
  51608. }
  51609. }
  51610. return localResources || Dict.empty;
  51611. }
  51612. getFieldObject() {
  51613. return null;
  51614. }
  51615. }
  51616. class TextWidgetAnnotation extends WidgetAnnotation {
  51617. constructor(params) {
  51618. super(params);
  51619. this.data.hasOwnCanvas = this.data.readOnly && !this.data.noHTML;
  51620. this._hasText = true;
  51621. const dict = params.dict;
  51622. if (typeof this.data.fieldValue !== "string") {
  51623. this.data.fieldValue = "";
  51624. }
  51625. let alignment = getInheritableProperty({
  51626. dict,
  51627. key: "Q"
  51628. });
  51629. if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
  51630. alignment = null;
  51631. }
  51632. this.data.textAlignment = alignment;
  51633. let maximumLength = getInheritableProperty({
  51634. dict,
  51635. key: "MaxLen"
  51636. });
  51637. if (!Number.isInteger(maximumLength) || maximumLength < 0) {
  51638. maximumLength = 0;
  51639. }
  51640. this.data.maxLen = maximumLength;
  51641. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  51642. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== 0;
  51643. this.data.doNotScroll = this.hasFieldFlag(AnnotationFieldFlag.DONOTSCROLL);
  51644. }
  51645. get hasTextContent() {
  51646. return !!this.appearance && !this._needAppearances;
  51647. }
  51648. _getCombAppearance(defaultAppearance, font, text, fontSize, width, height, hPadding, vPadding, descent, lineHeight, annotationStorage) {
  51649. const combWidth = width / this.data.maxLen;
  51650. const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
  51651. const buf = [];
  51652. const positions = font.getCharPositions(text);
  51653. for (const [start, end] of positions) {
  51654. buf.push(`(${escapeString(text.substring(start, end))}) Tj`);
  51655. }
  51656. const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `);
  51657. return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(hPadding)} ${numberToString(vPadding + descent)} Tm ${renderedComb}` + " ET Q EMC";
  51658. }
  51659. _getMultilineAppearance(defaultAppearance, lines, font, fontSize, width, height, alignment, hPadding, vPadding, descent, lineHeight, annotationStorage) {
  51660. const buf = [];
  51661. const totalWidth = width - 2 * hPadding;
  51662. const prevInfo = {
  51663. shift: 0
  51664. };
  51665. for (let i = 0, ii = lines.length; i < ii; i++) {
  51666. const line = lines[i];
  51667. const chunks = this._splitLine(line, font, fontSize, totalWidth);
  51668. for (let j = 0, jj = chunks.length; j < jj; j++) {
  51669. const chunk = chunks[j];
  51670. const vShift = i === 0 && j === 0 ? -vPadding - (lineHeight - descent) : -lineHeight;
  51671. buf.push(this._renderText(chunk, font, fontSize, width, alignment, prevInfo, hPadding, vShift));
  51672. }
  51673. }
  51674. const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
  51675. const renderedText = buf.join("\n");
  51676. return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 ${numberToString(height)} Tm ${renderedText}` + " ET Q EMC";
  51677. }
  51678. _splitLine(line, font, fontSize, width, cache = {}) {
  51679. line = cache.line || line;
  51680. const glyphs = cache.glyphs || font.charsToGlyphs(line);
  51681. if (glyphs.length <= 1) {
  51682. return [line];
  51683. }
  51684. const positions = cache.positions || font.getCharPositions(line);
  51685. const scale = fontSize / 1000;
  51686. const chunks = [];
  51687. let lastSpacePosInStringStart = -1,
  51688. lastSpacePosInStringEnd = -1,
  51689. lastSpacePos = -1,
  51690. startChunk = 0,
  51691. currentWidth = 0;
  51692. for (let i = 0, ii = glyphs.length; i < ii; i++) {
  51693. const [start, end] = positions[i];
  51694. const glyph = glyphs[i];
  51695. const glyphWidth = glyph.width * scale;
  51696. if (glyph.unicode === " ") {
  51697. if (currentWidth + glyphWidth > width) {
  51698. chunks.push(line.substring(startChunk, start));
  51699. startChunk = start;
  51700. currentWidth = glyphWidth;
  51701. lastSpacePosInStringStart = -1;
  51702. lastSpacePos = -1;
  51703. } else {
  51704. currentWidth += glyphWidth;
  51705. lastSpacePosInStringStart = start;
  51706. lastSpacePosInStringEnd = end;
  51707. lastSpacePos = i;
  51708. }
  51709. } else if (currentWidth + glyphWidth > width) {
  51710. if (lastSpacePosInStringStart !== -1) {
  51711. chunks.push(line.substring(startChunk, lastSpacePosInStringEnd));
  51712. startChunk = lastSpacePosInStringEnd;
  51713. i = lastSpacePos + 1;
  51714. lastSpacePosInStringStart = -1;
  51715. currentWidth = 0;
  51716. } else {
  51717. chunks.push(line.substring(startChunk, start));
  51718. startChunk = start;
  51719. currentWidth = glyphWidth;
  51720. }
  51721. } else {
  51722. currentWidth += glyphWidth;
  51723. }
  51724. }
  51725. if (startChunk < line.length) {
  51726. chunks.push(line.substring(startChunk, line.length));
  51727. }
  51728. return chunks;
  51729. }
  51730. getFieldObject() {
  51731. return {
  51732. id: this.data.id,
  51733. value: this.data.fieldValue,
  51734. defaultValue: this.data.defaultFieldValue || "",
  51735. multiline: this.data.multiLine,
  51736. password: this.hasFieldFlag(AnnotationFieldFlag.PASSWORD),
  51737. charLimit: this.data.maxLen,
  51738. comb: this.data.comb,
  51739. editable: !this.data.readOnly,
  51740. hidden: this.data.hidden,
  51741. name: this.data.fieldName,
  51742. rect: this.data.rect,
  51743. actions: this.data.actions,
  51744. page: this.data.pageIndex,
  51745. strokeColor: this.data.borderColor,
  51746. fillColor: this.data.backgroundColor,
  51747. rotation: this.rotation,
  51748. type: "text"
  51749. };
  51750. }
  51751. }
  51752. class ButtonWidgetAnnotation extends WidgetAnnotation {
  51753. constructor(params) {
  51754. super(params);
  51755. this.checkedAppearance = null;
  51756. this.uncheckedAppearance = null;
  51757. this.data.checkBox = !this.hasFieldFlag(AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
  51758. this.data.radioButton = this.hasFieldFlag(AnnotationFieldFlag.RADIO) && !this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
  51759. this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
  51760. this.data.isTooltipOnly = false;
  51761. if (this.data.checkBox) {
  51762. this._processCheckBox(params);
  51763. } else if (this.data.radioButton) {
  51764. this._processRadioButton(params);
  51765. } else if (this.data.pushButton) {
  51766. this.data.hasOwnCanvas = true;
  51767. this.data.noHTML = false;
  51768. this._processPushButton(params);
  51769. } else {
  51770. warn("Invalid field flags for button widget annotation");
  51771. }
  51772. }
  51773. async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
  51774. if (this.data.pushButton) {
  51775. return super.getOperatorList(evaluator, task, intent, false, annotationStorage);
  51776. }
  51777. let value = null;
  51778. let rotation = null;
  51779. if (annotationStorage) {
  51780. const storageEntry = annotationStorage.get(this.data.id);
  51781. value = storageEntry ? storageEntry.value : null;
  51782. rotation = storageEntry ? storageEntry.rotation : null;
  51783. }
  51784. if (value === null && this.appearance) {
  51785. return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
  51786. }
  51787. if (value === null || value === undefined) {
  51788. value = this.data.checkBox ? this.data.fieldValue === this.data.exportValue : this.data.fieldValue === this.data.buttonValue;
  51789. }
  51790. const appearance = value ? this.checkedAppearance : this.uncheckedAppearance;
  51791. if (appearance) {
  51792. const savedAppearance = this.appearance;
  51793. const savedMatrix = appearance.dict.getArray("Matrix") || IDENTITY_MATRIX;
  51794. if (rotation) {
  51795. appearance.dict.set("Matrix", this.getRotationMatrix(annotationStorage));
  51796. }
  51797. this.appearance = appearance;
  51798. const operatorList = super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
  51799. this.appearance = savedAppearance;
  51800. appearance.dict.set("Matrix", savedMatrix);
  51801. return operatorList;
  51802. }
  51803. return {
  51804. opList: new OperatorList(),
  51805. separateForm: false,
  51806. separateCanvas: false
  51807. };
  51808. }
  51809. async save(evaluator, task, annotationStorage) {
  51810. if (this.data.checkBox) {
  51811. return this._saveCheckbox(evaluator, task, annotationStorage);
  51812. }
  51813. if (this.data.radioButton) {
  51814. return this._saveRadioButton(evaluator, task, annotationStorage);
  51815. }
  51816. return null;
  51817. }
  51818. async _saveCheckbox(evaluator, task, annotationStorage) {
  51819. if (!annotationStorage) {
  51820. return null;
  51821. }
  51822. const storageEntry = annotationStorage.get(this.data.id);
  51823. let rotation = storageEntry?.rotation,
  51824. value = storageEntry?.value;
  51825. if (rotation === undefined) {
  51826. if (value === undefined) {
  51827. return null;
  51828. }
  51829. const defaultValue = this.data.fieldValue === this.data.exportValue;
  51830. if (defaultValue === value) {
  51831. return null;
  51832. }
  51833. }
  51834. const dict = evaluator.xref.fetchIfRef(this.ref);
  51835. if (!(dict instanceof Dict)) {
  51836. return null;
  51837. }
  51838. if (rotation === undefined) {
  51839. rotation = this.rotation;
  51840. }
  51841. if (value === undefined) {
  51842. value = this.data.fieldValue === this.data.exportValue;
  51843. }
  51844. const xfa = {
  51845. path: this.data.fieldName,
  51846. value: value ? this.data.exportValue : ""
  51847. };
  51848. const name = Name.get(value ? this.data.exportValue : "Off");
  51849. dict.set("V", name);
  51850. dict.set("AS", name);
  51851. dict.set("M", `D:${getModificationDate()}`);
  51852. const maybeMK = this._getMKDict(rotation);
  51853. if (maybeMK) {
  51854. dict.set("MK", maybeMK);
  51855. }
  51856. const buffer = [];
  51857. await writeObject(this.ref, dict, buffer, evaluator.xref);
  51858. return [{
  51859. ref: this.ref,
  51860. data: buffer.join(""),
  51861. xfa
  51862. }];
  51863. }
  51864. async _saveRadioButton(evaluator, task, annotationStorage) {
  51865. if (!annotationStorage) {
  51866. return null;
  51867. }
  51868. const storageEntry = annotationStorage.get(this.data.id);
  51869. let rotation = storageEntry?.rotation,
  51870. value = storageEntry?.value;
  51871. if (rotation === undefined) {
  51872. if (value === undefined) {
  51873. return null;
  51874. }
  51875. const defaultValue = this.data.fieldValue === this.data.buttonValue;
  51876. if (defaultValue === value) {
  51877. return null;
  51878. }
  51879. }
  51880. const dict = evaluator.xref.fetchIfRef(this.ref);
  51881. if (!(dict instanceof Dict)) {
  51882. return null;
  51883. }
  51884. if (value === undefined) {
  51885. value = this.data.fieldValue === this.data.buttonValue;
  51886. }
  51887. if (rotation === undefined) {
  51888. rotation = this.rotation;
  51889. }
  51890. const xfa = {
  51891. path: this.data.fieldName,
  51892. value: value ? this.data.buttonValue : ""
  51893. };
  51894. const name = Name.get(value ? this.data.buttonValue : "Off");
  51895. const buffer = [];
  51896. let parentData = null;
  51897. if (value) {
  51898. if (this.parent instanceof Ref) {
  51899. const parent = evaluator.xref.fetch(this.parent);
  51900. parent.set("V", name);
  51901. await writeObject(this.parent, parent, buffer, evaluator.xref);
  51902. parentData = buffer.join("");
  51903. buffer.length = 0;
  51904. } else if (this.parent instanceof Dict) {
  51905. this.parent.set("V", name);
  51906. }
  51907. }
  51908. dict.set("AS", name);
  51909. dict.set("M", `D:${getModificationDate()}`);
  51910. const maybeMK = this._getMKDict(rotation);
  51911. if (maybeMK) {
  51912. dict.set("MK", maybeMK);
  51913. }
  51914. await writeObject(this.ref, dict, buffer, evaluator.xref);
  51915. const newRefs = [{
  51916. ref: this.ref,
  51917. data: buffer.join(""),
  51918. xfa
  51919. }];
  51920. if (parentData) {
  51921. newRefs.push({
  51922. ref: this.parent,
  51923. data: parentData,
  51924. xfa: null
  51925. });
  51926. }
  51927. return newRefs;
  51928. }
  51929. _getDefaultCheckedAppearance(params, type) {
  51930. const width = this.data.rect[2] - this.data.rect[0];
  51931. const height = this.data.rect[3] - this.data.rect[1];
  51932. const bbox = [0, 0, width, height];
  51933. const FONT_RATIO = 0.8;
  51934. const fontSize = Math.min(width, height) * FONT_RATIO;
  51935. let metrics, char;
  51936. if (type === "check") {
  51937. metrics = {
  51938. width: 0.755 * fontSize,
  51939. height: 0.705 * fontSize
  51940. };
  51941. char = "\x33";
  51942. } else if (type === "disc") {
  51943. metrics = {
  51944. width: 0.791 * fontSize,
  51945. height: 0.705 * fontSize
  51946. };
  51947. char = "\x6C";
  51948. } else {
  51949. unreachable(`_getDefaultCheckedAppearance - unsupported type: ${type}`);
  51950. }
  51951. const xShift = numberToString((width - metrics.width) / 2);
  51952. const yShift = numberToString((height - metrics.height) / 2);
  51953. const appearance = `q BT /PdfJsZaDb ${fontSize} Tf 0 g ${xShift} ${yShift} Td (${char}) Tj ET Q`;
  51954. const appearanceStreamDict = new Dict(params.xref);
  51955. appearanceStreamDict.set("FormType", 1);
  51956. appearanceStreamDict.set("Subtype", Name.get("Form"));
  51957. appearanceStreamDict.set("Type", Name.get("XObject"));
  51958. appearanceStreamDict.set("BBox", bbox);
  51959. appearanceStreamDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
  51960. appearanceStreamDict.set("Length", appearance.length);
  51961. const resources = new Dict(params.xref);
  51962. const font = new Dict(params.xref);
  51963. font.set("PdfJsZaDb", this.fallbackFontDict);
  51964. resources.set("Font", font);
  51965. appearanceStreamDict.set("Resources", resources);
  51966. this.checkedAppearance = new StringStream(appearance);
  51967. this.checkedAppearance.dict = appearanceStreamDict;
  51968. this._streams.push(this.checkedAppearance);
  51969. }
  51970. _processCheckBox(params) {
  51971. const customAppearance = params.dict.get("AP");
  51972. if (!(customAppearance instanceof Dict)) {
  51973. return;
  51974. }
  51975. const normalAppearance = customAppearance.get("N");
  51976. if (!(normalAppearance instanceof Dict)) {
  51977. return;
  51978. }
  51979. const asValue = this._decodeFormValue(params.dict.get("AS"));
  51980. if (typeof asValue === "string") {
  51981. this.data.fieldValue = asValue;
  51982. }
  51983. const yes = this.data.fieldValue !== null && this.data.fieldValue !== "Off" ? this.data.fieldValue : "Yes";
  51984. const exportValues = normalAppearance.getKeys();
  51985. if (exportValues.length === 0) {
  51986. exportValues.push("Off", yes);
  51987. } else if (exportValues.length === 1) {
  51988. if (exportValues[0] === "Off") {
  51989. exportValues.push(yes);
  51990. } else {
  51991. exportValues.unshift("Off");
  51992. }
  51993. } else if (exportValues.includes(yes)) {
  51994. exportValues.length = 0;
  51995. exportValues.push("Off", yes);
  51996. } else {
  51997. const otherYes = exportValues.find(v => v !== "Off");
  51998. exportValues.length = 0;
  51999. exportValues.push("Off", otherYes);
  52000. }
  52001. if (!exportValues.includes(this.data.fieldValue)) {
  52002. this.data.fieldValue = "Off";
  52003. }
  52004. this.data.exportValue = exportValues[1];
  52005. const checkedAppearance = normalAppearance.get(this.data.exportValue);
  52006. this.checkedAppearance = checkedAppearance instanceof BaseStream ? checkedAppearance : null;
  52007. const uncheckedAppearance = normalAppearance.get("Off");
  52008. this.uncheckedAppearance = uncheckedAppearance instanceof BaseStream ? uncheckedAppearance : null;
  52009. if (this.checkedAppearance) {
  52010. this._streams.push(this.checkedAppearance);
  52011. } else {
  52012. this._getDefaultCheckedAppearance(params, "check");
  52013. }
  52014. if (this.uncheckedAppearance) {
  52015. this._streams.push(this.uncheckedAppearance);
  52016. }
  52017. this._fallbackFontDict = this.fallbackFontDict;
  52018. if (this.data.defaultFieldValue === null) {
  52019. this.data.defaultFieldValue = "Off";
  52020. }
  52021. }
  52022. _processRadioButton(params) {
  52023. this.data.buttonValue = null;
  52024. const fieldParent = params.dict.get("Parent");
  52025. if (fieldParent instanceof Dict) {
  52026. this.parent = params.dict.getRaw("Parent");
  52027. const fieldParentValue = fieldParent.get("V");
  52028. if (fieldParentValue instanceof Name) {
  52029. this.data.fieldValue = this._decodeFormValue(fieldParentValue);
  52030. }
  52031. }
  52032. const appearanceStates = params.dict.get("AP");
  52033. if (!(appearanceStates instanceof Dict)) {
  52034. return;
  52035. }
  52036. const normalAppearance = appearanceStates.get("N");
  52037. if (!(normalAppearance instanceof Dict)) {
  52038. return;
  52039. }
  52040. for (const key of normalAppearance.getKeys()) {
  52041. if (key !== "Off") {
  52042. this.data.buttonValue = this._decodeFormValue(key);
  52043. break;
  52044. }
  52045. }
  52046. const checkedAppearance = normalAppearance.get(this.data.buttonValue);
  52047. this.checkedAppearance = checkedAppearance instanceof BaseStream ? checkedAppearance : null;
  52048. const uncheckedAppearance = normalAppearance.get("Off");
  52049. this.uncheckedAppearance = uncheckedAppearance instanceof BaseStream ? uncheckedAppearance : null;
  52050. if (this.checkedAppearance) {
  52051. this._streams.push(this.checkedAppearance);
  52052. } else {
  52053. this._getDefaultCheckedAppearance(params, "disc");
  52054. }
  52055. if (this.uncheckedAppearance) {
  52056. this._streams.push(this.uncheckedAppearance);
  52057. }
  52058. this._fallbackFontDict = this.fallbackFontDict;
  52059. if (this.data.defaultFieldValue === null) {
  52060. this.data.defaultFieldValue = "Off";
  52061. }
  52062. }
  52063. _processPushButton(params) {
  52064. const {
  52065. dict,
  52066. annotationGlobals
  52067. } = params;
  52068. if (!dict.has("A") && !dict.has("AA") && !this.data.alternativeText) {
  52069. warn("Push buttons without action dictionaries are not supported");
  52070. return;
  52071. }
  52072. this.data.isTooltipOnly = !dict.has("A") && !dict.has("AA");
  52073. Catalog.parseDestDictionary({
  52074. destDict: dict,
  52075. resultObj: this.data,
  52076. docBaseUrl: annotationGlobals.baseUrl,
  52077. docAttachments: annotationGlobals.attachments
  52078. });
  52079. }
  52080. getFieldObject() {
  52081. let type = "button";
  52082. let exportValues;
  52083. if (this.data.checkBox) {
  52084. type = "checkbox";
  52085. exportValues = this.data.exportValue;
  52086. } else if (this.data.radioButton) {
  52087. type = "radiobutton";
  52088. exportValues = this.data.buttonValue;
  52089. }
  52090. return {
  52091. id: this.data.id,
  52092. value: this.data.fieldValue || "Off",
  52093. defaultValue: this.data.defaultFieldValue,
  52094. exportValues,
  52095. editable: !this.data.readOnly,
  52096. name: this.data.fieldName,
  52097. rect: this.data.rect,
  52098. hidden: this.data.hidden,
  52099. actions: this.data.actions,
  52100. page: this.data.pageIndex,
  52101. strokeColor: this.data.borderColor,
  52102. fillColor: this.data.backgroundColor,
  52103. rotation: this.rotation,
  52104. type
  52105. };
  52106. }
  52107. get fallbackFontDict() {
  52108. const dict = new Dict();
  52109. dict.set("BaseFont", Name.get("ZapfDingbats"));
  52110. dict.set("Type", Name.get("FallbackType"));
  52111. dict.set("Subtype", Name.get("FallbackType"));
  52112. dict.set("Encoding", Name.get("ZapfDingbatsEncoding"));
  52113. return shadow(this, "fallbackFontDict", dict);
  52114. }
  52115. }
  52116. class ChoiceWidgetAnnotation extends WidgetAnnotation {
  52117. constructor(params) {
  52118. super(params);
  52119. const {
  52120. dict,
  52121. xref
  52122. } = params;
  52123. this.indices = dict.getArray("I");
  52124. this.hasIndices = Array.isArray(this.indices) && this.indices.length > 0;
  52125. this.data.options = [];
  52126. const options = getInheritableProperty({
  52127. dict,
  52128. key: "Opt"
  52129. });
  52130. if (Array.isArray(options)) {
  52131. for (let i = 0, ii = options.length; i < ii; i++) {
  52132. const option = xref.fetchIfRef(options[i]);
  52133. const isOptionArray = Array.isArray(option);
  52134. this.data.options[i] = {
  52135. exportValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[0]) : option),
  52136. displayValue: this._decodeFormValue(isOptionArray ? xref.fetchIfRef(option[1]) : option)
  52137. };
  52138. }
  52139. }
  52140. if (!this.hasIndices) {
  52141. if (typeof this.data.fieldValue === "string") {
  52142. this.data.fieldValue = [this.data.fieldValue];
  52143. } else if (!this.data.fieldValue) {
  52144. this.data.fieldValue = [];
  52145. }
  52146. } else {
  52147. this.data.fieldValue = [];
  52148. const ii = this.data.options.length;
  52149. for (const i of this.indices) {
  52150. if (Number.isInteger(i) && i >= 0 && i < ii) {
  52151. this.data.fieldValue.push(this.data.options[i].exportValue);
  52152. }
  52153. }
  52154. }
  52155. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  52156. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  52157. this._hasText = true;
  52158. }
  52159. getFieldObject() {
  52160. const type = this.data.combo ? "combobox" : "listbox";
  52161. const value = this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : null;
  52162. return {
  52163. id: this.data.id,
  52164. value,
  52165. defaultValue: this.data.defaultFieldValue,
  52166. editable: !this.data.readOnly,
  52167. name: this.data.fieldName,
  52168. rect: this.data.rect,
  52169. numItems: this.data.fieldValue.length,
  52170. multipleSelection: this.data.multiSelect,
  52171. hidden: this.data.hidden,
  52172. actions: this.data.actions,
  52173. items: this.data.options,
  52174. page: this.data.pageIndex,
  52175. strokeColor: this.data.borderColor,
  52176. fillColor: this.data.backgroundColor,
  52177. rotation: this.rotation,
  52178. type
  52179. };
  52180. }
  52181. amendSavedDict(annotationStorage, dict) {
  52182. if (!this.hasIndices) {
  52183. return;
  52184. }
  52185. let values = annotationStorage?.get(this.data.id)?.value;
  52186. if (!Array.isArray(values)) {
  52187. values = [values];
  52188. }
  52189. const indices = [];
  52190. const {
  52191. options
  52192. } = this.data;
  52193. for (let i = 0, j = 0, ii = options.length; i < ii; i++) {
  52194. if (options[i].exportValue === values[j]) {
  52195. indices.push(i);
  52196. j += 1;
  52197. }
  52198. }
  52199. dict.set("I", indices);
  52200. }
  52201. async _getAppearance(evaluator, task, intent, annotationStorage) {
  52202. if (this.data.combo) {
  52203. return super._getAppearance(evaluator, task, intent, annotationStorage);
  52204. }
  52205. let exportedValue, rotation;
  52206. const storageEntry = annotationStorage?.get(this.data.id);
  52207. if (storageEntry) {
  52208. rotation = storageEntry.rotation;
  52209. exportedValue = storageEntry.value;
  52210. }
  52211. if (rotation === undefined && exportedValue === undefined && !this._needAppearances) {
  52212. return null;
  52213. }
  52214. if (exportedValue === undefined) {
  52215. exportedValue = this.data.fieldValue;
  52216. } else if (!Array.isArray(exportedValue)) {
  52217. exportedValue = [exportedValue];
  52218. }
  52219. const defaultPadding = 1;
  52220. const defaultHPadding = 2;
  52221. let totalHeight = this.data.rect[3] - this.data.rect[1];
  52222. let totalWidth = this.data.rect[2] - this.data.rect[0];
  52223. if (rotation === 90 || rotation === 270) {
  52224. [totalWidth, totalHeight] = [totalHeight, totalWidth];
  52225. }
  52226. const lineCount = this.data.options.length;
  52227. const valueIndices = [];
  52228. for (let i = 0; i < lineCount; i++) {
  52229. const {
  52230. exportValue
  52231. } = this.data.options[i];
  52232. if (exportedValue.includes(exportValue)) {
  52233. valueIndices.push(i);
  52234. }
  52235. }
  52236. if (!this._defaultAppearance) {
  52237. this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g");
  52238. }
  52239. const font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources);
  52240. let defaultAppearance;
  52241. let {
  52242. fontSize
  52243. } = this.data.defaultAppearanceData;
  52244. if (!fontSize) {
  52245. const lineHeight = (totalHeight - defaultPadding) / lineCount;
  52246. let lineWidth = -1;
  52247. let value;
  52248. for (const {
  52249. displayValue
  52250. } of this.data.options) {
  52251. const width = this._getTextWidth(displayValue, font);
  52252. if (width > lineWidth) {
  52253. lineWidth = width;
  52254. value = displayValue;
  52255. }
  52256. }
  52257. [defaultAppearance, fontSize] = this._computeFontSize(lineHeight, totalWidth - 2 * defaultHPadding, value, font, -1);
  52258. } else {
  52259. defaultAppearance = this._defaultAppearance;
  52260. }
  52261. const lineHeight = fontSize * LINE_FACTOR;
  52262. const vPadding = (lineHeight - fontSize) / 2;
  52263. const numberOfVisibleLines = Math.floor(totalHeight / lineHeight);
  52264. let firstIndex = 0;
  52265. if (valueIndices.length > 0) {
  52266. const minIndex = Math.min(...valueIndices);
  52267. const maxIndex = Math.max(...valueIndices);
  52268. firstIndex = Math.max(0, maxIndex - numberOfVisibleLines + 1);
  52269. if (firstIndex > minIndex) {
  52270. firstIndex = minIndex;
  52271. }
  52272. }
  52273. const end = Math.min(firstIndex + numberOfVisibleLines + 1, lineCount);
  52274. const buf = ["/Tx BMC q", `1 1 ${totalWidth} ${totalHeight} re W n`];
  52275. if (valueIndices.length) {
  52276. buf.push("0.600006 0.756866 0.854904 rg");
  52277. for (const index of valueIndices) {
  52278. if (firstIndex <= index && index < end) {
  52279. buf.push(`1 ${totalHeight - (index - firstIndex + 1) * lineHeight} ${totalWidth} ${lineHeight} re f`);
  52280. }
  52281. }
  52282. }
  52283. buf.push("BT", defaultAppearance, `1 0 0 1 0 ${totalHeight} Tm`);
  52284. const prevInfo = {
  52285. shift: 0
  52286. };
  52287. for (let i = firstIndex; i < end; i++) {
  52288. const {
  52289. displayValue
  52290. } = this.data.options[i];
  52291. const vpadding = i === firstIndex ? vPadding : 0;
  52292. buf.push(this._renderText(displayValue, font, fontSize, totalWidth, 0, prevInfo, defaultHPadding, -lineHeight + vpadding));
  52293. }
  52294. buf.push("ET Q EMC");
  52295. return buf.join("\n");
  52296. }
  52297. }
  52298. class SignatureWidgetAnnotation extends WidgetAnnotation {
  52299. constructor(params) {
  52300. super(params);
  52301. this.data.fieldValue = null;
  52302. this.data.hasOwnCanvas = this.data.noRotate;
  52303. this.data.noHTML = !this.data.hasOwnCanvas;
  52304. }
  52305. getFieldObject() {
  52306. return {
  52307. id: this.data.id,
  52308. value: null,
  52309. page: this.data.pageIndex,
  52310. type: "signature"
  52311. };
  52312. }
  52313. }
  52314. class TextAnnotation extends MarkupAnnotation {
  52315. constructor(params) {
  52316. const DEFAULT_ICON_SIZE = 22;
  52317. super(params);
  52318. this.data.noRotate = true;
  52319. this.data.hasOwnCanvas = this.data.noRotate;
  52320. this.data.noHTML = false;
  52321. const {
  52322. dict
  52323. } = params;
  52324. this.data.annotationType = AnnotationType.TEXT;
  52325. if (this.data.hasAppearance) {
  52326. this.data.name = "NoIcon";
  52327. } else {
  52328. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  52329. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  52330. this.data.name = dict.has("Name") ? dict.get("Name").name : "Note";
  52331. }
  52332. if (dict.has("State")) {
  52333. this.data.state = dict.get("State") || null;
  52334. this.data.stateModel = dict.get("StateModel") || null;
  52335. } else {
  52336. this.data.state = null;
  52337. this.data.stateModel = null;
  52338. }
  52339. }
  52340. }
  52341. class LinkAnnotation extends Annotation {
  52342. constructor(params) {
  52343. super(params);
  52344. const {
  52345. dict,
  52346. annotationGlobals
  52347. } = params;
  52348. this.data.annotationType = AnnotationType.LINK;
  52349. const quadPoints = getQuadPoints(dict, this.rectangle);
  52350. if (quadPoints) {
  52351. this.data.quadPoints = quadPoints;
  52352. }
  52353. this.data.borderColor ||= this.data.color;
  52354. Catalog.parseDestDictionary({
  52355. destDict: dict,
  52356. resultObj: this.data,
  52357. docBaseUrl: annotationGlobals.baseUrl,
  52358. docAttachments: annotationGlobals.attachments
  52359. });
  52360. }
  52361. }
  52362. class PopupAnnotation extends Annotation {
  52363. constructor(params) {
  52364. super(params);
  52365. const {
  52366. dict
  52367. } = params;
  52368. this.data.annotationType = AnnotationType.POPUP;
  52369. this.data.noHTML = false;
  52370. if (this.data.rect[0] === this.data.rect[2] || this.data.rect[1] === this.data.rect[3]) {
  52371. this.data.rect = null;
  52372. }
  52373. let parentItem = dict.get("Parent");
  52374. if (!parentItem) {
  52375. warn("Popup annotation has a missing or invalid parent annotation.");
  52376. return;
  52377. }
  52378. const parentRect = parentItem.getArray("Rect");
  52379. this.data.parentRect = Array.isArray(parentRect) && parentRect.length === 4 ? Util.normalizeRect(parentRect) : null;
  52380. const rt = parentItem.get("RT");
  52381. if (isName(rt, AnnotationReplyType.GROUP)) {
  52382. parentItem = parentItem.get("IRT");
  52383. }
  52384. if (!parentItem.has("M")) {
  52385. this.data.modificationDate = null;
  52386. } else {
  52387. this.setModificationDate(parentItem.get("M"));
  52388. this.data.modificationDate = this.modificationDate;
  52389. }
  52390. if (!parentItem.has("C")) {
  52391. this.data.color = null;
  52392. } else {
  52393. this.setColor(parentItem.getArray("C"));
  52394. this.data.color = this.color;
  52395. }
  52396. if (!this.viewable) {
  52397. const parentFlags = parentItem.get("F");
  52398. if (this._isViewable(parentFlags)) {
  52399. this.setFlags(parentFlags);
  52400. }
  52401. }
  52402. this.setTitle(parentItem.get("T"));
  52403. this.data.titleObj = this._title;
  52404. this.setContents(parentItem.get("Contents"));
  52405. this.data.contentsObj = this._contents;
  52406. if (parentItem.has("RC")) {
  52407. this.data.richText = XFAFactory.getRichTextAsHtml(parentItem.get("RC"));
  52408. }
  52409. this.data.open = !!dict.get("Open");
  52410. }
  52411. }
  52412. class FreeTextAnnotation extends MarkupAnnotation {
  52413. constructor(params) {
  52414. super(params);
  52415. this.data.hasOwnCanvas = !this.data.noHTML;
  52416. this.data.noHTML = false;
  52417. const {
  52418. evaluatorOptions,
  52419. xref
  52420. } = params;
  52421. this.data.annotationType = AnnotationType.FREETEXT;
  52422. this.setDefaultAppearance(params);
  52423. if (this.appearance) {
  52424. const {
  52425. fontColor,
  52426. fontSize
  52427. } = parseAppearanceStream(this.appearance, evaluatorOptions, xref);
  52428. this.data.defaultAppearanceData.fontColor = fontColor;
  52429. this.data.defaultAppearanceData.fontSize = fontSize || 10;
  52430. } else if (this._isOffscreenCanvasSupported) {
  52431. const strokeAlpha = params.dict.get("CA");
  52432. const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
  52433. this.data.defaultAppearanceData.fontSize ||= 10;
  52434. const {
  52435. fontColor,
  52436. fontSize
  52437. } = this.data.defaultAppearanceData;
  52438. this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
  52439. this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream);
  52440. } else {
  52441. warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
  52442. }
  52443. }
  52444. get hasTextContent() {
  52445. return !!this.appearance;
  52446. }
  52447. static createNewDict(annotation, xref, {
  52448. apRef,
  52449. ap
  52450. }) {
  52451. const {
  52452. color,
  52453. fontSize,
  52454. rect,
  52455. rotation,
  52456. user,
  52457. value
  52458. } = annotation;
  52459. const freetext = new Dict(xref);
  52460. freetext.set("Type", Name.get("Annot"));
  52461. freetext.set("Subtype", Name.get("FreeText"));
  52462. freetext.set("CreationDate", `D:${getModificationDate()}`);
  52463. freetext.set("Rect", rect);
  52464. const da = `/Helv ${fontSize} Tf ${getPdfColor(color, true)}`;
  52465. freetext.set("DA", da);
  52466. freetext.set("Contents", isAscii(value) ? value : stringToUTF16String(value, true));
  52467. freetext.set("F", 4);
  52468. freetext.set("Border", [0, 0, 0]);
  52469. freetext.set("Rotate", rotation);
  52470. if (user) {
  52471. freetext.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
  52472. }
  52473. if (apRef || ap) {
  52474. const n = new Dict(xref);
  52475. freetext.set("AP", n);
  52476. if (apRef) {
  52477. n.set("N", apRef);
  52478. } else {
  52479. n.set("N", ap);
  52480. }
  52481. }
  52482. return freetext;
  52483. }
  52484. static async createNewAppearanceStream(annotation, xref, params) {
  52485. const {
  52486. baseFontRef,
  52487. evaluator,
  52488. task
  52489. } = params;
  52490. const {
  52491. color,
  52492. fontSize,
  52493. rect,
  52494. rotation,
  52495. value
  52496. } = annotation;
  52497. const resources = new Dict(xref);
  52498. const font = new Dict(xref);
  52499. if (baseFontRef) {
  52500. font.set("Helv", baseFontRef);
  52501. } else {
  52502. const baseFont = new Dict(xref);
  52503. baseFont.set("BaseFont", Name.get("Helvetica"));
  52504. baseFont.set("Type", Name.get("Font"));
  52505. baseFont.set("Subtype", Name.get("Type1"));
  52506. baseFont.set("Encoding", Name.get("WinAnsiEncoding"));
  52507. font.set("Helv", baseFont);
  52508. }
  52509. resources.set("Font", font);
  52510. const helv = await WidgetAnnotation._getFontData(evaluator, task, {
  52511. fontName: "Helv",
  52512. fontSize
  52513. }, resources);
  52514. const [x1, y1, x2, y2] = rect;
  52515. let w = x2 - x1;
  52516. let h = y2 - y1;
  52517. if (rotation % 180 !== 0) {
  52518. [w, h] = [h, w];
  52519. }
  52520. const lines = value.split("\n");
  52521. const scale = fontSize / 1000;
  52522. let totalWidth = -Infinity;
  52523. const encodedLines = [];
  52524. for (let line of lines) {
  52525. const encoded = helv.encodeString(line);
  52526. if (encoded.length > 1) {
  52527. return null;
  52528. }
  52529. line = encoded.join("");
  52530. encodedLines.push(line);
  52531. let lineWidth = 0;
  52532. const glyphs = helv.charsToGlyphs(line);
  52533. for (const glyph of glyphs) {
  52534. lineWidth += glyph.width * scale;
  52535. }
  52536. totalWidth = Math.max(totalWidth, lineWidth);
  52537. }
  52538. let hscale = 1;
  52539. if (totalWidth > w) {
  52540. hscale = w / totalWidth;
  52541. }
  52542. let vscale = 1;
  52543. const lineHeight = LINE_FACTOR * fontSize;
  52544. const lineAscent = (LINE_FACTOR - LINE_DESCENT_FACTOR) * fontSize;
  52545. const totalHeight = lineHeight * lines.length;
  52546. if (totalHeight > h) {
  52547. vscale = h / totalHeight;
  52548. }
  52549. const fscale = Math.min(hscale, vscale);
  52550. const newFontSize = fontSize * fscale;
  52551. let firstPoint, clipBox, matrix;
  52552. switch (rotation) {
  52553. case 0:
  52554. matrix = [1, 0, 0, 1];
  52555. clipBox = [rect[0], rect[1], w, h];
  52556. firstPoint = [rect[0], rect[3] - lineAscent];
  52557. break;
  52558. case 90:
  52559. matrix = [0, 1, -1, 0];
  52560. clipBox = [rect[1], -rect[2], w, h];
  52561. firstPoint = [rect[1], -rect[0] - lineAscent];
  52562. break;
  52563. case 180:
  52564. matrix = [-1, 0, 0, -1];
  52565. clipBox = [-rect[2], -rect[3], w, h];
  52566. firstPoint = [-rect[2], -rect[1] - lineAscent];
  52567. break;
  52568. case 270:
  52569. matrix = [0, -1, 1, 0];
  52570. clipBox = [-rect[3], rect[0], w, h];
  52571. firstPoint = [-rect[3], rect[2] - lineAscent];
  52572. break;
  52573. }
  52574. const buffer = ["q", `${matrix.join(" ")} 0 0 cm`, `${clipBox.join(" ")} re W n`, `BT`, `${getPdfColor(color, true)}`, `0 Tc /Helv ${numberToString(newFontSize)} Tf`];
  52575. buffer.push(`${firstPoint.join(" ")} Td (${escapeString(encodedLines[0])}) Tj`);
  52576. const vShift = numberToString(lineHeight);
  52577. for (let i = 1, ii = encodedLines.length; i < ii; i++) {
  52578. const line = encodedLines[i];
  52579. buffer.push(`0 -${vShift} Td (${escapeString(line)}) Tj`);
  52580. }
  52581. buffer.push("ET", "Q");
  52582. const appearance = buffer.join("\n");
  52583. const appearanceStreamDict = new Dict(xref);
  52584. appearanceStreamDict.set("FormType", 1);
  52585. appearanceStreamDict.set("Subtype", Name.get("Form"));
  52586. appearanceStreamDict.set("Type", Name.get("XObject"));
  52587. appearanceStreamDict.set("BBox", rect);
  52588. appearanceStreamDict.set("Resources", resources);
  52589. appearanceStreamDict.set("Matrix", [1, 0, 0, 1, -rect[0], -rect[1]]);
  52590. const ap = new StringStream(appearance);
  52591. ap.dict = appearanceStreamDict;
  52592. return ap;
  52593. }
  52594. }
  52595. class LineAnnotation extends MarkupAnnotation {
  52596. constructor(params) {
  52597. super(params);
  52598. const {
  52599. dict,
  52600. xref
  52601. } = params;
  52602. this.data.annotationType = AnnotationType.LINE;
  52603. this.data.hasOwnCanvas = this.data.noRotate;
  52604. this.data.noHTML = false;
  52605. const lineCoordinates = dict.getArray("L");
  52606. this.data.lineCoordinates = Util.normalizeRect(lineCoordinates);
  52607. this.setLineEndings(dict.getArray("LE"));
  52608. this.data.lineEndings = this.lineEndings;
  52609. if (!this.appearance) {
  52610. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  52611. const strokeAlpha = dict.get("CA");
  52612. const interiorColor = getRgbColor(dict.getArray("IC"), null);
  52613. const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
  52614. const fillAlpha = fillColor ? strokeAlpha : null;
  52615. const borderWidth = this.borderStyle.width || 1,
  52616. borderAdjust = 2 * borderWidth;
  52617. const bbox = [this.data.lineCoordinates[0] - borderAdjust, this.data.lineCoordinates[1] - borderAdjust, this.data.lineCoordinates[2] + borderAdjust, this.data.lineCoordinates[3] + borderAdjust];
  52618. if (!Util.intersect(this.rectangle, bbox)) {
  52619. this.rectangle = bbox;
  52620. }
  52621. this._setDefaultAppearance({
  52622. xref,
  52623. extra: `${borderWidth} w`,
  52624. strokeColor,
  52625. fillColor,
  52626. strokeAlpha,
  52627. fillAlpha,
  52628. pointsCallback: (buffer, points) => {
  52629. buffer.push(`${lineCoordinates[0]} ${lineCoordinates[1]} m`, `${lineCoordinates[2]} ${lineCoordinates[3]} l`, "S");
  52630. return [points[0].x - borderWidth, points[1].x + borderWidth, points[3].y - borderWidth, points[1].y + borderWidth];
  52631. }
  52632. });
  52633. }
  52634. }
  52635. }
  52636. class SquareAnnotation extends MarkupAnnotation {
  52637. constructor(params) {
  52638. super(params);
  52639. const {
  52640. dict,
  52641. xref
  52642. } = params;
  52643. this.data.annotationType = AnnotationType.SQUARE;
  52644. this.data.hasOwnCanvas = this.data.noRotate;
  52645. this.data.noHTML = false;
  52646. if (!this.appearance) {
  52647. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  52648. const strokeAlpha = dict.get("CA");
  52649. const interiorColor = getRgbColor(dict.getArray("IC"), null);
  52650. const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
  52651. const fillAlpha = fillColor ? strokeAlpha : null;
  52652. if (this.borderStyle.width === 0 && !fillColor) {
  52653. return;
  52654. }
  52655. this._setDefaultAppearance({
  52656. xref,
  52657. extra: `${this.borderStyle.width} w`,
  52658. strokeColor,
  52659. fillColor,
  52660. strokeAlpha,
  52661. fillAlpha,
  52662. pointsCallback: (buffer, points) => {
  52663. const x = points[2].x + this.borderStyle.width / 2;
  52664. const y = points[2].y + this.borderStyle.width / 2;
  52665. const width = points[3].x - points[2].x - this.borderStyle.width;
  52666. const height = points[1].y - points[3].y - this.borderStyle.width;
  52667. buffer.push(`${x} ${y} ${width} ${height} re`);
  52668. if (fillColor) {
  52669. buffer.push("B");
  52670. } else {
  52671. buffer.push("S");
  52672. }
  52673. return [points[0].x, points[1].x, points[3].y, points[1].y];
  52674. }
  52675. });
  52676. }
  52677. }
  52678. }
  52679. class CircleAnnotation extends MarkupAnnotation {
  52680. constructor(params) {
  52681. super(params);
  52682. const {
  52683. dict,
  52684. xref
  52685. } = params;
  52686. this.data.annotationType = AnnotationType.CIRCLE;
  52687. if (!this.appearance) {
  52688. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  52689. const strokeAlpha = dict.get("CA");
  52690. const interiorColor = getRgbColor(dict.getArray("IC"), null);
  52691. const fillColor = interiorColor ? getPdfColorArray(interiorColor) : null;
  52692. const fillAlpha = fillColor ? strokeAlpha : null;
  52693. if (this.borderStyle.width === 0 && !fillColor) {
  52694. return;
  52695. }
  52696. const controlPointsDistance = 4 / 3 * Math.tan(Math.PI / (2 * 4));
  52697. this._setDefaultAppearance({
  52698. xref,
  52699. extra: `${this.borderStyle.width} w`,
  52700. strokeColor,
  52701. fillColor,
  52702. strokeAlpha,
  52703. fillAlpha,
  52704. pointsCallback: (buffer, points) => {
  52705. const x0 = points[0].x + this.borderStyle.width / 2;
  52706. const y0 = points[0].y - this.borderStyle.width / 2;
  52707. const x1 = points[3].x - this.borderStyle.width / 2;
  52708. const y1 = points[3].y + this.borderStyle.width / 2;
  52709. const xMid = x0 + (x1 - x0) / 2;
  52710. const yMid = y0 + (y1 - y0) / 2;
  52711. const xOffset = (x1 - x0) / 2 * controlPointsDistance;
  52712. const yOffset = (y1 - y0) / 2 * controlPointsDistance;
  52713. buffer.push(`${xMid} ${y1} m`, `${xMid + xOffset} ${y1} ${x1} ${yMid + yOffset} ${x1} ${yMid} c`, `${x1} ${yMid - yOffset} ${xMid + xOffset} ${y0} ${xMid} ${y0} c`, `${xMid - xOffset} ${y0} ${x0} ${yMid - yOffset} ${x0} ${yMid} c`, `${x0} ${yMid + yOffset} ${xMid - xOffset} ${y1} ${xMid} ${y1} c`, "h");
  52714. if (fillColor) {
  52715. buffer.push("B");
  52716. } else {
  52717. buffer.push("S");
  52718. }
  52719. return [points[0].x, points[1].x, points[3].y, points[1].y];
  52720. }
  52721. });
  52722. }
  52723. }
  52724. }
  52725. class PolylineAnnotation extends MarkupAnnotation {
  52726. constructor(params) {
  52727. super(params);
  52728. const {
  52729. dict,
  52730. xref
  52731. } = params;
  52732. this.data.annotationType = AnnotationType.POLYLINE;
  52733. this.data.hasOwnCanvas = this.data.noRotate;
  52734. this.data.noHTML = false;
  52735. this.data.vertices = [];
  52736. if (!(this instanceof PolygonAnnotation)) {
  52737. this.setLineEndings(dict.getArray("LE"));
  52738. this.data.lineEndings = this.lineEndings;
  52739. }
  52740. const rawVertices = dict.getArray("Vertices");
  52741. if (!Array.isArray(rawVertices)) {
  52742. return;
  52743. }
  52744. for (let i = 0, ii = rawVertices.length; i < ii; i += 2) {
  52745. this.data.vertices.push({
  52746. x: rawVertices[i],
  52747. y: rawVertices[i + 1]
  52748. });
  52749. }
  52750. if (!this.appearance) {
  52751. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  52752. const strokeAlpha = dict.get("CA");
  52753. const borderWidth = this.borderStyle.width || 1,
  52754. borderAdjust = 2 * borderWidth;
  52755. const bbox = [Infinity, Infinity, -Infinity, -Infinity];
  52756. for (const vertex of this.data.vertices) {
  52757. bbox[0] = Math.min(bbox[0], vertex.x - borderAdjust);
  52758. bbox[1] = Math.min(bbox[1], vertex.y - borderAdjust);
  52759. bbox[2] = Math.max(bbox[2], vertex.x + borderAdjust);
  52760. bbox[3] = Math.max(bbox[3], vertex.y + borderAdjust);
  52761. }
  52762. if (!Util.intersect(this.rectangle, bbox)) {
  52763. this.rectangle = bbox;
  52764. }
  52765. this._setDefaultAppearance({
  52766. xref,
  52767. extra: `${borderWidth} w`,
  52768. strokeColor,
  52769. strokeAlpha,
  52770. pointsCallback: (buffer, points) => {
  52771. const vertices = this.data.vertices;
  52772. for (let i = 0, ii = vertices.length; i < ii; i++) {
  52773. buffer.push(`${vertices[i].x} ${vertices[i].y} ${i === 0 ? "m" : "l"}`);
  52774. }
  52775. buffer.push("S");
  52776. return [points[0].x, points[1].x, points[3].y, points[1].y];
  52777. }
  52778. });
  52779. }
  52780. }
  52781. }
  52782. class PolygonAnnotation extends PolylineAnnotation {
  52783. constructor(params) {
  52784. super(params);
  52785. this.data.annotationType = AnnotationType.POLYGON;
  52786. }
  52787. }
  52788. class CaretAnnotation extends MarkupAnnotation {
  52789. constructor(params) {
  52790. super(params);
  52791. this.data.annotationType = AnnotationType.CARET;
  52792. }
  52793. }
  52794. class InkAnnotation extends MarkupAnnotation {
  52795. constructor(params) {
  52796. super(params);
  52797. this.data.hasOwnCanvas = this.data.noRotate;
  52798. this.data.noHTML = false;
  52799. const {
  52800. dict,
  52801. xref
  52802. } = params;
  52803. this.data.annotationType = AnnotationType.INK;
  52804. this.data.inkLists = [];
  52805. const rawInkLists = dict.getArray("InkList");
  52806. if (!Array.isArray(rawInkLists)) {
  52807. return;
  52808. }
  52809. for (let i = 0, ii = rawInkLists.length; i < ii; ++i) {
  52810. this.data.inkLists.push([]);
  52811. for (let j = 0, jj = rawInkLists[i].length; j < jj; j += 2) {
  52812. this.data.inkLists[i].push({
  52813. x: xref.fetchIfRef(rawInkLists[i][j]),
  52814. y: xref.fetchIfRef(rawInkLists[i][j + 1])
  52815. });
  52816. }
  52817. }
  52818. if (!this.appearance) {
  52819. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  52820. const strokeAlpha = dict.get("CA");
  52821. const borderWidth = this.borderStyle.width || 1,
  52822. borderAdjust = 2 * borderWidth;
  52823. const bbox = [Infinity, Infinity, -Infinity, -Infinity];
  52824. for (const inkLists of this.data.inkLists) {
  52825. for (const vertex of inkLists) {
  52826. bbox[0] = Math.min(bbox[0], vertex.x - borderAdjust);
  52827. bbox[1] = Math.min(bbox[1], vertex.y - borderAdjust);
  52828. bbox[2] = Math.max(bbox[2], vertex.x + borderAdjust);
  52829. bbox[3] = Math.max(bbox[3], vertex.y + borderAdjust);
  52830. }
  52831. }
  52832. if (!Util.intersect(this.rectangle, bbox)) {
  52833. this.rectangle = bbox;
  52834. }
  52835. this._setDefaultAppearance({
  52836. xref,
  52837. extra: `${borderWidth} w`,
  52838. strokeColor,
  52839. strokeAlpha,
  52840. pointsCallback: (buffer, points) => {
  52841. for (const inkList of this.data.inkLists) {
  52842. for (let i = 0, ii = inkList.length; i < ii; i++) {
  52843. buffer.push(`${inkList[i].x} ${inkList[i].y} ${i === 0 ? "m" : "l"}`);
  52844. }
  52845. buffer.push("S");
  52846. }
  52847. return [points[0].x, points[1].x, points[3].y, points[1].y];
  52848. }
  52849. });
  52850. }
  52851. }
  52852. static createNewDict(annotation, xref, {
  52853. apRef,
  52854. ap
  52855. }) {
  52856. const {
  52857. color,
  52858. opacity,
  52859. paths,
  52860. rect,
  52861. rotation,
  52862. thickness
  52863. } = annotation;
  52864. const ink = new Dict(xref);
  52865. ink.set("Type", Name.get("Annot"));
  52866. ink.set("Subtype", Name.get("Ink"));
  52867. ink.set("CreationDate", `D:${getModificationDate()}`);
  52868. ink.set("Rect", rect);
  52869. ink.set("InkList", paths.map(p => p.points));
  52870. ink.set("F", 4);
  52871. ink.set("Rotate", rotation);
  52872. const bs = new Dict(xref);
  52873. ink.set("BS", bs);
  52874. bs.set("W", thickness);
  52875. ink.set("C", Array.from(color, c => c / 255));
  52876. ink.set("CA", opacity);
  52877. const n = new Dict(xref);
  52878. ink.set("AP", n);
  52879. if (apRef) {
  52880. n.set("N", apRef);
  52881. } else {
  52882. n.set("N", ap);
  52883. }
  52884. return ink;
  52885. }
  52886. static async createNewAppearanceStream(annotation, xref, params) {
  52887. const {
  52888. color,
  52889. rect,
  52890. paths,
  52891. thickness,
  52892. opacity
  52893. } = annotation;
  52894. const appearanceBuffer = [`${thickness} w 1 J 1 j`, `${getPdfColor(color, false)}`];
  52895. if (opacity !== 1) {
  52896. appearanceBuffer.push("/R0 gs");
  52897. }
  52898. const buffer = [];
  52899. for (const {
  52900. bezier
  52901. } of paths) {
  52902. buffer.length = 0;
  52903. buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} m`);
  52904. for (let i = 2, ii = bezier.length; i < ii; i += 6) {
  52905. const curve = bezier.slice(i, i + 6).map(numberToString).join(" ");
  52906. buffer.push(`${curve} c`);
  52907. }
  52908. buffer.push("S");
  52909. appearanceBuffer.push(buffer.join("\n"));
  52910. }
  52911. const appearance = appearanceBuffer.join("\n");
  52912. const appearanceStreamDict = new Dict(xref);
  52913. appearanceStreamDict.set("FormType", 1);
  52914. appearanceStreamDict.set("Subtype", Name.get("Form"));
  52915. appearanceStreamDict.set("Type", Name.get("XObject"));
  52916. appearanceStreamDict.set("BBox", rect);
  52917. appearanceStreamDict.set("Length", appearance.length);
  52918. if (opacity !== 1) {
  52919. const resources = new Dict(xref);
  52920. const extGState = new Dict(xref);
  52921. const r0 = new Dict(xref);
  52922. r0.set("CA", opacity);
  52923. r0.set("Type", Name.get("ExtGState"));
  52924. extGState.set("R0", r0);
  52925. resources.set("ExtGState", extGState);
  52926. appearanceStreamDict.set("Resources", resources);
  52927. }
  52928. const ap = new StringStream(appearance);
  52929. ap.dict = appearanceStreamDict;
  52930. return ap;
  52931. }
  52932. }
  52933. class HighlightAnnotation extends MarkupAnnotation {
  52934. constructor(params) {
  52935. super(params);
  52936. const {
  52937. dict,
  52938. xref
  52939. } = params;
  52940. this.data.annotationType = AnnotationType.HIGHLIGHT;
  52941. const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
  52942. if (quadPoints) {
  52943. const resources = this.appearance?.dict.get("Resources");
  52944. if (!this.appearance || !resources?.has("ExtGState")) {
  52945. if (this.appearance) {
  52946. warn("HighlightAnnotation - ignoring built-in appearance stream.");
  52947. }
  52948. const fillColor = this.color ? getPdfColorArray(this.color) : [1, 1, 0];
  52949. const fillAlpha = dict.get("CA");
  52950. this._setDefaultAppearance({
  52951. xref,
  52952. fillColor,
  52953. blendMode: "Multiply",
  52954. fillAlpha,
  52955. pointsCallback: (buffer, points) => {
  52956. buffer.push(`${points[0].x} ${points[0].y} m`, `${points[1].x} ${points[1].y} l`, `${points[3].x} ${points[3].y} l`, `${points[2].x} ${points[2].y} l`, "f");
  52957. return [points[0].x, points[1].x, points[3].y, points[1].y];
  52958. }
  52959. });
  52960. }
  52961. } else {
  52962. this.data.popupRef = null;
  52963. }
  52964. }
  52965. static createNewDict(annotation, xref, {
  52966. apRef,
  52967. ap
  52968. }) {
  52969. const {
  52970. color,
  52971. opacity,
  52972. rect,
  52973. rotation,
  52974. user,
  52975. quadPoints
  52976. } = annotation;
  52977. const highlight = new Dict(xref);
  52978. highlight.set("Type", Name.get("Annot"));
  52979. highlight.set("Subtype", Name.get("Highlight"));
  52980. highlight.set("CreationDate", `D:${getModificationDate()}`);
  52981. highlight.set("Rect", rect);
  52982. highlight.set("F", 4);
  52983. highlight.set("Border", [0, 0, 0]);
  52984. highlight.set("Rotate", rotation);
  52985. highlight.set("QuadPoints", quadPoints);
  52986. highlight.set("C", Array.from(color, c => c / 255));
  52987. highlight.set("CA", opacity);
  52988. if (user) {
  52989. highlight.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
  52990. }
  52991. if (apRef || ap) {
  52992. const n = new Dict(xref);
  52993. highlight.set("AP", n);
  52994. n.set("N", apRef || ap);
  52995. }
  52996. return highlight;
  52997. }
  52998. static async createNewAppearanceStream(annotation, xref, params) {
  52999. const {
  53000. color,
  53001. rect,
  53002. outlines,
  53003. opacity
  53004. } = annotation;
  53005. const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"];
  53006. const buffer = [];
  53007. for (const outline of outlines) {
  53008. buffer.length = 0;
  53009. buffer.push(`${numberToString(outline[0])} ${numberToString(outline[1])} m`);
  53010. for (let i = 2, ii = outline.length; i < ii; i += 2) {
  53011. buffer.push(`${numberToString(outline[i])} ${numberToString(outline[i + 1])} l`);
  53012. }
  53013. buffer.push("h");
  53014. appearanceBuffer.push(buffer.join("\n"));
  53015. }
  53016. appearanceBuffer.push("f*");
  53017. const appearance = appearanceBuffer.join("\n");
  53018. const appearanceStreamDict = new Dict(xref);
  53019. appearanceStreamDict.set("FormType", 1);
  53020. appearanceStreamDict.set("Subtype", Name.get("Form"));
  53021. appearanceStreamDict.set("Type", Name.get("XObject"));
  53022. appearanceStreamDict.set("BBox", rect);
  53023. appearanceStreamDict.set("Length", appearance.length);
  53024. const resources = new Dict(xref);
  53025. const extGState = new Dict(xref);
  53026. resources.set("ExtGState", extGState);
  53027. appearanceStreamDict.set("Resources", resources);
  53028. const r0 = new Dict(xref);
  53029. extGState.set("R0", r0);
  53030. r0.set("BM", Name.get("Multiply"));
  53031. if (opacity !== 1) {
  53032. r0.set("ca", opacity);
  53033. r0.set("Type", Name.get("ExtGState"));
  53034. }
  53035. const ap = new StringStream(appearance);
  53036. ap.dict = appearanceStreamDict;
  53037. return ap;
  53038. }
  53039. }
  53040. class UnderlineAnnotation extends MarkupAnnotation {
  53041. constructor(params) {
  53042. super(params);
  53043. const {
  53044. dict,
  53045. xref
  53046. } = params;
  53047. this.data.annotationType = AnnotationType.UNDERLINE;
  53048. const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
  53049. if (quadPoints) {
  53050. if (!this.appearance) {
  53051. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  53052. const strokeAlpha = dict.get("CA");
  53053. this._setDefaultAppearance({
  53054. xref,
  53055. extra: "[] 0 d 0.571 w",
  53056. strokeColor,
  53057. strokeAlpha,
  53058. pointsCallback: (buffer, points) => {
  53059. buffer.push(`${points[2].x} ${points[2].y + 1.3} m`, `${points[3].x} ${points[3].y + 1.3} l`, "S");
  53060. return [points[0].x, points[1].x, points[3].y, points[1].y];
  53061. }
  53062. });
  53063. }
  53064. } else {
  53065. this.data.popupRef = null;
  53066. }
  53067. }
  53068. }
  53069. class SquigglyAnnotation extends MarkupAnnotation {
  53070. constructor(params) {
  53071. super(params);
  53072. const {
  53073. dict,
  53074. xref
  53075. } = params;
  53076. this.data.annotationType = AnnotationType.SQUIGGLY;
  53077. const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
  53078. if (quadPoints) {
  53079. if (!this.appearance) {
  53080. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  53081. const strokeAlpha = dict.get("CA");
  53082. this._setDefaultAppearance({
  53083. xref,
  53084. extra: "[] 0 d 1 w",
  53085. strokeColor,
  53086. strokeAlpha,
  53087. pointsCallback: (buffer, points) => {
  53088. const dy = (points[0].y - points[2].y) / 6;
  53089. let shift = dy;
  53090. let x = points[2].x;
  53091. const y = points[2].y;
  53092. const xEnd = points[3].x;
  53093. buffer.push(`${x} ${y + shift} m`);
  53094. do {
  53095. x += 2;
  53096. shift = shift === 0 ? dy : 0;
  53097. buffer.push(`${x} ${y + shift} l`);
  53098. } while (x < xEnd);
  53099. buffer.push("S");
  53100. return [points[2].x, xEnd, y - 2 * dy, y + 2 * dy];
  53101. }
  53102. });
  53103. }
  53104. } else {
  53105. this.data.popupRef = null;
  53106. }
  53107. }
  53108. }
  53109. class StrikeOutAnnotation extends MarkupAnnotation {
  53110. constructor(params) {
  53111. super(params);
  53112. const {
  53113. dict,
  53114. xref
  53115. } = params;
  53116. this.data.annotationType = AnnotationType.STRIKEOUT;
  53117. const quadPoints = this.data.quadPoints = getQuadPoints(dict, null);
  53118. if (quadPoints) {
  53119. if (!this.appearance) {
  53120. const strokeColor = this.color ? getPdfColorArray(this.color) : [0, 0, 0];
  53121. const strokeAlpha = dict.get("CA");
  53122. this._setDefaultAppearance({
  53123. xref,
  53124. extra: "[] 0 d 1 w",
  53125. strokeColor,
  53126. strokeAlpha,
  53127. pointsCallback: (buffer, points) => {
  53128. buffer.push(`${(points[0].x + points[2].x) / 2} ` + `${(points[0].y + points[2].y) / 2} m`, `${(points[1].x + points[3].x) / 2} ` + `${(points[1].y + points[3].y) / 2} l`, "S");
  53129. return [points[0].x, points[1].x, points[3].y, points[1].y];
  53130. }
  53131. });
  53132. }
  53133. } else {
  53134. this.data.popupRef = null;
  53135. }
  53136. }
  53137. }
  53138. class StampAnnotation extends MarkupAnnotation {
  53139. constructor(params) {
  53140. super(params);
  53141. this.data.annotationType = AnnotationType.STAMP;
  53142. this.data.hasOwnCanvas = this.data.noRotate;
  53143. this.data.noHTML = false;
  53144. }
  53145. static async createImage(bitmap, xref) {
  53146. const {
  53147. width,
  53148. height
  53149. } = bitmap;
  53150. const canvas = new OffscreenCanvas(width, height);
  53151. const ctx = canvas.getContext("2d", {
  53152. alpha: true
  53153. });
  53154. ctx.drawImage(bitmap, 0, 0);
  53155. const data = ctx.getImageData(0, 0, width, height).data;
  53156. const buf32 = new Uint32Array(data.buffer);
  53157. const hasAlpha = buf32.some(FeatureTest.isLittleEndian ? x => x >>> 24 !== 0xff : x => (x & 0xff) !== 0xff);
  53158. if (hasAlpha) {
  53159. ctx.fillStyle = "white";
  53160. ctx.fillRect(0, 0, width, height);
  53161. ctx.drawImage(bitmap, 0, 0);
  53162. }
  53163. const jpegBufferPromise = canvas.convertToBlob({
  53164. type: "image/jpeg",
  53165. quality: 1
  53166. }).then(blob => {
  53167. return blob.arrayBuffer();
  53168. });
  53169. const xobjectName = Name.get("XObject");
  53170. const imageName = Name.get("Image");
  53171. const image = new Dict(xref);
  53172. image.set("Type", xobjectName);
  53173. image.set("Subtype", imageName);
  53174. image.set("BitsPerComponent", 8);
  53175. image.set("ColorSpace", Name.get("DeviceRGB"));
  53176. image.set("Filter", Name.get("DCTDecode"));
  53177. image.set("BBox", [0, 0, width, height]);
  53178. image.set("Width", width);
  53179. image.set("Height", height);
  53180. let smaskStream = null;
  53181. if (hasAlpha) {
  53182. const alphaBuffer = new Uint8Array(buf32.length);
  53183. if (FeatureTest.isLittleEndian) {
  53184. for (let i = 0, ii = buf32.length; i < ii; i++) {
  53185. alphaBuffer[i] = buf32[i] >>> 24;
  53186. }
  53187. } else {
  53188. for (let i = 0, ii = buf32.length; i < ii; i++) {
  53189. alphaBuffer[i] = buf32[i] & 0xff;
  53190. }
  53191. }
  53192. const smask = new Dict(xref);
  53193. smask.set("Type", xobjectName);
  53194. smask.set("Subtype", imageName);
  53195. smask.set("BitsPerComponent", 8);
  53196. smask.set("ColorSpace", Name.get("DeviceGray"));
  53197. smask.set("Width", width);
  53198. smask.set("Height", height);
  53199. smaskStream = new Stream(alphaBuffer, 0, 0, smask);
  53200. }
  53201. const imageStream = new Stream(await jpegBufferPromise, 0, 0, image);
  53202. return {
  53203. imageStream,
  53204. smaskStream,
  53205. width,
  53206. height
  53207. };
  53208. }
  53209. static createNewDict(annotation, xref, {
  53210. apRef,
  53211. ap
  53212. }) {
  53213. const {
  53214. rect,
  53215. rotation,
  53216. user
  53217. } = annotation;
  53218. const stamp = new Dict(xref);
  53219. stamp.set("Type", Name.get("Annot"));
  53220. stamp.set("Subtype", Name.get("Stamp"));
  53221. stamp.set("CreationDate", `D:${getModificationDate()}`);
  53222. stamp.set("Rect", rect);
  53223. stamp.set("F", 4);
  53224. stamp.set("Border", [0, 0, 0]);
  53225. stamp.set("Rotate", rotation);
  53226. if (user) {
  53227. stamp.set("T", isAscii(user) ? user : stringToUTF16String(user, true));
  53228. }
  53229. if (apRef || ap) {
  53230. const n = new Dict(xref);
  53231. stamp.set("AP", n);
  53232. if (apRef) {
  53233. n.set("N", apRef);
  53234. } else {
  53235. n.set("N", ap);
  53236. }
  53237. }
  53238. return stamp;
  53239. }
  53240. static async createNewAppearanceStream(annotation, xref, params) {
  53241. const {
  53242. rotation
  53243. } = annotation;
  53244. const {
  53245. imageRef,
  53246. width,
  53247. height
  53248. } = params.image;
  53249. const resources = new Dict(xref);
  53250. const xobject = new Dict(xref);
  53251. resources.set("XObject", xobject);
  53252. xobject.set("Im0", imageRef);
  53253. const appearance = `q ${width} 0 0 ${height} 0 0 cm /Im0 Do Q`;
  53254. const appearanceStreamDict = new Dict(xref);
  53255. appearanceStreamDict.set("FormType", 1);
  53256. appearanceStreamDict.set("Subtype", Name.get("Form"));
  53257. appearanceStreamDict.set("Type", Name.get("XObject"));
  53258. appearanceStreamDict.set("BBox", [0, 0, width, height]);
  53259. appearanceStreamDict.set("Resources", resources);
  53260. if (rotation) {
  53261. const matrix = getRotationMatrix(rotation, width, height);
  53262. appearanceStreamDict.set("Matrix", matrix);
  53263. }
  53264. const ap = new StringStream(appearance);
  53265. ap.dict = appearanceStreamDict;
  53266. return ap;
  53267. }
  53268. }
  53269. class FileAttachmentAnnotation extends MarkupAnnotation {
  53270. constructor(params) {
  53271. super(params);
  53272. const {
  53273. dict,
  53274. xref
  53275. } = params;
  53276. const file = new FileSpec(dict.get("FS"), xref);
  53277. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  53278. this.data.hasOwnCanvas = this.data.noRotate;
  53279. this.data.noHTML = false;
  53280. this.data.file = file.serializable;
  53281. const name = dict.get("Name");
  53282. this.data.name = name instanceof Name ? stringToPDFString(name.name) : "PushPin";
  53283. const fillAlpha = dict.get("ca");
  53284. this.data.fillAlpha = typeof fillAlpha === "number" && fillAlpha >= 0 && fillAlpha <= 1 ? fillAlpha : null;
  53285. }
  53286. }
  53287. ;// CONCATENATED MODULE: ./src/core/dataset_reader.js
  53288. function decodeString(str) {
  53289. try {
  53290. return stringToUTF8String(str);
  53291. } catch (ex) {
  53292. warn(`UTF-8 decoding failed: "${ex}".`);
  53293. return str;
  53294. }
  53295. }
  53296. class DatasetXMLParser extends SimpleXMLParser {
  53297. constructor(options) {
  53298. super(options);
  53299. this.node = null;
  53300. }
  53301. onEndElement(name) {
  53302. const node = super.onEndElement(name);
  53303. if (node && name === "xfa:datasets") {
  53304. this.node = node;
  53305. throw new Error("Aborting DatasetXMLParser.");
  53306. }
  53307. }
  53308. }
  53309. class DatasetReader {
  53310. constructor(data) {
  53311. if (data.datasets) {
  53312. this.node = new SimpleXMLParser({
  53313. hasAttributes: true
  53314. }).parseFromString(data.datasets).documentElement;
  53315. } else {
  53316. const parser = new DatasetXMLParser({
  53317. hasAttributes: true
  53318. });
  53319. try {
  53320. parser.parseFromString(data["xdp:xdp"]);
  53321. } catch {}
  53322. this.node = parser.node;
  53323. }
  53324. }
  53325. getValue(path) {
  53326. if (!this.node || !path) {
  53327. return "";
  53328. }
  53329. const node = this.node.searchNode(parseXFAPath(path), 0);
  53330. if (!node) {
  53331. return "";
  53332. }
  53333. const first = node.firstChild;
  53334. if (first?.nodeName === "value") {
  53335. return node.children.map(child => decodeString(child.textContent));
  53336. }
  53337. return decodeString(node.textContent);
  53338. }
  53339. }
  53340. ;// CONCATENATED MODULE: ./src/core/xref.js
  53341. class XRef {
  53342. #firstXRefStmPos = null;
  53343. constructor(stream, pdfManager) {
  53344. this.stream = stream;
  53345. this.pdfManager = pdfManager;
  53346. this.entries = [];
  53347. this._xrefStms = new Set();
  53348. this._cacheMap = new Map();
  53349. this._pendingRefs = new RefSet();
  53350. this._newPersistentRefNum = null;
  53351. this._newTemporaryRefNum = null;
  53352. this._persistentRefsCache = null;
  53353. }
  53354. getNewPersistentRef(obj) {
  53355. if (this._newPersistentRefNum === null) {
  53356. this._newPersistentRefNum = this.entries.length || 1;
  53357. }
  53358. const num = this._newPersistentRefNum++;
  53359. this._cacheMap.set(num, obj);
  53360. return Ref.get(num, 0);
  53361. }
  53362. getNewTemporaryRef() {
  53363. if (this._newTemporaryRefNum === null) {
  53364. this._newTemporaryRefNum = this.entries.length || 1;
  53365. if (this._newPersistentRefNum) {
  53366. this._persistentRefsCache = new Map();
  53367. for (let i = this._newTemporaryRefNum; i < this._newPersistentRefNum; i++) {
  53368. this._persistentRefsCache.set(i, this._cacheMap.get(i));
  53369. this._cacheMap.delete(i);
  53370. }
  53371. }
  53372. }
  53373. return Ref.get(this._newTemporaryRefNum++, 0);
  53374. }
  53375. resetNewTemporaryRef() {
  53376. this._newTemporaryRefNum = null;
  53377. if (this._persistentRefsCache) {
  53378. for (const [num, obj] of this._persistentRefsCache) {
  53379. this._cacheMap.set(num, obj);
  53380. }
  53381. }
  53382. this._persistentRefsCache = null;
  53383. }
  53384. setStartXRef(startXRef) {
  53385. this.startXRefQueue = [startXRef];
  53386. }
  53387. parse(recoveryMode = false) {
  53388. let trailerDict;
  53389. if (!recoveryMode) {
  53390. trailerDict = this.readXRef();
  53391. } else {
  53392. warn("Indexing all PDF objects");
  53393. trailerDict = this.indexObjects();
  53394. }
  53395. trailerDict.assignXref(this);
  53396. this.trailer = trailerDict;
  53397. let encrypt;
  53398. try {
  53399. encrypt = trailerDict.get("Encrypt");
  53400. } catch (ex) {
  53401. if (ex instanceof MissingDataException) {
  53402. throw ex;
  53403. }
  53404. warn(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`);
  53405. }
  53406. if (encrypt instanceof Dict) {
  53407. const ids = trailerDict.get("ID");
  53408. const fileId = ids?.length ? ids[0] : "";
  53409. encrypt.suppressEncryption = true;
  53410. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.pdfManager.password);
  53411. }
  53412. let root;
  53413. try {
  53414. root = trailerDict.get("Root");
  53415. } catch (ex) {
  53416. if (ex instanceof MissingDataException) {
  53417. throw ex;
  53418. }
  53419. warn(`XRef.parse - Invalid "Root" reference: "${ex}".`);
  53420. }
  53421. if (root instanceof Dict) {
  53422. try {
  53423. const pages = root.get("Pages");
  53424. if (pages instanceof Dict) {
  53425. this.root = root;
  53426. return;
  53427. }
  53428. } catch (ex) {
  53429. if (ex instanceof MissingDataException) {
  53430. throw ex;
  53431. }
  53432. warn(`XRef.parse - Invalid "Pages" reference: "${ex}".`);
  53433. }
  53434. }
  53435. if (!recoveryMode) {
  53436. throw new XRefParseException();
  53437. }
  53438. throw new InvalidPDFException("Invalid Root reference.");
  53439. }
  53440. processXRefTable(parser) {
  53441. if (!("tableState" in this)) {
  53442. this.tableState = {
  53443. entryNum: 0,
  53444. streamPos: parser.lexer.stream.pos,
  53445. parserBuf1: parser.buf1,
  53446. parserBuf2: parser.buf2
  53447. };
  53448. }
  53449. const obj = this.readXRefTable(parser);
  53450. if (!isCmd(obj, "trailer")) {
  53451. throw new FormatError("Invalid XRef table: could not find trailer dictionary");
  53452. }
  53453. let dict = parser.getObj();
  53454. if (!(dict instanceof Dict) && dict.dict) {
  53455. dict = dict.dict;
  53456. }
  53457. if (!(dict instanceof Dict)) {
  53458. throw new FormatError("Invalid XRef table: could not parse trailer dictionary");
  53459. }
  53460. delete this.tableState;
  53461. return dict;
  53462. }
  53463. readXRefTable(parser) {
  53464. const stream = parser.lexer.stream;
  53465. const tableState = this.tableState;
  53466. stream.pos = tableState.streamPos;
  53467. parser.buf1 = tableState.parserBuf1;
  53468. parser.buf2 = tableState.parserBuf2;
  53469. let obj;
  53470. while (true) {
  53471. if (!("firstEntryNum" in tableState) || !("entryCount" in tableState)) {
  53472. if (isCmd(obj = parser.getObj(), "trailer")) {
  53473. break;
  53474. }
  53475. tableState.firstEntryNum = obj;
  53476. tableState.entryCount = parser.getObj();
  53477. }
  53478. let first = tableState.firstEntryNum;
  53479. const count = tableState.entryCount;
  53480. if (!Number.isInteger(first) || !Number.isInteger(count)) {
  53481. throw new FormatError("Invalid XRef table: wrong types in subsection header");
  53482. }
  53483. for (let i = tableState.entryNum; i < count; i++) {
  53484. tableState.streamPos = stream.pos;
  53485. tableState.entryNum = i;
  53486. tableState.parserBuf1 = parser.buf1;
  53487. tableState.parserBuf2 = parser.buf2;
  53488. const entry = {};
  53489. entry.offset = parser.getObj();
  53490. entry.gen = parser.getObj();
  53491. const type = parser.getObj();
  53492. if (type instanceof Cmd) {
  53493. switch (type.cmd) {
  53494. case "f":
  53495. entry.free = true;
  53496. break;
  53497. case "n":
  53498. entry.uncompressed = true;
  53499. break;
  53500. }
  53501. }
  53502. if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {
  53503. throw new FormatError(`Invalid entry in XRef subsection: ${first}, ${count}`);
  53504. }
  53505. if (i === 0 && entry.free && first === 1) {
  53506. first = 0;
  53507. }
  53508. if (!this.entries[i + first]) {
  53509. this.entries[i + first] = entry;
  53510. }
  53511. }
  53512. tableState.entryNum = 0;
  53513. tableState.streamPos = stream.pos;
  53514. tableState.parserBuf1 = parser.buf1;
  53515. tableState.parserBuf2 = parser.buf2;
  53516. delete tableState.firstEntryNum;
  53517. delete tableState.entryCount;
  53518. }
  53519. if (this.entries[0] && !this.entries[0].free) {
  53520. throw new FormatError("Invalid XRef table: unexpected first object");
  53521. }
  53522. return obj;
  53523. }
  53524. processXRefStream(stream) {
  53525. if (!("streamState" in this)) {
  53526. const streamParameters = stream.dict;
  53527. const byteWidths = streamParameters.get("W");
  53528. let range = streamParameters.get("Index");
  53529. if (!range) {
  53530. range = [0, streamParameters.get("Size")];
  53531. }
  53532. this.streamState = {
  53533. entryRanges: range,
  53534. byteWidths,
  53535. entryNum: 0,
  53536. streamPos: stream.pos
  53537. };
  53538. }
  53539. this.readXRefStream(stream);
  53540. delete this.streamState;
  53541. return stream.dict;
  53542. }
  53543. readXRefStream(stream) {
  53544. const streamState = this.streamState;
  53545. stream.pos = streamState.streamPos;
  53546. const [typeFieldWidth, offsetFieldWidth, generationFieldWidth] = streamState.byteWidths;
  53547. const entryRanges = streamState.entryRanges;
  53548. while (entryRanges.length > 0) {
  53549. const [first, n] = entryRanges;
  53550. if (!Number.isInteger(first) || !Number.isInteger(n)) {
  53551. throw new FormatError(`Invalid XRef range fields: ${first}, ${n}`);
  53552. }
  53553. if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) {
  53554. throw new FormatError(`Invalid XRef entry fields length: ${first}, ${n}`);
  53555. }
  53556. for (let i = streamState.entryNum; i < n; ++i) {
  53557. streamState.entryNum = i;
  53558. streamState.streamPos = stream.pos;
  53559. let type = 0,
  53560. offset = 0,
  53561. generation = 0;
  53562. for (let j = 0; j < typeFieldWidth; ++j) {
  53563. const typeByte = stream.getByte();
  53564. if (typeByte === -1) {
  53565. throw new FormatError("Invalid XRef byteWidths 'type'.");
  53566. }
  53567. type = type << 8 | typeByte;
  53568. }
  53569. if (typeFieldWidth === 0) {
  53570. type = 1;
  53571. }
  53572. for (let j = 0; j < offsetFieldWidth; ++j) {
  53573. const offsetByte = stream.getByte();
  53574. if (offsetByte === -1) {
  53575. throw new FormatError("Invalid XRef byteWidths 'offset'.");
  53576. }
  53577. offset = offset << 8 | offsetByte;
  53578. }
  53579. for (let j = 0; j < generationFieldWidth; ++j) {
  53580. const generationByte = stream.getByte();
  53581. if (generationByte === -1) {
  53582. throw new FormatError("Invalid XRef byteWidths 'generation'.");
  53583. }
  53584. generation = generation << 8 | generationByte;
  53585. }
  53586. const entry = {};
  53587. entry.offset = offset;
  53588. entry.gen = generation;
  53589. switch (type) {
  53590. case 0:
  53591. entry.free = true;
  53592. break;
  53593. case 1:
  53594. entry.uncompressed = true;
  53595. break;
  53596. case 2:
  53597. break;
  53598. default:
  53599. throw new FormatError(`Invalid XRef entry type: ${type}`);
  53600. }
  53601. if (!this.entries[first + i]) {
  53602. this.entries[first + i] = entry;
  53603. }
  53604. }
  53605. streamState.entryNum = 0;
  53606. streamState.streamPos = stream.pos;
  53607. entryRanges.splice(0, 2);
  53608. }
  53609. }
  53610. indexObjects() {
  53611. const TAB = 0x9,
  53612. LF = 0xa,
  53613. CR = 0xd,
  53614. SPACE = 0x20;
  53615. const PERCENT = 0x25,
  53616. LT = 0x3c;
  53617. function readToken(data, offset) {
  53618. let token = "",
  53619. ch = data[offset];
  53620. while (ch !== LF && ch !== CR && ch !== LT) {
  53621. if (++offset >= data.length) {
  53622. break;
  53623. }
  53624. token += String.fromCharCode(ch);
  53625. ch = data[offset];
  53626. }
  53627. return token;
  53628. }
  53629. function skipUntil(data, offset, what) {
  53630. const length = what.length,
  53631. dataLength = data.length;
  53632. let skipped = 0;
  53633. while (offset < dataLength) {
  53634. let i = 0;
  53635. while (i < length && data[offset + i] === what[i]) {
  53636. ++i;
  53637. }
  53638. if (i >= length) {
  53639. break;
  53640. }
  53641. offset++;
  53642. skipped++;
  53643. }
  53644. return skipped;
  53645. }
  53646. const gEndobjRegExp = /\b(endobj|\d+\s+\d+\s+obj|xref|trailer\s*<<)\b/g;
  53647. const gStartxrefRegExp = /\b(startxref|\d+\s+\d+\s+obj)\b/g;
  53648. const objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  53649. const trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  53650. const startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]);
  53651. const xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  53652. this.entries.length = 0;
  53653. this._cacheMap.clear();
  53654. const stream = this.stream;
  53655. stream.pos = 0;
  53656. const buffer = stream.getBytes(),
  53657. bufferStr = bytesToString(buffer),
  53658. length = buffer.length;
  53659. let position = stream.start;
  53660. const trailers = [],
  53661. xrefStms = [];
  53662. while (position < length) {
  53663. let ch = buffer[position];
  53664. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  53665. ++position;
  53666. continue;
  53667. }
  53668. if (ch === PERCENT) {
  53669. do {
  53670. ++position;
  53671. if (position >= length) {
  53672. break;
  53673. }
  53674. ch = buffer[position];
  53675. } while (ch !== LF && ch !== CR);
  53676. continue;
  53677. }
  53678. const token = readToken(buffer, position);
  53679. let m;
  53680. if (token.startsWith("xref") && (token.length === 4 || /\s/.test(token[4]))) {
  53681. position += skipUntil(buffer, position, trailerBytes);
  53682. trailers.push(position);
  53683. position += skipUntil(buffer, position, startxrefBytes);
  53684. } else if (m = objRegExp.exec(token)) {
  53685. const num = m[1] | 0,
  53686. gen = m[2] | 0;
  53687. const startPos = position + token.length;
  53688. let contentLength,
  53689. updateEntries = false;
  53690. if (!this.entries[num]) {
  53691. updateEntries = true;
  53692. } else if (this.entries[num].gen === gen) {
  53693. try {
  53694. const parser = new Parser({
  53695. lexer: new Lexer(stream.makeSubStream(startPos))
  53696. });
  53697. parser.getObj();
  53698. updateEntries = true;
  53699. } catch (ex) {
  53700. if (ex instanceof ParserEOFException) {
  53701. warn(`indexObjects -- checking object (${token}): "${ex}".`);
  53702. } else {
  53703. updateEntries = true;
  53704. }
  53705. }
  53706. }
  53707. if (updateEntries) {
  53708. this.entries[num] = {
  53709. offset: position - stream.start,
  53710. gen,
  53711. uncompressed: true
  53712. };
  53713. }
  53714. gEndobjRegExp.lastIndex = startPos;
  53715. const match = gEndobjRegExp.exec(bufferStr);
  53716. if (match) {
  53717. const endPos = gEndobjRegExp.lastIndex + 1;
  53718. contentLength = endPos - position;
  53719. if (match[1] !== "endobj") {
  53720. warn(`indexObjects: Found "${match[1]}" inside of another "obj", ` + 'caused by missing "endobj" -- trying to recover.');
  53721. contentLength -= match[1].length + 1;
  53722. }
  53723. } else {
  53724. contentLength = length - position;
  53725. }
  53726. const content = buffer.subarray(position, position + contentLength);
  53727. const xrefTagOffset = skipUntil(content, 0, xrefBytes);
  53728. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  53729. xrefStms.push(position - stream.start);
  53730. this._xrefStms.add(position - stream.start);
  53731. }
  53732. position += contentLength;
  53733. } else if (token.startsWith("trailer") && (token.length === 7 || /\s/.test(token[7]))) {
  53734. trailers.push(position);
  53735. const startPos = position + token.length;
  53736. let contentLength;
  53737. gStartxrefRegExp.lastIndex = startPos;
  53738. const match = gStartxrefRegExp.exec(bufferStr);
  53739. if (match) {
  53740. const endPos = gStartxrefRegExp.lastIndex + 1;
  53741. contentLength = endPos - position;
  53742. if (match[1] !== "startxref") {
  53743. warn(`indexObjects: Found "${match[1]}" after "trailer", ` + 'caused by missing "startxref" -- trying to recover.');
  53744. contentLength -= match[1].length + 1;
  53745. }
  53746. } else {
  53747. contentLength = length - position;
  53748. }
  53749. position += contentLength;
  53750. } else {
  53751. position += token.length + 1;
  53752. }
  53753. }
  53754. for (const xrefStm of xrefStms) {
  53755. this.startXRefQueue.push(xrefStm);
  53756. this.readXRef(true);
  53757. }
  53758. const trailerDicts = [];
  53759. let isEncrypted = false;
  53760. for (const trailer of trailers) {
  53761. stream.pos = trailer;
  53762. const parser = new Parser({
  53763. lexer: new Lexer(stream),
  53764. xref: this,
  53765. allowStreams: true,
  53766. recoveryMode: true
  53767. });
  53768. const obj = parser.getObj();
  53769. if (!isCmd(obj, "trailer")) {
  53770. continue;
  53771. }
  53772. const dict = parser.getObj();
  53773. if (!(dict instanceof Dict)) {
  53774. continue;
  53775. }
  53776. trailerDicts.push(dict);
  53777. if (dict.has("Encrypt")) {
  53778. isEncrypted = true;
  53779. }
  53780. }
  53781. let trailerDict, trailerError;
  53782. for (const dict of [...trailerDicts, "genFallback", ...trailerDicts]) {
  53783. if (dict === "genFallback") {
  53784. if (!trailerError) {
  53785. break;
  53786. }
  53787. this._generationFallback = true;
  53788. continue;
  53789. }
  53790. let validPagesDict = false;
  53791. try {
  53792. const rootDict = dict.get("Root");
  53793. if (!(rootDict instanceof Dict)) {
  53794. continue;
  53795. }
  53796. const pagesDict = rootDict.get("Pages");
  53797. if (!(pagesDict instanceof Dict)) {
  53798. continue;
  53799. }
  53800. const pagesCount = pagesDict.get("Count");
  53801. if (Number.isInteger(pagesCount)) {
  53802. validPagesDict = true;
  53803. }
  53804. } catch (ex) {
  53805. trailerError = ex;
  53806. continue;
  53807. }
  53808. if (validPagesDict && (!isEncrypted || dict.has("Encrypt")) && dict.has("ID")) {
  53809. return dict;
  53810. }
  53811. trailerDict = dict;
  53812. }
  53813. if (trailerDict) {
  53814. return trailerDict;
  53815. }
  53816. if (this.topDict) {
  53817. return this.topDict;
  53818. }
  53819. throw new InvalidPDFException("Invalid PDF structure.");
  53820. }
  53821. readXRef(recoveryMode = false) {
  53822. const stream = this.stream;
  53823. const startXRefParsedCache = new Set();
  53824. while (this.startXRefQueue.length) {
  53825. try {
  53826. const startXRef = this.startXRefQueue[0];
  53827. if (startXRefParsedCache.has(startXRef)) {
  53828. warn("readXRef - skipping XRef table since it was already parsed.");
  53829. this.startXRefQueue.shift();
  53830. continue;
  53831. }
  53832. startXRefParsedCache.add(startXRef);
  53833. stream.pos = startXRef + stream.start;
  53834. const parser = new Parser({
  53835. lexer: new Lexer(stream),
  53836. xref: this,
  53837. allowStreams: true
  53838. });
  53839. let obj = parser.getObj();
  53840. let dict;
  53841. if (isCmd(obj, "xref")) {
  53842. dict = this.processXRefTable(parser);
  53843. if (!this.topDict) {
  53844. this.topDict = dict;
  53845. }
  53846. obj = dict.get("XRefStm");
  53847. if (Number.isInteger(obj) && !this._xrefStms.has(obj)) {
  53848. this._xrefStms.add(obj);
  53849. this.startXRefQueue.push(obj);
  53850. this.#firstXRefStmPos ??= obj;
  53851. }
  53852. } else if (Number.isInteger(obj)) {
  53853. if (!Number.isInteger(parser.getObj()) || !isCmd(parser.getObj(), "obj") || !((obj = parser.getObj()) instanceof BaseStream)) {
  53854. throw new FormatError("Invalid XRef stream");
  53855. }
  53856. dict = this.processXRefStream(obj);
  53857. if (!this.topDict) {
  53858. this.topDict = dict;
  53859. }
  53860. if (!dict) {
  53861. throw new FormatError("Failed to read XRef stream");
  53862. }
  53863. } else {
  53864. throw new FormatError("Invalid XRef stream header");
  53865. }
  53866. obj = dict.get("Prev");
  53867. if (Number.isInteger(obj)) {
  53868. this.startXRefQueue.push(obj);
  53869. } else if (obj instanceof Ref) {
  53870. this.startXRefQueue.push(obj.num);
  53871. }
  53872. } catch (e) {
  53873. if (e instanceof MissingDataException) {
  53874. throw e;
  53875. }
  53876. info("(while reading XRef): " + e);
  53877. }
  53878. this.startXRefQueue.shift();
  53879. }
  53880. if (this.topDict) {
  53881. return this.topDict;
  53882. }
  53883. if (recoveryMode) {
  53884. return undefined;
  53885. }
  53886. throw new XRefParseException();
  53887. }
  53888. get lastXRefStreamPos() {
  53889. return this.#firstXRefStmPos ?? (this._xrefStms.size > 0 ? Math.max(...this._xrefStms) : null);
  53890. }
  53891. getEntry(i) {
  53892. const xrefEntry = this.entries[i];
  53893. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  53894. return xrefEntry;
  53895. }
  53896. return null;
  53897. }
  53898. fetchIfRef(obj, suppressEncryption = false) {
  53899. if (obj instanceof Ref) {
  53900. return this.fetch(obj, suppressEncryption);
  53901. }
  53902. return obj;
  53903. }
  53904. fetch(ref, suppressEncryption = false) {
  53905. if (!(ref instanceof Ref)) {
  53906. throw new Error("ref object is not a reference");
  53907. }
  53908. const num = ref.num;
  53909. const cacheEntry = this._cacheMap.get(num);
  53910. if (cacheEntry !== undefined) {
  53911. if (cacheEntry instanceof Dict && !cacheEntry.objId) {
  53912. cacheEntry.objId = ref.toString();
  53913. }
  53914. return cacheEntry;
  53915. }
  53916. let xrefEntry = this.getEntry(num);
  53917. if (xrefEntry === null) {
  53918. this._cacheMap.set(num, xrefEntry);
  53919. return xrefEntry;
  53920. }
  53921. if (this._pendingRefs.has(ref)) {
  53922. this._pendingRefs.remove(ref);
  53923. warn(`Ignoring circular reference: ${ref}.`);
  53924. return CIRCULAR_REF;
  53925. }
  53926. this._pendingRefs.put(ref);
  53927. try {
  53928. xrefEntry = xrefEntry.uncompressed ? this.fetchUncompressed(ref, xrefEntry, suppressEncryption) : this.fetchCompressed(ref, xrefEntry, suppressEncryption);
  53929. this._pendingRefs.remove(ref);
  53930. } catch (ex) {
  53931. this._pendingRefs.remove(ref);
  53932. throw ex;
  53933. }
  53934. if (xrefEntry instanceof Dict) {
  53935. xrefEntry.objId = ref.toString();
  53936. } else if (xrefEntry instanceof BaseStream) {
  53937. xrefEntry.dict.objId = ref.toString();
  53938. }
  53939. return xrefEntry;
  53940. }
  53941. fetchUncompressed(ref, xrefEntry, suppressEncryption = false) {
  53942. const gen = ref.gen;
  53943. let num = ref.num;
  53944. if (xrefEntry.gen !== gen) {
  53945. const msg = `Inconsistent generation in XRef: ${ref}`;
  53946. if (this._generationFallback && xrefEntry.gen < gen) {
  53947. warn(msg);
  53948. return this.fetchUncompressed(Ref.get(num, xrefEntry.gen), xrefEntry, suppressEncryption);
  53949. }
  53950. throw new XRefEntryException(msg);
  53951. }
  53952. const stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  53953. const parser = new Parser({
  53954. lexer: new Lexer(stream),
  53955. xref: this,
  53956. allowStreams: true
  53957. });
  53958. const obj1 = parser.getObj();
  53959. const obj2 = parser.getObj();
  53960. const obj3 = parser.getObj();
  53961. if (obj1 !== num || obj2 !== gen || !(obj3 instanceof Cmd)) {
  53962. throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
  53963. }
  53964. if (obj3.cmd !== "obj") {
  53965. if (obj3.cmd.startsWith("obj")) {
  53966. num = parseInt(obj3.cmd.substring(3), 10);
  53967. if (!Number.isNaN(num)) {
  53968. return num;
  53969. }
  53970. }
  53971. throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
  53972. }
  53973. xrefEntry = this.encrypt && !suppressEncryption ? parser.getObj(this.encrypt.createCipherTransform(num, gen)) : parser.getObj();
  53974. if (!(xrefEntry instanceof BaseStream)) {
  53975. this._cacheMap.set(num, xrefEntry);
  53976. }
  53977. return xrefEntry;
  53978. }
  53979. fetchCompressed(ref, xrefEntry, suppressEncryption = false) {
  53980. const tableOffset = xrefEntry.offset;
  53981. const stream = this.fetch(Ref.get(tableOffset, 0));
  53982. if (!(stream instanceof BaseStream)) {
  53983. throw new FormatError("bad ObjStm stream");
  53984. }
  53985. const first = stream.dict.get("First");
  53986. const n = stream.dict.get("N");
  53987. if (!Number.isInteger(first) || !Number.isInteger(n)) {
  53988. throw new FormatError("invalid first and n parameters for ObjStm stream");
  53989. }
  53990. let parser = new Parser({
  53991. lexer: new Lexer(stream),
  53992. xref: this,
  53993. allowStreams: true
  53994. });
  53995. const nums = new Array(n);
  53996. const offsets = new Array(n);
  53997. for (let i = 0; i < n; ++i) {
  53998. const num = parser.getObj();
  53999. if (!Number.isInteger(num)) {
  54000. throw new FormatError(`invalid object number in the ObjStm stream: ${num}`);
  54001. }
  54002. const offset = parser.getObj();
  54003. if (!Number.isInteger(offset)) {
  54004. throw new FormatError(`invalid object offset in the ObjStm stream: ${offset}`);
  54005. }
  54006. nums[i] = num;
  54007. offsets[i] = offset;
  54008. }
  54009. const start = (stream.start || 0) + first;
  54010. const entries = new Array(n);
  54011. for (let i = 0; i < n; ++i) {
  54012. const length = i < n - 1 ? offsets[i + 1] - offsets[i] : undefined;
  54013. if (length < 0) {
  54014. throw new FormatError("Invalid offset in the ObjStm stream.");
  54015. }
  54016. parser = new Parser({
  54017. lexer: new Lexer(stream.makeSubStream(start + offsets[i], length, stream.dict)),
  54018. xref: this,
  54019. allowStreams: true
  54020. });
  54021. const obj = parser.getObj();
  54022. entries[i] = obj;
  54023. if (obj instanceof BaseStream) {
  54024. continue;
  54025. }
  54026. const num = nums[i],
  54027. entry = this.entries[num];
  54028. if (entry && entry.offset === tableOffset && entry.gen === i) {
  54029. this._cacheMap.set(num, obj);
  54030. }
  54031. }
  54032. xrefEntry = entries[xrefEntry.gen];
  54033. if (xrefEntry === undefined) {
  54034. throw new XRefEntryException(`Bad (compressed) XRef entry: ${ref}`);
  54035. }
  54036. return xrefEntry;
  54037. }
  54038. async fetchIfRefAsync(obj, suppressEncryption) {
  54039. if (obj instanceof Ref) {
  54040. return this.fetchAsync(obj, suppressEncryption);
  54041. }
  54042. return obj;
  54043. }
  54044. async fetchAsync(ref, suppressEncryption) {
  54045. try {
  54046. return this.fetch(ref, suppressEncryption);
  54047. } catch (ex) {
  54048. if (!(ex instanceof MissingDataException)) {
  54049. throw ex;
  54050. }
  54051. await this.pdfManager.requestRange(ex.begin, ex.end);
  54052. return this.fetchAsync(ref, suppressEncryption);
  54053. }
  54054. }
  54055. getCatalogObj() {
  54056. return this.root;
  54057. }
  54058. }
  54059. ;// CONCATENATED MODULE: ./src/core/document.js
  54060. const DEFAULT_USER_UNIT = 1.0;
  54061. const LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  54062. class Page {
  54063. constructor({
  54064. pdfManager,
  54065. xref,
  54066. pageIndex,
  54067. pageDict,
  54068. ref,
  54069. globalIdFactory,
  54070. fontCache,
  54071. builtInCMapCache,
  54072. standardFontDataCache,
  54073. globalImageCache,
  54074. systemFontCache,
  54075. nonBlendModesSet,
  54076. xfaFactory
  54077. }) {
  54078. this.pdfManager = pdfManager;
  54079. this.pageIndex = pageIndex;
  54080. this.pageDict = pageDict;
  54081. this.xref = xref;
  54082. this.ref = ref;
  54083. this.fontCache = fontCache;
  54084. this.builtInCMapCache = builtInCMapCache;
  54085. this.standardFontDataCache = standardFontDataCache;
  54086. this.globalImageCache = globalImageCache;
  54087. this.systemFontCache = systemFontCache;
  54088. this.nonBlendModesSet = nonBlendModesSet;
  54089. this.evaluatorOptions = pdfManager.evaluatorOptions;
  54090. this.resourcesPromise = null;
  54091. this.xfaFactory = xfaFactory;
  54092. const idCounters = {
  54093. obj: 0
  54094. };
  54095. this._localIdFactory = class extends globalIdFactory {
  54096. static createObjId() {
  54097. return `p${pageIndex}_${++idCounters.obj}`;
  54098. }
  54099. static getPageObjId() {
  54100. return `p${ref.toString()}`;
  54101. }
  54102. };
  54103. }
  54104. _getInheritableProperty(key, getArray = false) {
  54105. const value = getInheritableProperty({
  54106. dict: this.pageDict,
  54107. key,
  54108. getArray,
  54109. stopWhenFound: false
  54110. });
  54111. if (!Array.isArray(value)) {
  54112. return value;
  54113. }
  54114. if (value.length === 1 || !(value[0] instanceof Dict)) {
  54115. return value[0];
  54116. }
  54117. return Dict.merge({
  54118. xref: this.xref,
  54119. dictArray: value
  54120. });
  54121. }
  54122. get content() {
  54123. return this.pageDict.getArray("Contents");
  54124. }
  54125. get resources() {
  54126. const resources = this._getInheritableProperty("Resources");
  54127. return shadow(this, "resources", resources instanceof Dict ? resources : Dict.empty);
  54128. }
  54129. _getBoundingBox(name) {
  54130. if (this.xfaData) {
  54131. return this.xfaData.bbox;
  54132. }
  54133. let box = this._getInheritableProperty(name, true);
  54134. if (Array.isArray(box) && box.length === 4) {
  54135. box = Util.normalizeRect(box);
  54136. if (box[2] - box[0] > 0 && box[3] - box[1] > 0) {
  54137. return box;
  54138. }
  54139. warn(`Empty, or invalid, /${name} entry.`);
  54140. }
  54141. return null;
  54142. }
  54143. get mediaBox() {
  54144. return shadow(this, "mediaBox", this._getBoundingBox("MediaBox") || LETTER_SIZE_MEDIABOX);
  54145. }
  54146. get cropBox() {
  54147. return shadow(this, "cropBox", this._getBoundingBox("CropBox") || this.mediaBox);
  54148. }
  54149. get userUnit() {
  54150. let obj = this.pageDict.get("UserUnit");
  54151. if (typeof obj !== "number" || obj <= 0) {
  54152. obj = DEFAULT_USER_UNIT;
  54153. }
  54154. return shadow(this, "userUnit", obj);
  54155. }
  54156. get view() {
  54157. const {
  54158. cropBox,
  54159. mediaBox
  54160. } = this;
  54161. if (cropBox !== mediaBox && !isArrayEqual(cropBox, mediaBox)) {
  54162. const box = Util.intersect(cropBox, mediaBox);
  54163. if (box && box[2] - box[0] > 0 && box[3] - box[1] > 0) {
  54164. return shadow(this, "view", box);
  54165. }
  54166. warn("Empty /CropBox and /MediaBox intersection.");
  54167. }
  54168. return shadow(this, "view", mediaBox);
  54169. }
  54170. get rotate() {
  54171. let rotate = this._getInheritableProperty("Rotate") || 0;
  54172. if (rotate % 90 !== 0) {
  54173. rotate = 0;
  54174. } else if (rotate >= 360) {
  54175. rotate %= 360;
  54176. } else if (rotate < 0) {
  54177. rotate = (rotate % 360 + 360) % 360;
  54178. }
  54179. return shadow(this, "rotate", rotate);
  54180. }
  54181. _onSubStreamError(reason, objId) {
  54182. if (this.evaluatorOptions.ignoreErrors) {
  54183. warn(`getContentStream - ignoring sub-stream (${objId}): "${reason}".`);
  54184. return;
  54185. }
  54186. throw reason;
  54187. }
  54188. getContentStream() {
  54189. return this.pdfManager.ensure(this, "content").then(content => {
  54190. if (content instanceof BaseStream) {
  54191. return content;
  54192. }
  54193. if (Array.isArray(content)) {
  54194. return new StreamsSequenceStream(content, this._onSubStreamError.bind(this));
  54195. }
  54196. return new NullStream();
  54197. });
  54198. }
  54199. get xfaData() {
  54200. return shadow(this, "xfaData", this.xfaFactory ? {
  54201. bbox: this.xfaFactory.getBoundingBox(this.pageIndex)
  54202. } : null);
  54203. }
  54204. #replaceIdByRef(annotations, deletedAnnotations, existingAnnotations) {
  54205. for (const annotation of annotations) {
  54206. if (annotation.id) {
  54207. const ref = Ref.fromString(annotation.id);
  54208. if (!ref) {
  54209. warn(`A non-linked annotation cannot be modified: ${annotation.id}`);
  54210. continue;
  54211. }
  54212. if (annotation.deleted) {
  54213. deletedAnnotations.put(ref);
  54214. continue;
  54215. }
  54216. existingAnnotations?.put(ref);
  54217. annotation.ref = ref;
  54218. delete annotation.id;
  54219. }
  54220. }
  54221. }
  54222. async saveNewAnnotations(handler, task, annotations, imagePromises) {
  54223. if (this.xfaFactory) {
  54224. throw new Error("XFA: Cannot save new annotations.");
  54225. }
  54226. const partialEvaluator = new PartialEvaluator({
  54227. xref: this.xref,
  54228. handler,
  54229. pageIndex: this.pageIndex,
  54230. idFactory: this._localIdFactory,
  54231. fontCache: this.fontCache,
  54232. builtInCMapCache: this.builtInCMapCache,
  54233. standardFontDataCache: this.standardFontDataCache,
  54234. globalImageCache: this.globalImageCache,
  54235. systemFontCache: this.systemFontCache,
  54236. options: this.evaluatorOptions
  54237. });
  54238. const deletedAnnotations = new RefSet();
  54239. const existingAnnotations = new RefSet();
  54240. this.#replaceIdByRef(annotations, deletedAnnotations, existingAnnotations);
  54241. const pageDict = this.pageDict;
  54242. const annotationsArray = this.annotations.filter(a => !(a instanceof Ref && deletedAnnotations.has(a)));
  54243. const newData = await AnnotationFactory.saveNewAnnotations(partialEvaluator, task, annotations, imagePromises);
  54244. for (const {
  54245. ref
  54246. } of newData.annotations) {
  54247. if (ref instanceof Ref && !existingAnnotations.has(ref)) {
  54248. annotationsArray.push(ref);
  54249. }
  54250. }
  54251. const savedDict = pageDict.get("Annots");
  54252. pageDict.set("Annots", annotationsArray);
  54253. const buffer = [];
  54254. await writeObject(this.ref, pageDict, buffer, this.xref);
  54255. if (savedDict) {
  54256. pageDict.set("Annots", savedDict);
  54257. }
  54258. const objects = newData.dependencies;
  54259. objects.push({
  54260. ref: this.ref,
  54261. data: buffer.join("")
  54262. }, ...newData.annotations);
  54263. return objects;
  54264. }
  54265. save(handler, task, annotationStorage) {
  54266. const partialEvaluator = new PartialEvaluator({
  54267. xref: this.xref,
  54268. handler,
  54269. pageIndex: this.pageIndex,
  54270. idFactory: this._localIdFactory,
  54271. fontCache: this.fontCache,
  54272. builtInCMapCache: this.builtInCMapCache,
  54273. standardFontDataCache: this.standardFontDataCache,
  54274. globalImageCache: this.globalImageCache,
  54275. systemFontCache: this.systemFontCache,
  54276. options: this.evaluatorOptions
  54277. });
  54278. return this._parsedAnnotations.then(function (annotations) {
  54279. const newRefsPromises = [];
  54280. for (const annotation of annotations) {
  54281. if (!annotation.mustBePrinted(annotationStorage)) {
  54282. continue;
  54283. }
  54284. newRefsPromises.push(annotation.save(partialEvaluator, task, annotationStorage).catch(function (reason) {
  54285. warn("save - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
  54286. return null;
  54287. }));
  54288. }
  54289. return Promise.all(newRefsPromises).then(function (newRefs) {
  54290. return newRefs.filter(newRef => !!newRef);
  54291. });
  54292. });
  54293. }
  54294. loadResources(keys) {
  54295. if (!this.resourcesPromise) {
  54296. this.resourcesPromise = this.pdfManager.ensure(this, "resources");
  54297. }
  54298. return this.resourcesPromise.then(() => {
  54299. const objectLoader = new ObjectLoader(this.resources, keys, this.xref);
  54300. return objectLoader.load();
  54301. });
  54302. }
  54303. getOperatorList({
  54304. handler,
  54305. sink,
  54306. task,
  54307. intent,
  54308. cacheKey,
  54309. annotationStorage = null
  54310. }) {
  54311. const contentStreamPromise = this.getContentStream();
  54312. const resourcesPromise = this.loadResources(["ColorSpace", "ExtGState", "Font", "Pattern", "Properties", "Shading", "XObject"]);
  54313. const partialEvaluator = new PartialEvaluator({
  54314. xref: this.xref,
  54315. handler,
  54316. pageIndex: this.pageIndex,
  54317. idFactory: this._localIdFactory,
  54318. fontCache: this.fontCache,
  54319. builtInCMapCache: this.builtInCMapCache,
  54320. standardFontDataCache: this.standardFontDataCache,
  54321. globalImageCache: this.globalImageCache,
  54322. systemFontCache: this.systemFontCache,
  54323. options: this.evaluatorOptions
  54324. });
  54325. const newAnnotationsByPage = !this.xfaFactory ? getNewAnnotationsMap(annotationStorage) : null;
  54326. let deletedAnnotations = null;
  54327. let newAnnotationsPromise = Promise.resolve(null);
  54328. if (newAnnotationsByPage) {
  54329. const newAnnotations = newAnnotationsByPage.get(this.pageIndex);
  54330. if (newAnnotations) {
  54331. const annotationGlobalsPromise = this.pdfManager.ensureDoc("annotationGlobals");
  54332. let imagePromises;
  54333. const missingBitmaps = new Set();
  54334. for (const {
  54335. bitmapId,
  54336. bitmap
  54337. } of newAnnotations) {
  54338. if (bitmapId && !bitmap && !missingBitmaps.has(bitmapId)) {
  54339. missingBitmaps.add(bitmapId);
  54340. }
  54341. }
  54342. const {
  54343. isOffscreenCanvasSupported
  54344. } = this.evaluatorOptions;
  54345. if (missingBitmaps.size > 0) {
  54346. const annotationWithBitmaps = newAnnotations.slice();
  54347. for (const [key, annotation] of annotationStorage) {
  54348. if (!key.startsWith(AnnotationEditorPrefix)) {
  54349. continue;
  54350. }
  54351. if (annotation.bitmap && missingBitmaps.has(annotation.bitmapId)) {
  54352. annotationWithBitmaps.push(annotation);
  54353. }
  54354. }
  54355. imagePromises = AnnotationFactory.generateImages(annotationWithBitmaps, this.xref, isOffscreenCanvasSupported);
  54356. } else {
  54357. imagePromises = AnnotationFactory.generateImages(newAnnotations, this.xref, isOffscreenCanvasSupported);
  54358. }
  54359. deletedAnnotations = new RefSet();
  54360. this.#replaceIdByRef(newAnnotations, deletedAnnotations, null);
  54361. newAnnotationsPromise = annotationGlobalsPromise.then(annotationGlobals => {
  54362. if (!annotationGlobals) {
  54363. return null;
  54364. }
  54365. return AnnotationFactory.printNewAnnotations(annotationGlobals, partialEvaluator, task, newAnnotations, imagePromises);
  54366. });
  54367. }
  54368. }
  54369. const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  54370. const pageListPromise = dataPromises.then(([contentStream]) => {
  54371. const opList = new OperatorList(intent, sink);
  54372. handler.send("StartRenderPage", {
  54373. transparency: partialEvaluator.hasBlendModes(this.resources, this.nonBlendModesSet),
  54374. pageIndex: this.pageIndex,
  54375. cacheKey
  54376. });
  54377. return partialEvaluator.getOperatorList({
  54378. stream: contentStream,
  54379. task,
  54380. resources: this.resources,
  54381. operatorList: opList
  54382. }).then(function () {
  54383. return opList;
  54384. });
  54385. });
  54386. return Promise.all([pageListPromise, this._parsedAnnotations, newAnnotationsPromise]).then(function ([pageOpList, annotations, newAnnotations]) {
  54387. if (newAnnotations) {
  54388. annotations = annotations.filter(a => !(a.ref && deletedAnnotations.has(a.ref)));
  54389. for (let i = 0, ii = newAnnotations.length; i < ii; i++) {
  54390. const newAnnotation = newAnnotations[i];
  54391. if (newAnnotation.refToReplace) {
  54392. const j = annotations.findIndex(a => a.ref && isRefsEqual(a.ref, newAnnotation.refToReplace));
  54393. if (j >= 0) {
  54394. annotations.splice(j, 1, newAnnotation);
  54395. newAnnotations.splice(i--, 1);
  54396. ii--;
  54397. }
  54398. }
  54399. }
  54400. annotations = annotations.concat(newAnnotations);
  54401. }
  54402. if (annotations.length === 0 || intent & RenderingIntentFlag.ANNOTATIONS_DISABLE) {
  54403. pageOpList.flush(true);
  54404. return {
  54405. length: pageOpList.totalLength
  54406. };
  54407. }
  54408. const renderForms = !!(intent & RenderingIntentFlag.ANNOTATIONS_FORMS),
  54409. intentAny = !!(intent & RenderingIntentFlag.ANY),
  54410. intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
  54411. intentPrint = !!(intent & RenderingIntentFlag.PRINT);
  54412. const opListPromises = [];
  54413. for (const annotation of annotations) {
  54414. if (intentAny || intentDisplay && annotation.mustBeViewed(annotationStorage, renderForms) || intentPrint && annotation.mustBePrinted(annotationStorage)) {
  54415. opListPromises.push(annotation.getOperatorList(partialEvaluator, task, intent, renderForms, annotationStorage).catch(function (reason) {
  54416. warn("getOperatorList - ignoring annotation data during " + `"${task.name}" task: "${reason}".`);
  54417. return {
  54418. opList: null,
  54419. separateForm: false,
  54420. separateCanvas: false
  54421. };
  54422. }));
  54423. }
  54424. }
  54425. return Promise.all(opListPromises).then(function (opLists) {
  54426. let form = false,
  54427. canvas = false;
  54428. for (const {
  54429. opList,
  54430. separateForm,
  54431. separateCanvas
  54432. } of opLists) {
  54433. pageOpList.addOpList(opList);
  54434. form ||= separateForm;
  54435. canvas ||= separateCanvas;
  54436. }
  54437. pageOpList.flush(true, {
  54438. form,
  54439. canvas
  54440. });
  54441. return {
  54442. length: pageOpList.totalLength
  54443. };
  54444. });
  54445. });
  54446. }
  54447. extractTextContent({
  54448. handler,
  54449. task,
  54450. includeMarkedContent,
  54451. disableNormalization,
  54452. sink
  54453. }) {
  54454. const contentStreamPromise = this.getContentStream();
  54455. const resourcesPromise = this.loadResources(["ExtGState", "Font", "Properties", "XObject"]);
  54456. const dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  54457. return dataPromises.then(([contentStream]) => {
  54458. const partialEvaluator = new PartialEvaluator({
  54459. xref: this.xref,
  54460. handler,
  54461. pageIndex: this.pageIndex,
  54462. idFactory: this._localIdFactory,
  54463. fontCache: this.fontCache,
  54464. builtInCMapCache: this.builtInCMapCache,
  54465. standardFontDataCache: this.standardFontDataCache,
  54466. globalImageCache: this.globalImageCache,
  54467. systemFontCache: this.systemFontCache,
  54468. options: this.evaluatorOptions
  54469. });
  54470. return partialEvaluator.getTextContent({
  54471. stream: contentStream,
  54472. task,
  54473. resources: this.resources,
  54474. includeMarkedContent,
  54475. disableNormalization,
  54476. sink,
  54477. viewBox: this.view
  54478. });
  54479. });
  54480. }
  54481. async getStructTree() {
  54482. const structTreeRoot = await this.pdfManager.ensureCatalog("structTreeRoot");
  54483. if (!structTreeRoot) {
  54484. return null;
  54485. }
  54486. await this._parsedAnnotations;
  54487. const structTree = await this.pdfManager.ensure(this, "_parseStructTree", [structTreeRoot]);
  54488. return structTree.serializable;
  54489. }
  54490. _parseStructTree(structTreeRoot) {
  54491. const tree = new StructTreePage(structTreeRoot, this.pageDict);
  54492. tree.parse(this.ref);
  54493. return tree;
  54494. }
  54495. async getAnnotationsData(handler, task, intent) {
  54496. const annotations = await this._parsedAnnotations;
  54497. if (annotations.length === 0) {
  54498. return annotations;
  54499. }
  54500. const annotationsData = [],
  54501. textContentPromises = [];
  54502. let partialEvaluator;
  54503. const intentAny = !!(intent & RenderingIntentFlag.ANY),
  54504. intentDisplay = !!(intent & RenderingIntentFlag.DISPLAY),
  54505. intentPrint = !!(intent & RenderingIntentFlag.PRINT);
  54506. for (const annotation of annotations) {
  54507. const isVisible = intentAny || intentDisplay && annotation.viewable;
  54508. if (isVisible || intentPrint && annotation.printable) {
  54509. annotationsData.push(annotation.data);
  54510. }
  54511. if (annotation.hasTextContent && isVisible) {
  54512. partialEvaluator ||= new PartialEvaluator({
  54513. xref: this.xref,
  54514. handler,
  54515. pageIndex: this.pageIndex,
  54516. idFactory: this._localIdFactory,
  54517. fontCache: this.fontCache,
  54518. builtInCMapCache: this.builtInCMapCache,
  54519. standardFontDataCache: this.standardFontDataCache,
  54520. globalImageCache: this.globalImageCache,
  54521. systemFontCache: this.systemFontCache,
  54522. options: this.evaluatorOptions
  54523. });
  54524. textContentPromises.push(annotation.extractTextContent(partialEvaluator, task, [-Infinity, -Infinity, Infinity, Infinity]).catch(function (reason) {
  54525. warn(`getAnnotationsData - ignoring textContent during "${task.name}" task: "${reason}".`);
  54526. }));
  54527. }
  54528. }
  54529. await Promise.all(textContentPromises);
  54530. return annotationsData;
  54531. }
  54532. get annotations() {
  54533. const annots = this._getInheritableProperty("Annots");
  54534. return shadow(this, "annotations", Array.isArray(annots) ? annots : []);
  54535. }
  54536. get _parsedAnnotations() {
  54537. const promise = this.pdfManager.ensure(this, "annotations").then(async annots => {
  54538. if (annots.length === 0) {
  54539. return annots;
  54540. }
  54541. const annotationGlobals = await this.pdfManager.ensureDoc("annotationGlobals");
  54542. if (!annotationGlobals) {
  54543. return [];
  54544. }
  54545. const annotationPromises = [];
  54546. for (const annotationRef of annots) {
  54547. annotationPromises.push(AnnotationFactory.create(this.xref, annotationRef, annotationGlobals, this._localIdFactory, false, this.ref).catch(function (reason) {
  54548. warn(`_parsedAnnotations: "${reason}".`);
  54549. return null;
  54550. }));
  54551. }
  54552. const sortedAnnotations = [];
  54553. let popupAnnotations;
  54554. for (const annotation of await Promise.all(annotationPromises)) {
  54555. if (!annotation) {
  54556. continue;
  54557. }
  54558. if (annotation instanceof PopupAnnotation) {
  54559. (popupAnnotations ||= []).push(annotation);
  54560. continue;
  54561. }
  54562. sortedAnnotations.push(annotation);
  54563. }
  54564. if (popupAnnotations) {
  54565. sortedAnnotations.push(...popupAnnotations);
  54566. }
  54567. return sortedAnnotations;
  54568. });
  54569. return shadow(this, "_parsedAnnotations", promise);
  54570. }
  54571. get jsActions() {
  54572. const actions = collectActions(this.xref, this.pageDict, PageActionEventType);
  54573. return shadow(this, "jsActions", actions);
  54574. }
  54575. }
  54576. const PDF_HEADER_SIGNATURE = new Uint8Array([0x25, 0x50, 0x44, 0x46, 0x2d]);
  54577. const STARTXREF_SIGNATURE = new Uint8Array([0x73, 0x74, 0x61, 0x72, 0x74, 0x78, 0x72, 0x65, 0x66]);
  54578. const ENDOBJ_SIGNATURE = new Uint8Array([0x65, 0x6e, 0x64, 0x6f, 0x62, 0x6a]);
  54579. const FINGERPRINT_FIRST_BYTES = 1024;
  54580. const EMPTY_FINGERPRINT = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  54581. function find(stream, signature, limit = 1024, backwards = false) {
  54582. const signatureLength = signature.length;
  54583. const scanBytes = stream.peekBytes(limit);
  54584. const scanLength = scanBytes.length - signatureLength;
  54585. if (scanLength <= 0) {
  54586. return false;
  54587. }
  54588. if (backwards) {
  54589. const signatureEnd = signatureLength - 1;
  54590. let pos = scanBytes.length - 1;
  54591. while (pos >= signatureEnd) {
  54592. let j = 0;
  54593. while (j < signatureLength && scanBytes[pos - j] === signature[signatureEnd - j]) {
  54594. j++;
  54595. }
  54596. if (j >= signatureLength) {
  54597. stream.pos += pos - signatureEnd;
  54598. return true;
  54599. }
  54600. pos--;
  54601. }
  54602. } else {
  54603. let pos = 0;
  54604. while (pos <= scanLength) {
  54605. let j = 0;
  54606. while (j < signatureLength && scanBytes[pos + j] === signature[j]) {
  54607. j++;
  54608. }
  54609. if (j >= signatureLength) {
  54610. stream.pos += pos;
  54611. return true;
  54612. }
  54613. pos++;
  54614. }
  54615. }
  54616. return false;
  54617. }
  54618. class PDFDocument {
  54619. constructor(pdfManager, stream) {
  54620. if (stream.length <= 0) {
  54621. throw new InvalidPDFException("The PDF file is empty, i.e. its size is zero bytes.");
  54622. }
  54623. this.pdfManager = pdfManager;
  54624. this.stream = stream;
  54625. this.xref = new XRef(stream, pdfManager);
  54626. this._pagePromises = new Map();
  54627. this._version = null;
  54628. const idCounters = {
  54629. font: 0
  54630. };
  54631. this._globalIdFactory = class {
  54632. static getDocId() {
  54633. return `g_${pdfManager.docId}`;
  54634. }
  54635. static createFontId() {
  54636. return `f${++idCounters.font}`;
  54637. }
  54638. static createObjId() {
  54639. unreachable("Abstract method `createObjId` called.");
  54640. }
  54641. static getPageObjId() {
  54642. unreachable("Abstract method `getPageObjId` called.");
  54643. }
  54644. };
  54645. }
  54646. parse(recoveryMode) {
  54647. this.xref.parse(recoveryMode);
  54648. this.catalog = new Catalog(this.pdfManager, this.xref);
  54649. }
  54650. get linearization() {
  54651. let linearization = null;
  54652. try {
  54653. linearization = Linearization.create(this.stream);
  54654. } catch (err) {
  54655. if (err instanceof MissingDataException) {
  54656. throw err;
  54657. }
  54658. info(err);
  54659. }
  54660. return shadow(this, "linearization", linearization);
  54661. }
  54662. get startXRef() {
  54663. const stream = this.stream;
  54664. let startXRef = 0;
  54665. if (this.linearization) {
  54666. stream.reset();
  54667. if (find(stream, ENDOBJ_SIGNATURE)) {
  54668. startXRef = stream.pos + 6 - stream.start;
  54669. }
  54670. } else {
  54671. const step = 1024;
  54672. const startXRefLength = STARTXREF_SIGNATURE.length;
  54673. let found = false,
  54674. pos = stream.end;
  54675. while (!found && pos > 0) {
  54676. pos -= step - startXRefLength;
  54677. if (pos < 0) {
  54678. pos = 0;
  54679. }
  54680. stream.pos = pos;
  54681. found = find(stream, STARTXREF_SIGNATURE, step, true);
  54682. }
  54683. if (found) {
  54684. stream.skip(9);
  54685. let ch;
  54686. do {
  54687. ch = stream.getByte();
  54688. } while (isWhiteSpace(ch));
  54689. let str = "";
  54690. while (ch >= 0x20 && ch <= 0x39) {
  54691. str += String.fromCharCode(ch);
  54692. ch = stream.getByte();
  54693. }
  54694. startXRef = parseInt(str, 10);
  54695. if (isNaN(startXRef)) {
  54696. startXRef = 0;
  54697. }
  54698. }
  54699. }
  54700. return shadow(this, "startXRef", startXRef);
  54701. }
  54702. checkHeader() {
  54703. const stream = this.stream;
  54704. stream.reset();
  54705. if (!find(stream, PDF_HEADER_SIGNATURE)) {
  54706. return;
  54707. }
  54708. stream.moveStart();
  54709. stream.skip(PDF_HEADER_SIGNATURE.length);
  54710. let version = "",
  54711. ch;
  54712. while ((ch = stream.getByte()) > 0x20 && version.length < 7) {
  54713. version += String.fromCharCode(ch);
  54714. }
  54715. if (PDF_VERSION_REGEXP.test(version)) {
  54716. this._version = version;
  54717. } else {
  54718. warn(`Invalid PDF header version: ${version}`);
  54719. }
  54720. }
  54721. parseStartXRef() {
  54722. this.xref.setStartXRef(this.startXRef);
  54723. }
  54724. get numPages() {
  54725. let num = 0;
  54726. if (this.catalog.hasActualNumPages) {
  54727. num = this.catalog.numPages;
  54728. } else if (this.xfaFactory) {
  54729. num = this.xfaFactory.getNumPages();
  54730. } else if (this.linearization) {
  54731. num = this.linearization.numPages;
  54732. } else {
  54733. num = this.catalog.numPages;
  54734. }
  54735. return shadow(this, "numPages", num);
  54736. }
  54737. _hasOnlyDocumentSignatures(fields, recursionDepth = 0) {
  54738. const RECURSION_LIMIT = 10;
  54739. if (!Array.isArray(fields)) {
  54740. return false;
  54741. }
  54742. return fields.every(field => {
  54743. field = this.xref.fetchIfRef(field);
  54744. if (!(field instanceof Dict)) {
  54745. return false;
  54746. }
  54747. if (field.has("Kids")) {
  54748. if (++recursionDepth > RECURSION_LIMIT) {
  54749. warn("_hasOnlyDocumentSignatures: maximum recursion depth reached");
  54750. return false;
  54751. }
  54752. return this._hasOnlyDocumentSignatures(field.get("Kids"), recursionDepth);
  54753. }
  54754. const isSignature = isName(field.get("FT"), "Sig");
  54755. const rectangle = field.get("Rect");
  54756. const isInvisible = Array.isArray(rectangle) && rectangle.every(value => value === 0);
  54757. return isSignature && isInvisible;
  54758. });
  54759. }
  54760. get _xfaStreams() {
  54761. const acroForm = this.catalog.acroForm;
  54762. if (!acroForm) {
  54763. return null;
  54764. }
  54765. const xfa = acroForm.get("XFA");
  54766. const entries = {
  54767. "xdp:xdp": "",
  54768. template: "",
  54769. datasets: "",
  54770. config: "",
  54771. connectionSet: "",
  54772. localeSet: "",
  54773. stylesheet: "",
  54774. "/xdp:xdp": ""
  54775. };
  54776. if (xfa instanceof BaseStream && !xfa.isEmpty) {
  54777. entries["xdp:xdp"] = xfa;
  54778. return entries;
  54779. }
  54780. if (!Array.isArray(xfa) || xfa.length === 0) {
  54781. return null;
  54782. }
  54783. for (let i = 0, ii = xfa.length; i < ii; i += 2) {
  54784. let name;
  54785. if (i === 0) {
  54786. name = "xdp:xdp";
  54787. } else if (i === ii - 2) {
  54788. name = "/xdp:xdp";
  54789. } else {
  54790. name = xfa[i];
  54791. }
  54792. if (!entries.hasOwnProperty(name)) {
  54793. continue;
  54794. }
  54795. const data = this.xref.fetchIfRef(xfa[i + 1]);
  54796. if (!(data instanceof BaseStream) || data.isEmpty) {
  54797. continue;
  54798. }
  54799. entries[name] = data;
  54800. }
  54801. return entries;
  54802. }
  54803. get xfaDatasets() {
  54804. const streams = this._xfaStreams;
  54805. if (!streams) {
  54806. return shadow(this, "xfaDatasets", null);
  54807. }
  54808. for (const key of ["datasets", "xdp:xdp"]) {
  54809. const stream = streams[key];
  54810. if (!stream) {
  54811. continue;
  54812. }
  54813. try {
  54814. const str = stringToUTF8String(stream.getString());
  54815. const data = {
  54816. [key]: str
  54817. };
  54818. return shadow(this, "xfaDatasets", new DatasetReader(data));
  54819. } catch {
  54820. warn("XFA - Invalid utf-8 string.");
  54821. break;
  54822. }
  54823. }
  54824. return shadow(this, "xfaDatasets", null);
  54825. }
  54826. get xfaData() {
  54827. const streams = this._xfaStreams;
  54828. if (!streams) {
  54829. return null;
  54830. }
  54831. const data = Object.create(null);
  54832. for (const [key, stream] of Object.entries(streams)) {
  54833. if (!stream) {
  54834. continue;
  54835. }
  54836. try {
  54837. data[key] = stringToUTF8String(stream.getString());
  54838. } catch {
  54839. warn("XFA - Invalid utf-8 string.");
  54840. return null;
  54841. }
  54842. }
  54843. return data;
  54844. }
  54845. get xfaFactory() {
  54846. let data;
  54847. if (this.pdfManager.enableXfa && this.catalog.needsRendering && this.formInfo.hasXfa && !this.formInfo.hasAcroForm) {
  54848. data = this.xfaData;
  54849. }
  54850. return shadow(this, "xfaFactory", data ? new XFAFactory(data) : null);
  54851. }
  54852. get isPureXfa() {
  54853. return this.xfaFactory ? this.xfaFactory.isValid() : false;
  54854. }
  54855. get htmlForXfa() {
  54856. return this.xfaFactory ? this.xfaFactory.getPages() : null;
  54857. }
  54858. async loadXfaImages() {
  54859. const xfaImagesDict = await this.pdfManager.ensureCatalog("xfaImages");
  54860. if (!xfaImagesDict) {
  54861. return;
  54862. }
  54863. const keys = xfaImagesDict.getKeys();
  54864. const objectLoader = new ObjectLoader(xfaImagesDict, keys, this.xref);
  54865. await objectLoader.load();
  54866. const xfaImages = new Map();
  54867. for (const key of keys) {
  54868. const stream = xfaImagesDict.get(key);
  54869. if (stream instanceof BaseStream) {
  54870. xfaImages.set(key, stream.getBytes());
  54871. }
  54872. }
  54873. this.xfaFactory.setImages(xfaImages);
  54874. }
  54875. async loadXfaFonts(handler, task) {
  54876. const acroForm = await this.pdfManager.ensureCatalog("acroForm");
  54877. if (!acroForm) {
  54878. return;
  54879. }
  54880. const resources = await acroForm.getAsync("DR");
  54881. if (!(resources instanceof Dict)) {
  54882. return;
  54883. }
  54884. const objectLoader = new ObjectLoader(resources, ["Font"], this.xref);
  54885. await objectLoader.load();
  54886. const fontRes = resources.get("Font");
  54887. if (!(fontRes instanceof Dict)) {
  54888. return;
  54889. }
  54890. const options = Object.assign(Object.create(null), this.pdfManager.evaluatorOptions);
  54891. options.useSystemFonts = false;
  54892. const partialEvaluator = new PartialEvaluator({
  54893. xref: this.xref,
  54894. handler,
  54895. pageIndex: -1,
  54896. idFactory: this._globalIdFactory,
  54897. fontCache: this.catalog.fontCache,
  54898. builtInCMapCache: this.catalog.builtInCMapCache,
  54899. standardFontDataCache: this.catalog.standardFontDataCache,
  54900. options
  54901. });
  54902. const operatorList = new OperatorList();
  54903. const pdfFonts = [];
  54904. const initialState = {
  54905. get font() {
  54906. return pdfFonts.at(-1);
  54907. },
  54908. set font(font) {
  54909. pdfFonts.push(font);
  54910. },
  54911. clone() {
  54912. return this;
  54913. }
  54914. };
  54915. const fonts = new Map();
  54916. fontRes.forEach((fontName, font) => {
  54917. fonts.set(fontName, font);
  54918. });
  54919. const promises = [];
  54920. for (const [fontName, font] of fonts) {
  54921. const descriptor = font.get("FontDescriptor");
  54922. if (!(descriptor instanceof Dict)) {
  54923. continue;
  54924. }
  54925. let fontFamily = descriptor.get("FontFamily");
  54926. fontFamily = fontFamily.replaceAll(/[ ]+(\d)/g, "$1");
  54927. const fontWeight = descriptor.get("FontWeight");
  54928. const italicAngle = -descriptor.get("ItalicAngle");
  54929. const cssFontInfo = {
  54930. fontFamily,
  54931. fontWeight,
  54932. italicAngle
  54933. };
  54934. if (!validateCSSFont(cssFontInfo)) {
  54935. continue;
  54936. }
  54937. promises.push(partialEvaluator.handleSetFont(resources, [Name.get(fontName), 1], null, operatorList, task, initialState, null, cssFontInfo).catch(function (reason) {
  54938. warn(`loadXfaFonts: "${reason}".`);
  54939. return null;
  54940. }));
  54941. }
  54942. await Promise.all(promises);
  54943. const missingFonts = this.xfaFactory.setFonts(pdfFonts);
  54944. if (!missingFonts) {
  54945. return;
  54946. }
  54947. options.ignoreErrors = true;
  54948. promises.length = 0;
  54949. pdfFonts.length = 0;
  54950. const reallyMissingFonts = new Set();
  54951. for (const missing of missingFonts) {
  54952. if (!getXfaFontName(`${missing}-Regular`)) {
  54953. reallyMissingFonts.add(missing);
  54954. }
  54955. }
  54956. if (reallyMissingFonts.size) {
  54957. missingFonts.push("PdfJS-Fallback");
  54958. }
  54959. for (const missing of missingFonts) {
  54960. if (reallyMissingFonts.has(missing)) {
  54961. continue;
  54962. }
  54963. for (const fontInfo of [{
  54964. name: "Regular",
  54965. fontWeight: 400,
  54966. italicAngle: 0
  54967. }, {
  54968. name: "Bold",
  54969. fontWeight: 700,
  54970. italicAngle: 0
  54971. }, {
  54972. name: "Italic",
  54973. fontWeight: 400,
  54974. italicAngle: 12
  54975. }, {
  54976. name: "BoldItalic",
  54977. fontWeight: 700,
  54978. italicAngle: 12
  54979. }]) {
  54980. const name = `${missing}-${fontInfo.name}`;
  54981. const dict = getXfaFontDict(name);
  54982. promises.push(partialEvaluator.handleSetFont(resources, [Name.get(name), 1], null, operatorList, task, initialState, dict, {
  54983. fontFamily: missing,
  54984. fontWeight: fontInfo.fontWeight,
  54985. italicAngle: fontInfo.italicAngle
  54986. }).catch(function (reason) {
  54987. warn(`loadXfaFonts: "${reason}".`);
  54988. return null;
  54989. }));
  54990. }
  54991. }
  54992. await Promise.all(promises);
  54993. this.xfaFactory.appendFonts(pdfFonts, reallyMissingFonts);
  54994. }
  54995. async serializeXfaData(annotationStorage) {
  54996. return this.xfaFactory ? this.xfaFactory.serializeData(annotationStorage) : null;
  54997. }
  54998. get version() {
  54999. return this.catalog.version || this._version;
  55000. }
  55001. get formInfo() {
  55002. const formInfo = {
  55003. hasFields: false,
  55004. hasAcroForm: false,
  55005. hasXfa: false,
  55006. hasSignatures: false
  55007. };
  55008. const acroForm = this.catalog.acroForm;
  55009. if (!acroForm) {
  55010. return shadow(this, "formInfo", formInfo);
  55011. }
  55012. try {
  55013. const fields = acroForm.get("Fields");
  55014. const hasFields = Array.isArray(fields) && fields.length > 0;
  55015. formInfo.hasFields = hasFields;
  55016. const xfa = acroForm.get("XFA");
  55017. formInfo.hasXfa = Array.isArray(xfa) && xfa.length > 0 || xfa instanceof BaseStream && !xfa.isEmpty;
  55018. const sigFlags = acroForm.get("SigFlags");
  55019. const hasSignatures = !!(sigFlags & 0x1);
  55020. const hasOnlyDocumentSignatures = hasSignatures && this._hasOnlyDocumentSignatures(fields);
  55021. formInfo.hasAcroForm = hasFields && !hasOnlyDocumentSignatures;
  55022. formInfo.hasSignatures = hasSignatures;
  55023. } catch (ex) {
  55024. if (ex instanceof MissingDataException) {
  55025. throw ex;
  55026. }
  55027. warn(`Cannot fetch form information: "${ex}".`);
  55028. }
  55029. return shadow(this, "formInfo", formInfo);
  55030. }
  55031. get documentInfo() {
  55032. const docInfo = {
  55033. PDFFormatVersion: this.version,
  55034. Language: this.catalog.lang,
  55035. EncryptFilterName: this.xref.encrypt ? this.xref.encrypt.filterName : null,
  55036. IsLinearized: !!this.linearization,
  55037. IsAcroFormPresent: this.formInfo.hasAcroForm,
  55038. IsXFAPresent: this.formInfo.hasXfa,
  55039. IsCollectionPresent: !!this.catalog.collection,
  55040. IsSignaturesPresent: this.formInfo.hasSignatures
  55041. };
  55042. let infoDict;
  55043. try {
  55044. infoDict = this.xref.trailer.get("Info");
  55045. } catch (err) {
  55046. if (err instanceof MissingDataException) {
  55047. throw err;
  55048. }
  55049. info("The document information dictionary is invalid.");
  55050. }
  55051. if (!(infoDict instanceof Dict)) {
  55052. return shadow(this, "documentInfo", docInfo);
  55053. }
  55054. for (const key of infoDict.getKeys()) {
  55055. const value = infoDict.get(key);
  55056. switch (key) {
  55057. case "Title":
  55058. case "Author":
  55059. case "Subject":
  55060. case "Keywords":
  55061. case "Creator":
  55062. case "Producer":
  55063. case "CreationDate":
  55064. case "ModDate":
  55065. if (typeof value === "string") {
  55066. docInfo[key] = stringToPDFString(value);
  55067. continue;
  55068. }
  55069. break;
  55070. case "Trapped":
  55071. if (value instanceof Name) {
  55072. docInfo[key] = value;
  55073. continue;
  55074. }
  55075. break;
  55076. default:
  55077. let customValue;
  55078. switch (typeof value) {
  55079. case "string":
  55080. customValue = stringToPDFString(value);
  55081. break;
  55082. case "number":
  55083. case "boolean":
  55084. customValue = value;
  55085. break;
  55086. default:
  55087. if (value instanceof Name) {
  55088. customValue = value;
  55089. }
  55090. break;
  55091. }
  55092. if (customValue === undefined) {
  55093. warn(`Bad value, for custom key "${key}", in Info: ${value}.`);
  55094. continue;
  55095. }
  55096. if (!docInfo.Custom) {
  55097. docInfo.Custom = Object.create(null);
  55098. }
  55099. docInfo.Custom[key] = customValue;
  55100. continue;
  55101. }
  55102. warn(`Bad value, for key "${key}", in Info: ${value}.`);
  55103. }
  55104. return shadow(this, "documentInfo", docInfo);
  55105. }
  55106. get fingerprints() {
  55107. function validate(data) {
  55108. return typeof data === "string" && data.length > 0 && data !== EMPTY_FINGERPRINT;
  55109. }
  55110. function hexString(hash) {
  55111. const buf = [];
  55112. for (const num of hash) {
  55113. const hex = num.toString(16);
  55114. buf.push(hex.padStart(2, "0"));
  55115. }
  55116. return buf.join("");
  55117. }
  55118. const idArray = this.xref.trailer.get("ID");
  55119. let hashOriginal, hashModified;
  55120. if (Array.isArray(idArray) && validate(idArray[0])) {
  55121. hashOriginal = stringToBytes(idArray[0]);
  55122. if (idArray[1] !== idArray[0] && validate(idArray[1])) {
  55123. hashModified = stringToBytes(idArray[1]);
  55124. }
  55125. } else {
  55126. hashOriginal = calculateMD5(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  55127. }
  55128. return shadow(this, "fingerprints", [hexString(hashOriginal), hashModified ? hexString(hashModified) : null]);
  55129. }
  55130. async _getLinearizationPage(pageIndex) {
  55131. const {
  55132. catalog,
  55133. linearization,
  55134. xref
  55135. } = this;
  55136. const ref = Ref.get(linearization.objectNumberFirst, 0);
  55137. try {
  55138. const obj = await xref.fetchAsync(ref);
  55139. if (obj instanceof Dict) {
  55140. let type = obj.getRaw("Type");
  55141. if (type instanceof Ref) {
  55142. type = await xref.fetchAsync(type);
  55143. }
  55144. if (isName(type, "Page") || !obj.has("Type") && !obj.has("Kids")) {
  55145. if (!catalog.pageKidsCountCache.has(ref)) {
  55146. catalog.pageKidsCountCache.put(ref, 1);
  55147. }
  55148. if (!catalog.pageIndexCache.has(ref)) {
  55149. catalog.pageIndexCache.put(ref, 0);
  55150. }
  55151. return [obj, ref];
  55152. }
  55153. }
  55154. throw new FormatError("The Linearization dictionary doesn't point to a valid Page dictionary.");
  55155. } catch (reason) {
  55156. warn(`_getLinearizationPage: "${reason.message}".`);
  55157. return catalog.getPageDict(pageIndex);
  55158. }
  55159. }
  55160. getPage(pageIndex) {
  55161. const cachedPromise = this._pagePromises.get(pageIndex);
  55162. if (cachedPromise) {
  55163. return cachedPromise;
  55164. }
  55165. const {
  55166. catalog,
  55167. linearization,
  55168. xfaFactory
  55169. } = this;
  55170. let promise;
  55171. if (xfaFactory) {
  55172. promise = Promise.resolve([Dict.empty, null]);
  55173. } else if (linearization?.pageFirst === pageIndex) {
  55174. promise = this._getLinearizationPage(pageIndex);
  55175. } else {
  55176. promise = catalog.getPageDict(pageIndex);
  55177. }
  55178. promise = promise.then(([pageDict, ref]) => {
  55179. return new Page({
  55180. pdfManager: this.pdfManager,
  55181. xref: this.xref,
  55182. pageIndex,
  55183. pageDict,
  55184. ref,
  55185. globalIdFactory: this._globalIdFactory,
  55186. fontCache: catalog.fontCache,
  55187. builtInCMapCache: catalog.builtInCMapCache,
  55188. standardFontDataCache: catalog.standardFontDataCache,
  55189. globalImageCache: catalog.globalImageCache,
  55190. systemFontCache: catalog.systemFontCache,
  55191. nonBlendModesSet: catalog.nonBlendModesSet,
  55192. xfaFactory
  55193. });
  55194. });
  55195. this._pagePromises.set(pageIndex, promise);
  55196. return promise;
  55197. }
  55198. async checkFirstPage(recoveryMode = false) {
  55199. if (recoveryMode) {
  55200. return;
  55201. }
  55202. try {
  55203. await this.getPage(0);
  55204. } catch (reason) {
  55205. if (reason instanceof XRefEntryException) {
  55206. this._pagePromises.delete(0);
  55207. await this.cleanup();
  55208. throw new XRefParseException();
  55209. }
  55210. }
  55211. }
  55212. async checkLastPage(recoveryMode = false) {
  55213. const {
  55214. catalog,
  55215. pdfManager
  55216. } = this;
  55217. catalog.setActualNumPages();
  55218. let numPages;
  55219. try {
  55220. await Promise.all([pdfManager.ensureDoc("xfaFactory"), pdfManager.ensureDoc("linearization"), pdfManager.ensureCatalog("numPages")]);
  55221. if (this.xfaFactory) {
  55222. return;
  55223. } else if (this.linearization) {
  55224. numPages = this.linearization.numPages;
  55225. } else {
  55226. numPages = catalog.numPages;
  55227. }
  55228. if (!Number.isInteger(numPages)) {
  55229. throw new FormatError("Page count is not an integer.");
  55230. } else if (numPages <= 1) {
  55231. return;
  55232. }
  55233. await this.getPage(numPages - 1);
  55234. } catch (reason) {
  55235. this._pagePromises.delete(numPages - 1);
  55236. await this.cleanup();
  55237. if (reason instanceof XRefEntryException && !recoveryMode) {
  55238. throw new XRefParseException();
  55239. }
  55240. warn(`checkLastPage - invalid /Pages tree /Count: ${numPages}.`);
  55241. let pagesTree;
  55242. try {
  55243. pagesTree = await catalog.getAllPageDicts(recoveryMode);
  55244. } catch (reasonAll) {
  55245. if (reasonAll instanceof XRefEntryException && !recoveryMode) {
  55246. throw new XRefParseException();
  55247. }
  55248. catalog.setActualNumPages(1);
  55249. return;
  55250. }
  55251. for (const [pageIndex, [pageDict, ref]] of pagesTree) {
  55252. let promise;
  55253. if (pageDict instanceof Error) {
  55254. promise = Promise.reject(pageDict);
  55255. promise.catch(() => {});
  55256. } else {
  55257. promise = Promise.resolve(new Page({
  55258. pdfManager,
  55259. xref: this.xref,
  55260. pageIndex,
  55261. pageDict,
  55262. ref,
  55263. globalIdFactory: this._globalIdFactory,
  55264. fontCache: catalog.fontCache,
  55265. builtInCMapCache: catalog.builtInCMapCache,
  55266. standardFontDataCache: catalog.standardFontDataCache,
  55267. globalImageCache: catalog.globalImageCache,
  55268. systemFontCache: catalog.systemFontCache,
  55269. nonBlendModesSet: catalog.nonBlendModesSet,
  55270. xfaFactory: null
  55271. }));
  55272. }
  55273. this._pagePromises.set(pageIndex, promise);
  55274. }
  55275. catalog.setActualNumPages(pagesTree.size);
  55276. }
  55277. }
  55278. fontFallback(id, handler) {
  55279. return this.catalog.fontFallback(id, handler);
  55280. }
  55281. async cleanup(manuallyTriggered = false) {
  55282. return this.catalog ? this.catalog.cleanup(manuallyTriggered) : clearGlobalCaches();
  55283. }
  55284. async #collectFieldObjects(name, fieldRef, promises, annotationGlobals, visitedRefs) {
  55285. const {
  55286. xref
  55287. } = this;
  55288. if (!(fieldRef instanceof Ref) || visitedRefs.has(fieldRef)) {
  55289. return;
  55290. }
  55291. visitedRefs.put(fieldRef);
  55292. const field = await xref.fetchAsync(fieldRef);
  55293. if (!(field instanceof Dict)) {
  55294. return;
  55295. }
  55296. if (field.has("T")) {
  55297. const partName = stringToPDFString(await field.getAsync("T"));
  55298. name = name === "" ? partName : `${name}.${partName}`;
  55299. } else {
  55300. let obj = field;
  55301. while (true) {
  55302. obj = obj.getRaw("Parent");
  55303. if (obj instanceof Ref) {
  55304. if (visitedRefs.has(obj)) {
  55305. break;
  55306. }
  55307. obj = await xref.fetchAsync(obj);
  55308. }
  55309. if (!(obj instanceof Dict)) {
  55310. break;
  55311. }
  55312. if (obj.has("T")) {
  55313. const partName = stringToPDFString(await obj.getAsync("T"));
  55314. name = name === "" ? partName : `${name}.${partName}`;
  55315. break;
  55316. }
  55317. }
  55318. }
  55319. if (!promises.has(name)) {
  55320. promises.set(name, []);
  55321. }
  55322. promises.get(name).push(AnnotationFactory.create(xref, fieldRef, annotationGlobals, null, true, null).then(annotation => annotation?.getFieldObject()).catch(function (reason) {
  55323. warn(`#collectFieldObjects: "${reason}".`);
  55324. return null;
  55325. }));
  55326. if (!field.has("Kids")) {
  55327. return;
  55328. }
  55329. const kids = await field.getAsync("Kids");
  55330. if (Array.isArray(kids)) {
  55331. for (const kid of kids) {
  55332. await this.#collectFieldObjects(name, kid, promises, annotationGlobals, visitedRefs);
  55333. }
  55334. }
  55335. }
  55336. get fieldObjects() {
  55337. if (!this.formInfo.hasFields) {
  55338. return shadow(this, "fieldObjects", Promise.resolve(null));
  55339. }
  55340. const promise = Promise.all([this.pdfManager.ensureDoc("annotationGlobals"), this.pdfManager.ensureCatalog("acroForm")]).then(async ([annotationGlobals, acroForm]) => {
  55341. if (!annotationGlobals) {
  55342. return null;
  55343. }
  55344. const visitedRefs = new RefSet();
  55345. const allFields = Object.create(null);
  55346. const fieldPromises = new Map();
  55347. for (const fieldRef of await acroForm.getAsync("Fields")) {
  55348. await this.#collectFieldObjects("", fieldRef, fieldPromises, annotationGlobals, visitedRefs);
  55349. }
  55350. const allPromises = [];
  55351. for (const [name, promises] of fieldPromises) {
  55352. allPromises.push(Promise.all(promises).then(fields => {
  55353. fields = fields.filter(field => !!field);
  55354. if (fields.length > 0) {
  55355. allFields[name] = fields;
  55356. }
  55357. }));
  55358. }
  55359. await Promise.all(allPromises);
  55360. return allFields;
  55361. });
  55362. return shadow(this, "fieldObjects", promise);
  55363. }
  55364. get hasJSActions() {
  55365. const promise = this.pdfManager.ensureDoc("_parseHasJSActions");
  55366. return shadow(this, "hasJSActions", promise);
  55367. }
  55368. async _parseHasJSActions() {
  55369. const [catalogJsActions, fieldObjects] = await Promise.all([this.pdfManager.ensureCatalog("jsActions"), this.pdfManager.ensureDoc("fieldObjects")]);
  55370. if (catalogJsActions) {
  55371. return true;
  55372. }
  55373. if (fieldObjects) {
  55374. return Object.values(fieldObjects).some(fieldObject => fieldObject.some(object => object.actions !== null));
  55375. }
  55376. return false;
  55377. }
  55378. get calculationOrderIds() {
  55379. const acroForm = this.catalog.acroForm;
  55380. if (!acroForm?.has("CO")) {
  55381. return shadow(this, "calculationOrderIds", null);
  55382. }
  55383. const calculationOrder = acroForm.get("CO");
  55384. if (!Array.isArray(calculationOrder) || calculationOrder.length === 0) {
  55385. return shadow(this, "calculationOrderIds", null);
  55386. }
  55387. const ids = [];
  55388. for (const id of calculationOrder) {
  55389. if (id instanceof Ref) {
  55390. ids.push(id.toString());
  55391. }
  55392. }
  55393. if (ids.length === 0) {
  55394. return shadow(this, "calculationOrderIds", null);
  55395. }
  55396. return shadow(this, "calculationOrderIds", ids);
  55397. }
  55398. get annotationGlobals() {
  55399. return shadow(this, "annotationGlobals", AnnotationFactory.createGlobals(this.pdfManager));
  55400. }
  55401. }
  55402. ;// CONCATENATED MODULE: ./src/core/pdf_manager.js
  55403. function parseDocBaseUrl(url) {
  55404. if (url) {
  55405. const absoluteUrl = createValidAbsoluteUrl(url);
  55406. if (absoluteUrl) {
  55407. return absoluteUrl.href;
  55408. }
  55409. warn(`Invalid absolute docBaseUrl: "${url}".`);
  55410. }
  55411. return null;
  55412. }
  55413. class BasePdfManager {
  55414. constructor(args) {
  55415. if (this.constructor === BasePdfManager) {
  55416. unreachable("Cannot initialize BasePdfManager.");
  55417. }
  55418. this._docBaseUrl = parseDocBaseUrl(args.docBaseUrl);
  55419. this._docId = args.docId;
  55420. this._password = args.password;
  55421. this.enableXfa = args.enableXfa;
  55422. args.evaluatorOptions.isOffscreenCanvasSupported &&= FeatureTest.isOffscreenCanvasSupported;
  55423. this.evaluatorOptions = args.evaluatorOptions;
  55424. }
  55425. get docId() {
  55426. return this._docId;
  55427. }
  55428. get password() {
  55429. return this._password;
  55430. }
  55431. get docBaseUrl() {
  55432. return this._docBaseUrl;
  55433. }
  55434. get catalog() {
  55435. return this.pdfDocument.catalog;
  55436. }
  55437. ensureDoc(prop, args) {
  55438. return this.ensure(this.pdfDocument, prop, args);
  55439. }
  55440. ensureXRef(prop, args) {
  55441. return this.ensure(this.pdfDocument.xref, prop, args);
  55442. }
  55443. ensureCatalog(prop, args) {
  55444. return this.ensure(this.pdfDocument.catalog, prop, args);
  55445. }
  55446. getPage(pageIndex) {
  55447. return this.pdfDocument.getPage(pageIndex);
  55448. }
  55449. fontFallback(id, handler) {
  55450. return this.pdfDocument.fontFallback(id, handler);
  55451. }
  55452. loadXfaFonts(handler, task) {
  55453. return this.pdfDocument.loadXfaFonts(handler, task);
  55454. }
  55455. loadXfaImages() {
  55456. return this.pdfDocument.loadXfaImages();
  55457. }
  55458. serializeXfaData(annotationStorage) {
  55459. return this.pdfDocument.serializeXfaData(annotationStorage);
  55460. }
  55461. cleanup(manuallyTriggered = false) {
  55462. return this.pdfDocument.cleanup(manuallyTriggered);
  55463. }
  55464. async ensure(obj, prop, args) {
  55465. unreachable("Abstract method `ensure` called");
  55466. }
  55467. requestRange(begin, end) {
  55468. unreachable("Abstract method `requestRange` called");
  55469. }
  55470. requestLoadedStream(noFetch = false) {
  55471. unreachable("Abstract method `requestLoadedStream` called");
  55472. }
  55473. sendProgressiveData(chunk) {
  55474. unreachable("Abstract method `sendProgressiveData` called");
  55475. }
  55476. updatePassword(password) {
  55477. this._password = password;
  55478. }
  55479. terminate(reason) {
  55480. unreachable("Abstract method `terminate` called");
  55481. }
  55482. }
  55483. class LocalPdfManager extends BasePdfManager {
  55484. constructor(args) {
  55485. super(args);
  55486. const stream = new Stream(args.source);
  55487. this.pdfDocument = new PDFDocument(this, stream);
  55488. this._loadedStreamPromise = Promise.resolve(stream);
  55489. }
  55490. async ensure(obj, prop, args) {
  55491. const value = obj[prop];
  55492. if (typeof value === "function") {
  55493. return value.apply(obj, args);
  55494. }
  55495. return value;
  55496. }
  55497. requestRange(begin, end) {
  55498. return Promise.resolve();
  55499. }
  55500. requestLoadedStream(noFetch = false) {
  55501. return this._loadedStreamPromise;
  55502. }
  55503. terminate(reason) {}
  55504. }
  55505. class NetworkPdfManager extends BasePdfManager {
  55506. constructor(args) {
  55507. super(args);
  55508. this.streamManager = new ChunkedStreamManager(args.source, {
  55509. msgHandler: args.handler,
  55510. length: args.length,
  55511. disableAutoFetch: args.disableAutoFetch,
  55512. rangeChunkSize: args.rangeChunkSize
  55513. });
  55514. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream());
  55515. }
  55516. async ensure(obj, prop, args) {
  55517. try {
  55518. const value = obj[prop];
  55519. if (typeof value === "function") {
  55520. return value.apply(obj, args);
  55521. }
  55522. return value;
  55523. } catch (ex) {
  55524. if (!(ex instanceof MissingDataException)) {
  55525. throw ex;
  55526. }
  55527. await this.requestRange(ex.begin, ex.end);
  55528. return this.ensure(obj, prop, args);
  55529. }
  55530. }
  55531. requestRange(begin, end) {
  55532. return this.streamManager.requestRange(begin, end);
  55533. }
  55534. requestLoadedStream(noFetch = false) {
  55535. return this.streamManager.requestAllChunks(noFetch);
  55536. }
  55537. sendProgressiveData(chunk) {
  55538. this.streamManager.onReceiveData({
  55539. chunk
  55540. });
  55541. }
  55542. terminate(reason) {
  55543. this.streamManager.abort(reason);
  55544. }
  55545. }
  55546. ;// CONCATENATED MODULE: ./src/shared/message_handler.js
  55547. const CallbackKind = {
  55548. UNKNOWN: 0,
  55549. DATA: 1,
  55550. ERROR: 2
  55551. };
  55552. const StreamKind = {
  55553. UNKNOWN: 0,
  55554. CANCEL: 1,
  55555. CANCEL_COMPLETE: 2,
  55556. CLOSE: 3,
  55557. ENQUEUE: 4,
  55558. ERROR: 5,
  55559. PULL: 6,
  55560. PULL_COMPLETE: 7,
  55561. START_COMPLETE: 8
  55562. };
  55563. function wrapReason(reason) {
  55564. if (!(reason instanceof Error || typeof reason === "object" && reason !== null)) {
  55565. unreachable('wrapReason: Expected "reason" to be a (possibly cloned) Error.');
  55566. }
  55567. switch (reason.name) {
  55568. case "AbortException":
  55569. return new AbortException(reason.message);
  55570. case "MissingPDFException":
  55571. return new MissingPDFException(reason.message);
  55572. case "PasswordException":
  55573. return new PasswordException(reason.message, reason.code);
  55574. case "UnexpectedResponseException":
  55575. return new UnexpectedResponseException(reason.message, reason.status);
  55576. case "UnknownErrorException":
  55577. return new UnknownErrorException(reason.message, reason.details);
  55578. default:
  55579. return new UnknownErrorException(reason.message, reason.toString());
  55580. }
  55581. }
  55582. class MessageHandler {
  55583. constructor(sourceName, targetName, comObj) {
  55584. this.sourceName = sourceName;
  55585. this.targetName = targetName;
  55586. this.comObj = comObj;
  55587. this.callbackId = 1;
  55588. this.streamId = 1;
  55589. this.streamSinks = Object.create(null);
  55590. this.streamControllers = Object.create(null);
  55591. this.callbackCapabilities = Object.create(null);
  55592. this.actionHandler = Object.create(null);
  55593. this._onComObjOnMessage = event => {
  55594. const data = event.data;
  55595. if (data.targetName !== this.sourceName) {
  55596. return;
  55597. }
  55598. if (data.stream) {
  55599. this.#processStreamMessage(data);
  55600. return;
  55601. }
  55602. if (data.callback) {
  55603. const callbackId = data.callbackId;
  55604. const capability = this.callbackCapabilities[callbackId];
  55605. if (!capability) {
  55606. throw new Error(`Cannot resolve callback ${callbackId}`);
  55607. }
  55608. delete this.callbackCapabilities[callbackId];
  55609. if (data.callback === CallbackKind.DATA) {
  55610. capability.resolve(data.data);
  55611. } else if (data.callback === CallbackKind.ERROR) {
  55612. capability.reject(wrapReason(data.reason));
  55613. } else {
  55614. throw new Error("Unexpected callback case");
  55615. }
  55616. return;
  55617. }
  55618. const action = this.actionHandler[data.action];
  55619. if (!action) {
  55620. throw new Error(`Unknown action from worker: ${data.action}`);
  55621. }
  55622. if (data.callbackId) {
  55623. const cbSourceName = this.sourceName;
  55624. const cbTargetName = data.sourceName;
  55625. new Promise(function (resolve) {
  55626. resolve(action(data.data));
  55627. }).then(function (result) {
  55628. comObj.postMessage({
  55629. sourceName: cbSourceName,
  55630. targetName: cbTargetName,
  55631. callback: CallbackKind.DATA,
  55632. callbackId: data.callbackId,
  55633. data: result
  55634. });
  55635. }, function (reason) {
  55636. comObj.postMessage({
  55637. sourceName: cbSourceName,
  55638. targetName: cbTargetName,
  55639. callback: CallbackKind.ERROR,
  55640. callbackId: data.callbackId,
  55641. reason: wrapReason(reason)
  55642. });
  55643. });
  55644. return;
  55645. }
  55646. if (data.streamId) {
  55647. this.#createStreamSink(data);
  55648. return;
  55649. }
  55650. action(data.data);
  55651. };
  55652. comObj.addEventListener("message", this._onComObjOnMessage);
  55653. }
  55654. on(actionName, handler) {
  55655. const ah = this.actionHandler;
  55656. if (ah[actionName]) {
  55657. throw new Error(`There is already an actionName called "${actionName}"`);
  55658. }
  55659. ah[actionName] = handler;
  55660. }
  55661. send(actionName, data, transfers) {
  55662. this.comObj.postMessage({
  55663. sourceName: this.sourceName,
  55664. targetName: this.targetName,
  55665. action: actionName,
  55666. data
  55667. }, transfers);
  55668. }
  55669. sendWithPromise(actionName, data, transfers) {
  55670. const callbackId = this.callbackId++;
  55671. const capability = new PromiseCapability();
  55672. this.callbackCapabilities[callbackId] = capability;
  55673. try {
  55674. this.comObj.postMessage({
  55675. sourceName: this.sourceName,
  55676. targetName: this.targetName,
  55677. action: actionName,
  55678. callbackId,
  55679. data
  55680. }, transfers);
  55681. } catch (ex) {
  55682. capability.reject(ex);
  55683. }
  55684. return capability.promise;
  55685. }
  55686. sendWithStream(actionName, data, queueingStrategy, transfers) {
  55687. const streamId = this.streamId++,
  55688. sourceName = this.sourceName,
  55689. targetName = this.targetName,
  55690. comObj = this.comObj;
  55691. return new ReadableStream({
  55692. start: controller => {
  55693. const startCapability = new PromiseCapability();
  55694. this.streamControllers[streamId] = {
  55695. controller,
  55696. startCall: startCapability,
  55697. pullCall: null,
  55698. cancelCall: null,
  55699. isClosed: false
  55700. };
  55701. comObj.postMessage({
  55702. sourceName,
  55703. targetName,
  55704. action: actionName,
  55705. streamId,
  55706. data,
  55707. desiredSize: controller.desiredSize
  55708. }, transfers);
  55709. return startCapability.promise;
  55710. },
  55711. pull: controller => {
  55712. const pullCapability = new PromiseCapability();
  55713. this.streamControllers[streamId].pullCall = pullCapability;
  55714. comObj.postMessage({
  55715. sourceName,
  55716. targetName,
  55717. stream: StreamKind.PULL,
  55718. streamId,
  55719. desiredSize: controller.desiredSize
  55720. });
  55721. return pullCapability.promise;
  55722. },
  55723. cancel: reason => {
  55724. assert(reason instanceof Error, "cancel must have a valid reason");
  55725. const cancelCapability = new PromiseCapability();
  55726. this.streamControllers[streamId].cancelCall = cancelCapability;
  55727. this.streamControllers[streamId].isClosed = true;
  55728. comObj.postMessage({
  55729. sourceName,
  55730. targetName,
  55731. stream: StreamKind.CANCEL,
  55732. streamId,
  55733. reason: wrapReason(reason)
  55734. });
  55735. return cancelCapability.promise;
  55736. }
  55737. }, queueingStrategy);
  55738. }
  55739. #createStreamSink(data) {
  55740. const streamId = data.streamId,
  55741. sourceName = this.sourceName,
  55742. targetName = data.sourceName,
  55743. comObj = this.comObj;
  55744. const self = this,
  55745. action = this.actionHandler[data.action];
  55746. const streamSink = {
  55747. enqueue(chunk, size = 1, transfers) {
  55748. if (this.isCancelled) {
  55749. return;
  55750. }
  55751. const lastDesiredSize = this.desiredSize;
  55752. this.desiredSize -= size;
  55753. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  55754. this.sinkCapability = new PromiseCapability();
  55755. this.ready = this.sinkCapability.promise;
  55756. }
  55757. comObj.postMessage({
  55758. sourceName,
  55759. targetName,
  55760. stream: StreamKind.ENQUEUE,
  55761. streamId,
  55762. chunk
  55763. }, transfers);
  55764. },
  55765. close() {
  55766. if (this.isCancelled) {
  55767. return;
  55768. }
  55769. this.isCancelled = true;
  55770. comObj.postMessage({
  55771. sourceName,
  55772. targetName,
  55773. stream: StreamKind.CLOSE,
  55774. streamId
  55775. });
  55776. delete self.streamSinks[streamId];
  55777. },
  55778. error(reason) {
  55779. assert(reason instanceof Error, "error must have a valid reason");
  55780. if (this.isCancelled) {
  55781. return;
  55782. }
  55783. this.isCancelled = true;
  55784. comObj.postMessage({
  55785. sourceName,
  55786. targetName,
  55787. stream: StreamKind.ERROR,
  55788. streamId,
  55789. reason: wrapReason(reason)
  55790. });
  55791. },
  55792. sinkCapability: new PromiseCapability(),
  55793. onPull: null,
  55794. onCancel: null,
  55795. isCancelled: false,
  55796. desiredSize: data.desiredSize,
  55797. ready: null
  55798. };
  55799. streamSink.sinkCapability.resolve();
  55800. streamSink.ready = streamSink.sinkCapability.promise;
  55801. this.streamSinks[streamId] = streamSink;
  55802. new Promise(function (resolve) {
  55803. resolve(action(data.data, streamSink));
  55804. }).then(function () {
  55805. comObj.postMessage({
  55806. sourceName,
  55807. targetName,
  55808. stream: StreamKind.START_COMPLETE,
  55809. streamId,
  55810. success: true
  55811. });
  55812. }, function (reason) {
  55813. comObj.postMessage({
  55814. sourceName,
  55815. targetName,
  55816. stream: StreamKind.START_COMPLETE,
  55817. streamId,
  55818. reason: wrapReason(reason)
  55819. });
  55820. });
  55821. }
  55822. #processStreamMessage(data) {
  55823. const streamId = data.streamId,
  55824. sourceName = this.sourceName,
  55825. targetName = data.sourceName,
  55826. comObj = this.comObj;
  55827. const streamController = this.streamControllers[streamId],
  55828. streamSink = this.streamSinks[streamId];
  55829. switch (data.stream) {
  55830. case StreamKind.START_COMPLETE:
  55831. if (data.success) {
  55832. streamController.startCall.resolve();
  55833. } else {
  55834. streamController.startCall.reject(wrapReason(data.reason));
  55835. }
  55836. break;
  55837. case StreamKind.PULL_COMPLETE:
  55838. if (data.success) {
  55839. streamController.pullCall.resolve();
  55840. } else {
  55841. streamController.pullCall.reject(wrapReason(data.reason));
  55842. }
  55843. break;
  55844. case StreamKind.PULL:
  55845. if (!streamSink) {
  55846. comObj.postMessage({
  55847. sourceName,
  55848. targetName,
  55849. stream: StreamKind.PULL_COMPLETE,
  55850. streamId,
  55851. success: true
  55852. });
  55853. break;
  55854. }
  55855. if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
  55856. streamSink.sinkCapability.resolve();
  55857. }
  55858. streamSink.desiredSize = data.desiredSize;
  55859. new Promise(function (resolve) {
  55860. resolve(streamSink.onPull?.());
  55861. }).then(function () {
  55862. comObj.postMessage({
  55863. sourceName,
  55864. targetName,
  55865. stream: StreamKind.PULL_COMPLETE,
  55866. streamId,
  55867. success: true
  55868. });
  55869. }, function (reason) {
  55870. comObj.postMessage({
  55871. sourceName,
  55872. targetName,
  55873. stream: StreamKind.PULL_COMPLETE,
  55874. streamId,
  55875. reason: wrapReason(reason)
  55876. });
  55877. });
  55878. break;
  55879. case StreamKind.ENQUEUE:
  55880. assert(streamController, "enqueue should have stream controller");
  55881. if (streamController.isClosed) {
  55882. break;
  55883. }
  55884. streamController.controller.enqueue(data.chunk);
  55885. break;
  55886. case StreamKind.CLOSE:
  55887. assert(streamController, "close should have stream controller");
  55888. if (streamController.isClosed) {
  55889. break;
  55890. }
  55891. streamController.isClosed = true;
  55892. streamController.controller.close();
  55893. this.#deleteStreamController(streamController, streamId);
  55894. break;
  55895. case StreamKind.ERROR:
  55896. assert(streamController, "error should have stream controller");
  55897. streamController.controller.error(wrapReason(data.reason));
  55898. this.#deleteStreamController(streamController, streamId);
  55899. break;
  55900. case StreamKind.CANCEL_COMPLETE:
  55901. if (data.success) {
  55902. streamController.cancelCall.resolve();
  55903. } else {
  55904. streamController.cancelCall.reject(wrapReason(data.reason));
  55905. }
  55906. this.#deleteStreamController(streamController, streamId);
  55907. break;
  55908. case StreamKind.CANCEL:
  55909. if (!streamSink) {
  55910. break;
  55911. }
  55912. new Promise(function (resolve) {
  55913. resolve(streamSink.onCancel?.(wrapReason(data.reason)));
  55914. }).then(function () {
  55915. comObj.postMessage({
  55916. sourceName,
  55917. targetName,
  55918. stream: StreamKind.CANCEL_COMPLETE,
  55919. streamId,
  55920. success: true
  55921. });
  55922. }, function (reason) {
  55923. comObj.postMessage({
  55924. sourceName,
  55925. targetName,
  55926. stream: StreamKind.CANCEL_COMPLETE,
  55927. streamId,
  55928. reason: wrapReason(reason)
  55929. });
  55930. });
  55931. streamSink.sinkCapability.reject(wrapReason(data.reason));
  55932. streamSink.isCancelled = true;
  55933. delete this.streamSinks[streamId];
  55934. break;
  55935. default:
  55936. throw new Error("Unexpected stream case");
  55937. }
  55938. }
  55939. async #deleteStreamController(streamController, streamId) {
  55940. await Promise.allSettled([streamController.startCall?.promise, streamController.pullCall?.promise, streamController.cancelCall?.promise]);
  55941. delete this.streamControllers[streamId];
  55942. }
  55943. destroy() {
  55944. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  55945. }
  55946. }
  55947. ;// CONCATENATED MODULE: ./src/core/worker_stream.js
  55948. class PDFWorkerStream {
  55949. constructor(msgHandler) {
  55950. this._msgHandler = msgHandler;
  55951. this._contentLength = null;
  55952. this._fullRequestReader = null;
  55953. this._rangeRequestReaders = [];
  55954. }
  55955. getFullReader() {
  55956. assert(!this._fullRequestReader, "PDFWorkerStream.getFullReader can only be called once.");
  55957. this._fullRequestReader = new PDFWorkerStreamReader(this._msgHandler);
  55958. return this._fullRequestReader;
  55959. }
  55960. getRangeReader(begin, end) {
  55961. const reader = new PDFWorkerStreamRangeReader(begin, end, this._msgHandler);
  55962. this._rangeRequestReaders.push(reader);
  55963. return reader;
  55964. }
  55965. cancelAllRequests(reason) {
  55966. this._fullRequestReader?.cancel(reason);
  55967. for (const reader of this._rangeRequestReaders.slice(0)) {
  55968. reader.cancel(reason);
  55969. }
  55970. }
  55971. }
  55972. class PDFWorkerStreamReader {
  55973. constructor(msgHandler) {
  55974. this._msgHandler = msgHandler;
  55975. this.onProgress = null;
  55976. this._contentLength = null;
  55977. this._isRangeSupported = false;
  55978. this._isStreamingSupported = false;
  55979. const readableStream = this._msgHandler.sendWithStream("GetReader");
  55980. this._reader = readableStream.getReader();
  55981. this._headersReady = this._msgHandler.sendWithPromise("ReaderHeadersReady").then(data => {
  55982. this._isStreamingSupported = data.isStreamingSupported;
  55983. this._isRangeSupported = data.isRangeSupported;
  55984. this._contentLength = data.contentLength;
  55985. });
  55986. }
  55987. get headersReady() {
  55988. return this._headersReady;
  55989. }
  55990. get contentLength() {
  55991. return this._contentLength;
  55992. }
  55993. get isStreamingSupported() {
  55994. return this._isStreamingSupported;
  55995. }
  55996. get isRangeSupported() {
  55997. return this._isRangeSupported;
  55998. }
  55999. async read() {
  56000. const {
  56001. value,
  56002. done
  56003. } = await this._reader.read();
  56004. if (done) {
  56005. return {
  56006. value: undefined,
  56007. done: true
  56008. };
  56009. }
  56010. return {
  56011. value: value.buffer,
  56012. done: false
  56013. };
  56014. }
  56015. cancel(reason) {
  56016. this._reader.cancel(reason);
  56017. }
  56018. }
  56019. class PDFWorkerStreamRangeReader {
  56020. constructor(begin, end, msgHandler) {
  56021. this._msgHandler = msgHandler;
  56022. this.onProgress = null;
  56023. const readableStream = this._msgHandler.sendWithStream("GetRangeReader", {
  56024. begin,
  56025. end
  56026. });
  56027. this._reader = readableStream.getReader();
  56028. }
  56029. get isStreamingSupported() {
  56030. return false;
  56031. }
  56032. async read() {
  56033. const {
  56034. value,
  56035. done
  56036. } = await this._reader.read();
  56037. if (done) {
  56038. return {
  56039. value: undefined,
  56040. done: true
  56041. };
  56042. }
  56043. return {
  56044. value: value.buffer,
  56045. done: false
  56046. };
  56047. }
  56048. cancel(reason) {
  56049. this._reader.cancel(reason);
  56050. }
  56051. }
  56052. ;// CONCATENATED MODULE: ./src/core/worker.js
  56053. class WorkerTask {
  56054. constructor(name) {
  56055. this.name = name;
  56056. this.terminated = false;
  56057. this._capability = new PromiseCapability();
  56058. }
  56059. get finished() {
  56060. return this._capability.promise;
  56061. }
  56062. finish() {
  56063. this._capability.resolve();
  56064. }
  56065. terminate() {
  56066. this.terminated = true;
  56067. }
  56068. ensureNotTerminated() {
  56069. if (this.terminated) {
  56070. throw new Error("Worker task was terminated");
  56071. }
  56072. }
  56073. }
  56074. class WorkerMessageHandler {
  56075. static setup(handler, port) {
  56076. let testMessageProcessed = false;
  56077. handler.on("test", function (data) {
  56078. if (testMessageProcessed) {
  56079. return;
  56080. }
  56081. testMessageProcessed = true;
  56082. handler.send("test", data instanceof Uint8Array);
  56083. });
  56084. handler.on("configure", function (data) {
  56085. setVerbosityLevel(data.verbosity);
  56086. });
  56087. handler.on("GetDocRequest", function (data) {
  56088. return WorkerMessageHandler.createDocumentHandler(data, port);
  56089. });
  56090. }
  56091. static createDocumentHandler(docParams, port) {
  56092. let pdfManager;
  56093. let terminated = false;
  56094. let cancelXHRs = null;
  56095. const WorkerTasks = new Set();
  56096. const verbosity = getVerbosityLevel();
  56097. const {
  56098. docId,
  56099. apiVersion
  56100. } = docParams;
  56101. const workerVersion = '4.0.379';
  56102. if (apiVersion !== workerVersion) {
  56103. throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
  56104. }
  56105. const enumerableProperties = [];
  56106. for (const property in []) {
  56107. enumerableProperties.push(property);
  56108. }
  56109. if (enumerableProperties.length) {
  56110. throw new Error("The `Array.prototype` contains unexpected enumerable properties: " + enumerableProperties.join(", ") + "; thus breaking e.g. `for...in` iteration of `Array`s.");
  56111. }
  56112. const workerHandlerName = docId + "_worker";
  56113. let handler = new MessageHandler(workerHandlerName, docId, port);
  56114. function ensureNotTerminated() {
  56115. if (terminated) {
  56116. throw new Error("Worker was terminated");
  56117. }
  56118. }
  56119. function startWorkerTask(task) {
  56120. WorkerTasks.add(task);
  56121. }
  56122. function finishWorkerTask(task) {
  56123. task.finish();
  56124. WorkerTasks.delete(task);
  56125. }
  56126. async function loadDocument(recoveryMode) {
  56127. await pdfManager.ensureDoc("checkHeader");
  56128. await pdfManager.ensureDoc("parseStartXRef");
  56129. await pdfManager.ensureDoc("parse", [recoveryMode]);
  56130. await pdfManager.ensureDoc("checkFirstPage", [recoveryMode]);
  56131. await pdfManager.ensureDoc("checkLastPage", [recoveryMode]);
  56132. const isPureXfa = await pdfManager.ensureDoc("isPureXfa");
  56133. if (isPureXfa) {
  56134. const task = new WorkerTask("loadXfaFonts");
  56135. startWorkerTask(task);
  56136. await Promise.all([pdfManager.loadXfaFonts(handler, task).catch(reason => {}).then(() => finishWorkerTask(task)), pdfManager.loadXfaImages()]);
  56137. }
  56138. const [numPages, fingerprints] = await Promise.all([pdfManager.ensureDoc("numPages"), pdfManager.ensureDoc("fingerprints")]);
  56139. const htmlForXfa = isPureXfa ? await pdfManager.ensureDoc("htmlForXfa") : null;
  56140. return {
  56141. numPages,
  56142. fingerprints,
  56143. htmlForXfa
  56144. };
  56145. }
  56146. function getPdfManager({
  56147. data,
  56148. password,
  56149. disableAutoFetch,
  56150. rangeChunkSize,
  56151. length,
  56152. docBaseUrl,
  56153. enableXfa,
  56154. evaluatorOptions
  56155. }) {
  56156. const pdfManagerArgs = {
  56157. source: null,
  56158. disableAutoFetch,
  56159. docBaseUrl,
  56160. docId,
  56161. enableXfa,
  56162. evaluatorOptions,
  56163. handler,
  56164. length,
  56165. password,
  56166. rangeChunkSize
  56167. };
  56168. const pdfManagerCapability = new PromiseCapability();
  56169. let newPdfManager;
  56170. if (data) {
  56171. try {
  56172. pdfManagerArgs.source = data;
  56173. newPdfManager = new LocalPdfManager(pdfManagerArgs);
  56174. pdfManagerCapability.resolve(newPdfManager);
  56175. } catch (ex) {
  56176. pdfManagerCapability.reject(ex);
  56177. }
  56178. return pdfManagerCapability.promise;
  56179. }
  56180. let pdfStream,
  56181. cachedChunks = [];
  56182. try {
  56183. pdfStream = new PDFWorkerStream(handler);
  56184. } catch (ex) {
  56185. pdfManagerCapability.reject(ex);
  56186. return pdfManagerCapability.promise;
  56187. }
  56188. const fullRequest = pdfStream.getFullReader();
  56189. fullRequest.headersReady.then(function () {
  56190. if (!fullRequest.isRangeSupported) {
  56191. return;
  56192. }
  56193. pdfManagerArgs.source = pdfStream;
  56194. pdfManagerArgs.length = fullRequest.contentLength;
  56195. pdfManagerArgs.disableAutoFetch ||= fullRequest.isStreamingSupported;
  56196. newPdfManager = new NetworkPdfManager(pdfManagerArgs);
  56197. for (const chunk of cachedChunks) {
  56198. newPdfManager.sendProgressiveData(chunk);
  56199. }
  56200. cachedChunks = [];
  56201. pdfManagerCapability.resolve(newPdfManager);
  56202. cancelXHRs = null;
  56203. }).catch(function (reason) {
  56204. pdfManagerCapability.reject(reason);
  56205. cancelXHRs = null;
  56206. });
  56207. let loaded = 0;
  56208. const flushChunks = function () {
  56209. const pdfFile = arrayBuffersToBytes(cachedChunks);
  56210. if (length && pdfFile.length !== length) {
  56211. warn("reported HTTP length is different from actual");
  56212. }
  56213. try {
  56214. pdfManagerArgs.source = pdfFile;
  56215. newPdfManager = new LocalPdfManager(pdfManagerArgs);
  56216. pdfManagerCapability.resolve(newPdfManager);
  56217. } catch (ex) {
  56218. pdfManagerCapability.reject(ex);
  56219. }
  56220. cachedChunks = [];
  56221. };
  56222. new Promise(function (resolve, reject) {
  56223. const readChunk = function ({
  56224. value,
  56225. done
  56226. }) {
  56227. try {
  56228. ensureNotTerminated();
  56229. if (done) {
  56230. if (!newPdfManager) {
  56231. flushChunks();
  56232. }
  56233. cancelXHRs = null;
  56234. return;
  56235. }
  56236. loaded += value.byteLength;
  56237. if (!fullRequest.isStreamingSupported) {
  56238. handler.send("DocProgress", {
  56239. loaded,
  56240. total: Math.max(loaded, fullRequest.contentLength || 0)
  56241. });
  56242. }
  56243. if (newPdfManager) {
  56244. newPdfManager.sendProgressiveData(value);
  56245. } else {
  56246. cachedChunks.push(value);
  56247. }
  56248. fullRequest.read().then(readChunk, reject);
  56249. } catch (e) {
  56250. reject(e);
  56251. }
  56252. };
  56253. fullRequest.read().then(readChunk, reject);
  56254. }).catch(function (e) {
  56255. pdfManagerCapability.reject(e);
  56256. cancelXHRs = null;
  56257. });
  56258. cancelXHRs = function (reason) {
  56259. pdfStream.cancelAllRequests(reason);
  56260. };
  56261. return pdfManagerCapability.promise;
  56262. }
  56263. function setupDoc(data) {
  56264. function onSuccess(doc) {
  56265. ensureNotTerminated();
  56266. handler.send("GetDoc", {
  56267. pdfInfo: doc
  56268. });
  56269. }
  56270. function onFailure(ex) {
  56271. ensureNotTerminated();
  56272. if (ex instanceof PasswordException) {
  56273. const task = new WorkerTask(`PasswordException: response ${ex.code}`);
  56274. startWorkerTask(task);
  56275. handler.sendWithPromise("PasswordRequest", ex).then(function ({
  56276. password
  56277. }) {
  56278. finishWorkerTask(task);
  56279. pdfManager.updatePassword(password);
  56280. pdfManagerReady();
  56281. }).catch(function () {
  56282. finishWorkerTask(task);
  56283. handler.send("DocException", ex);
  56284. });
  56285. } else if (ex instanceof InvalidPDFException || ex instanceof MissingPDFException || ex instanceof UnexpectedResponseException || ex instanceof UnknownErrorException) {
  56286. handler.send("DocException", ex);
  56287. } else {
  56288. handler.send("DocException", new UnknownErrorException(ex.message, ex.toString()));
  56289. }
  56290. }
  56291. function pdfManagerReady() {
  56292. ensureNotTerminated();
  56293. loadDocument(false).then(onSuccess, function (reason) {
  56294. ensureNotTerminated();
  56295. if (!(reason instanceof XRefParseException)) {
  56296. onFailure(reason);
  56297. return;
  56298. }
  56299. pdfManager.requestLoadedStream().then(function () {
  56300. ensureNotTerminated();
  56301. loadDocument(true).then(onSuccess, onFailure);
  56302. });
  56303. });
  56304. }
  56305. ensureNotTerminated();
  56306. getPdfManager(data).then(function (newPdfManager) {
  56307. if (terminated) {
  56308. newPdfManager.terminate(new AbortException("Worker was terminated."));
  56309. throw new Error("Worker was terminated");
  56310. }
  56311. pdfManager = newPdfManager;
  56312. pdfManager.requestLoadedStream(true).then(stream => {
  56313. handler.send("DataLoaded", {
  56314. length: stream.bytes.byteLength
  56315. });
  56316. });
  56317. }).then(pdfManagerReady, onFailure);
  56318. }
  56319. handler.on("GetPage", function (data) {
  56320. return pdfManager.getPage(data.pageIndex).then(function (page) {
  56321. return Promise.all([pdfManager.ensure(page, "rotate"), pdfManager.ensure(page, "ref"), pdfManager.ensure(page, "userUnit"), pdfManager.ensure(page, "view")]).then(function ([rotate, ref, userUnit, view]) {
  56322. return {
  56323. rotate,
  56324. ref,
  56325. userUnit,
  56326. view
  56327. };
  56328. });
  56329. });
  56330. });
  56331. handler.on("GetPageIndex", function (data) {
  56332. const pageRef = Ref.get(data.num, data.gen);
  56333. return pdfManager.ensureCatalog("getPageIndex", [pageRef]);
  56334. });
  56335. handler.on("GetDestinations", function (data) {
  56336. return pdfManager.ensureCatalog("destinations");
  56337. });
  56338. handler.on("GetDestination", function (data) {
  56339. return pdfManager.ensureCatalog("getDestination", [data.id]);
  56340. });
  56341. handler.on("GetPageLabels", function (data) {
  56342. return pdfManager.ensureCatalog("pageLabels");
  56343. });
  56344. handler.on("GetPageLayout", function (data) {
  56345. return pdfManager.ensureCatalog("pageLayout");
  56346. });
  56347. handler.on("GetPageMode", function (data) {
  56348. return pdfManager.ensureCatalog("pageMode");
  56349. });
  56350. handler.on("GetViewerPreferences", function (data) {
  56351. return pdfManager.ensureCatalog("viewerPreferences");
  56352. });
  56353. handler.on("GetOpenAction", function (data) {
  56354. return pdfManager.ensureCatalog("openAction");
  56355. });
  56356. handler.on("GetAttachments", function (data) {
  56357. return pdfManager.ensureCatalog("attachments");
  56358. });
  56359. handler.on("GetDocJSActions", function (data) {
  56360. return pdfManager.ensureCatalog("jsActions");
  56361. });
  56362. handler.on("GetPageJSActions", function ({
  56363. pageIndex
  56364. }) {
  56365. return pdfManager.getPage(pageIndex).then(function (page) {
  56366. return pdfManager.ensure(page, "jsActions");
  56367. });
  56368. });
  56369. handler.on("GetOutline", function (data) {
  56370. return pdfManager.ensureCatalog("documentOutline");
  56371. });
  56372. handler.on("GetOptionalContentConfig", function (data) {
  56373. return pdfManager.ensureCatalog("optionalContentConfig");
  56374. });
  56375. handler.on("GetPermissions", function (data) {
  56376. return pdfManager.ensureCatalog("permissions");
  56377. });
  56378. handler.on("GetMetadata", function (data) {
  56379. return Promise.all([pdfManager.ensureDoc("documentInfo"), pdfManager.ensureCatalog("metadata")]);
  56380. });
  56381. handler.on("GetMarkInfo", function (data) {
  56382. return pdfManager.ensureCatalog("markInfo");
  56383. });
  56384. handler.on("GetData", function (data) {
  56385. return pdfManager.requestLoadedStream().then(function (stream) {
  56386. return stream.bytes;
  56387. });
  56388. });
  56389. handler.on("GetAnnotations", function ({
  56390. pageIndex,
  56391. intent
  56392. }) {
  56393. return pdfManager.getPage(pageIndex).then(function (page) {
  56394. const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`);
  56395. startWorkerTask(task);
  56396. return page.getAnnotationsData(handler, task, intent).then(data => {
  56397. finishWorkerTask(task);
  56398. return data;
  56399. }, reason => {
  56400. finishWorkerTask(task);
  56401. throw reason;
  56402. });
  56403. });
  56404. });
  56405. handler.on("GetFieldObjects", function (data) {
  56406. return pdfManager.ensureDoc("fieldObjects");
  56407. });
  56408. handler.on("HasJSActions", function (data) {
  56409. return pdfManager.ensureDoc("hasJSActions");
  56410. });
  56411. handler.on("GetCalculationOrderIds", function (data) {
  56412. return pdfManager.ensureDoc("calculationOrderIds");
  56413. });
  56414. handler.on("SaveDocument", async function ({
  56415. isPureXfa,
  56416. numPages,
  56417. annotationStorage,
  56418. filename
  56419. }) {
  56420. const globalPromises = [pdfManager.requestLoadedStream(), pdfManager.ensureCatalog("acroForm"), pdfManager.ensureCatalog("acroFormRef"), pdfManager.ensureDoc("startXRef"), pdfManager.ensureDoc("xref"), pdfManager.ensureDoc("linearization"), pdfManager.ensureCatalog("structTreeRoot")];
  56421. const promises = [];
  56422. const newAnnotationsByPage = !isPureXfa ? getNewAnnotationsMap(annotationStorage) : null;
  56423. const [stream, acroForm, acroFormRef, startXRef, xref, linearization, _structTreeRoot] = await Promise.all(globalPromises);
  56424. const catalogRef = xref.trailer.getRaw("Root") || null;
  56425. let structTreeRoot;
  56426. if (newAnnotationsByPage) {
  56427. if (!_structTreeRoot) {
  56428. if (await StructTreeRoot.canCreateStructureTree({
  56429. catalogRef,
  56430. pdfManager,
  56431. newAnnotationsByPage
  56432. })) {
  56433. structTreeRoot = null;
  56434. }
  56435. } else if (await _structTreeRoot.canUpdateStructTree({
  56436. pdfManager,
  56437. xref,
  56438. newAnnotationsByPage
  56439. })) {
  56440. structTreeRoot = _structTreeRoot;
  56441. }
  56442. const imagePromises = AnnotationFactory.generateImages(annotationStorage.values(), xref, pdfManager.evaluatorOptions.isOffscreenCanvasSupported);
  56443. const newAnnotationPromises = structTreeRoot === undefined ? promises : [];
  56444. for (const [pageIndex, annotations] of newAnnotationsByPage) {
  56445. newAnnotationPromises.push(pdfManager.getPage(pageIndex).then(page => {
  56446. const task = new WorkerTask(`Save (editor): page ${pageIndex}`);
  56447. return page.saveNewAnnotations(handler, task, annotations, imagePromises).finally(function () {
  56448. finishWorkerTask(task);
  56449. });
  56450. }));
  56451. }
  56452. if (structTreeRoot === null) {
  56453. promises.push(Promise.all(newAnnotationPromises).then(async newRefs => {
  56454. await StructTreeRoot.createStructureTree({
  56455. newAnnotationsByPage,
  56456. xref,
  56457. catalogRef,
  56458. pdfManager,
  56459. newRefs
  56460. });
  56461. return newRefs;
  56462. }));
  56463. } else if (structTreeRoot) {
  56464. promises.push(Promise.all(newAnnotationPromises).then(async newRefs => {
  56465. await structTreeRoot.updateStructureTree({
  56466. newAnnotationsByPage,
  56467. pdfManager,
  56468. newRefs
  56469. });
  56470. return newRefs;
  56471. }));
  56472. }
  56473. }
  56474. if (isPureXfa) {
  56475. promises.push(pdfManager.serializeXfaData(annotationStorage));
  56476. } else {
  56477. for (let pageIndex = 0; pageIndex < numPages; pageIndex++) {
  56478. promises.push(pdfManager.getPage(pageIndex).then(function (page) {
  56479. const task = new WorkerTask(`Save: page ${pageIndex}`);
  56480. return page.save(handler, task, annotationStorage).finally(function () {
  56481. finishWorkerTask(task);
  56482. });
  56483. }));
  56484. }
  56485. }
  56486. const refs = await Promise.all(promises);
  56487. let newRefs = [];
  56488. let xfaData = null;
  56489. if (isPureXfa) {
  56490. xfaData = refs[0];
  56491. if (!xfaData) {
  56492. return stream.bytes;
  56493. }
  56494. } else {
  56495. newRefs = refs.flat(2);
  56496. if (newRefs.length === 0) {
  56497. return stream.bytes;
  56498. }
  56499. }
  56500. const needAppearances = acroFormRef && acroForm instanceof Dict && newRefs.some(ref => ref.needAppearances);
  56501. const xfa = acroForm instanceof Dict && acroForm.get("XFA") || null;
  56502. let xfaDatasetsRef = null;
  56503. let hasXfaDatasetsEntry = false;
  56504. if (Array.isArray(xfa)) {
  56505. for (let i = 0, ii = xfa.length; i < ii; i += 2) {
  56506. if (xfa[i] === "datasets") {
  56507. xfaDatasetsRef = xfa[i + 1];
  56508. hasXfaDatasetsEntry = true;
  56509. }
  56510. }
  56511. if (xfaDatasetsRef === null) {
  56512. xfaDatasetsRef = xref.getNewTemporaryRef();
  56513. }
  56514. } else if (xfa) {
  56515. warn("Unsupported XFA type.");
  56516. }
  56517. let newXrefInfo = Object.create(null);
  56518. if (xref.trailer) {
  56519. const infoObj = Object.create(null);
  56520. const xrefInfo = xref.trailer.get("Info") || null;
  56521. if (xrefInfo instanceof Dict) {
  56522. xrefInfo.forEach((key, value) => {
  56523. if (typeof value === "string") {
  56524. infoObj[key] = stringToPDFString(value);
  56525. }
  56526. });
  56527. }
  56528. newXrefInfo = {
  56529. rootRef: catalogRef,
  56530. encryptRef: xref.trailer.getRaw("Encrypt") || null,
  56531. newRef: xref.getNewTemporaryRef(),
  56532. infoRef: xref.trailer.getRaw("Info") || null,
  56533. info: infoObj,
  56534. fileIds: xref.trailer.get("ID") || null,
  56535. startXRef: linearization ? startXRef : xref.lastXRefStreamPos ?? startXRef,
  56536. filename
  56537. };
  56538. }
  56539. return incrementalUpdate({
  56540. originalData: stream.bytes,
  56541. xrefInfo: newXrefInfo,
  56542. newRefs,
  56543. xref,
  56544. hasXfa: !!xfa,
  56545. xfaDatasetsRef,
  56546. hasXfaDatasetsEntry,
  56547. needAppearances,
  56548. acroFormRef,
  56549. acroForm,
  56550. xfaData
  56551. }).finally(() => {
  56552. xref.resetNewTemporaryRef();
  56553. });
  56554. });
  56555. handler.on("GetOperatorList", function (data, sink) {
  56556. const pageIndex = data.pageIndex;
  56557. pdfManager.getPage(pageIndex).then(function (page) {
  56558. const task = new WorkerTask(`GetOperatorList: page ${pageIndex}`);
  56559. startWorkerTask(task);
  56560. const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
  56561. page.getOperatorList({
  56562. handler,
  56563. sink,
  56564. task,
  56565. intent: data.intent,
  56566. cacheKey: data.cacheKey,
  56567. annotationStorage: data.annotationStorage
  56568. }).then(function (operatorListInfo) {
  56569. finishWorkerTask(task);
  56570. if (start) {
  56571. info(`page=${pageIndex + 1} - getOperatorList: time=` + `${Date.now() - start}ms, len=${operatorListInfo.length}`);
  56572. }
  56573. sink.close();
  56574. }, function (reason) {
  56575. finishWorkerTask(task);
  56576. if (task.terminated) {
  56577. return;
  56578. }
  56579. sink.error(reason);
  56580. });
  56581. });
  56582. });
  56583. handler.on("GetTextContent", function (data, sink) {
  56584. const {
  56585. pageIndex,
  56586. includeMarkedContent,
  56587. disableNormalization
  56588. } = data;
  56589. pdfManager.getPage(pageIndex).then(function (page) {
  56590. const task = new WorkerTask("GetTextContent: page " + pageIndex);
  56591. startWorkerTask(task);
  56592. const start = verbosity >= VerbosityLevel.INFOS ? Date.now() : 0;
  56593. page.extractTextContent({
  56594. handler,
  56595. task,
  56596. sink,
  56597. includeMarkedContent,
  56598. disableNormalization
  56599. }).then(function () {
  56600. finishWorkerTask(task);
  56601. if (start) {
  56602. info(`page=${pageIndex + 1} - getTextContent: time=` + `${Date.now() - start}ms`);
  56603. }
  56604. sink.close();
  56605. }, function (reason) {
  56606. finishWorkerTask(task);
  56607. if (task.terminated) {
  56608. return;
  56609. }
  56610. sink.error(reason);
  56611. });
  56612. });
  56613. });
  56614. handler.on("GetStructTree", function (data) {
  56615. return pdfManager.getPage(data.pageIndex).then(function (page) {
  56616. return pdfManager.ensure(page, "getStructTree");
  56617. });
  56618. });
  56619. handler.on("FontFallback", function (data) {
  56620. return pdfManager.fontFallback(data.id, handler);
  56621. });
  56622. handler.on("Cleanup", function (data) {
  56623. return pdfManager.cleanup(true);
  56624. });
  56625. handler.on("Terminate", function (data) {
  56626. terminated = true;
  56627. const waitOn = [];
  56628. if (pdfManager) {
  56629. pdfManager.terminate(new AbortException("Worker was terminated."));
  56630. const cleanupPromise = pdfManager.cleanup();
  56631. waitOn.push(cleanupPromise);
  56632. pdfManager = null;
  56633. } else {
  56634. clearGlobalCaches();
  56635. }
  56636. if (cancelXHRs) {
  56637. cancelXHRs(new AbortException("Worker was terminated."));
  56638. }
  56639. for (const task of WorkerTasks) {
  56640. waitOn.push(task.finished);
  56641. task.terminate();
  56642. }
  56643. return Promise.all(waitOn).then(function () {
  56644. handler.destroy();
  56645. handler = null;
  56646. });
  56647. });
  56648. handler.on("Ready", function (data) {
  56649. setupDoc(docParams);
  56650. docParams = null;
  56651. });
  56652. return workerHandlerName;
  56653. }
  56654. static initializeFromPort(port) {
  56655. const handler = new MessageHandler("worker", "main", port);
  56656. WorkerMessageHandler.setup(handler, port);
  56657. handler.send("ready", null);
  56658. }
  56659. }
  56660. function isMessagePort(maybePort) {
  56661. return typeof maybePort.postMessage === "function" && "onmessage" in maybePort;
  56662. }
  56663. if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" && isMessagePort(self)) {
  56664. WorkerMessageHandler.initializeFromPort(self);
  56665. }
  56666. ;// CONCATENATED MODULE: ./src/pdf.worker.js
  56667. const pdfjsVersion = '4.0.379';
  56668. const pdfjsBuild = '9e14d04fd';
  56669. var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler;
  56670. export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler };
  56671. //# sourceMappingURL=pdf.worker.mjs.map