pdf.js 376 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/build/pdf", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/build/pdf"] = factory();
  29. else
  30. root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
  31. })(this, function() {
  32. return /******/ (function(modules) { // webpackBootstrap
  33. /******/ // The module cache
  34. /******/ var installedModules = {};
  35. /******/
  36. /******/ // The require function
  37. /******/ function __w_pdfjs_require__(moduleId) {
  38. /******/
  39. /******/ // Check if module is in cache
  40. /******/ if(installedModules[moduleId]) {
  41. /******/ return installedModules[moduleId].exports;
  42. /******/ }
  43. /******/ // Create a new module (and put it into the cache)
  44. /******/ var module = installedModules[moduleId] = {
  45. /******/ i: moduleId,
  46. /******/ l: false,
  47. /******/ exports: {}
  48. /******/ };
  49. /******/
  50. /******/ // Execute the module function
  51. /******/ modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
  52. /******/
  53. /******/ // Flag the module as loaded
  54. /******/ module.l = true;
  55. /******/
  56. /******/ // Return the exports of the module
  57. /******/ return module.exports;
  58. /******/ }
  59. /******/
  60. /******/
  61. /******/ // expose the modules object (__webpack_modules__)
  62. /******/ __w_pdfjs_require__.m = modules;
  63. /******/
  64. /******/ // expose the module cache
  65. /******/ __w_pdfjs_require__.c = installedModules;
  66. /******/
  67. /******/ // define getter function for harmony exports
  68. /******/ __w_pdfjs_require__.d = function(exports, name, getter) {
  69. /******/ if(!__w_pdfjs_require__.o(exports, name)) {
  70. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  71. /******/ }
  72. /******/ };
  73. /******/
  74. /******/ // define __esModule on exports
  75. /******/ __w_pdfjs_require__.r = function(exports) {
  76. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  77. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  78. /******/ }
  79. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  80. /******/ };
  81. /******/
  82. /******/ // create a fake namespace object
  83. /******/ // mode & 1: value is a module id, require it
  84. /******/ // mode & 2: merge all properties of value into the ns
  85. /******/ // mode & 4: return value when already ns object
  86. /******/ // mode & 8|1: behave like require
  87. /******/ __w_pdfjs_require__.t = function(value, mode) {
  88. /******/ if(mode & 1) value = __w_pdfjs_require__(value);
  89. /******/ if(mode & 8) return value;
  90. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  91. /******/ var ns = Object.create(null);
  92. /******/ __w_pdfjs_require__.r(ns);
  93. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  94. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __w_pdfjs_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  95. /******/ return ns;
  96. /******/ };
  97. /******/
  98. /******/ // getDefaultExport function for compatibility with non-harmony modules
  99. /******/ __w_pdfjs_require__.n = function(module) {
  100. /******/ var getter = module && module.__esModule ?
  101. /******/ function getDefault() { return module['default']; } :
  102. /******/ function getModuleExports() { return module; };
  103. /******/ __w_pdfjs_require__.d(getter, 'a', getter);
  104. /******/ return getter;
  105. /******/ };
  106. /******/
  107. /******/ // Object.prototype.hasOwnProperty.call
  108. /******/ __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  109. /******/
  110. /******/ // __webpack_public_path__
  111. /******/ __w_pdfjs_require__.p = "";
  112. /******/
  113. /******/
  114. /******/ // Load entry module and return exports
  115. /******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 0);
  116. /******/ })
  117. /************************************************************************/
  118. /******/ ([
  119. /* 0 */
  120. /***/ (function(module, exports, __w_pdfjs_require__) {
  121. "use strict";
  122. Object.defineProperty(exports, "__esModule", {
  123. value: true
  124. });
  125. Object.defineProperty(exports, "addLinkAttributes", {
  126. enumerable: true,
  127. get: function () {
  128. return _display_utils.addLinkAttributes;
  129. }
  130. });
  131. Object.defineProperty(exports, "getFilenameFromUrl", {
  132. enumerable: true,
  133. get: function () {
  134. return _display_utils.getFilenameFromUrl;
  135. }
  136. });
  137. Object.defineProperty(exports, "LinkTarget", {
  138. enumerable: true,
  139. get: function () {
  140. return _display_utils.LinkTarget;
  141. }
  142. });
  143. Object.defineProperty(exports, "loadScript", {
  144. enumerable: true,
  145. get: function () {
  146. return _display_utils.loadScript;
  147. }
  148. });
  149. Object.defineProperty(exports, "PDFDateString", {
  150. enumerable: true,
  151. get: function () {
  152. return _display_utils.PDFDateString;
  153. }
  154. });
  155. Object.defineProperty(exports, "RenderingCancelledException", {
  156. enumerable: true,
  157. get: function () {
  158. return _display_utils.RenderingCancelledException;
  159. }
  160. });
  161. Object.defineProperty(exports, "build", {
  162. enumerable: true,
  163. get: function () {
  164. return _api.build;
  165. }
  166. });
  167. Object.defineProperty(exports, "getDocument", {
  168. enumerable: true,
  169. get: function () {
  170. return _api.getDocument;
  171. }
  172. });
  173. Object.defineProperty(exports, "LoopbackPort", {
  174. enumerable: true,
  175. get: function () {
  176. return _api.LoopbackPort;
  177. }
  178. });
  179. Object.defineProperty(exports, "PDFDataRangeTransport", {
  180. enumerable: true,
  181. get: function () {
  182. return _api.PDFDataRangeTransport;
  183. }
  184. });
  185. Object.defineProperty(exports, "PDFWorker", {
  186. enumerable: true,
  187. get: function () {
  188. return _api.PDFWorker;
  189. }
  190. });
  191. Object.defineProperty(exports, "version", {
  192. enumerable: true,
  193. get: function () {
  194. return _api.version;
  195. }
  196. });
  197. Object.defineProperty(exports, "CMapCompressionType", {
  198. enumerable: true,
  199. get: function () {
  200. return _util.CMapCompressionType;
  201. }
  202. });
  203. Object.defineProperty(exports, "createObjectURL", {
  204. enumerable: true,
  205. get: function () {
  206. return _util.createObjectURL;
  207. }
  208. });
  209. Object.defineProperty(exports, "createPromiseCapability", {
  210. enumerable: true,
  211. get: function () {
  212. return _util.createPromiseCapability;
  213. }
  214. });
  215. Object.defineProperty(exports, "createValidAbsoluteUrl", {
  216. enumerable: true,
  217. get: function () {
  218. return _util.createValidAbsoluteUrl;
  219. }
  220. });
  221. Object.defineProperty(exports, "InvalidPDFException", {
  222. enumerable: true,
  223. get: function () {
  224. return _util.InvalidPDFException;
  225. }
  226. });
  227. Object.defineProperty(exports, "MissingPDFException", {
  228. enumerable: true,
  229. get: function () {
  230. return _util.MissingPDFException;
  231. }
  232. });
  233. Object.defineProperty(exports, "OPS", {
  234. enumerable: true,
  235. get: function () {
  236. return _util.OPS;
  237. }
  238. });
  239. Object.defineProperty(exports, "PasswordResponses", {
  240. enumerable: true,
  241. get: function () {
  242. return _util.PasswordResponses;
  243. }
  244. });
  245. Object.defineProperty(exports, "PermissionFlag", {
  246. enumerable: true,
  247. get: function () {
  248. return _util.PermissionFlag;
  249. }
  250. });
  251. Object.defineProperty(exports, "removeNullCharacters", {
  252. enumerable: true,
  253. get: function () {
  254. return _util.removeNullCharacters;
  255. }
  256. });
  257. Object.defineProperty(exports, "shadow", {
  258. enumerable: true,
  259. get: function () {
  260. return _util.shadow;
  261. }
  262. });
  263. Object.defineProperty(exports, "UnexpectedResponseException", {
  264. enumerable: true,
  265. get: function () {
  266. return _util.UnexpectedResponseException;
  267. }
  268. });
  269. Object.defineProperty(exports, "UNSUPPORTED_FEATURES", {
  270. enumerable: true,
  271. get: function () {
  272. return _util.UNSUPPORTED_FEATURES;
  273. }
  274. });
  275. Object.defineProperty(exports, "Util", {
  276. enumerable: true,
  277. get: function () {
  278. return _util.Util;
  279. }
  280. });
  281. Object.defineProperty(exports, "VerbosityLevel", {
  282. enumerable: true,
  283. get: function () {
  284. return _util.VerbosityLevel;
  285. }
  286. });
  287. Object.defineProperty(exports, "AnnotationLayer", {
  288. enumerable: true,
  289. get: function () {
  290. return _annotation_layer.AnnotationLayer;
  291. }
  292. });
  293. Object.defineProperty(exports, "apiCompatibilityParams", {
  294. enumerable: true,
  295. get: function () {
  296. return _api_compatibility.apiCompatibilityParams;
  297. }
  298. });
  299. Object.defineProperty(exports, "GlobalWorkerOptions", {
  300. enumerable: true,
  301. get: function () {
  302. return _worker_options.GlobalWorkerOptions;
  303. }
  304. });
  305. Object.defineProperty(exports, "renderTextLayer", {
  306. enumerable: true,
  307. get: function () {
  308. return _text_layer.renderTextLayer;
  309. }
  310. });
  311. Object.defineProperty(exports, "SVGGraphics", {
  312. enumerable: true,
  313. get: function () {
  314. return _svg.SVGGraphics;
  315. }
  316. });
  317. var _display_utils = __w_pdfjs_require__(1);
  318. var _api = __w_pdfjs_require__(5);
  319. var _util = __w_pdfjs_require__(2);
  320. var _annotation_layer = __w_pdfjs_require__(19);
  321. var _api_compatibility = __w_pdfjs_require__(9);
  322. var _worker_options = __w_pdfjs_require__(12);
  323. var _text_layer = __w_pdfjs_require__(20);
  324. var _svg = __w_pdfjs_require__(21);
  325. const pdfjsVersion = '2.6.347';
  326. const pdfjsBuild = '3be9c65f';
  327. {
  328. const {
  329. isNodeJS
  330. } = __w_pdfjs_require__(4);
  331. if (isNodeJS) {
  332. const PDFNodeStream = __w_pdfjs_require__(22).PDFNodeStream;
  333. (0, _api.setPDFNetworkStreamFactory)(params => {
  334. return new PDFNodeStream(params);
  335. });
  336. } else {
  337. const PDFNetworkStream = __w_pdfjs_require__(25).PDFNetworkStream;
  338. let PDFFetchStream;
  339. if ((0, _display_utils.isFetchSupported)()) {
  340. PDFFetchStream = __w_pdfjs_require__(26).PDFFetchStream;
  341. }
  342. (0, _api.setPDFNetworkStreamFactory)(params => {
  343. if (PDFFetchStream && (0, _display_utils.isValidFetchUrl)(params.url)) {
  344. return new PDFFetchStream(params);
  345. }
  346. return new PDFNetworkStream(params);
  347. });
  348. }
  349. }
  350. /***/ }),
  351. /* 1 */
  352. /***/ (function(module, exports, __w_pdfjs_require__) {
  353. "use strict";
  354. Object.defineProperty(exports, "__esModule", {
  355. value: true
  356. });
  357. exports.addLinkAttributes = addLinkAttributes;
  358. exports.getFilenameFromUrl = getFilenameFromUrl;
  359. exports.isFetchSupported = isFetchSupported;
  360. exports.isValidFetchUrl = isValidFetchUrl;
  361. exports.loadScript = loadScript;
  362. exports.deprecated = deprecated;
  363. exports.PDFDateString = exports.StatTimer = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.BaseCMapReaderFactory = exports.DOMCanvasFactory = exports.BaseCanvasFactory = exports.DEFAULT_LINK_REL = exports.LinkTarget = exports.RenderingCancelledException = exports.PageViewport = void 0;
  364. var _util = __w_pdfjs_require__(2);
  365. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  366. exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
  367. const SVG_NS = "http://www.w3.org/2000/svg";
  368. class BaseCanvasFactory {
  369. constructor() {
  370. if (this.constructor === BaseCanvasFactory) {
  371. (0, _util.unreachable)("Cannot initialize BaseCanvasFactory.");
  372. }
  373. }
  374. create(width, height) {
  375. (0, _util.unreachable)("Abstract method `create` called.");
  376. }
  377. reset(canvasAndContext, width, height) {
  378. if (!canvasAndContext.canvas) {
  379. throw new Error("Canvas is not specified");
  380. }
  381. if (width <= 0 || height <= 0) {
  382. throw new Error("Invalid canvas size");
  383. }
  384. canvasAndContext.canvas.width = width;
  385. canvasAndContext.canvas.height = height;
  386. }
  387. destroy(canvasAndContext) {
  388. if (!canvasAndContext.canvas) {
  389. throw new Error("Canvas is not specified");
  390. }
  391. canvasAndContext.canvas.width = 0;
  392. canvasAndContext.canvas.height = 0;
  393. canvasAndContext.canvas = null;
  394. canvasAndContext.context = null;
  395. }
  396. }
  397. exports.BaseCanvasFactory = BaseCanvasFactory;
  398. class DOMCanvasFactory extends BaseCanvasFactory {
  399. constructor({
  400. ownerDocument = globalThis.document
  401. } = {}) {
  402. super();
  403. this._document = ownerDocument;
  404. }
  405. create(width, height) {
  406. if (width <= 0 || height <= 0) {
  407. throw new Error("Invalid canvas size");
  408. }
  409. const canvas = this._document.createElement("canvas");
  410. const context = canvas.getContext("2d");
  411. canvas.width = width;
  412. canvas.height = height;
  413. return {
  414. canvas,
  415. context
  416. };
  417. }
  418. }
  419. exports.DOMCanvasFactory = DOMCanvasFactory;
  420. class BaseCMapReaderFactory {
  421. constructor({
  422. baseUrl = null,
  423. isCompressed = false
  424. }) {
  425. if (this.constructor === BaseCMapReaderFactory) {
  426. (0, _util.unreachable)("Cannot initialize BaseCMapReaderFactory.");
  427. }
  428. this.baseUrl = baseUrl;
  429. this.isCompressed = isCompressed;
  430. }
  431. async fetch({
  432. name
  433. }) {
  434. if (!this.baseUrl) {
  435. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  436. }
  437. if (!name) {
  438. throw new Error("CMap name must be specified.");
  439. }
  440. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  441. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  442. return this._fetchData(url, compressionType).catch(reason => {
  443. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
  444. });
  445. }
  446. _fetchData(url, compressionType) {
  447. (0, _util.unreachable)("Abstract method `_fetchData` called.");
  448. }
  449. }
  450. exports.BaseCMapReaderFactory = BaseCMapReaderFactory;
  451. class DOMCMapReaderFactory extends BaseCMapReaderFactory {
  452. _fetchData(url, compressionType) {
  453. if (isFetchSupported() && isValidFetchUrl(url, document.baseURI)) {
  454. return fetch(url).then(async response => {
  455. if (!response.ok) {
  456. throw new Error(response.statusText);
  457. }
  458. let cMapData;
  459. if (this.isCompressed) {
  460. cMapData = new Uint8Array(await response.arrayBuffer());
  461. } else {
  462. cMapData = (0, _util.stringToBytes)(await response.text());
  463. }
  464. return {
  465. cMapData,
  466. compressionType
  467. };
  468. });
  469. }
  470. return new Promise((resolve, reject) => {
  471. const request = new XMLHttpRequest();
  472. request.open("GET", url, true);
  473. if (this.isCompressed) {
  474. request.responseType = "arraybuffer";
  475. }
  476. request.onreadystatechange = () => {
  477. if (request.readyState !== XMLHttpRequest.DONE) {
  478. return;
  479. }
  480. if (request.status === 200 || request.status === 0) {
  481. let cMapData;
  482. if (this.isCompressed && request.response) {
  483. cMapData = new Uint8Array(request.response);
  484. } else if (!this.isCompressed && request.responseText) {
  485. cMapData = (0, _util.stringToBytes)(request.responseText);
  486. }
  487. if (cMapData) {
  488. resolve({
  489. cMapData,
  490. compressionType
  491. });
  492. return;
  493. }
  494. }
  495. reject(new Error(request.statusText));
  496. };
  497. request.send(null);
  498. });
  499. }
  500. }
  501. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  502. class DOMSVGFactory {
  503. create(width, height) {
  504. (0, _util.assert)(width > 0 && height > 0, "Invalid SVG dimensions");
  505. const svg = document.createElementNS(SVG_NS, "svg:svg");
  506. svg.setAttribute("version", "1.1");
  507. svg.setAttribute("width", width + "px");
  508. svg.setAttribute("height", height + "px");
  509. svg.setAttribute("preserveAspectRatio", "none");
  510. svg.setAttribute("viewBox", "0 0 " + width + " " + height);
  511. return svg;
  512. }
  513. createElement(type) {
  514. (0, _util.assert)(typeof type === "string", "Invalid SVG element type");
  515. return document.createElementNS(SVG_NS, type);
  516. }
  517. }
  518. exports.DOMSVGFactory = DOMSVGFactory;
  519. class PageViewport {
  520. constructor({
  521. viewBox,
  522. scale,
  523. rotation,
  524. offsetX = 0,
  525. offsetY = 0,
  526. dontFlip = false
  527. }) {
  528. this.viewBox = viewBox;
  529. this.scale = scale;
  530. this.rotation = rotation;
  531. this.offsetX = offsetX;
  532. this.offsetY = offsetY;
  533. const centerX = (viewBox[2] + viewBox[0]) / 2;
  534. const centerY = (viewBox[3] + viewBox[1]) / 2;
  535. let rotateA, rotateB, rotateC, rotateD;
  536. rotation = rotation % 360;
  537. rotation = rotation < 0 ? rotation + 360 : rotation;
  538. switch (rotation) {
  539. case 180:
  540. rotateA = -1;
  541. rotateB = 0;
  542. rotateC = 0;
  543. rotateD = 1;
  544. break;
  545. case 90:
  546. rotateA = 0;
  547. rotateB = 1;
  548. rotateC = 1;
  549. rotateD = 0;
  550. break;
  551. case 270:
  552. rotateA = 0;
  553. rotateB = -1;
  554. rotateC = -1;
  555. rotateD = 0;
  556. break;
  557. case 0:
  558. rotateA = 1;
  559. rotateB = 0;
  560. rotateC = 0;
  561. rotateD = -1;
  562. break;
  563. default:
  564. throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
  565. }
  566. if (dontFlip) {
  567. rotateC = -rotateC;
  568. rotateD = -rotateD;
  569. }
  570. let offsetCanvasX, offsetCanvasY;
  571. let width, height;
  572. if (rotateA === 0) {
  573. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  574. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  575. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  576. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  577. } else {
  578. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  579. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  580. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  581. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  582. }
  583. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  584. this.width = width;
  585. this.height = height;
  586. }
  587. clone({
  588. scale = this.scale,
  589. rotation = this.rotation,
  590. offsetX = this.offsetX,
  591. offsetY = this.offsetY,
  592. dontFlip = false
  593. } = {}) {
  594. return new PageViewport({
  595. viewBox: this.viewBox.slice(),
  596. scale,
  597. rotation,
  598. offsetX,
  599. offsetY,
  600. dontFlip
  601. });
  602. }
  603. convertToViewportPoint(x, y) {
  604. return _util.Util.applyTransform([x, y], this.transform);
  605. }
  606. convertToViewportRectangle(rect) {
  607. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  608. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  609. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  610. }
  611. convertToPdfPoint(x, y) {
  612. return _util.Util.applyInverseTransform([x, y], this.transform);
  613. }
  614. }
  615. exports.PageViewport = PageViewport;
  616. class RenderingCancelledException extends _util.BaseException {
  617. constructor(msg, type) {
  618. super(msg);
  619. this.type = type;
  620. }
  621. }
  622. exports.RenderingCancelledException = RenderingCancelledException;
  623. const LinkTarget = {
  624. NONE: 0,
  625. SELF: 1,
  626. BLANK: 2,
  627. PARENT: 3,
  628. TOP: 4
  629. };
  630. exports.LinkTarget = LinkTarget;
  631. function addLinkAttributes(link, {
  632. url,
  633. target,
  634. rel,
  635. enabled = true
  636. } = {}) {
  637. (0, _util.assert)(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
  638. const urlNullRemoved = (0, _util.removeNullCharacters)(url);
  639. if (enabled) {
  640. link.href = link.title = urlNullRemoved;
  641. } else {
  642. link.href = "";
  643. link.title = `Disabled: ${urlNullRemoved}`;
  644. link.onclick = () => {
  645. return false;
  646. };
  647. }
  648. let targetStr = "";
  649. switch (target) {
  650. case LinkTarget.NONE:
  651. break;
  652. case LinkTarget.SELF:
  653. targetStr = "_self";
  654. break;
  655. case LinkTarget.BLANK:
  656. targetStr = "_blank";
  657. break;
  658. case LinkTarget.PARENT:
  659. targetStr = "_parent";
  660. break;
  661. case LinkTarget.TOP:
  662. targetStr = "_top";
  663. break;
  664. }
  665. link.target = targetStr;
  666. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  667. }
  668. function getFilenameFromUrl(url) {
  669. const anchor = url.indexOf("#");
  670. const query = url.indexOf("?");
  671. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  672. return url.substring(url.lastIndexOf("/", end) + 1, end);
  673. }
  674. class StatTimer {
  675. constructor() {
  676. this.started = Object.create(null);
  677. this.times = [];
  678. }
  679. time(name) {
  680. if (name in this.started) {
  681. (0, _util.warn)(`Timer is already running for ${name}`);
  682. }
  683. this.started[name] = Date.now();
  684. }
  685. timeEnd(name) {
  686. if (!(name in this.started)) {
  687. (0, _util.warn)(`Timer has not been started for ${name}`);
  688. }
  689. this.times.push({
  690. name,
  691. start: this.started[name],
  692. end: Date.now()
  693. });
  694. delete this.started[name];
  695. }
  696. toString() {
  697. const outBuf = [];
  698. let longest = 0;
  699. for (const time of this.times) {
  700. const name = time.name;
  701. if (name.length > longest) {
  702. longest = name.length;
  703. }
  704. }
  705. for (const time of this.times) {
  706. const duration = time.end - time.start;
  707. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  708. }
  709. return outBuf.join("");
  710. }
  711. }
  712. exports.StatTimer = StatTimer;
  713. function isFetchSupported() {
  714. return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined";
  715. }
  716. function isValidFetchUrl(url, baseUrl) {
  717. try {
  718. const {
  719. protocol
  720. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  721. return protocol === "http:" || protocol === "https:";
  722. } catch (ex) {
  723. return false;
  724. }
  725. }
  726. function loadScript(src) {
  727. return new Promise((resolve, reject) => {
  728. const script = document.createElement("script");
  729. script.src = src;
  730. script.onload = resolve;
  731. script.onerror = function () {
  732. reject(new Error(`Cannot load script at: ${script.src}`));
  733. };
  734. (document.head || document.documentElement).appendChild(script);
  735. });
  736. }
  737. function deprecated(details) {
  738. console.log("Deprecated API usage: " + details);
  739. }
  740. let pdfDateStringRegex;
  741. class PDFDateString {
  742. static toDateObject(input) {
  743. if (!input || !(0, _util.isString)(input)) {
  744. return null;
  745. }
  746. if (!pdfDateStringRegex) {
  747. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  748. }
  749. const matches = pdfDateStringRegex.exec(input);
  750. if (!matches) {
  751. return null;
  752. }
  753. const year = parseInt(matches[1], 10);
  754. let month = parseInt(matches[2], 10);
  755. month = month >= 1 && month <= 12 ? month - 1 : 0;
  756. let day = parseInt(matches[3], 10);
  757. day = day >= 1 && day <= 31 ? day : 1;
  758. let hour = parseInt(matches[4], 10);
  759. hour = hour >= 0 && hour <= 23 ? hour : 0;
  760. let minute = parseInt(matches[5], 10);
  761. minute = minute >= 0 && minute <= 59 ? minute : 0;
  762. let second = parseInt(matches[6], 10);
  763. second = second >= 0 && second <= 59 ? second : 0;
  764. const universalTimeRelation = matches[7] || "Z";
  765. let offsetHour = parseInt(matches[8], 10);
  766. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  767. let offsetMinute = parseInt(matches[9], 10) || 0;
  768. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  769. if (universalTimeRelation === "-") {
  770. hour += offsetHour;
  771. minute += offsetMinute;
  772. } else if (universalTimeRelation === "+") {
  773. hour -= offsetHour;
  774. minute -= offsetMinute;
  775. }
  776. return new Date(Date.UTC(year, month, day, hour, minute, second));
  777. }
  778. }
  779. exports.PDFDateString = PDFDateString;
  780. /***/ }),
  781. /* 2 */
  782. /***/ (function(module, exports, __w_pdfjs_require__) {
  783. "use strict";
  784. Object.defineProperty(exports, "__esModule", {
  785. value: true
  786. });
  787. exports.arrayByteLength = arrayByteLength;
  788. exports.arraysToBytes = arraysToBytes;
  789. exports.assert = assert;
  790. exports.bytesToString = bytesToString;
  791. exports.createPromiseCapability = createPromiseCapability;
  792. exports.escapeString = escapeString;
  793. exports.getModificationDate = getModificationDate;
  794. exports.getVerbosityLevel = getVerbosityLevel;
  795. exports.info = info;
  796. exports.isArrayBuffer = isArrayBuffer;
  797. exports.isArrayEqual = isArrayEqual;
  798. exports.isBool = isBool;
  799. exports.isNum = isNum;
  800. exports.isString = isString;
  801. exports.isSameOrigin = isSameOrigin;
  802. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  803. exports.removeNullCharacters = removeNullCharacters;
  804. exports.setVerbosityLevel = setVerbosityLevel;
  805. exports.shadow = shadow;
  806. exports.string32 = string32;
  807. exports.stringToBytes = stringToBytes;
  808. exports.stringToPDFString = stringToPDFString;
  809. exports.stringToUTF8String = stringToUTF8String;
  810. exports.utf8StringToString = utf8StringToString;
  811. exports.warn = warn;
  812. exports.unreachable = unreachable;
  813. exports.IsEvalSupportedCached = exports.IsLittleEndianCached = exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0;
  814. __w_pdfjs_require__(3);
  815. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  816. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  817. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  818. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  819. const PermissionFlag = {
  820. PRINT: 0x04,
  821. MODIFY_CONTENTS: 0x08,
  822. COPY: 0x10,
  823. MODIFY_ANNOTATIONS: 0x20,
  824. FILL_INTERACTIVE_FORMS: 0x100,
  825. COPY_FOR_ACCESSIBILITY: 0x200,
  826. ASSEMBLE: 0x400,
  827. PRINT_HIGH_QUALITY: 0x800
  828. };
  829. exports.PermissionFlag = PermissionFlag;
  830. const TextRenderingMode = {
  831. FILL: 0,
  832. STROKE: 1,
  833. FILL_STROKE: 2,
  834. INVISIBLE: 3,
  835. FILL_ADD_TO_PATH: 4,
  836. STROKE_ADD_TO_PATH: 5,
  837. FILL_STROKE_ADD_TO_PATH: 6,
  838. ADD_TO_PATH: 7,
  839. FILL_STROKE_MASK: 3,
  840. ADD_TO_PATH_FLAG: 4
  841. };
  842. exports.TextRenderingMode = TextRenderingMode;
  843. const ImageKind = {
  844. GRAYSCALE_1BPP: 1,
  845. RGB_24BPP: 2,
  846. RGBA_32BPP: 3
  847. };
  848. exports.ImageKind = ImageKind;
  849. const AnnotationType = {
  850. TEXT: 1,
  851. LINK: 2,
  852. FREETEXT: 3,
  853. LINE: 4,
  854. SQUARE: 5,
  855. CIRCLE: 6,
  856. POLYGON: 7,
  857. POLYLINE: 8,
  858. HIGHLIGHT: 9,
  859. UNDERLINE: 10,
  860. SQUIGGLY: 11,
  861. STRIKEOUT: 12,
  862. STAMP: 13,
  863. CARET: 14,
  864. INK: 15,
  865. POPUP: 16,
  866. FILEATTACHMENT: 17,
  867. SOUND: 18,
  868. MOVIE: 19,
  869. WIDGET: 20,
  870. SCREEN: 21,
  871. PRINTERMARK: 22,
  872. TRAPNET: 23,
  873. WATERMARK: 24,
  874. THREED: 25,
  875. REDACT: 26
  876. };
  877. exports.AnnotationType = AnnotationType;
  878. const AnnotationStateModelType = {
  879. MARKED: "Marked",
  880. REVIEW: "Review"
  881. };
  882. exports.AnnotationStateModelType = AnnotationStateModelType;
  883. const AnnotationMarkedState = {
  884. MARKED: "Marked",
  885. UNMARKED: "Unmarked"
  886. };
  887. exports.AnnotationMarkedState = AnnotationMarkedState;
  888. const AnnotationReviewState = {
  889. ACCEPTED: "Accepted",
  890. REJECTED: "Rejected",
  891. CANCELLED: "Cancelled",
  892. COMPLETED: "Completed",
  893. NONE: "None"
  894. };
  895. exports.AnnotationReviewState = AnnotationReviewState;
  896. const AnnotationReplyType = {
  897. GROUP: "Group",
  898. REPLY: "R"
  899. };
  900. exports.AnnotationReplyType = AnnotationReplyType;
  901. const AnnotationFlag = {
  902. INVISIBLE: 0x01,
  903. HIDDEN: 0x02,
  904. PRINT: 0x04,
  905. NOZOOM: 0x08,
  906. NOROTATE: 0x10,
  907. NOVIEW: 0x20,
  908. READONLY: 0x40,
  909. LOCKED: 0x80,
  910. TOGGLENOVIEW: 0x100,
  911. LOCKEDCONTENTS: 0x200
  912. };
  913. exports.AnnotationFlag = AnnotationFlag;
  914. const AnnotationFieldFlag = {
  915. READONLY: 0x0000001,
  916. REQUIRED: 0x0000002,
  917. NOEXPORT: 0x0000004,
  918. MULTILINE: 0x0001000,
  919. PASSWORD: 0x0002000,
  920. NOTOGGLETOOFF: 0x0004000,
  921. RADIO: 0x0008000,
  922. PUSHBUTTON: 0x0010000,
  923. COMBO: 0x0020000,
  924. EDIT: 0x0040000,
  925. SORT: 0x0080000,
  926. FILESELECT: 0x0100000,
  927. MULTISELECT: 0x0200000,
  928. DONOTSPELLCHECK: 0x0400000,
  929. DONOTSCROLL: 0x0800000,
  930. COMB: 0x1000000,
  931. RICHTEXT: 0x2000000,
  932. RADIOSINUNISON: 0x2000000,
  933. COMMITONSELCHANGE: 0x4000000
  934. };
  935. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  936. const AnnotationBorderStyleType = {
  937. SOLID: 1,
  938. DASHED: 2,
  939. BEVELED: 3,
  940. INSET: 4,
  941. UNDERLINE: 5
  942. };
  943. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  944. const StreamType = {
  945. UNKNOWN: "UNKNOWN",
  946. FLATE: "FLATE",
  947. LZW: "LZW",
  948. DCT: "DCT",
  949. JPX: "JPX",
  950. JBIG: "JBIG",
  951. A85: "A85",
  952. AHX: "AHX",
  953. CCF: "CCF",
  954. RLX: "RLX"
  955. };
  956. exports.StreamType = StreamType;
  957. const FontType = {
  958. UNKNOWN: "UNKNOWN",
  959. TYPE1: "TYPE1",
  960. TYPE1C: "TYPE1C",
  961. CIDFONTTYPE0: "CIDFONTTYPE0",
  962. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  963. TRUETYPE: "TRUETYPE",
  964. CIDFONTTYPE2: "CIDFONTTYPE2",
  965. TYPE3: "TYPE3",
  966. OPENTYPE: "OPENTYPE",
  967. TYPE0: "TYPE0",
  968. MMTYPE1: "MMTYPE1"
  969. };
  970. exports.FontType = FontType;
  971. const VerbosityLevel = {
  972. ERRORS: 0,
  973. WARNINGS: 1,
  974. INFOS: 5
  975. };
  976. exports.VerbosityLevel = VerbosityLevel;
  977. const CMapCompressionType = {
  978. NONE: 0,
  979. BINARY: 1,
  980. STREAM: 2
  981. };
  982. exports.CMapCompressionType = CMapCompressionType;
  983. const OPS = {
  984. dependency: 1,
  985. setLineWidth: 2,
  986. setLineCap: 3,
  987. setLineJoin: 4,
  988. setMiterLimit: 5,
  989. setDash: 6,
  990. setRenderingIntent: 7,
  991. setFlatness: 8,
  992. setGState: 9,
  993. save: 10,
  994. restore: 11,
  995. transform: 12,
  996. moveTo: 13,
  997. lineTo: 14,
  998. curveTo: 15,
  999. curveTo2: 16,
  1000. curveTo3: 17,
  1001. closePath: 18,
  1002. rectangle: 19,
  1003. stroke: 20,
  1004. closeStroke: 21,
  1005. fill: 22,
  1006. eoFill: 23,
  1007. fillStroke: 24,
  1008. eoFillStroke: 25,
  1009. closeFillStroke: 26,
  1010. closeEOFillStroke: 27,
  1011. endPath: 28,
  1012. clip: 29,
  1013. eoClip: 30,
  1014. beginText: 31,
  1015. endText: 32,
  1016. setCharSpacing: 33,
  1017. setWordSpacing: 34,
  1018. setHScale: 35,
  1019. setLeading: 36,
  1020. setFont: 37,
  1021. setTextRenderingMode: 38,
  1022. setTextRise: 39,
  1023. moveText: 40,
  1024. setLeadingMoveText: 41,
  1025. setTextMatrix: 42,
  1026. nextLine: 43,
  1027. showText: 44,
  1028. showSpacedText: 45,
  1029. nextLineShowText: 46,
  1030. nextLineSetSpacingShowText: 47,
  1031. setCharWidth: 48,
  1032. setCharWidthAndBounds: 49,
  1033. setStrokeColorSpace: 50,
  1034. setFillColorSpace: 51,
  1035. setStrokeColor: 52,
  1036. setStrokeColorN: 53,
  1037. setFillColor: 54,
  1038. setFillColorN: 55,
  1039. setStrokeGray: 56,
  1040. setFillGray: 57,
  1041. setStrokeRGBColor: 58,
  1042. setFillRGBColor: 59,
  1043. setStrokeCMYKColor: 60,
  1044. setFillCMYKColor: 61,
  1045. shadingFill: 62,
  1046. beginInlineImage: 63,
  1047. beginImageData: 64,
  1048. endInlineImage: 65,
  1049. paintXObject: 66,
  1050. markPoint: 67,
  1051. markPointProps: 68,
  1052. beginMarkedContent: 69,
  1053. beginMarkedContentProps: 70,
  1054. endMarkedContent: 71,
  1055. beginCompat: 72,
  1056. endCompat: 73,
  1057. paintFormXObjectBegin: 74,
  1058. paintFormXObjectEnd: 75,
  1059. beginGroup: 76,
  1060. endGroup: 77,
  1061. beginAnnotations: 78,
  1062. endAnnotations: 79,
  1063. beginAnnotation: 80,
  1064. endAnnotation: 81,
  1065. paintJpegXObject: 82,
  1066. paintImageMaskXObject: 83,
  1067. paintImageMaskXObjectGroup: 84,
  1068. paintImageXObject: 85,
  1069. paintInlineImageXObject: 86,
  1070. paintInlineImageXObjectGroup: 87,
  1071. paintImageXObjectRepeat: 88,
  1072. paintImageMaskXObjectRepeat: 89,
  1073. paintSolidColorImageMask: 90,
  1074. constructPath: 91
  1075. };
  1076. exports.OPS = OPS;
  1077. const UNSUPPORTED_FEATURES = {
  1078. unknown: "unknown",
  1079. forms: "forms",
  1080. javaScript: "javaScript",
  1081. smask: "smask",
  1082. shadingPattern: "shadingPattern",
  1083. font: "font",
  1084. errorTilingPattern: "errorTilingPattern",
  1085. errorExtGState: "errorExtGState",
  1086. errorXObject: "errorXObject",
  1087. errorFontLoadType3: "errorFontLoadType3",
  1088. errorFontState: "errorFontState",
  1089. errorFontMissing: "errorFontMissing",
  1090. errorFontTranslate: "errorFontTranslate",
  1091. errorColorSpace: "errorColorSpace",
  1092. errorOperatorList: "errorOperatorList",
  1093. errorFontToUnicode: "errorFontToUnicode",
  1094. errorFontLoadNative: "errorFontLoadNative",
  1095. errorFontGetPath: "errorFontGetPath",
  1096. errorMarkedContent: "errorMarkedContent"
  1097. };
  1098. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1099. const PasswordResponses = {
  1100. NEED_PASSWORD: 1,
  1101. INCORRECT_PASSWORD: 2
  1102. };
  1103. exports.PasswordResponses = PasswordResponses;
  1104. let verbosity = VerbosityLevel.WARNINGS;
  1105. function setVerbosityLevel(level) {
  1106. if (Number.isInteger(level)) {
  1107. verbosity = level;
  1108. }
  1109. }
  1110. function getVerbosityLevel() {
  1111. return verbosity;
  1112. }
  1113. function info(msg) {
  1114. if (verbosity >= VerbosityLevel.INFOS) {
  1115. console.log(`Info: ${msg}`);
  1116. }
  1117. }
  1118. function warn(msg) {
  1119. if (verbosity >= VerbosityLevel.WARNINGS) {
  1120. console.log(`Warning: ${msg}`);
  1121. }
  1122. }
  1123. function unreachable(msg) {
  1124. throw new Error(msg);
  1125. }
  1126. function assert(cond, msg) {
  1127. if (!cond) {
  1128. unreachable(msg);
  1129. }
  1130. }
  1131. function isSameOrigin(baseUrl, otherUrl) {
  1132. let base;
  1133. try {
  1134. base = new URL(baseUrl);
  1135. if (!base.origin || base.origin === "null") {
  1136. return false;
  1137. }
  1138. } catch (e) {
  1139. return false;
  1140. }
  1141. const other = new URL(otherUrl, base);
  1142. return base.origin === other.origin;
  1143. }
  1144. function _isValidProtocol(url) {
  1145. if (!url) {
  1146. return false;
  1147. }
  1148. switch (url.protocol) {
  1149. case "http:":
  1150. case "https:":
  1151. case "ftp:":
  1152. case "mailto:":
  1153. case "tel:":
  1154. return true;
  1155. default:
  1156. return false;
  1157. }
  1158. }
  1159. function createValidAbsoluteUrl(url, baseUrl) {
  1160. if (!url) {
  1161. return null;
  1162. }
  1163. try {
  1164. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  1165. if (_isValidProtocol(absoluteUrl)) {
  1166. return absoluteUrl;
  1167. }
  1168. } catch (ex) {}
  1169. return null;
  1170. }
  1171. function shadow(obj, prop, value) {
  1172. Object.defineProperty(obj, prop, {
  1173. value,
  1174. enumerable: true,
  1175. configurable: true,
  1176. writable: false
  1177. });
  1178. return value;
  1179. }
  1180. const BaseException = function BaseExceptionClosure() {
  1181. function BaseException(message) {
  1182. if (this.constructor === BaseException) {
  1183. unreachable("Cannot initialize BaseException.");
  1184. }
  1185. this.message = message;
  1186. this.name = this.constructor.name;
  1187. }
  1188. BaseException.prototype = new Error();
  1189. BaseException.constructor = BaseException;
  1190. return BaseException;
  1191. }();
  1192. exports.BaseException = BaseException;
  1193. class PasswordException extends BaseException {
  1194. constructor(msg, code) {
  1195. super(msg);
  1196. this.code = code;
  1197. }
  1198. }
  1199. exports.PasswordException = PasswordException;
  1200. class UnknownErrorException extends BaseException {
  1201. constructor(msg, details) {
  1202. super(msg);
  1203. this.details = details;
  1204. }
  1205. }
  1206. exports.UnknownErrorException = UnknownErrorException;
  1207. class InvalidPDFException extends BaseException {}
  1208. exports.InvalidPDFException = InvalidPDFException;
  1209. class MissingPDFException extends BaseException {}
  1210. exports.MissingPDFException = MissingPDFException;
  1211. class UnexpectedResponseException extends BaseException {
  1212. constructor(msg, status) {
  1213. super(msg);
  1214. this.status = status;
  1215. }
  1216. }
  1217. exports.UnexpectedResponseException = UnexpectedResponseException;
  1218. class FormatError extends BaseException {}
  1219. exports.FormatError = FormatError;
  1220. class AbortException extends BaseException {}
  1221. exports.AbortException = AbortException;
  1222. const NullCharactersRegExp = /\x00/g;
  1223. function removeNullCharacters(str) {
  1224. if (typeof str !== "string") {
  1225. warn("The argument for removeNullCharacters must be a string.");
  1226. return str;
  1227. }
  1228. return str.replace(NullCharactersRegExp, "");
  1229. }
  1230. function bytesToString(bytes) {
  1231. assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
  1232. const length = bytes.length;
  1233. const MAX_ARGUMENT_COUNT = 8192;
  1234. if (length < MAX_ARGUMENT_COUNT) {
  1235. return String.fromCharCode.apply(null, bytes);
  1236. }
  1237. const strBuf = [];
  1238. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  1239. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  1240. const chunk = bytes.subarray(i, chunkEnd);
  1241. strBuf.push(String.fromCharCode.apply(null, chunk));
  1242. }
  1243. return strBuf.join("");
  1244. }
  1245. function stringToBytes(str) {
  1246. assert(typeof str === "string", "Invalid argument for stringToBytes");
  1247. const length = str.length;
  1248. const bytes = new Uint8Array(length);
  1249. for (let i = 0; i < length; ++i) {
  1250. bytes[i] = str.charCodeAt(i) & 0xff;
  1251. }
  1252. return bytes;
  1253. }
  1254. function arrayByteLength(arr) {
  1255. if (arr.length !== undefined) {
  1256. return arr.length;
  1257. }
  1258. assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
  1259. return arr.byteLength;
  1260. }
  1261. function arraysToBytes(arr) {
  1262. const length = arr.length;
  1263. if (length === 1 && arr[0] instanceof Uint8Array) {
  1264. return arr[0];
  1265. }
  1266. let resultLength = 0;
  1267. for (let i = 0; i < length; i++) {
  1268. resultLength += arrayByteLength(arr[i]);
  1269. }
  1270. let pos = 0;
  1271. const data = new Uint8Array(resultLength);
  1272. for (let i = 0; i < length; i++) {
  1273. let item = arr[i];
  1274. if (!(item instanceof Uint8Array)) {
  1275. if (typeof item === "string") {
  1276. item = stringToBytes(item);
  1277. } else {
  1278. item = new Uint8Array(item);
  1279. }
  1280. }
  1281. const itemLength = item.byteLength;
  1282. data.set(item, pos);
  1283. pos += itemLength;
  1284. }
  1285. return data;
  1286. }
  1287. function string32(value) {
  1288. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  1289. }
  1290. function isLittleEndian() {
  1291. const buffer8 = new Uint8Array(4);
  1292. buffer8[0] = 1;
  1293. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  1294. return view32[0] === 1;
  1295. }
  1296. const IsLittleEndianCached = {
  1297. get value() {
  1298. return shadow(this, "value", isLittleEndian());
  1299. }
  1300. };
  1301. exports.IsLittleEndianCached = IsLittleEndianCached;
  1302. function isEvalSupported() {
  1303. try {
  1304. new Function("");
  1305. return true;
  1306. } catch (e) {
  1307. return false;
  1308. }
  1309. }
  1310. const IsEvalSupportedCached = {
  1311. get value() {
  1312. return shadow(this, "value", isEvalSupported());
  1313. }
  1314. };
  1315. exports.IsEvalSupportedCached = IsEvalSupportedCached;
  1316. const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
  1317. class Util {
  1318. static makeCssRgb(r, g, b) {
  1319. rgbBuf[1] = r;
  1320. rgbBuf[3] = g;
  1321. rgbBuf[5] = b;
  1322. return rgbBuf.join("");
  1323. }
  1324. static transform(m1, m2) {
  1325. 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]];
  1326. }
  1327. static applyTransform(p, m) {
  1328. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  1329. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  1330. return [xt, yt];
  1331. }
  1332. static applyInverseTransform(p, m) {
  1333. const d = m[0] * m[3] - m[1] * m[2];
  1334. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  1335. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  1336. return [xt, yt];
  1337. }
  1338. static getAxialAlignedBoundingBox(r, m) {
  1339. const p1 = Util.applyTransform(r, m);
  1340. const p2 = Util.applyTransform(r.slice(2, 4), m);
  1341. const p3 = Util.applyTransform([r[0], r[3]], m);
  1342. const p4 = Util.applyTransform([r[2], r[1]], m);
  1343. 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])];
  1344. }
  1345. static inverseTransform(m) {
  1346. const d = m[0] * m[3] - m[1] * m[2];
  1347. 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];
  1348. }
  1349. static apply3dTransform(m, v) {
  1350. return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
  1351. }
  1352. static singularValueDecompose2dScale(m) {
  1353. const transpose = [m[0], m[2], m[1], m[3]];
  1354. const a = m[0] * transpose[0] + m[1] * transpose[2];
  1355. const b = m[0] * transpose[1] + m[1] * transpose[3];
  1356. const c = m[2] * transpose[0] + m[3] * transpose[2];
  1357. const d = m[2] * transpose[1] + m[3] * transpose[3];
  1358. const first = (a + d) / 2;
  1359. const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  1360. const sx = first + second || 1;
  1361. const sy = first - second || 1;
  1362. return [Math.sqrt(sx), Math.sqrt(sy)];
  1363. }
  1364. static normalizeRect(rect) {
  1365. const r = rect.slice(0);
  1366. if (rect[0] > rect[2]) {
  1367. r[0] = rect[2];
  1368. r[2] = rect[0];
  1369. }
  1370. if (rect[1] > rect[3]) {
  1371. r[1] = rect[3];
  1372. r[3] = rect[1];
  1373. }
  1374. return r;
  1375. }
  1376. static intersect(rect1, rect2) {
  1377. function compare(a, b) {
  1378. return a - b;
  1379. }
  1380. const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
  1381. const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
  1382. const result = [];
  1383. rect1 = Util.normalizeRect(rect1);
  1384. rect2 = Util.normalizeRect(rect2);
  1385. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  1386. result[0] = orderedX[1];
  1387. result[2] = orderedX[2];
  1388. } else {
  1389. return null;
  1390. }
  1391. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  1392. result[1] = orderedY[1];
  1393. result[3] = orderedY[2];
  1394. } else {
  1395. return null;
  1396. }
  1397. return result;
  1398. }
  1399. }
  1400. exports.Util = Util;
  1401. 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];
  1402. function stringToPDFString(str) {
  1403. const length = str.length,
  1404. strBuf = [];
  1405. if (str[0] === "\xFE" && str[1] === "\xFF") {
  1406. for (let i = 2; i < length; i += 2) {
  1407. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  1408. }
  1409. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  1410. for (let i = 2; i < length; i += 2) {
  1411. strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
  1412. }
  1413. } else {
  1414. for (let i = 0; i < length; ++i) {
  1415. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  1416. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  1417. }
  1418. }
  1419. return strBuf.join("");
  1420. }
  1421. function escapeString(str) {
  1422. return str.replace(/([\(\)\\])/g, "\\$1");
  1423. }
  1424. function stringToUTF8String(str) {
  1425. return decodeURIComponent(escape(str));
  1426. }
  1427. function utf8StringToString(str) {
  1428. return unescape(encodeURIComponent(str));
  1429. }
  1430. function isBool(v) {
  1431. return typeof v === "boolean";
  1432. }
  1433. function isNum(v) {
  1434. return typeof v === "number";
  1435. }
  1436. function isString(v) {
  1437. return typeof v === "string";
  1438. }
  1439. function isArrayBuffer(v) {
  1440. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  1441. }
  1442. function isArrayEqual(arr1, arr2) {
  1443. if (arr1.length !== arr2.length) {
  1444. return false;
  1445. }
  1446. return arr1.every(function (element, index) {
  1447. return element === arr2[index];
  1448. });
  1449. }
  1450. function getModificationDate(date = new Date(Date.now())) {
  1451. const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), (date.getUTCDate() + 1).toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
  1452. return buffer.join("");
  1453. }
  1454. function createPromiseCapability() {
  1455. const capability = Object.create(null);
  1456. let isSettled = false;
  1457. Object.defineProperty(capability, "settled", {
  1458. get() {
  1459. return isSettled;
  1460. }
  1461. });
  1462. capability.promise = new Promise(function (resolve, reject) {
  1463. capability.resolve = function (data) {
  1464. isSettled = true;
  1465. resolve(data);
  1466. };
  1467. capability.reject = function (reason) {
  1468. isSettled = true;
  1469. reject(reason);
  1470. };
  1471. });
  1472. return capability;
  1473. }
  1474. const createObjectURL = function createObjectURLClosure() {
  1475. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1476. return function createObjectURL(data, contentType, forceDataSchema = false) {
  1477. if (!forceDataSchema && URL.createObjectURL) {
  1478. const blob = new Blob([data], {
  1479. type: contentType
  1480. });
  1481. return URL.createObjectURL(blob);
  1482. }
  1483. let buffer = `data:${contentType};base64,`;
  1484. for (let i = 0, ii = data.length; i < ii; i += 3) {
  1485. const b1 = data[i] & 0xff;
  1486. const b2 = data[i + 1] & 0xff;
  1487. const b3 = data[i + 2] & 0xff;
  1488. const d1 = b1 >> 2,
  1489. d2 = (b1 & 3) << 4 | b2 >> 4;
  1490. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  1491. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  1492. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1493. }
  1494. return buffer;
  1495. };
  1496. }();
  1497. exports.createObjectURL = createObjectURL;
  1498. /***/ }),
  1499. /* 3 */
  1500. /***/ (function(module, exports, __w_pdfjs_require__) {
  1501. "use strict";
  1502. var _is_node = __w_pdfjs_require__(4);
  1503. ;
  1504. /***/ }),
  1505. /* 4 */
  1506. /***/ (function(module, exports, __w_pdfjs_require__) {
  1507. "use strict";
  1508. Object.defineProperty(exports, "__esModule", {
  1509. value: true
  1510. });
  1511. exports.isNodeJS = void 0;
  1512. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
  1513. exports.isNodeJS = isNodeJS;
  1514. /***/ }),
  1515. /* 5 */
  1516. /***/ (function(module, exports, __w_pdfjs_require__) {
  1517. "use strict";
  1518. Object.defineProperty(exports, "__esModule", {
  1519. value: true
  1520. });
  1521. exports.getDocument = getDocument;
  1522. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  1523. exports.build = exports.version = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFWorker = exports.PDFDataRangeTransport = exports.LoopbackPort = void 0;
  1524. var _util = __w_pdfjs_require__(2);
  1525. var _display_utils = __w_pdfjs_require__(1);
  1526. var _font_loader = __w_pdfjs_require__(6);
  1527. var _node_utils = __w_pdfjs_require__(7);
  1528. var _annotation_storage = __w_pdfjs_require__(8);
  1529. var _api_compatibility = __w_pdfjs_require__(9);
  1530. var _canvas = __w_pdfjs_require__(10);
  1531. var _worker_options = __w_pdfjs_require__(12);
  1532. var _is_node = __w_pdfjs_require__(4);
  1533. var _message_handler = __w_pdfjs_require__(13);
  1534. var _metadata = __w_pdfjs_require__(14);
  1535. var _optional_content_config = __w_pdfjs_require__(16);
  1536. var _transport_stream = __w_pdfjs_require__(17);
  1537. var _webgl = __w_pdfjs_require__(18);
  1538. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  1539. const RENDERING_CANCELLED_TIMEOUT = 100;
  1540. const DefaultCanvasFactory = _is_node.isNodeJS ? _node_utils.NodeCanvasFactory : _display_utils.DOMCanvasFactory;
  1541. const DefaultCMapReaderFactory = _is_node.isNodeJS ? _node_utils.NodeCMapReaderFactory : _display_utils.DOMCMapReaderFactory;
  1542. let createPDFNetworkStream;
  1543. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  1544. createPDFNetworkStream = pdfNetworkStreamFactory;
  1545. }
  1546. function getDocument(src) {
  1547. const task = new PDFDocumentLoadingTask();
  1548. let source;
  1549. if (typeof src === "string") {
  1550. source = {
  1551. url: src
  1552. };
  1553. } else if ((0, _util.isArrayBuffer)(src)) {
  1554. source = {
  1555. data: src
  1556. };
  1557. } else if (src instanceof PDFDataRangeTransport) {
  1558. source = {
  1559. range: src
  1560. };
  1561. } else {
  1562. if (typeof src !== "object") {
  1563. throw new Error("Invalid parameter in getDocument, " + "need either Uint8Array, string or a parameter object");
  1564. }
  1565. if (!src.url && !src.data && !src.range) {
  1566. throw new Error("Invalid parameter object: need either .data, .range or .url");
  1567. }
  1568. source = src;
  1569. }
  1570. const params = Object.create(null);
  1571. let rangeTransport = null,
  1572. worker = null;
  1573. for (const key in source) {
  1574. if (key === "url" && typeof window !== "undefined") {
  1575. params[key] = new URL(source[key], window.location).href;
  1576. continue;
  1577. } else if (key === "range") {
  1578. rangeTransport = source[key];
  1579. continue;
  1580. } else if (key === "worker") {
  1581. worker = source[key];
  1582. continue;
  1583. } else if (key === "data" && !(source[key] instanceof Uint8Array)) {
  1584. const pdfBytes = source[key];
  1585. if (typeof pdfBytes === "string") {
  1586. params[key] = (0, _util.stringToBytes)(pdfBytes);
  1587. } else if (typeof pdfBytes === "object" && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  1588. params[key] = new Uint8Array(pdfBytes);
  1589. } else if ((0, _util.isArrayBuffer)(pdfBytes)) {
  1590. params[key] = new Uint8Array(pdfBytes);
  1591. } else {
  1592. throw new Error("Invalid PDF binary data: either typed array, " + "string or array-like object is expected in the " + "data property.");
  1593. }
  1594. continue;
  1595. }
  1596. params[key] = source[key];
  1597. }
  1598. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1599. params.CMapReaderFactory = params.CMapReaderFactory || DefaultCMapReaderFactory;
  1600. params.ignoreErrors = params.stopAtErrors !== true;
  1601. params.fontExtraProperties = params.fontExtraProperties === true;
  1602. params.pdfBug = params.pdfBug === true;
  1603. if (!Number.isInteger(params.maxImageSize)) {
  1604. params.maxImageSize = -1;
  1605. }
  1606. if (typeof params.isEvalSupported !== "boolean") {
  1607. params.isEvalSupported = true;
  1608. }
  1609. if (typeof params.disableFontFace !== "boolean") {
  1610. params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false;
  1611. }
  1612. if (typeof params.ownerDocument === "undefined") {
  1613. params.ownerDocument = globalThis.document;
  1614. }
  1615. if (typeof params.disableRange !== "boolean") {
  1616. params.disableRange = false;
  1617. }
  1618. if (typeof params.disableStream !== "boolean") {
  1619. params.disableStream = false;
  1620. }
  1621. if (typeof params.disableAutoFetch !== "boolean") {
  1622. params.disableAutoFetch = false;
  1623. }
  1624. (0, _util.setVerbosityLevel)(params.verbosity);
  1625. if (!worker) {
  1626. const workerParams = {
  1627. verbosity: params.verbosity,
  1628. port: _worker_options.GlobalWorkerOptions.workerPort
  1629. };
  1630. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1631. task._worker = worker;
  1632. }
  1633. const docId = task.docId;
  1634. worker.promise.then(function () {
  1635. if (task.destroyed) {
  1636. throw new Error("Loading aborted");
  1637. }
  1638. const workerIdPromise = _fetchDocument(worker, params, rangeTransport, docId);
  1639. const networkStreamPromise = new Promise(function (resolve) {
  1640. let networkStream;
  1641. if (rangeTransport) {
  1642. networkStream = new _transport_stream.PDFDataTransportStream({
  1643. length: params.length,
  1644. initialData: params.initialData,
  1645. progressiveDone: params.progressiveDone,
  1646. disableRange: params.disableRange,
  1647. disableStream: params.disableStream
  1648. }, rangeTransport);
  1649. } else if (!params.data) {
  1650. networkStream = createPDFNetworkStream({
  1651. url: params.url,
  1652. length: params.length,
  1653. httpHeaders: params.httpHeaders,
  1654. withCredentials: params.withCredentials,
  1655. rangeChunkSize: params.rangeChunkSize,
  1656. disableRange: params.disableRange,
  1657. disableStream: params.disableStream
  1658. });
  1659. }
  1660. resolve(networkStream);
  1661. });
  1662. return Promise.all([workerIdPromise, networkStreamPromise]).then(function ([workerId, networkStream]) {
  1663. if (task.destroyed) {
  1664. throw new Error("Loading aborted");
  1665. }
  1666. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1667. messageHandler.postMessageTransfers = worker.postMessageTransfers;
  1668. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1669. task._transport = transport;
  1670. messageHandler.send("Ready", null);
  1671. });
  1672. }).catch(task._capability.reject);
  1673. return task;
  1674. }
  1675. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1676. if (worker.destroyed) {
  1677. return Promise.reject(new Error("Worker was destroyed"));
  1678. }
  1679. if (pdfDataRangeTransport) {
  1680. source.length = pdfDataRangeTransport.length;
  1681. source.initialData = pdfDataRangeTransport.initialData;
  1682. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1683. }
  1684. return worker.messageHandler.sendWithPromise("GetDocRequest", {
  1685. docId,
  1686. apiVersion: '2.6.347',
  1687. source: {
  1688. data: source.data,
  1689. url: source.url,
  1690. password: source.password,
  1691. disableAutoFetch: source.disableAutoFetch,
  1692. rangeChunkSize: source.rangeChunkSize,
  1693. length: source.length
  1694. },
  1695. maxImageSize: source.maxImageSize,
  1696. disableFontFace: source.disableFontFace,
  1697. postMessageTransfers: worker.postMessageTransfers,
  1698. docBaseUrl: source.docBaseUrl,
  1699. ignoreErrors: source.ignoreErrors,
  1700. isEvalSupported: source.isEvalSupported,
  1701. fontExtraProperties: source.fontExtraProperties
  1702. }).then(function (workerId) {
  1703. if (worker.destroyed) {
  1704. throw new Error("Worker was destroyed");
  1705. }
  1706. return workerId;
  1707. });
  1708. }
  1709. const PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  1710. let nextDocumentId = 0;
  1711. class PDFDocumentLoadingTask {
  1712. constructor() {
  1713. this._capability = (0, _util.createPromiseCapability)();
  1714. this._transport = null;
  1715. this._worker = null;
  1716. this.docId = "d" + nextDocumentId++;
  1717. this.destroyed = false;
  1718. this.onPassword = null;
  1719. this.onProgress = null;
  1720. this.onUnsupportedFeature = null;
  1721. }
  1722. get promise() {
  1723. return this._capability.promise;
  1724. }
  1725. destroy() {
  1726. this.destroyed = true;
  1727. const transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  1728. return transportDestroyed.then(() => {
  1729. this._transport = null;
  1730. if (this._worker) {
  1731. this._worker.destroy();
  1732. this._worker = null;
  1733. }
  1734. });
  1735. }
  1736. }
  1737. return PDFDocumentLoadingTask;
  1738. }();
  1739. class PDFDataRangeTransport {
  1740. constructor(length, initialData, progressiveDone = false) {
  1741. this.length = length;
  1742. this.initialData = initialData;
  1743. this.progressiveDone = progressiveDone;
  1744. this._rangeListeners = [];
  1745. this._progressListeners = [];
  1746. this._progressiveReadListeners = [];
  1747. this._progressiveDoneListeners = [];
  1748. this._readyCapability = (0, _util.createPromiseCapability)();
  1749. }
  1750. addRangeListener(listener) {
  1751. this._rangeListeners.push(listener);
  1752. }
  1753. addProgressListener(listener) {
  1754. this._progressListeners.push(listener);
  1755. }
  1756. addProgressiveReadListener(listener) {
  1757. this._progressiveReadListeners.push(listener);
  1758. }
  1759. addProgressiveDoneListener(listener) {
  1760. this._progressiveDoneListeners.push(listener);
  1761. }
  1762. onDataRange(begin, chunk) {
  1763. for (const listener of this._rangeListeners) {
  1764. listener(begin, chunk);
  1765. }
  1766. }
  1767. onDataProgress(loaded, total) {
  1768. this._readyCapability.promise.then(() => {
  1769. for (const listener of this._progressListeners) {
  1770. listener(loaded, total);
  1771. }
  1772. });
  1773. }
  1774. onDataProgressiveRead(chunk) {
  1775. this._readyCapability.promise.then(() => {
  1776. for (const listener of this._progressiveReadListeners) {
  1777. listener(chunk);
  1778. }
  1779. });
  1780. }
  1781. onDataProgressiveDone() {
  1782. this._readyCapability.promise.then(() => {
  1783. for (const listener of this._progressiveDoneListeners) {
  1784. listener();
  1785. }
  1786. });
  1787. }
  1788. transportReady() {
  1789. this._readyCapability.resolve();
  1790. }
  1791. requestDataRange(begin, end) {
  1792. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1793. }
  1794. abort() {}
  1795. }
  1796. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1797. class PDFDocumentProxy {
  1798. constructor(pdfInfo, transport) {
  1799. this._pdfInfo = pdfInfo;
  1800. this._transport = transport;
  1801. }
  1802. get annotationStorage() {
  1803. return (0, _util.shadow)(this, "annotationStorage", new _annotation_storage.AnnotationStorage());
  1804. }
  1805. get numPages() {
  1806. return this._pdfInfo.numPages;
  1807. }
  1808. get fingerprint() {
  1809. return this._pdfInfo.fingerprint;
  1810. }
  1811. getPage(pageNumber) {
  1812. return this._transport.getPage(pageNumber);
  1813. }
  1814. getPageIndex(ref) {
  1815. return this._transport.getPageIndex(ref);
  1816. }
  1817. getDestinations() {
  1818. return this._transport.getDestinations();
  1819. }
  1820. getDestination(id) {
  1821. return this._transport.getDestination(id);
  1822. }
  1823. getPageLabels() {
  1824. return this._transport.getPageLabels();
  1825. }
  1826. getPageLayout() {
  1827. return this._transport.getPageLayout();
  1828. }
  1829. getPageMode() {
  1830. return this._transport.getPageMode();
  1831. }
  1832. getViewerPreferences() {
  1833. return this._transport.getViewerPreferences();
  1834. }
  1835. getOpenAction() {
  1836. return this._transport.getOpenAction();
  1837. }
  1838. getAttachments() {
  1839. return this._transport.getAttachments();
  1840. }
  1841. getJavaScript() {
  1842. return this._transport.getJavaScript();
  1843. }
  1844. getOutline() {
  1845. return this._transport.getOutline();
  1846. }
  1847. getOptionalContentConfig() {
  1848. return this._transport.getOptionalContentConfig();
  1849. }
  1850. getPermissions() {
  1851. return this._transport.getPermissions();
  1852. }
  1853. getMetadata() {
  1854. return this._transport.getMetadata();
  1855. }
  1856. getData() {
  1857. return this._transport.getData();
  1858. }
  1859. getDownloadInfo() {
  1860. return this._transport.downloadInfoCapability.promise;
  1861. }
  1862. getStats() {
  1863. return this._transport.getStats();
  1864. }
  1865. cleanup() {
  1866. return this._transport.startCleanup();
  1867. }
  1868. destroy() {
  1869. return this.loadingTask.destroy();
  1870. }
  1871. get loadingParams() {
  1872. return this._transport.loadingParams;
  1873. }
  1874. get loadingTask() {
  1875. return this._transport.loadingTask;
  1876. }
  1877. saveDocument(annotationStorage) {
  1878. return this._transport.saveDocument(annotationStorage);
  1879. }
  1880. }
  1881. exports.PDFDocumentProxy = PDFDocumentProxy;
  1882. class PDFPageProxy {
  1883. constructor(pageIndex, pageInfo, transport, ownerDocument, pdfBug = false) {
  1884. this._pageIndex = pageIndex;
  1885. this._pageInfo = pageInfo;
  1886. this._ownerDocument = ownerDocument;
  1887. this._transport = transport;
  1888. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1889. this._pdfBug = pdfBug;
  1890. this.commonObjs = transport.commonObjs;
  1891. this.objs = new PDFObjects();
  1892. this.cleanupAfterRender = false;
  1893. this.pendingCleanup = false;
  1894. this._intentStates = new Map();
  1895. this.destroyed = false;
  1896. }
  1897. get pageNumber() {
  1898. return this._pageIndex + 1;
  1899. }
  1900. get rotate() {
  1901. return this._pageInfo.rotate;
  1902. }
  1903. get ref() {
  1904. return this._pageInfo.ref;
  1905. }
  1906. get userUnit() {
  1907. return this._pageInfo.userUnit;
  1908. }
  1909. get view() {
  1910. return this._pageInfo.view;
  1911. }
  1912. getViewport({
  1913. scale,
  1914. rotation = this.rotate,
  1915. offsetX = 0,
  1916. offsetY = 0,
  1917. dontFlip = false
  1918. } = {}) {
  1919. return new _display_utils.PageViewport({
  1920. viewBox: this.view,
  1921. scale,
  1922. rotation,
  1923. offsetX,
  1924. offsetY,
  1925. dontFlip
  1926. });
  1927. }
  1928. getAnnotations({
  1929. intent = null
  1930. } = {}) {
  1931. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  1932. this.annotationsPromise = this._transport.getAnnotations(this._pageIndex, intent);
  1933. this.annotationsIntent = intent;
  1934. }
  1935. return this.annotationsPromise;
  1936. }
  1937. render({
  1938. canvasContext,
  1939. viewport,
  1940. intent = "display",
  1941. enableWebGL = false,
  1942. renderInteractiveForms = false,
  1943. transform = null,
  1944. imageLayer = null,
  1945. canvasFactory = null,
  1946. background = null,
  1947. annotationStorage = null,
  1948. optionalContentConfigPromise = null
  1949. }) {
  1950. if (this._stats) {
  1951. this._stats.time("Overall");
  1952. }
  1953. const renderingIntent = intent === "print" ? "print" : "display";
  1954. this.pendingCleanup = false;
  1955. if (!optionalContentConfigPromise) {
  1956. optionalContentConfigPromise = this._transport.getOptionalContentConfig();
  1957. }
  1958. let intentState = this._intentStates.get(renderingIntent);
  1959. if (!intentState) {
  1960. intentState = Object.create(null);
  1961. this._intentStates.set(renderingIntent, intentState);
  1962. }
  1963. if (intentState.streamReaderCancelTimeout) {
  1964. clearTimeout(intentState.streamReaderCancelTimeout);
  1965. intentState.streamReaderCancelTimeout = null;
  1966. }
  1967. const canvasFactoryInstance = canvasFactory || new DefaultCanvasFactory({
  1968. ownerDocument: this._ownerDocument
  1969. });
  1970. const webGLContext = new _webgl.WebGLContext({
  1971. enable: enableWebGL
  1972. });
  1973. if (!intentState.displayReadyCapability) {
  1974. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1975. intentState.operatorList = {
  1976. fnArray: [],
  1977. argsArray: [],
  1978. lastChunk: false
  1979. };
  1980. if (this._stats) {
  1981. this._stats.time("Page Request");
  1982. }
  1983. this._pumpOperatorList({
  1984. pageIndex: this._pageIndex,
  1985. intent: renderingIntent,
  1986. renderInteractiveForms: renderInteractiveForms === true,
  1987. annotationStorage: annotationStorage && annotationStorage.getAll() || null
  1988. });
  1989. }
  1990. const complete = error => {
  1991. const i = intentState.renderTasks.indexOf(internalRenderTask);
  1992. if (i >= 0) {
  1993. intentState.renderTasks.splice(i, 1);
  1994. }
  1995. if (this.cleanupAfterRender || renderingIntent === "print") {
  1996. this.pendingCleanup = true;
  1997. }
  1998. this._tryCleanup();
  1999. if (error) {
  2000. internalRenderTask.capability.reject(error);
  2001. this._abortOperatorList({
  2002. intentState,
  2003. reason: error
  2004. });
  2005. } else {
  2006. internalRenderTask.capability.resolve();
  2007. }
  2008. if (this._stats) {
  2009. this._stats.timeEnd("Rendering");
  2010. this._stats.timeEnd("Overall");
  2011. }
  2012. };
  2013. const internalRenderTask = new InternalRenderTask({
  2014. callback: complete,
  2015. params: {
  2016. canvasContext,
  2017. viewport,
  2018. transform,
  2019. imageLayer,
  2020. background
  2021. },
  2022. objs: this.objs,
  2023. commonObjs: this.commonObjs,
  2024. operatorList: intentState.operatorList,
  2025. pageIndex: this._pageIndex,
  2026. canvasFactory: canvasFactoryInstance,
  2027. webGLContext,
  2028. useRequestAnimationFrame: renderingIntent !== "print",
  2029. pdfBug: this._pdfBug
  2030. });
  2031. if (!intentState.renderTasks) {
  2032. intentState.renderTasks = [];
  2033. }
  2034. intentState.renderTasks.push(internalRenderTask);
  2035. const renderTask = internalRenderTask.task;
  2036. Promise.all([intentState.displayReadyCapability.promise, optionalContentConfigPromise]).then(([transparency, optionalContentConfig]) => {
  2037. if (this.pendingCleanup) {
  2038. complete();
  2039. return;
  2040. }
  2041. if (this._stats) {
  2042. this._stats.time("Rendering");
  2043. }
  2044. internalRenderTask.initializeGraphics({
  2045. transparency,
  2046. optionalContentConfig
  2047. });
  2048. internalRenderTask.operatorListChanged();
  2049. }).catch(complete);
  2050. return renderTask;
  2051. }
  2052. getOperatorList() {
  2053. function operatorListChanged() {
  2054. if (intentState.operatorList.lastChunk) {
  2055. intentState.opListReadCapability.resolve(intentState.operatorList);
  2056. const i = intentState.renderTasks.indexOf(opListTask);
  2057. if (i >= 0) {
  2058. intentState.renderTasks.splice(i, 1);
  2059. }
  2060. }
  2061. }
  2062. const renderingIntent = "oplist";
  2063. let intentState = this._intentStates.get(renderingIntent);
  2064. if (!intentState) {
  2065. intentState = Object.create(null);
  2066. this._intentStates.set(renderingIntent, intentState);
  2067. }
  2068. let opListTask;
  2069. if (!intentState.opListReadCapability) {
  2070. opListTask = Object.create(null);
  2071. opListTask.operatorListChanged = operatorListChanged;
  2072. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  2073. intentState.renderTasks = [];
  2074. intentState.renderTasks.push(opListTask);
  2075. intentState.operatorList = {
  2076. fnArray: [],
  2077. argsArray: [],
  2078. lastChunk: false
  2079. };
  2080. if (this._stats) {
  2081. this._stats.time("Page Request");
  2082. }
  2083. this._pumpOperatorList({
  2084. pageIndex: this._pageIndex,
  2085. intent: renderingIntent
  2086. });
  2087. }
  2088. return intentState.opListReadCapability.promise;
  2089. }
  2090. streamTextContent({
  2091. normalizeWhitespace = false,
  2092. disableCombineTextItems = false
  2093. } = {}) {
  2094. const TEXT_CONTENT_CHUNK_SIZE = 100;
  2095. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  2096. pageIndex: this._pageIndex,
  2097. normalizeWhitespace: normalizeWhitespace === true,
  2098. combineTextItems: disableCombineTextItems !== true
  2099. }, {
  2100. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  2101. size(textContent) {
  2102. return textContent.items.length;
  2103. }
  2104. });
  2105. }
  2106. getTextContent(params = {}) {
  2107. const readableStream = this.streamTextContent(params);
  2108. return new Promise(function (resolve, reject) {
  2109. function pump() {
  2110. reader.read().then(function ({
  2111. value,
  2112. done
  2113. }) {
  2114. if (done) {
  2115. resolve(textContent);
  2116. return;
  2117. }
  2118. Object.assign(textContent.styles, value.styles);
  2119. textContent.items.push(...value.items);
  2120. pump();
  2121. }, reject);
  2122. }
  2123. const reader = readableStream.getReader();
  2124. const textContent = {
  2125. items: [],
  2126. styles: Object.create(null)
  2127. };
  2128. pump();
  2129. });
  2130. }
  2131. _destroy() {
  2132. this.destroyed = true;
  2133. this._transport.pageCache[this._pageIndex] = null;
  2134. const waitOn = [];
  2135. for (const [intent, intentState] of this._intentStates) {
  2136. this._abortOperatorList({
  2137. intentState,
  2138. reason: new Error("Page was destroyed."),
  2139. force: true
  2140. });
  2141. if (intent === "oplist") {
  2142. continue;
  2143. }
  2144. for (const internalRenderTask of intentState.renderTasks) {
  2145. waitOn.push(internalRenderTask.completed);
  2146. internalRenderTask.cancel();
  2147. }
  2148. }
  2149. this.objs.clear();
  2150. this.annotationsPromise = null;
  2151. this.pendingCleanup = false;
  2152. return Promise.all(waitOn);
  2153. }
  2154. cleanup(resetStats = false) {
  2155. this.pendingCleanup = true;
  2156. return this._tryCleanup(resetStats);
  2157. }
  2158. _tryCleanup(resetStats = false) {
  2159. if (!this.pendingCleanup) {
  2160. return false;
  2161. }
  2162. for (const {
  2163. renderTasks,
  2164. operatorList
  2165. } of this._intentStates.values()) {
  2166. if (renderTasks.length !== 0 || !operatorList.lastChunk) {
  2167. return false;
  2168. }
  2169. }
  2170. this._intentStates.clear();
  2171. this.objs.clear();
  2172. this.annotationsPromise = null;
  2173. if (resetStats && this._stats) {
  2174. this._stats = new _display_utils.StatTimer();
  2175. }
  2176. this.pendingCleanup = false;
  2177. return true;
  2178. }
  2179. _startRenderPage(transparency, intent) {
  2180. const intentState = this._intentStates.get(intent);
  2181. if (!intentState) {
  2182. return;
  2183. }
  2184. if (this._stats) {
  2185. this._stats.timeEnd("Page Request");
  2186. }
  2187. if (intentState.displayReadyCapability) {
  2188. intentState.displayReadyCapability.resolve(transparency);
  2189. }
  2190. }
  2191. _renderPageChunk(operatorListChunk, intentState) {
  2192. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2193. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2194. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  2195. }
  2196. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2197. for (let i = 0; i < intentState.renderTasks.length; i++) {
  2198. intentState.renderTasks[i].operatorListChanged();
  2199. }
  2200. if (operatorListChunk.lastChunk) {
  2201. this._tryCleanup();
  2202. }
  2203. }
  2204. _pumpOperatorList(args) {
  2205. (0, _util.assert)(args.intent, 'PDFPageProxy._pumpOperatorList: Expected "intent" argument.');
  2206. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", args);
  2207. const reader = readableStream.getReader();
  2208. const intentState = this._intentStates.get(args.intent);
  2209. intentState.streamReader = reader;
  2210. const pump = () => {
  2211. reader.read().then(({
  2212. value,
  2213. done
  2214. }) => {
  2215. if (done) {
  2216. intentState.streamReader = null;
  2217. return;
  2218. }
  2219. if (this._transport.destroyed) {
  2220. return;
  2221. }
  2222. this._renderPageChunk(value, intentState);
  2223. pump();
  2224. }, reason => {
  2225. intentState.streamReader = null;
  2226. if (this._transport.destroyed) {
  2227. return;
  2228. }
  2229. if (intentState.operatorList) {
  2230. intentState.operatorList.lastChunk = true;
  2231. for (let i = 0; i < intentState.renderTasks.length; i++) {
  2232. intentState.renderTasks[i].operatorListChanged();
  2233. }
  2234. this._tryCleanup();
  2235. }
  2236. if (intentState.displayReadyCapability) {
  2237. intentState.displayReadyCapability.reject(reason);
  2238. } else if (intentState.opListReadCapability) {
  2239. intentState.opListReadCapability.reject(reason);
  2240. } else {
  2241. throw reason;
  2242. }
  2243. });
  2244. };
  2245. pump();
  2246. }
  2247. _abortOperatorList({
  2248. intentState,
  2249. reason,
  2250. force = false
  2251. }) {
  2252. (0, _util.assert)(reason instanceof Error || typeof reason === "object" && reason !== null, 'PDFPageProxy._abortOperatorList: Expected "reason" argument.');
  2253. if (!intentState.streamReader) {
  2254. return;
  2255. }
  2256. if (!force) {
  2257. if (intentState.renderTasks.length !== 0) {
  2258. return;
  2259. }
  2260. if (reason instanceof _display_utils.RenderingCancelledException) {
  2261. intentState.streamReaderCancelTimeout = setTimeout(() => {
  2262. this._abortOperatorList({
  2263. intentState,
  2264. reason,
  2265. force: true
  2266. });
  2267. intentState.streamReaderCancelTimeout = null;
  2268. }, RENDERING_CANCELLED_TIMEOUT);
  2269. return;
  2270. }
  2271. }
  2272. intentState.streamReader.cancel(new _util.AbortException(reason && reason.message));
  2273. intentState.streamReader = null;
  2274. if (this._transport.destroyed) {
  2275. return;
  2276. }
  2277. for (const [intent, curIntentState] of this._intentStates) {
  2278. if (curIntentState === intentState) {
  2279. this._intentStates.delete(intent);
  2280. break;
  2281. }
  2282. }
  2283. this.cleanup();
  2284. }
  2285. get stats() {
  2286. return this._stats;
  2287. }
  2288. }
  2289. exports.PDFPageProxy = PDFPageProxy;
  2290. class LoopbackPort {
  2291. constructor(defer = true) {
  2292. this._listeners = [];
  2293. this._defer = defer;
  2294. this._deferred = Promise.resolve(undefined);
  2295. }
  2296. postMessage(obj, transfers) {
  2297. function cloneValue(value) {
  2298. if (typeof value !== "object" || value === null) {
  2299. return value;
  2300. }
  2301. if (cloned.has(value)) {
  2302. return cloned.get(value);
  2303. }
  2304. let buffer, result;
  2305. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  2306. const transferable = transfers && transfers.includes(buffer);
  2307. if (transferable) {
  2308. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  2309. } else {
  2310. result = new value.constructor(value);
  2311. }
  2312. cloned.set(value, result);
  2313. return result;
  2314. }
  2315. result = Array.isArray(value) ? [] : {};
  2316. cloned.set(value, result);
  2317. for (const i in value) {
  2318. let desc,
  2319. p = value;
  2320. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  2321. p = Object.getPrototypeOf(p);
  2322. }
  2323. if (typeof desc.value === "undefined") {
  2324. continue;
  2325. }
  2326. if (typeof desc.value === "function") {
  2327. if (value.hasOwnProperty && value.hasOwnProperty(i)) {
  2328. throw new Error(`LoopbackPort.postMessage - cannot clone: ${value[i]}`);
  2329. }
  2330. continue;
  2331. }
  2332. result[i] = cloneValue(desc.value);
  2333. }
  2334. return result;
  2335. }
  2336. if (!this._defer) {
  2337. this._listeners.forEach(listener => {
  2338. listener.call(this, {
  2339. data: obj
  2340. });
  2341. });
  2342. return;
  2343. }
  2344. const cloned = new WeakMap();
  2345. const e = {
  2346. data: cloneValue(obj)
  2347. };
  2348. this._deferred.then(() => {
  2349. this._listeners.forEach(listener => {
  2350. listener.call(this, e);
  2351. });
  2352. });
  2353. }
  2354. addEventListener(name, listener) {
  2355. this._listeners.push(listener);
  2356. }
  2357. removeEventListener(name, listener) {
  2358. const i = this._listeners.indexOf(listener);
  2359. this._listeners.splice(i, 1);
  2360. }
  2361. terminate() {
  2362. this._listeners.length = 0;
  2363. }
  2364. }
  2365. exports.LoopbackPort = LoopbackPort;
  2366. const PDFWorker = function PDFWorkerClosure() {
  2367. const pdfWorkerPorts = new WeakMap();
  2368. let isWorkerDisabled = false;
  2369. let fallbackWorkerSrc;
  2370. let nextFakeWorkerId = 0;
  2371. let fakeWorkerCapability;
  2372. if (_is_node.isNodeJS && typeof require === "function") {
  2373. isWorkerDisabled = true;
  2374. fallbackWorkerSrc = "./pdf.worker.js";
  2375. } else if (typeof document === "object" && "currentScript" in document) {
  2376. const pdfjsFilePath = document.currentScript && document.currentScript.src;
  2377. if (pdfjsFilePath) {
  2378. fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  2379. }
  2380. }
  2381. function getWorkerSrc() {
  2382. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  2383. return _worker_options.GlobalWorkerOptions.workerSrc;
  2384. }
  2385. if (typeof fallbackWorkerSrc !== "undefined") {
  2386. if (!_is_node.isNodeJS) {
  2387. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  2388. }
  2389. return fallbackWorkerSrc;
  2390. }
  2391. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  2392. }
  2393. function getMainThreadWorkerMessageHandler() {
  2394. let mainWorkerMessageHandler;
  2395. try {
  2396. mainWorkerMessageHandler = globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
  2397. } catch (ex) {}
  2398. return mainWorkerMessageHandler || null;
  2399. }
  2400. function setupFakeWorkerGlobal() {
  2401. if (fakeWorkerCapability) {
  2402. return fakeWorkerCapability.promise;
  2403. }
  2404. fakeWorkerCapability = (0, _util.createPromiseCapability)();
  2405. const loader = async function () {
  2406. const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
  2407. if (mainWorkerMessageHandler) {
  2408. return mainWorkerMessageHandler;
  2409. }
  2410. if (_is_node.isNodeJS && typeof require === "function") {
  2411. const worker = eval("require")(getWorkerSrc());
  2412. return worker.WorkerMessageHandler;
  2413. }
  2414. await (0, _display_utils.loadScript)(getWorkerSrc());
  2415. return window.pdfjsWorker.WorkerMessageHandler;
  2416. };
  2417. loader().then(fakeWorkerCapability.resolve, fakeWorkerCapability.reject);
  2418. return fakeWorkerCapability.promise;
  2419. }
  2420. function createCDNWrapper(url) {
  2421. const wrapper = "importScripts('" + url + "');";
  2422. return URL.createObjectURL(new Blob([wrapper]));
  2423. }
  2424. class PDFWorker {
  2425. constructor({
  2426. name = null,
  2427. port = null,
  2428. verbosity = (0, _util.getVerbosityLevel)()
  2429. } = {}) {
  2430. if (port && pdfWorkerPorts.has(port)) {
  2431. throw new Error("Cannot use more than one PDFWorker per port");
  2432. }
  2433. this.name = name;
  2434. this.destroyed = false;
  2435. this.postMessageTransfers = true;
  2436. this.verbosity = verbosity;
  2437. this._readyCapability = (0, _util.createPromiseCapability)();
  2438. this._port = null;
  2439. this._webWorker = null;
  2440. this._messageHandler = null;
  2441. if (port) {
  2442. pdfWorkerPorts.set(port, this);
  2443. this._initializeFromPort(port);
  2444. return;
  2445. }
  2446. this._initialize();
  2447. }
  2448. get promise() {
  2449. return this._readyCapability.promise;
  2450. }
  2451. get port() {
  2452. return this._port;
  2453. }
  2454. get messageHandler() {
  2455. return this._messageHandler;
  2456. }
  2457. _initializeFromPort(port) {
  2458. this._port = port;
  2459. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  2460. this._messageHandler.on("ready", function () {});
  2461. this._readyCapability.resolve();
  2462. }
  2463. _initialize() {
  2464. if (typeof Worker !== "undefined" && !isWorkerDisabled && !getMainThreadWorkerMessageHandler()) {
  2465. let workerSrc = getWorkerSrc();
  2466. try {
  2467. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  2468. workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
  2469. }
  2470. const worker = new Worker(workerSrc);
  2471. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  2472. const terminateEarly = () => {
  2473. worker.removeEventListener("error", onWorkerError);
  2474. messageHandler.destroy();
  2475. worker.terminate();
  2476. if (this.destroyed) {
  2477. this._readyCapability.reject(new Error("Worker was destroyed"));
  2478. } else {
  2479. this._setupFakeWorker();
  2480. }
  2481. };
  2482. const onWorkerError = () => {
  2483. if (!this._webWorker) {
  2484. terminateEarly();
  2485. }
  2486. };
  2487. worker.addEventListener("error", onWorkerError);
  2488. messageHandler.on("test", data => {
  2489. worker.removeEventListener("error", onWorkerError);
  2490. if (this.destroyed) {
  2491. terminateEarly();
  2492. return;
  2493. }
  2494. if (data) {
  2495. this._messageHandler = messageHandler;
  2496. this._port = worker;
  2497. this._webWorker = worker;
  2498. if (!data.supportTransfers) {
  2499. this.postMessageTransfers = false;
  2500. }
  2501. this._readyCapability.resolve();
  2502. messageHandler.send("configure", {
  2503. verbosity: this.verbosity
  2504. });
  2505. } else {
  2506. this._setupFakeWorker();
  2507. messageHandler.destroy();
  2508. worker.terminate();
  2509. }
  2510. });
  2511. messageHandler.on("ready", data => {
  2512. worker.removeEventListener("error", onWorkerError);
  2513. if (this.destroyed) {
  2514. terminateEarly();
  2515. return;
  2516. }
  2517. try {
  2518. sendTest();
  2519. } catch (e) {
  2520. this._setupFakeWorker();
  2521. }
  2522. });
  2523. const sendTest = () => {
  2524. const testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
  2525. try {
  2526. messageHandler.send("test", testObj, [testObj.buffer]);
  2527. } catch (ex) {
  2528. (0, _util.warn)("Cannot use postMessage transfers.");
  2529. testObj[0] = 0;
  2530. messageHandler.send("test", testObj);
  2531. }
  2532. };
  2533. sendTest();
  2534. return;
  2535. } catch (e) {
  2536. (0, _util.info)("The worker has been disabled.");
  2537. }
  2538. }
  2539. this._setupFakeWorker();
  2540. }
  2541. _setupFakeWorker() {
  2542. if (!isWorkerDisabled) {
  2543. (0, _util.warn)("Setting up fake worker.");
  2544. isWorkerDisabled = true;
  2545. }
  2546. setupFakeWorkerGlobal().then(WorkerMessageHandler => {
  2547. if (this.destroyed) {
  2548. this._readyCapability.reject(new Error("Worker was destroyed"));
  2549. return;
  2550. }
  2551. const port = new LoopbackPort();
  2552. this._port = port;
  2553. const id = "fake" + nextFakeWorkerId++;
  2554. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  2555. WorkerMessageHandler.setup(workerHandler, port);
  2556. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  2557. this._messageHandler = messageHandler;
  2558. this._readyCapability.resolve();
  2559. messageHandler.send("configure", {
  2560. verbosity: this.verbosity
  2561. });
  2562. }).catch(reason => {
  2563. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  2564. });
  2565. }
  2566. destroy() {
  2567. this.destroyed = true;
  2568. if (this._webWorker) {
  2569. this._webWorker.terminate();
  2570. this._webWorker = null;
  2571. }
  2572. pdfWorkerPorts.delete(this._port);
  2573. this._port = null;
  2574. if (this._messageHandler) {
  2575. this._messageHandler.destroy();
  2576. this._messageHandler = null;
  2577. }
  2578. }
  2579. static fromPort(params) {
  2580. if (!params || !params.port) {
  2581. throw new Error("PDFWorker.fromPort - invalid method signature.");
  2582. }
  2583. if (pdfWorkerPorts.has(params.port)) {
  2584. return pdfWorkerPorts.get(params.port);
  2585. }
  2586. return new PDFWorker(params);
  2587. }
  2588. static getWorkerSrc() {
  2589. return getWorkerSrc();
  2590. }
  2591. }
  2592. return PDFWorker;
  2593. }();
  2594. exports.PDFWorker = PDFWorker;
  2595. class WorkerTransport {
  2596. constructor(messageHandler, loadingTask, networkStream, params) {
  2597. this.messageHandler = messageHandler;
  2598. this.loadingTask = loadingTask;
  2599. this.commonObjs = new PDFObjects();
  2600. this.fontLoader = new _font_loader.FontLoader({
  2601. docId: loadingTask.docId,
  2602. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2603. ownerDocument: params.ownerDocument
  2604. });
  2605. this._params = params;
  2606. this.CMapReaderFactory = new params.CMapReaderFactory({
  2607. baseUrl: params.cMapUrl,
  2608. isCompressed: params.cMapPacked
  2609. });
  2610. this.destroyed = false;
  2611. this.destroyCapability = null;
  2612. this._passwordCapability = null;
  2613. this._networkStream = networkStream;
  2614. this._fullReader = null;
  2615. this._lastProgress = null;
  2616. this.pageCache = [];
  2617. this.pagePromises = [];
  2618. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  2619. this.setupMessageHandler();
  2620. }
  2621. destroy() {
  2622. if (this.destroyCapability) {
  2623. return this.destroyCapability.promise;
  2624. }
  2625. this.destroyed = true;
  2626. this.destroyCapability = (0, _util.createPromiseCapability)();
  2627. if (this._passwordCapability) {
  2628. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2629. }
  2630. const waitOn = [];
  2631. this.pageCache.forEach(function (page) {
  2632. if (page) {
  2633. waitOn.push(page._destroy());
  2634. }
  2635. });
  2636. this.pageCache.length = 0;
  2637. this.pagePromises.length = 0;
  2638. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2639. waitOn.push(terminated);
  2640. Promise.all(waitOn).then(() => {
  2641. this.fontLoader.clear();
  2642. if (this._networkStream) {
  2643. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2644. }
  2645. if (this.messageHandler) {
  2646. this.messageHandler.destroy();
  2647. this.messageHandler = null;
  2648. }
  2649. this.destroyCapability.resolve();
  2650. }, this.destroyCapability.reject);
  2651. return this.destroyCapability.promise;
  2652. }
  2653. setupMessageHandler() {
  2654. const {
  2655. messageHandler,
  2656. loadingTask
  2657. } = this;
  2658. messageHandler.on("GetReader", (data, sink) => {
  2659. (0, _util.assert)(this._networkStream, "GetReader - no `IPDFStream` instance available.");
  2660. this._fullReader = this._networkStream.getFullReader();
  2661. this._fullReader.onProgress = evt => {
  2662. this._lastProgress = {
  2663. loaded: evt.loaded,
  2664. total: evt.total
  2665. };
  2666. };
  2667. sink.onPull = () => {
  2668. this._fullReader.read().then(function ({
  2669. value,
  2670. done
  2671. }) {
  2672. if (done) {
  2673. sink.close();
  2674. return;
  2675. }
  2676. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetReader - expected an ArrayBuffer.");
  2677. sink.enqueue(new Uint8Array(value), 1, [value]);
  2678. }).catch(reason => {
  2679. sink.error(reason);
  2680. });
  2681. };
  2682. sink.onCancel = reason => {
  2683. this._fullReader.cancel(reason);
  2684. sink.ready.catch(readyReason => {
  2685. if (this.destroyed) {
  2686. return;
  2687. }
  2688. throw readyReason;
  2689. });
  2690. };
  2691. });
  2692. messageHandler.on("ReaderHeadersReady", data => {
  2693. const headersCapability = (0, _util.createPromiseCapability)();
  2694. const fullReader = this._fullReader;
  2695. fullReader.headersReady.then(() => {
  2696. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2697. if (this._lastProgress && loadingTask.onProgress) {
  2698. loadingTask.onProgress(this._lastProgress);
  2699. }
  2700. fullReader.onProgress = evt => {
  2701. if (loadingTask.onProgress) {
  2702. loadingTask.onProgress({
  2703. loaded: evt.loaded,
  2704. total: evt.total
  2705. });
  2706. }
  2707. };
  2708. }
  2709. headersCapability.resolve({
  2710. isStreamingSupported: fullReader.isStreamingSupported,
  2711. isRangeSupported: fullReader.isRangeSupported,
  2712. contentLength: fullReader.contentLength
  2713. });
  2714. }, headersCapability.reject);
  2715. return headersCapability.promise;
  2716. });
  2717. messageHandler.on("GetRangeReader", (data, sink) => {
  2718. (0, _util.assert)(this._networkStream, "GetRangeReader - no `IPDFStream` instance available.");
  2719. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2720. if (!rangeReader) {
  2721. sink.close();
  2722. return;
  2723. }
  2724. sink.onPull = () => {
  2725. rangeReader.read().then(function ({
  2726. value,
  2727. done
  2728. }) {
  2729. if (done) {
  2730. sink.close();
  2731. return;
  2732. }
  2733. (0, _util.assert)((0, _util.isArrayBuffer)(value), "GetRangeReader - expected an ArrayBuffer.");
  2734. sink.enqueue(new Uint8Array(value), 1, [value]);
  2735. }).catch(reason => {
  2736. sink.error(reason);
  2737. });
  2738. };
  2739. sink.onCancel = reason => {
  2740. rangeReader.cancel(reason);
  2741. sink.ready.catch(readyReason => {
  2742. if (this.destroyed) {
  2743. return;
  2744. }
  2745. throw readyReason;
  2746. });
  2747. };
  2748. });
  2749. messageHandler.on("GetDoc", ({
  2750. pdfInfo
  2751. }) => {
  2752. this._numPages = pdfInfo.numPages;
  2753. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2754. });
  2755. messageHandler.on("DocException", function (ex) {
  2756. let reason;
  2757. switch (ex.name) {
  2758. case "PasswordException":
  2759. reason = new _util.PasswordException(ex.message, ex.code);
  2760. break;
  2761. case "InvalidPDFException":
  2762. reason = new _util.InvalidPDFException(ex.message);
  2763. break;
  2764. case "MissingPDFException":
  2765. reason = new _util.MissingPDFException(ex.message);
  2766. break;
  2767. case "UnexpectedResponseException":
  2768. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2769. break;
  2770. case "UnknownErrorException":
  2771. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2772. break;
  2773. }
  2774. if (!(reason instanceof Error)) {
  2775. const msg = "DocException - expected a valid Error.";
  2776. (0, _util.warn)(msg);
  2777. }
  2778. loadingTask._capability.reject(reason);
  2779. });
  2780. messageHandler.on("PasswordRequest", exception => {
  2781. this._passwordCapability = (0, _util.createPromiseCapability)();
  2782. if (loadingTask.onPassword) {
  2783. const updatePassword = password => {
  2784. this._passwordCapability.resolve({
  2785. password
  2786. });
  2787. };
  2788. try {
  2789. loadingTask.onPassword(updatePassword, exception.code);
  2790. } catch (ex) {
  2791. this._passwordCapability.reject(ex);
  2792. }
  2793. } else {
  2794. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2795. }
  2796. return this._passwordCapability.promise;
  2797. });
  2798. messageHandler.on("DataLoaded", data => {
  2799. if (loadingTask.onProgress) {
  2800. loadingTask.onProgress({
  2801. loaded: data.length,
  2802. total: data.length
  2803. });
  2804. }
  2805. this.downloadInfoCapability.resolve(data);
  2806. });
  2807. messageHandler.on("StartRenderPage", data => {
  2808. if (this.destroyed) {
  2809. return;
  2810. }
  2811. const page = this.pageCache[data.pageIndex];
  2812. page._startRenderPage(data.transparency, data.intent);
  2813. });
  2814. messageHandler.on("commonobj", data => {
  2815. if (this.destroyed) {
  2816. return;
  2817. }
  2818. const [id, type, exportedData] = data;
  2819. if (this.commonObjs.has(id)) {
  2820. return;
  2821. }
  2822. switch (type) {
  2823. case "Font":
  2824. const params = this._params;
  2825. if ("error" in exportedData) {
  2826. const exportedError = exportedData.error;
  2827. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2828. this.commonObjs.resolve(id, exportedError);
  2829. break;
  2830. }
  2831. let fontRegistry = null;
  2832. if (params.pdfBug && globalThis.FontInspector && globalThis.FontInspector.enabled) {
  2833. fontRegistry = {
  2834. registerFont(font, url) {
  2835. globalThis.FontInspector.fontAdded(font, url);
  2836. }
  2837. };
  2838. }
  2839. const font = new _font_loader.FontFaceObject(exportedData, {
  2840. isEvalSupported: params.isEvalSupported,
  2841. disableFontFace: params.disableFontFace,
  2842. ignoreErrors: params.ignoreErrors,
  2843. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2844. fontRegistry
  2845. });
  2846. this.fontLoader.bind(font).catch(reason => {
  2847. return messageHandler.sendWithPromise("FontFallback", {
  2848. id
  2849. });
  2850. }).finally(() => {
  2851. if (!params.fontExtraProperties && font.data) {
  2852. font.data = null;
  2853. }
  2854. this.commonObjs.resolve(id, font);
  2855. });
  2856. break;
  2857. case "FontPath":
  2858. case "Image":
  2859. this.commonObjs.resolve(id, exportedData);
  2860. break;
  2861. default:
  2862. throw new Error(`Got unknown common object type ${type}`);
  2863. }
  2864. });
  2865. messageHandler.on("obj", data => {
  2866. if (this.destroyed) {
  2867. return undefined;
  2868. }
  2869. const [id, pageIndex, type, imageData] = data;
  2870. const pageProxy = this.pageCache[pageIndex];
  2871. if (pageProxy.objs.has(id)) {
  2872. return undefined;
  2873. }
  2874. switch (type) {
  2875. case "Image":
  2876. pageProxy.objs.resolve(id, imageData);
  2877. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2878. if (imageData && "data" in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2879. pageProxy.cleanupAfterRender = true;
  2880. }
  2881. break;
  2882. default:
  2883. throw new Error(`Got unknown object type ${type}`);
  2884. }
  2885. return undefined;
  2886. });
  2887. messageHandler.on("DocProgress", data => {
  2888. if (this.destroyed) {
  2889. return;
  2890. }
  2891. if (loadingTask.onProgress) {
  2892. loadingTask.onProgress({
  2893. loaded: data.loaded,
  2894. total: data.total
  2895. });
  2896. }
  2897. });
  2898. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2899. messageHandler.on("FetchBuiltInCMap", (data, sink) => {
  2900. if (this.destroyed) {
  2901. sink.error(new Error("Worker was destroyed"));
  2902. return;
  2903. }
  2904. let fetched = false;
  2905. sink.onPull = () => {
  2906. if (fetched) {
  2907. sink.close();
  2908. return;
  2909. }
  2910. fetched = true;
  2911. this.CMapReaderFactory.fetch(data).then(function (builtInCMap) {
  2912. sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
  2913. }).catch(function (reason) {
  2914. sink.error(reason);
  2915. });
  2916. };
  2917. });
  2918. }
  2919. _onUnsupportedFeature({
  2920. featureId
  2921. }) {
  2922. if (this.destroyed) {
  2923. return;
  2924. }
  2925. if (this.loadingTask.onUnsupportedFeature) {
  2926. this.loadingTask.onUnsupportedFeature(featureId);
  2927. }
  2928. }
  2929. getData() {
  2930. return this.messageHandler.sendWithPromise("GetData", null);
  2931. }
  2932. getPage(pageNumber) {
  2933. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2934. return Promise.reject(new Error("Invalid page request"));
  2935. }
  2936. const pageIndex = pageNumber - 1;
  2937. if (pageIndex in this.pagePromises) {
  2938. return this.pagePromises[pageIndex];
  2939. }
  2940. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2941. pageIndex
  2942. }).then(pageInfo => {
  2943. if (this.destroyed) {
  2944. throw new Error("Transport destroyed");
  2945. }
  2946. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.ownerDocument, this._params.pdfBug);
  2947. this.pageCache[pageIndex] = page;
  2948. return page;
  2949. });
  2950. this.pagePromises[pageIndex] = promise;
  2951. return promise;
  2952. }
  2953. getPageIndex(ref) {
  2954. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2955. ref
  2956. }).catch(function (reason) {
  2957. return Promise.reject(new Error(reason));
  2958. });
  2959. }
  2960. getAnnotations(pageIndex, intent) {
  2961. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2962. pageIndex,
  2963. intent
  2964. });
  2965. }
  2966. saveDocument(annotationStorage) {
  2967. return this.messageHandler.sendWithPromise("SaveDocument", {
  2968. numPages: this._numPages,
  2969. annotationStorage: annotationStorage && annotationStorage.getAll() || null,
  2970. filename: this._fullReader ? this._fullReader.filename : null
  2971. }).finally(() => {
  2972. if (annotationStorage) {
  2973. annotationStorage.resetModified();
  2974. }
  2975. });
  2976. }
  2977. getDestinations() {
  2978. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2979. }
  2980. getDestination(id) {
  2981. if (typeof id !== "string") {
  2982. return Promise.reject(new Error("Invalid destination request."));
  2983. }
  2984. return this.messageHandler.sendWithPromise("GetDestination", {
  2985. id
  2986. });
  2987. }
  2988. getPageLabels() {
  2989. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2990. }
  2991. getPageLayout() {
  2992. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2993. }
  2994. getPageMode() {
  2995. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2996. }
  2997. getViewerPreferences() {
  2998. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2999. }
  3000. getOpenAction() {
  3001. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  3002. }
  3003. getAttachments() {
  3004. return this.messageHandler.sendWithPromise("GetAttachments", null);
  3005. }
  3006. getJavaScript() {
  3007. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  3008. }
  3009. getOutline() {
  3010. return this.messageHandler.sendWithPromise("GetOutline", null);
  3011. }
  3012. getOptionalContentConfig() {
  3013. return this.messageHandler.sendWithPromise("GetOptionalContentConfig", null).then(results => {
  3014. return new _optional_content_config.OptionalContentConfig(results);
  3015. });
  3016. }
  3017. getPermissions() {
  3018. return this.messageHandler.sendWithPromise("GetPermissions", null);
  3019. }
  3020. getMetadata() {
  3021. return this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  3022. return {
  3023. info: results[0],
  3024. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  3025. contentDispositionFilename: this._fullReader ? this._fullReader.filename : null
  3026. };
  3027. });
  3028. }
  3029. getStats() {
  3030. return this.messageHandler.sendWithPromise("GetStats", null);
  3031. }
  3032. startCleanup() {
  3033. return this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
  3034. for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
  3035. const page = this.pageCache[i];
  3036. if (page) {
  3037. const cleanupSuccessful = page.cleanup();
  3038. if (!cleanupSuccessful) {
  3039. throw new Error(`startCleanup: Page ${i + 1} is currently rendering.`);
  3040. }
  3041. }
  3042. }
  3043. this.commonObjs.clear();
  3044. this.fontLoader.clear();
  3045. });
  3046. }
  3047. get loadingParams() {
  3048. const params = this._params;
  3049. return (0, _util.shadow)(this, "loadingParams", {
  3050. disableAutoFetch: params.disableAutoFetch,
  3051. disableFontFace: params.disableFontFace
  3052. });
  3053. }
  3054. }
  3055. class PDFObjects {
  3056. constructor() {
  3057. this._objs = Object.create(null);
  3058. }
  3059. _ensureObj(objId) {
  3060. if (this._objs[objId]) {
  3061. return this._objs[objId];
  3062. }
  3063. return this._objs[objId] = {
  3064. capability: (0, _util.createPromiseCapability)(),
  3065. data: null,
  3066. resolved: false
  3067. };
  3068. }
  3069. get(objId, callback = null) {
  3070. if (callback) {
  3071. this._ensureObj(objId).capability.promise.then(callback);
  3072. return null;
  3073. }
  3074. const obj = this._objs[objId];
  3075. if (!obj || !obj.resolved) {
  3076. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  3077. }
  3078. return obj.data;
  3079. }
  3080. has(objId) {
  3081. const obj = this._objs[objId];
  3082. return obj ? obj.resolved : false;
  3083. }
  3084. resolve(objId, data) {
  3085. const obj = this._ensureObj(objId);
  3086. obj.resolved = true;
  3087. obj.data = data;
  3088. obj.capability.resolve(data);
  3089. }
  3090. clear() {
  3091. this._objs = Object.create(null);
  3092. }
  3093. }
  3094. class RenderTask {
  3095. constructor(internalRenderTask) {
  3096. this._internalRenderTask = internalRenderTask;
  3097. this.onContinue = null;
  3098. }
  3099. get promise() {
  3100. return this._internalRenderTask.capability.promise;
  3101. }
  3102. cancel() {
  3103. this._internalRenderTask.cancel();
  3104. }
  3105. }
  3106. const InternalRenderTask = function InternalRenderTaskClosure() {
  3107. const canvasInRendering = new WeakSet();
  3108. class InternalRenderTask {
  3109. constructor({
  3110. callback,
  3111. params,
  3112. objs,
  3113. commonObjs,
  3114. operatorList,
  3115. pageIndex,
  3116. canvasFactory,
  3117. webGLContext,
  3118. useRequestAnimationFrame = false,
  3119. pdfBug = false
  3120. }) {
  3121. this.callback = callback;
  3122. this.params = params;
  3123. this.objs = objs;
  3124. this.commonObjs = commonObjs;
  3125. this.operatorListIdx = null;
  3126. this.operatorList = operatorList;
  3127. this._pageIndex = pageIndex;
  3128. this.canvasFactory = canvasFactory;
  3129. this.webGLContext = webGLContext;
  3130. this._pdfBug = pdfBug;
  3131. this.running = false;
  3132. this.graphicsReadyCallback = null;
  3133. this.graphicsReady = false;
  3134. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  3135. this.cancelled = false;
  3136. this.capability = (0, _util.createPromiseCapability)();
  3137. this.task = new RenderTask(this);
  3138. this._continueBound = this._continue.bind(this);
  3139. this._scheduleNextBound = this._scheduleNext.bind(this);
  3140. this._nextBound = this._next.bind(this);
  3141. this._canvas = params.canvasContext.canvas;
  3142. }
  3143. get completed() {
  3144. return this.capability.promise.catch(function () {});
  3145. }
  3146. initializeGraphics({
  3147. transparency = false,
  3148. optionalContentConfig
  3149. }) {
  3150. if (this.cancelled) {
  3151. return;
  3152. }
  3153. if (this._canvas) {
  3154. if (canvasInRendering.has(this._canvas)) {
  3155. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  3156. }
  3157. canvasInRendering.add(this._canvas);
  3158. }
  3159. if (this._pdfBug && globalThis.StepperManager && globalThis.StepperManager.enabled) {
  3160. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  3161. this.stepper.init(this.operatorList);
  3162. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  3163. }
  3164. const {
  3165. canvasContext,
  3166. viewport,
  3167. transform,
  3168. imageLayer,
  3169. background
  3170. } = this.params;
  3171. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext, imageLayer, optionalContentConfig);
  3172. this.gfx.beginDrawing({
  3173. transform,
  3174. viewport,
  3175. transparency,
  3176. background
  3177. });
  3178. this.operatorListIdx = 0;
  3179. this.graphicsReady = true;
  3180. if (this.graphicsReadyCallback) {
  3181. this.graphicsReadyCallback();
  3182. }
  3183. }
  3184. cancel(error = null) {
  3185. this.running = false;
  3186. this.cancelled = true;
  3187. if (this.gfx) {
  3188. this.gfx.endDrawing();
  3189. }
  3190. if (this._canvas) {
  3191. canvasInRendering.delete(this._canvas);
  3192. }
  3193. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  3194. }
  3195. operatorListChanged() {
  3196. if (!this.graphicsReady) {
  3197. if (!this.graphicsReadyCallback) {
  3198. this.graphicsReadyCallback = this._continueBound;
  3199. }
  3200. return;
  3201. }
  3202. if (this.stepper) {
  3203. this.stepper.updateOperatorList(this.operatorList);
  3204. }
  3205. if (this.running) {
  3206. return;
  3207. }
  3208. this._continue();
  3209. }
  3210. _continue() {
  3211. this.running = true;
  3212. if (this.cancelled) {
  3213. return;
  3214. }
  3215. if (this.task.onContinue) {
  3216. this.task.onContinue(this._scheduleNextBound);
  3217. } else {
  3218. this._scheduleNext();
  3219. }
  3220. }
  3221. _scheduleNext() {
  3222. if (this._useRequestAnimationFrame) {
  3223. window.requestAnimationFrame(() => {
  3224. this._nextBound().catch(this.cancel.bind(this));
  3225. });
  3226. } else {
  3227. Promise.resolve().then(this._nextBound).catch(this.cancel.bind(this));
  3228. }
  3229. }
  3230. async _next() {
  3231. if (this.cancelled) {
  3232. return;
  3233. }
  3234. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  3235. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3236. this.running = false;
  3237. if (this.operatorList.lastChunk) {
  3238. this.gfx.endDrawing();
  3239. if (this._canvas) {
  3240. canvasInRendering.delete(this._canvas);
  3241. }
  3242. this.callback();
  3243. }
  3244. }
  3245. }
  3246. }
  3247. return InternalRenderTask;
  3248. }();
  3249. const version = '2.6.347';
  3250. exports.version = version;
  3251. const build = '3be9c65f';
  3252. exports.build = build;
  3253. /***/ }),
  3254. /* 6 */
  3255. /***/ (function(module, exports, __w_pdfjs_require__) {
  3256. "use strict";
  3257. Object.defineProperty(exports, "__esModule", {
  3258. value: true
  3259. });
  3260. exports.FontLoader = exports.FontFaceObject = void 0;
  3261. var _util = __w_pdfjs_require__(2);
  3262. class BaseFontLoader {
  3263. constructor({
  3264. docId,
  3265. onUnsupportedFeature,
  3266. ownerDocument = globalThis.document
  3267. }) {
  3268. if (this.constructor === BaseFontLoader) {
  3269. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3270. }
  3271. this.docId = docId;
  3272. this._onUnsupportedFeature = onUnsupportedFeature;
  3273. this._document = ownerDocument;
  3274. this.nativeFontFaces = [];
  3275. this.styleElement = null;
  3276. }
  3277. addNativeFontFace(nativeFontFace) {
  3278. this.nativeFontFaces.push(nativeFontFace);
  3279. this._document.fonts.add(nativeFontFace);
  3280. }
  3281. insertRule(rule) {
  3282. let styleElement = this.styleElement;
  3283. if (!styleElement) {
  3284. styleElement = this.styleElement = this._document.createElement("style");
  3285. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3286. this._document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3287. }
  3288. const styleSheet = styleElement.sheet;
  3289. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3290. }
  3291. clear() {
  3292. this.nativeFontFaces.forEach(nativeFontFace => {
  3293. this._document.fonts.delete(nativeFontFace);
  3294. });
  3295. this.nativeFontFaces.length = 0;
  3296. if (this.styleElement) {
  3297. this.styleElement.remove();
  3298. this.styleElement = null;
  3299. }
  3300. }
  3301. async bind(font) {
  3302. if (font.attached || font.missingFile) {
  3303. return;
  3304. }
  3305. font.attached = true;
  3306. if (this.isFontLoadingAPISupported) {
  3307. const nativeFontFace = font.createNativeFontFace();
  3308. if (nativeFontFace) {
  3309. this.addNativeFontFace(nativeFontFace);
  3310. try {
  3311. await nativeFontFace.loaded;
  3312. } catch (ex) {
  3313. this._onUnsupportedFeature({
  3314. featureId: _util.UNSUPPORTED_FEATURES.errorFontLoadNative
  3315. });
  3316. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3317. font.disableFontFace = true;
  3318. throw ex;
  3319. }
  3320. }
  3321. return;
  3322. }
  3323. const rule = font.createFontFaceRule();
  3324. if (rule) {
  3325. this.insertRule(rule);
  3326. if (this.isSyncFontLoadingSupported) {
  3327. return;
  3328. }
  3329. await new Promise(resolve => {
  3330. const request = this._queueLoadingCallback(resolve);
  3331. this._prepareFontLoadEvent([rule], [font], request);
  3332. });
  3333. }
  3334. }
  3335. _queueLoadingCallback(callback) {
  3336. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3337. }
  3338. get isFontLoadingAPISupported() {
  3339. const supported = typeof this._document !== "undefined" && !!this._document.fonts;
  3340. return (0, _util.shadow)(this, "isFontLoadingAPISupported", supported);
  3341. }
  3342. get isSyncFontLoadingSupported() {
  3343. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3344. }
  3345. get _loadTestFont() {
  3346. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3347. }
  3348. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3349. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3350. }
  3351. }
  3352. let FontLoader;
  3353. exports.FontLoader = FontLoader;
  3354. {
  3355. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3356. constructor(params) {
  3357. super(params);
  3358. this.loadingContext = {
  3359. requests: [],
  3360. nextRequestId: 0
  3361. };
  3362. this.loadTestFontId = 0;
  3363. }
  3364. get isSyncFontLoadingSupported() {
  3365. let supported = false;
  3366. if (typeof navigator === "undefined") {
  3367. supported = true;
  3368. } else {
  3369. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3370. if (m && m[1] >= 14) {
  3371. supported = true;
  3372. }
  3373. }
  3374. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3375. }
  3376. _queueLoadingCallback(callback) {
  3377. function completeRequest() {
  3378. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3379. request.done = true;
  3380. while (context.requests.length > 0 && context.requests[0].done) {
  3381. const otherRequest = context.requests.shift();
  3382. setTimeout(otherRequest.callback, 0);
  3383. }
  3384. }
  3385. const context = this.loadingContext;
  3386. const request = {
  3387. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3388. done: false,
  3389. complete: completeRequest,
  3390. callback
  3391. };
  3392. context.requests.push(request);
  3393. return request;
  3394. }
  3395. get _loadTestFont() {
  3396. const getLoadTestFont = function () {
  3397. return atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
  3398. };
  3399. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3400. }
  3401. _prepareFontLoadEvent(rules, fonts, request) {
  3402. function int32(data, offset) {
  3403. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3404. }
  3405. function spliceString(s, offset, remove, insert) {
  3406. const chunk1 = s.substring(0, offset);
  3407. const chunk2 = s.substring(offset + remove);
  3408. return chunk1 + insert + chunk2;
  3409. }
  3410. let i, ii;
  3411. const canvas = this._document.createElement("canvas");
  3412. canvas.width = 1;
  3413. canvas.height = 1;
  3414. const ctx = canvas.getContext("2d");
  3415. let called = 0;
  3416. function isFontReady(name, callback) {
  3417. called++;
  3418. if (called > 30) {
  3419. (0, _util.warn)("Load test font never loaded.");
  3420. callback();
  3421. return;
  3422. }
  3423. ctx.font = "30px " + name;
  3424. ctx.fillText(".", 0, 20);
  3425. const imageData = ctx.getImageData(0, 0, 1, 1);
  3426. if (imageData.data[3] > 0) {
  3427. callback();
  3428. return;
  3429. }
  3430. setTimeout(isFontReady.bind(null, name, callback));
  3431. }
  3432. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3433. let data = this._loadTestFont;
  3434. const COMMENT_OFFSET = 976;
  3435. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3436. const CFF_CHECKSUM_OFFSET = 16;
  3437. const XXXX_VALUE = 0x58585858;
  3438. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3439. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3440. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3441. }
  3442. if (i < loadTestFontId.length) {
  3443. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3444. }
  3445. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3446. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3447. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3448. this.insertRule(rule);
  3449. const names = [];
  3450. for (i = 0, ii = fonts.length; i < ii; i++) {
  3451. names.push(fonts[i].loadedName);
  3452. }
  3453. names.push(loadTestFontId);
  3454. const div = this._document.createElement("div");
  3455. div.style.visibility = "hidden";
  3456. div.style.width = div.style.height = "10px";
  3457. div.style.position = "absolute";
  3458. div.style.top = div.style.left = "0px";
  3459. for (i = 0, ii = names.length; i < ii; ++i) {
  3460. const span = this._document.createElement("span");
  3461. span.textContent = "Hi";
  3462. span.style.fontFamily = names[i];
  3463. div.appendChild(span);
  3464. }
  3465. this._document.body.appendChild(div);
  3466. isFontReady(loadTestFontId, () => {
  3467. this._document.body.removeChild(div);
  3468. request.complete();
  3469. });
  3470. }
  3471. };
  3472. }
  3473. class FontFaceObject {
  3474. constructor(translatedData, {
  3475. isEvalSupported = true,
  3476. disableFontFace = false,
  3477. ignoreErrors = false,
  3478. onUnsupportedFeature = null,
  3479. fontRegistry = null
  3480. }) {
  3481. this.compiledGlyphs = Object.create(null);
  3482. for (const i in translatedData) {
  3483. this[i] = translatedData[i];
  3484. }
  3485. this.isEvalSupported = isEvalSupported !== false;
  3486. this.disableFontFace = disableFontFace === true;
  3487. this.ignoreErrors = ignoreErrors === true;
  3488. this._onUnsupportedFeature = onUnsupportedFeature;
  3489. this.fontRegistry = fontRegistry;
  3490. }
  3491. createNativeFontFace() {
  3492. if (!this.data || this.disableFontFace) {
  3493. return null;
  3494. }
  3495. const nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3496. if (this.fontRegistry) {
  3497. this.fontRegistry.registerFont(this);
  3498. }
  3499. return nativeFontFace;
  3500. }
  3501. createFontFaceRule() {
  3502. if (!this.data || this.disableFontFace) {
  3503. return null;
  3504. }
  3505. const data = (0, _util.bytesToString)(new Uint8Array(this.data));
  3506. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3507. const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3508. if (this.fontRegistry) {
  3509. this.fontRegistry.registerFont(this, url);
  3510. }
  3511. return rule;
  3512. }
  3513. getPathGenerator(objs, character) {
  3514. if (this.compiledGlyphs[character] !== undefined) {
  3515. return this.compiledGlyphs[character];
  3516. }
  3517. let cmds, current;
  3518. try {
  3519. cmds = objs.get(this.loadedName + "_path_" + character);
  3520. } catch (ex) {
  3521. if (!this.ignoreErrors) {
  3522. throw ex;
  3523. }
  3524. if (this._onUnsupportedFeature) {
  3525. this._onUnsupportedFeature({
  3526. featureId: _util.UNSUPPORTED_FEATURES.errorFontGetPath
  3527. });
  3528. }
  3529. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3530. return this.compiledGlyphs[character] = function (c, size) {};
  3531. }
  3532. if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
  3533. let args,
  3534. js = "";
  3535. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3536. current = cmds[i];
  3537. if (current.args !== undefined) {
  3538. args = current.args.join(",");
  3539. } else {
  3540. args = "";
  3541. }
  3542. js += "c." + current.cmd + "(" + args + ");\n";
  3543. }
  3544. return this.compiledGlyphs[character] = new Function("c", "size", js);
  3545. }
  3546. return this.compiledGlyphs[character] = function (c, size) {
  3547. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3548. current = cmds[i];
  3549. if (current.cmd === "scale") {
  3550. current.args = [size, -size];
  3551. }
  3552. c[current.cmd].apply(c, current.args);
  3553. }
  3554. };
  3555. }
  3556. }
  3557. exports.FontFaceObject = FontFaceObject;
  3558. /***/ }),
  3559. /* 7 */
  3560. /***/ (function(module, exports, __w_pdfjs_require__) {
  3561. "use strict";
  3562. Object.defineProperty(exports, "__esModule", {
  3563. value: true
  3564. });
  3565. exports.NodeCMapReaderFactory = exports.NodeCanvasFactory = void 0;
  3566. var _display_utils = __w_pdfjs_require__(1);
  3567. var _is_node = __w_pdfjs_require__(4);
  3568. var _util = __w_pdfjs_require__(2);
  3569. let NodeCanvasFactory = class {
  3570. constructor() {
  3571. (0, _util.unreachable)("Not implemented: NodeCanvasFactory");
  3572. }
  3573. };
  3574. exports.NodeCanvasFactory = NodeCanvasFactory;
  3575. let NodeCMapReaderFactory = class {
  3576. constructor() {
  3577. (0, _util.unreachable)("Not implemented: NodeCMapReaderFactory");
  3578. }
  3579. };
  3580. exports.NodeCMapReaderFactory = NodeCMapReaderFactory;
  3581. if (_is_node.isNodeJS) {
  3582. exports.NodeCanvasFactory = NodeCanvasFactory = class extends _display_utils.BaseCanvasFactory {
  3583. create(width, height) {
  3584. if (width <= 0 || height <= 0) {
  3585. throw new Error("Invalid canvas size");
  3586. }
  3587. const Canvas = require("canvas");
  3588. const canvas = Canvas.createCanvas(width, height);
  3589. return {
  3590. canvas,
  3591. context: canvas.getContext("2d")
  3592. };
  3593. }
  3594. };
  3595. exports.NodeCMapReaderFactory = NodeCMapReaderFactory = class extends _display_utils.BaseCMapReaderFactory {
  3596. _fetchData(url, compressionType) {
  3597. return new Promise((resolve, reject) => {
  3598. const fs = require("fs");
  3599. fs.readFile(url, (error, data) => {
  3600. if (error || !data) {
  3601. reject(new Error(error));
  3602. return;
  3603. }
  3604. resolve({
  3605. cMapData: new Uint8Array(data),
  3606. compressionType
  3607. });
  3608. });
  3609. });
  3610. }
  3611. };
  3612. }
  3613. /***/ }),
  3614. /* 8 */
  3615. /***/ (function(module, exports, __w_pdfjs_require__) {
  3616. "use strict";
  3617. Object.defineProperty(exports, "__esModule", {
  3618. value: true
  3619. });
  3620. exports.AnnotationStorage = void 0;
  3621. class AnnotationStorage {
  3622. constructor() {
  3623. this._storage = new Map();
  3624. this._modified = false;
  3625. this.onSetModified = null;
  3626. this.onResetModified = null;
  3627. }
  3628. getOrCreateValue(key, defaultValue) {
  3629. if (this._storage.has(key)) {
  3630. return this._storage.get(key);
  3631. }
  3632. this._storage.set(key, defaultValue);
  3633. return defaultValue;
  3634. }
  3635. setValue(key, value) {
  3636. if (this._storage.get(key) !== value) {
  3637. this._setModified();
  3638. }
  3639. this._storage.set(key, value);
  3640. }
  3641. getAll() {
  3642. if (this._storage.size === 0) {
  3643. return null;
  3644. }
  3645. return Object.fromEntries(this._storage);
  3646. }
  3647. get size() {
  3648. return this._storage.size;
  3649. }
  3650. _setModified() {
  3651. if (!this._modified) {
  3652. this._modified = true;
  3653. if (typeof this.onSetModified === "function") {
  3654. this.onSetModified();
  3655. }
  3656. }
  3657. }
  3658. resetModified() {
  3659. if (this._modified) {
  3660. this._modified = false;
  3661. if (typeof this.onResetModified === "function") {
  3662. this.onResetModified();
  3663. }
  3664. }
  3665. }
  3666. }
  3667. exports.AnnotationStorage = AnnotationStorage;
  3668. /***/ }),
  3669. /* 9 */
  3670. /***/ (function(module, exports, __w_pdfjs_require__) {
  3671. "use strict";
  3672. Object.defineProperty(exports, "__esModule", {
  3673. value: true
  3674. });
  3675. exports.apiCompatibilityParams = void 0;
  3676. var _is_node = __w_pdfjs_require__(4);
  3677. const compatibilityParams = Object.create(null);
  3678. {
  3679. (function checkFontFace() {
  3680. if (_is_node.isNodeJS) {
  3681. compatibilityParams.disableFontFace = true;
  3682. }
  3683. })();
  3684. }
  3685. const apiCompatibilityParams = Object.freeze(compatibilityParams);
  3686. exports.apiCompatibilityParams = apiCompatibilityParams;
  3687. /***/ }),
  3688. /* 10 */
  3689. /***/ (function(module, exports, __w_pdfjs_require__) {
  3690. "use strict";
  3691. Object.defineProperty(exports, "__esModule", {
  3692. value: true
  3693. });
  3694. exports.CanvasGraphics = void 0;
  3695. var _util = __w_pdfjs_require__(2);
  3696. var _pattern_helper = __w_pdfjs_require__(11);
  3697. var MIN_FONT_SIZE = 16;
  3698. var MAX_FONT_SIZE = 100;
  3699. var MAX_GROUP_SIZE = 4096;
  3700. var MIN_WIDTH_FACTOR = 0.65;
  3701. var COMPILE_TYPE3_GLYPHS = true;
  3702. var MAX_SIZE_TO_COMPILE = 1000;
  3703. var FULL_CHUNK_HEIGHT = 16;
  3704. function addContextCurrentTransform(ctx) {
  3705. if (!ctx.mozCurrentTransform) {
  3706. ctx._originalSave = ctx.save;
  3707. ctx._originalRestore = ctx.restore;
  3708. ctx._originalRotate = ctx.rotate;
  3709. ctx._originalScale = ctx.scale;
  3710. ctx._originalTranslate = ctx.translate;
  3711. ctx._originalTransform = ctx.transform;
  3712. ctx._originalSetTransform = ctx.setTransform;
  3713. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3714. ctx._transformStack = [];
  3715. Object.defineProperty(ctx, "mozCurrentTransform", {
  3716. get: function getCurrentTransform() {
  3717. return this._transformMatrix;
  3718. }
  3719. });
  3720. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  3721. get: function getCurrentTransformInverse() {
  3722. var m = this._transformMatrix;
  3723. var a = m[0],
  3724. b = m[1],
  3725. c = m[2],
  3726. d = m[3],
  3727. e = m[4],
  3728. f = m[5];
  3729. var ad_bc = a * d - b * c;
  3730. var bc_ad = b * c - a * d;
  3731. return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
  3732. }
  3733. });
  3734. ctx.save = function ctxSave() {
  3735. var old = this._transformMatrix;
  3736. this._transformStack.push(old);
  3737. this._transformMatrix = old.slice(0, 6);
  3738. this._originalSave();
  3739. };
  3740. ctx.restore = function ctxRestore() {
  3741. var prev = this._transformStack.pop();
  3742. if (prev) {
  3743. this._transformMatrix = prev;
  3744. this._originalRestore();
  3745. }
  3746. };
  3747. ctx.translate = function ctxTranslate(x, y) {
  3748. var m = this._transformMatrix;
  3749. m[4] = m[0] * x + m[2] * y + m[4];
  3750. m[5] = m[1] * x + m[3] * y + m[5];
  3751. this._originalTranslate(x, y);
  3752. };
  3753. ctx.scale = function ctxScale(x, y) {
  3754. var m = this._transformMatrix;
  3755. m[0] = m[0] * x;
  3756. m[1] = m[1] * x;
  3757. m[2] = m[2] * y;
  3758. m[3] = m[3] * y;
  3759. this._originalScale(x, y);
  3760. };
  3761. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3762. var m = this._transformMatrix;
  3763. this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
  3764. ctx._originalTransform(a, b, c, d, e, f);
  3765. };
  3766. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3767. this._transformMatrix = [a, b, c, d, e, f];
  3768. ctx._originalSetTransform(a, b, c, d, e, f);
  3769. };
  3770. ctx.rotate = function ctxRotate(angle) {
  3771. var cosValue = Math.cos(angle);
  3772. var sinValue = Math.sin(angle);
  3773. var m = this._transformMatrix;
  3774. this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
  3775. this._originalRotate(angle);
  3776. };
  3777. }
  3778. }
  3779. var CachedCanvases = function CachedCanvasesClosure() {
  3780. function CachedCanvases(canvasFactory) {
  3781. this.canvasFactory = canvasFactory;
  3782. this.cache = Object.create(null);
  3783. }
  3784. CachedCanvases.prototype = {
  3785. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  3786. var canvasEntry;
  3787. if (this.cache[id] !== undefined) {
  3788. canvasEntry = this.cache[id];
  3789. this.canvasFactory.reset(canvasEntry, width, height);
  3790. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3791. } else {
  3792. canvasEntry = this.canvasFactory.create(width, height);
  3793. this.cache[id] = canvasEntry;
  3794. }
  3795. if (trackTransform) {
  3796. addContextCurrentTransform(canvasEntry.context);
  3797. }
  3798. return canvasEntry;
  3799. },
  3800. clear() {
  3801. for (var id in this.cache) {
  3802. var canvasEntry = this.cache[id];
  3803. this.canvasFactory.destroy(canvasEntry);
  3804. delete this.cache[id];
  3805. }
  3806. }
  3807. };
  3808. return CachedCanvases;
  3809. }();
  3810. function compileType3Glyph(imgData) {
  3811. var POINT_TO_PROCESS_LIMIT = 1000;
  3812. var width = imgData.width,
  3813. height = imgData.height;
  3814. var i,
  3815. j,
  3816. j0,
  3817. width1 = width + 1;
  3818. var points = new Uint8Array(width1 * (height + 1));
  3819. var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3820. var lineSize = width + 7 & ~7,
  3821. data0 = imgData.data;
  3822. var data = new Uint8Array(lineSize * height),
  3823. pos = 0,
  3824. ii;
  3825. for (i = 0, ii = data0.length; i < ii; i++) {
  3826. var mask = 128,
  3827. elem = data0[i];
  3828. while (mask > 0) {
  3829. data[pos++] = elem & mask ? 0 : 255;
  3830. mask >>= 1;
  3831. }
  3832. }
  3833. var count = 0;
  3834. pos = 0;
  3835. if (data[pos] !== 0) {
  3836. points[0] = 1;
  3837. ++count;
  3838. }
  3839. for (j = 1; j < width; j++) {
  3840. if (data[pos] !== data[pos + 1]) {
  3841. points[j] = data[pos] ? 2 : 1;
  3842. ++count;
  3843. }
  3844. pos++;
  3845. }
  3846. if (data[pos] !== 0) {
  3847. points[j] = 2;
  3848. ++count;
  3849. }
  3850. for (i = 1; i < height; i++) {
  3851. pos = i * lineSize;
  3852. j0 = i * width1;
  3853. if (data[pos - lineSize] !== data[pos]) {
  3854. points[j0] = data[pos] ? 1 : 8;
  3855. ++count;
  3856. }
  3857. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3858. for (j = 1; j < width; j++) {
  3859. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  3860. if (POINT_TYPES[sum]) {
  3861. points[j0 + j] = POINT_TYPES[sum];
  3862. ++count;
  3863. }
  3864. pos++;
  3865. }
  3866. if (data[pos - lineSize] !== data[pos]) {
  3867. points[j0 + j] = data[pos] ? 2 : 4;
  3868. ++count;
  3869. }
  3870. if (count > POINT_TO_PROCESS_LIMIT) {
  3871. return null;
  3872. }
  3873. }
  3874. pos = lineSize * (height - 1);
  3875. j0 = i * width1;
  3876. if (data[pos] !== 0) {
  3877. points[j0] = 8;
  3878. ++count;
  3879. }
  3880. for (j = 1; j < width; j++) {
  3881. if (data[pos] !== data[pos + 1]) {
  3882. points[j0 + j] = data[pos] ? 4 : 8;
  3883. ++count;
  3884. }
  3885. pos++;
  3886. }
  3887. if (data[pos] !== 0) {
  3888. points[j0 + j] = 4;
  3889. ++count;
  3890. }
  3891. if (count > POINT_TO_PROCESS_LIMIT) {
  3892. return null;
  3893. }
  3894. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3895. var outlines = [];
  3896. for (i = 0; count && i <= height; i++) {
  3897. var p = i * width1;
  3898. var end = p + width;
  3899. while (p < end && !points[p]) {
  3900. p++;
  3901. }
  3902. if (p === end) {
  3903. continue;
  3904. }
  3905. var coords = [p % width1, i];
  3906. var type = points[p],
  3907. p0 = p,
  3908. pp;
  3909. do {
  3910. var step = steps[type];
  3911. do {
  3912. p += step;
  3913. } while (!points[p]);
  3914. pp = points[p];
  3915. if (pp !== 5 && pp !== 10) {
  3916. type = pp;
  3917. points[p] = 0;
  3918. } else {
  3919. type = pp & 0x33 * type >> 4;
  3920. points[p] &= type >> 2 | type << 2;
  3921. }
  3922. coords.push(p % width1);
  3923. coords.push(p / width1 | 0);
  3924. if (!points[p]) {
  3925. --count;
  3926. }
  3927. } while (p0 !== p);
  3928. outlines.push(coords);
  3929. --i;
  3930. }
  3931. var drawOutline = function (c) {
  3932. c.save();
  3933. c.scale(1 / width, -1 / height);
  3934. c.translate(0, -height);
  3935. c.beginPath();
  3936. for (let k = 0, kk = outlines.length; k < kk; k++) {
  3937. var o = outlines[k];
  3938. c.moveTo(o[0], o[1]);
  3939. for (let l = 2, ll = o.length; l < ll; l += 2) {
  3940. c.lineTo(o[l], o[l + 1]);
  3941. }
  3942. }
  3943. c.fill();
  3944. c.beginPath();
  3945. c.restore();
  3946. };
  3947. return drawOutline;
  3948. }
  3949. var CanvasExtraState = function CanvasExtraStateClosure() {
  3950. function CanvasExtraState() {
  3951. this.alphaIsShape = false;
  3952. this.fontSize = 0;
  3953. this.fontSizeScale = 1;
  3954. this.textMatrix = _util.IDENTITY_MATRIX;
  3955. this.textMatrixScale = 1;
  3956. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  3957. this.leading = 0;
  3958. this.x = 0;
  3959. this.y = 0;
  3960. this.lineX = 0;
  3961. this.lineY = 0;
  3962. this.charSpacing = 0;
  3963. this.wordSpacing = 0;
  3964. this.textHScale = 1;
  3965. this.textRenderingMode = _util.TextRenderingMode.FILL;
  3966. this.textRise = 0;
  3967. this.fillColor = "#000000";
  3968. this.strokeColor = "#000000";
  3969. this.patternFill = false;
  3970. this.fillAlpha = 1;
  3971. this.strokeAlpha = 1;
  3972. this.lineWidth = 1;
  3973. this.activeSMask = null;
  3974. this.resumeSMaskCtx = null;
  3975. this.transferMaps = null;
  3976. }
  3977. CanvasExtraState.prototype = {
  3978. clone: function CanvasExtraState_clone() {
  3979. return Object.create(this);
  3980. },
  3981. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3982. this.x = x;
  3983. this.y = y;
  3984. }
  3985. };
  3986. return CanvasExtraState;
  3987. }();
  3988. var CanvasGraphics = function CanvasGraphicsClosure() {
  3989. var EXECUTION_TIME = 15;
  3990. var EXECUTION_STEPS = 10;
  3991. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer, optionalContentConfig) {
  3992. this.ctx = canvasCtx;
  3993. this.current = new CanvasExtraState();
  3994. this.stateStack = [];
  3995. this.pendingClip = null;
  3996. this.pendingEOFill = false;
  3997. this.res = null;
  3998. this.xobjs = null;
  3999. this.commonObjs = commonObjs;
  4000. this.objs = objs;
  4001. this.canvasFactory = canvasFactory;
  4002. this.webGLContext = webGLContext;
  4003. this.imageLayer = imageLayer;
  4004. this.groupStack = [];
  4005. this.processingType3 = null;
  4006. this.baseTransform = null;
  4007. this.baseTransformStack = [];
  4008. this.groupLevel = 0;
  4009. this.smaskStack = [];
  4010. this.smaskCounter = 0;
  4011. this.tempSMask = null;
  4012. this.contentVisible = true;
  4013. this.markedContentStack = [];
  4014. this.optionalContentConfig = optionalContentConfig;
  4015. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  4016. if (canvasCtx) {
  4017. addContextCurrentTransform(canvasCtx);
  4018. }
  4019. this._cachedGetSinglePixelWidth = null;
  4020. }
  4021. function putBinaryImageData(ctx, imgData, transferMaps = null) {
  4022. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  4023. ctx.putImageData(imgData, 0, 0);
  4024. return;
  4025. }
  4026. var height = imgData.height,
  4027. width = imgData.width;
  4028. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4029. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4030. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4031. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4032. var srcPos = 0,
  4033. destPos;
  4034. var src = imgData.data;
  4035. var dest = chunkImgData.data;
  4036. var i, j, thisChunkHeight, elemsInThisChunk;
  4037. let transferMapRed, transferMapGreen, transferMapBlue, transferMapGray;
  4038. if (transferMaps) {
  4039. switch (transferMaps.length) {
  4040. case 1:
  4041. transferMapRed = transferMaps[0];
  4042. transferMapGreen = transferMaps[0];
  4043. transferMapBlue = transferMaps[0];
  4044. transferMapGray = transferMaps[0];
  4045. break;
  4046. case 4:
  4047. transferMapRed = transferMaps[0];
  4048. transferMapGreen = transferMaps[1];
  4049. transferMapBlue = transferMaps[2];
  4050. transferMapGray = transferMaps[3];
  4051. break;
  4052. }
  4053. }
  4054. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  4055. var srcLength = src.byteLength;
  4056. var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  4057. var dest32DataLength = dest32.length;
  4058. var fullSrcDiff = width + 7 >> 3;
  4059. var white = 0xffffffff;
  4060. var black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
  4061. if (transferMapGray) {
  4062. if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {
  4063. [white, black] = [black, white];
  4064. }
  4065. }
  4066. for (i = 0; i < totalChunks; i++) {
  4067. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4068. destPos = 0;
  4069. for (j = 0; j < thisChunkHeight; j++) {
  4070. var srcDiff = srcLength - srcPos;
  4071. let k = 0;
  4072. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  4073. var kEndUnrolled = kEnd & ~7;
  4074. var mask = 0;
  4075. var srcByte = 0;
  4076. for (; k < kEndUnrolled; k += 8) {
  4077. srcByte = src[srcPos++];
  4078. dest32[destPos++] = srcByte & 128 ? white : black;
  4079. dest32[destPos++] = srcByte & 64 ? white : black;
  4080. dest32[destPos++] = srcByte & 32 ? white : black;
  4081. dest32[destPos++] = srcByte & 16 ? white : black;
  4082. dest32[destPos++] = srcByte & 8 ? white : black;
  4083. dest32[destPos++] = srcByte & 4 ? white : black;
  4084. dest32[destPos++] = srcByte & 2 ? white : black;
  4085. dest32[destPos++] = srcByte & 1 ? white : black;
  4086. }
  4087. for (; k < kEnd; k++) {
  4088. if (mask === 0) {
  4089. srcByte = src[srcPos++];
  4090. mask = 128;
  4091. }
  4092. dest32[destPos++] = srcByte & mask ? white : black;
  4093. mask >>= 1;
  4094. }
  4095. }
  4096. while (destPos < dest32DataLength) {
  4097. dest32[destPos++] = 0;
  4098. }
  4099. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4100. }
  4101. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  4102. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4103. j = 0;
  4104. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  4105. for (i = 0; i < fullChunks; i++) {
  4106. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4107. srcPos += elemsInThisChunk;
  4108. if (hasTransferMaps) {
  4109. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4110. if (transferMapRed) {
  4111. dest[k + 0] = transferMapRed[dest[k + 0]];
  4112. }
  4113. if (transferMapGreen) {
  4114. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4115. }
  4116. if (transferMapBlue) {
  4117. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4118. }
  4119. }
  4120. }
  4121. ctx.putImageData(chunkImgData, 0, j);
  4122. j += FULL_CHUNK_HEIGHT;
  4123. }
  4124. if (i < totalChunks) {
  4125. elemsInThisChunk = width * partialChunkHeight * 4;
  4126. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  4127. if (hasTransferMaps) {
  4128. for (let k = 0; k < elemsInThisChunk; k += 4) {
  4129. if (transferMapRed) {
  4130. dest[k + 0] = transferMapRed[dest[k + 0]];
  4131. }
  4132. if (transferMapGreen) {
  4133. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4134. }
  4135. if (transferMapBlue) {
  4136. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4137. }
  4138. }
  4139. }
  4140. ctx.putImageData(chunkImgData, 0, j);
  4141. }
  4142. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  4143. const hasTransferMaps = !!(transferMapRed || transferMapGreen || transferMapBlue);
  4144. thisChunkHeight = FULL_CHUNK_HEIGHT;
  4145. elemsInThisChunk = width * thisChunkHeight;
  4146. for (i = 0; i < totalChunks; i++) {
  4147. if (i >= fullChunks) {
  4148. thisChunkHeight = partialChunkHeight;
  4149. elemsInThisChunk = width * thisChunkHeight;
  4150. }
  4151. destPos = 0;
  4152. for (j = elemsInThisChunk; j--;) {
  4153. dest[destPos++] = src[srcPos++];
  4154. dest[destPos++] = src[srcPos++];
  4155. dest[destPos++] = src[srcPos++];
  4156. dest[destPos++] = 255;
  4157. }
  4158. if (hasTransferMaps) {
  4159. for (let k = 0; k < destPos; k += 4) {
  4160. if (transferMapRed) {
  4161. dest[k + 0] = transferMapRed[dest[k + 0]];
  4162. }
  4163. if (transferMapGreen) {
  4164. dest[k + 1] = transferMapGreen[dest[k + 1]];
  4165. }
  4166. if (transferMapBlue) {
  4167. dest[k + 2] = transferMapBlue[dest[k + 2]];
  4168. }
  4169. }
  4170. }
  4171. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4172. }
  4173. } else {
  4174. throw new Error(`bad image kind: ${imgData.kind}`);
  4175. }
  4176. }
  4177. function putBinaryImageMask(ctx, imgData) {
  4178. var height = imgData.height,
  4179. width = imgData.width;
  4180. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  4181. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  4182. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  4183. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  4184. var srcPos = 0;
  4185. var src = imgData.data;
  4186. var dest = chunkImgData.data;
  4187. for (var i = 0; i < totalChunks; i++) {
  4188. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  4189. var destPos = 3;
  4190. for (var j = 0; j < thisChunkHeight; j++) {
  4191. var mask = 0;
  4192. for (var k = 0; k < width; k++) {
  4193. if (!mask) {
  4194. var elem = src[srcPos++];
  4195. mask = 128;
  4196. }
  4197. dest[destPos] = elem & mask ? 0 : 255;
  4198. destPos += 4;
  4199. mask >>= 1;
  4200. }
  4201. }
  4202. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  4203. }
  4204. }
  4205. function copyCtxState(sourceCtx, destCtx) {
  4206. var properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  4207. for (var i = 0, ii = properties.length; i < ii; i++) {
  4208. var property = properties[i];
  4209. if (sourceCtx[property] !== undefined) {
  4210. destCtx[property] = sourceCtx[property];
  4211. }
  4212. }
  4213. if (sourceCtx.setLineDash !== undefined) {
  4214. destCtx.setLineDash(sourceCtx.getLineDash());
  4215. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  4216. }
  4217. }
  4218. function resetCtxToDefault(ctx) {
  4219. ctx.strokeStyle = "#000000";
  4220. ctx.fillStyle = "#000000";
  4221. ctx.fillRule = "nonzero";
  4222. ctx.globalAlpha = 1;
  4223. ctx.lineWidth = 1;
  4224. ctx.lineCap = "butt";
  4225. ctx.lineJoin = "miter";
  4226. ctx.miterLimit = 10;
  4227. ctx.globalCompositeOperation = "source-over";
  4228. ctx.font = "10px sans-serif";
  4229. if (ctx.setLineDash !== undefined) {
  4230. ctx.setLineDash([]);
  4231. ctx.lineDashOffset = 0;
  4232. }
  4233. }
  4234. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  4235. var length = bytes.length;
  4236. for (var i = 3; i < length; i += 4) {
  4237. var alpha = bytes[i];
  4238. if (alpha === 0) {
  4239. bytes[i - 3] = r0;
  4240. bytes[i - 2] = g0;
  4241. bytes[i - 1] = b0;
  4242. } else if (alpha < 255) {
  4243. var alpha_ = 255 - alpha;
  4244. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  4245. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  4246. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  4247. }
  4248. }
  4249. }
  4250. function composeSMaskAlpha(maskData, layerData, transferMap) {
  4251. var length = maskData.length;
  4252. var scale = 1 / 255;
  4253. for (var i = 3; i < length; i += 4) {
  4254. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  4255. layerData[i] = layerData[i] * alpha * scale | 0;
  4256. }
  4257. }
  4258. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  4259. var length = maskData.length;
  4260. for (var i = 3; i < length; i += 4) {
  4261. var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  4262. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  4263. }
  4264. }
  4265. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  4266. var hasBackdrop = !!backdrop;
  4267. var r0 = hasBackdrop ? backdrop[0] : 0;
  4268. var g0 = hasBackdrop ? backdrop[1] : 0;
  4269. var b0 = hasBackdrop ? backdrop[2] : 0;
  4270. var composeFn;
  4271. if (subtype === "Luminosity") {
  4272. composeFn = composeSMaskLuminosity;
  4273. } else {
  4274. composeFn = composeSMaskAlpha;
  4275. }
  4276. var PIXELS_TO_PROCESS = 1048576;
  4277. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  4278. for (var row = 0; row < height; row += chunkSize) {
  4279. var chunkHeight = Math.min(chunkSize, height - row);
  4280. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  4281. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  4282. if (hasBackdrop) {
  4283. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  4284. }
  4285. composeFn(maskData.data, layerData.data, transferMap);
  4286. maskCtx.putImageData(layerData, 0, row);
  4287. }
  4288. }
  4289. function composeSMask(ctx, smask, layerCtx, webGLContext) {
  4290. var mask = smask.canvas;
  4291. var maskCtx = smask.context;
  4292. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  4293. var backdrop = smask.backdrop || null;
  4294. if (!smask.transferMap && webGLContext.isEnabled) {
  4295. const composed = webGLContext.composeSMask({
  4296. layer: layerCtx.canvas,
  4297. mask,
  4298. properties: {
  4299. subtype: smask.subtype,
  4300. backdrop
  4301. }
  4302. });
  4303. ctx.setTransform(1, 0, 0, 1, 0, 0);
  4304. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  4305. return;
  4306. }
  4307. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  4308. ctx.drawImage(mask, 0, 0);
  4309. }
  4310. var LINE_CAP_STYLES = ["butt", "round", "square"];
  4311. var LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  4312. var NORMAL_CLIP = {};
  4313. var EO_CLIP = {};
  4314. CanvasGraphics.prototype = {
  4315. beginDrawing({
  4316. transform,
  4317. viewport,
  4318. transparency = false,
  4319. background = null
  4320. }) {
  4321. var width = this.ctx.canvas.width;
  4322. var height = this.ctx.canvas.height;
  4323. this.ctx.save();
  4324. this.ctx.fillStyle = background || "rgb(255, 255, 255)";
  4325. this.ctx.fillRect(0, 0, width, height);
  4326. this.ctx.restore();
  4327. if (transparency) {
  4328. var transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  4329. this.compositeCtx = this.ctx;
  4330. this.transparentCanvas = transparentCanvas.canvas;
  4331. this.ctx = transparentCanvas.context;
  4332. this.ctx.save();
  4333. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  4334. }
  4335. this.ctx.save();
  4336. resetCtxToDefault(this.ctx);
  4337. if (transform) {
  4338. this.ctx.transform.apply(this.ctx, transform);
  4339. }
  4340. this.ctx.transform.apply(this.ctx, viewport.transform);
  4341. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4342. if (this.imageLayer) {
  4343. this.imageLayer.beginLayout();
  4344. }
  4345. },
  4346. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4347. var argsArray = operatorList.argsArray;
  4348. var fnArray = operatorList.fnArray;
  4349. var i = executionStartIdx || 0;
  4350. var argsArrayLen = argsArray.length;
  4351. if (argsArrayLen === i) {
  4352. return i;
  4353. }
  4354. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4355. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4356. var steps = 0;
  4357. var commonObjs = this.commonObjs;
  4358. var objs = this.objs;
  4359. var fnId;
  4360. while (true) {
  4361. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4362. stepper.breakIt(i, continueCallback);
  4363. return i;
  4364. }
  4365. fnId = fnArray[i];
  4366. if (fnId !== _util.OPS.dependency) {
  4367. this[fnId].apply(this, argsArray[i]);
  4368. } else {
  4369. for (const depObjId of argsArray[i]) {
  4370. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4371. if (!objsPool.has(depObjId)) {
  4372. objsPool.get(depObjId, continueCallback);
  4373. return i;
  4374. }
  4375. }
  4376. }
  4377. i++;
  4378. if (i === argsArrayLen) {
  4379. return i;
  4380. }
  4381. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4382. if (Date.now() > endTime) {
  4383. continueCallback();
  4384. return i;
  4385. }
  4386. steps = 0;
  4387. }
  4388. }
  4389. },
  4390. endDrawing: function CanvasGraphics_endDrawing() {
  4391. if (this.current.activeSMask !== null) {
  4392. this.endSMaskGroup();
  4393. }
  4394. this.ctx.restore();
  4395. if (this.transparentCanvas) {
  4396. this.ctx = this.compositeCtx;
  4397. this.ctx.save();
  4398. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4399. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4400. this.ctx.restore();
  4401. this.transparentCanvas = null;
  4402. }
  4403. this.cachedCanvases.clear();
  4404. this.webGLContext.clear();
  4405. if (this.imageLayer) {
  4406. this.imageLayer.endLayout();
  4407. }
  4408. },
  4409. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4410. this.current.lineWidth = width;
  4411. this.ctx.lineWidth = width;
  4412. },
  4413. setLineCap: function CanvasGraphics_setLineCap(style) {
  4414. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4415. },
  4416. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4417. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4418. },
  4419. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4420. this.ctx.miterLimit = limit;
  4421. },
  4422. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4423. var ctx = this.ctx;
  4424. if (ctx.setLineDash !== undefined) {
  4425. ctx.setLineDash(dashArray);
  4426. ctx.lineDashOffset = dashPhase;
  4427. }
  4428. },
  4429. setRenderingIntent(intent) {},
  4430. setFlatness(flatness) {},
  4431. setGState: function CanvasGraphics_setGState(states) {
  4432. for (var i = 0, ii = states.length; i < ii; i++) {
  4433. var state = states[i];
  4434. var key = state[0];
  4435. var value = state[1];
  4436. switch (key) {
  4437. case "LW":
  4438. this.setLineWidth(value);
  4439. break;
  4440. case "LC":
  4441. this.setLineCap(value);
  4442. break;
  4443. case "LJ":
  4444. this.setLineJoin(value);
  4445. break;
  4446. case "ML":
  4447. this.setMiterLimit(value);
  4448. break;
  4449. case "D":
  4450. this.setDash(value[0], value[1]);
  4451. break;
  4452. case "RI":
  4453. this.setRenderingIntent(value);
  4454. break;
  4455. case "FL":
  4456. this.setFlatness(value);
  4457. break;
  4458. case "Font":
  4459. this.setFont(value[0], value[1]);
  4460. break;
  4461. case "CA":
  4462. this.current.strokeAlpha = state[1];
  4463. break;
  4464. case "ca":
  4465. this.current.fillAlpha = state[1];
  4466. this.ctx.globalAlpha = state[1];
  4467. break;
  4468. case "BM":
  4469. this.ctx.globalCompositeOperation = value;
  4470. break;
  4471. case "SMask":
  4472. if (this.current.activeSMask) {
  4473. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  4474. this.suspendSMaskGroup();
  4475. } else {
  4476. this.endSMaskGroup();
  4477. }
  4478. }
  4479. this.current.activeSMask = value ? this.tempSMask : null;
  4480. if (this.current.activeSMask) {
  4481. this.beginSMaskGroup();
  4482. }
  4483. this.tempSMask = null;
  4484. break;
  4485. case "TR":
  4486. this.current.transferMaps = value;
  4487. }
  4488. }
  4489. },
  4490. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4491. var activeSMask = this.current.activeSMask;
  4492. var drawnWidth = activeSMask.canvas.width;
  4493. var drawnHeight = activeSMask.canvas.height;
  4494. var cacheId = "smaskGroupAt" + this.groupLevel;
  4495. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4496. var currentCtx = this.ctx;
  4497. var currentTransform = currentCtx.mozCurrentTransform;
  4498. this.ctx.save();
  4499. var groupCtx = scratchCanvas.context;
  4500. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4501. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4502. groupCtx.transform.apply(groupCtx, currentTransform);
  4503. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  4504. copyCtxState(currentCtx, groupCtx);
  4505. this.ctx = groupCtx;
  4506. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4507. this.groupStack.push(currentCtx);
  4508. this.groupLevel++;
  4509. },
  4510. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4511. var groupCtx = this.ctx;
  4512. this.groupLevel--;
  4513. this.ctx = this.groupStack.pop();
  4514. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4515. this.ctx.restore();
  4516. this.ctx.save();
  4517. copyCtxState(groupCtx, this.ctx);
  4518. this.current.resumeSMaskCtx = groupCtx;
  4519. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4520. this.ctx.transform.apply(this.ctx, deltaTransform);
  4521. groupCtx.save();
  4522. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  4523. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  4524. groupCtx.restore();
  4525. },
  4526. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4527. var groupCtx = this.current.resumeSMaskCtx;
  4528. var currentCtx = this.ctx;
  4529. this.ctx = groupCtx;
  4530. this.groupStack.push(currentCtx);
  4531. this.groupLevel++;
  4532. },
  4533. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4534. var groupCtx = this.ctx;
  4535. this.groupLevel--;
  4536. this.ctx = this.groupStack.pop();
  4537. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4538. this.ctx.restore();
  4539. copyCtxState(groupCtx, this.ctx);
  4540. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4541. this.ctx.transform.apply(this.ctx, deltaTransform);
  4542. },
  4543. save: function CanvasGraphics_save() {
  4544. this.ctx.save();
  4545. var old = this.current;
  4546. this.stateStack.push(old);
  4547. this.current = old.clone();
  4548. this.current.resumeSMaskCtx = null;
  4549. },
  4550. restore: function CanvasGraphics_restore() {
  4551. if (this.current.resumeSMaskCtx) {
  4552. this.resumeSMaskGroup();
  4553. }
  4554. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  4555. this.endSMaskGroup();
  4556. }
  4557. if (this.stateStack.length !== 0) {
  4558. this.current = this.stateStack.pop();
  4559. this.ctx.restore();
  4560. this.pendingClip = null;
  4561. this._cachedGetSinglePixelWidth = null;
  4562. }
  4563. },
  4564. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4565. this.ctx.transform(a, b, c, d, e, f);
  4566. this._cachedGetSinglePixelWidth = null;
  4567. },
  4568. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4569. var ctx = this.ctx;
  4570. var current = this.current;
  4571. var x = current.x,
  4572. y = current.y;
  4573. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4574. switch (ops[i] | 0) {
  4575. case _util.OPS.rectangle:
  4576. x = args[j++];
  4577. y = args[j++];
  4578. var width = args[j++];
  4579. var height = args[j++];
  4580. if (width === 0 && ctx.lineWidth < this.getSinglePixelWidth()) {
  4581. width = this.getSinglePixelWidth();
  4582. }
  4583. if (height === 0 && ctx.lineWidth < this.getSinglePixelWidth()) {
  4584. height = this.getSinglePixelWidth();
  4585. }
  4586. var xw = x + width;
  4587. var yh = y + height;
  4588. ctx.moveTo(x, y);
  4589. ctx.lineTo(xw, y);
  4590. ctx.lineTo(xw, yh);
  4591. ctx.lineTo(x, yh);
  4592. ctx.lineTo(x, y);
  4593. ctx.closePath();
  4594. break;
  4595. case _util.OPS.moveTo:
  4596. x = args[j++];
  4597. y = args[j++];
  4598. ctx.moveTo(x, y);
  4599. break;
  4600. case _util.OPS.lineTo:
  4601. x = args[j++];
  4602. y = args[j++];
  4603. ctx.lineTo(x, y);
  4604. break;
  4605. case _util.OPS.curveTo:
  4606. x = args[j + 4];
  4607. y = args[j + 5];
  4608. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  4609. j += 6;
  4610. break;
  4611. case _util.OPS.curveTo2:
  4612. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  4613. x = args[j + 2];
  4614. y = args[j + 3];
  4615. j += 4;
  4616. break;
  4617. case _util.OPS.curveTo3:
  4618. x = args[j + 2];
  4619. y = args[j + 3];
  4620. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4621. j += 4;
  4622. break;
  4623. case _util.OPS.closePath:
  4624. ctx.closePath();
  4625. break;
  4626. }
  4627. }
  4628. current.setCurrentPoint(x, y);
  4629. },
  4630. closePath: function CanvasGraphics_closePath() {
  4631. this.ctx.closePath();
  4632. },
  4633. stroke: function CanvasGraphics_stroke(consumePath) {
  4634. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4635. var ctx = this.ctx;
  4636. var strokeColor = this.current.strokeColor;
  4637. ctx.globalAlpha = this.current.strokeAlpha;
  4638. if (this.contentVisible) {
  4639. if (strokeColor && strokeColor.hasOwnProperty("type") && strokeColor.type === "Pattern") {
  4640. ctx.save();
  4641. const transform = ctx.mozCurrentTransform;
  4642. const scale = _util.Util.singularValueDecompose2dScale(transform)[0];
  4643. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4644. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth * scale);
  4645. ctx.stroke();
  4646. ctx.restore();
  4647. } else {
  4648. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  4649. ctx.stroke();
  4650. }
  4651. }
  4652. if (consumePath) {
  4653. this.consumePath();
  4654. }
  4655. ctx.globalAlpha = this.current.fillAlpha;
  4656. },
  4657. closeStroke: function CanvasGraphics_closeStroke() {
  4658. this.closePath();
  4659. this.stroke();
  4660. },
  4661. fill: function CanvasGraphics_fill(consumePath) {
  4662. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4663. var ctx = this.ctx;
  4664. var fillColor = this.current.fillColor;
  4665. var isPatternFill = this.current.patternFill;
  4666. var needRestore = false;
  4667. if (isPatternFill) {
  4668. ctx.save();
  4669. if (this.baseTransform) {
  4670. ctx.setTransform.apply(ctx, this.baseTransform);
  4671. }
  4672. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4673. needRestore = true;
  4674. }
  4675. if (this.contentVisible) {
  4676. if (this.pendingEOFill) {
  4677. ctx.fill("evenodd");
  4678. this.pendingEOFill = false;
  4679. } else {
  4680. ctx.fill();
  4681. }
  4682. }
  4683. if (needRestore) {
  4684. ctx.restore();
  4685. }
  4686. if (consumePath) {
  4687. this.consumePath();
  4688. }
  4689. },
  4690. eoFill: function CanvasGraphics_eoFill() {
  4691. this.pendingEOFill = true;
  4692. this.fill();
  4693. },
  4694. fillStroke: function CanvasGraphics_fillStroke() {
  4695. this.fill(false);
  4696. this.stroke(false);
  4697. this.consumePath();
  4698. },
  4699. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4700. this.pendingEOFill = true;
  4701. this.fillStroke();
  4702. },
  4703. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4704. this.closePath();
  4705. this.fillStroke();
  4706. },
  4707. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4708. this.pendingEOFill = true;
  4709. this.closePath();
  4710. this.fillStroke();
  4711. },
  4712. endPath: function CanvasGraphics_endPath() {
  4713. this.consumePath();
  4714. },
  4715. clip: function CanvasGraphics_clip() {
  4716. this.pendingClip = NORMAL_CLIP;
  4717. },
  4718. eoClip: function CanvasGraphics_eoClip() {
  4719. this.pendingClip = EO_CLIP;
  4720. },
  4721. beginText: function CanvasGraphics_beginText() {
  4722. this.current.textMatrix = _util.IDENTITY_MATRIX;
  4723. this.current.textMatrixScale = 1;
  4724. this.current.x = this.current.lineX = 0;
  4725. this.current.y = this.current.lineY = 0;
  4726. },
  4727. endText: function CanvasGraphics_endText() {
  4728. var paths = this.pendingTextPaths;
  4729. var ctx = this.ctx;
  4730. if (paths === undefined) {
  4731. ctx.beginPath();
  4732. return;
  4733. }
  4734. ctx.save();
  4735. ctx.beginPath();
  4736. for (var i = 0; i < paths.length; i++) {
  4737. var path = paths[i];
  4738. ctx.setTransform.apply(ctx, path.transform);
  4739. ctx.translate(path.x, path.y);
  4740. path.addToPath(ctx, path.fontSize);
  4741. }
  4742. ctx.restore();
  4743. ctx.clip();
  4744. ctx.beginPath();
  4745. delete this.pendingTextPaths;
  4746. },
  4747. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4748. this.current.charSpacing = spacing;
  4749. },
  4750. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4751. this.current.wordSpacing = spacing;
  4752. },
  4753. setHScale: function CanvasGraphics_setHScale(scale) {
  4754. this.current.textHScale = scale / 100;
  4755. },
  4756. setLeading: function CanvasGraphics_setLeading(leading) {
  4757. this.current.leading = -leading;
  4758. },
  4759. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4760. var fontObj = this.commonObjs.get(fontRefName);
  4761. var current = this.current;
  4762. if (!fontObj) {
  4763. throw new Error(`Can't find font for ${fontRefName}`);
  4764. }
  4765. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  4766. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  4767. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  4768. }
  4769. if (size < 0) {
  4770. size = -size;
  4771. current.fontDirection = -1;
  4772. } else {
  4773. current.fontDirection = 1;
  4774. }
  4775. this.current.font = fontObj;
  4776. this.current.fontSize = size;
  4777. if (fontObj.isType3Font) {
  4778. return;
  4779. }
  4780. var name = fontObj.loadedName || "sans-serif";
  4781. let bold = "normal";
  4782. if (fontObj.black) {
  4783. bold = "900";
  4784. } else if (fontObj.bold) {
  4785. bold = "bold";
  4786. }
  4787. var italic = fontObj.italic ? "italic" : "normal";
  4788. var typeface = `"${name}", ${fontObj.fallbackName}`;
  4789. let browserFontSize = size;
  4790. if (size < MIN_FONT_SIZE) {
  4791. browserFontSize = MIN_FONT_SIZE;
  4792. } else if (size > MAX_FONT_SIZE) {
  4793. browserFontSize = MAX_FONT_SIZE;
  4794. }
  4795. this.current.fontSizeScale = size / browserFontSize;
  4796. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  4797. },
  4798. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4799. this.current.textRenderingMode = mode;
  4800. },
  4801. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4802. this.current.textRise = rise;
  4803. },
  4804. moveText: function CanvasGraphics_moveText(x, y) {
  4805. this.current.x = this.current.lineX += x;
  4806. this.current.y = this.current.lineY += y;
  4807. },
  4808. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4809. this.setLeading(-y);
  4810. this.moveText(x, y);
  4811. },
  4812. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4813. this.current.textMatrix = [a, b, c, d, e, f];
  4814. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4815. this.current.x = this.current.lineX = 0;
  4816. this.current.y = this.current.lineY = 0;
  4817. },
  4818. nextLine: function CanvasGraphics_nextLine() {
  4819. this.moveText(0, this.current.leading);
  4820. },
  4821. paintChar(character, x, y, patternTransform) {
  4822. var ctx = this.ctx;
  4823. var current = this.current;
  4824. var font = current.font;
  4825. var textRenderingMode = current.textRenderingMode;
  4826. var fontSize = current.fontSize / current.fontSizeScale;
  4827. var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4828. var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  4829. const patternFill = current.patternFill && !font.missingFile;
  4830. var addToPath;
  4831. if (font.disableFontFace || isAddToPathSet || patternFill) {
  4832. addToPath = font.getPathGenerator(this.commonObjs, character);
  4833. }
  4834. if (font.disableFontFace || patternFill) {
  4835. ctx.save();
  4836. ctx.translate(x, y);
  4837. ctx.beginPath();
  4838. addToPath(ctx, fontSize);
  4839. if (patternTransform) {
  4840. ctx.setTransform.apply(ctx, patternTransform);
  4841. }
  4842. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4843. ctx.fill();
  4844. }
  4845. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4846. ctx.stroke();
  4847. }
  4848. ctx.restore();
  4849. } else {
  4850. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4851. ctx.fillText(character, x, y);
  4852. }
  4853. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4854. ctx.strokeText(character, x, y);
  4855. }
  4856. }
  4857. if (isAddToPathSet) {
  4858. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4859. paths.push({
  4860. transform: ctx.mozCurrentTransform,
  4861. x,
  4862. y,
  4863. fontSize,
  4864. addToPath
  4865. });
  4866. }
  4867. },
  4868. get isFontSubpixelAAEnabled() {
  4869. const {
  4870. context: ctx
  4871. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  4872. ctx.scale(1.5, 1);
  4873. ctx.fillText("I", 0, 10);
  4874. var data = ctx.getImageData(0, 0, 10, 10).data;
  4875. var enabled = false;
  4876. for (var i = 3; i < data.length; i += 4) {
  4877. if (data[i] > 0 && data[i] < 255) {
  4878. enabled = true;
  4879. break;
  4880. }
  4881. }
  4882. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  4883. },
  4884. showText: function CanvasGraphics_showText(glyphs) {
  4885. var current = this.current;
  4886. var font = current.font;
  4887. if (font.isType3Font) {
  4888. return this.showType3Text(glyphs);
  4889. }
  4890. var fontSize = current.fontSize;
  4891. if (fontSize === 0) {
  4892. return undefined;
  4893. }
  4894. var ctx = this.ctx;
  4895. var fontSizeScale = current.fontSizeScale;
  4896. var charSpacing = current.charSpacing;
  4897. var wordSpacing = current.wordSpacing;
  4898. var fontDirection = current.fontDirection;
  4899. var textHScale = current.textHScale * fontDirection;
  4900. var glyphsLength = glyphs.length;
  4901. var vertical = font.vertical;
  4902. var spacingDir = vertical ? 1 : -1;
  4903. var defaultVMetrics = font.defaultVMetrics;
  4904. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4905. var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  4906. ctx.save();
  4907. let patternTransform;
  4908. if (current.patternFill) {
  4909. ctx.save();
  4910. const pattern = current.fillColor.getPattern(ctx, this);
  4911. patternTransform = ctx.mozCurrentTransform;
  4912. ctx.restore();
  4913. ctx.fillStyle = pattern;
  4914. }
  4915. ctx.transform.apply(ctx, current.textMatrix);
  4916. ctx.translate(current.x, current.y + current.textRise);
  4917. if (fontDirection > 0) {
  4918. ctx.scale(textHScale, -1);
  4919. } else {
  4920. ctx.scale(textHScale, 1);
  4921. }
  4922. var lineWidth = current.lineWidth;
  4923. var scale = current.textMatrixScale;
  4924. if (scale === 0 || lineWidth === 0) {
  4925. var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4926. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4927. this._cachedGetSinglePixelWidth = null;
  4928. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4929. }
  4930. } else {
  4931. lineWidth /= scale;
  4932. }
  4933. if (fontSizeScale !== 1.0) {
  4934. ctx.scale(fontSizeScale, fontSizeScale);
  4935. lineWidth /= fontSizeScale;
  4936. }
  4937. ctx.lineWidth = lineWidth;
  4938. var x = 0,
  4939. i;
  4940. for (i = 0; i < glyphsLength; ++i) {
  4941. var glyph = glyphs[i];
  4942. if ((0, _util.isNum)(glyph)) {
  4943. x += spacingDir * glyph * fontSize / 1000;
  4944. continue;
  4945. }
  4946. var restoreNeeded = false;
  4947. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4948. var character = glyph.fontChar;
  4949. var accent = glyph.accent;
  4950. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4951. var width = glyph.width;
  4952. if (vertical) {
  4953. var vmetric, vx, vy;
  4954. vmetric = glyph.vmetric || defaultVMetrics;
  4955. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4956. vx = -vx * widthAdvanceScale;
  4957. vy = vmetric[2] * widthAdvanceScale;
  4958. width = vmetric ? -vmetric[0] : width;
  4959. scaledX = vx / fontSizeScale;
  4960. scaledY = (x + vy) / fontSizeScale;
  4961. } else {
  4962. scaledX = x / fontSizeScale;
  4963. scaledY = 0;
  4964. }
  4965. if (font.remeasure && width > 0) {
  4966. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  4967. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  4968. var characterScaleX = width / measuredWidth;
  4969. restoreNeeded = true;
  4970. ctx.save();
  4971. ctx.scale(characterScaleX, 1);
  4972. scaledX /= characterScaleX;
  4973. } else if (width !== measuredWidth) {
  4974. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  4975. }
  4976. }
  4977. if (this.contentVisible && (glyph.isInFont || font.missingFile)) {
  4978. if (simpleFillText && !accent) {
  4979. ctx.fillText(character, scaledX, scaledY);
  4980. } else {
  4981. this.paintChar(character, scaledX, scaledY, patternTransform);
  4982. if (accent) {
  4983. scaledAccentX = scaledX + fontSize * accent.offset.x / fontSizeScale;
  4984. scaledAccentY = scaledY - fontSize * accent.offset.y / fontSizeScale;
  4985. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  4986. }
  4987. }
  4988. }
  4989. var charWidth;
  4990. if (vertical) {
  4991. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  4992. } else {
  4993. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4994. }
  4995. x += charWidth;
  4996. if (restoreNeeded) {
  4997. ctx.restore();
  4998. }
  4999. }
  5000. if (vertical) {
  5001. current.y -= x;
  5002. } else {
  5003. current.x += x * textHScale;
  5004. }
  5005. ctx.restore();
  5006. },
  5007. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  5008. var ctx = this.ctx;
  5009. var current = this.current;
  5010. var font = current.font;
  5011. var fontSize = current.fontSize;
  5012. var fontDirection = current.fontDirection;
  5013. var spacingDir = font.vertical ? 1 : -1;
  5014. var charSpacing = current.charSpacing;
  5015. var wordSpacing = current.wordSpacing;
  5016. var textHScale = current.textHScale * fontDirection;
  5017. var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  5018. var glyphsLength = glyphs.length;
  5019. var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  5020. var i, glyph, width, spacingLength;
  5021. if (isTextInvisible || fontSize === 0) {
  5022. return;
  5023. }
  5024. this._cachedGetSinglePixelWidth = null;
  5025. ctx.save();
  5026. ctx.transform.apply(ctx, current.textMatrix);
  5027. ctx.translate(current.x, current.y);
  5028. ctx.scale(textHScale, fontDirection);
  5029. for (i = 0; i < glyphsLength; ++i) {
  5030. glyph = glyphs[i];
  5031. if ((0, _util.isNum)(glyph)) {
  5032. spacingLength = spacingDir * glyph * fontSize / 1000;
  5033. this.ctx.translate(spacingLength, 0);
  5034. current.x += spacingLength * textHScale;
  5035. continue;
  5036. }
  5037. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  5038. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  5039. if (!operatorList) {
  5040. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  5041. continue;
  5042. }
  5043. if (this.contentVisible) {
  5044. this.processingType3 = glyph;
  5045. this.save();
  5046. ctx.scale(fontSize, fontSize);
  5047. ctx.transform.apply(ctx, fontMatrix);
  5048. this.executeOperatorList(operatorList);
  5049. this.restore();
  5050. }
  5051. var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  5052. width = transformed[0] * fontSize + spacing;
  5053. ctx.translate(width, 0);
  5054. current.x += width * textHScale;
  5055. }
  5056. ctx.restore();
  5057. this.processingType3 = null;
  5058. },
  5059. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
  5060. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  5061. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  5062. this.clip();
  5063. this.endPath();
  5064. },
  5065. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  5066. var pattern;
  5067. if (IR[0] === "TilingPattern") {
  5068. var color = IR[1];
  5069. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  5070. var canvasGraphicsFactory = {
  5071. createCanvasGraphics: ctx => {
  5072. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext);
  5073. }
  5074. };
  5075. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  5076. } else {
  5077. pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
  5078. }
  5079. return pattern;
  5080. },
  5081. setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
  5082. this.current.strokeColor = this.getColorN_Pattern(arguments);
  5083. },
  5084. setFillColorN: function CanvasGraphics_setFillColorN() {
  5085. this.current.fillColor = this.getColorN_Pattern(arguments);
  5086. this.current.patternFill = true;
  5087. },
  5088. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  5089. var color = _util.Util.makeCssRgb(r, g, b);
  5090. this.ctx.strokeStyle = color;
  5091. this.current.strokeColor = color;
  5092. },
  5093. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  5094. var color = _util.Util.makeCssRgb(r, g, b);
  5095. this.ctx.fillStyle = color;
  5096. this.current.fillColor = color;
  5097. this.current.patternFill = false;
  5098. },
  5099. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  5100. if (!this.contentVisible) {
  5101. return;
  5102. }
  5103. var ctx = this.ctx;
  5104. this.save();
  5105. var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
  5106. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  5107. var inv = ctx.mozCurrentTransformInverse;
  5108. if (inv) {
  5109. var canvas = ctx.canvas;
  5110. var width = canvas.width;
  5111. var height = canvas.height;
  5112. var bl = _util.Util.applyTransform([0, 0], inv);
  5113. var br = _util.Util.applyTransform([0, height], inv);
  5114. var ul = _util.Util.applyTransform([width, 0], inv);
  5115. var ur = _util.Util.applyTransform([width, height], inv);
  5116. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  5117. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  5118. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  5119. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  5120. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  5121. } else {
  5122. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  5123. }
  5124. this.restore();
  5125. },
  5126. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  5127. (0, _util.unreachable)("Should not call beginInlineImage");
  5128. },
  5129. beginImageData: function CanvasGraphics_beginImageData() {
  5130. (0, _util.unreachable)("Should not call beginImageData");
  5131. },
  5132. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  5133. if (!this.contentVisible) {
  5134. return;
  5135. }
  5136. this.save();
  5137. this.baseTransformStack.push(this.baseTransform);
  5138. if (Array.isArray(matrix) && matrix.length === 6) {
  5139. this.transform.apply(this, matrix);
  5140. }
  5141. this.baseTransform = this.ctx.mozCurrentTransform;
  5142. if (bbox) {
  5143. var width = bbox[2] - bbox[0];
  5144. var height = bbox[3] - bbox[1];
  5145. this.ctx.rect(bbox[0], bbox[1], width, height);
  5146. this.clip();
  5147. this.endPath();
  5148. }
  5149. },
  5150. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  5151. if (!this.contentVisible) {
  5152. return;
  5153. }
  5154. this.restore();
  5155. this.baseTransform = this.baseTransformStack.pop();
  5156. },
  5157. beginGroup: function CanvasGraphics_beginGroup(group) {
  5158. if (!this.contentVisible) {
  5159. return;
  5160. }
  5161. this.save();
  5162. var currentCtx = this.ctx;
  5163. if (!group.isolated) {
  5164. (0, _util.info)("TODO: Support non-isolated groups.");
  5165. }
  5166. if (group.knockout) {
  5167. (0, _util.warn)("Knockout groups not supported.");
  5168. }
  5169. var currentTransform = currentCtx.mozCurrentTransform;
  5170. if (group.matrix) {
  5171. currentCtx.transform.apply(currentCtx, group.matrix);
  5172. }
  5173. if (!group.bbox) {
  5174. throw new Error("Bounding box is required.");
  5175. }
  5176. var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  5177. var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  5178. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  5179. var offsetX = Math.floor(bounds[0]);
  5180. var offsetY = Math.floor(bounds[1]);
  5181. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  5182. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  5183. var scaleX = 1,
  5184. scaleY = 1;
  5185. if (drawnWidth > MAX_GROUP_SIZE) {
  5186. scaleX = drawnWidth / MAX_GROUP_SIZE;
  5187. drawnWidth = MAX_GROUP_SIZE;
  5188. }
  5189. if (drawnHeight > MAX_GROUP_SIZE) {
  5190. scaleY = drawnHeight / MAX_GROUP_SIZE;
  5191. drawnHeight = MAX_GROUP_SIZE;
  5192. }
  5193. var cacheId = "groupAt" + this.groupLevel;
  5194. if (group.smask) {
  5195. cacheId += "_smask_" + this.smaskCounter++ % 2;
  5196. }
  5197. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  5198. var groupCtx = scratchCanvas.context;
  5199. groupCtx.scale(1 / scaleX, 1 / scaleY);
  5200. groupCtx.translate(-offsetX, -offsetY);
  5201. groupCtx.transform.apply(groupCtx, currentTransform);
  5202. if (group.smask) {
  5203. this.smaskStack.push({
  5204. canvas: scratchCanvas.canvas,
  5205. context: groupCtx,
  5206. offsetX,
  5207. offsetY,
  5208. scaleX,
  5209. scaleY,
  5210. subtype: group.smask.subtype,
  5211. backdrop: group.smask.backdrop,
  5212. transferMap: group.smask.transferMap || null,
  5213. startTransformInverse: null
  5214. });
  5215. } else {
  5216. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  5217. currentCtx.translate(offsetX, offsetY);
  5218. currentCtx.scale(scaleX, scaleY);
  5219. }
  5220. copyCtxState(currentCtx, groupCtx);
  5221. this.ctx = groupCtx;
  5222. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  5223. this.groupStack.push(currentCtx);
  5224. this.groupLevel++;
  5225. this.current.activeSMask = null;
  5226. },
  5227. endGroup: function CanvasGraphics_endGroup(group) {
  5228. if (!this.contentVisible) {
  5229. return;
  5230. }
  5231. this.groupLevel--;
  5232. var groupCtx = this.ctx;
  5233. this.ctx = this.groupStack.pop();
  5234. if (this.ctx.imageSmoothingEnabled !== undefined) {
  5235. this.ctx.imageSmoothingEnabled = false;
  5236. } else {
  5237. this.ctx.mozImageSmoothingEnabled = false;
  5238. }
  5239. if (group.smask) {
  5240. this.tempSMask = this.smaskStack.pop();
  5241. } else {
  5242. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  5243. }
  5244. this.restore();
  5245. },
  5246. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  5247. this.save();
  5248. if (this.baseTransform) {
  5249. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  5250. }
  5251. },
  5252. endAnnotations: function CanvasGraphics_endAnnotations() {
  5253. this.restore();
  5254. },
  5255. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  5256. this.save();
  5257. resetCtxToDefault(this.ctx);
  5258. this.current = new CanvasExtraState();
  5259. if (Array.isArray(rect) && rect.length === 4) {
  5260. var width = rect[2] - rect[0];
  5261. var height = rect[3] - rect[1];
  5262. this.ctx.rect(rect[0], rect[1], width, height);
  5263. this.clip();
  5264. this.endPath();
  5265. }
  5266. this.transform.apply(this, transform);
  5267. this.transform.apply(this, matrix);
  5268. },
  5269. endAnnotation: function CanvasGraphics_endAnnotation() {
  5270. this.restore();
  5271. },
  5272. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  5273. if (!this.contentVisible) {
  5274. return;
  5275. }
  5276. var ctx = this.ctx;
  5277. var width = img.width,
  5278. height = img.height;
  5279. var fillColor = this.current.fillColor;
  5280. var isPatternFill = this.current.patternFill;
  5281. var glyph = this.processingType3;
  5282. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  5283. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  5284. glyph.compiled = compileType3Glyph({
  5285. data: img.data,
  5286. width,
  5287. height
  5288. });
  5289. } else {
  5290. glyph.compiled = null;
  5291. }
  5292. }
  5293. if (glyph && glyph.compiled) {
  5294. glyph.compiled(ctx);
  5295. return;
  5296. }
  5297. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5298. var maskCtx = maskCanvas.context;
  5299. maskCtx.save();
  5300. putBinaryImageMask(maskCtx, img);
  5301. maskCtx.globalCompositeOperation = "source-in";
  5302. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5303. maskCtx.fillRect(0, 0, width, height);
  5304. maskCtx.restore();
  5305. this.paintInlineImageXObject(maskCanvas.canvas);
  5306. },
  5307. paintImageMaskXObjectRepeat(imgData, scaleX, skewX = 0, skewY = 0, scaleY, positions) {
  5308. if (!this.contentVisible) {
  5309. return;
  5310. }
  5311. var width = imgData.width;
  5312. var height = imgData.height;
  5313. var fillColor = this.current.fillColor;
  5314. var isPatternFill = this.current.patternFill;
  5315. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5316. var maskCtx = maskCanvas.context;
  5317. maskCtx.save();
  5318. putBinaryImageMask(maskCtx, imgData);
  5319. maskCtx.globalCompositeOperation = "source-in";
  5320. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5321. maskCtx.fillRect(0, 0, width, height);
  5322. maskCtx.restore();
  5323. var ctx = this.ctx;
  5324. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5325. ctx.save();
  5326. ctx.transform(scaleX, skewX, skewY, scaleY, positions[i], positions[i + 1]);
  5327. ctx.scale(1, -1);
  5328. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5329. ctx.restore();
  5330. }
  5331. },
  5332. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  5333. if (!this.contentVisible) {
  5334. return;
  5335. }
  5336. var ctx = this.ctx;
  5337. var fillColor = this.current.fillColor;
  5338. var isPatternFill = this.current.patternFill;
  5339. for (var i = 0, ii = images.length; i < ii; i++) {
  5340. var image = images[i];
  5341. var width = image.width,
  5342. height = image.height;
  5343. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  5344. var maskCtx = maskCanvas.context;
  5345. maskCtx.save();
  5346. putBinaryImageMask(maskCtx, image);
  5347. maskCtx.globalCompositeOperation = "source-in";
  5348. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5349. maskCtx.fillRect(0, 0, width, height);
  5350. maskCtx.restore();
  5351. ctx.save();
  5352. ctx.transform.apply(ctx, image.transform);
  5353. ctx.scale(1, -1);
  5354. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5355. ctx.restore();
  5356. }
  5357. },
  5358. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5359. if (!this.contentVisible) {
  5360. return;
  5361. }
  5362. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5363. if (!imgData) {
  5364. (0, _util.warn)("Dependent image isn't ready yet");
  5365. return;
  5366. }
  5367. this.paintInlineImageXObject(imgData);
  5368. },
  5369. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  5370. if (!this.contentVisible) {
  5371. return;
  5372. }
  5373. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  5374. if (!imgData) {
  5375. (0, _util.warn)("Dependent image isn't ready yet");
  5376. return;
  5377. }
  5378. var width = imgData.width;
  5379. var height = imgData.height;
  5380. var map = [];
  5381. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5382. map.push({
  5383. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  5384. x: 0,
  5385. y: 0,
  5386. w: width,
  5387. h: height
  5388. });
  5389. }
  5390. this.paintInlineImageXObjectGroup(imgData, map);
  5391. },
  5392. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  5393. if (!this.contentVisible) {
  5394. return;
  5395. }
  5396. var width = imgData.width;
  5397. var height = imgData.height;
  5398. var ctx = this.ctx;
  5399. this.save();
  5400. ctx.scale(1 / width, -1 / height);
  5401. var currentTransform = ctx.mozCurrentTransformInverse;
  5402. var a = currentTransform[0],
  5403. b = currentTransform[1];
  5404. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  5405. var c = currentTransform[2],
  5406. d = currentTransform[3];
  5407. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  5408. var imgToPaint, tmpCanvas;
  5409. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  5410. imgToPaint = imgData;
  5411. } else {
  5412. tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  5413. var tmpCtx = tmpCanvas.context;
  5414. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5415. imgToPaint = tmpCanvas.canvas;
  5416. }
  5417. var paintWidth = width,
  5418. paintHeight = height;
  5419. var tmpCanvasId = "prescale1";
  5420. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5421. var newWidth = paintWidth,
  5422. newHeight = paintHeight;
  5423. if (widthScale > 2 && paintWidth > 1) {
  5424. newWidth = Math.ceil(paintWidth / 2);
  5425. widthScale /= paintWidth / newWidth;
  5426. }
  5427. if (heightScale > 2 && paintHeight > 1) {
  5428. newHeight = Math.ceil(paintHeight / 2);
  5429. heightScale /= paintHeight / newHeight;
  5430. }
  5431. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5432. tmpCtx = tmpCanvas.context;
  5433. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5434. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5435. imgToPaint = tmpCanvas.canvas;
  5436. paintWidth = newWidth;
  5437. paintHeight = newHeight;
  5438. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5439. }
  5440. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  5441. if (this.imageLayer) {
  5442. var position = this.getCanvasPosition(0, -height);
  5443. this.imageLayer.appendImage({
  5444. imgData,
  5445. left: position[0],
  5446. top: position[1],
  5447. width: width / currentTransform[0],
  5448. height: height / currentTransform[3]
  5449. });
  5450. }
  5451. this.restore();
  5452. },
  5453. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5454. if (!this.contentVisible) {
  5455. return;
  5456. }
  5457. var ctx = this.ctx;
  5458. var w = imgData.width;
  5459. var h = imgData.height;
  5460. var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  5461. var tmpCtx = tmpCanvas.context;
  5462. putBinaryImageData(tmpCtx, imgData, this.current.transferMaps);
  5463. for (var i = 0, ii = map.length; i < ii; i++) {
  5464. var entry = map[i];
  5465. ctx.save();
  5466. ctx.transform.apply(ctx, entry.transform);
  5467. ctx.scale(1, -1);
  5468. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  5469. if (this.imageLayer) {
  5470. var position = this.getCanvasPosition(entry.x, entry.y);
  5471. this.imageLayer.appendImage({
  5472. imgData,
  5473. left: position[0],
  5474. top: position[1],
  5475. width: w,
  5476. height: h
  5477. });
  5478. }
  5479. ctx.restore();
  5480. }
  5481. },
  5482. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  5483. if (!this.contentVisible) {
  5484. return;
  5485. }
  5486. this.ctx.fillRect(0, 0, 1, 1);
  5487. },
  5488. markPoint: function CanvasGraphics_markPoint(tag) {},
  5489. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
  5490. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  5491. this.markedContentStack.push({
  5492. visible: true
  5493. });
  5494. },
  5495. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {
  5496. if (tag === "OC") {
  5497. this.markedContentStack.push({
  5498. visible: this.optionalContentConfig.isVisible(properties)
  5499. });
  5500. } else {
  5501. this.markedContentStack.push({
  5502. visible: true
  5503. });
  5504. }
  5505. this.contentVisible = this.isContentVisible();
  5506. },
  5507. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  5508. this.markedContentStack.pop();
  5509. this.contentVisible = this.isContentVisible();
  5510. },
  5511. beginCompat: function CanvasGraphics_beginCompat() {},
  5512. endCompat: function CanvasGraphics_endCompat() {},
  5513. consumePath: function CanvasGraphics_consumePath() {
  5514. var ctx = this.ctx;
  5515. if (this.pendingClip) {
  5516. if (this.pendingClip === EO_CLIP) {
  5517. ctx.clip("evenodd");
  5518. } else {
  5519. ctx.clip();
  5520. }
  5521. this.pendingClip = null;
  5522. }
  5523. ctx.beginPath();
  5524. },
  5525. getSinglePixelWidth(scale) {
  5526. if (this._cachedGetSinglePixelWidth === null) {
  5527. const inverse = this.ctx.mozCurrentTransformInverse;
  5528. this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  5529. }
  5530. return this._cachedGetSinglePixelWidth;
  5531. },
  5532. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5533. var transform = this.ctx.mozCurrentTransform;
  5534. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  5535. },
  5536. isContentVisible: function CanvasGraphics_isContentVisible() {
  5537. for (let i = this.markedContentStack.length - 1; i >= 0; i--) {
  5538. if (!this.markedContentStack[i].visible) {
  5539. return false;
  5540. }
  5541. }
  5542. return true;
  5543. }
  5544. };
  5545. for (var op in _util.OPS) {
  5546. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  5547. }
  5548. return CanvasGraphics;
  5549. }();
  5550. exports.CanvasGraphics = CanvasGraphics;
  5551. /***/ }),
  5552. /* 11 */
  5553. /***/ (function(module, exports, __w_pdfjs_require__) {
  5554. "use strict";
  5555. Object.defineProperty(exports, "__esModule", {
  5556. value: true
  5557. });
  5558. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  5559. exports.TilingPattern = void 0;
  5560. var _util = __w_pdfjs_require__(2);
  5561. var ShadingIRs = {};
  5562. function applyBoundingBox(ctx, bbox) {
  5563. if (!bbox || typeof Path2D === "undefined") {
  5564. return;
  5565. }
  5566. const width = bbox[2] - bbox[0];
  5567. const height = bbox[3] - bbox[1];
  5568. const region = new Path2D();
  5569. region.rect(bbox[0], bbox[1], width, height);
  5570. ctx.clip(region);
  5571. }
  5572. ShadingIRs.RadialAxial = {
  5573. fromIR: function RadialAxial_fromIR(raw) {
  5574. var type = raw[1];
  5575. var bbox = raw[2];
  5576. var colorStops = raw[3];
  5577. var p0 = raw[4];
  5578. var p1 = raw[5];
  5579. var r0 = raw[6];
  5580. var r1 = raw[7];
  5581. return {
  5582. type: "Pattern",
  5583. getPattern: function RadialAxial_getPattern(ctx) {
  5584. applyBoundingBox(ctx, bbox);
  5585. var grad;
  5586. if (type === "axial") {
  5587. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5588. } else if (type === "radial") {
  5589. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5590. }
  5591. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5592. var c = colorStops[i];
  5593. grad.addColorStop(c[0], c[1]);
  5594. }
  5595. return grad;
  5596. }
  5597. };
  5598. }
  5599. };
  5600. var createMeshCanvas = function createMeshCanvasClosure() {
  5601. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5602. var coords = context.coords,
  5603. colors = context.colors;
  5604. var bytes = data.data,
  5605. rowSize = data.width * 4;
  5606. var tmp;
  5607. if (coords[p1 + 1] > coords[p2 + 1]) {
  5608. tmp = p1;
  5609. p1 = p2;
  5610. p2 = tmp;
  5611. tmp = c1;
  5612. c1 = c2;
  5613. c2 = tmp;
  5614. }
  5615. if (coords[p2 + 1] > coords[p3 + 1]) {
  5616. tmp = p2;
  5617. p2 = p3;
  5618. p3 = tmp;
  5619. tmp = c2;
  5620. c2 = c3;
  5621. c3 = tmp;
  5622. }
  5623. if (coords[p1 + 1] > coords[p2 + 1]) {
  5624. tmp = p1;
  5625. p1 = p2;
  5626. p2 = tmp;
  5627. tmp = c1;
  5628. c1 = c2;
  5629. c2 = tmp;
  5630. }
  5631. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5632. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5633. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5634. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5635. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5636. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5637. if (y1 >= y3) {
  5638. return;
  5639. }
  5640. var c1r = colors[c1],
  5641. c1g = colors[c1 + 1],
  5642. c1b = colors[c1 + 2];
  5643. var c2r = colors[c2],
  5644. c2g = colors[c2 + 1],
  5645. c2b = colors[c2 + 2];
  5646. var c3r = colors[c3],
  5647. c3g = colors[c3 + 1],
  5648. c3b = colors[c3 + 2];
  5649. var minY = Math.round(y1),
  5650. maxY = Math.round(y3);
  5651. var xa, car, cag, cab;
  5652. var xb, cbr, cbg, cbb;
  5653. for (var y = minY; y <= maxY; y++) {
  5654. if (y < y2) {
  5655. let k;
  5656. if (y < y1) {
  5657. k = 0;
  5658. } else if (y1 === y2) {
  5659. k = 1;
  5660. } else {
  5661. k = (y1 - y) / (y1 - y2);
  5662. }
  5663. xa = x1 - (x1 - x2) * k;
  5664. car = c1r - (c1r - c2r) * k;
  5665. cag = c1g - (c1g - c2g) * k;
  5666. cab = c1b - (c1b - c2b) * k;
  5667. } else {
  5668. let k;
  5669. if (y > y3) {
  5670. k = 1;
  5671. } else if (y2 === y3) {
  5672. k = 0;
  5673. } else {
  5674. k = (y2 - y) / (y2 - y3);
  5675. }
  5676. xa = x2 - (x2 - x3) * k;
  5677. car = c2r - (c2r - c3r) * k;
  5678. cag = c2g - (c2g - c3g) * k;
  5679. cab = c2b - (c2b - c3b) * k;
  5680. }
  5681. let k;
  5682. if (y < y1) {
  5683. k = 0;
  5684. } else if (y > y3) {
  5685. k = 1;
  5686. } else {
  5687. k = (y1 - y) / (y1 - y3);
  5688. }
  5689. xb = x1 - (x1 - x3) * k;
  5690. cbr = c1r - (c1r - c3r) * k;
  5691. cbg = c1g - (c1g - c3g) * k;
  5692. cbb = c1b - (c1b - c3b) * k;
  5693. var x1_ = Math.round(Math.min(xa, xb));
  5694. var x2_ = Math.round(Math.max(xa, xb));
  5695. var j = rowSize * y + x1_ * 4;
  5696. for (var x = x1_; x <= x2_; x++) {
  5697. k = (xa - x) / (xa - xb);
  5698. if (k < 0) {
  5699. k = 0;
  5700. } else if (k > 1) {
  5701. k = 1;
  5702. }
  5703. bytes[j++] = car - (car - cbr) * k | 0;
  5704. bytes[j++] = cag - (cag - cbg) * k | 0;
  5705. bytes[j++] = cab - (cab - cbb) * k | 0;
  5706. bytes[j++] = 255;
  5707. }
  5708. }
  5709. }
  5710. function drawFigure(data, figure, context) {
  5711. var ps = figure.coords;
  5712. var cs = figure.colors;
  5713. var i, ii;
  5714. switch (figure.type) {
  5715. case "lattice":
  5716. var verticesPerRow = figure.verticesPerRow;
  5717. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5718. var cols = verticesPerRow - 1;
  5719. for (i = 0; i < rows; i++) {
  5720. var q = i * verticesPerRow;
  5721. for (var j = 0; j < cols; j++, q++) {
  5722. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5723. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5724. }
  5725. }
  5726. break;
  5727. case "triangles":
  5728. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5729. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  5730. }
  5731. break;
  5732. default:
  5733. throw new Error("illegal figure");
  5734. }
  5735. }
  5736. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) {
  5737. var EXPECTED_SCALE = 1.1;
  5738. var MAX_PATTERN_SIZE = 3000;
  5739. var BORDER_SIZE = 2;
  5740. var offsetX = Math.floor(bounds[0]);
  5741. var offsetY = Math.floor(bounds[1]);
  5742. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5743. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5744. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5745. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5746. var scaleX = boundsWidth / width;
  5747. var scaleY = boundsHeight / height;
  5748. var context = {
  5749. coords,
  5750. colors,
  5751. offsetX: -offsetX,
  5752. offsetY: -offsetY,
  5753. scaleX: 1 / scaleX,
  5754. scaleY: 1 / scaleY
  5755. };
  5756. var paddedWidth = width + BORDER_SIZE * 2;
  5757. var paddedHeight = height + BORDER_SIZE * 2;
  5758. var canvas, tmpCanvas, i, ii;
  5759. if (webGLContext.isEnabled) {
  5760. canvas = webGLContext.drawFigures({
  5761. width,
  5762. height,
  5763. backgroundColor,
  5764. figures,
  5765. context
  5766. });
  5767. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5768. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  5769. canvas = tmpCanvas.canvas;
  5770. } else {
  5771. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5772. var tmpCtx = tmpCanvas.context;
  5773. var data = tmpCtx.createImageData(width, height);
  5774. if (backgroundColor) {
  5775. var bytes = data.data;
  5776. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5777. bytes[i] = backgroundColor[0];
  5778. bytes[i + 1] = backgroundColor[1];
  5779. bytes[i + 2] = backgroundColor[2];
  5780. bytes[i + 3] = 255;
  5781. }
  5782. }
  5783. for (i = 0; i < figures.length; i++) {
  5784. drawFigure(data, figures[i], context);
  5785. }
  5786. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  5787. canvas = tmpCanvas.canvas;
  5788. }
  5789. return {
  5790. canvas,
  5791. offsetX: offsetX - BORDER_SIZE * scaleX,
  5792. offsetY: offsetY - BORDER_SIZE * scaleY,
  5793. scaleX,
  5794. scaleY
  5795. };
  5796. }
  5797. return createMeshCanvas;
  5798. }();
  5799. ShadingIRs.Mesh = {
  5800. fromIR: function Mesh_fromIR(raw) {
  5801. var coords = raw[2];
  5802. var colors = raw[3];
  5803. var figures = raw[4];
  5804. var bounds = raw[5];
  5805. var matrix = raw[6];
  5806. var bbox = raw[7];
  5807. var background = raw[8];
  5808. return {
  5809. type: "Pattern",
  5810. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5811. applyBoundingBox(ctx, bbox);
  5812. var scale;
  5813. if (shadingFill) {
  5814. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5815. } else {
  5816. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  5817. if (matrix) {
  5818. var matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
  5819. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  5820. }
  5821. }
  5822. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext);
  5823. if (!shadingFill) {
  5824. ctx.setTransform.apply(ctx, owner.baseTransform);
  5825. if (matrix) {
  5826. ctx.transform.apply(ctx, matrix);
  5827. }
  5828. }
  5829. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5830. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  5831. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  5832. }
  5833. };
  5834. }
  5835. };
  5836. ShadingIRs.Dummy = {
  5837. fromIR: function Dummy_fromIR() {
  5838. return {
  5839. type: "Pattern",
  5840. getPattern: function Dummy_fromIR_getPattern() {
  5841. return "hotpink";
  5842. }
  5843. };
  5844. }
  5845. };
  5846. function getShadingPatternFromIR(raw) {
  5847. var shadingIR = ShadingIRs[raw[0]];
  5848. if (!shadingIR) {
  5849. throw new Error(`Unknown IR type: ${raw[0]}`);
  5850. }
  5851. return shadingIR.fromIR(raw);
  5852. }
  5853. var TilingPattern = function TilingPatternClosure() {
  5854. var PaintType = {
  5855. COLORED: 1,
  5856. UNCOLORED: 2
  5857. };
  5858. var MAX_PATTERN_SIZE = 3000;
  5859. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  5860. this.operatorList = IR[2];
  5861. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5862. this.bbox = IR[4];
  5863. this.xstep = IR[5];
  5864. this.ystep = IR[6];
  5865. this.paintType = IR[7];
  5866. this.tilingType = IR[8];
  5867. this.color = color;
  5868. this.canvasGraphicsFactory = canvasGraphicsFactory;
  5869. this.baseTransform = baseTransform;
  5870. this.type = "Pattern";
  5871. this.ctx = ctx;
  5872. }
  5873. TilingPattern.prototype = {
  5874. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5875. var operatorList = this.operatorList;
  5876. var bbox = this.bbox;
  5877. var xstep = this.xstep;
  5878. var ystep = this.ystep;
  5879. var paintType = this.paintType;
  5880. var tilingType = this.tilingType;
  5881. var color = this.color;
  5882. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  5883. (0, _util.info)("TilingType: " + tilingType);
  5884. var x0 = bbox[0],
  5885. y0 = bbox[1],
  5886. x1 = bbox[2],
  5887. y1 = bbox[3];
  5888. var matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  5889. var curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  5890. var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  5891. var dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  5892. var dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  5893. var tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  5894. var tmpCtx = tmpCanvas.context;
  5895. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  5896. graphics.groupLevel = owner.groupLevel;
  5897. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  5898. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  5899. graphics.transform(1, 0, 0, 1, -x0, -y0);
  5900. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5901. graphics.executeOperatorList(operatorList);
  5902. this.ctx.transform(1, 0, 0, 1, x0, y0);
  5903. this.ctx.scale(1 / dimx.scale, 1 / dimy.scale);
  5904. return tmpCanvas.canvas;
  5905. },
  5906. getSizeAndScale: function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
  5907. step = Math.abs(step);
  5908. var maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
  5909. var size = Math.ceil(step * scale);
  5910. if (size >= maxSize) {
  5911. size = maxSize;
  5912. } else {
  5913. scale = size / step;
  5914. }
  5915. return {
  5916. scale,
  5917. size
  5918. };
  5919. },
  5920. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5921. if (Array.isArray(bbox) && bbox.length === 4) {
  5922. var bboxWidth = x1 - x0;
  5923. var bboxHeight = y1 - y0;
  5924. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5925. graphics.clip();
  5926. graphics.endPath();
  5927. }
  5928. },
  5929. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(graphics, paintType, color) {
  5930. const context = graphics.ctx,
  5931. current = graphics.current;
  5932. switch (paintType) {
  5933. case PaintType.COLORED:
  5934. var ctx = this.ctx;
  5935. context.fillStyle = ctx.fillStyle;
  5936. context.strokeStyle = ctx.strokeStyle;
  5937. current.fillColor = ctx.fillStyle;
  5938. current.strokeColor = ctx.strokeStyle;
  5939. break;
  5940. case PaintType.UNCOLORED:
  5941. var cssColor = _util.Util.makeCssRgb(color[0], color[1], color[2]);
  5942. context.fillStyle = cssColor;
  5943. context.strokeStyle = cssColor;
  5944. current.fillColor = cssColor;
  5945. current.strokeColor = cssColor;
  5946. break;
  5947. default:
  5948. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  5949. }
  5950. },
  5951. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5952. ctx = this.ctx;
  5953. ctx.setTransform.apply(ctx, this.baseTransform);
  5954. ctx.transform.apply(ctx, this.matrix);
  5955. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5956. return ctx.createPattern(temporaryPatternCanvas, "repeat");
  5957. }
  5958. };
  5959. return TilingPattern;
  5960. }();
  5961. exports.TilingPattern = TilingPattern;
  5962. /***/ }),
  5963. /* 12 */
  5964. /***/ (function(module, exports, __w_pdfjs_require__) {
  5965. "use strict";
  5966. Object.defineProperty(exports, "__esModule", {
  5967. value: true
  5968. });
  5969. exports.GlobalWorkerOptions = void 0;
  5970. const GlobalWorkerOptions = Object.create(null);
  5971. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  5972. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  5973. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  5974. /***/ }),
  5975. /* 13 */
  5976. /***/ (function(module, exports, __w_pdfjs_require__) {
  5977. "use strict";
  5978. Object.defineProperty(exports, "__esModule", {
  5979. value: true
  5980. });
  5981. exports.MessageHandler = void 0;
  5982. var _util = __w_pdfjs_require__(2);
  5983. const CallbackKind = {
  5984. UNKNOWN: 0,
  5985. DATA: 1,
  5986. ERROR: 2
  5987. };
  5988. const StreamKind = {
  5989. UNKNOWN: 0,
  5990. CANCEL: 1,
  5991. CANCEL_COMPLETE: 2,
  5992. CLOSE: 3,
  5993. ENQUEUE: 4,
  5994. ERROR: 5,
  5995. PULL: 6,
  5996. PULL_COMPLETE: 7,
  5997. START_COMPLETE: 8
  5998. };
  5999. function wrapReason(reason) {
  6000. if (typeof reason !== "object" || reason === null) {
  6001. return reason;
  6002. }
  6003. switch (reason.name) {
  6004. case "AbortException":
  6005. return new _util.AbortException(reason.message);
  6006. case "MissingPDFException":
  6007. return new _util.MissingPDFException(reason.message);
  6008. case "UnexpectedResponseException":
  6009. return new _util.UnexpectedResponseException(reason.message, reason.status);
  6010. case "UnknownErrorException":
  6011. return new _util.UnknownErrorException(reason.message, reason.details);
  6012. default:
  6013. return new _util.UnknownErrorException(reason.message, reason.toString());
  6014. }
  6015. }
  6016. class MessageHandler {
  6017. constructor(sourceName, targetName, comObj) {
  6018. this.sourceName = sourceName;
  6019. this.targetName = targetName;
  6020. this.comObj = comObj;
  6021. this.callbackId = 1;
  6022. this.streamId = 1;
  6023. this.postMessageTransfers = true;
  6024. this.streamSinks = Object.create(null);
  6025. this.streamControllers = Object.create(null);
  6026. this.callbackCapabilities = Object.create(null);
  6027. this.actionHandler = Object.create(null);
  6028. this._onComObjOnMessage = event => {
  6029. const data = event.data;
  6030. if (data.targetName !== this.sourceName) {
  6031. return;
  6032. }
  6033. if (data.stream) {
  6034. this._processStreamMessage(data);
  6035. return;
  6036. }
  6037. if (data.callback) {
  6038. const callbackId = data.callbackId;
  6039. const capability = this.callbackCapabilities[callbackId];
  6040. if (!capability) {
  6041. throw new Error(`Cannot resolve callback ${callbackId}`);
  6042. }
  6043. delete this.callbackCapabilities[callbackId];
  6044. if (data.callback === CallbackKind.DATA) {
  6045. capability.resolve(data.data);
  6046. } else if (data.callback === CallbackKind.ERROR) {
  6047. capability.reject(wrapReason(data.reason));
  6048. } else {
  6049. throw new Error("Unexpected callback case");
  6050. }
  6051. return;
  6052. }
  6053. const action = this.actionHandler[data.action];
  6054. if (!action) {
  6055. throw new Error(`Unknown action from worker: ${data.action}`);
  6056. }
  6057. if (data.callbackId) {
  6058. const cbSourceName = this.sourceName;
  6059. const cbTargetName = data.sourceName;
  6060. new Promise(function (resolve) {
  6061. resolve(action(data.data));
  6062. }).then(function (result) {
  6063. comObj.postMessage({
  6064. sourceName: cbSourceName,
  6065. targetName: cbTargetName,
  6066. callback: CallbackKind.DATA,
  6067. callbackId: data.callbackId,
  6068. data: result
  6069. });
  6070. }, function (reason) {
  6071. comObj.postMessage({
  6072. sourceName: cbSourceName,
  6073. targetName: cbTargetName,
  6074. callback: CallbackKind.ERROR,
  6075. callbackId: data.callbackId,
  6076. reason: wrapReason(reason)
  6077. });
  6078. });
  6079. return;
  6080. }
  6081. if (data.streamId) {
  6082. this._createStreamSink(data);
  6083. return;
  6084. }
  6085. action(data.data);
  6086. };
  6087. comObj.addEventListener("message", this._onComObjOnMessage);
  6088. }
  6089. on(actionName, handler) {
  6090. const ah = this.actionHandler;
  6091. if (ah[actionName]) {
  6092. throw new Error(`There is already an actionName called "${actionName}"`);
  6093. }
  6094. ah[actionName] = handler;
  6095. }
  6096. send(actionName, data, transfers) {
  6097. this._postMessage({
  6098. sourceName: this.sourceName,
  6099. targetName: this.targetName,
  6100. action: actionName,
  6101. data
  6102. }, transfers);
  6103. }
  6104. sendWithPromise(actionName, data, transfers) {
  6105. const callbackId = this.callbackId++;
  6106. const capability = (0, _util.createPromiseCapability)();
  6107. this.callbackCapabilities[callbackId] = capability;
  6108. try {
  6109. this._postMessage({
  6110. sourceName: this.sourceName,
  6111. targetName: this.targetName,
  6112. action: actionName,
  6113. callbackId,
  6114. data
  6115. }, transfers);
  6116. } catch (ex) {
  6117. capability.reject(ex);
  6118. }
  6119. return capability.promise;
  6120. }
  6121. sendWithStream(actionName, data, queueingStrategy, transfers) {
  6122. const streamId = this.streamId++;
  6123. const sourceName = this.sourceName;
  6124. const targetName = this.targetName;
  6125. const comObj = this.comObj;
  6126. return new ReadableStream({
  6127. start: controller => {
  6128. const startCapability = (0, _util.createPromiseCapability)();
  6129. this.streamControllers[streamId] = {
  6130. controller,
  6131. startCall: startCapability,
  6132. pullCall: null,
  6133. cancelCall: null,
  6134. isClosed: false
  6135. };
  6136. this._postMessage({
  6137. sourceName,
  6138. targetName,
  6139. action: actionName,
  6140. streamId,
  6141. data,
  6142. desiredSize: controller.desiredSize
  6143. }, transfers);
  6144. return startCapability.promise;
  6145. },
  6146. pull: controller => {
  6147. const pullCapability = (0, _util.createPromiseCapability)();
  6148. this.streamControllers[streamId].pullCall = pullCapability;
  6149. comObj.postMessage({
  6150. sourceName,
  6151. targetName,
  6152. stream: StreamKind.PULL,
  6153. streamId,
  6154. desiredSize: controller.desiredSize
  6155. });
  6156. return pullCapability.promise;
  6157. },
  6158. cancel: reason => {
  6159. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  6160. const cancelCapability = (0, _util.createPromiseCapability)();
  6161. this.streamControllers[streamId].cancelCall = cancelCapability;
  6162. this.streamControllers[streamId].isClosed = true;
  6163. comObj.postMessage({
  6164. sourceName,
  6165. targetName,
  6166. stream: StreamKind.CANCEL,
  6167. streamId,
  6168. reason: wrapReason(reason)
  6169. });
  6170. return cancelCapability.promise;
  6171. }
  6172. }, queueingStrategy);
  6173. }
  6174. _createStreamSink(data) {
  6175. const self = this;
  6176. const action = this.actionHandler[data.action];
  6177. const streamId = data.streamId;
  6178. const sourceName = this.sourceName;
  6179. const targetName = data.sourceName;
  6180. const comObj = this.comObj;
  6181. const streamSink = {
  6182. enqueue(chunk, size = 1, transfers) {
  6183. if (this.isCancelled) {
  6184. return;
  6185. }
  6186. const lastDesiredSize = this.desiredSize;
  6187. this.desiredSize -= size;
  6188. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  6189. this.sinkCapability = (0, _util.createPromiseCapability)();
  6190. this.ready = this.sinkCapability.promise;
  6191. }
  6192. self._postMessage({
  6193. sourceName,
  6194. targetName,
  6195. stream: StreamKind.ENQUEUE,
  6196. streamId,
  6197. chunk
  6198. }, transfers);
  6199. },
  6200. close() {
  6201. if (this.isCancelled) {
  6202. return;
  6203. }
  6204. this.isCancelled = true;
  6205. comObj.postMessage({
  6206. sourceName,
  6207. targetName,
  6208. stream: StreamKind.CLOSE,
  6209. streamId
  6210. });
  6211. delete self.streamSinks[streamId];
  6212. },
  6213. error(reason) {
  6214. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  6215. if (this.isCancelled) {
  6216. return;
  6217. }
  6218. this.isCancelled = true;
  6219. comObj.postMessage({
  6220. sourceName,
  6221. targetName,
  6222. stream: StreamKind.ERROR,
  6223. streamId,
  6224. reason: wrapReason(reason)
  6225. });
  6226. },
  6227. sinkCapability: (0, _util.createPromiseCapability)(),
  6228. onPull: null,
  6229. onCancel: null,
  6230. isCancelled: false,
  6231. desiredSize: data.desiredSize,
  6232. ready: null
  6233. };
  6234. streamSink.sinkCapability.resolve();
  6235. streamSink.ready = streamSink.sinkCapability.promise;
  6236. this.streamSinks[streamId] = streamSink;
  6237. new Promise(function (resolve) {
  6238. resolve(action(data.data, streamSink));
  6239. }).then(function () {
  6240. comObj.postMessage({
  6241. sourceName,
  6242. targetName,
  6243. stream: StreamKind.START_COMPLETE,
  6244. streamId,
  6245. success: true
  6246. });
  6247. }, function (reason) {
  6248. comObj.postMessage({
  6249. sourceName,
  6250. targetName,
  6251. stream: StreamKind.START_COMPLETE,
  6252. streamId,
  6253. reason: wrapReason(reason)
  6254. });
  6255. });
  6256. }
  6257. _processStreamMessage(data) {
  6258. const streamId = data.streamId;
  6259. const sourceName = this.sourceName;
  6260. const targetName = data.sourceName;
  6261. const comObj = this.comObj;
  6262. switch (data.stream) {
  6263. case StreamKind.START_COMPLETE:
  6264. if (data.success) {
  6265. this.streamControllers[streamId].startCall.resolve();
  6266. } else {
  6267. this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
  6268. }
  6269. break;
  6270. case StreamKind.PULL_COMPLETE:
  6271. if (data.success) {
  6272. this.streamControllers[streamId].pullCall.resolve();
  6273. } else {
  6274. this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
  6275. }
  6276. break;
  6277. case StreamKind.PULL:
  6278. if (!this.streamSinks[streamId]) {
  6279. comObj.postMessage({
  6280. sourceName,
  6281. targetName,
  6282. stream: StreamKind.PULL_COMPLETE,
  6283. streamId,
  6284. success: true
  6285. });
  6286. break;
  6287. }
  6288. if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
  6289. this.streamSinks[streamId].sinkCapability.resolve();
  6290. }
  6291. this.streamSinks[streamId].desiredSize = data.desiredSize;
  6292. const {
  6293. onPull
  6294. } = this.streamSinks[data.streamId];
  6295. new Promise(function (resolve) {
  6296. resolve(onPull && onPull());
  6297. }).then(function () {
  6298. comObj.postMessage({
  6299. sourceName,
  6300. targetName,
  6301. stream: StreamKind.PULL_COMPLETE,
  6302. streamId,
  6303. success: true
  6304. });
  6305. }, function (reason) {
  6306. comObj.postMessage({
  6307. sourceName,
  6308. targetName,
  6309. stream: StreamKind.PULL_COMPLETE,
  6310. streamId,
  6311. reason: wrapReason(reason)
  6312. });
  6313. });
  6314. break;
  6315. case StreamKind.ENQUEUE:
  6316. (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
  6317. if (this.streamControllers[streamId].isClosed) {
  6318. break;
  6319. }
  6320. this.streamControllers[streamId].controller.enqueue(data.chunk);
  6321. break;
  6322. case StreamKind.CLOSE:
  6323. (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
  6324. if (this.streamControllers[streamId].isClosed) {
  6325. break;
  6326. }
  6327. this.streamControllers[streamId].isClosed = true;
  6328. this.streamControllers[streamId].controller.close();
  6329. this._deleteStreamController(streamId);
  6330. break;
  6331. case StreamKind.ERROR:
  6332. (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
  6333. this.streamControllers[streamId].controller.error(wrapReason(data.reason));
  6334. this._deleteStreamController(streamId);
  6335. break;
  6336. case StreamKind.CANCEL_COMPLETE:
  6337. if (data.success) {
  6338. this.streamControllers[streamId].cancelCall.resolve();
  6339. } else {
  6340. this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
  6341. }
  6342. this._deleteStreamController(streamId);
  6343. break;
  6344. case StreamKind.CANCEL:
  6345. if (!this.streamSinks[streamId]) {
  6346. break;
  6347. }
  6348. const {
  6349. onCancel
  6350. } = this.streamSinks[data.streamId];
  6351. new Promise(function (resolve) {
  6352. resolve(onCancel && onCancel(wrapReason(data.reason)));
  6353. }).then(function () {
  6354. comObj.postMessage({
  6355. sourceName,
  6356. targetName,
  6357. stream: StreamKind.CANCEL_COMPLETE,
  6358. streamId,
  6359. success: true
  6360. });
  6361. }, function (reason) {
  6362. comObj.postMessage({
  6363. sourceName,
  6364. targetName,
  6365. stream: StreamKind.CANCEL_COMPLETE,
  6366. streamId,
  6367. reason: wrapReason(reason)
  6368. });
  6369. });
  6370. this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
  6371. this.streamSinks[streamId].isCancelled = true;
  6372. delete this.streamSinks[streamId];
  6373. break;
  6374. default:
  6375. throw new Error("Unexpected stream case");
  6376. }
  6377. }
  6378. async _deleteStreamController(streamId) {
  6379. await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
  6380. return capability && capability.promise;
  6381. }));
  6382. delete this.streamControllers[streamId];
  6383. }
  6384. _postMessage(message, transfers) {
  6385. if (transfers && this.postMessageTransfers) {
  6386. this.comObj.postMessage(message, transfers);
  6387. } else {
  6388. this.comObj.postMessage(message);
  6389. }
  6390. }
  6391. destroy() {
  6392. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  6393. }
  6394. }
  6395. exports.MessageHandler = MessageHandler;
  6396. /***/ }),
  6397. /* 14 */
  6398. /***/ (function(module, exports, __w_pdfjs_require__) {
  6399. "use strict";
  6400. Object.defineProperty(exports, "__esModule", {
  6401. value: true
  6402. });
  6403. exports.Metadata = void 0;
  6404. var _util = __w_pdfjs_require__(2);
  6405. var _xml_parser = __w_pdfjs_require__(15);
  6406. class Metadata {
  6407. constructor(data) {
  6408. (0, _util.assert)(typeof data === "string", "Metadata: input is not a string");
  6409. data = this._repair(data);
  6410. const parser = new _xml_parser.SimpleXMLParser();
  6411. const xmlDocument = parser.parseFromString(data);
  6412. this._metadataMap = new Map();
  6413. if (xmlDocument) {
  6414. this._parse(xmlDocument);
  6415. }
  6416. }
  6417. _repair(data) {
  6418. return data.replace(/^[^<]+/, "").replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  6419. const bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  6420. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  6421. }).replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
  6422. switch (name) {
  6423. case "amp":
  6424. return "&";
  6425. case "apos":
  6426. return "'";
  6427. case "gt":
  6428. return ">";
  6429. case "lt":
  6430. return "<";
  6431. case "quot":
  6432. return '"';
  6433. }
  6434. throw new Error(`_repair: ${name} isn't defined.`);
  6435. });
  6436. let chars = "";
  6437. for (let i = 0, ii = bytes.length; i < ii; i += 2) {
  6438. const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  6439. if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
  6440. chars += String.fromCharCode(code);
  6441. } else {
  6442. chars += "&#x" + (0x10000 + code).toString(16).substring(1) + ";";
  6443. }
  6444. }
  6445. return ">" + chars;
  6446. });
  6447. }
  6448. _parse(xmlDocument) {
  6449. let rdf = xmlDocument.documentElement;
  6450. if (rdf.nodeName.toLowerCase() !== "rdf:rdf") {
  6451. rdf = rdf.firstChild;
  6452. while (rdf && rdf.nodeName.toLowerCase() !== "rdf:rdf") {
  6453. rdf = rdf.nextSibling;
  6454. }
  6455. }
  6456. const nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  6457. if (!rdf || nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
  6458. return;
  6459. }
  6460. const children = rdf.childNodes;
  6461. for (let i = 0, ii = children.length; i < ii; i++) {
  6462. const desc = children[i];
  6463. if (desc.nodeName.toLowerCase() !== "rdf:description") {
  6464. continue;
  6465. }
  6466. for (let j = 0, jj = desc.childNodes.length; j < jj; j++) {
  6467. if (desc.childNodes[j].nodeName.toLowerCase() !== "#text") {
  6468. const entry = desc.childNodes[j];
  6469. const name = entry.nodeName.toLowerCase();
  6470. this._metadataMap.set(name, entry.textContent.trim());
  6471. }
  6472. }
  6473. }
  6474. }
  6475. get(name) {
  6476. return this._metadataMap.has(name) ? this._metadataMap.get(name) : null;
  6477. }
  6478. getAll() {
  6479. return Object.fromEntries(this._metadataMap);
  6480. }
  6481. has(name) {
  6482. return this._metadataMap.has(name);
  6483. }
  6484. }
  6485. exports.Metadata = Metadata;
  6486. /***/ }),
  6487. /* 15 */
  6488. /***/ (function(module, exports, __w_pdfjs_require__) {
  6489. "use strict";
  6490. Object.defineProperty(exports, "__esModule", {
  6491. value: true
  6492. });
  6493. exports.SimpleXMLParser = void 0;
  6494. const XMLParserErrorCode = {
  6495. NoError: 0,
  6496. EndOfDocument: -1,
  6497. UnterminatedCdat: -2,
  6498. UnterminatedXmlDeclaration: -3,
  6499. UnterminatedDoctypeDeclaration: -4,
  6500. UnterminatedComment: -5,
  6501. MalformedElement: -6,
  6502. OutOfMemory: -7,
  6503. UnterminatedAttributeValue: -8,
  6504. UnterminatedElement: -9,
  6505. ElementNeverBegun: -10
  6506. };
  6507. function isWhitespace(s, index) {
  6508. const ch = s[index];
  6509. return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
  6510. }
  6511. function isWhitespaceString(s) {
  6512. for (let i = 0, ii = s.length; i < ii; i++) {
  6513. if (!isWhitespace(s, i)) {
  6514. return false;
  6515. }
  6516. }
  6517. return true;
  6518. }
  6519. class XMLParserBase {
  6520. _resolveEntities(s) {
  6521. return s.replace(/&([^;]+);/g, (all, entity) => {
  6522. if (entity.substring(0, 2) === "#x") {
  6523. return String.fromCharCode(parseInt(entity.substring(2), 16));
  6524. } else if (entity.substring(0, 1) === "#") {
  6525. return String.fromCharCode(parseInt(entity.substring(1), 10));
  6526. }
  6527. switch (entity) {
  6528. case "lt":
  6529. return "<";
  6530. case "gt":
  6531. return ">";
  6532. case "amp":
  6533. return "&";
  6534. case "quot":
  6535. return '"';
  6536. }
  6537. return this.onResolveEntity(entity);
  6538. });
  6539. }
  6540. _parseContent(s, start) {
  6541. const attributes = [];
  6542. let pos = start;
  6543. function skipWs() {
  6544. while (pos < s.length && isWhitespace(s, pos)) {
  6545. ++pos;
  6546. }
  6547. }
  6548. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  6549. ++pos;
  6550. }
  6551. const name = s.substring(start, pos);
  6552. skipWs();
  6553. while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
  6554. skipWs();
  6555. let attrName = "",
  6556. attrValue = "";
  6557. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
  6558. attrName += s[pos];
  6559. ++pos;
  6560. }
  6561. skipWs();
  6562. if (s[pos] !== "=") {
  6563. return null;
  6564. }
  6565. ++pos;
  6566. skipWs();
  6567. const attrEndChar = s[pos];
  6568. if (attrEndChar !== '"' && attrEndChar !== "'") {
  6569. return null;
  6570. }
  6571. const attrEndIndex = s.indexOf(attrEndChar, ++pos);
  6572. if (attrEndIndex < 0) {
  6573. return null;
  6574. }
  6575. attrValue = s.substring(pos, attrEndIndex);
  6576. attributes.push({
  6577. name: attrName,
  6578. value: this._resolveEntities(attrValue)
  6579. });
  6580. pos = attrEndIndex + 1;
  6581. skipWs();
  6582. }
  6583. return {
  6584. name,
  6585. attributes,
  6586. parsed: pos - start
  6587. };
  6588. }
  6589. _parseProcessingInstruction(s, start) {
  6590. let pos = start;
  6591. function skipWs() {
  6592. while (pos < s.length && isWhitespace(s, pos)) {
  6593. ++pos;
  6594. }
  6595. }
  6596. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  6597. ++pos;
  6598. }
  6599. const name = s.substring(start, pos);
  6600. skipWs();
  6601. const attrStart = pos;
  6602. while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
  6603. ++pos;
  6604. }
  6605. const value = s.substring(attrStart, pos);
  6606. return {
  6607. name,
  6608. value,
  6609. parsed: pos - start
  6610. };
  6611. }
  6612. parseXml(s) {
  6613. let i = 0;
  6614. while (i < s.length) {
  6615. const ch = s[i];
  6616. let j = i;
  6617. if (ch === "<") {
  6618. ++j;
  6619. const ch2 = s[j];
  6620. let q;
  6621. switch (ch2) {
  6622. case "/":
  6623. ++j;
  6624. q = s.indexOf(">", j);
  6625. if (q < 0) {
  6626. this.onError(XMLParserErrorCode.UnterminatedElement);
  6627. return;
  6628. }
  6629. this.onEndElement(s.substring(j, q));
  6630. j = q + 1;
  6631. break;
  6632. case "?":
  6633. ++j;
  6634. const pi = this._parseProcessingInstruction(s, j);
  6635. if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
  6636. this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
  6637. return;
  6638. }
  6639. this.onPi(pi.name, pi.value);
  6640. j += pi.parsed + 2;
  6641. break;
  6642. case "!":
  6643. if (s.substring(j + 1, j + 3) === "--") {
  6644. q = s.indexOf("-->", j + 3);
  6645. if (q < 0) {
  6646. this.onError(XMLParserErrorCode.UnterminatedComment);
  6647. return;
  6648. }
  6649. this.onComment(s.substring(j + 3, q));
  6650. j = q + 3;
  6651. } else if (s.substring(j + 1, j + 8) === "[CDATA[") {
  6652. q = s.indexOf("]]>", j + 8);
  6653. if (q < 0) {
  6654. this.onError(XMLParserErrorCode.UnterminatedCdat);
  6655. return;
  6656. }
  6657. this.onCdata(s.substring(j + 8, q));
  6658. j = q + 3;
  6659. } else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
  6660. const q2 = s.indexOf("[", j + 8);
  6661. let complexDoctype = false;
  6662. q = s.indexOf(">", j + 8);
  6663. if (q < 0) {
  6664. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  6665. return;
  6666. }
  6667. if (q2 > 0 && q > q2) {
  6668. q = s.indexOf("]>", j + 8);
  6669. if (q < 0) {
  6670. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  6671. return;
  6672. }
  6673. complexDoctype = true;
  6674. }
  6675. const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
  6676. this.onDoctype(doctypeContent);
  6677. j = q + (complexDoctype ? 2 : 1);
  6678. } else {
  6679. this.onError(XMLParserErrorCode.MalformedElement);
  6680. return;
  6681. }
  6682. break;
  6683. default:
  6684. const content = this._parseContent(s, j);
  6685. if (content === null) {
  6686. this.onError(XMLParserErrorCode.MalformedElement);
  6687. return;
  6688. }
  6689. let isClosed = false;
  6690. if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
  6691. isClosed = true;
  6692. } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
  6693. this.onError(XMLParserErrorCode.UnterminatedElement);
  6694. return;
  6695. }
  6696. this.onBeginElement(content.name, content.attributes, isClosed);
  6697. j += content.parsed + (isClosed ? 2 : 1);
  6698. break;
  6699. }
  6700. } else {
  6701. while (j < s.length && s[j] !== "<") {
  6702. j++;
  6703. }
  6704. const text = s.substring(i, j);
  6705. this.onText(this._resolveEntities(text));
  6706. }
  6707. i = j;
  6708. }
  6709. }
  6710. onResolveEntity(name) {
  6711. return `&${name};`;
  6712. }
  6713. onPi(name, value) {}
  6714. onComment(text) {}
  6715. onCdata(text) {}
  6716. onDoctype(doctypeContent) {}
  6717. onText(text) {}
  6718. onBeginElement(name, attributes, isEmpty) {}
  6719. onEndElement(name) {}
  6720. onError(code) {}
  6721. }
  6722. class SimpleDOMNode {
  6723. constructor(nodeName, nodeValue) {
  6724. this.nodeName = nodeName;
  6725. this.nodeValue = nodeValue;
  6726. Object.defineProperty(this, "parentNode", {
  6727. value: null,
  6728. writable: true
  6729. });
  6730. }
  6731. get firstChild() {
  6732. return this.childNodes && this.childNodes[0];
  6733. }
  6734. get nextSibling() {
  6735. const childNodes = this.parentNode.childNodes;
  6736. if (!childNodes) {
  6737. return undefined;
  6738. }
  6739. const index = childNodes.indexOf(this);
  6740. if (index === -1) {
  6741. return undefined;
  6742. }
  6743. return childNodes[index + 1];
  6744. }
  6745. get textContent() {
  6746. if (!this.childNodes) {
  6747. return this.nodeValue || "";
  6748. }
  6749. return this.childNodes.map(function (child) {
  6750. return child.textContent;
  6751. }).join("");
  6752. }
  6753. hasChildNodes() {
  6754. return this.childNodes && this.childNodes.length > 0;
  6755. }
  6756. }
  6757. class SimpleXMLParser extends XMLParserBase {
  6758. constructor() {
  6759. super();
  6760. this._currentFragment = null;
  6761. this._stack = null;
  6762. this._errorCode = XMLParserErrorCode.NoError;
  6763. }
  6764. parseFromString(data) {
  6765. this._currentFragment = [];
  6766. this._stack = [];
  6767. this._errorCode = XMLParserErrorCode.NoError;
  6768. this.parseXml(data);
  6769. if (this._errorCode !== XMLParserErrorCode.NoError) {
  6770. return undefined;
  6771. }
  6772. const [documentElement] = this._currentFragment;
  6773. if (!documentElement) {
  6774. return undefined;
  6775. }
  6776. return {
  6777. documentElement
  6778. };
  6779. }
  6780. onResolveEntity(name) {
  6781. switch (name) {
  6782. case "apos":
  6783. return "'";
  6784. }
  6785. return super.onResolveEntity(name);
  6786. }
  6787. onText(text) {
  6788. if (isWhitespaceString(text)) {
  6789. return;
  6790. }
  6791. const node = new SimpleDOMNode("#text", text);
  6792. this._currentFragment.push(node);
  6793. }
  6794. onCdata(text) {
  6795. const node = new SimpleDOMNode("#text", text);
  6796. this._currentFragment.push(node);
  6797. }
  6798. onBeginElement(name, attributes, isEmpty) {
  6799. const node = new SimpleDOMNode(name);
  6800. node.childNodes = [];
  6801. this._currentFragment.push(node);
  6802. if (isEmpty) {
  6803. return;
  6804. }
  6805. this._stack.push(this._currentFragment);
  6806. this._currentFragment = node.childNodes;
  6807. }
  6808. onEndElement(name) {
  6809. this._currentFragment = this._stack.pop() || [];
  6810. const lastElement = this._currentFragment[this._currentFragment.length - 1];
  6811. if (!lastElement) {
  6812. return;
  6813. }
  6814. for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
  6815. lastElement.childNodes[i].parentNode = lastElement;
  6816. }
  6817. }
  6818. onError(code) {
  6819. this._errorCode = code;
  6820. }
  6821. }
  6822. exports.SimpleXMLParser = SimpleXMLParser;
  6823. /***/ }),
  6824. /* 16 */
  6825. /***/ (function(module, exports, __w_pdfjs_require__) {
  6826. "use strict";
  6827. Object.defineProperty(exports, "__esModule", {
  6828. value: true
  6829. });
  6830. exports.OptionalContentConfig = void 0;
  6831. var _util = __w_pdfjs_require__(2);
  6832. class OptionalContentGroup {
  6833. constructor(name, intent) {
  6834. this.visible = true;
  6835. this.name = name;
  6836. this.intent = intent;
  6837. }
  6838. }
  6839. class OptionalContentConfig {
  6840. constructor(data) {
  6841. this.name = null;
  6842. this.creator = null;
  6843. this._order = null;
  6844. this._groups = new Map();
  6845. if (data === null) {
  6846. return;
  6847. }
  6848. this.name = data.name;
  6849. this.creator = data.creator;
  6850. this._order = data.order;
  6851. for (const group of data.groups) {
  6852. this._groups.set(group.id, new OptionalContentGroup(group.name, group.intent));
  6853. }
  6854. if (data.baseState === "OFF") {
  6855. for (const group of this._groups) {
  6856. group.visible = false;
  6857. }
  6858. }
  6859. for (const on of data.on) {
  6860. this._groups.get(on).visible = true;
  6861. }
  6862. for (const off of data.off) {
  6863. this._groups.get(off).visible = false;
  6864. }
  6865. }
  6866. isVisible(group) {
  6867. if (group.type === "OCG") {
  6868. if (!this._groups.has(group.id)) {
  6869. (0, _util.warn)(`Optional content group not found: ${group.id}`);
  6870. return true;
  6871. }
  6872. return this._groups.get(group.id).visible;
  6873. } else if (group.type === "OCMD") {
  6874. if (group.expression) {
  6875. (0, _util.warn)("Visibility expression not supported yet.");
  6876. }
  6877. if (!group.policy || group.policy === "AnyOn") {
  6878. for (const id of group.ids) {
  6879. if (!this._groups.has(id)) {
  6880. (0, _util.warn)(`Optional content group not found: ${id}`);
  6881. return true;
  6882. }
  6883. if (this._groups.get(id).visible) {
  6884. return true;
  6885. }
  6886. }
  6887. return false;
  6888. } else if (group.policy === "AllOn") {
  6889. for (const id of group.ids) {
  6890. if (!this._groups.has(id)) {
  6891. (0, _util.warn)(`Optional content group not found: ${id}`);
  6892. return true;
  6893. }
  6894. if (!this._groups.get(id).visible) {
  6895. return false;
  6896. }
  6897. }
  6898. return true;
  6899. } else if (group.policy === "AnyOff") {
  6900. for (const id of group.ids) {
  6901. if (!this._groups.has(id)) {
  6902. (0, _util.warn)(`Optional content group not found: ${id}`);
  6903. return true;
  6904. }
  6905. if (!this._groups.get(id).visible) {
  6906. return true;
  6907. }
  6908. }
  6909. return false;
  6910. } else if (group.policy === "AllOff") {
  6911. for (const id of group.ids) {
  6912. if (!this._groups.has(id)) {
  6913. (0, _util.warn)(`Optional content group not found: ${id}`);
  6914. return true;
  6915. }
  6916. if (this._groups.get(id).visible) {
  6917. return false;
  6918. }
  6919. }
  6920. return true;
  6921. }
  6922. (0, _util.warn)(`Unknown optional content policy ${group.policy}.`);
  6923. return true;
  6924. }
  6925. (0, _util.warn)(`Unknown group type ${group.type}.`);
  6926. return true;
  6927. }
  6928. setVisibility(id, visible = true) {
  6929. if (!this._groups.has(id)) {
  6930. (0, _util.warn)(`Optional content group not found: ${id}`);
  6931. return;
  6932. }
  6933. this._groups.get(id).visible = !!visible;
  6934. }
  6935. getOrder() {
  6936. if (!this._groups.size) {
  6937. return null;
  6938. }
  6939. if (this._order) {
  6940. return this._order.slice();
  6941. }
  6942. return Array.from(this._groups.keys());
  6943. }
  6944. getGroups() {
  6945. if (!this._groups.size) {
  6946. return null;
  6947. }
  6948. return Object.fromEntries(this._groups);
  6949. }
  6950. getGroup(id) {
  6951. return this._groups.get(id) || null;
  6952. }
  6953. }
  6954. exports.OptionalContentConfig = OptionalContentConfig;
  6955. /***/ }),
  6956. /* 17 */
  6957. /***/ (function(module, exports, __w_pdfjs_require__) {
  6958. "use strict";
  6959. Object.defineProperty(exports, "__esModule", {
  6960. value: true
  6961. });
  6962. exports.PDFDataTransportStream = void 0;
  6963. var _util = __w_pdfjs_require__(2);
  6964. class PDFDataTransportStream {
  6965. constructor(params, pdfDataRangeTransport) {
  6966. (0, _util.assert)(pdfDataRangeTransport, 'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');
  6967. this._queuedChunks = [];
  6968. this._progressiveDone = params.progressiveDone || false;
  6969. const initialData = params.initialData;
  6970. if (initialData && initialData.length > 0) {
  6971. const buffer = new Uint8Array(initialData).buffer;
  6972. this._queuedChunks.push(buffer);
  6973. }
  6974. this._pdfDataRangeTransport = pdfDataRangeTransport;
  6975. this._isStreamingSupported = !params.disableStream;
  6976. this._isRangeSupported = !params.disableRange;
  6977. this._contentLength = params.length;
  6978. this._fullRequestReader = null;
  6979. this._rangeReaders = [];
  6980. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  6981. this._onReceiveData({
  6982. begin,
  6983. chunk
  6984. });
  6985. });
  6986. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  6987. this._onProgress({
  6988. loaded,
  6989. total
  6990. });
  6991. });
  6992. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  6993. this._onReceiveData({
  6994. chunk
  6995. });
  6996. });
  6997. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  6998. this._onProgressiveDone();
  6999. });
  7000. this._pdfDataRangeTransport.transportReady();
  7001. }
  7002. _onReceiveData(args) {
  7003. const buffer = new Uint8Array(args.chunk).buffer;
  7004. if (args.begin === undefined) {
  7005. if (this._fullRequestReader) {
  7006. this._fullRequestReader._enqueue(buffer);
  7007. } else {
  7008. this._queuedChunks.push(buffer);
  7009. }
  7010. } else {
  7011. const found = this._rangeReaders.some(function (rangeReader) {
  7012. if (rangeReader._begin !== args.begin) {
  7013. return false;
  7014. }
  7015. rangeReader._enqueue(buffer);
  7016. return true;
  7017. });
  7018. (0, _util.assert)(found, "_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");
  7019. }
  7020. }
  7021. get _progressiveDataLength() {
  7022. return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
  7023. }
  7024. _onProgress(evt) {
  7025. if (evt.total === undefined) {
  7026. const firstReader = this._rangeReaders[0];
  7027. if (firstReader && firstReader.onProgress) {
  7028. firstReader.onProgress({
  7029. loaded: evt.loaded
  7030. });
  7031. }
  7032. } else {
  7033. const fullReader = this._fullRequestReader;
  7034. if (fullReader && fullReader.onProgress) {
  7035. fullReader.onProgress({
  7036. loaded: evt.loaded,
  7037. total: evt.total
  7038. });
  7039. }
  7040. }
  7041. }
  7042. _onProgressiveDone() {
  7043. if (this._fullRequestReader) {
  7044. this._fullRequestReader.progressiveDone();
  7045. }
  7046. this._progressiveDone = true;
  7047. }
  7048. _removeRangeReader(reader) {
  7049. const i = this._rangeReaders.indexOf(reader);
  7050. if (i >= 0) {
  7051. this._rangeReaders.splice(i, 1);
  7052. }
  7053. }
  7054. getFullReader() {
  7055. (0, _util.assert)(!this._fullRequestReader, "PDFDataTransportStream.getFullReader can only be called once.");
  7056. const queuedChunks = this._queuedChunks;
  7057. this._queuedChunks = null;
  7058. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone);
  7059. }
  7060. getRangeReader(begin, end) {
  7061. if (end <= this._progressiveDataLength) {
  7062. return null;
  7063. }
  7064. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  7065. this._pdfDataRangeTransport.requestDataRange(begin, end);
  7066. this._rangeReaders.push(reader);
  7067. return reader;
  7068. }
  7069. cancelAllRequests(reason) {
  7070. if (this._fullRequestReader) {
  7071. this._fullRequestReader.cancel(reason);
  7072. }
  7073. const readers = this._rangeReaders.slice(0);
  7074. readers.forEach(function (rangeReader) {
  7075. rangeReader.cancel(reason);
  7076. });
  7077. this._pdfDataRangeTransport.abort();
  7078. }
  7079. }
  7080. exports.PDFDataTransportStream = PDFDataTransportStream;
  7081. class PDFDataTransportStreamReader {
  7082. constructor(stream, queuedChunks, progressiveDone = false) {
  7083. this._stream = stream;
  7084. this._done = progressiveDone || false;
  7085. this._filename = null;
  7086. this._queuedChunks = queuedChunks || [];
  7087. this._loaded = 0;
  7088. for (const chunk of this._queuedChunks) {
  7089. this._loaded += chunk.byteLength;
  7090. }
  7091. this._requests = [];
  7092. this._headersReady = Promise.resolve();
  7093. stream._fullRequestReader = this;
  7094. this.onProgress = null;
  7095. }
  7096. _enqueue(chunk) {
  7097. if (this._done) {
  7098. return;
  7099. }
  7100. if (this._requests.length > 0) {
  7101. const requestCapability = this._requests.shift();
  7102. requestCapability.resolve({
  7103. value: chunk,
  7104. done: false
  7105. });
  7106. } else {
  7107. this._queuedChunks.push(chunk);
  7108. }
  7109. this._loaded += chunk.byteLength;
  7110. }
  7111. get headersReady() {
  7112. return this._headersReady;
  7113. }
  7114. get filename() {
  7115. return this._filename;
  7116. }
  7117. get isRangeSupported() {
  7118. return this._stream._isRangeSupported;
  7119. }
  7120. get isStreamingSupported() {
  7121. return this._stream._isStreamingSupported;
  7122. }
  7123. get contentLength() {
  7124. return this._stream._contentLength;
  7125. }
  7126. async read() {
  7127. if (this._queuedChunks.length > 0) {
  7128. const chunk = this._queuedChunks.shift();
  7129. return {
  7130. value: chunk,
  7131. done: false
  7132. };
  7133. }
  7134. if (this._done) {
  7135. return {
  7136. value: undefined,
  7137. done: true
  7138. };
  7139. }
  7140. const requestCapability = (0, _util.createPromiseCapability)();
  7141. this._requests.push(requestCapability);
  7142. return requestCapability.promise;
  7143. }
  7144. cancel(reason) {
  7145. this._done = true;
  7146. this._requests.forEach(function (requestCapability) {
  7147. requestCapability.resolve({
  7148. value: undefined,
  7149. done: true
  7150. });
  7151. });
  7152. this._requests = [];
  7153. }
  7154. progressiveDone() {
  7155. if (this._done) {
  7156. return;
  7157. }
  7158. this._done = true;
  7159. }
  7160. }
  7161. class PDFDataTransportStreamRangeReader {
  7162. constructor(stream, begin, end) {
  7163. this._stream = stream;
  7164. this._begin = begin;
  7165. this._end = end;
  7166. this._queuedChunk = null;
  7167. this._requests = [];
  7168. this._done = false;
  7169. this.onProgress = null;
  7170. }
  7171. _enqueue(chunk) {
  7172. if (this._done) {
  7173. return;
  7174. }
  7175. if (this._requests.length === 0) {
  7176. this._queuedChunk = chunk;
  7177. } else {
  7178. const requestsCapability = this._requests.shift();
  7179. requestsCapability.resolve({
  7180. value: chunk,
  7181. done: false
  7182. });
  7183. this._requests.forEach(function (requestCapability) {
  7184. requestCapability.resolve({
  7185. value: undefined,
  7186. done: true
  7187. });
  7188. });
  7189. this._requests = [];
  7190. }
  7191. this._done = true;
  7192. this._stream._removeRangeReader(this);
  7193. }
  7194. get isStreamingSupported() {
  7195. return false;
  7196. }
  7197. async read() {
  7198. if (this._queuedChunk) {
  7199. const chunk = this._queuedChunk;
  7200. this._queuedChunk = null;
  7201. return {
  7202. value: chunk,
  7203. done: false
  7204. };
  7205. }
  7206. if (this._done) {
  7207. return {
  7208. value: undefined,
  7209. done: true
  7210. };
  7211. }
  7212. const requestCapability = (0, _util.createPromiseCapability)();
  7213. this._requests.push(requestCapability);
  7214. return requestCapability.promise;
  7215. }
  7216. cancel(reason) {
  7217. this._done = true;
  7218. this._requests.forEach(function (requestCapability) {
  7219. requestCapability.resolve({
  7220. value: undefined,
  7221. done: true
  7222. });
  7223. });
  7224. this._requests = [];
  7225. this._stream._removeRangeReader(this);
  7226. }
  7227. }
  7228. /***/ }),
  7229. /* 18 */
  7230. /***/ (function(module, exports, __w_pdfjs_require__) {
  7231. "use strict";
  7232. Object.defineProperty(exports, "__esModule", {
  7233. value: true
  7234. });
  7235. exports.WebGLContext = void 0;
  7236. var _util = __w_pdfjs_require__(2);
  7237. class WebGLContext {
  7238. constructor({
  7239. enable = false
  7240. }) {
  7241. this._enabled = enable === true;
  7242. }
  7243. get isEnabled() {
  7244. let enabled = this._enabled;
  7245. if (enabled) {
  7246. enabled = WebGLUtils.tryInitGL();
  7247. }
  7248. return (0, _util.shadow)(this, "isEnabled", enabled);
  7249. }
  7250. composeSMask({
  7251. layer,
  7252. mask,
  7253. properties
  7254. }) {
  7255. return WebGLUtils.composeSMask(layer, mask, properties);
  7256. }
  7257. drawFigures({
  7258. width,
  7259. height,
  7260. backgroundColor,
  7261. figures,
  7262. context
  7263. }) {
  7264. return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  7265. }
  7266. clear() {
  7267. WebGLUtils.cleanup();
  7268. }
  7269. }
  7270. exports.WebGLContext = WebGLContext;
  7271. var WebGLUtils = function WebGLUtilsClosure() {
  7272. function loadShader(gl, code, shaderType) {
  7273. var shader = gl.createShader(shaderType);
  7274. gl.shaderSource(shader, code);
  7275. gl.compileShader(shader);
  7276. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  7277. if (!compiled) {
  7278. var errorMsg = gl.getShaderInfoLog(shader);
  7279. throw new Error("Error during shader compilation: " + errorMsg);
  7280. }
  7281. return shader;
  7282. }
  7283. function createVertexShader(gl, code) {
  7284. return loadShader(gl, code, gl.VERTEX_SHADER);
  7285. }
  7286. function createFragmentShader(gl, code) {
  7287. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  7288. }
  7289. function createProgram(gl, shaders) {
  7290. var program = gl.createProgram();
  7291. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  7292. gl.attachShader(program, shaders[i]);
  7293. }
  7294. gl.linkProgram(program);
  7295. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  7296. if (!linked) {
  7297. var errorMsg = gl.getProgramInfoLog(program);
  7298. throw new Error("Error during program linking: " + errorMsg);
  7299. }
  7300. return program;
  7301. }
  7302. function createTexture(gl, image, textureId) {
  7303. gl.activeTexture(textureId);
  7304. var texture = gl.createTexture();
  7305. gl.bindTexture(gl.TEXTURE_2D, texture);
  7306. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  7307. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  7308. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  7309. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  7310. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  7311. return texture;
  7312. }
  7313. var currentGL, currentCanvas;
  7314. function generateGL() {
  7315. if (currentGL) {
  7316. return;
  7317. }
  7318. currentCanvas = document.createElement("canvas");
  7319. currentGL = currentCanvas.getContext("webgl", {
  7320. premultipliedalpha: false
  7321. });
  7322. }
  7323. var smaskVertexShaderCode = "\
  7324. attribute vec2 a_position; \
  7325. attribute vec2 a_texCoord; \
  7326. \
  7327. uniform vec2 u_resolution; \
  7328. \
  7329. varying vec2 v_texCoord; \
  7330. \
  7331. void main() { \
  7332. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  7333. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  7334. \
  7335. v_texCoord = a_texCoord; \
  7336. } ";
  7337. var smaskFragmentShaderCode = "\
  7338. precision mediump float; \
  7339. \
  7340. uniform vec4 u_backdrop; \
  7341. uniform int u_subtype; \
  7342. uniform sampler2D u_image; \
  7343. uniform sampler2D u_mask; \
  7344. \
  7345. varying vec2 v_texCoord; \
  7346. \
  7347. void main() { \
  7348. vec4 imageColor = texture2D(u_image, v_texCoord); \
  7349. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  7350. if (u_backdrop.a > 0.0) { \
  7351. maskColor.rgb = maskColor.rgb * maskColor.a + \
  7352. u_backdrop.rgb * (1.0 - maskColor.a); \
  7353. } \
  7354. float lum; \
  7355. if (u_subtype == 0) { \
  7356. lum = maskColor.a; \
  7357. } else { \
  7358. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  7359. maskColor.b * 0.11; \
  7360. } \
  7361. imageColor.a *= lum; \
  7362. imageColor.rgb *= imageColor.a; \
  7363. gl_FragColor = imageColor; \
  7364. } ";
  7365. var smaskCache = null;
  7366. function initSmaskGL() {
  7367. var canvas, gl;
  7368. generateGL();
  7369. canvas = currentCanvas;
  7370. currentCanvas = null;
  7371. gl = currentGL;
  7372. currentGL = null;
  7373. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  7374. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  7375. var program = createProgram(gl, [vertexShader, fragmentShader]);
  7376. gl.useProgram(program);
  7377. var cache = {};
  7378. cache.gl = gl;
  7379. cache.canvas = canvas;
  7380. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  7381. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  7382. cache.backdropLocation = gl.getUniformLocation(program, "u_backdrop");
  7383. cache.subtypeLocation = gl.getUniformLocation(program, "u_subtype");
  7384. var texCoordLocation = gl.getAttribLocation(program, "a_texCoord");
  7385. var texLayerLocation = gl.getUniformLocation(program, "u_image");
  7386. var texMaskLocation = gl.getUniformLocation(program, "u_mask");
  7387. var texCoordBuffer = gl.createBuffer();
  7388. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  7389. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
  7390. gl.enableVertexAttribArray(texCoordLocation);
  7391. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  7392. gl.uniform1i(texLayerLocation, 0);
  7393. gl.uniform1i(texMaskLocation, 1);
  7394. smaskCache = cache;
  7395. }
  7396. function composeSMask(layer, mask, properties) {
  7397. var width = layer.width,
  7398. height = layer.height;
  7399. if (!smaskCache) {
  7400. initSmaskGL();
  7401. }
  7402. var cache = smaskCache,
  7403. canvas = cache.canvas,
  7404. gl = cache.gl;
  7405. canvas.width = width;
  7406. canvas.height = height;
  7407. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  7408. gl.uniform2f(cache.resolutionLocation, width, height);
  7409. if (properties.backdrop) {
  7410. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  7411. } else {
  7412. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  7413. }
  7414. gl.uniform1i(cache.subtypeLocation, properties.subtype === "Luminosity" ? 1 : 0);
  7415. var texture = createTexture(gl, layer, gl.TEXTURE0);
  7416. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  7417. var buffer = gl.createBuffer();
  7418. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  7419. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
  7420. gl.enableVertexAttribArray(cache.positionLocation);
  7421. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  7422. gl.clearColor(0, 0, 0, 0);
  7423. gl.enable(gl.BLEND);
  7424. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  7425. gl.clear(gl.COLOR_BUFFER_BIT);
  7426. gl.drawArrays(gl.TRIANGLES, 0, 6);
  7427. gl.flush();
  7428. gl.deleteTexture(texture);
  7429. gl.deleteTexture(maskTexture);
  7430. gl.deleteBuffer(buffer);
  7431. return canvas;
  7432. }
  7433. var figuresVertexShaderCode = "\
  7434. attribute vec2 a_position; \
  7435. attribute vec3 a_color; \
  7436. \
  7437. uniform vec2 u_resolution; \
  7438. uniform vec2 u_scale; \
  7439. uniform vec2 u_offset; \
  7440. \
  7441. varying vec4 v_color; \
  7442. \
  7443. void main() { \
  7444. vec2 position = (a_position + u_offset) * u_scale; \
  7445. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  7446. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  7447. \
  7448. v_color = vec4(a_color / 255.0, 1.0); \
  7449. } ";
  7450. var figuresFragmentShaderCode = "\
  7451. precision mediump float; \
  7452. \
  7453. varying vec4 v_color; \
  7454. \
  7455. void main() { \
  7456. gl_FragColor = v_color; \
  7457. } ";
  7458. var figuresCache = null;
  7459. function initFiguresGL() {
  7460. var canvas, gl;
  7461. generateGL();
  7462. canvas = currentCanvas;
  7463. currentCanvas = null;
  7464. gl = currentGL;
  7465. currentGL = null;
  7466. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  7467. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  7468. var program = createProgram(gl, [vertexShader, fragmentShader]);
  7469. gl.useProgram(program);
  7470. var cache = {};
  7471. cache.gl = gl;
  7472. cache.canvas = canvas;
  7473. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  7474. cache.scaleLocation = gl.getUniformLocation(program, "u_scale");
  7475. cache.offsetLocation = gl.getUniformLocation(program, "u_offset");
  7476. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  7477. cache.colorLocation = gl.getAttribLocation(program, "a_color");
  7478. figuresCache = cache;
  7479. }
  7480. function drawFigures(width, height, backgroundColor, figures, context) {
  7481. if (!figuresCache) {
  7482. initFiguresGL();
  7483. }
  7484. var cache = figuresCache,
  7485. canvas = cache.canvas,
  7486. gl = cache.gl;
  7487. canvas.width = width;
  7488. canvas.height = height;
  7489. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  7490. gl.uniform2f(cache.resolutionLocation, width, height);
  7491. var count = 0;
  7492. var i, ii, rows;
  7493. for (i = 0, ii = figures.length; i < ii; i++) {
  7494. switch (figures[i].type) {
  7495. case "lattice":
  7496. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  7497. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  7498. break;
  7499. case "triangles":
  7500. count += figures[i].coords.length;
  7501. break;
  7502. }
  7503. }
  7504. var coords = new Float32Array(count * 2);
  7505. var colors = new Uint8Array(count * 3);
  7506. var coordsMap = context.coords,
  7507. colorsMap = context.colors;
  7508. var pIndex = 0,
  7509. cIndex = 0;
  7510. for (i = 0, ii = figures.length; i < ii; i++) {
  7511. var figure = figures[i],
  7512. ps = figure.coords,
  7513. cs = figure.colors;
  7514. switch (figure.type) {
  7515. case "lattice":
  7516. var cols = figure.verticesPerRow;
  7517. rows = ps.length / cols | 0;
  7518. for (var row = 1; row < rows; row++) {
  7519. var offset = row * cols + 1;
  7520. for (var col = 1; col < cols; col++, offset++) {
  7521. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  7522. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  7523. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  7524. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  7525. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  7526. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  7527. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  7528. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  7529. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  7530. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  7531. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  7532. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  7533. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  7534. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  7535. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  7536. coords[pIndex + 6] = coords[pIndex + 2];
  7537. coords[pIndex + 7] = coords[pIndex + 3];
  7538. coords[pIndex + 8] = coords[pIndex + 4];
  7539. coords[pIndex + 9] = coords[pIndex + 5];
  7540. coords[pIndex + 10] = coordsMap[ps[offset]];
  7541. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  7542. colors[cIndex + 9] = colors[cIndex + 3];
  7543. colors[cIndex + 10] = colors[cIndex + 4];
  7544. colors[cIndex + 11] = colors[cIndex + 5];
  7545. colors[cIndex + 12] = colors[cIndex + 6];
  7546. colors[cIndex + 13] = colors[cIndex + 7];
  7547. colors[cIndex + 14] = colors[cIndex + 8];
  7548. colors[cIndex + 15] = colorsMap[cs[offset]];
  7549. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  7550. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  7551. pIndex += 12;
  7552. cIndex += 18;
  7553. }
  7554. }
  7555. break;
  7556. case "triangles":
  7557. for (var j = 0, jj = ps.length; j < jj; j++) {
  7558. coords[pIndex] = coordsMap[ps[j]];
  7559. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  7560. colors[cIndex] = colorsMap[cs[j]];
  7561. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  7562. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  7563. pIndex += 2;
  7564. cIndex += 3;
  7565. }
  7566. break;
  7567. }
  7568. }
  7569. if (backgroundColor) {
  7570. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  7571. } else {
  7572. gl.clearColor(0, 0, 0, 0);
  7573. }
  7574. gl.clear(gl.COLOR_BUFFER_BIT);
  7575. var coordsBuffer = gl.createBuffer();
  7576. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  7577. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  7578. gl.enableVertexAttribArray(cache.positionLocation);
  7579. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  7580. var colorsBuffer = gl.createBuffer();
  7581. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  7582. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  7583. gl.enableVertexAttribArray(cache.colorLocation);
  7584. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  7585. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  7586. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  7587. gl.drawArrays(gl.TRIANGLES, 0, count);
  7588. gl.flush();
  7589. gl.deleteBuffer(coordsBuffer);
  7590. gl.deleteBuffer(colorsBuffer);
  7591. return canvas;
  7592. }
  7593. return {
  7594. tryInitGL() {
  7595. try {
  7596. generateGL();
  7597. return !!currentGL;
  7598. } catch (ex) {}
  7599. return false;
  7600. },
  7601. composeSMask,
  7602. drawFigures,
  7603. cleanup() {
  7604. if (smaskCache && smaskCache.canvas) {
  7605. smaskCache.canvas.width = 0;
  7606. smaskCache.canvas.height = 0;
  7607. }
  7608. if (figuresCache && figuresCache.canvas) {
  7609. figuresCache.canvas.width = 0;
  7610. figuresCache.canvas.height = 0;
  7611. }
  7612. smaskCache = null;
  7613. figuresCache = null;
  7614. }
  7615. };
  7616. }();
  7617. /***/ }),
  7618. /* 19 */
  7619. /***/ (function(module, exports, __w_pdfjs_require__) {
  7620. "use strict";
  7621. Object.defineProperty(exports, "__esModule", {
  7622. value: true
  7623. });
  7624. exports.AnnotationLayer = void 0;
  7625. var _display_utils = __w_pdfjs_require__(1);
  7626. var _util = __w_pdfjs_require__(2);
  7627. var _annotation_storage = __w_pdfjs_require__(8);
  7628. class AnnotationElementFactory {
  7629. static create(parameters) {
  7630. const subtype = parameters.data.annotationType;
  7631. switch (subtype) {
  7632. case _util.AnnotationType.LINK:
  7633. return new LinkAnnotationElement(parameters);
  7634. case _util.AnnotationType.TEXT:
  7635. return new TextAnnotationElement(parameters);
  7636. case _util.AnnotationType.WIDGET:
  7637. const fieldType = parameters.data.fieldType;
  7638. switch (fieldType) {
  7639. case "Tx":
  7640. return new TextWidgetAnnotationElement(parameters);
  7641. case "Btn":
  7642. if (parameters.data.radioButton) {
  7643. return new RadioButtonWidgetAnnotationElement(parameters);
  7644. } else if (parameters.data.checkBox) {
  7645. return new CheckboxWidgetAnnotationElement(parameters);
  7646. }
  7647. return new PushButtonWidgetAnnotationElement(parameters);
  7648. case "Ch":
  7649. return new ChoiceWidgetAnnotationElement(parameters);
  7650. }
  7651. return new WidgetAnnotationElement(parameters);
  7652. case _util.AnnotationType.POPUP:
  7653. return new PopupAnnotationElement(parameters);
  7654. case _util.AnnotationType.FREETEXT:
  7655. return new FreeTextAnnotationElement(parameters);
  7656. case _util.AnnotationType.LINE:
  7657. return new LineAnnotationElement(parameters);
  7658. case _util.AnnotationType.SQUARE:
  7659. return new SquareAnnotationElement(parameters);
  7660. case _util.AnnotationType.CIRCLE:
  7661. return new CircleAnnotationElement(parameters);
  7662. case _util.AnnotationType.POLYLINE:
  7663. return new PolylineAnnotationElement(parameters);
  7664. case _util.AnnotationType.CARET:
  7665. return new CaretAnnotationElement(parameters);
  7666. case _util.AnnotationType.INK:
  7667. return new InkAnnotationElement(parameters);
  7668. case _util.AnnotationType.POLYGON:
  7669. return new PolygonAnnotationElement(parameters);
  7670. case _util.AnnotationType.HIGHLIGHT:
  7671. return new HighlightAnnotationElement(parameters);
  7672. case _util.AnnotationType.UNDERLINE:
  7673. return new UnderlineAnnotationElement(parameters);
  7674. case _util.AnnotationType.SQUIGGLY:
  7675. return new SquigglyAnnotationElement(parameters);
  7676. case _util.AnnotationType.STRIKEOUT:
  7677. return new StrikeOutAnnotationElement(parameters);
  7678. case _util.AnnotationType.STAMP:
  7679. return new StampAnnotationElement(parameters);
  7680. case _util.AnnotationType.FILEATTACHMENT:
  7681. return new FileAttachmentAnnotationElement(parameters);
  7682. default:
  7683. return new AnnotationElement(parameters);
  7684. }
  7685. }
  7686. }
  7687. class AnnotationElement {
  7688. constructor(parameters, isRenderable = false, ignoreBorder = false) {
  7689. this.isRenderable = isRenderable;
  7690. this.data = parameters.data;
  7691. this.layer = parameters.layer;
  7692. this.page = parameters.page;
  7693. this.viewport = parameters.viewport;
  7694. this.linkService = parameters.linkService;
  7695. this.downloadManager = parameters.downloadManager;
  7696. this.imageResourcesPath = parameters.imageResourcesPath;
  7697. this.renderInteractiveForms = parameters.renderInteractiveForms;
  7698. this.svgFactory = parameters.svgFactory;
  7699. this.annotationStorage = parameters.annotationStorage;
  7700. if (isRenderable) {
  7701. this.container = this._createContainer(ignoreBorder);
  7702. }
  7703. }
  7704. _createContainer(ignoreBorder = false) {
  7705. const data = this.data,
  7706. page = this.page,
  7707. viewport = this.viewport;
  7708. const container = document.createElement("section");
  7709. let width = data.rect[2] - data.rect[0];
  7710. let height = data.rect[3] - data.rect[1];
  7711. container.setAttribute("data-annotation-id", data.id);
  7712. const rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  7713. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7714. container.style.transformOrigin = `-${rect[0]}px -${rect[1]}px`;
  7715. if (!ignoreBorder && data.borderStyle.width > 0) {
  7716. container.style.borderWidth = `${data.borderStyle.width}px`;
  7717. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7718. width = width - 2 * data.borderStyle.width;
  7719. height = height - 2 * data.borderStyle.width;
  7720. }
  7721. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7722. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7723. if (horizontalRadius > 0 || verticalRadius > 0) {
  7724. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7725. container.style.borderRadius = radius;
  7726. }
  7727. switch (data.borderStyle.style) {
  7728. case _util.AnnotationBorderStyleType.SOLID:
  7729. container.style.borderStyle = "solid";
  7730. break;
  7731. case _util.AnnotationBorderStyleType.DASHED:
  7732. container.style.borderStyle = "dashed";
  7733. break;
  7734. case _util.AnnotationBorderStyleType.BEVELED:
  7735. (0, _util.warn)("Unimplemented border style: beveled");
  7736. break;
  7737. case _util.AnnotationBorderStyleType.INSET:
  7738. (0, _util.warn)("Unimplemented border style: inset");
  7739. break;
  7740. case _util.AnnotationBorderStyleType.UNDERLINE:
  7741. container.style.borderBottomStyle = "solid";
  7742. break;
  7743. default:
  7744. break;
  7745. }
  7746. if (data.color) {
  7747. container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7748. } else {
  7749. container.style.borderWidth = 0;
  7750. }
  7751. }
  7752. container.style.left = `${rect[0]}px`;
  7753. container.style.top = `${rect[1]}px`;
  7754. container.style.width = `${width}px`;
  7755. container.style.height = `${height}px`;
  7756. return container;
  7757. }
  7758. _createPopup(container, trigger, data) {
  7759. if (!trigger) {
  7760. trigger = document.createElement("div");
  7761. trigger.style.height = container.style.height;
  7762. trigger.style.width = container.style.width;
  7763. container.appendChild(trigger);
  7764. }
  7765. const popupElement = new PopupElement({
  7766. container,
  7767. trigger,
  7768. color: data.color,
  7769. title: data.title,
  7770. modificationDate: data.modificationDate,
  7771. contents: data.contents,
  7772. hideWrapper: true
  7773. });
  7774. const popup = popupElement.render();
  7775. popup.style.left = container.style.width;
  7776. container.appendChild(popup);
  7777. }
  7778. render() {
  7779. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  7780. }
  7781. }
  7782. class LinkAnnotationElement extends AnnotationElement {
  7783. constructor(parameters) {
  7784. const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action);
  7785. super(parameters, isRenderable);
  7786. }
  7787. render() {
  7788. this.container.className = "linkAnnotation";
  7789. const {
  7790. data,
  7791. linkService
  7792. } = this;
  7793. const link = document.createElement("a");
  7794. if (data.url) {
  7795. (0, _display_utils.addLinkAttributes)(link, {
  7796. url: data.url,
  7797. target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget,
  7798. rel: linkService.externalLinkRel,
  7799. enabled: linkService.externalLinkEnabled
  7800. });
  7801. } else if (data.action) {
  7802. this._bindNamedAction(link, data.action);
  7803. } else {
  7804. this._bindLink(link, data.dest);
  7805. }
  7806. this.container.appendChild(link);
  7807. return this.container;
  7808. }
  7809. _bindLink(link, destination) {
  7810. link.href = this.linkService.getDestinationHash(destination);
  7811. link.onclick = () => {
  7812. if (destination) {
  7813. this.linkService.navigateTo(destination);
  7814. }
  7815. return false;
  7816. };
  7817. if (destination) {
  7818. link.className = "internalLink";
  7819. }
  7820. }
  7821. _bindNamedAction(link, action) {
  7822. link.href = this.linkService.getAnchorUrl("");
  7823. link.onclick = () => {
  7824. this.linkService.executeNamedAction(action);
  7825. return false;
  7826. };
  7827. link.className = "internalLink";
  7828. }
  7829. }
  7830. class TextAnnotationElement extends AnnotationElement {
  7831. constructor(parameters) {
  7832. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  7833. super(parameters, isRenderable);
  7834. }
  7835. render() {
  7836. this.container.className = "textAnnotation";
  7837. const image = document.createElement("img");
  7838. image.style.height = this.container.style.height;
  7839. image.style.width = this.container.style.width;
  7840. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  7841. image.alt = "[{{type}} Annotation]";
  7842. image.dataset.l10nId = "text_annotation_type";
  7843. image.dataset.l10nArgs = JSON.stringify({
  7844. type: this.data.name
  7845. });
  7846. if (!this.data.hasPopup) {
  7847. this._createPopup(this.container, image, this.data);
  7848. }
  7849. this.container.appendChild(image);
  7850. return this.container;
  7851. }
  7852. }
  7853. class WidgetAnnotationElement extends AnnotationElement {
  7854. render() {
  7855. return this.container;
  7856. }
  7857. }
  7858. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  7859. constructor(parameters) {
  7860. const isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  7861. super(parameters, isRenderable);
  7862. }
  7863. render() {
  7864. const TEXT_ALIGNMENT = ["left", "center", "right"];
  7865. const storage = this.annotationStorage;
  7866. const id = this.data.id;
  7867. this.container.className = "textWidgetAnnotation";
  7868. let element = null;
  7869. if (this.renderInteractiveForms) {
  7870. const textContent = storage.getOrCreateValue(id, this.data.fieldValue);
  7871. if (this.data.multiLine) {
  7872. element = document.createElement("textarea");
  7873. element.textContent = textContent;
  7874. } else {
  7875. element = document.createElement("input");
  7876. element.type = "text";
  7877. element.setAttribute("value", textContent);
  7878. }
  7879. element.addEventListener("input", function (event) {
  7880. storage.setValue(id, event.target.value);
  7881. });
  7882. element.disabled = this.data.readOnly;
  7883. element.name = this.data.fieldName;
  7884. if (this.data.maxLen !== null) {
  7885. element.maxLength = this.data.maxLen;
  7886. }
  7887. if (this.data.comb) {
  7888. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  7889. const combWidth = fieldWidth / this.data.maxLen;
  7890. element.classList.add("comb");
  7891. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  7892. }
  7893. } else {
  7894. element = document.createElement("div");
  7895. element.textContent = this.data.fieldValue;
  7896. element.style.verticalAlign = "middle";
  7897. element.style.display = "table-cell";
  7898. let font = null;
  7899. if (this.data.fontRefName && this.page.commonObjs.has(this.data.fontRefName)) {
  7900. font = this.page.commonObjs.get(this.data.fontRefName);
  7901. }
  7902. this._setTextStyle(element, font);
  7903. }
  7904. if (this.data.textAlignment !== null) {
  7905. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  7906. }
  7907. this.container.appendChild(element);
  7908. return this.container;
  7909. }
  7910. _setTextStyle(element, font) {
  7911. const style = element.style;
  7912. style.fontSize = `${this.data.fontSize}px`;
  7913. style.direction = this.data.fontDirection < 0 ? "rtl" : "ltr";
  7914. if (!font) {
  7915. return;
  7916. }
  7917. let bold = "normal";
  7918. if (font.black) {
  7919. bold = "900";
  7920. } else if (font.bold) {
  7921. bold = "bold";
  7922. }
  7923. style.fontWeight = bold;
  7924. style.fontStyle = font.italic ? "italic" : "normal";
  7925. const fontFamily = font.loadedName ? `"${font.loadedName}", ` : "";
  7926. const fallbackName = font.fallbackName || "Helvetica, sans-serif";
  7927. style.fontFamily = fontFamily + fallbackName;
  7928. }
  7929. }
  7930. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  7931. constructor(parameters) {
  7932. super(parameters, parameters.renderInteractiveForms);
  7933. }
  7934. render() {
  7935. const storage = this.annotationStorage;
  7936. const data = this.data;
  7937. const id = data.id;
  7938. const value = storage.getOrCreateValue(id, data.fieldValue && data.fieldValue !== "Off");
  7939. this.container.className = "buttonWidgetAnnotation checkBox";
  7940. const element = document.createElement("input");
  7941. element.disabled = data.readOnly;
  7942. element.type = "checkbox";
  7943. element.name = this.data.fieldName;
  7944. if (value) {
  7945. element.setAttribute("checked", true);
  7946. }
  7947. element.addEventListener("change", function (event) {
  7948. storage.setValue(id, event.target.checked);
  7949. });
  7950. this.container.appendChild(element);
  7951. return this.container;
  7952. }
  7953. }
  7954. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  7955. constructor(parameters) {
  7956. super(parameters, parameters.renderInteractiveForms);
  7957. }
  7958. render() {
  7959. this.container.className = "buttonWidgetAnnotation radioButton";
  7960. const storage = this.annotationStorage;
  7961. const data = this.data;
  7962. const id = data.id;
  7963. const value = storage.getOrCreateValue(id, data.fieldValue === data.buttonValue);
  7964. const element = document.createElement("input");
  7965. element.disabled = data.readOnly;
  7966. element.type = "radio";
  7967. element.name = data.fieldName;
  7968. if (value) {
  7969. element.setAttribute("checked", true);
  7970. }
  7971. element.addEventListener("change", function (event) {
  7972. const name = event.target.name;
  7973. for (const radio of document.getElementsByName(name)) {
  7974. if (radio !== event.target) {
  7975. storage.setValue(radio.parentNode.getAttribute("data-annotation-id"), false);
  7976. }
  7977. }
  7978. storage.setValue(id, event.target.checked);
  7979. });
  7980. this.container.appendChild(element);
  7981. return this.container;
  7982. }
  7983. }
  7984. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  7985. render() {
  7986. const container = super.render();
  7987. container.className = "buttonWidgetAnnotation pushButton";
  7988. return container;
  7989. }
  7990. }
  7991. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  7992. constructor(parameters) {
  7993. super(parameters, parameters.renderInteractiveForms);
  7994. }
  7995. render() {
  7996. this.container.className = "choiceWidgetAnnotation";
  7997. const storage = this.annotationStorage;
  7998. const id = this.data.id;
  7999. storage.getOrCreateValue(id, this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : null);
  8000. const selectElement = document.createElement("select");
  8001. selectElement.disabled = this.data.readOnly;
  8002. selectElement.name = this.data.fieldName;
  8003. if (!this.data.combo) {
  8004. selectElement.size = this.data.options.length;
  8005. if (this.data.multiSelect) {
  8006. selectElement.multiple = true;
  8007. }
  8008. }
  8009. for (const option of this.data.options) {
  8010. const optionElement = document.createElement("option");
  8011. optionElement.textContent = option.displayValue;
  8012. optionElement.value = option.exportValue;
  8013. if (this.data.fieldValue.includes(option.exportValue)) {
  8014. optionElement.setAttribute("selected", true);
  8015. }
  8016. selectElement.appendChild(optionElement);
  8017. }
  8018. selectElement.addEventListener("input", function (event) {
  8019. const options = event.target.options;
  8020. const value = options[options.selectedIndex].value;
  8021. storage.setValue(id, value);
  8022. });
  8023. this.container.appendChild(selectElement);
  8024. return this.container;
  8025. }
  8026. }
  8027. class PopupAnnotationElement extends AnnotationElement {
  8028. constructor(parameters) {
  8029. const isRenderable = !!(parameters.data.title || parameters.data.contents);
  8030. super(parameters, isRenderable);
  8031. }
  8032. render() {
  8033. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  8034. this.container.className = "popupAnnotation";
  8035. if (IGNORE_TYPES.includes(this.data.parentType)) {
  8036. return this.container;
  8037. }
  8038. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  8039. const parentElement = this.layer.querySelector(selector);
  8040. if (!parentElement) {
  8041. return this.container;
  8042. }
  8043. const popup = new PopupElement({
  8044. container: this.container,
  8045. trigger: parentElement,
  8046. color: this.data.color,
  8047. title: this.data.title,
  8048. modificationDate: this.data.modificationDate,
  8049. contents: this.data.contents
  8050. });
  8051. const parentLeft = parseFloat(parentElement.style.left);
  8052. const parentWidth = parseFloat(parentElement.style.width);
  8053. this.container.style.transformOrigin = `-${parentLeft + parentWidth}px -${parentElement.style.top}`;
  8054. this.container.style.left = `${parentLeft + parentWidth}px`;
  8055. this.container.appendChild(popup.render());
  8056. return this.container;
  8057. }
  8058. }
  8059. class PopupElement {
  8060. constructor(parameters) {
  8061. this.container = parameters.container;
  8062. this.trigger = parameters.trigger;
  8063. this.color = parameters.color;
  8064. this.title = parameters.title;
  8065. this.modificationDate = parameters.modificationDate;
  8066. this.contents = parameters.contents;
  8067. this.hideWrapper = parameters.hideWrapper || false;
  8068. this.pinned = false;
  8069. }
  8070. render() {
  8071. const BACKGROUND_ENLIGHT = 0.7;
  8072. const wrapper = document.createElement("div");
  8073. wrapper.className = "popupWrapper";
  8074. this.hideElement = this.hideWrapper ? wrapper : this.container;
  8075. this.hideElement.setAttribute("hidden", true);
  8076. const popup = document.createElement("div");
  8077. popup.className = "popup";
  8078. const color = this.color;
  8079. if (color) {
  8080. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  8081. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  8082. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  8083. popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
  8084. }
  8085. const title = document.createElement("h1");
  8086. title.textContent = this.title;
  8087. popup.appendChild(title);
  8088. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  8089. if (dateObject) {
  8090. const modificationDate = document.createElement("span");
  8091. modificationDate.textContent = "{{date}}, {{time}}";
  8092. modificationDate.dataset.l10nId = "annotation_date_string";
  8093. modificationDate.dataset.l10nArgs = JSON.stringify({
  8094. date: dateObject.toLocaleDateString(),
  8095. time: dateObject.toLocaleTimeString()
  8096. });
  8097. popup.appendChild(modificationDate);
  8098. }
  8099. const contents = this._formatContents(this.contents);
  8100. popup.appendChild(contents);
  8101. this.trigger.addEventListener("click", this._toggle.bind(this));
  8102. this.trigger.addEventListener("mouseover", this._show.bind(this, false));
  8103. this.trigger.addEventListener("mouseout", this._hide.bind(this, false));
  8104. popup.addEventListener("click", this._hide.bind(this, true));
  8105. wrapper.appendChild(popup);
  8106. return wrapper;
  8107. }
  8108. _formatContents(contents) {
  8109. const p = document.createElement("p");
  8110. const lines = contents.split(/(?:\r\n?|\n)/);
  8111. for (let i = 0, ii = lines.length; i < ii; ++i) {
  8112. const line = lines[i];
  8113. p.appendChild(document.createTextNode(line));
  8114. if (i < ii - 1) {
  8115. p.appendChild(document.createElement("br"));
  8116. }
  8117. }
  8118. return p;
  8119. }
  8120. _toggle() {
  8121. if (this.pinned) {
  8122. this._hide(true);
  8123. } else {
  8124. this._show(true);
  8125. }
  8126. }
  8127. _show(pin = false) {
  8128. if (pin) {
  8129. this.pinned = true;
  8130. }
  8131. if (this.hideElement.hasAttribute("hidden")) {
  8132. this.hideElement.removeAttribute("hidden");
  8133. this.container.style.zIndex += 1;
  8134. }
  8135. }
  8136. _hide(unpin = true) {
  8137. if (unpin) {
  8138. this.pinned = false;
  8139. }
  8140. if (!this.hideElement.hasAttribute("hidden") && !this.pinned) {
  8141. this.hideElement.setAttribute("hidden", true);
  8142. this.container.style.zIndex -= 1;
  8143. }
  8144. }
  8145. }
  8146. class FreeTextAnnotationElement extends AnnotationElement {
  8147. constructor(parameters) {
  8148. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8149. super(parameters, isRenderable, true);
  8150. }
  8151. render() {
  8152. this.container.className = "freeTextAnnotation";
  8153. if (!this.data.hasPopup) {
  8154. this._createPopup(this.container, null, this.data);
  8155. }
  8156. return this.container;
  8157. }
  8158. }
  8159. class LineAnnotationElement extends AnnotationElement {
  8160. constructor(parameters) {
  8161. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8162. super(parameters, isRenderable, true);
  8163. }
  8164. render() {
  8165. this.container.className = "lineAnnotation";
  8166. const data = this.data;
  8167. const width = data.rect[2] - data.rect[0];
  8168. const height = data.rect[3] - data.rect[1];
  8169. const svg = this.svgFactory.create(width, height);
  8170. const line = this.svgFactory.createElement("svg:line");
  8171. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  8172. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  8173. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  8174. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  8175. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  8176. line.setAttribute("stroke", "transparent");
  8177. svg.appendChild(line);
  8178. this.container.append(svg);
  8179. this._createPopup(this.container, line, data);
  8180. return this.container;
  8181. }
  8182. }
  8183. class SquareAnnotationElement extends AnnotationElement {
  8184. constructor(parameters) {
  8185. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8186. super(parameters, isRenderable, true);
  8187. }
  8188. render() {
  8189. this.container.className = "squareAnnotation";
  8190. const data = this.data;
  8191. const width = data.rect[2] - data.rect[0];
  8192. const height = data.rect[3] - data.rect[1];
  8193. const svg = this.svgFactory.create(width, height);
  8194. const borderWidth = data.borderStyle.width;
  8195. const square = this.svgFactory.createElement("svg:rect");
  8196. square.setAttribute("x", borderWidth / 2);
  8197. square.setAttribute("y", borderWidth / 2);
  8198. square.setAttribute("width", width - borderWidth);
  8199. square.setAttribute("height", height - borderWidth);
  8200. square.setAttribute("stroke-width", borderWidth || 1);
  8201. square.setAttribute("stroke", "transparent");
  8202. square.setAttribute("fill", "none");
  8203. svg.appendChild(square);
  8204. this.container.append(svg);
  8205. this._createPopup(this.container, square, data);
  8206. return this.container;
  8207. }
  8208. }
  8209. class CircleAnnotationElement extends AnnotationElement {
  8210. constructor(parameters) {
  8211. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8212. super(parameters, isRenderable, true);
  8213. }
  8214. render() {
  8215. this.container.className = "circleAnnotation";
  8216. const data = this.data;
  8217. const width = data.rect[2] - data.rect[0];
  8218. const height = data.rect[3] - data.rect[1];
  8219. const svg = this.svgFactory.create(width, height);
  8220. const borderWidth = data.borderStyle.width;
  8221. const circle = this.svgFactory.createElement("svg:ellipse");
  8222. circle.setAttribute("cx", width / 2);
  8223. circle.setAttribute("cy", height / 2);
  8224. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  8225. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  8226. circle.setAttribute("stroke-width", borderWidth || 1);
  8227. circle.setAttribute("stroke", "transparent");
  8228. circle.setAttribute("fill", "none");
  8229. svg.appendChild(circle);
  8230. this.container.append(svg);
  8231. this._createPopup(this.container, circle, data);
  8232. return this.container;
  8233. }
  8234. }
  8235. class PolylineAnnotationElement extends AnnotationElement {
  8236. constructor(parameters) {
  8237. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8238. super(parameters, isRenderable, true);
  8239. this.containerClassName = "polylineAnnotation";
  8240. this.svgElementName = "svg:polyline";
  8241. }
  8242. render() {
  8243. this.container.className = this.containerClassName;
  8244. const data = this.data;
  8245. const width = data.rect[2] - data.rect[0];
  8246. const height = data.rect[3] - data.rect[1];
  8247. const svg = this.svgFactory.create(width, height);
  8248. let points = [];
  8249. for (const coordinate of data.vertices) {
  8250. const x = coordinate.x - data.rect[0];
  8251. const y = data.rect[3] - coordinate.y;
  8252. points.push(x + "," + y);
  8253. }
  8254. points = points.join(" ");
  8255. const polyline = this.svgFactory.createElement(this.svgElementName);
  8256. polyline.setAttribute("points", points);
  8257. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8258. polyline.setAttribute("stroke", "transparent");
  8259. polyline.setAttribute("fill", "none");
  8260. svg.appendChild(polyline);
  8261. this.container.append(svg);
  8262. this._createPopup(this.container, polyline, data);
  8263. return this.container;
  8264. }
  8265. }
  8266. class PolygonAnnotationElement extends PolylineAnnotationElement {
  8267. constructor(parameters) {
  8268. super(parameters);
  8269. this.containerClassName = "polygonAnnotation";
  8270. this.svgElementName = "svg:polygon";
  8271. }
  8272. }
  8273. class CaretAnnotationElement extends AnnotationElement {
  8274. constructor(parameters) {
  8275. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8276. super(parameters, isRenderable, true);
  8277. }
  8278. render() {
  8279. this.container.className = "caretAnnotation";
  8280. if (!this.data.hasPopup) {
  8281. this._createPopup(this.container, null, this.data);
  8282. }
  8283. return this.container;
  8284. }
  8285. }
  8286. class InkAnnotationElement extends AnnotationElement {
  8287. constructor(parameters) {
  8288. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8289. super(parameters, isRenderable, true);
  8290. this.containerClassName = "inkAnnotation";
  8291. this.svgElementName = "svg:polyline";
  8292. }
  8293. render() {
  8294. this.container.className = this.containerClassName;
  8295. const data = this.data;
  8296. const width = data.rect[2] - data.rect[0];
  8297. const height = data.rect[3] - data.rect[1];
  8298. const svg = this.svgFactory.create(width, height);
  8299. for (const inkList of data.inkLists) {
  8300. let points = [];
  8301. for (const coordinate of inkList) {
  8302. const x = coordinate.x - data.rect[0];
  8303. const y = data.rect[3] - coordinate.y;
  8304. points.push(`${x},${y}`);
  8305. }
  8306. points = points.join(" ");
  8307. const polyline = this.svgFactory.createElement(this.svgElementName);
  8308. polyline.setAttribute("points", points);
  8309. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8310. polyline.setAttribute("stroke", "transparent");
  8311. polyline.setAttribute("fill", "none");
  8312. this._createPopup(this.container, polyline, data);
  8313. svg.appendChild(polyline);
  8314. }
  8315. this.container.append(svg);
  8316. return this.container;
  8317. }
  8318. }
  8319. class HighlightAnnotationElement extends AnnotationElement {
  8320. constructor(parameters) {
  8321. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8322. super(parameters, isRenderable, true);
  8323. }
  8324. render() {
  8325. this.container.className = "highlightAnnotation";
  8326. if (!this.data.hasPopup) {
  8327. this._createPopup(this.container, null, this.data);
  8328. }
  8329. return this.container;
  8330. }
  8331. }
  8332. class UnderlineAnnotationElement extends AnnotationElement {
  8333. constructor(parameters) {
  8334. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8335. super(parameters, isRenderable, true);
  8336. }
  8337. render() {
  8338. this.container.className = "underlineAnnotation";
  8339. if (!this.data.hasPopup) {
  8340. this._createPopup(this.container, null, this.data);
  8341. }
  8342. return this.container;
  8343. }
  8344. }
  8345. class SquigglyAnnotationElement extends AnnotationElement {
  8346. constructor(parameters) {
  8347. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8348. super(parameters, isRenderable, true);
  8349. }
  8350. render() {
  8351. this.container.className = "squigglyAnnotation";
  8352. if (!this.data.hasPopup) {
  8353. this._createPopup(this.container, null, this.data);
  8354. }
  8355. return this.container;
  8356. }
  8357. }
  8358. class StrikeOutAnnotationElement extends AnnotationElement {
  8359. constructor(parameters) {
  8360. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8361. super(parameters, isRenderable, true);
  8362. }
  8363. render() {
  8364. this.container.className = "strikeoutAnnotation";
  8365. if (!this.data.hasPopup) {
  8366. this._createPopup(this.container, null, this.data);
  8367. }
  8368. return this.container;
  8369. }
  8370. }
  8371. class StampAnnotationElement extends AnnotationElement {
  8372. constructor(parameters) {
  8373. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8374. super(parameters, isRenderable, true);
  8375. }
  8376. render() {
  8377. this.container.className = "stampAnnotation";
  8378. if (!this.data.hasPopup) {
  8379. this._createPopup(this.container, null, this.data);
  8380. }
  8381. return this.container;
  8382. }
  8383. }
  8384. class FileAttachmentAnnotationElement extends AnnotationElement {
  8385. constructor(parameters) {
  8386. super(parameters, true);
  8387. const {
  8388. filename,
  8389. content
  8390. } = this.data.file;
  8391. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  8392. this.content = content;
  8393. if (this.linkService.eventBus) {
  8394. this.linkService.eventBus.dispatch("fileattachmentannotation", {
  8395. source: this,
  8396. id: (0, _util.stringToPDFString)(filename),
  8397. filename,
  8398. content
  8399. });
  8400. }
  8401. }
  8402. render() {
  8403. this.container.className = "fileAttachmentAnnotation";
  8404. const trigger = document.createElement("div");
  8405. trigger.style.height = this.container.style.height;
  8406. trigger.style.width = this.container.style.width;
  8407. trigger.addEventListener("dblclick", this._download.bind(this));
  8408. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  8409. this._createPopup(this.container, trigger, this.data);
  8410. }
  8411. this.container.appendChild(trigger);
  8412. return this.container;
  8413. }
  8414. _download() {
  8415. if (!this.downloadManager) {
  8416. (0, _util.warn)("Download cannot be started due to unavailable download manager");
  8417. return;
  8418. }
  8419. this.downloadManager.downloadData(this.content, this.filename, "");
  8420. }
  8421. }
  8422. class AnnotationLayer {
  8423. static render(parameters) {
  8424. const sortedAnnotations = [],
  8425. popupAnnotations = [];
  8426. for (const data of parameters.annotations) {
  8427. if (!data) {
  8428. continue;
  8429. }
  8430. if (data.annotationType === _util.AnnotationType.POPUP) {
  8431. popupAnnotations.push(data);
  8432. continue;
  8433. }
  8434. sortedAnnotations.push(data);
  8435. }
  8436. if (popupAnnotations.length) {
  8437. sortedAnnotations.push(...popupAnnotations);
  8438. }
  8439. for (const data of sortedAnnotations) {
  8440. const element = AnnotationElementFactory.create({
  8441. data,
  8442. layer: parameters.div,
  8443. page: parameters.page,
  8444. viewport: parameters.viewport,
  8445. linkService: parameters.linkService,
  8446. downloadManager: parameters.downloadManager,
  8447. imageResourcesPath: parameters.imageResourcesPath || "",
  8448. renderInteractiveForms: typeof parameters.renderInteractiveForms === "boolean" ? parameters.renderInteractiveForms : true,
  8449. svgFactory: new _display_utils.DOMSVGFactory(),
  8450. annotationStorage: parameters.annotationStorage || new _annotation_storage.AnnotationStorage()
  8451. });
  8452. if (element.isRenderable) {
  8453. parameters.div.appendChild(element.render());
  8454. }
  8455. }
  8456. }
  8457. static update(parameters) {
  8458. for (const data of parameters.annotations) {
  8459. const element = parameters.div.querySelector(`[data-annotation-id="${data.id}"]`);
  8460. if (element) {
  8461. element.style.transform = `matrix(${parameters.viewport.transform.join(",")})`;
  8462. }
  8463. }
  8464. parameters.div.removeAttribute("hidden");
  8465. }
  8466. }
  8467. exports.AnnotationLayer = AnnotationLayer;
  8468. /***/ }),
  8469. /* 20 */
  8470. /***/ (function(module, exports, __w_pdfjs_require__) {
  8471. "use strict";
  8472. Object.defineProperty(exports, "__esModule", {
  8473. value: true
  8474. });
  8475. exports.renderTextLayer = void 0;
  8476. var _util = __w_pdfjs_require__(2);
  8477. var renderTextLayer = function renderTextLayerClosure() {
  8478. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  8479. var NonWhitespaceRegexp = /\S/;
  8480. function isAllWhitespace(str) {
  8481. return !NonWhitespaceRegexp.test(str);
  8482. }
  8483. function appendText(task, geom, styles) {
  8484. var textDiv = document.createElement("span");
  8485. var textDivProperties = {
  8486. angle: 0,
  8487. canvasWidth: 0,
  8488. isWhitespace: false,
  8489. originalTransform: null,
  8490. paddingBottom: 0,
  8491. paddingLeft: 0,
  8492. paddingRight: 0,
  8493. paddingTop: 0,
  8494. scale: 1
  8495. };
  8496. task._textDivs.push(textDiv);
  8497. if (isAllWhitespace(geom.str)) {
  8498. textDivProperties.isWhitespace = true;
  8499. task._textDivProperties.set(textDiv, textDivProperties);
  8500. return;
  8501. }
  8502. var tx = _util.Util.transform(task._viewport.transform, geom.transform);
  8503. var angle = Math.atan2(tx[1], tx[0]);
  8504. var style = styles[geom.fontName];
  8505. if (style.vertical) {
  8506. angle += Math.PI / 2;
  8507. }
  8508. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  8509. var fontAscent = fontHeight;
  8510. if (style.ascent) {
  8511. fontAscent = style.ascent * fontAscent;
  8512. } else if (style.descent) {
  8513. fontAscent = (1 + style.descent) * fontAscent;
  8514. }
  8515. let left, top;
  8516. if (angle === 0) {
  8517. left = tx[4];
  8518. top = tx[5] - fontAscent;
  8519. } else {
  8520. left = tx[4] + fontAscent * Math.sin(angle);
  8521. top = tx[5] - fontAscent * Math.cos(angle);
  8522. }
  8523. textDiv.style.left = `${left}px`;
  8524. textDiv.style.top = `${top}px`;
  8525. textDiv.style.fontSize = `${fontHeight}px`;
  8526. textDiv.style.fontFamily = style.fontFamily;
  8527. textDiv.textContent = geom.str;
  8528. if (task._fontInspectorEnabled) {
  8529. textDiv.dataset.fontName = geom.fontName;
  8530. }
  8531. if (angle !== 0) {
  8532. textDivProperties.angle = angle * (180 / Math.PI);
  8533. }
  8534. let shouldScaleText = false;
  8535. if (geom.str.length > 1) {
  8536. shouldScaleText = true;
  8537. } else if (geom.transform[0] !== geom.transform[3]) {
  8538. const absScaleX = Math.abs(geom.transform[0]),
  8539. absScaleY = Math.abs(geom.transform[3]);
  8540. if (absScaleX !== absScaleY && Math.max(absScaleX, absScaleY) / Math.min(absScaleX, absScaleY) > 1.5) {
  8541. shouldScaleText = true;
  8542. }
  8543. }
  8544. if (shouldScaleText) {
  8545. if (style.vertical) {
  8546. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  8547. } else {
  8548. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  8549. }
  8550. }
  8551. task._textDivProperties.set(textDiv, textDivProperties);
  8552. if (task._textContentStream) {
  8553. task._layoutText(textDiv);
  8554. }
  8555. if (task._enhanceTextSelection) {
  8556. var angleCos = 1,
  8557. angleSin = 0;
  8558. if (angle !== 0) {
  8559. angleCos = Math.cos(angle);
  8560. angleSin = Math.sin(angle);
  8561. }
  8562. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  8563. var divHeight = fontHeight;
  8564. var m, b;
  8565. if (angle !== 0) {
  8566. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  8567. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  8568. } else {
  8569. b = [left, top, left + divWidth, top + divHeight];
  8570. }
  8571. task._bounds.push({
  8572. left: b[0],
  8573. top: b[1],
  8574. right: b[2],
  8575. bottom: b[3],
  8576. div: textDiv,
  8577. size: [divWidth, divHeight],
  8578. m
  8579. });
  8580. }
  8581. }
  8582. function render(task) {
  8583. if (task._canceled) {
  8584. return;
  8585. }
  8586. var textDivs = task._textDivs;
  8587. var capability = task._capability;
  8588. var textDivsLength = textDivs.length;
  8589. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  8590. task._renderingDone = true;
  8591. capability.resolve();
  8592. return;
  8593. }
  8594. if (!task._textContentStream) {
  8595. for (var i = 0; i < textDivsLength; i++) {
  8596. task._layoutText(textDivs[i]);
  8597. }
  8598. }
  8599. task._renderingDone = true;
  8600. capability.resolve();
  8601. }
  8602. function findPositiveMin(ts, offset, count) {
  8603. let result = 0;
  8604. for (let i = 0; i < count; i++) {
  8605. const t = ts[offset++];
  8606. if (t > 0) {
  8607. result = result ? Math.min(t, result) : t;
  8608. }
  8609. }
  8610. return result;
  8611. }
  8612. function expand(task) {
  8613. var bounds = task._bounds;
  8614. var viewport = task._viewport;
  8615. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  8616. for (var i = 0; i < expanded.length; i++) {
  8617. var div = bounds[i].div;
  8618. var divProperties = task._textDivProperties.get(div);
  8619. if (divProperties.angle === 0) {
  8620. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  8621. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  8622. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  8623. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  8624. task._textDivProperties.set(div, divProperties);
  8625. continue;
  8626. }
  8627. var e = expanded[i],
  8628. b = bounds[i];
  8629. var m = b.m,
  8630. c = m[0],
  8631. s = m[1];
  8632. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  8633. var ts = new Float64Array(64);
  8634. points.forEach(function (p, j) {
  8635. var t = _util.Util.applyTransform(p, m);
  8636. ts[j + 0] = c && (e.left - t[0]) / c;
  8637. ts[j + 4] = s && (e.top - t[1]) / s;
  8638. ts[j + 8] = c && (e.right - t[0]) / c;
  8639. ts[j + 12] = s && (e.bottom - t[1]) / s;
  8640. ts[j + 16] = s && (e.left - t[0]) / -s;
  8641. ts[j + 20] = c && (e.top - t[1]) / c;
  8642. ts[j + 24] = s && (e.right - t[0]) / -s;
  8643. ts[j + 28] = c && (e.bottom - t[1]) / c;
  8644. ts[j + 32] = c && (e.left - t[0]) / -c;
  8645. ts[j + 36] = s && (e.top - t[1]) / -s;
  8646. ts[j + 40] = c && (e.right - t[0]) / -c;
  8647. ts[j + 44] = s && (e.bottom - t[1]) / -s;
  8648. ts[j + 48] = s && (e.left - t[0]) / s;
  8649. ts[j + 52] = c && (e.top - t[1]) / -c;
  8650. ts[j + 56] = s && (e.right - t[0]) / s;
  8651. ts[j + 60] = c && (e.bottom - t[1]) / -c;
  8652. });
  8653. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  8654. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  8655. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  8656. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  8657. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  8658. task._textDivProperties.set(div, divProperties);
  8659. }
  8660. }
  8661. function expandBounds(width, height, boxes) {
  8662. var bounds = boxes.map(function (box, i) {
  8663. return {
  8664. x1: box.left,
  8665. y1: box.top,
  8666. x2: box.right,
  8667. y2: box.bottom,
  8668. index: i,
  8669. x1New: undefined,
  8670. x2New: undefined
  8671. };
  8672. });
  8673. expandBoundsLTR(width, bounds);
  8674. var expanded = new Array(boxes.length);
  8675. bounds.forEach(function (b) {
  8676. var i = b.index;
  8677. expanded[i] = {
  8678. left: b.x1New,
  8679. top: 0,
  8680. right: b.x2New,
  8681. bottom: 0
  8682. };
  8683. });
  8684. boxes.map(function (box, i) {
  8685. var e = expanded[i],
  8686. b = bounds[i];
  8687. b.x1 = box.top;
  8688. b.y1 = width - e.right;
  8689. b.x2 = box.bottom;
  8690. b.y2 = width - e.left;
  8691. b.index = i;
  8692. b.x1New = undefined;
  8693. b.x2New = undefined;
  8694. });
  8695. expandBoundsLTR(height, bounds);
  8696. bounds.forEach(function (b) {
  8697. var i = b.index;
  8698. expanded[i].top = b.x1New;
  8699. expanded[i].bottom = b.x2New;
  8700. });
  8701. return expanded;
  8702. }
  8703. function expandBoundsLTR(width, bounds) {
  8704. bounds.sort(function (a, b) {
  8705. return a.x1 - b.x1 || a.index - b.index;
  8706. });
  8707. var fakeBoundary = {
  8708. x1: -Infinity,
  8709. y1: -Infinity,
  8710. x2: 0,
  8711. y2: Infinity,
  8712. index: -1,
  8713. x1New: 0,
  8714. x2New: 0
  8715. };
  8716. var horizon = [{
  8717. start: -Infinity,
  8718. end: Infinity,
  8719. boundary: fakeBoundary
  8720. }];
  8721. bounds.forEach(function (boundary) {
  8722. var i = 0;
  8723. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  8724. i++;
  8725. }
  8726. var j = horizon.length - 1;
  8727. while (j >= 0 && horizon[j].start >= boundary.y2) {
  8728. j--;
  8729. }
  8730. var horizonPart, affectedBoundary;
  8731. var q,
  8732. k,
  8733. maxXNew = -Infinity;
  8734. for (q = i; q <= j; q++) {
  8735. horizonPart = horizon[q];
  8736. affectedBoundary = horizonPart.boundary;
  8737. var xNew;
  8738. if (affectedBoundary.x2 > boundary.x1) {
  8739. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  8740. } else if (affectedBoundary.x2New === undefined) {
  8741. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  8742. } else {
  8743. xNew = affectedBoundary.x2New;
  8744. }
  8745. if (xNew > maxXNew) {
  8746. maxXNew = xNew;
  8747. }
  8748. }
  8749. boundary.x1New = maxXNew;
  8750. for (q = i; q <= j; q++) {
  8751. horizonPart = horizon[q];
  8752. affectedBoundary = horizonPart.boundary;
  8753. if (affectedBoundary.x2New === undefined) {
  8754. if (affectedBoundary.x2 > boundary.x1) {
  8755. if (affectedBoundary.index > boundary.index) {
  8756. affectedBoundary.x2New = affectedBoundary.x2;
  8757. }
  8758. } else {
  8759. affectedBoundary.x2New = maxXNew;
  8760. }
  8761. } else if (affectedBoundary.x2New > maxXNew) {
  8762. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  8763. }
  8764. }
  8765. var changedHorizon = [],
  8766. lastBoundary = null;
  8767. for (q = i; q <= j; q++) {
  8768. horizonPart = horizon[q];
  8769. affectedBoundary = horizonPart.boundary;
  8770. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  8771. if (lastBoundary === useBoundary) {
  8772. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  8773. } else {
  8774. changedHorizon.push({
  8775. start: horizonPart.start,
  8776. end: horizonPart.end,
  8777. boundary: useBoundary
  8778. });
  8779. lastBoundary = useBoundary;
  8780. }
  8781. }
  8782. if (horizon[i].start < boundary.y1) {
  8783. changedHorizon[0].start = boundary.y1;
  8784. changedHorizon.unshift({
  8785. start: horizon[i].start,
  8786. end: boundary.y1,
  8787. boundary: horizon[i].boundary
  8788. });
  8789. }
  8790. if (boundary.y2 < horizon[j].end) {
  8791. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  8792. changedHorizon.push({
  8793. start: boundary.y2,
  8794. end: horizon[j].end,
  8795. boundary: horizon[j].boundary
  8796. });
  8797. }
  8798. for (q = i; q <= j; q++) {
  8799. horizonPart = horizon[q];
  8800. affectedBoundary = horizonPart.boundary;
  8801. if (affectedBoundary.x2New !== undefined) {
  8802. continue;
  8803. }
  8804. var used = false;
  8805. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  8806. used = horizon[k].boundary === affectedBoundary;
  8807. }
  8808. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  8809. used = horizon[k].boundary === affectedBoundary;
  8810. }
  8811. for (k = 0; !used && k < changedHorizon.length; k++) {
  8812. used = changedHorizon[k].boundary === affectedBoundary;
  8813. }
  8814. if (!used) {
  8815. affectedBoundary.x2New = maxXNew;
  8816. }
  8817. }
  8818. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  8819. });
  8820. horizon.forEach(function (horizonPart) {
  8821. var affectedBoundary = horizonPart.boundary;
  8822. if (affectedBoundary.x2New === undefined) {
  8823. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  8824. }
  8825. });
  8826. }
  8827. function TextLayerRenderTask({
  8828. textContent,
  8829. textContentStream,
  8830. container,
  8831. viewport,
  8832. textDivs,
  8833. textContentItemsStr,
  8834. enhanceTextSelection
  8835. }) {
  8836. this._textContent = textContent;
  8837. this._textContentStream = textContentStream;
  8838. this._container = container;
  8839. this._document = container.ownerDocument;
  8840. this._viewport = viewport;
  8841. this._textDivs = textDivs || [];
  8842. this._textContentItemsStr = textContentItemsStr || [];
  8843. this._enhanceTextSelection = !!enhanceTextSelection;
  8844. this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
  8845. this._reader = null;
  8846. this._layoutTextLastFontSize = null;
  8847. this._layoutTextLastFontFamily = null;
  8848. this._layoutTextCtx = null;
  8849. this._textDivProperties = new WeakMap();
  8850. this._renderingDone = false;
  8851. this._canceled = false;
  8852. this._capability = (0, _util.createPromiseCapability)();
  8853. this._renderTimer = null;
  8854. this._bounds = [];
  8855. this._capability.promise.finally(() => {
  8856. if (this._layoutTextCtx) {
  8857. this._layoutTextCtx.canvas.width = 0;
  8858. this._layoutTextCtx.canvas.height = 0;
  8859. this._layoutTextCtx = null;
  8860. }
  8861. }).catch(() => {});
  8862. }
  8863. TextLayerRenderTask.prototype = {
  8864. get promise() {
  8865. return this._capability.promise;
  8866. },
  8867. cancel: function TextLayer_cancel() {
  8868. this._canceled = true;
  8869. if (this._reader) {
  8870. this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
  8871. this._reader = null;
  8872. }
  8873. if (this._renderTimer !== null) {
  8874. clearTimeout(this._renderTimer);
  8875. this._renderTimer = null;
  8876. }
  8877. this._capability.reject(new Error("TextLayer task cancelled."));
  8878. },
  8879. _processItems(items, styleCache) {
  8880. for (let i = 0, len = items.length; i < len; i++) {
  8881. this._textContentItemsStr.push(items[i].str);
  8882. appendText(this, items[i], styleCache);
  8883. }
  8884. },
  8885. _layoutText(textDiv) {
  8886. const textDivProperties = this._textDivProperties.get(textDiv);
  8887. if (textDivProperties.isWhitespace) {
  8888. return;
  8889. }
  8890. let transform = "";
  8891. if (textDivProperties.canvasWidth !== 0) {
  8892. const {
  8893. fontSize,
  8894. fontFamily
  8895. } = textDiv.style;
  8896. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  8897. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  8898. this._layoutTextLastFontSize = fontSize;
  8899. this._layoutTextLastFontFamily = fontFamily;
  8900. }
  8901. const {
  8902. width
  8903. } = this._layoutTextCtx.measureText(textDiv.textContent);
  8904. if (width > 0) {
  8905. textDivProperties.scale = textDivProperties.canvasWidth / width;
  8906. transform = `scaleX(${textDivProperties.scale})`;
  8907. }
  8908. }
  8909. if (textDivProperties.angle !== 0) {
  8910. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  8911. }
  8912. if (transform.length > 0) {
  8913. if (this._enhanceTextSelection) {
  8914. textDivProperties.originalTransform = transform;
  8915. }
  8916. textDiv.style.transform = transform;
  8917. }
  8918. this._textDivProperties.set(textDiv, textDivProperties);
  8919. this._container.appendChild(textDiv);
  8920. },
  8921. _render: function TextLayer_render(timeout) {
  8922. const capability = (0, _util.createPromiseCapability)();
  8923. let styleCache = Object.create(null);
  8924. const canvas = this._document.createElement("canvas");
  8925. canvas.mozOpaque = true;
  8926. this._layoutTextCtx = canvas.getContext("2d", {
  8927. alpha: false
  8928. });
  8929. if (this._textContent) {
  8930. const textItems = this._textContent.items;
  8931. const textStyles = this._textContent.styles;
  8932. this._processItems(textItems, textStyles);
  8933. capability.resolve();
  8934. } else if (this._textContentStream) {
  8935. const pump = () => {
  8936. this._reader.read().then(({
  8937. value,
  8938. done
  8939. }) => {
  8940. if (done) {
  8941. capability.resolve();
  8942. return;
  8943. }
  8944. Object.assign(styleCache, value.styles);
  8945. this._processItems(value.items, styleCache);
  8946. pump();
  8947. }, capability.reject);
  8948. };
  8949. this._reader = this._textContentStream.getReader();
  8950. pump();
  8951. } else {
  8952. throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
  8953. }
  8954. capability.promise.then(() => {
  8955. styleCache = null;
  8956. if (!timeout) {
  8957. render(this);
  8958. } else {
  8959. this._renderTimer = setTimeout(() => {
  8960. render(this);
  8961. this._renderTimer = null;
  8962. }, timeout);
  8963. }
  8964. }, this._capability.reject);
  8965. },
  8966. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  8967. if (!this._enhanceTextSelection || !this._renderingDone) {
  8968. return;
  8969. }
  8970. if (this._bounds !== null) {
  8971. expand(this);
  8972. this._bounds = null;
  8973. }
  8974. const transformBuf = [],
  8975. paddingBuf = [];
  8976. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  8977. const div = this._textDivs[i];
  8978. const divProps = this._textDivProperties.get(div);
  8979. if (divProps.isWhitespace) {
  8980. continue;
  8981. }
  8982. if (expandDivs) {
  8983. transformBuf.length = 0;
  8984. paddingBuf.length = 0;
  8985. if (divProps.originalTransform) {
  8986. transformBuf.push(divProps.originalTransform);
  8987. }
  8988. if (divProps.paddingTop > 0) {
  8989. paddingBuf.push(`${divProps.paddingTop}px`);
  8990. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  8991. } else {
  8992. paddingBuf.push(0);
  8993. }
  8994. if (divProps.paddingRight > 0) {
  8995. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  8996. } else {
  8997. paddingBuf.push(0);
  8998. }
  8999. if (divProps.paddingBottom > 0) {
  9000. paddingBuf.push(`${divProps.paddingBottom}px`);
  9001. } else {
  9002. paddingBuf.push(0);
  9003. }
  9004. if (divProps.paddingLeft > 0) {
  9005. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  9006. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  9007. } else {
  9008. paddingBuf.push(0);
  9009. }
  9010. div.style.padding = paddingBuf.join(" ");
  9011. if (transformBuf.length) {
  9012. div.style.transform = transformBuf.join(" ");
  9013. }
  9014. } else {
  9015. div.style.padding = null;
  9016. div.style.transform = divProps.originalTransform;
  9017. }
  9018. }
  9019. }
  9020. };
  9021. function renderTextLayer(renderParameters) {
  9022. var task = new TextLayerRenderTask({
  9023. textContent: renderParameters.textContent,
  9024. textContentStream: renderParameters.textContentStream,
  9025. container: renderParameters.container,
  9026. viewport: renderParameters.viewport,
  9027. textDivs: renderParameters.textDivs,
  9028. textContentItemsStr: renderParameters.textContentItemsStr,
  9029. enhanceTextSelection: renderParameters.enhanceTextSelection
  9030. });
  9031. task._render(renderParameters.timeout);
  9032. return task;
  9033. }
  9034. return renderTextLayer;
  9035. }();
  9036. exports.renderTextLayer = renderTextLayer;
  9037. /***/ }),
  9038. /* 21 */
  9039. /***/ (function(module, exports, __w_pdfjs_require__) {
  9040. "use strict";
  9041. Object.defineProperty(exports, "__esModule", {
  9042. value: true
  9043. });
  9044. exports.SVGGraphics = void 0;
  9045. var _util = __w_pdfjs_require__(2);
  9046. var _display_utils = __w_pdfjs_require__(1);
  9047. var _is_node = __w_pdfjs_require__(4);
  9048. let SVGGraphics = function () {
  9049. throw new Error("Not implemented: SVGGraphics");
  9050. };
  9051. exports.SVGGraphics = SVGGraphics;
  9052. {
  9053. const SVG_DEFAULTS = {
  9054. fontStyle: "normal",
  9055. fontWeight: "normal",
  9056. fillColor: "#000000"
  9057. };
  9058. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  9059. const XLINK_NS = "http://www.w3.org/1999/xlink";
  9060. const LINE_CAP_STYLES = ["butt", "round", "square"];
  9061. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  9062. const convertImgDataToPng = function () {
  9063. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  9064. const CHUNK_WRAPPER_SIZE = 12;
  9065. const crcTable = new Int32Array(256);
  9066. for (let i = 0; i < 256; i++) {
  9067. let c = i;
  9068. for (let h = 0; h < 8; h++) {
  9069. if (c & 1) {
  9070. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  9071. } else {
  9072. c = c >> 1 & 0x7fffffff;
  9073. }
  9074. }
  9075. crcTable[i] = c;
  9076. }
  9077. function crc32(data, start, end) {
  9078. let crc = -1;
  9079. for (let i = start; i < end; i++) {
  9080. const a = (crc ^ data[i]) & 0xff;
  9081. const b = crcTable[a];
  9082. crc = crc >>> 8 ^ b;
  9083. }
  9084. return crc ^ -1;
  9085. }
  9086. function writePngChunk(type, body, data, offset) {
  9087. let p = offset;
  9088. const len = body.length;
  9089. data[p] = len >> 24 & 0xff;
  9090. data[p + 1] = len >> 16 & 0xff;
  9091. data[p + 2] = len >> 8 & 0xff;
  9092. data[p + 3] = len & 0xff;
  9093. p += 4;
  9094. data[p] = type.charCodeAt(0) & 0xff;
  9095. data[p + 1] = type.charCodeAt(1) & 0xff;
  9096. data[p + 2] = type.charCodeAt(2) & 0xff;
  9097. data[p + 3] = type.charCodeAt(3) & 0xff;
  9098. p += 4;
  9099. data.set(body, p);
  9100. p += body.length;
  9101. const crc = crc32(data, offset + 4, p);
  9102. data[p] = crc >> 24 & 0xff;
  9103. data[p + 1] = crc >> 16 & 0xff;
  9104. data[p + 2] = crc >> 8 & 0xff;
  9105. data[p + 3] = crc & 0xff;
  9106. }
  9107. function adler32(data, start, end) {
  9108. let a = 1;
  9109. let b = 0;
  9110. for (let i = start; i < end; ++i) {
  9111. a = (a + (data[i] & 0xff)) % 65521;
  9112. b = (b + a) % 65521;
  9113. }
  9114. return b << 16 | a;
  9115. }
  9116. function deflateSync(literals) {
  9117. if (!_is_node.isNodeJS) {
  9118. return deflateSyncUncompressed(literals);
  9119. }
  9120. try {
  9121. let input;
  9122. if (parseInt(process.versions.node) >= 8) {
  9123. input = literals;
  9124. } else {
  9125. input = Buffer.from(literals);
  9126. }
  9127. const output = require("zlib").deflateSync(input, {
  9128. level: 9
  9129. });
  9130. return output instanceof Uint8Array ? output : new Uint8Array(output);
  9131. } catch (e) {
  9132. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  9133. }
  9134. return deflateSyncUncompressed(literals);
  9135. }
  9136. function deflateSyncUncompressed(literals) {
  9137. let len = literals.length;
  9138. const maxBlockLength = 0xffff;
  9139. const deflateBlocks = Math.ceil(len / maxBlockLength);
  9140. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  9141. let pi = 0;
  9142. idat[pi++] = 0x78;
  9143. idat[pi++] = 0x9c;
  9144. let pos = 0;
  9145. while (len > maxBlockLength) {
  9146. idat[pi++] = 0x00;
  9147. idat[pi++] = 0xff;
  9148. idat[pi++] = 0xff;
  9149. idat[pi++] = 0x00;
  9150. idat[pi++] = 0x00;
  9151. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  9152. pi += maxBlockLength;
  9153. pos += maxBlockLength;
  9154. len -= maxBlockLength;
  9155. }
  9156. idat[pi++] = 0x01;
  9157. idat[pi++] = len & 0xff;
  9158. idat[pi++] = len >> 8 & 0xff;
  9159. idat[pi++] = ~len & 0xffff & 0xff;
  9160. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  9161. idat.set(literals.subarray(pos), pi);
  9162. pi += literals.length - pos;
  9163. const adler = adler32(literals, 0, literals.length);
  9164. idat[pi++] = adler >> 24 & 0xff;
  9165. idat[pi++] = adler >> 16 & 0xff;
  9166. idat[pi++] = adler >> 8 & 0xff;
  9167. idat[pi++] = adler & 0xff;
  9168. return idat;
  9169. }
  9170. function encode(imgData, kind, forceDataSchema, isMask) {
  9171. const width = imgData.width;
  9172. const height = imgData.height;
  9173. let bitDepth, colorType, lineSize;
  9174. const bytes = imgData.data;
  9175. switch (kind) {
  9176. case _util.ImageKind.GRAYSCALE_1BPP:
  9177. colorType = 0;
  9178. bitDepth = 1;
  9179. lineSize = width + 7 >> 3;
  9180. break;
  9181. case _util.ImageKind.RGB_24BPP:
  9182. colorType = 2;
  9183. bitDepth = 8;
  9184. lineSize = width * 3;
  9185. break;
  9186. case _util.ImageKind.RGBA_32BPP:
  9187. colorType = 6;
  9188. bitDepth = 8;
  9189. lineSize = width * 4;
  9190. break;
  9191. default:
  9192. throw new Error("invalid format");
  9193. }
  9194. const literals = new Uint8Array((1 + lineSize) * height);
  9195. let offsetLiterals = 0,
  9196. offsetBytes = 0;
  9197. for (let y = 0; y < height; ++y) {
  9198. literals[offsetLiterals++] = 0;
  9199. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  9200. offsetBytes += lineSize;
  9201. offsetLiterals += lineSize;
  9202. }
  9203. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  9204. offsetLiterals = 0;
  9205. for (let y = 0; y < height; y++) {
  9206. offsetLiterals++;
  9207. for (let i = 0; i < lineSize; i++) {
  9208. literals[offsetLiterals++] ^= 0xff;
  9209. }
  9210. }
  9211. }
  9212. const ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]);
  9213. const idat = deflateSync(literals);
  9214. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  9215. const data = new Uint8Array(pngLength);
  9216. let offset = 0;
  9217. data.set(PNG_HEADER, offset);
  9218. offset += PNG_HEADER.length;
  9219. writePngChunk("IHDR", ihdr, data, offset);
  9220. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  9221. writePngChunk("IDATA", idat, data, offset);
  9222. offset += CHUNK_WRAPPER_SIZE + idat.length;
  9223. writePngChunk("IEND", new Uint8Array(0), data, offset);
  9224. return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
  9225. }
  9226. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  9227. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  9228. return encode(imgData, kind, forceDataSchema, isMask);
  9229. };
  9230. }();
  9231. class SVGExtraState {
  9232. constructor() {
  9233. this.fontSizeScale = 1;
  9234. this.fontWeight = SVG_DEFAULTS.fontWeight;
  9235. this.fontSize = 0;
  9236. this.textMatrix = _util.IDENTITY_MATRIX;
  9237. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  9238. this.leading = 0;
  9239. this.textRenderingMode = _util.TextRenderingMode.FILL;
  9240. this.textMatrixScale = 1;
  9241. this.x = 0;
  9242. this.y = 0;
  9243. this.lineX = 0;
  9244. this.lineY = 0;
  9245. this.charSpacing = 0;
  9246. this.wordSpacing = 0;
  9247. this.textHScale = 1;
  9248. this.textRise = 0;
  9249. this.fillColor = SVG_DEFAULTS.fillColor;
  9250. this.strokeColor = "#000000";
  9251. this.fillAlpha = 1;
  9252. this.strokeAlpha = 1;
  9253. this.lineWidth = 1;
  9254. this.lineJoin = "";
  9255. this.lineCap = "";
  9256. this.miterLimit = 0;
  9257. this.dashArray = [];
  9258. this.dashPhase = 0;
  9259. this.dependencies = [];
  9260. this.activeClipUrl = null;
  9261. this.clipGroup = null;
  9262. this.maskId = "";
  9263. }
  9264. clone() {
  9265. return Object.create(this);
  9266. }
  9267. setCurrentPoint(x, y) {
  9268. this.x = x;
  9269. this.y = y;
  9270. }
  9271. }
  9272. function opListToTree(opList) {
  9273. let opTree = [];
  9274. const tmp = [];
  9275. for (const opListElement of opList) {
  9276. if (opListElement.fn === "save") {
  9277. opTree.push({
  9278. fnId: 92,
  9279. fn: "group",
  9280. items: []
  9281. });
  9282. tmp.push(opTree);
  9283. opTree = opTree[opTree.length - 1].items;
  9284. continue;
  9285. }
  9286. if (opListElement.fn === "restore") {
  9287. opTree = tmp.pop();
  9288. } else {
  9289. opTree.push(opListElement);
  9290. }
  9291. }
  9292. return opTree;
  9293. }
  9294. function pf(value) {
  9295. if (Number.isInteger(value)) {
  9296. return value.toString();
  9297. }
  9298. const s = value.toFixed(10);
  9299. let i = s.length - 1;
  9300. if (s[i] !== "0") {
  9301. return s;
  9302. }
  9303. do {
  9304. i--;
  9305. } while (s[i] === "0");
  9306. return s.substring(0, s[i] === "." ? i : i + 1);
  9307. }
  9308. function pm(m) {
  9309. if (m[4] === 0 && m[5] === 0) {
  9310. if (m[1] === 0 && m[2] === 0) {
  9311. if (m[0] === 1 && m[3] === 1) {
  9312. return "";
  9313. }
  9314. return `scale(${pf(m[0])} ${pf(m[3])})`;
  9315. }
  9316. if (m[0] === m[3] && m[1] === -m[2]) {
  9317. const a = Math.acos(m[0]) * 180 / Math.PI;
  9318. return `rotate(${pf(a)})`;
  9319. }
  9320. } else {
  9321. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  9322. return `translate(${pf(m[4])} ${pf(m[5])})`;
  9323. }
  9324. }
  9325. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  9326. }
  9327. let clipCount = 0;
  9328. let maskCount = 0;
  9329. let shadingCount = 0;
  9330. exports.SVGGraphics = SVGGraphics = class SVGGraphics {
  9331. constructor(commonObjs, objs, forceDataSchema = false) {
  9332. this.svgFactory = new _display_utils.DOMSVGFactory();
  9333. this.current = new SVGExtraState();
  9334. this.transformMatrix = _util.IDENTITY_MATRIX;
  9335. this.transformStack = [];
  9336. this.extraStack = [];
  9337. this.commonObjs = commonObjs;
  9338. this.objs = objs;
  9339. this.pendingClip = null;
  9340. this.pendingEOFill = false;
  9341. this.embedFonts = false;
  9342. this.embeddedFonts = Object.create(null);
  9343. this.cssStyle = null;
  9344. this.forceDataSchema = !!forceDataSchema;
  9345. this._operatorIdMapping = [];
  9346. for (const op in _util.OPS) {
  9347. this._operatorIdMapping[_util.OPS[op]] = op;
  9348. }
  9349. }
  9350. save() {
  9351. this.transformStack.push(this.transformMatrix);
  9352. const old = this.current;
  9353. this.extraStack.push(old);
  9354. this.current = old.clone();
  9355. }
  9356. restore() {
  9357. this.transformMatrix = this.transformStack.pop();
  9358. this.current = this.extraStack.pop();
  9359. this.pendingClip = null;
  9360. this.tgrp = null;
  9361. }
  9362. group(items) {
  9363. this.save();
  9364. this.executeOpTree(items);
  9365. this.restore();
  9366. }
  9367. loadDependencies(operatorList) {
  9368. const fnArray = operatorList.fnArray;
  9369. const argsArray = operatorList.argsArray;
  9370. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  9371. if (fnArray[i] !== _util.OPS.dependency) {
  9372. continue;
  9373. }
  9374. for (const obj of argsArray[i]) {
  9375. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  9376. const promise = new Promise(resolve => {
  9377. objsPool.get(obj, resolve);
  9378. });
  9379. this.current.dependencies.push(promise);
  9380. }
  9381. }
  9382. return Promise.all(this.current.dependencies);
  9383. }
  9384. transform(a, b, c, d, e, f) {
  9385. const transformMatrix = [a, b, c, d, e, f];
  9386. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  9387. this.tgrp = null;
  9388. }
  9389. getSVG(operatorList, viewport) {
  9390. this.viewport = viewport;
  9391. const svgElement = this._initialize(viewport);
  9392. return this.loadDependencies(operatorList).then(() => {
  9393. this.transformMatrix = _util.IDENTITY_MATRIX;
  9394. this.executeOpTree(this.convertOpList(operatorList));
  9395. return svgElement;
  9396. });
  9397. }
  9398. convertOpList(operatorList) {
  9399. const operatorIdMapping = this._operatorIdMapping;
  9400. const argsArray = operatorList.argsArray;
  9401. const fnArray = operatorList.fnArray;
  9402. const opList = [];
  9403. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  9404. const fnId = fnArray[i];
  9405. opList.push({
  9406. fnId,
  9407. fn: operatorIdMapping[fnId],
  9408. args: argsArray[i]
  9409. });
  9410. }
  9411. return opListToTree(opList);
  9412. }
  9413. executeOpTree(opTree) {
  9414. for (const opTreeElement of opTree) {
  9415. const fn = opTreeElement.fn;
  9416. const fnId = opTreeElement.fnId;
  9417. const args = opTreeElement.args;
  9418. switch (fnId | 0) {
  9419. case _util.OPS.beginText:
  9420. this.beginText();
  9421. break;
  9422. case _util.OPS.dependency:
  9423. break;
  9424. case _util.OPS.setLeading:
  9425. this.setLeading(args);
  9426. break;
  9427. case _util.OPS.setLeadingMoveText:
  9428. this.setLeadingMoveText(args[0], args[1]);
  9429. break;
  9430. case _util.OPS.setFont:
  9431. this.setFont(args);
  9432. break;
  9433. case _util.OPS.showText:
  9434. this.showText(args[0]);
  9435. break;
  9436. case _util.OPS.showSpacedText:
  9437. this.showText(args[0]);
  9438. break;
  9439. case _util.OPS.endText:
  9440. this.endText();
  9441. break;
  9442. case _util.OPS.moveText:
  9443. this.moveText(args[0], args[1]);
  9444. break;
  9445. case _util.OPS.setCharSpacing:
  9446. this.setCharSpacing(args[0]);
  9447. break;
  9448. case _util.OPS.setWordSpacing:
  9449. this.setWordSpacing(args[0]);
  9450. break;
  9451. case _util.OPS.setHScale:
  9452. this.setHScale(args[0]);
  9453. break;
  9454. case _util.OPS.setTextMatrix:
  9455. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  9456. break;
  9457. case _util.OPS.setTextRise:
  9458. this.setTextRise(args[0]);
  9459. break;
  9460. case _util.OPS.setTextRenderingMode:
  9461. this.setTextRenderingMode(args[0]);
  9462. break;
  9463. case _util.OPS.setLineWidth:
  9464. this.setLineWidth(args[0]);
  9465. break;
  9466. case _util.OPS.setLineJoin:
  9467. this.setLineJoin(args[0]);
  9468. break;
  9469. case _util.OPS.setLineCap:
  9470. this.setLineCap(args[0]);
  9471. break;
  9472. case _util.OPS.setMiterLimit:
  9473. this.setMiterLimit(args[0]);
  9474. break;
  9475. case _util.OPS.setFillRGBColor:
  9476. this.setFillRGBColor(args[0], args[1], args[2]);
  9477. break;
  9478. case _util.OPS.setStrokeRGBColor:
  9479. this.setStrokeRGBColor(args[0], args[1], args[2]);
  9480. break;
  9481. case _util.OPS.setStrokeColorN:
  9482. this.setStrokeColorN(args);
  9483. break;
  9484. case _util.OPS.setFillColorN:
  9485. this.setFillColorN(args);
  9486. break;
  9487. case _util.OPS.shadingFill:
  9488. this.shadingFill(args[0]);
  9489. break;
  9490. case _util.OPS.setDash:
  9491. this.setDash(args[0], args[1]);
  9492. break;
  9493. case _util.OPS.setRenderingIntent:
  9494. this.setRenderingIntent(args[0]);
  9495. break;
  9496. case _util.OPS.setFlatness:
  9497. this.setFlatness(args[0]);
  9498. break;
  9499. case _util.OPS.setGState:
  9500. this.setGState(args[0]);
  9501. break;
  9502. case _util.OPS.fill:
  9503. this.fill();
  9504. break;
  9505. case _util.OPS.eoFill:
  9506. this.eoFill();
  9507. break;
  9508. case _util.OPS.stroke:
  9509. this.stroke();
  9510. break;
  9511. case _util.OPS.fillStroke:
  9512. this.fillStroke();
  9513. break;
  9514. case _util.OPS.eoFillStroke:
  9515. this.eoFillStroke();
  9516. break;
  9517. case _util.OPS.clip:
  9518. this.clip("nonzero");
  9519. break;
  9520. case _util.OPS.eoClip:
  9521. this.clip("evenodd");
  9522. break;
  9523. case _util.OPS.paintSolidColorImageMask:
  9524. this.paintSolidColorImageMask();
  9525. break;
  9526. case _util.OPS.paintImageXObject:
  9527. this.paintImageXObject(args[0]);
  9528. break;
  9529. case _util.OPS.paintInlineImageXObject:
  9530. this.paintInlineImageXObject(args[0]);
  9531. break;
  9532. case _util.OPS.paintImageMaskXObject:
  9533. this.paintImageMaskXObject(args[0]);
  9534. break;
  9535. case _util.OPS.paintFormXObjectBegin:
  9536. this.paintFormXObjectBegin(args[0], args[1]);
  9537. break;
  9538. case _util.OPS.paintFormXObjectEnd:
  9539. this.paintFormXObjectEnd();
  9540. break;
  9541. case _util.OPS.closePath:
  9542. this.closePath();
  9543. break;
  9544. case _util.OPS.closeStroke:
  9545. this.closeStroke();
  9546. break;
  9547. case _util.OPS.closeFillStroke:
  9548. this.closeFillStroke();
  9549. break;
  9550. case _util.OPS.closeEOFillStroke:
  9551. this.closeEOFillStroke();
  9552. break;
  9553. case _util.OPS.nextLine:
  9554. this.nextLine();
  9555. break;
  9556. case _util.OPS.transform:
  9557. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  9558. break;
  9559. case _util.OPS.constructPath:
  9560. this.constructPath(args[0], args[1]);
  9561. break;
  9562. case _util.OPS.endPath:
  9563. this.endPath();
  9564. break;
  9565. case 92:
  9566. this.group(opTreeElement.items);
  9567. break;
  9568. default:
  9569. (0, _util.warn)(`Unimplemented operator ${fn}`);
  9570. break;
  9571. }
  9572. }
  9573. }
  9574. setWordSpacing(wordSpacing) {
  9575. this.current.wordSpacing = wordSpacing;
  9576. }
  9577. setCharSpacing(charSpacing) {
  9578. this.current.charSpacing = charSpacing;
  9579. }
  9580. nextLine() {
  9581. this.moveText(0, this.current.leading);
  9582. }
  9583. setTextMatrix(a, b, c, d, e, f) {
  9584. const current = this.current;
  9585. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  9586. current.textMatrixScale = Math.sqrt(a * a + b * b);
  9587. current.x = current.lineX = 0;
  9588. current.y = current.lineY = 0;
  9589. current.xcoords = [];
  9590. current.ycoords = [];
  9591. current.tspan = this.svgFactory.createElement("svg:tspan");
  9592. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9593. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9594. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9595. current.txtElement = this.svgFactory.createElement("svg:text");
  9596. current.txtElement.appendChild(current.tspan);
  9597. }
  9598. beginText() {
  9599. const current = this.current;
  9600. current.x = current.lineX = 0;
  9601. current.y = current.lineY = 0;
  9602. current.textMatrix = _util.IDENTITY_MATRIX;
  9603. current.lineMatrix = _util.IDENTITY_MATRIX;
  9604. current.textMatrixScale = 1;
  9605. current.tspan = this.svgFactory.createElement("svg:tspan");
  9606. current.txtElement = this.svgFactory.createElement("svg:text");
  9607. current.txtgrp = this.svgFactory.createElement("svg:g");
  9608. current.xcoords = [];
  9609. current.ycoords = [];
  9610. }
  9611. moveText(x, y) {
  9612. const current = this.current;
  9613. current.x = current.lineX += x;
  9614. current.y = current.lineY += y;
  9615. current.xcoords = [];
  9616. current.ycoords = [];
  9617. current.tspan = this.svgFactory.createElement("svg:tspan");
  9618. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9619. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9620. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9621. }
  9622. showText(glyphs) {
  9623. const current = this.current;
  9624. const font = current.font;
  9625. const fontSize = current.fontSize;
  9626. if (fontSize === 0) {
  9627. return;
  9628. }
  9629. const fontSizeScale = current.fontSizeScale;
  9630. const charSpacing = current.charSpacing;
  9631. const wordSpacing = current.wordSpacing;
  9632. const fontDirection = current.fontDirection;
  9633. const textHScale = current.textHScale * fontDirection;
  9634. const vertical = font.vertical;
  9635. const spacingDir = vertical ? 1 : -1;
  9636. const defaultVMetrics = font.defaultVMetrics;
  9637. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  9638. let x = 0;
  9639. for (const glyph of glyphs) {
  9640. if (glyph === null) {
  9641. x += fontDirection * wordSpacing;
  9642. continue;
  9643. } else if ((0, _util.isNum)(glyph)) {
  9644. x += spacingDir * glyph * fontSize / 1000;
  9645. continue;
  9646. }
  9647. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  9648. const character = glyph.fontChar;
  9649. let scaledX, scaledY;
  9650. let width = glyph.width;
  9651. if (vertical) {
  9652. let vx;
  9653. const vmetric = glyph.vmetric || defaultVMetrics;
  9654. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  9655. vx = -vx * widthAdvanceScale;
  9656. const vy = vmetric[2] * widthAdvanceScale;
  9657. width = vmetric ? -vmetric[0] : width;
  9658. scaledX = vx / fontSizeScale;
  9659. scaledY = (x + vy) / fontSizeScale;
  9660. } else {
  9661. scaledX = x / fontSizeScale;
  9662. scaledY = 0;
  9663. }
  9664. if (glyph.isInFont || font.missingFile) {
  9665. current.xcoords.push(current.x + scaledX);
  9666. if (vertical) {
  9667. current.ycoords.push(-current.y + scaledY);
  9668. }
  9669. current.tspan.textContent += character;
  9670. } else {}
  9671. let charWidth;
  9672. if (vertical) {
  9673. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  9674. } else {
  9675. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  9676. }
  9677. x += charWidth;
  9678. }
  9679. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  9680. if (vertical) {
  9681. current.tspan.setAttributeNS(null, "y", current.ycoords.map(pf).join(" "));
  9682. } else {
  9683. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9684. }
  9685. if (vertical) {
  9686. current.y -= x;
  9687. } else {
  9688. current.x += x * textHScale;
  9689. }
  9690. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9691. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9692. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  9693. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  9694. }
  9695. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  9696. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  9697. }
  9698. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  9699. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  9700. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  9701. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  9702. }
  9703. if (current.fillAlpha < 1) {
  9704. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  9705. }
  9706. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  9707. current.tspan.setAttributeNS(null, "fill", "transparent");
  9708. } else {
  9709. current.tspan.setAttributeNS(null, "fill", "none");
  9710. }
  9711. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  9712. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  9713. this._setStrokeAttributes(current.tspan, lineWidthScale);
  9714. }
  9715. let textMatrix = current.textMatrix;
  9716. if (current.textRise !== 0) {
  9717. textMatrix = textMatrix.slice();
  9718. textMatrix[5] += current.textRise;
  9719. }
  9720. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  9721. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  9722. current.txtElement.appendChild(current.tspan);
  9723. current.txtgrp.appendChild(current.txtElement);
  9724. this._ensureTransformGroup().appendChild(current.txtElement);
  9725. }
  9726. setLeadingMoveText(x, y) {
  9727. this.setLeading(-y);
  9728. this.moveText(x, y);
  9729. }
  9730. addFontStyle(fontObj) {
  9731. if (!fontObj.data) {
  9732. throw new Error("addFontStyle: No font data available, " + 'ensure that the "fontExtraProperties" API parameter is set.');
  9733. }
  9734. if (!this.cssStyle) {
  9735. this.cssStyle = this.svgFactory.createElement("svg:style");
  9736. this.cssStyle.setAttributeNS(null, "type", "text/css");
  9737. this.defs.appendChild(this.cssStyle);
  9738. }
  9739. const url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  9740. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  9741. }
  9742. setFont(details) {
  9743. const current = this.current;
  9744. const fontObj = this.commonObjs.get(details[0]);
  9745. let size = details[1];
  9746. current.font = fontObj;
  9747. if (this.embedFonts && !fontObj.missingFile && !this.embeddedFonts[fontObj.loadedName]) {
  9748. this.addFontStyle(fontObj);
  9749. this.embeddedFonts[fontObj.loadedName] = fontObj;
  9750. }
  9751. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  9752. let bold = "normal";
  9753. if (fontObj.black) {
  9754. bold = "900";
  9755. } else if (fontObj.bold) {
  9756. bold = "bold";
  9757. }
  9758. const italic = fontObj.italic ? "italic" : "normal";
  9759. if (size < 0) {
  9760. size = -size;
  9761. current.fontDirection = -1;
  9762. } else {
  9763. current.fontDirection = 1;
  9764. }
  9765. current.fontSize = size;
  9766. current.fontFamily = fontObj.loadedName;
  9767. current.fontWeight = bold;
  9768. current.fontStyle = italic;
  9769. current.tspan = this.svgFactory.createElement("svg:tspan");
  9770. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9771. current.xcoords = [];
  9772. current.ycoords = [];
  9773. }
  9774. endText() {
  9775. const current = this.current;
  9776. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
  9777. current.element = current.txtElement;
  9778. this.clip("nonzero");
  9779. this.endPath();
  9780. }
  9781. }
  9782. setLineWidth(width) {
  9783. if (width > 0) {
  9784. this.current.lineWidth = width;
  9785. }
  9786. }
  9787. setLineCap(style) {
  9788. this.current.lineCap = LINE_CAP_STYLES[style];
  9789. }
  9790. setLineJoin(style) {
  9791. this.current.lineJoin = LINE_JOIN_STYLES[style];
  9792. }
  9793. setMiterLimit(limit) {
  9794. this.current.miterLimit = limit;
  9795. }
  9796. setStrokeAlpha(strokeAlpha) {
  9797. this.current.strokeAlpha = strokeAlpha;
  9798. }
  9799. setStrokeRGBColor(r, g, b) {
  9800. this.current.strokeColor = _util.Util.makeCssRgb(r, g, b);
  9801. }
  9802. setFillAlpha(fillAlpha) {
  9803. this.current.fillAlpha = fillAlpha;
  9804. }
  9805. setFillRGBColor(r, g, b) {
  9806. this.current.fillColor = _util.Util.makeCssRgb(r, g, b);
  9807. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  9808. this.current.xcoords = [];
  9809. this.current.ycoords = [];
  9810. }
  9811. setStrokeColorN(args) {
  9812. this.current.strokeColor = this._makeColorN_Pattern(args);
  9813. }
  9814. setFillColorN(args) {
  9815. this.current.fillColor = this._makeColorN_Pattern(args);
  9816. }
  9817. shadingFill(args) {
  9818. const width = this.viewport.width;
  9819. const height = this.viewport.height;
  9820. const inv = _util.Util.inverseTransform(this.transformMatrix);
  9821. const bl = _util.Util.applyTransform([0, 0], inv);
  9822. const br = _util.Util.applyTransform([0, height], inv);
  9823. const ul = _util.Util.applyTransform([width, 0], inv);
  9824. const ur = _util.Util.applyTransform([width, height], inv);
  9825. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  9826. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  9827. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  9828. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  9829. const rect = this.svgFactory.createElement("svg:rect");
  9830. rect.setAttributeNS(null, "x", x0);
  9831. rect.setAttributeNS(null, "y", y0);
  9832. rect.setAttributeNS(null, "width", x1 - x0);
  9833. rect.setAttributeNS(null, "height", y1 - y0);
  9834. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  9835. if (this.current.fillAlpha < 1) {
  9836. rect.setAttributeNS(null, "fill-opacity", this.current.fillAlpha);
  9837. }
  9838. this._ensureTransformGroup().appendChild(rect);
  9839. }
  9840. _makeColorN_Pattern(args) {
  9841. if (args[0] === "TilingPattern") {
  9842. return this._makeTilingPattern(args);
  9843. }
  9844. return this._makeShadingPattern(args);
  9845. }
  9846. _makeTilingPattern(args) {
  9847. const color = args[1];
  9848. const operatorList = args[2];
  9849. const matrix = args[3] || _util.IDENTITY_MATRIX;
  9850. const [x0, y0, x1, y1] = args[4];
  9851. const xstep = args[5];
  9852. const ystep = args[6];
  9853. const paintType = args[7];
  9854. const tilingId = `shading${shadingCount++}`;
  9855. const [tx0, ty0] = _util.Util.applyTransform([x0, y0], matrix);
  9856. const [tx1, ty1] = _util.Util.applyTransform([x1, y1], matrix);
  9857. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  9858. const txstep = xstep * xscale;
  9859. const tystep = ystep * yscale;
  9860. const tiling = this.svgFactory.createElement("svg:pattern");
  9861. tiling.setAttributeNS(null, "id", tilingId);
  9862. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  9863. tiling.setAttributeNS(null, "width", txstep);
  9864. tiling.setAttributeNS(null, "height", tystep);
  9865. tiling.setAttributeNS(null, "x", `${tx0}`);
  9866. tiling.setAttributeNS(null, "y", `${ty0}`);
  9867. const svg = this.svg;
  9868. const transformMatrix = this.transformMatrix;
  9869. const fillColor = this.current.fillColor;
  9870. const strokeColor = this.current.strokeColor;
  9871. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  9872. this.svg = bbox;
  9873. this.transformMatrix = matrix;
  9874. if (paintType === 2) {
  9875. const cssColor = _util.Util.makeCssRgb(...color);
  9876. this.current.fillColor = cssColor;
  9877. this.current.strokeColor = cssColor;
  9878. }
  9879. this.executeOpTree(this.convertOpList(operatorList));
  9880. this.svg = svg;
  9881. this.transformMatrix = transformMatrix;
  9882. this.current.fillColor = fillColor;
  9883. this.current.strokeColor = strokeColor;
  9884. tiling.appendChild(bbox.childNodes[0]);
  9885. this.defs.appendChild(tiling);
  9886. return `url(#${tilingId})`;
  9887. }
  9888. _makeShadingPattern(args) {
  9889. switch (args[0]) {
  9890. case "RadialAxial":
  9891. const shadingId = `shading${shadingCount++}`;
  9892. const colorStops = args[3];
  9893. let gradient;
  9894. switch (args[1]) {
  9895. case "axial":
  9896. const point0 = args[4];
  9897. const point1 = args[5];
  9898. gradient = this.svgFactory.createElement("svg:linearGradient");
  9899. gradient.setAttributeNS(null, "id", shadingId);
  9900. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  9901. gradient.setAttributeNS(null, "x1", point0[0]);
  9902. gradient.setAttributeNS(null, "y1", point0[1]);
  9903. gradient.setAttributeNS(null, "x2", point1[0]);
  9904. gradient.setAttributeNS(null, "y2", point1[1]);
  9905. break;
  9906. case "radial":
  9907. const focalPoint = args[4];
  9908. const circlePoint = args[5];
  9909. const focalRadius = args[6];
  9910. const circleRadius = args[7];
  9911. gradient = this.svgFactory.createElement("svg:radialGradient");
  9912. gradient.setAttributeNS(null, "id", shadingId);
  9913. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  9914. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  9915. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  9916. gradient.setAttributeNS(null, "r", circleRadius);
  9917. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  9918. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  9919. gradient.setAttributeNS(null, "fr", focalRadius);
  9920. break;
  9921. default:
  9922. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  9923. }
  9924. for (const colorStop of colorStops) {
  9925. const stop = this.svgFactory.createElement("svg:stop");
  9926. stop.setAttributeNS(null, "offset", colorStop[0]);
  9927. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  9928. gradient.appendChild(stop);
  9929. }
  9930. this.defs.appendChild(gradient);
  9931. return `url(#${shadingId})`;
  9932. case "Mesh":
  9933. (0, _util.warn)("Unimplemented pattern Mesh");
  9934. return null;
  9935. case "Dummy":
  9936. return "hotpink";
  9937. default:
  9938. throw new Error(`Unknown IR type: ${args[0]}`);
  9939. }
  9940. }
  9941. setDash(dashArray, dashPhase) {
  9942. this.current.dashArray = dashArray;
  9943. this.current.dashPhase = dashPhase;
  9944. }
  9945. constructPath(ops, args) {
  9946. const current = this.current;
  9947. let x = current.x,
  9948. y = current.y;
  9949. let d = [];
  9950. let j = 0;
  9951. for (const op of ops) {
  9952. switch (op | 0) {
  9953. case _util.OPS.rectangle:
  9954. x = args[j++];
  9955. y = args[j++];
  9956. const width = args[j++];
  9957. const height = args[j++];
  9958. const xw = x + width;
  9959. const yh = y + height;
  9960. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  9961. break;
  9962. case _util.OPS.moveTo:
  9963. x = args[j++];
  9964. y = args[j++];
  9965. d.push("M", pf(x), pf(y));
  9966. break;
  9967. case _util.OPS.lineTo:
  9968. x = args[j++];
  9969. y = args[j++];
  9970. d.push("L", pf(x), pf(y));
  9971. break;
  9972. case _util.OPS.curveTo:
  9973. x = args[j + 4];
  9974. y = args[j + 5];
  9975. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  9976. j += 6;
  9977. break;
  9978. case _util.OPS.curveTo2:
  9979. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  9980. x = args[j + 2];
  9981. y = args[j + 3];
  9982. j += 4;
  9983. break;
  9984. case _util.OPS.curveTo3:
  9985. x = args[j + 2];
  9986. y = args[j + 3];
  9987. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  9988. j += 4;
  9989. break;
  9990. case _util.OPS.closePath:
  9991. d.push("Z");
  9992. break;
  9993. }
  9994. }
  9995. d = d.join(" ");
  9996. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  9997. d = current.path.getAttributeNS(null, "d") + d;
  9998. } else {
  9999. current.path = this.svgFactory.createElement("svg:path");
  10000. this._ensureTransformGroup().appendChild(current.path);
  10001. }
  10002. current.path.setAttributeNS(null, "d", d);
  10003. current.path.setAttributeNS(null, "fill", "none");
  10004. current.element = current.path;
  10005. current.setCurrentPoint(x, y);
  10006. }
  10007. endPath() {
  10008. const current = this.current;
  10009. current.path = null;
  10010. if (!this.pendingClip) {
  10011. return;
  10012. }
  10013. if (!current.element) {
  10014. this.pendingClip = null;
  10015. return;
  10016. }
  10017. const clipId = `clippath${clipCount++}`;
  10018. const clipPath = this.svgFactory.createElement("svg:clipPath");
  10019. clipPath.setAttributeNS(null, "id", clipId);
  10020. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  10021. const clipElement = current.element.cloneNode(true);
  10022. if (this.pendingClip === "evenodd") {
  10023. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  10024. } else {
  10025. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  10026. }
  10027. this.pendingClip = null;
  10028. clipPath.appendChild(clipElement);
  10029. this.defs.appendChild(clipPath);
  10030. if (current.activeClipUrl) {
  10031. current.clipGroup = null;
  10032. this.extraStack.forEach(function (prev) {
  10033. prev.clipGroup = null;
  10034. });
  10035. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  10036. }
  10037. current.activeClipUrl = `url(#${clipId})`;
  10038. this.tgrp = null;
  10039. }
  10040. clip(type) {
  10041. this.pendingClip = type;
  10042. }
  10043. closePath() {
  10044. const current = this.current;
  10045. if (current.path) {
  10046. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  10047. current.path.setAttributeNS(null, "d", d);
  10048. }
  10049. }
  10050. setLeading(leading) {
  10051. this.current.leading = -leading;
  10052. }
  10053. setTextRise(textRise) {
  10054. this.current.textRise = textRise;
  10055. }
  10056. setTextRenderingMode(textRenderingMode) {
  10057. this.current.textRenderingMode = textRenderingMode;
  10058. }
  10059. setHScale(scale) {
  10060. this.current.textHScale = scale / 100;
  10061. }
  10062. setRenderingIntent(intent) {}
  10063. setFlatness(flatness) {}
  10064. setGState(states) {
  10065. for (const [key, value] of states) {
  10066. switch (key) {
  10067. case "LW":
  10068. this.setLineWidth(value);
  10069. break;
  10070. case "LC":
  10071. this.setLineCap(value);
  10072. break;
  10073. case "LJ":
  10074. this.setLineJoin(value);
  10075. break;
  10076. case "ML":
  10077. this.setMiterLimit(value);
  10078. break;
  10079. case "D":
  10080. this.setDash(value[0], value[1]);
  10081. break;
  10082. case "RI":
  10083. this.setRenderingIntent(value);
  10084. break;
  10085. case "FL":
  10086. this.setFlatness(value);
  10087. break;
  10088. case "Font":
  10089. this.setFont(value);
  10090. break;
  10091. case "CA":
  10092. this.setStrokeAlpha(value);
  10093. break;
  10094. case "ca":
  10095. this.setFillAlpha(value);
  10096. break;
  10097. default:
  10098. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  10099. break;
  10100. }
  10101. }
  10102. }
  10103. fill() {
  10104. const current = this.current;
  10105. if (current.element) {
  10106. current.element.setAttributeNS(null, "fill", current.fillColor);
  10107. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  10108. this.endPath();
  10109. }
  10110. }
  10111. stroke() {
  10112. const current = this.current;
  10113. if (current.element) {
  10114. this._setStrokeAttributes(current.element);
  10115. current.element.setAttributeNS(null, "fill", "none");
  10116. this.endPath();
  10117. }
  10118. }
  10119. _setStrokeAttributes(element, lineWidthScale = 1) {
  10120. const current = this.current;
  10121. let dashArray = current.dashArray;
  10122. if (lineWidthScale !== 1 && dashArray.length > 0) {
  10123. dashArray = dashArray.map(function (value) {
  10124. return lineWidthScale * value;
  10125. });
  10126. }
  10127. element.setAttributeNS(null, "stroke", current.strokeColor);
  10128. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  10129. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  10130. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  10131. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  10132. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  10133. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  10134. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  10135. }
  10136. eoFill() {
  10137. if (this.current.element) {
  10138. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  10139. }
  10140. this.fill();
  10141. }
  10142. fillStroke() {
  10143. this.stroke();
  10144. this.fill();
  10145. }
  10146. eoFillStroke() {
  10147. if (this.current.element) {
  10148. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  10149. }
  10150. this.fillStroke();
  10151. }
  10152. closeStroke() {
  10153. this.closePath();
  10154. this.stroke();
  10155. }
  10156. closeFillStroke() {
  10157. this.closePath();
  10158. this.fillStroke();
  10159. }
  10160. closeEOFillStroke() {
  10161. this.closePath();
  10162. this.eoFillStroke();
  10163. }
  10164. paintSolidColorImageMask() {
  10165. const rect = this.svgFactory.createElement("svg:rect");
  10166. rect.setAttributeNS(null, "x", "0");
  10167. rect.setAttributeNS(null, "y", "0");
  10168. rect.setAttributeNS(null, "width", "1px");
  10169. rect.setAttributeNS(null, "height", "1px");
  10170. rect.setAttributeNS(null, "fill", this.current.fillColor);
  10171. this._ensureTransformGroup().appendChild(rect);
  10172. }
  10173. paintImageXObject(objId) {
  10174. const imgData = objId.startsWith("g_") ? this.commonObjs.get(objId) : this.objs.get(objId);
  10175. if (!imgData) {
  10176. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  10177. return;
  10178. }
  10179. this.paintInlineImageXObject(imgData);
  10180. }
  10181. paintInlineImageXObject(imgData, mask) {
  10182. const width = imgData.width;
  10183. const height = imgData.height;
  10184. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  10185. const cliprect = this.svgFactory.createElement("svg:rect");
  10186. cliprect.setAttributeNS(null, "x", "0");
  10187. cliprect.setAttributeNS(null, "y", "0");
  10188. cliprect.setAttributeNS(null, "width", pf(width));
  10189. cliprect.setAttributeNS(null, "height", pf(height));
  10190. this.current.element = cliprect;
  10191. this.clip("nonzero");
  10192. const imgEl = this.svgFactory.createElement("svg:image");
  10193. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  10194. imgEl.setAttributeNS(null, "x", "0");
  10195. imgEl.setAttributeNS(null, "y", pf(-height));
  10196. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  10197. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  10198. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  10199. if (mask) {
  10200. mask.appendChild(imgEl);
  10201. } else {
  10202. this._ensureTransformGroup().appendChild(imgEl);
  10203. }
  10204. }
  10205. paintImageMaskXObject(imgData) {
  10206. const current = this.current;
  10207. const width = imgData.width;
  10208. const height = imgData.height;
  10209. const fillColor = current.fillColor;
  10210. current.maskId = `mask${maskCount++}`;
  10211. const mask = this.svgFactory.createElement("svg:mask");
  10212. mask.setAttributeNS(null, "id", current.maskId);
  10213. const rect = this.svgFactory.createElement("svg:rect");
  10214. rect.setAttributeNS(null, "x", "0");
  10215. rect.setAttributeNS(null, "y", "0");
  10216. rect.setAttributeNS(null, "width", pf(width));
  10217. rect.setAttributeNS(null, "height", pf(height));
  10218. rect.setAttributeNS(null, "fill", fillColor);
  10219. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  10220. this.defs.appendChild(mask);
  10221. this._ensureTransformGroup().appendChild(rect);
  10222. this.paintInlineImageXObject(imgData, mask);
  10223. }
  10224. paintFormXObjectBegin(matrix, bbox) {
  10225. if (Array.isArray(matrix) && matrix.length === 6) {
  10226. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  10227. }
  10228. if (bbox) {
  10229. const width = bbox[2] - bbox[0];
  10230. const height = bbox[3] - bbox[1];
  10231. const cliprect = this.svgFactory.createElement("svg:rect");
  10232. cliprect.setAttributeNS(null, "x", bbox[0]);
  10233. cliprect.setAttributeNS(null, "y", bbox[1]);
  10234. cliprect.setAttributeNS(null, "width", pf(width));
  10235. cliprect.setAttributeNS(null, "height", pf(height));
  10236. this.current.element = cliprect;
  10237. this.clip("nonzero");
  10238. this.endPath();
  10239. }
  10240. }
  10241. paintFormXObjectEnd() {}
  10242. _initialize(viewport) {
  10243. const svg = this.svgFactory.create(viewport.width, viewport.height);
  10244. const definitions = this.svgFactory.createElement("svg:defs");
  10245. svg.appendChild(definitions);
  10246. this.defs = definitions;
  10247. const rootGroup = this.svgFactory.createElement("svg:g");
  10248. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  10249. svg.appendChild(rootGroup);
  10250. this.svg = rootGroup;
  10251. return svg;
  10252. }
  10253. _ensureClipGroup() {
  10254. if (!this.current.clipGroup) {
  10255. const clipGroup = this.svgFactory.createElement("svg:g");
  10256. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  10257. this.svg.appendChild(clipGroup);
  10258. this.current.clipGroup = clipGroup;
  10259. }
  10260. return this.current.clipGroup;
  10261. }
  10262. _ensureTransformGroup() {
  10263. if (!this.tgrp) {
  10264. this.tgrp = this.svgFactory.createElement("svg:g");
  10265. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  10266. if (this.current.activeClipUrl) {
  10267. this._ensureClipGroup().appendChild(this.tgrp);
  10268. } else {
  10269. this.svg.appendChild(this.tgrp);
  10270. }
  10271. }
  10272. return this.tgrp;
  10273. }
  10274. };
  10275. }
  10276. /***/ }),
  10277. /* 22 */
  10278. /***/ (function(module, exports, __w_pdfjs_require__) {
  10279. "use strict";
  10280. Object.defineProperty(exports, "__esModule", {
  10281. value: true
  10282. });
  10283. exports.PDFNodeStream = void 0;
  10284. var _util = __w_pdfjs_require__(2);
  10285. var _network_utils = __w_pdfjs_require__(23);
  10286. ;
  10287. const fs = require("fs");
  10288. const http = require("http");
  10289. const https = require("https");
  10290. const url = require("url");
  10291. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  10292. function parseUrl(sourceUrl) {
  10293. const parsedUrl = url.parse(sourceUrl);
  10294. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  10295. return parsedUrl;
  10296. }
  10297. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  10298. return url.parse(`file:///${sourceUrl}`);
  10299. }
  10300. if (!parsedUrl.host) {
  10301. parsedUrl.protocol = "file:";
  10302. }
  10303. return parsedUrl;
  10304. }
  10305. class PDFNodeStream {
  10306. constructor(source) {
  10307. this.source = source;
  10308. this.url = parseUrl(source.url);
  10309. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  10310. this.isFsUrl = this.url.protocol === "file:";
  10311. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  10312. this._fullRequestReader = null;
  10313. this._rangeRequestReaders = [];
  10314. }
  10315. get _progressiveDataLength() {
  10316. return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
  10317. }
  10318. getFullReader() {
  10319. (0, _util.assert)(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
  10320. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  10321. return this._fullRequestReader;
  10322. }
  10323. getRangeReader(start, end) {
  10324. if (end <= this._progressiveDataLength) {
  10325. return null;
  10326. }
  10327. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  10328. this._rangeRequestReaders.push(rangeReader);
  10329. return rangeReader;
  10330. }
  10331. cancelAllRequests(reason) {
  10332. if (this._fullRequestReader) {
  10333. this._fullRequestReader.cancel(reason);
  10334. }
  10335. const readers = this._rangeRequestReaders.slice(0);
  10336. readers.forEach(function (reader) {
  10337. reader.cancel(reason);
  10338. });
  10339. }
  10340. }
  10341. exports.PDFNodeStream = PDFNodeStream;
  10342. class BaseFullReader {
  10343. constructor(stream) {
  10344. this._url = stream.url;
  10345. this._done = false;
  10346. this._storedError = null;
  10347. this.onProgress = null;
  10348. const source = stream.source;
  10349. this._contentLength = source.length;
  10350. this._loaded = 0;
  10351. this._filename = null;
  10352. this._disableRange = source.disableRange || false;
  10353. this._rangeChunkSize = source.rangeChunkSize;
  10354. if (!this._rangeChunkSize && !this._disableRange) {
  10355. this._disableRange = true;
  10356. }
  10357. this._isStreamingSupported = !source.disableStream;
  10358. this._isRangeSupported = !source.disableRange;
  10359. this._readableStream = null;
  10360. this._readCapability = (0, _util.createPromiseCapability)();
  10361. this._headersCapability = (0, _util.createPromiseCapability)();
  10362. }
  10363. get headersReady() {
  10364. return this._headersCapability.promise;
  10365. }
  10366. get filename() {
  10367. return this._filename;
  10368. }
  10369. get contentLength() {
  10370. return this._contentLength;
  10371. }
  10372. get isRangeSupported() {
  10373. return this._isRangeSupported;
  10374. }
  10375. get isStreamingSupported() {
  10376. return this._isStreamingSupported;
  10377. }
  10378. async read() {
  10379. await this._readCapability.promise;
  10380. if (this._done) {
  10381. return {
  10382. value: undefined,
  10383. done: true
  10384. };
  10385. }
  10386. if (this._storedError) {
  10387. throw this._storedError;
  10388. }
  10389. const chunk = this._readableStream.read();
  10390. if (chunk === null) {
  10391. this._readCapability = (0, _util.createPromiseCapability)();
  10392. return this.read();
  10393. }
  10394. this._loaded += chunk.length;
  10395. if (this.onProgress) {
  10396. this.onProgress({
  10397. loaded: this._loaded,
  10398. total: this._contentLength
  10399. });
  10400. }
  10401. const buffer = new Uint8Array(chunk).buffer;
  10402. return {
  10403. value: buffer,
  10404. done: false
  10405. };
  10406. }
  10407. cancel(reason) {
  10408. if (!this._readableStream) {
  10409. this._error(reason);
  10410. return;
  10411. }
  10412. this._readableStream.destroy(reason);
  10413. }
  10414. _error(reason) {
  10415. this._storedError = reason;
  10416. this._readCapability.resolve();
  10417. }
  10418. _setReadableStream(readableStream) {
  10419. this._readableStream = readableStream;
  10420. readableStream.on("readable", () => {
  10421. this._readCapability.resolve();
  10422. });
  10423. readableStream.on("end", () => {
  10424. readableStream.destroy();
  10425. this._done = true;
  10426. this._readCapability.resolve();
  10427. });
  10428. readableStream.on("error", reason => {
  10429. this._error(reason);
  10430. });
  10431. if (!this._isStreamingSupported && this._isRangeSupported) {
  10432. this._error(new _util.AbortException("streaming is disabled"));
  10433. }
  10434. if (this._storedError) {
  10435. this._readableStream.destroy(this._storedError);
  10436. }
  10437. }
  10438. }
  10439. class BaseRangeReader {
  10440. constructor(stream) {
  10441. this._url = stream.url;
  10442. this._done = false;
  10443. this._storedError = null;
  10444. this.onProgress = null;
  10445. this._loaded = 0;
  10446. this._readableStream = null;
  10447. this._readCapability = (0, _util.createPromiseCapability)();
  10448. const source = stream.source;
  10449. this._isStreamingSupported = !source.disableStream;
  10450. }
  10451. get isStreamingSupported() {
  10452. return this._isStreamingSupported;
  10453. }
  10454. async read() {
  10455. await this._readCapability.promise;
  10456. if (this._done) {
  10457. return {
  10458. value: undefined,
  10459. done: true
  10460. };
  10461. }
  10462. if (this._storedError) {
  10463. throw this._storedError;
  10464. }
  10465. const chunk = this._readableStream.read();
  10466. if (chunk === null) {
  10467. this._readCapability = (0, _util.createPromiseCapability)();
  10468. return this.read();
  10469. }
  10470. this._loaded += chunk.length;
  10471. if (this.onProgress) {
  10472. this.onProgress({
  10473. loaded: this._loaded
  10474. });
  10475. }
  10476. const buffer = new Uint8Array(chunk).buffer;
  10477. return {
  10478. value: buffer,
  10479. done: false
  10480. };
  10481. }
  10482. cancel(reason) {
  10483. if (!this._readableStream) {
  10484. this._error(reason);
  10485. return;
  10486. }
  10487. this._readableStream.destroy(reason);
  10488. }
  10489. _error(reason) {
  10490. this._storedError = reason;
  10491. this._readCapability.resolve();
  10492. }
  10493. _setReadableStream(readableStream) {
  10494. this._readableStream = readableStream;
  10495. readableStream.on("readable", () => {
  10496. this._readCapability.resolve();
  10497. });
  10498. readableStream.on("end", () => {
  10499. readableStream.destroy();
  10500. this._done = true;
  10501. this._readCapability.resolve();
  10502. });
  10503. readableStream.on("error", reason => {
  10504. this._error(reason);
  10505. });
  10506. if (this._storedError) {
  10507. this._readableStream.destroy(this._storedError);
  10508. }
  10509. }
  10510. }
  10511. function createRequestOptions(parsedUrl, headers) {
  10512. return {
  10513. protocol: parsedUrl.protocol,
  10514. auth: parsedUrl.auth,
  10515. host: parsedUrl.hostname,
  10516. port: parsedUrl.port,
  10517. path: parsedUrl.path,
  10518. method: "GET",
  10519. headers
  10520. };
  10521. }
  10522. class PDFNodeStreamFullReader extends BaseFullReader {
  10523. constructor(stream) {
  10524. super(stream);
  10525. const handleResponse = response => {
  10526. if (response.statusCode === 404) {
  10527. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  10528. this._storedError = error;
  10529. this._headersCapability.reject(error);
  10530. return;
  10531. }
  10532. this._headersCapability.resolve();
  10533. this._setReadableStream(response);
  10534. const getResponseHeader = name => {
  10535. return this._readableStream.headers[name.toLowerCase()];
  10536. };
  10537. const {
  10538. allowRangeRequests,
  10539. suggestedLength
  10540. } = (0, _network_utils.validateRangeRequestCapabilities)({
  10541. getResponseHeader,
  10542. isHttp: stream.isHttp,
  10543. rangeChunkSize: this._rangeChunkSize,
  10544. disableRange: this._disableRange
  10545. });
  10546. this._isRangeSupported = allowRangeRequests;
  10547. this._contentLength = suggestedLength || this._contentLength;
  10548. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  10549. };
  10550. this._request = null;
  10551. if (this._url.protocol === "http:") {
  10552. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  10553. } else {
  10554. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  10555. }
  10556. this._request.on("error", reason => {
  10557. this._storedError = reason;
  10558. this._headersCapability.reject(reason);
  10559. });
  10560. this._request.end();
  10561. }
  10562. }
  10563. class PDFNodeStreamRangeReader extends BaseRangeReader {
  10564. constructor(stream, start, end) {
  10565. super(stream);
  10566. this._httpHeaders = {};
  10567. for (const property in stream.httpHeaders) {
  10568. const value = stream.httpHeaders[property];
  10569. if (typeof value === "undefined") {
  10570. continue;
  10571. }
  10572. this._httpHeaders[property] = value;
  10573. }
  10574. this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
  10575. const handleResponse = response => {
  10576. if (response.statusCode === 404) {
  10577. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  10578. this._storedError = error;
  10579. return;
  10580. }
  10581. this._setReadableStream(response);
  10582. };
  10583. this._request = null;
  10584. if (this._url.protocol === "http:") {
  10585. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  10586. } else {
  10587. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  10588. }
  10589. this._request.on("error", reason => {
  10590. this._storedError = reason;
  10591. });
  10592. this._request.end();
  10593. }
  10594. }
  10595. class PDFNodeStreamFsFullReader extends BaseFullReader {
  10596. constructor(stream) {
  10597. super(stream);
  10598. let path = decodeURIComponent(this._url.path);
  10599. if (fileUriRegex.test(this._url.href)) {
  10600. path = path.replace(/^\//, "");
  10601. }
  10602. fs.lstat(path, (error, stat) => {
  10603. if (error) {
  10604. if (error.code === "ENOENT") {
  10605. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  10606. }
  10607. this._storedError = error;
  10608. this._headersCapability.reject(error);
  10609. return;
  10610. }
  10611. this._contentLength = stat.size;
  10612. this._setReadableStream(fs.createReadStream(path));
  10613. this._headersCapability.resolve();
  10614. });
  10615. }
  10616. }
  10617. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  10618. constructor(stream, start, end) {
  10619. super(stream);
  10620. let path = decodeURIComponent(this._url.path);
  10621. if (fileUriRegex.test(this._url.href)) {
  10622. path = path.replace(/^\//, "");
  10623. }
  10624. this._setReadableStream(fs.createReadStream(path, {
  10625. start,
  10626. end: end - 1
  10627. }));
  10628. }
  10629. }
  10630. /***/ }),
  10631. /* 23 */
  10632. /***/ (function(module, exports, __w_pdfjs_require__) {
  10633. "use strict";
  10634. Object.defineProperty(exports, "__esModule", {
  10635. value: true
  10636. });
  10637. exports.createResponseStatusError = createResponseStatusError;
  10638. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  10639. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  10640. exports.validateResponseStatus = validateResponseStatus;
  10641. var _util = __w_pdfjs_require__(2);
  10642. var _content_disposition = __w_pdfjs_require__(24);
  10643. function validateRangeRequestCapabilities({
  10644. getResponseHeader,
  10645. isHttp,
  10646. rangeChunkSize,
  10647. disableRange
  10648. }) {
  10649. (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
  10650. const returnValues = {
  10651. allowRangeRequests: false,
  10652. suggestedLength: undefined
  10653. };
  10654. const length = parseInt(getResponseHeader("Content-Length"), 10);
  10655. if (!Number.isInteger(length)) {
  10656. return returnValues;
  10657. }
  10658. returnValues.suggestedLength = length;
  10659. if (length <= 2 * rangeChunkSize) {
  10660. return returnValues;
  10661. }
  10662. if (disableRange || !isHttp) {
  10663. return returnValues;
  10664. }
  10665. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  10666. return returnValues;
  10667. }
  10668. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  10669. if (contentEncoding !== "identity") {
  10670. return returnValues;
  10671. }
  10672. returnValues.allowRangeRequests = true;
  10673. return returnValues;
  10674. }
  10675. function extractFilenameFromHeader(getResponseHeader) {
  10676. const contentDisposition = getResponseHeader("Content-Disposition");
  10677. if (contentDisposition) {
  10678. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  10679. if (filename.includes("%")) {
  10680. try {
  10681. filename = decodeURIComponent(filename);
  10682. } catch (ex) {}
  10683. }
  10684. if (/\.pdf$/i.test(filename)) {
  10685. return filename;
  10686. }
  10687. }
  10688. return null;
  10689. }
  10690. function createResponseStatusError(status, url) {
  10691. if (status === 404 || status === 0 && url.startsWith("file:")) {
  10692. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  10693. }
  10694. return new _util.UnexpectedResponseException("Unexpected server response (" + status + ') while retrieving PDF "' + url + '".', status);
  10695. }
  10696. function validateResponseStatus(status) {
  10697. return status === 200 || status === 206;
  10698. }
  10699. /***/ }),
  10700. /* 24 */
  10701. /***/ (function(module, exports, __w_pdfjs_require__) {
  10702. "use strict";
  10703. Object.defineProperty(exports, "__esModule", {
  10704. value: true
  10705. });
  10706. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  10707. function getFilenameFromContentDispositionHeader(contentDisposition) {
  10708. let needsEncodingFixup = true;
  10709. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  10710. if (tmp) {
  10711. tmp = tmp[1];
  10712. let filename = rfc2616unquote(tmp);
  10713. filename = unescape(filename);
  10714. filename = rfc5987decode(filename);
  10715. filename = rfc2047decode(filename);
  10716. return fixupEncoding(filename);
  10717. }
  10718. tmp = rfc2231getparam(contentDisposition);
  10719. if (tmp) {
  10720. const filename = rfc2047decode(tmp);
  10721. return fixupEncoding(filename);
  10722. }
  10723. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  10724. if (tmp) {
  10725. tmp = tmp[1];
  10726. let filename = rfc2616unquote(tmp);
  10727. filename = rfc2047decode(filename);
  10728. return fixupEncoding(filename);
  10729. }
  10730. function toParamRegExp(attributePattern, flags) {
  10731. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  10732. }
  10733. function textdecode(encoding, value) {
  10734. if (encoding) {
  10735. if (!/^[\x00-\xFF]+$/.test(value)) {
  10736. return value;
  10737. }
  10738. try {
  10739. const decoder = new TextDecoder(encoding, {
  10740. fatal: true
  10741. });
  10742. const bytes = Array.from(value, function (ch) {
  10743. return ch.charCodeAt(0) & 0xff;
  10744. });
  10745. value = decoder.decode(new Uint8Array(bytes));
  10746. needsEncodingFixup = false;
  10747. } catch (e) {
  10748. if (/^utf-?8$/i.test(encoding)) {
  10749. try {
  10750. value = decodeURIComponent(escape(value));
  10751. needsEncodingFixup = false;
  10752. } catch (err) {}
  10753. }
  10754. }
  10755. }
  10756. return value;
  10757. }
  10758. function fixupEncoding(value) {
  10759. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  10760. value = textdecode("utf-8", value);
  10761. if (needsEncodingFixup) {
  10762. value = textdecode("iso-8859-1", value);
  10763. }
  10764. }
  10765. return value;
  10766. }
  10767. function rfc2231getparam(contentDispositionStr) {
  10768. const matches = [];
  10769. let match;
  10770. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  10771. while ((match = iter.exec(contentDispositionStr)) !== null) {
  10772. let [, n, quot, part] = match;
  10773. n = parseInt(n, 10);
  10774. if (n in matches) {
  10775. if (n === 0) {
  10776. break;
  10777. }
  10778. continue;
  10779. }
  10780. matches[n] = [quot, part];
  10781. }
  10782. const parts = [];
  10783. for (let n = 0; n < matches.length; ++n) {
  10784. if (!(n in matches)) {
  10785. break;
  10786. }
  10787. let [quot, part] = matches[n];
  10788. part = rfc2616unquote(part);
  10789. if (quot) {
  10790. part = unescape(part);
  10791. if (n === 0) {
  10792. part = rfc5987decode(part);
  10793. }
  10794. }
  10795. parts.push(part);
  10796. }
  10797. return parts.join("");
  10798. }
  10799. function rfc2616unquote(value) {
  10800. if (value.startsWith('"')) {
  10801. const parts = value.slice(1).split('\\"');
  10802. for (let i = 0; i < parts.length; ++i) {
  10803. const quotindex = parts[i].indexOf('"');
  10804. if (quotindex !== -1) {
  10805. parts[i] = parts[i].slice(0, quotindex);
  10806. parts.length = i + 1;
  10807. }
  10808. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  10809. }
  10810. value = parts.join('"');
  10811. }
  10812. return value;
  10813. }
  10814. function rfc5987decode(extvalue) {
  10815. const encodingend = extvalue.indexOf("'");
  10816. if (encodingend === -1) {
  10817. return extvalue;
  10818. }
  10819. const encoding = extvalue.slice(0, encodingend);
  10820. const langvalue = extvalue.slice(encodingend + 1);
  10821. const value = langvalue.replace(/^[^']*'/, "");
  10822. return textdecode(encoding, value);
  10823. }
  10824. function rfc2047decode(value) {
  10825. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  10826. return value;
  10827. }
  10828. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
  10829. if (encoding === "q" || encoding === "Q") {
  10830. text = text.replace(/_/g, " ");
  10831. text = text.replace(/=([0-9a-fA-F]{2})/g, function (match, hex) {
  10832. return String.fromCharCode(parseInt(hex, 16));
  10833. });
  10834. return textdecode(charset, text);
  10835. }
  10836. try {
  10837. text = atob(text);
  10838. } catch (e) {}
  10839. return textdecode(charset, text);
  10840. });
  10841. }
  10842. return "";
  10843. }
  10844. /***/ }),
  10845. /* 25 */
  10846. /***/ (function(module, exports, __w_pdfjs_require__) {
  10847. "use strict";
  10848. Object.defineProperty(exports, "__esModule", {
  10849. value: true
  10850. });
  10851. exports.PDFNetworkStream = void 0;
  10852. var _util = __w_pdfjs_require__(2);
  10853. var _network_utils = __w_pdfjs_require__(23);
  10854. ;
  10855. const OK_RESPONSE = 200;
  10856. const PARTIAL_CONTENT_RESPONSE = 206;
  10857. function getArrayBuffer(xhr) {
  10858. const data = xhr.response;
  10859. if (typeof data !== "string") {
  10860. return data;
  10861. }
  10862. const array = (0, _util.stringToBytes)(data);
  10863. return array.buffer;
  10864. }
  10865. class NetworkManager {
  10866. constructor(url, args) {
  10867. this.url = url;
  10868. args = args || {};
  10869. this.isHttp = /^https?:/i.test(url);
  10870. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  10871. this.withCredentials = args.withCredentials || false;
  10872. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  10873. return new XMLHttpRequest();
  10874. };
  10875. this.currXhrId = 0;
  10876. this.pendingRequests = Object.create(null);
  10877. }
  10878. requestRange(begin, end, listeners) {
  10879. const args = {
  10880. begin,
  10881. end
  10882. };
  10883. for (const prop in listeners) {
  10884. args[prop] = listeners[prop];
  10885. }
  10886. return this.request(args);
  10887. }
  10888. requestFull(listeners) {
  10889. return this.request(listeners);
  10890. }
  10891. request(args) {
  10892. const xhr = this.getXhr();
  10893. const xhrId = this.currXhrId++;
  10894. const pendingRequest = this.pendingRequests[xhrId] = {
  10895. xhr
  10896. };
  10897. xhr.open("GET", this.url);
  10898. xhr.withCredentials = this.withCredentials;
  10899. for (const property in this.httpHeaders) {
  10900. const value = this.httpHeaders[property];
  10901. if (typeof value === "undefined") {
  10902. continue;
  10903. }
  10904. xhr.setRequestHeader(property, value);
  10905. }
  10906. if (this.isHttp && "begin" in args && "end" in args) {
  10907. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  10908. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  10909. } else {
  10910. pendingRequest.expectedStatus = OK_RESPONSE;
  10911. }
  10912. xhr.responseType = "arraybuffer";
  10913. if (args.onError) {
  10914. xhr.onerror = function (evt) {
  10915. args.onError(xhr.status);
  10916. };
  10917. }
  10918. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  10919. xhr.onprogress = this.onProgress.bind(this, xhrId);
  10920. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  10921. pendingRequest.onDone = args.onDone;
  10922. pendingRequest.onError = args.onError;
  10923. pendingRequest.onProgress = args.onProgress;
  10924. xhr.send(null);
  10925. return xhrId;
  10926. }
  10927. onProgress(xhrId, evt) {
  10928. const pendingRequest = this.pendingRequests[xhrId];
  10929. if (!pendingRequest) {
  10930. return;
  10931. }
  10932. if (pendingRequest.onProgress) {
  10933. pendingRequest.onProgress(evt);
  10934. }
  10935. }
  10936. onStateChange(xhrId, evt) {
  10937. const pendingRequest = this.pendingRequests[xhrId];
  10938. if (!pendingRequest) {
  10939. return;
  10940. }
  10941. const xhr = pendingRequest.xhr;
  10942. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  10943. pendingRequest.onHeadersReceived();
  10944. delete pendingRequest.onHeadersReceived;
  10945. }
  10946. if (xhr.readyState !== 4) {
  10947. return;
  10948. }
  10949. if (!(xhrId in this.pendingRequests)) {
  10950. return;
  10951. }
  10952. delete this.pendingRequests[xhrId];
  10953. if (xhr.status === 0 && this.isHttp) {
  10954. if (pendingRequest.onError) {
  10955. pendingRequest.onError(xhr.status);
  10956. }
  10957. return;
  10958. }
  10959. const xhrStatus = xhr.status || OK_RESPONSE;
  10960. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  10961. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  10962. if (pendingRequest.onError) {
  10963. pendingRequest.onError(xhr.status);
  10964. }
  10965. return;
  10966. }
  10967. const chunk = getArrayBuffer(xhr);
  10968. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  10969. const rangeHeader = xhr.getResponseHeader("Content-Range");
  10970. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  10971. pendingRequest.onDone({
  10972. begin: parseInt(matches[1], 10),
  10973. chunk
  10974. });
  10975. } else if (chunk) {
  10976. pendingRequest.onDone({
  10977. begin: 0,
  10978. chunk
  10979. });
  10980. } else if (pendingRequest.onError) {
  10981. pendingRequest.onError(xhr.status);
  10982. }
  10983. }
  10984. getRequestXhr(xhrId) {
  10985. return this.pendingRequests[xhrId].xhr;
  10986. }
  10987. isPendingRequest(xhrId) {
  10988. return xhrId in this.pendingRequests;
  10989. }
  10990. abortRequest(xhrId) {
  10991. const xhr = this.pendingRequests[xhrId].xhr;
  10992. delete this.pendingRequests[xhrId];
  10993. xhr.abort();
  10994. }
  10995. }
  10996. class PDFNetworkStream {
  10997. constructor(source) {
  10998. this._source = source;
  10999. this._manager = new NetworkManager(source.url, {
  11000. httpHeaders: source.httpHeaders,
  11001. withCredentials: source.withCredentials
  11002. });
  11003. this._rangeChunkSize = source.rangeChunkSize;
  11004. this._fullRequestReader = null;
  11005. this._rangeRequestReaders = [];
  11006. }
  11007. _onRangeRequestReaderClosed(reader) {
  11008. const i = this._rangeRequestReaders.indexOf(reader);
  11009. if (i >= 0) {
  11010. this._rangeRequestReaders.splice(i, 1);
  11011. }
  11012. }
  11013. getFullReader() {
  11014. (0, _util.assert)(!this._fullRequestReader, "PDFNetworkStream.getFullReader can only be called once.");
  11015. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  11016. return this._fullRequestReader;
  11017. }
  11018. getRangeReader(begin, end) {
  11019. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  11020. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  11021. this._rangeRequestReaders.push(reader);
  11022. return reader;
  11023. }
  11024. cancelAllRequests(reason) {
  11025. if (this._fullRequestReader) {
  11026. this._fullRequestReader.cancel(reason);
  11027. }
  11028. const readers = this._rangeRequestReaders.slice(0);
  11029. readers.forEach(function (reader) {
  11030. reader.cancel(reason);
  11031. });
  11032. }
  11033. }
  11034. exports.PDFNetworkStream = PDFNetworkStream;
  11035. class PDFNetworkStreamFullRequestReader {
  11036. constructor(manager, source) {
  11037. this._manager = manager;
  11038. const args = {
  11039. onHeadersReceived: this._onHeadersReceived.bind(this),
  11040. onDone: this._onDone.bind(this),
  11041. onError: this._onError.bind(this),
  11042. onProgress: this._onProgress.bind(this)
  11043. };
  11044. this._url = source.url;
  11045. this._fullRequestId = manager.requestFull(args);
  11046. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  11047. this._disableRange = source.disableRange || false;
  11048. this._contentLength = source.length;
  11049. this._rangeChunkSize = source.rangeChunkSize;
  11050. if (!this._rangeChunkSize && !this._disableRange) {
  11051. this._disableRange = true;
  11052. }
  11053. this._isStreamingSupported = false;
  11054. this._isRangeSupported = false;
  11055. this._cachedChunks = [];
  11056. this._requests = [];
  11057. this._done = false;
  11058. this._storedError = undefined;
  11059. this._filename = null;
  11060. this.onProgress = null;
  11061. }
  11062. _onHeadersReceived() {
  11063. const fullRequestXhrId = this._fullRequestId;
  11064. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  11065. const getResponseHeader = name => {
  11066. return fullRequestXhr.getResponseHeader(name);
  11067. };
  11068. const {
  11069. allowRangeRequests,
  11070. suggestedLength
  11071. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11072. getResponseHeader,
  11073. isHttp: this._manager.isHttp,
  11074. rangeChunkSize: this._rangeChunkSize,
  11075. disableRange: this._disableRange
  11076. });
  11077. if (allowRangeRequests) {
  11078. this._isRangeSupported = true;
  11079. }
  11080. this._contentLength = suggestedLength || this._contentLength;
  11081. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11082. if (this._isRangeSupported) {
  11083. this._manager.abortRequest(fullRequestXhrId);
  11084. }
  11085. this._headersReceivedCapability.resolve();
  11086. }
  11087. _onDone(args) {
  11088. if (args) {
  11089. if (this._requests.length > 0) {
  11090. const requestCapability = this._requests.shift();
  11091. requestCapability.resolve({
  11092. value: args.chunk,
  11093. done: false
  11094. });
  11095. } else {
  11096. this._cachedChunks.push(args.chunk);
  11097. }
  11098. }
  11099. this._done = true;
  11100. if (this._cachedChunks.length > 0) {
  11101. return;
  11102. }
  11103. this._requests.forEach(function (requestCapability) {
  11104. requestCapability.resolve({
  11105. value: undefined,
  11106. done: true
  11107. });
  11108. });
  11109. this._requests = [];
  11110. }
  11111. _onError(status) {
  11112. const url = this._url;
  11113. const exception = (0, _network_utils.createResponseStatusError)(status, url);
  11114. this._storedError = exception;
  11115. this._headersReceivedCapability.reject(exception);
  11116. this._requests.forEach(function (requestCapability) {
  11117. requestCapability.reject(exception);
  11118. });
  11119. this._requests = [];
  11120. this._cachedChunks = [];
  11121. }
  11122. _onProgress(data) {
  11123. if (this.onProgress) {
  11124. this.onProgress({
  11125. loaded: data.loaded,
  11126. total: data.lengthComputable ? data.total : this._contentLength
  11127. });
  11128. }
  11129. }
  11130. get filename() {
  11131. return this._filename;
  11132. }
  11133. get isRangeSupported() {
  11134. return this._isRangeSupported;
  11135. }
  11136. get isStreamingSupported() {
  11137. return this._isStreamingSupported;
  11138. }
  11139. get contentLength() {
  11140. return this._contentLength;
  11141. }
  11142. get headersReady() {
  11143. return this._headersReceivedCapability.promise;
  11144. }
  11145. async read() {
  11146. if (this._storedError) {
  11147. throw this._storedError;
  11148. }
  11149. if (this._cachedChunks.length > 0) {
  11150. const chunk = this._cachedChunks.shift();
  11151. return {
  11152. value: chunk,
  11153. done: false
  11154. };
  11155. }
  11156. if (this._done) {
  11157. return {
  11158. value: undefined,
  11159. done: true
  11160. };
  11161. }
  11162. const requestCapability = (0, _util.createPromiseCapability)();
  11163. this._requests.push(requestCapability);
  11164. return requestCapability.promise;
  11165. }
  11166. cancel(reason) {
  11167. this._done = true;
  11168. this._headersReceivedCapability.reject(reason);
  11169. this._requests.forEach(function (requestCapability) {
  11170. requestCapability.resolve({
  11171. value: undefined,
  11172. done: true
  11173. });
  11174. });
  11175. this._requests = [];
  11176. if (this._manager.isPendingRequest(this._fullRequestId)) {
  11177. this._manager.abortRequest(this._fullRequestId);
  11178. }
  11179. this._fullRequestReader = null;
  11180. }
  11181. }
  11182. class PDFNetworkStreamRangeRequestReader {
  11183. constructor(manager, begin, end) {
  11184. this._manager = manager;
  11185. const args = {
  11186. onDone: this._onDone.bind(this),
  11187. onProgress: this._onProgress.bind(this)
  11188. };
  11189. this._requestId = manager.requestRange(begin, end, args);
  11190. this._requests = [];
  11191. this._queuedChunk = null;
  11192. this._done = false;
  11193. this.onProgress = null;
  11194. this.onClosed = null;
  11195. }
  11196. _close() {
  11197. if (this.onClosed) {
  11198. this.onClosed(this);
  11199. }
  11200. }
  11201. _onDone(data) {
  11202. const chunk = data.chunk;
  11203. if (this._requests.length > 0) {
  11204. const requestCapability = this._requests.shift();
  11205. requestCapability.resolve({
  11206. value: chunk,
  11207. done: false
  11208. });
  11209. } else {
  11210. this._queuedChunk = chunk;
  11211. }
  11212. this._done = true;
  11213. this._requests.forEach(function (requestCapability) {
  11214. requestCapability.resolve({
  11215. value: undefined,
  11216. done: true
  11217. });
  11218. });
  11219. this._requests = [];
  11220. this._close();
  11221. }
  11222. _onProgress(evt) {
  11223. if (!this.isStreamingSupported && this.onProgress) {
  11224. this.onProgress({
  11225. loaded: evt.loaded
  11226. });
  11227. }
  11228. }
  11229. get isStreamingSupported() {
  11230. return false;
  11231. }
  11232. async read() {
  11233. if (this._queuedChunk !== null) {
  11234. const chunk = this._queuedChunk;
  11235. this._queuedChunk = null;
  11236. return {
  11237. value: chunk,
  11238. done: false
  11239. };
  11240. }
  11241. if (this._done) {
  11242. return {
  11243. value: undefined,
  11244. done: true
  11245. };
  11246. }
  11247. const requestCapability = (0, _util.createPromiseCapability)();
  11248. this._requests.push(requestCapability);
  11249. return requestCapability.promise;
  11250. }
  11251. cancel(reason) {
  11252. this._done = true;
  11253. this._requests.forEach(function (requestCapability) {
  11254. requestCapability.resolve({
  11255. value: undefined,
  11256. done: true
  11257. });
  11258. });
  11259. this._requests = [];
  11260. if (this._manager.isPendingRequest(this._requestId)) {
  11261. this._manager.abortRequest(this._requestId);
  11262. }
  11263. this._close();
  11264. }
  11265. }
  11266. /***/ }),
  11267. /* 26 */
  11268. /***/ (function(module, exports, __w_pdfjs_require__) {
  11269. "use strict";
  11270. Object.defineProperty(exports, "__esModule", {
  11271. value: true
  11272. });
  11273. exports.PDFFetchStream = void 0;
  11274. var _util = __w_pdfjs_require__(2);
  11275. var _network_utils = __w_pdfjs_require__(23);
  11276. ;
  11277. function createFetchOptions(headers, withCredentials, abortController) {
  11278. return {
  11279. method: "GET",
  11280. headers,
  11281. signal: abortController && abortController.signal,
  11282. mode: "cors",
  11283. credentials: withCredentials ? "include" : "same-origin",
  11284. redirect: "follow"
  11285. };
  11286. }
  11287. function createHeaders(httpHeaders) {
  11288. const headers = new Headers();
  11289. for (const property in httpHeaders) {
  11290. const value = httpHeaders[property];
  11291. if (typeof value === "undefined") {
  11292. continue;
  11293. }
  11294. headers.append(property, value);
  11295. }
  11296. return headers;
  11297. }
  11298. class PDFFetchStream {
  11299. constructor(source) {
  11300. this.source = source;
  11301. this.isHttp = /^https?:/i.test(source.url);
  11302. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  11303. this._fullRequestReader = null;
  11304. this._rangeRequestReaders = [];
  11305. }
  11306. get _progressiveDataLength() {
  11307. return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
  11308. }
  11309. getFullReader() {
  11310. (0, _util.assert)(!this._fullRequestReader, "PDFFetchStream.getFullReader can only be called once.");
  11311. this._fullRequestReader = new PDFFetchStreamReader(this);
  11312. return this._fullRequestReader;
  11313. }
  11314. getRangeReader(begin, end) {
  11315. if (end <= this._progressiveDataLength) {
  11316. return null;
  11317. }
  11318. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  11319. this._rangeRequestReaders.push(reader);
  11320. return reader;
  11321. }
  11322. cancelAllRequests(reason) {
  11323. if (this._fullRequestReader) {
  11324. this._fullRequestReader.cancel(reason);
  11325. }
  11326. const readers = this._rangeRequestReaders.slice(0);
  11327. readers.forEach(function (reader) {
  11328. reader.cancel(reason);
  11329. });
  11330. }
  11331. }
  11332. exports.PDFFetchStream = PDFFetchStream;
  11333. class PDFFetchStreamReader {
  11334. constructor(stream) {
  11335. this._stream = stream;
  11336. this._reader = null;
  11337. this._loaded = 0;
  11338. this._filename = null;
  11339. const source = stream.source;
  11340. this._withCredentials = source.withCredentials || false;
  11341. this._contentLength = source.length;
  11342. this._headersCapability = (0, _util.createPromiseCapability)();
  11343. this._disableRange = source.disableRange || false;
  11344. this._rangeChunkSize = source.rangeChunkSize;
  11345. if (!this._rangeChunkSize && !this._disableRange) {
  11346. this._disableRange = true;
  11347. }
  11348. if (typeof AbortController !== "undefined") {
  11349. this._abortController = new AbortController();
  11350. }
  11351. this._isStreamingSupported = !source.disableStream;
  11352. this._isRangeSupported = !source.disableRange;
  11353. this._headers = createHeaders(this._stream.httpHeaders);
  11354. const url = source.url;
  11355. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  11356. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  11357. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  11358. }
  11359. this._reader = response.body.getReader();
  11360. this._headersCapability.resolve();
  11361. const getResponseHeader = name => {
  11362. return response.headers.get(name);
  11363. };
  11364. const {
  11365. allowRangeRequests,
  11366. suggestedLength
  11367. } = (0, _network_utils.validateRangeRequestCapabilities)({
  11368. getResponseHeader,
  11369. isHttp: this._stream.isHttp,
  11370. rangeChunkSize: this._rangeChunkSize,
  11371. disableRange: this._disableRange
  11372. });
  11373. this._isRangeSupported = allowRangeRequests;
  11374. this._contentLength = suggestedLength || this._contentLength;
  11375. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  11376. if (!this._isStreamingSupported && this._isRangeSupported) {
  11377. this.cancel(new _util.AbortException("Streaming is disabled."));
  11378. }
  11379. }).catch(this._headersCapability.reject);
  11380. this.onProgress = null;
  11381. }
  11382. get headersReady() {
  11383. return this._headersCapability.promise;
  11384. }
  11385. get filename() {
  11386. return this._filename;
  11387. }
  11388. get contentLength() {
  11389. return this._contentLength;
  11390. }
  11391. get isRangeSupported() {
  11392. return this._isRangeSupported;
  11393. }
  11394. get isStreamingSupported() {
  11395. return this._isStreamingSupported;
  11396. }
  11397. async read() {
  11398. await this._headersCapability.promise;
  11399. const {
  11400. value,
  11401. done
  11402. } = await this._reader.read();
  11403. if (done) {
  11404. return {
  11405. value,
  11406. done
  11407. };
  11408. }
  11409. this._loaded += value.byteLength;
  11410. if (this.onProgress) {
  11411. this.onProgress({
  11412. loaded: this._loaded,
  11413. total: this._contentLength
  11414. });
  11415. }
  11416. const buffer = new Uint8Array(value).buffer;
  11417. return {
  11418. value: buffer,
  11419. done: false
  11420. };
  11421. }
  11422. cancel(reason) {
  11423. if (this._reader) {
  11424. this._reader.cancel(reason);
  11425. }
  11426. if (this._abortController) {
  11427. this._abortController.abort();
  11428. }
  11429. }
  11430. }
  11431. class PDFFetchStreamRangeReader {
  11432. constructor(stream, begin, end) {
  11433. this._stream = stream;
  11434. this._reader = null;
  11435. this._loaded = 0;
  11436. const source = stream.source;
  11437. this._withCredentials = source.withCredentials || false;
  11438. this._readCapability = (0, _util.createPromiseCapability)();
  11439. this._isStreamingSupported = !source.disableStream;
  11440. if (typeof AbortController !== "undefined") {
  11441. this._abortController = new AbortController();
  11442. }
  11443. this._headers = createHeaders(this._stream.httpHeaders);
  11444. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  11445. const url = source.url;
  11446. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  11447. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  11448. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  11449. }
  11450. this._readCapability.resolve();
  11451. this._reader = response.body.getReader();
  11452. }).catch(reason => {
  11453. if (reason && reason.name === "AbortError") {
  11454. return;
  11455. }
  11456. throw reason;
  11457. });
  11458. this.onProgress = null;
  11459. }
  11460. get isStreamingSupported() {
  11461. return this._isStreamingSupported;
  11462. }
  11463. async read() {
  11464. await this._readCapability.promise;
  11465. const {
  11466. value,
  11467. done
  11468. } = await this._reader.read();
  11469. if (done) {
  11470. return {
  11471. value,
  11472. done
  11473. };
  11474. }
  11475. this._loaded += value.byteLength;
  11476. if (this.onProgress) {
  11477. this.onProgress({
  11478. loaded: this._loaded
  11479. });
  11480. }
  11481. const buffer = new Uint8Array(value).buffer;
  11482. return {
  11483. value: buffer,
  11484. done: false
  11485. };
  11486. }
  11487. cancel(reason) {
  11488. if (this._reader) {
  11489. this._reader.cancel(reason);
  11490. }
  11491. if (this._abortController) {
  11492. this._abortController.abort();
  11493. }
  11494. }
  11495. }
  11496. /***/ })
  11497. /******/ ]);
  11498. });
  11499. //# sourceMappingURL=pdf.js.map