2
0

pdf.combined.js 2.0 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777617786177961780617816178261783617846178561786617876178861789617906179161792617936179461795617966179761798617996180061801618026180361804618056180661807618086180961810618116181261813618146181561816618176181861819618206182161822618236182461825618266182761828618296183061831618326183361834618356183661837
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. (function (root, factory) {
  16. 'use strict';
  17. if (typeof define === 'function' && define.amd) {
  18. define('pdfjs-dist/build/pdf.combined', ['exports'], factory);
  19. } else if (typeof exports !== 'undefined') {
  20. factory(exports);
  21. } else {
  22. factory(root['pdfjsDistBuildPdfCombined'] = {});
  23. }
  24. }(this, function (exports) {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. var pdfjsVersion = '1.6.289';
  28. var pdfjsBuild = '29fc2f9';
  29. var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
  30. var pdfjsLibs = {};
  31. (function pdfjsWrapper() {
  32. (function (root, factory) {
  33. factory(root.pdfjsCoreArithmeticDecoder = {});
  34. }(this, function (exports) {
  35. /* This class implements the QM Coder decoding as defined in
  36. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37. * Annex C.3 Arithmetic decoding procedure
  38. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  39. *
  40. * The arithmetic decoder is used in conjunction with context models to decode
  41. * JPEG2000 and JBIG2 streams.
  42. */
  43. var ArithmeticDecoder = function ArithmeticDecoderClosure() {
  44. // Table C-2
  45. var QeTable = [
  46. {
  47. qe: 0x5601,
  48. nmps: 1,
  49. nlps: 1,
  50. switchFlag: 1
  51. },
  52. {
  53. qe: 0x3401,
  54. nmps: 2,
  55. nlps: 6,
  56. switchFlag: 0
  57. },
  58. {
  59. qe: 0x1801,
  60. nmps: 3,
  61. nlps: 9,
  62. switchFlag: 0
  63. },
  64. {
  65. qe: 0x0AC1,
  66. nmps: 4,
  67. nlps: 12,
  68. switchFlag: 0
  69. },
  70. {
  71. qe: 0x0521,
  72. nmps: 5,
  73. nlps: 29,
  74. switchFlag: 0
  75. },
  76. {
  77. qe: 0x0221,
  78. nmps: 38,
  79. nlps: 33,
  80. switchFlag: 0
  81. },
  82. {
  83. qe: 0x5601,
  84. nmps: 7,
  85. nlps: 6,
  86. switchFlag: 1
  87. },
  88. {
  89. qe: 0x5401,
  90. nmps: 8,
  91. nlps: 14,
  92. switchFlag: 0
  93. },
  94. {
  95. qe: 0x4801,
  96. nmps: 9,
  97. nlps: 14,
  98. switchFlag: 0
  99. },
  100. {
  101. qe: 0x3801,
  102. nmps: 10,
  103. nlps: 14,
  104. switchFlag: 0
  105. },
  106. {
  107. qe: 0x3001,
  108. nmps: 11,
  109. nlps: 17,
  110. switchFlag: 0
  111. },
  112. {
  113. qe: 0x2401,
  114. nmps: 12,
  115. nlps: 18,
  116. switchFlag: 0
  117. },
  118. {
  119. qe: 0x1C01,
  120. nmps: 13,
  121. nlps: 20,
  122. switchFlag: 0
  123. },
  124. {
  125. qe: 0x1601,
  126. nmps: 29,
  127. nlps: 21,
  128. switchFlag: 0
  129. },
  130. {
  131. qe: 0x5601,
  132. nmps: 15,
  133. nlps: 14,
  134. switchFlag: 1
  135. },
  136. {
  137. qe: 0x5401,
  138. nmps: 16,
  139. nlps: 14,
  140. switchFlag: 0
  141. },
  142. {
  143. qe: 0x5101,
  144. nmps: 17,
  145. nlps: 15,
  146. switchFlag: 0
  147. },
  148. {
  149. qe: 0x4801,
  150. nmps: 18,
  151. nlps: 16,
  152. switchFlag: 0
  153. },
  154. {
  155. qe: 0x3801,
  156. nmps: 19,
  157. nlps: 17,
  158. switchFlag: 0
  159. },
  160. {
  161. qe: 0x3401,
  162. nmps: 20,
  163. nlps: 18,
  164. switchFlag: 0
  165. },
  166. {
  167. qe: 0x3001,
  168. nmps: 21,
  169. nlps: 19,
  170. switchFlag: 0
  171. },
  172. {
  173. qe: 0x2801,
  174. nmps: 22,
  175. nlps: 19,
  176. switchFlag: 0
  177. },
  178. {
  179. qe: 0x2401,
  180. nmps: 23,
  181. nlps: 20,
  182. switchFlag: 0
  183. },
  184. {
  185. qe: 0x2201,
  186. nmps: 24,
  187. nlps: 21,
  188. switchFlag: 0
  189. },
  190. {
  191. qe: 0x1C01,
  192. nmps: 25,
  193. nlps: 22,
  194. switchFlag: 0
  195. },
  196. {
  197. qe: 0x1801,
  198. nmps: 26,
  199. nlps: 23,
  200. switchFlag: 0
  201. },
  202. {
  203. qe: 0x1601,
  204. nmps: 27,
  205. nlps: 24,
  206. switchFlag: 0
  207. },
  208. {
  209. qe: 0x1401,
  210. nmps: 28,
  211. nlps: 25,
  212. switchFlag: 0
  213. },
  214. {
  215. qe: 0x1201,
  216. nmps: 29,
  217. nlps: 26,
  218. switchFlag: 0
  219. },
  220. {
  221. qe: 0x1101,
  222. nmps: 30,
  223. nlps: 27,
  224. switchFlag: 0
  225. },
  226. {
  227. qe: 0x0AC1,
  228. nmps: 31,
  229. nlps: 28,
  230. switchFlag: 0
  231. },
  232. {
  233. qe: 0x09C1,
  234. nmps: 32,
  235. nlps: 29,
  236. switchFlag: 0
  237. },
  238. {
  239. qe: 0x08A1,
  240. nmps: 33,
  241. nlps: 30,
  242. switchFlag: 0
  243. },
  244. {
  245. qe: 0x0521,
  246. nmps: 34,
  247. nlps: 31,
  248. switchFlag: 0
  249. },
  250. {
  251. qe: 0x0441,
  252. nmps: 35,
  253. nlps: 32,
  254. switchFlag: 0
  255. },
  256. {
  257. qe: 0x02A1,
  258. nmps: 36,
  259. nlps: 33,
  260. switchFlag: 0
  261. },
  262. {
  263. qe: 0x0221,
  264. nmps: 37,
  265. nlps: 34,
  266. switchFlag: 0
  267. },
  268. {
  269. qe: 0x0141,
  270. nmps: 38,
  271. nlps: 35,
  272. switchFlag: 0
  273. },
  274. {
  275. qe: 0x0111,
  276. nmps: 39,
  277. nlps: 36,
  278. switchFlag: 0
  279. },
  280. {
  281. qe: 0x0085,
  282. nmps: 40,
  283. nlps: 37,
  284. switchFlag: 0
  285. },
  286. {
  287. qe: 0x0049,
  288. nmps: 41,
  289. nlps: 38,
  290. switchFlag: 0
  291. },
  292. {
  293. qe: 0x0025,
  294. nmps: 42,
  295. nlps: 39,
  296. switchFlag: 0
  297. },
  298. {
  299. qe: 0x0015,
  300. nmps: 43,
  301. nlps: 40,
  302. switchFlag: 0
  303. },
  304. {
  305. qe: 0x0009,
  306. nmps: 44,
  307. nlps: 41,
  308. switchFlag: 0
  309. },
  310. {
  311. qe: 0x0005,
  312. nmps: 45,
  313. nlps: 42,
  314. switchFlag: 0
  315. },
  316. {
  317. qe: 0x0001,
  318. nmps: 45,
  319. nlps: 43,
  320. switchFlag: 0
  321. },
  322. {
  323. qe: 0x5601,
  324. nmps: 46,
  325. nlps: 46,
  326. switchFlag: 0
  327. }
  328. ];
  329. // C.3.5 Initialisation of the decoder (INITDEC)
  330. function ArithmeticDecoder(data, start, end) {
  331. this.data = data;
  332. this.bp = start;
  333. this.dataEnd = end;
  334. this.chigh = data[start];
  335. this.clow = 0;
  336. this.byteIn();
  337. this.chigh = this.chigh << 7 & 0xFFFF | this.clow >> 9 & 0x7F;
  338. this.clow = this.clow << 7 & 0xFFFF;
  339. this.ct -= 7;
  340. this.a = 0x8000;
  341. }
  342. ArithmeticDecoder.prototype = {
  343. // C.3.4 Compressed data input (BYTEIN)
  344. byteIn: function ArithmeticDecoder_byteIn() {
  345. var data = this.data;
  346. var bp = this.bp;
  347. if (data[bp] === 0xFF) {
  348. var b1 = data[bp + 1];
  349. if (b1 > 0x8F) {
  350. this.clow += 0xFF00;
  351. this.ct = 8;
  352. } else {
  353. bp++;
  354. this.clow += data[bp] << 9;
  355. this.ct = 7;
  356. this.bp = bp;
  357. }
  358. } else {
  359. bp++;
  360. this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xFF00;
  361. this.ct = 8;
  362. this.bp = bp;
  363. }
  364. if (this.clow > 0xFFFF) {
  365. this.chigh += this.clow >> 16;
  366. this.clow &= 0xFFFF;
  367. }
  368. },
  369. // C.3.2 Decoding a decision (DECODE)
  370. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  371. // contexts are packed into 1 byte:
  372. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  373. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  374. var qeTableIcx = QeTable[cx_index];
  375. var qeIcx = qeTableIcx.qe;
  376. var d;
  377. var a = this.a - qeIcx;
  378. if (this.chigh < qeIcx) {
  379. // exchangeLps
  380. if (a < qeIcx) {
  381. a = qeIcx;
  382. d = cx_mps;
  383. cx_index = qeTableIcx.nmps;
  384. } else {
  385. a = qeIcx;
  386. d = 1 ^ cx_mps;
  387. if (qeTableIcx.switchFlag === 1) {
  388. cx_mps = d;
  389. }
  390. cx_index = qeTableIcx.nlps;
  391. }
  392. } else {
  393. this.chigh -= qeIcx;
  394. if ((a & 0x8000) !== 0) {
  395. this.a = a;
  396. return cx_mps;
  397. }
  398. // exchangeMps
  399. if (a < qeIcx) {
  400. d = 1 ^ cx_mps;
  401. if (qeTableIcx.switchFlag === 1) {
  402. cx_mps = d;
  403. }
  404. cx_index = qeTableIcx.nlps;
  405. } else {
  406. d = cx_mps;
  407. cx_index = qeTableIcx.nmps;
  408. }
  409. }
  410. // C.3.3 renormD;
  411. do {
  412. if (this.ct === 0) {
  413. this.byteIn();
  414. }
  415. a <<= 1;
  416. this.chigh = this.chigh << 1 & 0xFFFF | this.clow >> 15 & 1;
  417. this.clow = this.clow << 1 & 0xFFFF;
  418. this.ct--;
  419. } while ((a & 0x8000) === 0);
  420. this.a = a;
  421. contexts[pos] = cx_index << 1 | cx_mps;
  422. return d;
  423. }
  424. };
  425. return ArithmeticDecoder;
  426. }();
  427. exports.ArithmeticDecoder = ArithmeticDecoder;
  428. }));
  429. (function (root, factory) {
  430. factory(root.pdfjsCoreBidi = {});
  431. }(this, function (exports) {
  432. // Character types for symbols from 0000 to 00FF.
  433. var baseTypes = [
  434. 'BN',
  435. 'BN',
  436. 'BN',
  437. 'BN',
  438. 'BN',
  439. 'BN',
  440. 'BN',
  441. 'BN',
  442. 'BN',
  443. 'S',
  444. 'B',
  445. 'S',
  446. 'WS',
  447. 'B',
  448. 'BN',
  449. 'BN',
  450. 'BN',
  451. 'BN',
  452. 'BN',
  453. 'BN',
  454. 'BN',
  455. 'BN',
  456. 'BN',
  457. 'BN',
  458. 'BN',
  459. 'BN',
  460. 'BN',
  461. 'BN',
  462. 'B',
  463. 'B',
  464. 'B',
  465. 'S',
  466. 'WS',
  467. 'ON',
  468. 'ON',
  469. 'ET',
  470. 'ET',
  471. 'ET',
  472. 'ON',
  473. 'ON',
  474. 'ON',
  475. 'ON',
  476. 'ON',
  477. 'ON',
  478. 'CS',
  479. 'ON',
  480. 'CS',
  481. 'ON',
  482. 'EN',
  483. 'EN',
  484. 'EN',
  485. 'EN',
  486. 'EN',
  487. 'EN',
  488. 'EN',
  489. 'EN',
  490. 'EN',
  491. 'EN',
  492. 'ON',
  493. 'ON',
  494. 'ON',
  495. 'ON',
  496. 'ON',
  497. 'ON',
  498. 'ON',
  499. 'L',
  500. 'L',
  501. 'L',
  502. 'L',
  503. 'L',
  504. 'L',
  505. 'L',
  506. 'L',
  507. 'L',
  508. 'L',
  509. 'L',
  510. 'L',
  511. 'L',
  512. 'L',
  513. 'L',
  514. 'L',
  515. 'L',
  516. 'L',
  517. 'L',
  518. 'L',
  519. 'L',
  520. 'L',
  521. 'L',
  522. 'L',
  523. 'L',
  524. 'L',
  525. 'ON',
  526. 'ON',
  527. 'ON',
  528. 'ON',
  529. 'ON',
  530. 'ON',
  531. 'L',
  532. 'L',
  533. 'L',
  534. 'L',
  535. 'L',
  536. 'L',
  537. 'L',
  538. 'L',
  539. 'L',
  540. 'L',
  541. 'L',
  542. 'L',
  543. 'L',
  544. 'L',
  545. 'L',
  546. 'L',
  547. 'L',
  548. 'L',
  549. 'L',
  550. 'L',
  551. 'L',
  552. 'L',
  553. 'L',
  554. 'L',
  555. 'L',
  556. 'L',
  557. 'ON',
  558. 'ON',
  559. 'ON',
  560. 'ON',
  561. 'BN',
  562. 'BN',
  563. 'BN',
  564. 'BN',
  565. 'BN',
  566. 'BN',
  567. 'B',
  568. 'BN',
  569. 'BN',
  570. 'BN',
  571. 'BN',
  572. 'BN',
  573. 'BN',
  574. 'BN',
  575. 'BN',
  576. 'BN',
  577. 'BN',
  578. 'BN',
  579. 'BN',
  580. 'BN',
  581. 'BN',
  582. 'BN',
  583. 'BN',
  584. 'BN',
  585. 'BN',
  586. 'BN',
  587. 'BN',
  588. 'BN',
  589. 'BN',
  590. 'BN',
  591. 'BN',
  592. 'BN',
  593. 'BN',
  594. 'CS',
  595. 'ON',
  596. 'ET',
  597. 'ET',
  598. 'ET',
  599. 'ET',
  600. 'ON',
  601. 'ON',
  602. 'ON',
  603. 'ON',
  604. 'L',
  605. 'ON',
  606. 'ON',
  607. 'ON',
  608. 'ON',
  609. 'ON',
  610. 'ET',
  611. 'ET',
  612. 'EN',
  613. 'EN',
  614. 'ON',
  615. 'L',
  616. 'ON',
  617. 'ON',
  618. 'ON',
  619. 'EN',
  620. 'L',
  621. 'ON',
  622. 'ON',
  623. 'ON',
  624. 'ON',
  625. 'ON',
  626. 'L',
  627. 'L',
  628. 'L',
  629. 'L',
  630. 'L',
  631. 'L',
  632. 'L',
  633. 'L',
  634. 'L',
  635. 'L',
  636. 'L',
  637. 'L',
  638. 'L',
  639. 'L',
  640. 'L',
  641. 'L',
  642. 'L',
  643. 'L',
  644. 'L',
  645. 'L',
  646. 'L',
  647. 'L',
  648. 'L',
  649. 'ON',
  650. 'L',
  651. 'L',
  652. 'L',
  653. 'L',
  654. 'L',
  655. 'L',
  656. 'L',
  657. 'L',
  658. 'L',
  659. 'L',
  660. 'L',
  661. 'L',
  662. 'L',
  663. 'L',
  664. 'L',
  665. 'L',
  666. 'L',
  667. 'L',
  668. 'L',
  669. 'L',
  670. 'L',
  671. 'L',
  672. 'L',
  673. 'L',
  674. 'L',
  675. 'L',
  676. 'L',
  677. 'L',
  678. 'L',
  679. 'L',
  680. 'L',
  681. 'ON',
  682. 'L',
  683. 'L',
  684. 'L',
  685. 'L',
  686. 'L',
  687. 'L',
  688. 'L',
  689. 'L'
  690. ];
  691. // Character types for symbols from 0600 to 06FF
  692. var arabicTypes = [
  693. 'AL',
  694. 'AL',
  695. 'AL',
  696. 'AL',
  697. 'AL',
  698. 'AL',
  699. 'AL',
  700. 'AL',
  701. 'AL',
  702. 'AL',
  703. 'AL',
  704. 'AL',
  705. 'CS',
  706. 'AL',
  707. 'ON',
  708. 'ON',
  709. 'NSM',
  710. 'NSM',
  711. 'NSM',
  712. 'NSM',
  713. 'NSM',
  714. 'NSM',
  715. 'AL',
  716. 'AL',
  717. 'AL',
  718. 'AL',
  719. 'AL',
  720. 'AL',
  721. 'AL',
  722. 'AL',
  723. 'AL',
  724. 'AL',
  725. 'AL',
  726. 'AL',
  727. 'AL',
  728. 'AL',
  729. 'AL',
  730. 'AL',
  731. 'AL',
  732. 'AL',
  733. 'AL',
  734. 'AL',
  735. 'AL',
  736. 'AL',
  737. 'AL',
  738. 'AL',
  739. 'AL',
  740. 'AL',
  741. 'AL',
  742. 'AL',
  743. 'AL',
  744. 'AL',
  745. 'AL',
  746. 'AL',
  747. 'AL',
  748. 'AL',
  749. 'AL',
  750. 'AL',
  751. 'AL',
  752. 'AL',
  753. 'AL',
  754. 'AL',
  755. 'AL',
  756. 'AL',
  757. 'AL',
  758. 'AL',
  759. 'AL',
  760. 'AL',
  761. 'AL',
  762. 'AL',
  763. 'AL',
  764. 'AL',
  765. 'AL',
  766. 'AL',
  767. 'AL',
  768. 'NSM',
  769. 'NSM',
  770. 'NSM',
  771. 'NSM',
  772. 'NSM',
  773. 'NSM',
  774. 'NSM',
  775. 'NSM',
  776. 'NSM',
  777. 'NSM',
  778. 'NSM',
  779. 'NSM',
  780. 'NSM',
  781. 'NSM',
  782. 'AL',
  783. 'AL',
  784. 'AL',
  785. 'AL',
  786. 'AL',
  787. 'AL',
  788. 'AL',
  789. 'AN',
  790. 'AN',
  791. 'AN',
  792. 'AN',
  793. 'AN',
  794. 'AN',
  795. 'AN',
  796. 'AN',
  797. 'AN',
  798. 'AN',
  799. 'ET',
  800. 'AN',
  801. 'AN',
  802. 'AL',
  803. 'AL',
  804. 'AL',
  805. 'NSM',
  806. 'AL',
  807. 'AL',
  808. 'AL',
  809. 'AL',
  810. 'AL',
  811. 'AL',
  812. 'AL',
  813. 'AL',
  814. 'AL',
  815. 'AL',
  816. 'AL',
  817. 'AL',
  818. 'AL',
  819. 'AL',
  820. 'AL',
  821. 'AL',
  822. 'AL',
  823. 'AL',
  824. 'AL',
  825. 'AL',
  826. 'AL',
  827. 'AL',
  828. 'AL',
  829. 'AL',
  830. 'AL',
  831. 'AL',
  832. 'AL',
  833. 'AL',
  834. 'AL',
  835. 'AL',
  836. 'AL',
  837. 'AL',
  838. 'AL',
  839. 'AL',
  840. 'AL',
  841. 'AL',
  842. 'AL',
  843. 'AL',
  844. 'AL',
  845. 'AL',
  846. 'AL',
  847. 'AL',
  848. 'AL',
  849. 'AL',
  850. 'AL',
  851. 'AL',
  852. 'AL',
  853. 'AL',
  854. 'AL',
  855. 'AL',
  856. 'AL',
  857. 'AL',
  858. 'AL',
  859. 'AL',
  860. 'AL',
  861. 'AL',
  862. 'AL',
  863. 'AL',
  864. 'AL',
  865. 'AL',
  866. 'AL',
  867. 'AL',
  868. 'AL',
  869. 'AL',
  870. 'AL',
  871. 'AL',
  872. 'AL',
  873. 'AL',
  874. 'AL',
  875. 'AL',
  876. 'AL',
  877. 'AL',
  878. 'AL',
  879. 'AL',
  880. 'AL',
  881. 'AL',
  882. 'AL',
  883. 'AL',
  884. 'AL',
  885. 'AL',
  886. 'AL',
  887. 'AL',
  888. 'AL',
  889. 'AL',
  890. 'AL',
  891. 'AL',
  892. 'AL',
  893. 'AL',
  894. 'AL',
  895. 'AL',
  896. 'AL',
  897. 'AL',
  898. 'AL',
  899. 'AL',
  900. 'AL',
  901. 'AL',
  902. 'AL',
  903. 'AL',
  904. 'AL',
  905. 'AL',
  906. 'AL',
  907. 'NSM',
  908. 'NSM',
  909. 'NSM',
  910. 'NSM',
  911. 'NSM',
  912. 'NSM',
  913. 'NSM',
  914. 'NSM',
  915. 'NSM',
  916. 'NSM',
  917. 'NSM',
  918. 'NSM',
  919. 'NSM',
  920. 'NSM',
  921. 'NSM',
  922. 'NSM',
  923. 'NSM',
  924. 'NSM',
  925. 'NSM',
  926. 'ON',
  927. 'NSM',
  928. 'NSM',
  929. 'NSM',
  930. 'NSM',
  931. 'AL',
  932. 'AL',
  933. 'AL',
  934. 'AL',
  935. 'AL',
  936. 'AL',
  937. 'AL',
  938. 'AL',
  939. 'AL',
  940. 'AL',
  941. 'AL',
  942. 'AL',
  943. 'AL',
  944. 'AL',
  945. 'AL',
  946. 'AL',
  947. 'AL',
  948. 'AL'
  949. ];
  950. function isOdd(i) {
  951. return (i & 1) !== 0;
  952. }
  953. function isEven(i) {
  954. return (i & 1) === 0;
  955. }
  956. function findUnequal(arr, start, value) {
  957. for (var j = start, jj = arr.length; j < jj; ++j) {
  958. if (arr[j] !== value) {
  959. return j;
  960. }
  961. }
  962. return j;
  963. }
  964. function setValues(arr, start, end, value) {
  965. for (var j = start; j < end; ++j) {
  966. arr[j] = value;
  967. }
  968. }
  969. function reverseValues(arr, start, end) {
  970. for (var i = start, j = end - 1; i < j; ++i, --j) {
  971. var temp = arr[i];
  972. arr[i] = arr[j];
  973. arr[j] = temp;
  974. }
  975. }
  976. function createBidiText(str, isLTR, vertical) {
  977. return {
  978. str: str,
  979. dir: vertical ? 'ttb' : isLTR ? 'ltr' : 'rtl'
  980. };
  981. }
  982. // These are used in bidi(), which is called frequently. We re-use them on
  983. // each call to avoid unnecessary allocations.
  984. var chars = [];
  985. var types = [];
  986. function bidi(str, startLevel, vertical) {
  987. var isLTR = true;
  988. var strLength = str.length;
  989. if (strLength === 0 || vertical) {
  990. return createBidiText(str, isLTR, vertical);
  991. }
  992. // Get types and fill arrays
  993. chars.length = strLength;
  994. types.length = strLength;
  995. var numBidi = 0;
  996. var i, ii;
  997. for (i = 0; i < strLength; ++i) {
  998. chars[i] = str.charAt(i);
  999. var charCode = str.charCodeAt(i);
  1000. var charType = 'L';
  1001. if (charCode <= 0x00ff) {
  1002. charType = baseTypes[charCode];
  1003. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1004. charType = 'R';
  1005. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1006. charType = arabicTypes[charCode & 0xff];
  1007. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1008. charType = 'AL';
  1009. }
  1010. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1011. numBidi++;
  1012. }
  1013. types[i] = charType;
  1014. }
  1015. // Detect the bidi method
  1016. // - If there are no rtl characters then no bidi needed
  1017. // - If less than 30% chars are rtl then string is primarily ltr
  1018. // - If more than 30% chars are rtl then string is primarily rtl
  1019. if (numBidi === 0) {
  1020. isLTR = true;
  1021. return createBidiText(str, isLTR);
  1022. }
  1023. if (startLevel === -1) {
  1024. if (strLength / numBidi < 0.3) {
  1025. isLTR = true;
  1026. startLevel = 0;
  1027. } else {
  1028. isLTR = false;
  1029. startLevel = 1;
  1030. }
  1031. }
  1032. var levels = [];
  1033. for (i = 0; i < strLength; ++i) {
  1034. levels[i] = startLevel;
  1035. }
  1036. /*
  1037. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1038. */
  1039. var e = isOdd(startLevel) ? 'R' : 'L';
  1040. var sor = e;
  1041. var eor = sor;
  1042. /*
  1043. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1044. type of the NSM to the type of the previous character. If the NSM is at the
  1045. start of the level run, it will get the type of sor.
  1046. */
  1047. var lastType = sor;
  1048. for (i = 0; i < strLength; ++i) {
  1049. if (types[i] === 'NSM') {
  1050. types[i] = lastType;
  1051. } else {
  1052. lastType = types[i];
  1053. }
  1054. }
  1055. /*
  1056. W2. Search backwards from each instance of a European number until the
  1057. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1058. the type of the European number to Arabic number.
  1059. */
  1060. lastType = sor;
  1061. var t;
  1062. for (i = 0; i < strLength; ++i) {
  1063. t = types[i];
  1064. if (t === 'EN') {
  1065. types[i] = lastType === 'AL' ? 'AN' : 'EN';
  1066. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1067. lastType = t;
  1068. }
  1069. }
  1070. /*
  1071. W3. Change all ALs to R.
  1072. */
  1073. for (i = 0; i < strLength; ++i) {
  1074. t = types[i];
  1075. if (t === 'AL') {
  1076. types[i] = 'R';
  1077. }
  1078. }
  1079. /*
  1080. W4. A single European separator between two European numbers changes to a
  1081. European number. A single common separator between two numbers of the same
  1082. type changes to that type:
  1083. */
  1084. for (i = 1; i < strLength - 1; ++i) {
  1085. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1086. types[i] = 'EN';
  1087. }
  1088. if (types[i] === 'CS' && (types[i - 1] === 'EN' || types[i - 1] === 'AN') && types[i + 1] === types[i - 1]) {
  1089. types[i] = types[i - 1];
  1090. }
  1091. }
  1092. /*
  1093. W5. A sequence of European terminators adjacent to European numbers changes
  1094. to all European numbers:
  1095. */
  1096. for (i = 0; i < strLength; ++i) {
  1097. if (types[i] === 'EN') {
  1098. // do before
  1099. var j;
  1100. for (j = i - 1; j >= 0; --j) {
  1101. if (types[j] !== 'ET') {
  1102. break;
  1103. }
  1104. types[j] = 'EN';
  1105. }
  1106. // do after
  1107. for (j = i + 1; j < strLength; ++j) {
  1108. if (types[j] !== 'ET') {
  1109. break;
  1110. }
  1111. types[j] = 'EN';
  1112. }
  1113. }
  1114. }
  1115. /*
  1116. W6. Otherwise, separators and terminators change to Other Neutral:
  1117. */
  1118. for (i = 0; i < strLength; ++i) {
  1119. t = types[i];
  1120. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1121. types[i] = 'ON';
  1122. }
  1123. }
  1124. /*
  1125. W7. Search backwards from each instance of a European number until the
  1126. first strong type (R, L, or sor) is found. If an L is found, then change
  1127. the type of the European number to L.
  1128. */
  1129. lastType = sor;
  1130. for (i = 0; i < strLength; ++i) {
  1131. t = types[i];
  1132. if (t === 'EN') {
  1133. types[i] = lastType === 'L' ? 'L' : 'EN';
  1134. } else if (t === 'R' || t === 'L') {
  1135. lastType = t;
  1136. }
  1137. }
  1138. /*
  1139. N1. A sequence of neutrals takes the direction of the surrounding strong
  1140. text if the text on both sides has the same direction. European and Arabic
  1141. numbers are treated as though they were R. Start-of-level-run (sor) and
  1142. end-of-level-run (eor) are used at level run boundaries.
  1143. */
  1144. for (i = 0; i < strLength; ++i) {
  1145. if (types[i] === 'ON') {
  1146. var end = findUnequal(types, i + 1, 'ON');
  1147. var before = sor;
  1148. if (i > 0) {
  1149. before = types[i - 1];
  1150. }
  1151. var after = eor;
  1152. if (end + 1 < strLength) {
  1153. after = types[end + 1];
  1154. }
  1155. if (before !== 'L') {
  1156. before = 'R';
  1157. }
  1158. if (after !== 'L') {
  1159. after = 'R';
  1160. }
  1161. if (before === after) {
  1162. setValues(types, i, end, before);
  1163. }
  1164. i = end - 1;
  1165. }
  1166. }
  1167. // reset to end (-1 so next iteration is ok)
  1168. /*
  1169. N2. Any remaining neutrals take the embedding direction.
  1170. */
  1171. for (i = 0; i < strLength; ++i) {
  1172. if (types[i] === 'ON') {
  1173. types[i] = e;
  1174. }
  1175. }
  1176. /*
  1177. I1. For all characters with an even (left-to-right) embedding direction,
  1178. those of type R go up one level and those of type AN or EN go up two
  1179. levels.
  1180. I2. For all characters with an odd (right-to-left) embedding direction,
  1181. those of type L, EN or AN go up one level.
  1182. */
  1183. for (i = 0; i < strLength; ++i) {
  1184. t = types[i];
  1185. if (isEven(levels[i])) {
  1186. if (t === 'R') {
  1187. levels[i] += 1;
  1188. } else if (t === 'AN' || t === 'EN') {
  1189. levels[i] += 2;
  1190. }
  1191. } else {
  1192. // isOdd
  1193. if (t === 'L' || t === 'AN' || t === 'EN') {
  1194. levels[i] += 1;
  1195. }
  1196. }
  1197. }
  1198. /*
  1199. L1. On each line, reset the embedding level of the following characters to
  1200. the paragraph embedding level:
  1201. segment separators,
  1202. paragraph separators,
  1203. any sequence of whitespace characters preceding a segment separator or
  1204. paragraph separator, and any sequence of white space characters at the end
  1205. of the line.
  1206. */
  1207. // don't bother as text is only single line
  1208. /*
  1209. L2. From the highest level found in the text to the lowest odd level on
  1210. each line, reverse any contiguous sequence of characters that are at that
  1211. level or higher.
  1212. */
  1213. // find highest level & lowest odd level
  1214. var highestLevel = -1;
  1215. var lowestOddLevel = 99;
  1216. var level;
  1217. for (i = 0, ii = levels.length; i < ii; ++i) {
  1218. level = levels[i];
  1219. if (highestLevel < level) {
  1220. highestLevel = level;
  1221. }
  1222. if (lowestOddLevel > level && isOdd(level)) {
  1223. lowestOddLevel = level;
  1224. }
  1225. }
  1226. // now reverse between those limits
  1227. for (level = highestLevel; level >= lowestOddLevel; --level) {
  1228. // find segments to reverse
  1229. var start = -1;
  1230. for (i = 0, ii = levels.length; i < ii; ++i) {
  1231. if (levels[i] < level) {
  1232. if (start >= 0) {
  1233. reverseValues(chars, start, i);
  1234. start = -1;
  1235. }
  1236. } else if (start < 0) {
  1237. start = i;
  1238. }
  1239. }
  1240. if (start >= 0) {
  1241. reverseValues(chars, start, levels.length);
  1242. }
  1243. }
  1244. /*
  1245. L3. Combining marks applied to a right-to-left base character will at this
  1246. point precede their base character. If the rendering engine expects them to
  1247. follow the base characters in the final display process, then the ordering
  1248. of the marks and the base character must be reversed.
  1249. */
  1250. // don't bother for now
  1251. /*
  1252. L4. A character that possesses the mirrored property as specified by
  1253. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  1254. directionality of that character is R.
  1255. */
  1256. // don't mirror as characters are already mirrored in the pdf
  1257. // Finally, return string
  1258. for (i = 0, ii = chars.length; i < ii; ++i) {
  1259. var ch = chars[i];
  1260. if (ch === '<' || ch === '>') {
  1261. chars[i] = '';
  1262. }
  1263. }
  1264. return createBidiText(chars.join(''), isLTR);
  1265. }
  1266. exports.bidi = bidi;
  1267. }));
  1268. (function (root, factory) {
  1269. factory(root.pdfjsCoreCharsets = {});
  1270. }(this, function (exports) {
  1271. var ISOAdobeCharset = [
  1272. '.notdef',
  1273. 'space',
  1274. 'exclam',
  1275. 'quotedbl',
  1276. 'numbersign',
  1277. 'dollar',
  1278. 'percent',
  1279. 'ampersand',
  1280. 'quoteright',
  1281. 'parenleft',
  1282. 'parenright',
  1283. 'asterisk',
  1284. 'plus',
  1285. 'comma',
  1286. 'hyphen',
  1287. 'period',
  1288. 'slash',
  1289. 'zero',
  1290. 'one',
  1291. 'two',
  1292. 'three',
  1293. 'four',
  1294. 'five',
  1295. 'six',
  1296. 'seven',
  1297. 'eight',
  1298. 'nine',
  1299. 'colon',
  1300. 'semicolon',
  1301. 'less',
  1302. 'equal',
  1303. 'greater',
  1304. 'question',
  1305. 'at',
  1306. 'A',
  1307. 'B',
  1308. 'C',
  1309. 'D',
  1310. 'E',
  1311. 'F',
  1312. 'G',
  1313. 'H',
  1314. 'I',
  1315. 'J',
  1316. 'K',
  1317. 'L',
  1318. 'M',
  1319. 'N',
  1320. 'O',
  1321. 'P',
  1322. 'Q',
  1323. 'R',
  1324. 'S',
  1325. 'T',
  1326. 'U',
  1327. 'V',
  1328. 'W',
  1329. 'X',
  1330. 'Y',
  1331. 'Z',
  1332. 'bracketleft',
  1333. 'backslash',
  1334. 'bracketright',
  1335. 'asciicircum',
  1336. 'underscore',
  1337. 'quoteleft',
  1338. 'a',
  1339. 'b',
  1340. 'c',
  1341. 'd',
  1342. 'e',
  1343. 'f',
  1344. 'g',
  1345. 'h',
  1346. 'i',
  1347. 'j',
  1348. 'k',
  1349. 'l',
  1350. 'm',
  1351. 'n',
  1352. 'o',
  1353. 'p',
  1354. 'q',
  1355. 'r',
  1356. 's',
  1357. 't',
  1358. 'u',
  1359. 'v',
  1360. 'w',
  1361. 'x',
  1362. 'y',
  1363. 'z',
  1364. 'braceleft',
  1365. 'bar',
  1366. 'braceright',
  1367. 'asciitilde',
  1368. 'exclamdown',
  1369. 'cent',
  1370. 'sterling',
  1371. 'fraction',
  1372. 'yen',
  1373. 'florin',
  1374. 'section',
  1375. 'currency',
  1376. 'quotesingle',
  1377. 'quotedblleft',
  1378. 'guillemotleft',
  1379. 'guilsinglleft',
  1380. 'guilsinglright',
  1381. 'fi',
  1382. 'fl',
  1383. 'endash',
  1384. 'dagger',
  1385. 'daggerdbl',
  1386. 'periodcentered',
  1387. 'paragraph',
  1388. 'bullet',
  1389. 'quotesinglbase',
  1390. 'quotedblbase',
  1391. 'quotedblright',
  1392. 'guillemotright',
  1393. 'ellipsis',
  1394. 'perthousand',
  1395. 'questiondown',
  1396. 'grave',
  1397. 'acute',
  1398. 'circumflex',
  1399. 'tilde',
  1400. 'macron',
  1401. 'breve',
  1402. 'dotaccent',
  1403. 'dieresis',
  1404. 'ring',
  1405. 'cedilla',
  1406. 'hungarumlaut',
  1407. 'ogonek',
  1408. 'caron',
  1409. 'emdash',
  1410. 'AE',
  1411. 'ordfeminine',
  1412. 'Lslash',
  1413. 'Oslash',
  1414. 'OE',
  1415. 'ordmasculine',
  1416. 'ae',
  1417. 'dotlessi',
  1418. 'lslash',
  1419. 'oslash',
  1420. 'oe',
  1421. 'germandbls',
  1422. 'onesuperior',
  1423. 'logicalnot',
  1424. 'mu',
  1425. 'trademark',
  1426. 'Eth',
  1427. 'onehalf',
  1428. 'plusminus',
  1429. 'Thorn',
  1430. 'onequarter',
  1431. 'divide',
  1432. 'brokenbar',
  1433. 'degree',
  1434. 'thorn',
  1435. 'threequarters',
  1436. 'twosuperior',
  1437. 'registered',
  1438. 'minus',
  1439. 'eth',
  1440. 'multiply',
  1441. 'threesuperior',
  1442. 'copyright',
  1443. 'Aacute',
  1444. 'Acircumflex',
  1445. 'Adieresis',
  1446. 'Agrave',
  1447. 'Aring',
  1448. 'Atilde',
  1449. 'Ccedilla',
  1450. 'Eacute',
  1451. 'Ecircumflex',
  1452. 'Edieresis',
  1453. 'Egrave',
  1454. 'Iacute',
  1455. 'Icircumflex',
  1456. 'Idieresis',
  1457. 'Igrave',
  1458. 'Ntilde',
  1459. 'Oacute',
  1460. 'Ocircumflex',
  1461. 'Odieresis',
  1462. 'Ograve',
  1463. 'Otilde',
  1464. 'Scaron',
  1465. 'Uacute',
  1466. 'Ucircumflex',
  1467. 'Udieresis',
  1468. 'Ugrave',
  1469. 'Yacute',
  1470. 'Ydieresis',
  1471. 'Zcaron',
  1472. 'aacute',
  1473. 'acircumflex',
  1474. 'adieresis',
  1475. 'agrave',
  1476. 'aring',
  1477. 'atilde',
  1478. 'ccedilla',
  1479. 'eacute',
  1480. 'ecircumflex',
  1481. 'edieresis',
  1482. 'egrave',
  1483. 'iacute',
  1484. 'icircumflex',
  1485. 'idieresis',
  1486. 'igrave',
  1487. 'ntilde',
  1488. 'oacute',
  1489. 'ocircumflex',
  1490. 'odieresis',
  1491. 'ograve',
  1492. 'otilde',
  1493. 'scaron',
  1494. 'uacute',
  1495. 'ucircumflex',
  1496. 'udieresis',
  1497. 'ugrave',
  1498. 'yacute',
  1499. 'ydieresis',
  1500. 'zcaron'
  1501. ];
  1502. var ExpertCharset = [
  1503. '.notdef',
  1504. 'space',
  1505. 'exclamsmall',
  1506. 'Hungarumlautsmall',
  1507. 'dollaroldstyle',
  1508. 'dollarsuperior',
  1509. 'ampersandsmall',
  1510. 'Acutesmall',
  1511. 'parenleftsuperior',
  1512. 'parenrightsuperior',
  1513. 'twodotenleader',
  1514. 'onedotenleader',
  1515. 'comma',
  1516. 'hyphen',
  1517. 'period',
  1518. 'fraction',
  1519. 'zerooldstyle',
  1520. 'oneoldstyle',
  1521. 'twooldstyle',
  1522. 'threeoldstyle',
  1523. 'fouroldstyle',
  1524. 'fiveoldstyle',
  1525. 'sixoldstyle',
  1526. 'sevenoldstyle',
  1527. 'eightoldstyle',
  1528. 'nineoldstyle',
  1529. 'colon',
  1530. 'semicolon',
  1531. 'commasuperior',
  1532. 'threequartersemdash',
  1533. 'periodsuperior',
  1534. 'questionsmall',
  1535. 'asuperior',
  1536. 'bsuperior',
  1537. 'centsuperior',
  1538. 'dsuperior',
  1539. 'esuperior',
  1540. 'isuperior',
  1541. 'lsuperior',
  1542. 'msuperior',
  1543. 'nsuperior',
  1544. 'osuperior',
  1545. 'rsuperior',
  1546. 'ssuperior',
  1547. 'tsuperior',
  1548. 'ff',
  1549. 'fi',
  1550. 'fl',
  1551. 'ffi',
  1552. 'ffl',
  1553. 'parenleftinferior',
  1554. 'parenrightinferior',
  1555. 'Circumflexsmall',
  1556. 'hyphensuperior',
  1557. 'Gravesmall',
  1558. 'Asmall',
  1559. 'Bsmall',
  1560. 'Csmall',
  1561. 'Dsmall',
  1562. 'Esmall',
  1563. 'Fsmall',
  1564. 'Gsmall',
  1565. 'Hsmall',
  1566. 'Ismall',
  1567. 'Jsmall',
  1568. 'Ksmall',
  1569. 'Lsmall',
  1570. 'Msmall',
  1571. 'Nsmall',
  1572. 'Osmall',
  1573. 'Psmall',
  1574. 'Qsmall',
  1575. 'Rsmall',
  1576. 'Ssmall',
  1577. 'Tsmall',
  1578. 'Usmall',
  1579. 'Vsmall',
  1580. 'Wsmall',
  1581. 'Xsmall',
  1582. 'Ysmall',
  1583. 'Zsmall',
  1584. 'colonmonetary',
  1585. 'onefitted',
  1586. 'rupiah',
  1587. 'Tildesmall',
  1588. 'exclamdownsmall',
  1589. 'centoldstyle',
  1590. 'Lslashsmall',
  1591. 'Scaronsmall',
  1592. 'Zcaronsmall',
  1593. 'Dieresissmall',
  1594. 'Brevesmall',
  1595. 'Caronsmall',
  1596. 'Dotaccentsmall',
  1597. 'Macronsmall',
  1598. 'figuredash',
  1599. 'hypheninferior',
  1600. 'Ogoneksmall',
  1601. 'Ringsmall',
  1602. 'Cedillasmall',
  1603. 'onequarter',
  1604. 'onehalf',
  1605. 'threequarters',
  1606. 'questiondownsmall',
  1607. 'oneeighth',
  1608. 'threeeighths',
  1609. 'fiveeighths',
  1610. 'seveneighths',
  1611. 'onethird',
  1612. 'twothirds',
  1613. 'zerosuperior',
  1614. 'onesuperior',
  1615. 'twosuperior',
  1616. 'threesuperior',
  1617. 'foursuperior',
  1618. 'fivesuperior',
  1619. 'sixsuperior',
  1620. 'sevensuperior',
  1621. 'eightsuperior',
  1622. 'ninesuperior',
  1623. 'zeroinferior',
  1624. 'oneinferior',
  1625. 'twoinferior',
  1626. 'threeinferior',
  1627. 'fourinferior',
  1628. 'fiveinferior',
  1629. 'sixinferior',
  1630. 'seveninferior',
  1631. 'eightinferior',
  1632. 'nineinferior',
  1633. 'centinferior',
  1634. 'dollarinferior',
  1635. 'periodinferior',
  1636. 'commainferior',
  1637. 'Agravesmall',
  1638. 'Aacutesmall',
  1639. 'Acircumflexsmall',
  1640. 'Atildesmall',
  1641. 'Adieresissmall',
  1642. 'Aringsmall',
  1643. 'AEsmall',
  1644. 'Ccedillasmall',
  1645. 'Egravesmall',
  1646. 'Eacutesmall',
  1647. 'Ecircumflexsmall',
  1648. 'Edieresissmall',
  1649. 'Igravesmall',
  1650. 'Iacutesmall',
  1651. 'Icircumflexsmall',
  1652. 'Idieresissmall',
  1653. 'Ethsmall',
  1654. 'Ntildesmall',
  1655. 'Ogravesmall',
  1656. 'Oacutesmall',
  1657. 'Ocircumflexsmall',
  1658. 'Otildesmall',
  1659. 'Odieresissmall',
  1660. 'OEsmall',
  1661. 'Oslashsmall',
  1662. 'Ugravesmall',
  1663. 'Uacutesmall',
  1664. 'Ucircumflexsmall',
  1665. 'Udieresissmall',
  1666. 'Yacutesmall',
  1667. 'Thornsmall',
  1668. 'Ydieresissmall'
  1669. ];
  1670. var ExpertSubsetCharset = [
  1671. '.notdef',
  1672. 'space',
  1673. 'dollaroldstyle',
  1674. 'dollarsuperior',
  1675. 'parenleftsuperior',
  1676. 'parenrightsuperior',
  1677. 'twodotenleader',
  1678. 'onedotenleader',
  1679. 'comma',
  1680. 'hyphen',
  1681. 'period',
  1682. 'fraction',
  1683. 'zerooldstyle',
  1684. 'oneoldstyle',
  1685. 'twooldstyle',
  1686. 'threeoldstyle',
  1687. 'fouroldstyle',
  1688. 'fiveoldstyle',
  1689. 'sixoldstyle',
  1690. 'sevenoldstyle',
  1691. 'eightoldstyle',
  1692. 'nineoldstyle',
  1693. 'colon',
  1694. 'semicolon',
  1695. 'commasuperior',
  1696. 'threequartersemdash',
  1697. 'periodsuperior',
  1698. 'asuperior',
  1699. 'bsuperior',
  1700. 'centsuperior',
  1701. 'dsuperior',
  1702. 'esuperior',
  1703. 'isuperior',
  1704. 'lsuperior',
  1705. 'msuperior',
  1706. 'nsuperior',
  1707. 'osuperior',
  1708. 'rsuperior',
  1709. 'ssuperior',
  1710. 'tsuperior',
  1711. 'ff',
  1712. 'fi',
  1713. 'fl',
  1714. 'ffi',
  1715. 'ffl',
  1716. 'parenleftinferior',
  1717. 'parenrightinferior',
  1718. 'hyphensuperior',
  1719. 'colonmonetary',
  1720. 'onefitted',
  1721. 'rupiah',
  1722. 'centoldstyle',
  1723. 'figuredash',
  1724. 'hypheninferior',
  1725. 'onequarter',
  1726. 'onehalf',
  1727. 'threequarters',
  1728. 'oneeighth',
  1729. 'threeeighths',
  1730. 'fiveeighths',
  1731. 'seveneighths',
  1732. 'onethird',
  1733. 'twothirds',
  1734. 'zerosuperior',
  1735. 'onesuperior',
  1736. 'twosuperior',
  1737. 'threesuperior',
  1738. 'foursuperior',
  1739. 'fivesuperior',
  1740. 'sixsuperior',
  1741. 'sevensuperior',
  1742. 'eightsuperior',
  1743. 'ninesuperior',
  1744. 'zeroinferior',
  1745. 'oneinferior',
  1746. 'twoinferior',
  1747. 'threeinferior',
  1748. 'fourinferior',
  1749. 'fiveinferior',
  1750. 'sixinferior',
  1751. 'seveninferior',
  1752. 'eightinferior',
  1753. 'nineinferior',
  1754. 'centinferior',
  1755. 'dollarinferior',
  1756. 'periodinferior',
  1757. 'commainferior'
  1758. ];
  1759. exports.ISOAdobeCharset = ISOAdobeCharset;
  1760. exports.ExpertCharset = ExpertCharset;
  1761. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  1762. }));
  1763. (function (root, factory) {
  1764. factory(root.pdfjsCoreEncodings = {});
  1765. }(this, function (exports) {
  1766. var ExpertEncoding = [
  1767. '',
  1768. '',
  1769. '',
  1770. '',
  1771. '',
  1772. '',
  1773. '',
  1774. '',
  1775. '',
  1776. '',
  1777. '',
  1778. '',
  1779. '',
  1780. '',
  1781. '',
  1782. '',
  1783. '',
  1784. '',
  1785. '',
  1786. '',
  1787. '',
  1788. '',
  1789. '',
  1790. '',
  1791. '',
  1792. '',
  1793. '',
  1794. '',
  1795. '',
  1796. '',
  1797. '',
  1798. '',
  1799. 'space',
  1800. 'exclamsmall',
  1801. 'Hungarumlautsmall',
  1802. '',
  1803. 'dollaroldstyle',
  1804. 'dollarsuperior',
  1805. 'ampersandsmall',
  1806. 'Acutesmall',
  1807. 'parenleftsuperior',
  1808. 'parenrightsuperior',
  1809. 'twodotenleader',
  1810. 'onedotenleader',
  1811. 'comma',
  1812. 'hyphen',
  1813. 'period',
  1814. 'fraction',
  1815. 'zerooldstyle',
  1816. 'oneoldstyle',
  1817. 'twooldstyle',
  1818. 'threeoldstyle',
  1819. 'fouroldstyle',
  1820. 'fiveoldstyle',
  1821. 'sixoldstyle',
  1822. 'sevenoldstyle',
  1823. 'eightoldstyle',
  1824. 'nineoldstyle',
  1825. 'colon',
  1826. 'semicolon',
  1827. 'commasuperior',
  1828. 'threequartersemdash',
  1829. 'periodsuperior',
  1830. 'questionsmall',
  1831. '',
  1832. 'asuperior',
  1833. 'bsuperior',
  1834. 'centsuperior',
  1835. 'dsuperior',
  1836. 'esuperior',
  1837. '',
  1838. '',
  1839. 'isuperior',
  1840. '',
  1841. '',
  1842. 'lsuperior',
  1843. 'msuperior',
  1844. 'nsuperior',
  1845. 'osuperior',
  1846. '',
  1847. '',
  1848. 'rsuperior',
  1849. 'ssuperior',
  1850. 'tsuperior',
  1851. '',
  1852. 'ff',
  1853. 'fi',
  1854. 'fl',
  1855. 'ffi',
  1856. 'ffl',
  1857. 'parenleftinferior',
  1858. '',
  1859. 'parenrightinferior',
  1860. 'Circumflexsmall',
  1861. 'hyphensuperior',
  1862. 'Gravesmall',
  1863. 'Asmall',
  1864. 'Bsmall',
  1865. 'Csmall',
  1866. 'Dsmall',
  1867. 'Esmall',
  1868. 'Fsmall',
  1869. 'Gsmall',
  1870. 'Hsmall',
  1871. 'Ismall',
  1872. 'Jsmall',
  1873. 'Ksmall',
  1874. 'Lsmall',
  1875. 'Msmall',
  1876. 'Nsmall',
  1877. 'Osmall',
  1878. 'Psmall',
  1879. 'Qsmall',
  1880. 'Rsmall',
  1881. 'Ssmall',
  1882. 'Tsmall',
  1883. 'Usmall',
  1884. 'Vsmall',
  1885. 'Wsmall',
  1886. 'Xsmall',
  1887. 'Ysmall',
  1888. 'Zsmall',
  1889. 'colonmonetary',
  1890. 'onefitted',
  1891. 'rupiah',
  1892. 'Tildesmall',
  1893. '',
  1894. '',
  1895. '',
  1896. '',
  1897. '',
  1898. '',
  1899. '',
  1900. '',
  1901. '',
  1902. '',
  1903. '',
  1904. '',
  1905. '',
  1906. '',
  1907. '',
  1908. '',
  1909. '',
  1910. '',
  1911. '',
  1912. '',
  1913. '',
  1914. '',
  1915. '',
  1916. '',
  1917. '',
  1918. '',
  1919. '',
  1920. '',
  1921. '',
  1922. '',
  1923. '',
  1924. '',
  1925. '',
  1926. '',
  1927. 'exclamdownsmall',
  1928. 'centoldstyle',
  1929. 'Lslashsmall',
  1930. '',
  1931. '',
  1932. 'Scaronsmall',
  1933. 'Zcaronsmall',
  1934. 'Dieresissmall',
  1935. 'Brevesmall',
  1936. 'Caronsmall',
  1937. '',
  1938. 'Dotaccentsmall',
  1939. '',
  1940. '',
  1941. 'Macronsmall',
  1942. '',
  1943. '',
  1944. 'figuredash',
  1945. 'hypheninferior',
  1946. '',
  1947. '',
  1948. 'Ogoneksmall',
  1949. 'Ringsmall',
  1950. 'Cedillasmall',
  1951. '',
  1952. '',
  1953. '',
  1954. 'onequarter',
  1955. 'onehalf',
  1956. 'threequarters',
  1957. 'questiondownsmall',
  1958. 'oneeighth',
  1959. 'threeeighths',
  1960. 'fiveeighths',
  1961. 'seveneighths',
  1962. 'onethird',
  1963. 'twothirds',
  1964. '',
  1965. '',
  1966. 'zerosuperior',
  1967. 'onesuperior',
  1968. 'twosuperior',
  1969. 'threesuperior',
  1970. 'foursuperior',
  1971. 'fivesuperior',
  1972. 'sixsuperior',
  1973. 'sevensuperior',
  1974. 'eightsuperior',
  1975. 'ninesuperior',
  1976. 'zeroinferior',
  1977. 'oneinferior',
  1978. 'twoinferior',
  1979. 'threeinferior',
  1980. 'fourinferior',
  1981. 'fiveinferior',
  1982. 'sixinferior',
  1983. 'seveninferior',
  1984. 'eightinferior',
  1985. 'nineinferior',
  1986. 'centinferior',
  1987. 'dollarinferior',
  1988. 'periodinferior',
  1989. 'commainferior',
  1990. 'Agravesmall',
  1991. 'Aacutesmall',
  1992. 'Acircumflexsmall',
  1993. 'Atildesmall',
  1994. 'Adieresissmall',
  1995. 'Aringsmall',
  1996. 'AEsmall',
  1997. 'Ccedillasmall',
  1998. 'Egravesmall',
  1999. 'Eacutesmall',
  2000. 'Ecircumflexsmall',
  2001. 'Edieresissmall',
  2002. 'Igravesmall',
  2003. 'Iacutesmall',
  2004. 'Icircumflexsmall',
  2005. 'Idieresissmall',
  2006. 'Ethsmall',
  2007. 'Ntildesmall',
  2008. 'Ogravesmall',
  2009. 'Oacutesmall',
  2010. 'Ocircumflexsmall',
  2011. 'Otildesmall',
  2012. 'Odieresissmall',
  2013. 'OEsmall',
  2014. 'Oslashsmall',
  2015. 'Ugravesmall',
  2016. 'Uacutesmall',
  2017. 'Ucircumflexsmall',
  2018. 'Udieresissmall',
  2019. 'Yacutesmall',
  2020. 'Thornsmall',
  2021. 'Ydieresissmall'
  2022. ];
  2023. var MacExpertEncoding = [
  2024. '',
  2025. '',
  2026. '',
  2027. '',
  2028. '',
  2029. '',
  2030. '',
  2031. '',
  2032. '',
  2033. '',
  2034. '',
  2035. '',
  2036. '',
  2037. '',
  2038. '',
  2039. '',
  2040. '',
  2041. '',
  2042. '',
  2043. '',
  2044. '',
  2045. '',
  2046. '',
  2047. '',
  2048. '',
  2049. '',
  2050. '',
  2051. '',
  2052. '',
  2053. '',
  2054. '',
  2055. '',
  2056. 'space',
  2057. 'exclamsmall',
  2058. 'Hungarumlautsmall',
  2059. 'centoldstyle',
  2060. 'dollaroldstyle',
  2061. 'dollarsuperior',
  2062. 'ampersandsmall',
  2063. 'Acutesmall',
  2064. 'parenleftsuperior',
  2065. 'parenrightsuperior',
  2066. 'twodotenleader',
  2067. 'onedotenleader',
  2068. 'comma',
  2069. 'hyphen',
  2070. 'period',
  2071. 'fraction',
  2072. 'zerooldstyle',
  2073. 'oneoldstyle',
  2074. 'twooldstyle',
  2075. 'threeoldstyle',
  2076. 'fouroldstyle',
  2077. 'fiveoldstyle',
  2078. 'sixoldstyle',
  2079. 'sevenoldstyle',
  2080. 'eightoldstyle',
  2081. 'nineoldstyle',
  2082. 'colon',
  2083. 'semicolon',
  2084. '',
  2085. 'threequartersemdash',
  2086. '',
  2087. 'questionsmall',
  2088. '',
  2089. '',
  2090. '',
  2091. '',
  2092. 'Ethsmall',
  2093. '',
  2094. '',
  2095. 'onequarter',
  2096. 'onehalf',
  2097. 'threequarters',
  2098. 'oneeighth',
  2099. 'threeeighths',
  2100. 'fiveeighths',
  2101. 'seveneighths',
  2102. 'onethird',
  2103. 'twothirds',
  2104. '',
  2105. '',
  2106. '',
  2107. '',
  2108. '',
  2109. '',
  2110. 'ff',
  2111. 'fi',
  2112. 'fl',
  2113. 'ffi',
  2114. 'ffl',
  2115. 'parenleftinferior',
  2116. '',
  2117. 'parenrightinferior',
  2118. 'Circumflexsmall',
  2119. 'hypheninferior',
  2120. 'Gravesmall',
  2121. 'Asmall',
  2122. 'Bsmall',
  2123. 'Csmall',
  2124. 'Dsmall',
  2125. 'Esmall',
  2126. 'Fsmall',
  2127. 'Gsmall',
  2128. 'Hsmall',
  2129. 'Ismall',
  2130. 'Jsmall',
  2131. 'Ksmall',
  2132. 'Lsmall',
  2133. 'Msmall',
  2134. 'Nsmall',
  2135. 'Osmall',
  2136. 'Psmall',
  2137. 'Qsmall',
  2138. 'Rsmall',
  2139. 'Ssmall',
  2140. 'Tsmall',
  2141. 'Usmall',
  2142. 'Vsmall',
  2143. 'Wsmall',
  2144. 'Xsmall',
  2145. 'Ysmall',
  2146. 'Zsmall',
  2147. 'colonmonetary',
  2148. 'onefitted',
  2149. 'rupiah',
  2150. 'Tildesmall',
  2151. '',
  2152. '',
  2153. 'asuperior',
  2154. 'centsuperior',
  2155. '',
  2156. '',
  2157. '',
  2158. '',
  2159. 'Aacutesmall',
  2160. 'Agravesmall',
  2161. 'Acircumflexsmall',
  2162. 'Adieresissmall',
  2163. 'Atildesmall',
  2164. 'Aringsmall',
  2165. 'Ccedillasmall',
  2166. 'Eacutesmall',
  2167. 'Egravesmall',
  2168. 'Ecircumflexsmall',
  2169. 'Edieresissmall',
  2170. 'Iacutesmall',
  2171. 'Igravesmall',
  2172. 'Icircumflexsmall',
  2173. 'Idieresissmall',
  2174. 'Ntildesmall',
  2175. 'Oacutesmall',
  2176. 'Ogravesmall',
  2177. 'Ocircumflexsmall',
  2178. 'Odieresissmall',
  2179. 'Otildesmall',
  2180. 'Uacutesmall',
  2181. 'Ugravesmall',
  2182. 'Ucircumflexsmall',
  2183. 'Udieresissmall',
  2184. '',
  2185. 'eightsuperior',
  2186. 'fourinferior',
  2187. 'threeinferior',
  2188. 'sixinferior',
  2189. 'eightinferior',
  2190. 'seveninferior',
  2191. 'Scaronsmall',
  2192. '',
  2193. 'centinferior',
  2194. 'twoinferior',
  2195. '',
  2196. 'Dieresissmall',
  2197. '',
  2198. 'Caronsmall',
  2199. 'osuperior',
  2200. 'fiveinferior',
  2201. '',
  2202. 'commainferior',
  2203. 'periodinferior',
  2204. 'Yacutesmall',
  2205. '',
  2206. 'dollarinferior',
  2207. '',
  2208. 'Thornsmall',
  2209. '',
  2210. 'nineinferior',
  2211. 'zeroinferior',
  2212. 'Zcaronsmall',
  2213. 'AEsmall',
  2214. 'Oslashsmall',
  2215. 'questiondownsmall',
  2216. 'oneinferior',
  2217. 'Lslashsmall',
  2218. '',
  2219. '',
  2220. '',
  2221. '',
  2222. '',
  2223. '',
  2224. 'Cedillasmall',
  2225. '',
  2226. '',
  2227. '',
  2228. '',
  2229. '',
  2230. 'OEsmall',
  2231. 'figuredash',
  2232. 'hyphensuperior',
  2233. '',
  2234. '',
  2235. '',
  2236. '',
  2237. 'exclamdownsmall',
  2238. '',
  2239. 'Ydieresissmall',
  2240. '',
  2241. 'onesuperior',
  2242. 'twosuperior',
  2243. 'threesuperior',
  2244. 'foursuperior',
  2245. 'fivesuperior',
  2246. 'sixsuperior',
  2247. 'sevensuperior',
  2248. 'ninesuperior',
  2249. 'zerosuperior',
  2250. '',
  2251. 'esuperior',
  2252. 'rsuperior',
  2253. 'tsuperior',
  2254. '',
  2255. '',
  2256. 'isuperior',
  2257. 'ssuperior',
  2258. 'dsuperior',
  2259. '',
  2260. '',
  2261. '',
  2262. '',
  2263. '',
  2264. 'lsuperior',
  2265. 'Ogoneksmall',
  2266. 'Brevesmall',
  2267. 'Macronsmall',
  2268. 'bsuperior',
  2269. 'nsuperior',
  2270. 'msuperior',
  2271. 'commasuperior',
  2272. 'periodsuperior',
  2273. 'Dotaccentsmall',
  2274. 'Ringsmall'
  2275. ];
  2276. var MacRomanEncoding = [
  2277. '',
  2278. '',
  2279. '',
  2280. '',
  2281. '',
  2282. '',
  2283. '',
  2284. '',
  2285. '',
  2286. '',
  2287. '',
  2288. '',
  2289. '',
  2290. '',
  2291. '',
  2292. '',
  2293. '',
  2294. '',
  2295. '',
  2296. '',
  2297. '',
  2298. '',
  2299. '',
  2300. '',
  2301. '',
  2302. '',
  2303. '',
  2304. '',
  2305. '',
  2306. '',
  2307. '',
  2308. '',
  2309. 'space',
  2310. 'exclam',
  2311. 'quotedbl',
  2312. 'numbersign',
  2313. 'dollar',
  2314. 'percent',
  2315. 'ampersand',
  2316. 'quotesingle',
  2317. 'parenleft',
  2318. 'parenright',
  2319. 'asterisk',
  2320. 'plus',
  2321. 'comma',
  2322. 'hyphen',
  2323. 'period',
  2324. 'slash',
  2325. 'zero',
  2326. 'one',
  2327. 'two',
  2328. 'three',
  2329. 'four',
  2330. 'five',
  2331. 'six',
  2332. 'seven',
  2333. 'eight',
  2334. 'nine',
  2335. 'colon',
  2336. 'semicolon',
  2337. 'less',
  2338. 'equal',
  2339. 'greater',
  2340. 'question',
  2341. 'at',
  2342. 'A',
  2343. 'B',
  2344. 'C',
  2345. 'D',
  2346. 'E',
  2347. 'F',
  2348. 'G',
  2349. 'H',
  2350. 'I',
  2351. 'J',
  2352. 'K',
  2353. 'L',
  2354. 'M',
  2355. 'N',
  2356. 'O',
  2357. 'P',
  2358. 'Q',
  2359. 'R',
  2360. 'S',
  2361. 'T',
  2362. 'U',
  2363. 'V',
  2364. 'W',
  2365. 'X',
  2366. 'Y',
  2367. 'Z',
  2368. 'bracketleft',
  2369. 'backslash',
  2370. 'bracketright',
  2371. 'asciicircum',
  2372. 'underscore',
  2373. 'grave',
  2374. 'a',
  2375. 'b',
  2376. 'c',
  2377. 'd',
  2378. 'e',
  2379. 'f',
  2380. 'g',
  2381. 'h',
  2382. 'i',
  2383. 'j',
  2384. 'k',
  2385. 'l',
  2386. 'm',
  2387. 'n',
  2388. 'o',
  2389. 'p',
  2390. 'q',
  2391. 'r',
  2392. 's',
  2393. 't',
  2394. 'u',
  2395. 'v',
  2396. 'w',
  2397. 'x',
  2398. 'y',
  2399. 'z',
  2400. 'braceleft',
  2401. 'bar',
  2402. 'braceright',
  2403. 'asciitilde',
  2404. '',
  2405. 'Adieresis',
  2406. 'Aring',
  2407. 'Ccedilla',
  2408. 'Eacute',
  2409. 'Ntilde',
  2410. 'Odieresis',
  2411. 'Udieresis',
  2412. 'aacute',
  2413. 'agrave',
  2414. 'acircumflex',
  2415. 'adieresis',
  2416. 'atilde',
  2417. 'aring',
  2418. 'ccedilla',
  2419. 'eacute',
  2420. 'egrave',
  2421. 'ecircumflex',
  2422. 'edieresis',
  2423. 'iacute',
  2424. 'igrave',
  2425. 'icircumflex',
  2426. 'idieresis',
  2427. 'ntilde',
  2428. 'oacute',
  2429. 'ograve',
  2430. 'ocircumflex',
  2431. 'odieresis',
  2432. 'otilde',
  2433. 'uacute',
  2434. 'ugrave',
  2435. 'ucircumflex',
  2436. 'udieresis',
  2437. 'dagger',
  2438. 'degree',
  2439. 'cent',
  2440. 'sterling',
  2441. 'section',
  2442. 'bullet',
  2443. 'paragraph',
  2444. 'germandbls',
  2445. 'registered',
  2446. 'copyright',
  2447. 'trademark',
  2448. 'acute',
  2449. 'dieresis',
  2450. 'notequal',
  2451. 'AE',
  2452. 'Oslash',
  2453. 'infinity',
  2454. 'plusminus',
  2455. 'lessequal',
  2456. 'greaterequal',
  2457. 'yen',
  2458. 'mu',
  2459. 'partialdiff',
  2460. 'summation',
  2461. 'product',
  2462. 'pi',
  2463. 'integral',
  2464. 'ordfeminine',
  2465. 'ordmasculine',
  2466. 'Omega',
  2467. 'ae',
  2468. 'oslash',
  2469. 'questiondown',
  2470. 'exclamdown',
  2471. 'logicalnot',
  2472. 'radical',
  2473. 'florin',
  2474. 'approxequal',
  2475. 'Delta',
  2476. 'guillemotleft',
  2477. 'guillemotright',
  2478. 'ellipsis',
  2479. 'space',
  2480. 'Agrave',
  2481. 'Atilde',
  2482. 'Otilde',
  2483. 'OE',
  2484. 'oe',
  2485. 'endash',
  2486. 'emdash',
  2487. 'quotedblleft',
  2488. 'quotedblright',
  2489. 'quoteleft',
  2490. 'quoteright',
  2491. 'divide',
  2492. 'lozenge',
  2493. 'ydieresis',
  2494. 'Ydieresis',
  2495. 'fraction',
  2496. 'currency',
  2497. 'guilsinglleft',
  2498. 'guilsinglright',
  2499. 'fi',
  2500. 'fl',
  2501. 'daggerdbl',
  2502. 'periodcentered',
  2503. 'quotesinglbase',
  2504. 'quotedblbase',
  2505. 'perthousand',
  2506. 'Acircumflex',
  2507. 'Ecircumflex',
  2508. 'Aacute',
  2509. 'Edieresis',
  2510. 'Egrave',
  2511. 'Iacute',
  2512. 'Icircumflex',
  2513. 'Idieresis',
  2514. 'Igrave',
  2515. 'Oacute',
  2516. 'Ocircumflex',
  2517. 'apple',
  2518. 'Ograve',
  2519. 'Uacute',
  2520. 'Ucircumflex',
  2521. 'Ugrave',
  2522. 'dotlessi',
  2523. 'circumflex',
  2524. 'tilde',
  2525. 'macron',
  2526. 'breve',
  2527. 'dotaccent',
  2528. 'ring',
  2529. 'cedilla',
  2530. 'hungarumlaut',
  2531. 'ogonek',
  2532. 'caron'
  2533. ];
  2534. var StandardEncoding = [
  2535. '',
  2536. '',
  2537. '',
  2538. '',
  2539. '',
  2540. '',
  2541. '',
  2542. '',
  2543. '',
  2544. '',
  2545. '',
  2546. '',
  2547. '',
  2548. '',
  2549. '',
  2550. '',
  2551. '',
  2552. '',
  2553. '',
  2554. '',
  2555. '',
  2556. '',
  2557. '',
  2558. '',
  2559. '',
  2560. '',
  2561. '',
  2562. '',
  2563. '',
  2564. '',
  2565. '',
  2566. '',
  2567. 'space',
  2568. 'exclam',
  2569. 'quotedbl',
  2570. 'numbersign',
  2571. 'dollar',
  2572. 'percent',
  2573. 'ampersand',
  2574. 'quoteright',
  2575. 'parenleft',
  2576. 'parenright',
  2577. 'asterisk',
  2578. 'plus',
  2579. 'comma',
  2580. 'hyphen',
  2581. 'period',
  2582. 'slash',
  2583. 'zero',
  2584. 'one',
  2585. 'two',
  2586. 'three',
  2587. 'four',
  2588. 'five',
  2589. 'six',
  2590. 'seven',
  2591. 'eight',
  2592. 'nine',
  2593. 'colon',
  2594. 'semicolon',
  2595. 'less',
  2596. 'equal',
  2597. 'greater',
  2598. 'question',
  2599. 'at',
  2600. 'A',
  2601. 'B',
  2602. 'C',
  2603. 'D',
  2604. 'E',
  2605. 'F',
  2606. 'G',
  2607. 'H',
  2608. 'I',
  2609. 'J',
  2610. 'K',
  2611. 'L',
  2612. 'M',
  2613. 'N',
  2614. 'O',
  2615. 'P',
  2616. 'Q',
  2617. 'R',
  2618. 'S',
  2619. 'T',
  2620. 'U',
  2621. 'V',
  2622. 'W',
  2623. 'X',
  2624. 'Y',
  2625. 'Z',
  2626. 'bracketleft',
  2627. 'backslash',
  2628. 'bracketright',
  2629. 'asciicircum',
  2630. 'underscore',
  2631. 'quoteleft',
  2632. 'a',
  2633. 'b',
  2634. 'c',
  2635. 'd',
  2636. 'e',
  2637. 'f',
  2638. 'g',
  2639. 'h',
  2640. 'i',
  2641. 'j',
  2642. 'k',
  2643. 'l',
  2644. 'm',
  2645. 'n',
  2646. 'o',
  2647. 'p',
  2648. 'q',
  2649. 'r',
  2650. 's',
  2651. 't',
  2652. 'u',
  2653. 'v',
  2654. 'w',
  2655. 'x',
  2656. 'y',
  2657. 'z',
  2658. 'braceleft',
  2659. 'bar',
  2660. 'braceright',
  2661. 'asciitilde',
  2662. '',
  2663. '',
  2664. '',
  2665. '',
  2666. '',
  2667. '',
  2668. '',
  2669. '',
  2670. '',
  2671. '',
  2672. '',
  2673. '',
  2674. '',
  2675. '',
  2676. '',
  2677. '',
  2678. '',
  2679. '',
  2680. '',
  2681. '',
  2682. '',
  2683. '',
  2684. '',
  2685. '',
  2686. '',
  2687. '',
  2688. '',
  2689. '',
  2690. '',
  2691. '',
  2692. '',
  2693. '',
  2694. '',
  2695. '',
  2696. 'exclamdown',
  2697. 'cent',
  2698. 'sterling',
  2699. 'fraction',
  2700. 'yen',
  2701. 'florin',
  2702. 'section',
  2703. 'currency',
  2704. 'quotesingle',
  2705. 'quotedblleft',
  2706. 'guillemotleft',
  2707. 'guilsinglleft',
  2708. 'guilsinglright',
  2709. 'fi',
  2710. 'fl',
  2711. '',
  2712. 'endash',
  2713. 'dagger',
  2714. 'daggerdbl',
  2715. 'periodcentered',
  2716. '',
  2717. 'paragraph',
  2718. 'bullet',
  2719. 'quotesinglbase',
  2720. 'quotedblbase',
  2721. 'quotedblright',
  2722. 'guillemotright',
  2723. 'ellipsis',
  2724. 'perthousand',
  2725. '',
  2726. 'questiondown',
  2727. '',
  2728. 'grave',
  2729. 'acute',
  2730. 'circumflex',
  2731. 'tilde',
  2732. 'macron',
  2733. 'breve',
  2734. 'dotaccent',
  2735. 'dieresis',
  2736. '',
  2737. 'ring',
  2738. 'cedilla',
  2739. '',
  2740. 'hungarumlaut',
  2741. 'ogonek',
  2742. 'caron',
  2743. 'emdash',
  2744. '',
  2745. '',
  2746. '',
  2747. '',
  2748. '',
  2749. '',
  2750. '',
  2751. '',
  2752. '',
  2753. '',
  2754. '',
  2755. '',
  2756. '',
  2757. '',
  2758. '',
  2759. '',
  2760. 'AE',
  2761. '',
  2762. 'ordfeminine',
  2763. '',
  2764. '',
  2765. '',
  2766. '',
  2767. 'Lslash',
  2768. 'Oslash',
  2769. 'OE',
  2770. 'ordmasculine',
  2771. '',
  2772. '',
  2773. '',
  2774. '',
  2775. '',
  2776. 'ae',
  2777. '',
  2778. '',
  2779. '',
  2780. 'dotlessi',
  2781. '',
  2782. '',
  2783. 'lslash',
  2784. 'oslash',
  2785. 'oe',
  2786. 'germandbls'
  2787. ];
  2788. var WinAnsiEncoding = [
  2789. '',
  2790. '',
  2791. '',
  2792. '',
  2793. '',
  2794. '',
  2795. '',
  2796. '',
  2797. '',
  2798. '',
  2799. '',
  2800. '',
  2801. '',
  2802. '',
  2803. '',
  2804. '',
  2805. '',
  2806. '',
  2807. '',
  2808. '',
  2809. '',
  2810. '',
  2811. '',
  2812. '',
  2813. '',
  2814. '',
  2815. '',
  2816. '',
  2817. '',
  2818. '',
  2819. '',
  2820. '',
  2821. 'space',
  2822. 'exclam',
  2823. 'quotedbl',
  2824. 'numbersign',
  2825. 'dollar',
  2826. 'percent',
  2827. 'ampersand',
  2828. 'quotesingle',
  2829. 'parenleft',
  2830. 'parenright',
  2831. 'asterisk',
  2832. 'plus',
  2833. 'comma',
  2834. 'hyphen',
  2835. 'period',
  2836. 'slash',
  2837. 'zero',
  2838. 'one',
  2839. 'two',
  2840. 'three',
  2841. 'four',
  2842. 'five',
  2843. 'six',
  2844. 'seven',
  2845. 'eight',
  2846. 'nine',
  2847. 'colon',
  2848. 'semicolon',
  2849. 'less',
  2850. 'equal',
  2851. 'greater',
  2852. 'question',
  2853. 'at',
  2854. 'A',
  2855. 'B',
  2856. 'C',
  2857. 'D',
  2858. 'E',
  2859. 'F',
  2860. 'G',
  2861. 'H',
  2862. 'I',
  2863. 'J',
  2864. 'K',
  2865. 'L',
  2866. 'M',
  2867. 'N',
  2868. 'O',
  2869. 'P',
  2870. 'Q',
  2871. 'R',
  2872. 'S',
  2873. 'T',
  2874. 'U',
  2875. 'V',
  2876. 'W',
  2877. 'X',
  2878. 'Y',
  2879. 'Z',
  2880. 'bracketleft',
  2881. 'backslash',
  2882. 'bracketright',
  2883. 'asciicircum',
  2884. 'underscore',
  2885. 'grave',
  2886. 'a',
  2887. 'b',
  2888. 'c',
  2889. 'd',
  2890. 'e',
  2891. 'f',
  2892. 'g',
  2893. 'h',
  2894. 'i',
  2895. 'j',
  2896. 'k',
  2897. 'l',
  2898. 'm',
  2899. 'n',
  2900. 'o',
  2901. 'p',
  2902. 'q',
  2903. 'r',
  2904. 's',
  2905. 't',
  2906. 'u',
  2907. 'v',
  2908. 'w',
  2909. 'x',
  2910. 'y',
  2911. 'z',
  2912. 'braceleft',
  2913. 'bar',
  2914. 'braceright',
  2915. 'asciitilde',
  2916. 'bullet',
  2917. 'Euro',
  2918. 'bullet',
  2919. 'quotesinglbase',
  2920. 'florin',
  2921. 'quotedblbase',
  2922. 'ellipsis',
  2923. 'dagger',
  2924. 'daggerdbl',
  2925. 'circumflex',
  2926. 'perthousand',
  2927. 'Scaron',
  2928. 'guilsinglleft',
  2929. 'OE',
  2930. 'bullet',
  2931. 'Zcaron',
  2932. 'bullet',
  2933. 'bullet',
  2934. 'quoteleft',
  2935. 'quoteright',
  2936. 'quotedblleft',
  2937. 'quotedblright',
  2938. 'bullet',
  2939. 'endash',
  2940. 'emdash',
  2941. 'tilde',
  2942. 'trademark',
  2943. 'scaron',
  2944. 'guilsinglright',
  2945. 'oe',
  2946. 'bullet',
  2947. 'zcaron',
  2948. 'Ydieresis',
  2949. 'space',
  2950. 'exclamdown',
  2951. 'cent',
  2952. 'sterling',
  2953. 'currency',
  2954. 'yen',
  2955. 'brokenbar',
  2956. 'section',
  2957. 'dieresis',
  2958. 'copyright',
  2959. 'ordfeminine',
  2960. 'guillemotleft',
  2961. 'logicalnot',
  2962. 'hyphen',
  2963. 'registered',
  2964. 'macron',
  2965. 'degree',
  2966. 'plusminus',
  2967. 'twosuperior',
  2968. 'threesuperior',
  2969. 'acute',
  2970. 'mu',
  2971. 'paragraph',
  2972. 'periodcentered',
  2973. 'cedilla',
  2974. 'onesuperior',
  2975. 'ordmasculine',
  2976. 'guillemotright',
  2977. 'onequarter',
  2978. 'onehalf',
  2979. 'threequarters',
  2980. 'questiondown',
  2981. 'Agrave',
  2982. 'Aacute',
  2983. 'Acircumflex',
  2984. 'Atilde',
  2985. 'Adieresis',
  2986. 'Aring',
  2987. 'AE',
  2988. 'Ccedilla',
  2989. 'Egrave',
  2990. 'Eacute',
  2991. 'Ecircumflex',
  2992. 'Edieresis',
  2993. 'Igrave',
  2994. 'Iacute',
  2995. 'Icircumflex',
  2996. 'Idieresis',
  2997. 'Eth',
  2998. 'Ntilde',
  2999. 'Ograve',
  3000. 'Oacute',
  3001. 'Ocircumflex',
  3002. 'Otilde',
  3003. 'Odieresis',
  3004. 'multiply',
  3005. 'Oslash',
  3006. 'Ugrave',
  3007. 'Uacute',
  3008. 'Ucircumflex',
  3009. 'Udieresis',
  3010. 'Yacute',
  3011. 'Thorn',
  3012. 'germandbls',
  3013. 'agrave',
  3014. 'aacute',
  3015. 'acircumflex',
  3016. 'atilde',
  3017. 'adieresis',
  3018. 'aring',
  3019. 'ae',
  3020. 'ccedilla',
  3021. 'egrave',
  3022. 'eacute',
  3023. 'ecircumflex',
  3024. 'edieresis',
  3025. 'igrave',
  3026. 'iacute',
  3027. 'icircumflex',
  3028. 'idieresis',
  3029. 'eth',
  3030. 'ntilde',
  3031. 'ograve',
  3032. 'oacute',
  3033. 'ocircumflex',
  3034. 'otilde',
  3035. 'odieresis',
  3036. 'divide',
  3037. 'oslash',
  3038. 'ugrave',
  3039. 'uacute',
  3040. 'ucircumflex',
  3041. 'udieresis',
  3042. 'yacute',
  3043. 'thorn',
  3044. 'ydieresis'
  3045. ];
  3046. var SymbolSetEncoding = [
  3047. '',
  3048. '',
  3049. '',
  3050. '',
  3051. '',
  3052. '',
  3053. '',
  3054. '',
  3055. '',
  3056. '',
  3057. '',
  3058. '',
  3059. '',
  3060. '',
  3061. '',
  3062. '',
  3063. '',
  3064. '',
  3065. '',
  3066. '',
  3067. '',
  3068. '',
  3069. '',
  3070. '',
  3071. '',
  3072. '',
  3073. '',
  3074. '',
  3075. '',
  3076. '',
  3077. '',
  3078. '',
  3079. 'space',
  3080. 'exclam',
  3081. 'universal',
  3082. 'numbersign',
  3083. 'existential',
  3084. 'percent',
  3085. 'ampersand',
  3086. 'suchthat',
  3087. 'parenleft',
  3088. 'parenright',
  3089. 'asteriskmath',
  3090. 'plus',
  3091. 'comma',
  3092. 'minus',
  3093. 'period',
  3094. 'slash',
  3095. 'zero',
  3096. 'one',
  3097. 'two',
  3098. 'three',
  3099. 'four',
  3100. 'five',
  3101. 'six',
  3102. 'seven',
  3103. 'eight',
  3104. 'nine',
  3105. 'colon',
  3106. 'semicolon',
  3107. 'less',
  3108. 'equal',
  3109. 'greater',
  3110. 'question',
  3111. 'congruent',
  3112. 'Alpha',
  3113. 'Beta',
  3114. 'Chi',
  3115. 'Delta',
  3116. 'Epsilon',
  3117. 'Phi',
  3118. 'Gamma',
  3119. 'Eta',
  3120. 'Iota',
  3121. 'theta1',
  3122. 'Kappa',
  3123. 'Lambda',
  3124. 'Mu',
  3125. 'Nu',
  3126. 'Omicron',
  3127. 'Pi',
  3128. 'Theta',
  3129. 'Rho',
  3130. 'Sigma',
  3131. 'Tau',
  3132. 'Upsilon',
  3133. 'sigma1',
  3134. 'Omega',
  3135. 'Xi',
  3136. 'Psi',
  3137. 'Zeta',
  3138. 'bracketleft',
  3139. 'therefore',
  3140. 'bracketright',
  3141. 'perpendicular',
  3142. 'underscore',
  3143. 'radicalex',
  3144. 'alpha',
  3145. 'beta',
  3146. 'chi',
  3147. 'delta',
  3148. 'epsilon',
  3149. 'phi',
  3150. 'gamma',
  3151. 'eta',
  3152. 'iota',
  3153. 'phi1',
  3154. 'kappa',
  3155. 'lambda',
  3156. 'mu',
  3157. 'nu',
  3158. 'omicron',
  3159. 'pi',
  3160. 'theta',
  3161. 'rho',
  3162. 'sigma',
  3163. 'tau',
  3164. 'upsilon',
  3165. 'omega1',
  3166. 'omega',
  3167. 'xi',
  3168. 'psi',
  3169. 'zeta',
  3170. 'braceleft',
  3171. 'bar',
  3172. 'braceright',
  3173. 'similar',
  3174. '',
  3175. '',
  3176. '',
  3177. '',
  3178. '',
  3179. '',
  3180. '',
  3181. '',
  3182. '',
  3183. '',
  3184. '',
  3185. '',
  3186. '',
  3187. '',
  3188. '',
  3189. '',
  3190. '',
  3191. '',
  3192. '',
  3193. '',
  3194. '',
  3195. '',
  3196. '',
  3197. '',
  3198. '',
  3199. '',
  3200. '',
  3201. '',
  3202. '',
  3203. '',
  3204. '',
  3205. '',
  3206. '',
  3207. 'Euro',
  3208. 'Upsilon1',
  3209. 'minute',
  3210. 'lessequal',
  3211. 'fraction',
  3212. 'infinity',
  3213. 'florin',
  3214. 'club',
  3215. 'diamond',
  3216. 'heart',
  3217. 'spade',
  3218. 'arrowboth',
  3219. 'arrowleft',
  3220. 'arrowup',
  3221. 'arrowright',
  3222. 'arrowdown',
  3223. 'degree',
  3224. 'plusminus',
  3225. 'second',
  3226. 'greaterequal',
  3227. 'multiply',
  3228. 'proportional',
  3229. 'partialdiff',
  3230. 'bullet',
  3231. 'divide',
  3232. 'notequal',
  3233. 'equivalence',
  3234. 'approxequal',
  3235. 'ellipsis',
  3236. 'arrowvertex',
  3237. 'arrowhorizex',
  3238. 'carriagereturn',
  3239. 'aleph',
  3240. 'Ifraktur',
  3241. 'Rfraktur',
  3242. 'weierstrass',
  3243. 'circlemultiply',
  3244. 'circleplus',
  3245. 'emptyset',
  3246. 'intersection',
  3247. 'union',
  3248. 'propersuperset',
  3249. 'reflexsuperset',
  3250. 'notsubset',
  3251. 'propersubset',
  3252. 'reflexsubset',
  3253. 'element',
  3254. 'notelement',
  3255. 'angle',
  3256. 'gradient',
  3257. 'registerserif',
  3258. 'copyrightserif',
  3259. 'trademarkserif',
  3260. 'product',
  3261. 'radical',
  3262. 'dotmath',
  3263. 'logicalnot',
  3264. 'logicaland',
  3265. 'logicalor',
  3266. 'arrowdblboth',
  3267. 'arrowdblleft',
  3268. 'arrowdblup',
  3269. 'arrowdblright',
  3270. 'arrowdbldown',
  3271. 'lozenge',
  3272. 'angleleft',
  3273. 'registersans',
  3274. 'copyrightsans',
  3275. 'trademarksans',
  3276. 'summation',
  3277. 'parenlefttp',
  3278. 'parenleftex',
  3279. 'parenleftbt',
  3280. 'bracketlefttp',
  3281. 'bracketleftex',
  3282. 'bracketleftbt',
  3283. 'bracelefttp',
  3284. 'braceleftmid',
  3285. 'braceleftbt',
  3286. 'braceex',
  3287. '',
  3288. 'angleright',
  3289. 'integral',
  3290. 'integraltp',
  3291. 'integralex',
  3292. 'integralbt',
  3293. 'parenrighttp',
  3294. 'parenrightex',
  3295. 'parenrightbt',
  3296. 'bracketrighttp',
  3297. 'bracketrightex',
  3298. 'bracketrightbt',
  3299. 'bracerighttp',
  3300. 'bracerightmid',
  3301. 'bracerightbt'
  3302. ];
  3303. var ZapfDingbatsEncoding = [
  3304. '',
  3305. '',
  3306. '',
  3307. '',
  3308. '',
  3309. '',
  3310. '',
  3311. '',
  3312. '',
  3313. '',
  3314. '',
  3315. '',
  3316. '',
  3317. '',
  3318. '',
  3319. '',
  3320. '',
  3321. '',
  3322. '',
  3323. '',
  3324. '',
  3325. '',
  3326. '',
  3327. '',
  3328. '',
  3329. '',
  3330. '',
  3331. '',
  3332. '',
  3333. '',
  3334. '',
  3335. '',
  3336. 'space',
  3337. 'a1',
  3338. 'a2',
  3339. 'a202',
  3340. 'a3',
  3341. 'a4',
  3342. 'a5',
  3343. 'a119',
  3344. 'a118',
  3345. 'a117',
  3346. 'a11',
  3347. 'a12',
  3348. 'a13',
  3349. 'a14',
  3350. 'a15',
  3351. 'a16',
  3352. 'a105',
  3353. 'a17',
  3354. 'a18',
  3355. 'a19',
  3356. 'a20',
  3357. 'a21',
  3358. 'a22',
  3359. 'a23',
  3360. 'a24',
  3361. 'a25',
  3362. 'a26',
  3363. 'a27',
  3364. 'a28',
  3365. 'a6',
  3366. 'a7',
  3367. 'a8',
  3368. 'a9',
  3369. 'a10',
  3370. 'a29',
  3371. 'a30',
  3372. 'a31',
  3373. 'a32',
  3374. 'a33',
  3375. 'a34',
  3376. 'a35',
  3377. 'a36',
  3378. 'a37',
  3379. 'a38',
  3380. 'a39',
  3381. 'a40',
  3382. 'a41',
  3383. 'a42',
  3384. 'a43',
  3385. 'a44',
  3386. 'a45',
  3387. 'a46',
  3388. 'a47',
  3389. 'a48',
  3390. 'a49',
  3391. 'a50',
  3392. 'a51',
  3393. 'a52',
  3394. 'a53',
  3395. 'a54',
  3396. 'a55',
  3397. 'a56',
  3398. 'a57',
  3399. 'a58',
  3400. 'a59',
  3401. 'a60',
  3402. 'a61',
  3403. 'a62',
  3404. 'a63',
  3405. 'a64',
  3406. 'a65',
  3407. 'a66',
  3408. 'a67',
  3409. 'a68',
  3410. 'a69',
  3411. 'a70',
  3412. 'a71',
  3413. 'a72',
  3414. 'a73',
  3415. 'a74',
  3416. 'a203',
  3417. 'a75',
  3418. 'a204',
  3419. 'a76',
  3420. 'a77',
  3421. 'a78',
  3422. 'a79',
  3423. 'a81',
  3424. 'a82',
  3425. 'a83',
  3426. 'a84',
  3427. 'a97',
  3428. 'a98',
  3429. 'a99',
  3430. 'a100',
  3431. '',
  3432. 'a89',
  3433. 'a90',
  3434. 'a93',
  3435. 'a94',
  3436. 'a91',
  3437. 'a92',
  3438. 'a205',
  3439. 'a85',
  3440. 'a206',
  3441. 'a86',
  3442. 'a87',
  3443. 'a88',
  3444. 'a95',
  3445. 'a96',
  3446. '',
  3447. '',
  3448. '',
  3449. '',
  3450. '',
  3451. '',
  3452. '',
  3453. '',
  3454. '',
  3455. '',
  3456. '',
  3457. '',
  3458. '',
  3459. '',
  3460. '',
  3461. '',
  3462. '',
  3463. '',
  3464. '',
  3465. 'a101',
  3466. 'a102',
  3467. 'a103',
  3468. 'a104',
  3469. 'a106',
  3470. 'a107',
  3471. 'a108',
  3472. 'a112',
  3473. 'a111',
  3474. 'a110',
  3475. 'a109',
  3476. 'a120',
  3477. 'a121',
  3478. 'a122',
  3479. 'a123',
  3480. 'a124',
  3481. 'a125',
  3482. 'a126',
  3483. 'a127',
  3484. 'a128',
  3485. 'a129',
  3486. 'a130',
  3487. 'a131',
  3488. 'a132',
  3489. 'a133',
  3490. 'a134',
  3491. 'a135',
  3492. 'a136',
  3493. 'a137',
  3494. 'a138',
  3495. 'a139',
  3496. 'a140',
  3497. 'a141',
  3498. 'a142',
  3499. 'a143',
  3500. 'a144',
  3501. 'a145',
  3502. 'a146',
  3503. 'a147',
  3504. 'a148',
  3505. 'a149',
  3506. 'a150',
  3507. 'a151',
  3508. 'a152',
  3509. 'a153',
  3510. 'a154',
  3511. 'a155',
  3512. 'a156',
  3513. 'a157',
  3514. 'a158',
  3515. 'a159',
  3516. 'a160',
  3517. 'a161',
  3518. 'a163',
  3519. 'a164',
  3520. 'a196',
  3521. 'a165',
  3522. 'a192',
  3523. 'a166',
  3524. 'a167',
  3525. 'a168',
  3526. 'a169',
  3527. 'a170',
  3528. 'a171',
  3529. 'a172',
  3530. 'a173',
  3531. 'a162',
  3532. 'a174',
  3533. 'a175',
  3534. 'a176',
  3535. 'a177',
  3536. 'a178',
  3537. 'a179',
  3538. 'a193',
  3539. 'a180',
  3540. 'a199',
  3541. 'a181',
  3542. 'a200',
  3543. 'a182',
  3544. '',
  3545. 'a201',
  3546. 'a183',
  3547. 'a184',
  3548. 'a197',
  3549. 'a185',
  3550. 'a194',
  3551. 'a198',
  3552. 'a186',
  3553. 'a195',
  3554. 'a187',
  3555. 'a188',
  3556. 'a189',
  3557. 'a190',
  3558. 'a191'
  3559. ];
  3560. function getEncoding(encodingName) {
  3561. switch (encodingName) {
  3562. case 'WinAnsiEncoding':
  3563. return WinAnsiEncoding;
  3564. case 'StandardEncoding':
  3565. return StandardEncoding;
  3566. case 'MacRomanEncoding':
  3567. return MacRomanEncoding;
  3568. case 'SymbolSetEncoding':
  3569. return SymbolSetEncoding;
  3570. case 'ZapfDingbatsEncoding':
  3571. return ZapfDingbatsEncoding;
  3572. case 'ExpertEncoding':
  3573. return ExpertEncoding;
  3574. case 'MacExpertEncoding':
  3575. return MacExpertEncoding;
  3576. default:
  3577. return null;
  3578. }
  3579. }
  3580. exports.WinAnsiEncoding = WinAnsiEncoding;
  3581. exports.StandardEncoding = StandardEncoding;
  3582. exports.MacRomanEncoding = MacRomanEncoding;
  3583. exports.SymbolSetEncoding = SymbolSetEncoding;
  3584. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  3585. exports.ExpertEncoding = ExpertEncoding;
  3586. exports.getEncoding = getEncoding;
  3587. }));
  3588. (function (root, factory) {
  3589. factory(root.pdfjsSharedUtil = {});
  3590. }(this, function (exports) {
  3591. var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this;
  3592. var FONT_IDENTITY_MATRIX = [
  3593. 0.001,
  3594. 0,
  3595. 0,
  3596. 0.001,
  3597. 0,
  3598. 0
  3599. ];
  3600. var TextRenderingMode = {
  3601. FILL: 0,
  3602. STROKE: 1,
  3603. FILL_STROKE: 2,
  3604. INVISIBLE: 3,
  3605. FILL_ADD_TO_PATH: 4,
  3606. STROKE_ADD_TO_PATH: 5,
  3607. FILL_STROKE_ADD_TO_PATH: 6,
  3608. ADD_TO_PATH: 7,
  3609. FILL_STROKE_MASK: 3,
  3610. ADD_TO_PATH_FLAG: 4
  3611. };
  3612. var ImageKind = {
  3613. GRAYSCALE_1BPP: 1,
  3614. RGB_24BPP: 2,
  3615. RGBA_32BPP: 3
  3616. };
  3617. var AnnotationType = {
  3618. TEXT: 1,
  3619. LINK: 2,
  3620. FREETEXT: 3,
  3621. LINE: 4,
  3622. SQUARE: 5,
  3623. CIRCLE: 6,
  3624. POLYGON: 7,
  3625. POLYLINE: 8,
  3626. HIGHLIGHT: 9,
  3627. UNDERLINE: 10,
  3628. SQUIGGLY: 11,
  3629. STRIKEOUT: 12,
  3630. STAMP: 13,
  3631. CARET: 14,
  3632. INK: 15,
  3633. POPUP: 16,
  3634. FILEATTACHMENT: 17,
  3635. SOUND: 18,
  3636. MOVIE: 19,
  3637. WIDGET: 20,
  3638. SCREEN: 21,
  3639. PRINTERMARK: 22,
  3640. TRAPNET: 23,
  3641. WATERMARK: 24,
  3642. THREED: 25,
  3643. REDACT: 26
  3644. };
  3645. var AnnotationFlag = {
  3646. INVISIBLE: 0x01,
  3647. HIDDEN: 0x02,
  3648. PRINT: 0x04,
  3649. NOZOOM: 0x08,
  3650. NOROTATE: 0x10,
  3651. NOVIEW: 0x20,
  3652. READONLY: 0x40,
  3653. LOCKED: 0x80,
  3654. TOGGLENOVIEW: 0x100,
  3655. LOCKEDCONTENTS: 0x200
  3656. };
  3657. var AnnotationFieldFlag = {
  3658. READONLY: 0x0000001,
  3659. REQUIRED: 0x0000002,
  3660. NOEXPORT: 0x0000004,
  3661. MULTILINE: 0x0001000,
  3662. PASSWORD: 0x0002000,
  3663. NOTOGGLETOOFF: 0x0004000,
  3664. RADIO: 0x0008000,
  3665. PUSHBUTTON: 0x0010000,
  3666. COMBO: 0x0020000,
  3667. EDIT: 0x0040000,
  3668. SORT: 0x0080000,
  3669. FILESELECT: 0x0100000,
  3670. MULTISELECT: 0x0200000,
  3671. DONOTSPELLCHECK: 0x0400000,
  3672. DONOTSCROLL: 0x0800000,
  3673. COMB: 0x1000000,
  3674. RICHTEXT: 0x2000000,
  3675. RADIOSINUNISON: 0x2000000,
  3676. COMMITONSELCHANGE: 0x4000000
  3677. };
  3678. var AnnotationBorderStyleType = {
  3679. SOLID: 1,
  3680. DASHED: 2,
  3681. BEVELED: 3,
  3682. INSET: 4,
  3683. UNDERLINE: 5
  3684. };
  3685. var StreamType = {
  3686. UNKNOWN: 0,
  3687. FLATE: 1,
  3688. LZW: 2,
  3689. DCT: 3,
  3690. JPX: 4,
  3691. JBIG: 5,
  3692. A85: 6,
  3693. AHX: 7,
  3694. CCF: 8,
  3695. RL: 9
  3696. };
  3697. var FontType = {
  3698. UNKNOWN: 0,
  3699. TYPE1: 1,
  3700. TYPE1C: 2,
  3701. CIDFONTTYPE0: 3,
  3702. CIDFONTTYPE0C: 4,
  3703. TRUETYPE: 5,
  3704. CIDFONTTYPE2: 6,
  3705. TYPE3: 7,
  3706. OPENTYPE: 8,
  3707. TYPE0: 9,
  3708. MMTYPE1: 10
  3709. };
  3710. var VERBOSITY_LEVELS = {
  3711. errors: 0,
  3712. warnings: 1,
  3713. infos: 5
  3714. };
  3715. // All the possible operations for an operator list.
  3716. var OPS = {
  3717. // Intentionally start from 1 so it is easy to spot bad operators that will be
  3718. // 0's.
  3719. dependency: 1,
  3720. setLineWidth: 2,
  3721. setLineCap: 3,
  3722. setLineJoin: 4,
  3723. setMiterLimit: 5,
  3724. setDash: 6,
  3725. setRenderingIntent: 7,
  3726. setFlatness: 8,
  3727. setGState: 9,
  3728. save: 10,
  3729. restore: 11,
  3730. transform: 12,
  3731. moveTo: 13,
  3732. lineTo: 14,
  3733. curveTo: 15,
  3734. curveTo2: 16,
  3735. curveTo3: 17,
  3736. closePath: 18,
  3737. rectangle: 19,
  3738. stroke: 20,
  3739. closeStroke: 21,
  3740. fill: 22,
  3741. eoFill: 23,
  3742. fillStroke: 24,
  3743. eoFillStroke: 25,
  3744. closeFillStroke: 26,
  3745. closeEOFillStroke: 27,
  3746. endPath: 28,
  3747. clip: 29,
  3748. eoClip: 30,
  3749. beginText: 31,
  3750. endText: 32,
  3751. setCharSpacing: 33,
  3752. setWordSpacing: 34,
  3753. setHScale: 35,
  3754. setLeading: 36,
  3755. setFont: 37,
  3756. setTextRenderingMode: 38,
  3757. setTextRise: 39,
  3758. moveText: 40,
  3759. setLeadingMoveText: 41,
  3760. setTextMatrix: 42,
  3761. nextLine: 43,
  3762. showText: 44,
  3763. showSpacedText: 45,
  3764. nextLineShowText: 46,
  3765. nextLineSetSpacingShowText: 47,
  3766. setCharWidth: 48,
  3767. setCharWidthAndBounds: 49,
  3768. setStrokeColorSpace: 50,
  3769. setFillColorSpace: 51,
  3770. setStrokeColor: 52,
  3771. setStrokeColorN: 53,
  3772. setFillColor: 54,
  3773. setFillColorN: 55,
  3774. setStrokeGray: 56,
  3775. setFillGray: 57,
  3776. setStrokeRGBColor: 58,
  3777. setFillRGBColor: 59,
  3778. setStrokeCMYKColor: 60,
  3779. setFillCMYKColor: 61,
  3780. shadingFill: 62,
  3781. beginInlineImage: 63,
  3782. beginImageData: 64,
  3783. endInlineImage: 65,
  3784. paintXObject: 66,
  3785. markPoint: 67,
  3786. markPointProps: 68,
  3787. beginMarkedContent: 69,
  3788. beginMarkedContentProps: 70,
  3789. endMarkedContent: 71,
  3790. beginCompat: 72,
  3791. endCompat: 73,
  3792. paintFormXObjectBegin: 74,
  3793. paintFormXObjectEnd: 75,
  3794. beginGroup: 76,
  3795. endGroup: 77,
  3796. beginAnnotations: 78,
  3797. endAnnotations: 79,
  3798. beginAnnotation: 80,
  3799. endAnnotation: 81,
  3800. paintJpegXObject: 82,
  3801. paintImageMaskXObject: 83,
  3802. paintImageMaskXObjectGroup: 84,
  3803. paintImageXObject: 85,
  3804. paintInlineImageXObject: 86,
  3805. paintInlineImageXObjectGroup: 87,
  3806. paintImageXObjectRepeat: 88,
  3807. paintImageMaskXObjectRepeat: 89,
  3808. paintSolidColorImageMask: 90,
  3809. constructPath: 91
  3810. };
  3811. var verbosity = VERBOSITY_LEVELS.warnings;
  3812. function setVerbosityLevel(level) {
  3813. verbosity = level;
  3814. }
  3815. function getVerbosityLevel() {
  3816. return verbosity;
  3817. }
  3818. // A notice for devs. These are good for things that are helpful to devs, such
  3819. // as warning that Workers were disabled, which is important to devs but not
  3820. // end users.
  3821. function info(msg) {
  3822. if (verbosity >= VERBOSITY_LEVELS.infos) {
  3823. console.log('Info: ' + msg);
  3824. }
  3825. }
  3826. // Non-fatal warnings.
  3827. function warn(msg) {
  3828. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  3829. console.log('Warning: ' + msg);
  3830. }
  3831. }
  3832. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  3833. function deprecated(details) {
  3834. console.log('Deprecated API usage: ' + details);
  3835. }
  3836. // Fatal errors that should trigger the fallback UI and halt execution by
  3837. // throwing an exception.
  3838. function error(msg) {
  3839. if (verbosity >= VERBOSITY_LEVELS.errors) {
  3840. console.log('Error: ' + msg);
  3841. console.log(backtrace());
  3842. }
  3843. throw new Error(msg);
  3844. }
  3845. function backtrace() {
  3846. try {
  3847. throw new Error();
  3848. } catch (e) {
  3849. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  3850. }
  3851. }
  3852. function assert(cond, msg) {
  3853. if (!cond) {
  3854. error(msg);
  3855. }
  3856. }
  3857. var UNSUPPORTED_FEATURES = {
  3858. unknown: 'unknown',
  3859. forms: 'forms',
  3860. javaScript: 'javaScript',
  3861. smask: 'smask',
  3862. shadingPattern: 'shadingPattern',
  3863. font: 'font'
  3864. };
  3865. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  3866. function isSameOrigin(baseUrl, otherUrl) {
  3867. try {
  3868. var base = new URL(baseUrl);
  3869. if (!base.origin || base.origin === 'null') {
  3870. return false;
  3871. }
  3872. } // non-HTTP url
  3873. catch (e) {
  3874. return false;
  3875. }
  3876. var other = new URL(otherUrl, base);
  3877. return base.origin === other.origin;
  3878. }
  3879. // Checks if URLs use one of the whitelisted protocols, e.g. to avoid XSS.
  3880. function isValidProtocol(url) {
  3881. if (!url) {
  3882. return false;
  3883. }
  3884. switch (url.protocol) {
  3885. case 'http:':
  3886. case 'https:':
  3887. case 'ftp:':
  3888. case 'mailto:':
  3889. case 'tel:':
  3890. return true;
  3891. default:
  3892. return false;
  3893. }
  3894. }
  3895. /**
  3896. * Attempts to create a valid absolute URL (utilizing `isValidProtocol`).
  3897. * @param {URL|string} url - An absolute, or relative, URL.
  3898. * @param {URL|string} baseUrl - An absolute URL.
  3899. * @returns Either a valid {URL}, or `null` otherwise.
  3900. */
  3901. function createValidAbsoluteUrl(url, baseUrl) {
  3902. if (!url) {
  3903. return null;
  3904. }
  3905. try {
  3906. var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  3907. if (isValidProtocol(absoluteUrl)) {
  3908. return absoluteUrl;
  3909. }
  3910. } catch (ex) {
  3911. }
  3912. return null;
  3913. }
  3914. function shadow(obj, prop, value) {
  3915. Object.defineProperty(obj, prop, {
  3916. value: value,
  3917. enumerable: true,
  3918. configurable: true,
  3919. writable: false
  3920. });
  3921. return value;
  3922. }
  3923. function getLookupTableFactory(initializer) {
  3924. var lookup;
  3925. return function () {
  3926. if (initializer) {
  3927. lookup = Object.create(null);
  3928. initializer(lookup);
  3929. initializer = null;
  3930. }
  3931. return lookup;
  3932. };
  3933. }
  3934. var PasswordResponses = {
  3935. NEED_PASSWORD: 1,
  3936. INCORRECT_PASSWORD: 2
  3937. };
  3938. var PasswordException = function PasswordExceptionClosure() {
  3939. function PasswordException(msg, code) {
  3940. this.name = 'PasswordException';
  3941. this.message = msg;
  3942. this.code = code;
  3943. }
  3944. PasswordException.prototype = new Error();
  3945. PasswordException.constructor = PasswordException;
  3946. return PasswordException;
  3947. }();
  3948. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  3949. function UnknownErrorException(msg, details) {
  3950. this.name = 'UnknownErrorException';
  3951. this.message = msg;
  3952. this.details = details;
  3953. }
  3954. UnknownErrorException.prototype = new Error();
  3955. UnknownErrorException.constructor = UnknownErrorException;
  3956. return UnknownErrorException;
  3957. }();
  3958. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  3959. function InvalidPDFException(msg) {
  3960. this.name = 'InvalidPDFException';
  3961. this.message = msg;
  3962. }
  3963. InvalidPDFException.prototype = new Error();
  3964. InvalidPDFException.constructor = InvalidPDFException;
  3965. return InvalidPDFException;
  3966. }();
  3967. var MissingPDFException = function MissingPDFExceptionClosure() {
  3968. function MissingPDFException(msg) {
  3969. this.name = 'MissingPDFException';
  3970. this.message = msg;
  3971. }
  3972. MissingPDFException.prototype = new Error();
  3973. MissingPDFException.constructor = MissingPDFException;
  3974. return MissingPDFException;
  3975. }();
  3976. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  3977. function UnexpectedResponseException(msg, status) {
  3978. this.name = 'UnexpectedResponseException';
  3979. this.message = msg;
  3980. this.status = status;
  3981. }
  3982. UnexpectedResponseException.prototype = new Error();
  3983. UnexpectedResponseException.constructor = UnexpectedResponseException;
  3984. return UnexpectedResponseException;
  3985. }();
  3986. var NotImplementedException = function NotImplementedExceptionClosure() {
  3987. function NotImplementedException(msg) {
  3988. this.message = msg;
  3989. }
  3990. NotImplementedException.prototype = new Error();
  3991. NotImplementedException.prototype.name = 'NotImplementedException';
  3992. NotImplementedException.constructor = NotImplementedException;
  3993. return NotImplementedException;
  3994. }();
  3995. var MissingDataException = function MissingDataExceptionClosure() {
  3996. function MissingDataException(begin, end) {
  3997. this.begin = begin;
  3998. this.end = end;
  3999. this.message = 'Missing data [' + begin + ', ' + end + ')';
  4000. }
  4001. MissingDataException.prototype = new Error();
  4002. MissingDataException.prototype.name = 'MissingDataException';
  4003. MissingDataException.constructor = MissingDataException;
  4004. return MissingDataException;
  4005. }();
  4006. var XRefParseException = function XRefParseExceptionClosure() {
  4007. function XRefParseException(msg) {
  4008. this.message = msg;
  4009. }
  4010. XRefParseException.prototype = new Error();
  4011. XRefParseException.prototype.name = 'XRefParseException';
  4012. XRefParseException.constructor = XRefParseException;
  4013. return XRefParseException;
  4014. }();
  4015. var NullCharactersRegExp = /\x00/g;
  4016. function removeNullCharacters(str) {
  4017. if (typeof str !== 'string') {
  4018. warn('The argument for removeNullCharacters must be a string.');
  4019. return str;
  4020. }
  4021. return str.replace(NullCharactersRegExp, '');
  4022. }
  4023. function bytesToString(bytes) {
  4024. assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  4025. var length = bytes.length;
  4026. var MAX_ARGUMENT_COUNT = 8192;
  4027. if (length < MAX_ARGUMENT_COUNT) {
  4028. return String.fromCharCode.apply(null, bytes);
  4029. }
  4030. var strBuf = [];
  4031. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  4032. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  4033. var chunk = bytes.subarray(i, chunkEnd);
  4034. strBuf.push(String.fromCharCode.apply(null, chunk));
  4035. }
  4036. return strBuf.join('');
  4037. }
  4038. function stringToBytes(str) {
  4039. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  4040. var length = str.length;
  4041. var bytes = new Uint8Array(length);
  4042. for (var i = 0; i < length; ++i) {
  4043. bytes[i] = str.charCodeAt(i) & 0xFF;
  4044. }
  4045. return bytes;
  4046. }
  4047. /**
  4048. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  4049. * @param {Array|Uint8Array|string} arr
  4050. * @returns {number}
  4051. */
  4052. function arrayByteLength(arr) {
  4053. if (arr.length !== undefined) {
  4054. return arr.length;
  4055. }
  4056. assert(arr.byteLength !== undefined);
  4057. return arr.byteLength;
  4058. }
  4059. /**
  4060. * Combines array items (arrays) into single Uint8Array object.
  4061. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  4062. * @returns {Uint8Array}
  4063. */
  4064. function arraysToBytes(arr) {
  4065. // Shortcut: if first and only item is Uint8Array, return it.
  4066. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  4067. return arr[0];
  4068. }
  4069. var resultLength = 0;
  4070. var i, ii = arr.length;
  4071. var item, itemLength;
  4072. for (i = 0; i < ii; i++) {
  4073. item = arr[i];
  4074. itemLength = arrayByteLength(item);
  4075. resultLength += itemLength;
  4076. }
  4077. var pos = 0;
  4078. var data = new Uint8Array(resultLength);
  4079. for (i = 0; i < ii; i++) {
  4080. item = arr[i];
  4081. if (!(item instanceof Uint8Array)) {
  4082. if (typeof item === 'string') {
  4083. item = stringToBytes(item);
  4084. } else {
  4085. item = new Uint8Array(item);
  4086. }
  4087. }
  4088. itemLength = item.byteLength;
  4089. data.set(item, pos);
  4090. pos += itemLength;
  4091. }
  4092. return data;
  4093. }
  4094. function string32(value) {
  4095. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  4096. }
  4097. function log2(x) {
  4098. var n = 1, i = 0;
  4099. while (x > n) {
  4100. n <<= 1;
  4101. i++;
  4102. }
  4103. return i;
  4104. }
  4105. function readInt8(data, start) {
  4106. return data[start] << 24 >> 24;
  4107. }
  4108. function readUint16(data, offset) {
  4109. return data[offset] << 8 | data[offset + 1];
  4110. }
  4111. function readUint32(data, offset) {
  4112. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  4113. }
  4114. // Lazy test the endianness of the platform
  4115. // NOTE: This will be 'true' for simulated TypedArrays
  4116. function isLittleEndian() {
  4117. var buffer8 = new Uint8Array(2);
  4118. buffer8[0] = 1;
  4119. var buffer16 = new Uint16Array(buffer8.buffer);
  4120. return buffer16[0] === 1;
  4121. }
  4122. // Checks if it's possible to eval JS expressions.
  4123. function isEvalSupported() {
  4124. try {
  4125. new Function('');
  4126. return true;
  4127. } catch (e) {
  4128. return false;
  4129. }
  4130. }
  4131. var Uint32ArrayView = function Uint32ArrayViewClosure() {
  4132. function Uint32ArrayView(buffer, length) {
  4133. this.buffer = buffer;
  4134. this.byteLength = buffer.length;
  4135. this.length = length === undefined ? this.byteLength >> 2 : length;
  4136. ensureUint32ArrayViewProps(this.length);
  4137. }
  4138. Uint32ArrayView.prototype = Object.create(null);
  4139. var uint32ArrayViewSetters = 0;
  4140. function createUint32ArrayProp(index) {
  4141. return {
  4142. get: function () {
  4143. var buffer = this.buffer, offset = index << 2;
  4144. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  4145. },
  4146. set: function (value) {
  4147. var buffer = this.buffer, offset = index << 2;
  4148. buffer[offset] = value & 255;
  4149. buffer[offset + 1] = value >> 8 & 255;
  4150. buffer[offset + 2] = value >> 16 & 255;
  4151. buffer[offset + 3] = value >>> 24 & 255;
  4152. }
  4153. };
  4154. }
  4155. function ensureUint32ArrayViewProps(length) {
  4156. while (uint32ArrayViewSetters < length) {
  4157. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  4158. uint32ArrayViewSetters++;
  4159. }
  4160. }
  4161. return Uint32ArrayView;
  4162. }();
  4163. exports.Uint32ArrayView = Uint32ArrayView;
  4164. var IDENTITY_MATRIX = [
  4165. 1,
  4166. 0,
  4167. 0,
  4168. 1,
  4169. 0,
  4170. 0
  4171. ];
  4172. var Util = function UtilClosure() {
  4173. function Util() {
  4174. }
  4175. var rgbBuf = [
  4176. 'rgb(',
  4177. 0,
  4178. ',',
  4179. 0,
  4180. ',',
  4181. 0,
  4182. ')'
  4183. ];
  4184. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  4185. // creating many intermediate strings.
  4186. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  4187. rgbBuf[1] = r;
  4188. rgbBuf[3] = g;
  4189. rgbBuf[5] = b;
  4190. return rgbBuf.join('');
  4191. };
  4192. // Concatenates two transformation matrices together and returns the result.
  4193. Util.transform = function Util_transform(m1, m2) {
  4194. return [
  4195. m1[0] * m2[0] + m1[2] * m2[1],
  4196. m1[1] * m2[0] + m1[3] * m2[1],
  4197. m1[0] * m2[2] + m1[2] * m2[3],
  4198. m1[1] * m2[2] + m1[3] * m2[3],
  4199. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  4200. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  4201. ];
  4202. };
  4203. // For 2d affine transforms
  4204. Util.applyTransform = function Util_applyTransform(p, m) {
  4205. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  4206. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  4207. return [
  4208. xt,
  4209. yt
  4210. ];
  4211. };
  4212. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  4213. var d = m[0] * m[3] - m[1] * m[2];
  4214. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  4215. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  4216. return [
  4217. xt,
  4218. yt
  4219. ];
  4220. };
  4221. // Applies the transform to the rectangle and finds the minimum axially
  4222. // aligned bounding box.
  4223. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  4224. var p1 = Util.applyTransform(r, m);
  4225. var p2 = Util.applyTransform(r.slice(2, 4), m);
  4226. var p3 = Util.applyTransform([
  4227. r[0],
  4228. r[3]
  4229. ], m);
  4230. var p4 = Util.applyTransform([
  4231. r[2],
  4232. r[1]
  4233. ], m);
  4234. return [
  4235. Math.min(p1[0], p2[0], p3[0], p4[0]),
  4236. Math.min(p1[1], p2[1], p3[1], p4[1]),
  4237. Math.max(p1[0], p2[0], p3[0], p4[0]),
  4238. Math.max(p1[1], p2[1], p3[1], p4[1])
  4239. ];
  4240. };
  4241. Util.inverseTransform = function Util_inverseTransform(m) {
  4242. var d = m[0] * m[3] - m[1] * m[2];
  4243. return [
  4244. m[3] / d,
  4245. -m[1] / d,
  4246. -m[2] / d,
  4247. m[0] / d,
  4248. (m[2] * m[5] - m[4] * m[3]) / d,
  4249. (m[4] * m[1] - m[5] * m[0]) / d
  4250. ];
  4251. };
  4252. // Apply a generic 3d matrix M on a 3-vector v:
  4253. // | a b c | | X |
  4254. // | d e f | x | Y |
  4255. // | g h i | | Z |
  4256. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  4257. // with v as [X,Y,Z]
  4258. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  4259. return [
  4260. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  4261. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  4262. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  4263. ];
  4264. };
  4265. // This calculation uses Singular Value Decomposition.
  4266. // The SVD can be represented with formula A = USV. We are interested in the
  4267. // matrix S here because it represents the scale values.
  4268. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  4269. var transpose = [
  4270. m[0],
  4271. m[2],
  4272. m[1],
  4273. m[3]
  4274. ];
  4275. // Multiply matrix m with its transpose.
  4276. var a = m[0] * transpose[0] + m[1] * transpose[2];
  4277. var b = m[0] * transpose[1] + m[1] * transpose[3];
  4278. var c = m[2] * transpose[0] + m[3] * transpose[2];
  4279. var d = m[2] * transpose[1] + m[3] * transpose[3];
  4280. // Solve the second degree polynomial to get roots.
  4281. var first = (a + d) / 2;
  4282. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  4283. var sx = first + second || 1;
  4284. var sy = first - second || 1;
  4285. // Scale values are the square roots of the eigenvalues.
  4286. return [
  4287. Math.sqrt(sx),
  4288. Math.sqrt(sy)
  4289. ];
  4290. };
  4291. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  4292. // For coordinate systems whose origin lies in the bottom-left, this
  4293. // means normalization to (BL,TR) ordering. For systems with origin in the
  4294. // top-left, this means (TL,BR) ordering.
  4295. Util.normalizeRect = function Util_normalizeRect(rect) {
  4296. var r = rect.slice(0);
  4297. // clone rect
  4298. if (rect[0] > rect[2]) {
  4299. r[0] = rect[2];
  4300. r[2] = rect[0];
  4301. }
  4302. if (rect[1] > rect[3]) {
  4303. r[1] = rect[3];
  4304. r[3] = rect[1];
  4305. }
  4306. return r;
  4307. };
  4308. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  4309. // intersection of rect1 and rect2. If no intersection, returns 'false'
  4310. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  4311. Util.intersect = function Util_intersect(rect1, rect2) {
  4312. function compare(a, b) {
  4313. return a - b;
  4314. }
  4315. // Order points along the axes
  4316. var orderedX = [
  4317. rect1[0],
  4318. rect1[2],
  4319. rect2[0],
  4320. rect2[2]
  4321. ].sort(compare), orderedY = [
  4322. rect1[1],
  4323. rect1[3],
  4324. rect2[1],
  4325. rect2[3]
  4326. ].sort(compare), result = [];
  4327. rect1 = Util.normalizeRect(rect1);
  4328. rect2 = Util.normalizeRect(rect2);
  4329. // X: first and second points belong to different rectangles?
  4330. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  4331. // Intersection must be between second and third points
  4332. result[0] = orderedX[1];
  4333. result[2] = orderedX[2];
  4334. } else {
  4335. return false;
  4336. }
  4337. // Y: first and second points belong to different rectangles?
  4338. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  4339. // Intersection must be between second and third points
  4340. result[1] = orderedY[1];
  4341. result[3] = orderedY[2];
  4342. } else {
  4343. return false;
  4344. }
  4345. return result;
  4346. };
  4347. Util.sign = function Util_sign(num) {
  4348. return num < 0 ? -1 : 1;
  4349. };
  4350. var ROMAN_NUMBER_MAP = [
  4351. '',
  4352. 'C',
  4353. 'CC',
  4354. 'CCC',
  4355. 'CD',
  4356. 'D',
  4357. 'DC',
  4358. 'DCC',
  4359. 'DCCC',
  4360. 'CM',
  4361. '',
  4362. 'X',
  4363. 'XX',
  4364. 'XXX',
  4365. 'XL',
  4366. 'L',
  4367. 'LX',
  4368. 'LXX',
  4369. 'LXXX',
  4370. 'XC',
  4371. '',
  4372. 'I',
  4373. 'II',
  4374. 'III',
  4375. 'IV',
  4376. 'V',
  4377. 'VI',
  4378. 'VII',
  4379. 'VIII',
  4380. 'IX'
  4381. ];
  4382. /**
  4383. * Converts positive integers to (upper case) Roman numerals.
  4384. * @param {integer} number - The number that should be converted.
  4385. * @param {boolean} lowerCase - Indicates if the result should be converted
  4386. * to lower case letters. The default is false.
  4387. * @return {string} The resulting Roman number.
  4388. */
  4389. Util.toRoman = function Util_toRoman(number, lowerCase) {
  4390. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  4391. var pos, romanBuf = [];
  4392. // Thousands
  4393. while (number >= 1000) {
  4394. number -= 1000;
  4395. romanBuf.push('M');
  4396. }
  4397. // Hundreds
  4398. pos = number / 100 | 0;
  4399. number %= 100;
  4400. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  4401. // Tens
  4402. pos = number / 10 | 0;
  4403. number %= 10;
  4404. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  4405. // Ones
  4406. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  4407. var romanStr = romanBuf.join('');
  4408. return lowerCase ? romanStr.toLowerCase() : romanStr;
  4409. };
  4410. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  4411. Array.prototype.push.apply(arr1, arr2);
  4412. };
  4413. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  4414. Array.prototype.unshift.apply(arr1, arr2);
  4415. };
  4416. Util.extendObj = function extendObj(obj1, obj2) {
  4417. for (var key in obj2) {
  4418. obj1[key] = obj2[key];
  4419. }
  4420. };
  4421. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  4422. while (dict && !dict.has(name)) {
  4423. dict = dict.get('Parent');
  4424. }
  4425. if (!dict) {
  4426. return null;
  4427. }
  4428. return getArray ? dict.getArray(name) : dict.get(name);
  4429. };
  4430. Util.inherit = function Util_inherit(sub, base, prototype) {
  4431. sub.prototype = Object.create(base.prototype);
  4432. sub.prototype.constructor = sub;
  4433. for (var prop in prototype) {
  4434. sub.prototype[prop] = prototype[prop];
  4435. }
  4436. };
  4437. Util.loadScript = function Util_loadScript(src, callback) {
  4438. var script = document.createElement('script');
  4439. var loaded = false;
  4440. script.setAttribute('src', src);
  4441. if (callback) {
  4442. script.onload = function () {
  4443. if (!loaded) {
  4444. callback();
  4445. }
  4446. loaded = true;
  4447. };
  4448. }
  4449. document.getElementsByTagName('head')[0].appendChild(script);
  4450. };
  4451. return Util;
  4452. }();
  4453. /**
  4454. * PDF page viewport created based on scale, rotation and offset.
  4455. * @class
  4456. * @alias PageViewport
  4457. */
  4458. var PageViewport = function PageViewportClosure() {
  4459. /**
  4460. * @constructor
  4461. * @private
  4462. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  4463. * @param scale {number} scale of the viewport.
  4464. * @param rotation {number} rotations of the viewport in degrees.
  4465. * @param offsetX {number} offset X
  4466. * @param offsetY {number} offset Y
  4467. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  4468. */
  4469. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  4470. this.viewBox = viewBox;
  4471. this.scale = scale;
  4472. this.rotation = rotation;
  4473. this.offsetX = offsetX;
  4474. this.offsetY = offsetY;
  4475. // creating transform to convert pdf coordinate system to the normal
  4476. // canvas like coordinates taking in account scale and rotation
  4477. var centerX = (viewBox[2] + viewBox[0]) / 2;
  4478. var centerY = (viewBox[3] + viewBox[1]) / 2;
  4479. var rotateA, rotateB, rotateC, rotateD;
  4480. rotation = rotation % 360;
  4481. rotation = rotation < 0 ? rotation + 360 : rotation;
  4482. switch (rotation) {
  4483. case 180:
  4484. rotateA = -1;
  4485. rotateB = 0;
  4486. rotateC = 0;
  4487. rotateD = 1;
  4488. break;
  4489. case 90:
  4490. rotateA = 0;
  4491. rotateB = 1;
  4492. rotateC = 1;
  4493. rotateD = 0;
  4494. break;
  4495. case 270:
  4496. rotateA = 0;
  4497. rotateB = -1;
  4498. rotateC = -1;
  4499. rotateD = 0;
  4500. break;
  4501. //case 0:
  4502. default:
  4503. rotateA = 1;
  4504. rotateB = 0;
  4505. rotateC = 0;
  4506. rotateD = -1;
  4507. break;
  4508. }
  4509. if (dontFlip) {
  4510. rotateC = -rotateC;
  4511. rotateD = -rotateD;
  4512. }
  4513. var offsetCanvasX, offsetCanvasY;
  4514. var width, height;
  4515. if (rotateA === 0) {
  4516. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4517. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4518. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4519. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4520. } else {
  4521. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4522. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4523. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4524. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4525. }
  4526. // creating transform for the following operations:
  4527. // translate(-centerX, -centerY), rotate and flip vertically,
  4528. // scale, and translate(offsetCanvasX, offsetCanvasY)
  4529. this.transform = [
  4530. rotateA * scale,
  4531. rotateB * scale,
  4532. rotateC * scale,
  4533. rotateD * scale,
  4534. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  4535. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  4536. ];
  4537. this.width = width;
  4538. this.height = height;
  4539. this.fontScale = scale;
  4540. }
  4541. PageViewport.prototype = /** @lends PageViewport.prototype */
  4542. {
  4543. /**
  4544. * Clones viewport with additional properties.
  4545. * @param args {Object} (optional) If specified, may contain the 'scale' or
  4546. * 'rotation' properties to override the corresponding properties in
  4547. * the cloned viewport.
  4548. * @returns {PageViewport} Cloned viewport.
  4549. */
  4550. clone: function PageViewPort_clone(args) {
  4551. args = args || {};
  4552. var scale = 'scale' in args ? args.scale : this.scale;
  4553. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  4554. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  4555. },
  4556. /**
  4557. * Converts PDF point to the viewport coordinates. For examples, useful for
  4558. * converting PDF location into canvas pixel coordinates.
  4559. * @param x {number} X coordinate.
  4560. * @param y {number} Y coordinate.
  4561. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4562. * point in the viewport coordinate space.
  4563. * @see {@link convertToPdfPoint}
  4564. * @see {@link convertToViewportRectangle}
  4565. */
  4566. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  4567. return Util.applyTransform([
  4568. x,
  4569. y
  4570. ], this.transform);
  4571. },
  4572. /**
  4573. * Converts PDF rectangle to the viewport coordinates.
  4574. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  4575. * @returns {Array} Contains corresponding coordinates of the rectangle
  4576. * in the viewport coordinate space.
  4577. * @see {@link convertToViewportPoint}
  4578. */
  4579. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  4580. var tl = Util.applyTransform([
  4581. rect[0],
  4582. rect[1]
  4583. ], this.transform);
  4584. var br = Util.applyTransform([
  4585. rect[2],
  4586. rect[3]
  4587. ], this.transform);
  4588. return [
  4589. tl[0],
  4590. tl[1],
  4591. br[0],
  4592. br[1]
  4593. ];
  4594. },
  4595. /**
  4596. * Converts viewport coordinates to the PDF location. For examples, useful
  4597. * for converting canvas pixel location into PDF one.
  4598. * @param x {number} X coordinate.
  4599. * @param y {number} Y coordinate.
  4600. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4601. * point in the PDF coordinate space.
  4602. * @see {@link convertToViewportPoint}
  4603. */
  4604. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  4605. return Util.applyInverseTransform([
  4606. x,
  4607. y
  4608. ], this.transform);
  4609. }
  4610. };
  4611. return PageViewport;
  4612. }();
  4613. var PDFStringTranslateTable = [
  4614. 0,
  4615. 0,
  4616. 0,
  4617. 0,
  4618. 0,
  4619. 0,
  4620. 0,
  4621. 0,
  4622. 0,
  4623. 0,
  4624. 0,
  4625. 0,
  4626. 0,
  4627. 0,
  4628. 0,
  4629. 0,
  4630. 0,
  4631. 0,
  4632. 0,
  4633. 0,
  4634. 0,
  4635. 0,
  4636. 0,
  4637. 0,
  4638. 0x2D8,
  4639. 0x2C7,
  4640. 0x2C6,
  4641. 0x2D9,
  4642. 0x2DD,
  4643. 0x2DB,
  4644. 0x2DA,
  4645. 0x2DC,
  4646. 0,
  4647. 0,
  4648. 0,
  4649. 0,
  4650. 0,
  4651. 0,
  4652. 0,
  4653. 0,
  4654. 0,
  4655. 0,
  4656. 0,
  4657. 0,
  4658. 0,
  4659. 0,
  4660. 0,
  4661. 0,
  4662. 0,
  4663. 0,
  4664. 0,
  4665. 0,
  4666. 0,
  4667. 0,
  4668. 0,
  4669. 0,
  4670. 0,
  4671. 0,
  4672. 0,
  4673. 0,
  4674. 0,
  4675. 0,
  4676. 0,
  4677. 0,
  4678. 0,
  4679. 0,
  4680. 0,
  4681. 0,
  4682. 0,
  4683. 0,
  4684. 0,
  4685. 0,
  4686. 0,
  4687. 0,
  4688. 0,
  4689. 0,
  4690. 0,
  4691. 0,
  4692. 0,
  4693. 0,
  4694. 0,
  4695. 0,
  4696. 0,
  4697. 0,
  4698. 0,
  4699. 0,
  4700. 0,
  4701. 0,
  4702. 0,
  4703. 0,
  4704. 0,
  4705. 0,
  4706. 0,
  4707. 0,
  4708. 0,
  4709. 0,
  4710. 0,
  4711. 0,
  4712. 0,
  4713. 0,
  4714. 0,
  4715. 0,
  4716. 0,
  4717. 0,
  4718. 0,
  4719. 0,
  4720. 0,
  4721. 0,
  4722. 0,
  4723. 0,
  4724. 0,
  4725. 0,
  4726. 0,
  4727. 0,
  4728. 0,
  4729. 0,
  4730. 0,
  4731. 0,
  4732. 0,
  4733. 0,
  4734. 0,
  4735. 0,
  4736. 0,
  4737. 0,
  4738. 0,
  4739. 0,
  4740. 0,
  4741. 0,
  4742. 0x2022,
  4743. 0x2020,
  4744. 0x2021,
  4745. 0x2026,
  4746. 0x2014,
  4747. 0x2013,
  4748. 0x192,
  4749. 0x2044,
  4750. 0x2039,
  4751. 0x203A,
  4752. 0x2212,
  4753. 0x2030,
  4754. 0x201E,
  4755. 0x201C,
  4756. 0x201D,
  4757. 0x2018,
  4758. 0x2019,
  4759. 0x201A,
  4760. 0x2122,
  4761. 0xFB01,
  4762. 0xFB02,
  4763. 0x141,
  4764. 0x152,
  4765. 0x160,
  4766. 0x178,
  4767. 0x17D,
  4768. 0x131,
  4769. 0x142,
  4770. 0x153,
  4771. 0x161,
  4772. 0x17E,
  4773. 0,
  4774. 0x20AC
  4775. ];
  4776. function stringToPDFString(str) {
  4777. var i, n = str.length, strBuf = [];
  4778. if (str[0] === '\xFE' && str[1] === '\xFF') {
  4779. // UTF16BE BOM
  4780. for (i = 2; i < n; i += 2) {
  4781. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  4782. }
  4783. } else {
  4784. for (i = 0; i < n; ++i) {
  4785. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  4786. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  4787. }
  4788. }
  4789. return strBuf.join('');
  4790. }
  4791. function stringToUTF8String(str) {
  4792. return decodeURIComponent(escape(str));
  4793. }
  4794. function utf8StringToString(str) {
  4795. return unescape(encodeURIComponent(str));
  4796. }
  4797. function isEmptyObj(obj) {
  4798. for (var key in obj) {
  4799. return false;
  4800. }
  4801. return true;
  4802. }
  4803. function isBool(v) {
  4804. return typeof v === 'boolean';
  4805. }
  4806. function isInt(v) {
  4807. return typeof v === 'number' && (v | 0) === v;
  4808. }
  4809. function isNum(v) {
  4810. return typeof v === 'number';
  4811. }
  4812. function isString(v) {
  4813. return typeof v === 'string';
  4814. }
  4815. function isArray(v) {
  4816. return v instanceof Array;
  4817. }
  4818. function isArrayBuffer(v) {
  4819. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  4820. }
  4821. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  4822. function isSpace(ch) {
  4823. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  4824. }
  4825. /**
  4826. * Promise Capability object.
  4827. *
  4828. * @typedef {Object} PromiseCapability
  4829. * @property {Promise} promise - A promise object.
  4830. * @property {function} resolve - Fulfills the promise.
  4831. * @property {function} reject - Rejects the promise.
  4832. */
  4833. /**
  4834. * Creates a promise capability object.
  4835. * @alias createPromiseCapability
  4836. *
  4837. * @return {PromiseCapability} A capability object contains:
  4838. * - a Promise, resolve and reject methods.
  4839. */
  4840. function createPromiseCapability() {
  4841. var capability = {};
  4842. capability.promise = new Promise(function (resolve, reject) {
  4843. capability.resolve = resolve;
  4844. capability.reject = reject;
  4845. });
  4846. return capability;
  4847. }
  4848. /**
  4849. * Polyfill for Promises:
  4850. * The following promise implementation tries to generally implement the
  4851. * Promise/A+ spec. Some notable differences from other promise libraries are:
  4852. * - There currently isn't a separate deferred and promise object.
  4853. * - Unhandled rejections eventually show an error if they aren't handled.
  4854. *
  4855. * Based off of the work in:
  4856. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  4857. */
  4858. (function PromiseClosure() {
  4859. if (globalScope.Promise) {
  4860. // Promises existing in the DOM/Worker, checking presence of all/resolve
  4861. if (typeof globalScope.Promise.all !== 'function') {
  4862. globalScope.Promise.all = function (iterable) {
  4863. var count = 0, results = [], resolve, reject;
  4864. var promise = new globalScope.Promise(function (resolve_, reject_) {
  4865. resolve = resolve_;
  4866. reject = reject_;
  4867. });
  4868. iterable.forEach(function (p, i) {
  4869. count++;
  4870. p.then(function (result) {
  4871. results[i] = result;
  4872. count--;
  4873. if (count === 0) {
  4874. resolve(results);
  4875. }
  4876. }, reject);
  4877. });
  4878. if (count === 0) {
  4879. resolve(results);
  4880. }
  4881. return promise;
  4882. };
  4883. }
  4884. if (typeof globalScope.Promise.resolve !== 'function') {
  4885. globalScope.Promise.resolve = function (value) {
  4886. return new globalScope.Promise(function (resolve) {
  4887. resolve(value);
  4888. });
  4889. };
  4890. }
  4891. if (typeof globalScope.Promise.reject !== 'function') {
  4892. globalScope.Promise.reject = function (reason) {
  4893. return new globalScope.Promise(function (resolve, reject) {
  4894. reject(reason);
  4895. });
  4896. };
  4897. }
  4898. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  4899. globalScope.Promise.prototype.catch = function (onReject) {
  4900. return globalScope.Promise.prototype.then(undefined, onReject);
  4901. };
  4902. }
  4903. return;
  4904. }
  4905. var STATUS_PENDING = 0;
  4906. var STATUS_RESOLVED = 1;
  4907. var STATUS_REJECTED = 2;
  4908. // In an attempt to avoid silent exceptions, unhandled rejections are
  4909. // tracked and if they aren't handled in a certain amount of time an
  4910. // error is logged.
  4911. var REJECTION_TIMEOUT = 500;
  4912. var HandlerManager = {
  4913. handlers: [],
  4914. running: false,
  4915. unhandledRejections: [],
  4916. pendingRejectionCheck: false,
  4917. scheduleHandlers: function scheduleHandlers(promise) {
  4918. if (promise._status === STATUS_PENDING) {
  4919. return;
  4920. }
  4921. this.handlers = this.handlers.concat(promise._handlers);
  4922. promise._handlers = [];
  4923. if (this.running) {
  4924. return;
  4925. }
  4926. this.running = true;
  4927. setTimeout(this.runHandlers.bind(this), 0);
  4928. },
  4929. runHandlers: function runHandlers() {
  4930. var RUN_TIMEOUT = 1;
  4931. // ms
  4932. var timeoutAt = Date.now() + RUN_TIMEOUT;
  4933. while (this.handlers.length > 0) {
  4934. var handler = this.handlers.shift();
  4935. var nextStatus = handler.thisPromise._status;
  4936. var nextValue = handler.thisPromise._value;
  4937. try {
  4938. if (nextStatus === STATUS_RESOLVED) {
  4939. if (typeof handler.onResolve === 'function') {
  4940. nextValue = handler.onResolve(nextValue);
  4941. }
  4942. } else if (typeof handler.onReject === 'function') {
  4943. nextValue = handler.onReject(nextValue);
  4944. nextStatus = STATUS_RESOLVED;
  4945. if (handler.thisPromise._unhandledRejection) {
  4946. this.removeUnhandeledRejection(handler.thisPromise);
  4947. }
  4948. }
  4949. } catch (ex) {
  4950. nextStatus = STATUS_REJECTED;
  4951. nextValue = ex;
  4952. }
  4953. handler.nextPromise._updateStatus(nextStatus, nextValue);
  4954. if (Date.now() >= timeoutAt) {
  4955. break;
  4956. }
  4957. }
  4958. if (this.handlers.length > 0) {
  4959. setTimeout(this.runHandlers.bind(this), 0);
  4960. return;
  4961. }
  4962. this.running = false;
  4963. },
  4964. addUnhandledRejection: function addUnhandledRejection(promise) {
  4965. this.unhandledRejections.push({
  4966. promise: promise,
  4967. time: Date.now()
  4968. });
  4969. this.scheduleRejectionCheck();
  4970. },
  4971. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  4972. promise._unhandledRejection = false;
  4973. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4974. if (this.unhandledRejections[i].promise === promise) {
  4975. this.unhandledRejections.splice(i);
  4976. i--;
  4977. }
  4978. }
  4979. },
  4980. scheduleRejectionCheck: function scheduleRejectionCheck() {
  4981. if (this.pendingRejectionCheck) {
  4982. return;
  4983. }
  4984. this.pendingRejectionCheck = true;
  4985. setTimeout(function rejectionCheck() {
  4986. this.pendingRejectionCheck = false;
  4987. var now = Date.now();
  4988. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4989. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  4990. var unhandled = this.unhandledRejections[i].promise._value;
  4991. var msg = 'Unhandled rejection: ' + unhandled;
  4992. if (unhandled.stack) {
  4993. msg += '\n' + unhandled.stack;
  4994. }
  4995. warn(msg);
  4996. this.unhandledRejections.splice(i);
  4997. i--;
  4998. }
  4999. }
  5000. if (this.unhandledRejections.length) {
  5001. this.scheduleRejectionCheck();
  5002. }
  5003. }.bind(this), REJECTION_TIMEOUT);
  5004. }
  5005. };
  5006. var Promise = function Promise(resolver) {
  5007. this._status = STATUS_PENDING;
  5008. this._handlers = [];
  5009. try {
  5010. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  5011. } catch (e) {
  5012. this._reject(e);
  5013. }
  5014. };
  5015. /**
  5016. * Builds a promise that is resolved when all the passed in promises are
  5017. * resolved.
  5018. * @param {array} promises array of data and/or promises to wait for.
  5019. * @return {Promise} New dependent promise.
  5020. */
  5021. Promise.all = function Promise_all(promises) {
  5022. var resolveAll, rejectAll;
  5023. var deferred = new Promise(function (resolve, reject) {
  5024. resolveAll = resolve;
  5025. rejectAll = reject;
  5026. });
  5027. var unresolved = promises.length;
  5028. var results = [];
  5029. if (unresolved === 0) {
  5030. resolveAll(results);
  5031. return deferred;
  5032. }
  5033. function reject(reason) {
  5034. if (deferred._status === STATUS_REJECTED) {
  5035. return;
  5036. }
  5037. results = [];
  5038. rejectAll(reason);
  5039. }
  5040. for (var i = 0, ii = promises.length; i < ii; ++i) {
  5041. var promise = promises[i];
  5042. var resolve = function (i) {
  5043. return function (value) {
  5044. if (deferred._status === STATUS_REJECTED) {
  5045. return;
  5046. }
  5047. results[i] = value;
  5048. unresolved--;
  5049. if (unresolved === 0) {
  5050. resolveAll(results);
  5051. }
  5052. };
  5053. }(i);
  5054. if (Promise.isPromise(promise)) {
  5055. promise.then(resolve, reject);
  5056. } else {
  5057. resolve(promise);
  5058. }
  5059. }
  5060. return deferred;
  5061. };
  5062. /**
  5063. * Checks if the value is likely a promise (has a 'then' function).
  5064. * @return {boolean} true if value is thenable
  5065. */
  5066. Promise.isPromise = function Promise_isPromise(value) {
  5067. return value && typeof value.then === 'function';
  5068. };
  5069. /**
  5070. * Creates resolved promise
  5071. * @param value resolve value
  5072. * @returns {Promise}
  5073. */
  5074. Promise.resolve = function Promise_resolve(value) {
  5075. return new Promise(function (resolve) {
  5076. resolve(value);
  5077. });
  5078. };
  5079. /**
  5080. * Creates rejected promise
  5081. * @param reason rejection value
  5082. * @returns {Promise}
  5083. */
  5084. Promise.reject = function Promise_reject(reason) {
  5085. return new Promise(function (resolve, reject) {
  5086. reject(reason);
  5087. });
  5088. };
  5089. Promise.prototype = {
  5090. _status: null,
  5091. _value: null,
  5092. _handlers: null,
  5093. _unhandledRejection: null,
  5094. _updateStatus: function Promise__updateStatus(status, value) {
  5095. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  5096. return;
  5097. }
  5098. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  5099. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  5100. return;
  5101. }
  5102. this._status = status;
  5103. this._value = value;
  5104. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  5105. this._unhandledRejection = true;
  5106. HandlerManager.addUnhandledRejection(this);
  5107. }
  5108. HandlerManager.scheduleHandlers(this);
  5109. },
  5110. _resolve: function Promise_resolve(value) {
  5111. this._updateStatus(STATUS_RESOLVED, value);
  5112. },
  5113. _reject: function Promise_reject(reason) {
  5114. this._updateStatus(STATUS_REJECTED, reason);
  5115. },
  5116. then: function Promise_then(onResolve, onReject) {
  5117. var nextPromise = new Promise(function (resolve, reject) {
  5118. this.resolve = resolve;
  5119. this.reject = reject;
  5120. });
  5121. this._handlers.push({
  5122. thisPromise: this,
  5123. onResolve: onResolve,
  5124. onReject: onReject,
  5125. nextPromise: nextPromise
  5126. });
  5127. HandlerManager.scheduleHandlers(this);
  5128. return nextPromise;
  5129. },
  5130. catch: function Promise_catch(onReject) {
  5131. return this.then(undefined, onReject);
  5132. }
  5133. };
  5134. globalScope.Promise = Promise;
  5135. }());
  5136. (function WeakMapClosure() {
  5137. if (globalScope.WeakMap) {
  5138. return;
  5139. }
  5140. var id = 0;
  5141. function WeakMap() {
  5142. this.id = '$weakmap' + id++;
  5143. }
  5144. WeakMap.prototype = {
  5145. has: function (obj) {
  5146. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  5147. },
  5148. get: function (obj, defaultValue) {
  5149. return this.has(obj) ? obj[this.id] : defaultValue;
  5150. },
  5151. set: function (obj, value) {
  5152. Object.defineProperty(obj, this.id, {
  5153. value: value,
  5154. enumerable: false,
  5155. configurable: true
  5156. });
  5157. },
  5158. delete: function (obj) {
  5159. delete obj[this.id];
  5160. }
  5161. };
  5162. globalScope.WeakMap = WeakMap;
  5163. }());
  5164. var StatTimer = function StatTimerClosure() {
  5165. function rpad(str, pad, length) {
  5166. while (str.length < length) {
  5167. str += pad;
  5168. }
  5169. return str;
  5170. }
  5171. function StatTimer() {
  5172. this.started = Object.create(null);
  5173. this.times = [];
  5174. this.enabled = true;
  5175. }
  5176. StatTimer.prototype = {
  5177. time: function StatTimer_time(name) {
  5178. if (!this.enabled) {
  5179. return;
  5180. }
  5181. if (name in this.started) {
  5182. warn('Timer is already running for ' + name);
  5183. }
  5184. this.started[name] = Date.now();
  5185. },
  5186. timeEnd: function StatTimer_timeEnd(name) {
  5187. if (!this.enabled) {
  5188. return;
  5189. }
  5190. if (!(name in this.started)) {
  5191. warn('Timer has not been started for ' + name);
  5192. }
  5193. this.times.push({
  5194. 'name': name,
  5195. 'start': this.started[name],
  5196. 'end': Date.now()
  5197. });
  5198. // Remove timer from started so it can be called again.
  5199. delete this.started[name];
  5200. },
  5201. toString: function StatTimer_toString() {
  5202. var i, ii;
  5203. var times = this.times;
  5204. var out = '';
  5205. // Find the longest name for padding purposes.
  5206. var longest = 0;
  5207. for (i = 0, ii = times.length; i < ii; ++i) {
  5208. var name = times[i]['name'];
  5209. if (name.length > longest) {
  5210. longest = name.length;
  5211. }
  5212. }
  5213. for (i = 0, ii = times.length; i < ii; ++i) {
  5214. var span = times[i];
  5215. var duration = span.end - span.start;
  5216. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  5217. }
  5218. return out;
  5219. }
  5220. };
  5221. return StatTimer;
  5222. }();
  5223. var createBlob = function createBlob(data, contentType) {
  5224. if (typeof Blob !== 'undefined') {
  5225. return new Blob([data], { type: contentType });
  5226. }
  5227. warn('The "Blob" constructor is not supported.');
  5228. };
  5229. var createObjectURL = function createObjectURLClosure() {
  5230. // Blob/createObjectURL is not available, falling back to data schema.
  5231. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5232. return function createObjectURL(data, contentType, forceDataSchema) {
  5233. if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) {
  5234. var blob = createBlob(data, contentType);
  5235. return URL.createObjectURL(blob);
  5236. }
  5237. var buffer = 'data:' + contentType + ';base64,';
  5238. for (var i = 0, ii = data.length; i < ii; i += 3) {
  5239. var b1 = data[i] & 0xFF;
  5240. var b2 = data[i + 1] & 0xFF;
  5241. var b3 = data[i + 2] & 0xFF;
  5242. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  5243. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  5244. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  5245. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  5246. }
  5247. return buffer;
  5248. };
  5249. }();
  5250. function MessageHandler(sourceName, targetName, comObj) {
  5251. this.sourceName = sourceName;
  5252. this.targetName = targetName;
  5253. this.comObj = comObj;
  5254. this.callbackIndex = 1;
  5255. this.postMessageTransfers = true;
  5256. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  5257. var ah = this.actionHandler = Object.create(null);
  5258. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  5259. var data = event.data;
  5260. if (data.targetName !== this.sourceName) {
  5261. return;
  5262. }
  5263. if (data.isReply) {
  5264. var callbackId = data.callbackId;
  5265. if (data.callbackId in callbacksCapabilities) {
  5266. var callback = callbacksCapabilities[callbackId];
  5267. delete callbacksCapabilities[callbackId];
  5268. if ('error' in data) {
  5269. callback.reject(data.error);
  5270. } else {
  5271. callback.resolve(data.data);
  5272. }
  5273. } else {
  5274. error('Cannot resolve callback ' + callbackId);
  5275. }
  5276. } else if (data.action in ah) {
  5277. var action = ah[data.action];
  5278. if (data.callbackId) {
  5279. var sourceName = this.sourceName;
  5280. var targetName = data.sourceName;
  5281. Promise.resolve().then(function () {
  5282. return action[0].call(action[1], data.data);
  5283. }).then(function (result) {
  5284. comObj.postMessage({
  5285. sourceName: sourceName,
  5286. targetName: targetName,
  5287. isReply: true,
  5288. callbackId: data.callbackId,
  5289. data: result
  5290. });
  5291. }, function (reason) {
  5292. if (reason instanceof Error) {
  5293. // Serialize error to avoid "DataCloneError"
  5294. reason = reason + '';
  5295. }
  5296. comObj.postMessage({
  5297. sourceName: sourceName,
  5298. targetName: targetName,
  5299. isReply: true,
  5300. callbackId: data.callbackId,
  5301. error: reason
  5302. });
  5303. });
  5304. } else {
  5305. action[0].call(action[1], data.data);
  5306. }
  5307. } else {
  5308. error('Unknown action from worker: ' + data.action);
  5309. }
  5310. }.bind(this);
  5311. comObj.addEventListener('message', this._onComObjOnMessage);
  5312. }
  5313. MessageHandler.prototype = {
  5314. on: function messageHandlerOn(actionName, handler, scope) {
  5315. var ah = this.actionHandler;
  5316. if (ah[actionName]) {
  5317. error('There is already an actionName called "' + actionName + '"');
  5318. }
  5319. ah[actionName] = [
  5320. handler,
  5321. scope
  5322. ];
  5323. },
  5324. /**
  5325. * Sends a message to the comObj to invoke the action with the supplied data.
  5326. * @param {String} actionName Action to call.
  5327. * @param {JSON} data JSON data to send.
  5328. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  5329. */
  5330. send: function messageHandlerSend(actionName, data, transfers) {
  5331. var message = {
  5332. sourceName: this.sourceName,
  5333. targetName: this.targetName,
  5334. action: actionName,
  5335. data: data
  5336. };
  5337. this.postMessage(message, transfers);
  5338. },
  5339. /**
  5340. * Sends a message to the comObj to invoke the action with the supplied data.
  5341. * Expects that other side will callback with the response.
  5342. * @param {String} actionName Action to call.
  5343. * @param {JSON} data JSON data to send.
  5344. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  5345. * @returns {Promise} Promise to be resolved with response data.
  5346. */
  5347. sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) {
  5348. var callbackId = this.callbackIndex++;
  5349. var message = {
  5350. sourceName: this.sourceName,
  5351. targetName: this.targetName,
  5352. action: actionName,
  5353. data: data,
  5354. callbackId: callbackId
  5355. };
  5356. var capability = createPromiseCapability();
  5357. this.callbacksCapabilities[callbackId] = capability;
  5358. try {
  5359. this.postMessage(message, transfers);
  5360. } catch (e) {
  5361. capability.reject(e);
  5362. }
  5363. return capability.promise;
  5364. },
  5365. /**
  5366. * Sends raw message to the comObj.
  5367. * @private
  5368. * @param message {Object} Raw message.
  5369. * @param transfers List of transfers/ArrayBuffers, or undefined.
  5370. */
  5371. postMessage: function (message, transfers) {
  5372. if (transfers && this.postMessageTransfers) {
  5373. this.comObj.postMessage(message, transfers);
  5374. } else {
  5375. this.comObj.postMessage(message);
  5376. }
  5377. },
  5378. destroy: function () {
  5379. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  5380. }
  5381. };
  5382. function loadJpegStream(id, imageUrl, objs) {
  5383. var img = new Image();
  5384. img.onload = function loadJpegStream_onloadClosure() {
  5385. objs.resolve(id, img);
  5386. };
  5387. img.onerror = function loadJpegStream_onerrorClosure() {
  5388. objs.resolve(id, null);
  5389. warn('Error during JPEG image loading');
  5390. };
  5391. img.src = imageUrl;
  5392. }
  5393. // Polyfill from https://github.com/Polymer/URL
  5394. /* Any copyright is dedicated to the Public Domain.
  5395. * http://creativecommons.org/publicdomain/zero/1.0/ */
  5396. (function checkURLConstructor(scope) {
  5397. // feature detect for URL constructor
  5398. var hasWorkingUrl = false;
  5399. try {
  5400. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  5401. var u = new URL('b', 'http://a');
  5402. u.pathname = 'c%20d';
  5403. hasWorkingUrl = u.href === 'http://a/c%20d';
  5404. }
  5405. } catch (e) {
  5406. }
  5407. if (hasWorkingUrl) {
  5408. return;
  5409. }
  5410. var relative = Object.create(null);
  5411. relative['ftp'] = 21;
  5412. relative['file'] = 0;
  5413. relative['gopher'] = 70;
  5414. relative['http'] = 80;
  5415. relative['https'] = 443;
  5416. relative['ws'] = 80;
  5417. relative['wss'] = 443;
  5418. var relativePathDotMapping = Object.create(null);
  5419. relativePathDotMapping['%2e'] = '.';
  5420. relativePathDotMapping['.%2e'] = '..';
  5421. relativePathDotMapping['%2e.'] = '..';
  5422. relativePathDotMapping['%2e%2e'] = '..';
  5423. function isRelativeScheme(scheme) {
  5424. return relative[scheme] !== undefined;
  5425. }
  5426. function invalid() {
  5427. clear.call(this);
  5428. this._isInvalid = true;
  5429. }
  5430. function IDNAToASCII(h) {
  5431. if ('' === h) {
  5432. invalid.call(this);
  5433. }
  5434. // XXX
  5435. return h.toLowerCase();
  5436. }
  5437. function percentEscape(c) {
  5438. var unicode = c.charCodeAt(0);
  5439. if (unicode > 0x20 && unicode < 0x7F && // " # < > ? `
  5440. [
  5441. 0x22,
  5442. 0x23,
  5443. 0x3C,
  5444. 0x3E,
  5445. 0x3F,
  5446. 0x60
  5447. ].indexOf(unicode) === -1) {
  5448. return c;
  5449. }
  5450. return encodeURIComponent(c);
  5451. }
  5452. function percentEscapeQuery(c) {
  5453. // XXX This actually needs to encode c using encoding and then
  5454. // convert the bytes one-by-one.
  5455. var unicode = c.charCodeAt(0);
  5456. if (unicode > 0x20 && unicode < 0x7F && // " # < > ` (do not escape '?')
  5457. [
  5458. 0x22,
  5459. 0x23,
  5460. 0x3C,
  5461. 0x3E,
  5462. 0x60
  5463. ].indexOf(unicode) === -1) {
  5464. return c;
  5465. }
  5466. return encodeURIComponent(c);
  5467. }
  5468. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  5469. function parse(input, stateOverride, base) {
  5470. function err(message) {
  5471. errors.push(message);
  5472. }
  5473. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  5474. loop:
  5475. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  5476. var c = input[cursor];
  5477. switch (state) {
  5478. case 'scheme start':
  5479. if (c && ALPHA.test(c)) {
  5480. buffer += c.toLowerCase();
  5481. // ASCII-safe
  5482. state = 'scheme';
  5483. } else if (!stateOverride) {
  5484. buffer = '';
  5485. state = 'no scheme';
  5486. continue;
  5487. } else {
  5488. err('Invalid scheme.');
  5489. break loop;
  5490. }
  5491. break;
  5492. case 'scheme':
  5493. if (c && ALPHANUMERIC.test(c)) {
  5494. buffer += c.toLowerCase();
  5495. } else // ASCII-safe
  5496. if (':' === c) {
  5497. this._scheme = buffer;
  5498. buffer = '';
  5499. if (stateOverride) {
  5500. break loop;
  5501. }
  5502. if (isRelativeScheme(this._scheme)) {
  5503. this._isRelative = true;
  5504. }
  5505. if ('file' === this._scheme) {
  5506. state = 'relative';
  5507. } else if (this._isRelative && base && base._scheme === this._scheme) {
  5508. state = 'relative or authority';
  5509. } else if (this._isRelative) {
  5510. state = 'authority first slash';
  5511. } else {
  5512. state = 'scheme data';
  5513. }
  5514. } else if (!stateOverride) {
  5515. buffer = '';
  5516. cursor = 0;
  5517. state = 'no scheme';
  5518. continue;
  5519. } else if (EOF === c) {
  5520. break loop;
  5521. } else {
  5522. err('Code point not allowed in scheme: ' + c);
  5523. break loop;
  5524. }
  5525. break;
  5526. case 'scheme data':
  5527. if ('?' === c) {
  5528. this._query = '?';
  5529. state = 'query';
  5530. } else if ('#' === c) {
  5531. this._fragment = '#';
  5532. state = 'fragment';
  5533. } else {
  5534. // XXX error handling
  5535. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5536. this._schemeData += percentEscape(c);
  5537. }
  5538. }
  5539. break;
  5540. case 'no scheme':
  5541. if (!base || !isRelativeScheme(base._scheme)) {
  5542. err('Missing scheme.');
  5543. invalid.call(this);
  5544. } else {
  5545. state = 'relative';
  5546. continue;
  5547. }
  5548. break;
  5549. case 'relative or authority':
  5550. if ('/' === c && '/' === input[cursor + 1]) {
  5551. state = 'authority ignore slashes';
  5552. } else {
  5553. err('Expected /, got: ' + c);
  5554. state = 'relative';
  5555. continue;
  5556. }
  5557. break;
  5558. case 'relative':
  5559. this._isRelative = true;
  5560. if ('file' !== this._scheme) {
  5561. this._scheme = base._scheme;
  5562. }
  5563. if (EOF === c) {
  5564. this._host = base._host;
  5565. this._port = base._port;
  5566. this._path = base._path.slice();
  5567. this._query = base._query;
  5568. this._username = base._username;
  5569. this._password = base._password;
  5570. break loop;
  5571. } else if ('/' === c || '\\' === c) {
  5572. if ('\\' === c) {
  5573. err('\\ is an invalid code point.');
  5574. }
  5575. state = 'relative slash';
  5576. } else if ('?' === c) {
  5577. this._host = base._host;
  5578. this._port = base._port;
  5579. this._path = base._path.slice();
  5580. this._query = '?';
  5581. this._username = base._username;
  5582. this._password = base._password;
  5583. state = 'query';
  5584. } else if ('#' === c) {
  5585. this._host = base._host;
  5586. this._port = base._port;
  5587. this._path = base._path.slice();
  5588. this._query = base._query;
  5589. this._fragment = '#';
  5590. this._username = base._username;
  5591. this._password = base._password;
  5592. state = 'fragment';
  5593. } else {
  5594. var nextC = input[cursor + 1];
  5595. var nextNextC = input[cursor + 2];
  5596. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  5597. this._host = base._host;
  5598. this._port = base._port;
  5599. this._username = base._username;
  5600. this._password = base._password;
  5601. this._path = base._path.slice();
  5602. this._path.pop();
  5603. }
  5604. state = 'relative path';
  5605. continue;
  5606. }
  5607. break;
  5608. case 'relative slash':
  5609. if ('/' === c || '\\' === c) {
  5610. if ('\\' === c) {
  5611. err('\\ is an invalid code point.');
  5612. }
  5613. if ('file' === this._scheme) {
  5614. state = 'file host';
  5615. } else {
  5616. state = 'authority ignore slashes';
  5617. }
  5618. } else {
  5619. if ('file' !== this._scheme) {
  5620. this._host = base._host;
  5621. this._port = base._port;
  5622. this._username = base._username;
  5623. this._password = base._password;
  5624. }
  5625. state = 'relative path';
  5626. continue;
  5627. }
  5628. break;
  5629. case 'authority first slash':
  5630. if ('/' === c) {
  5631. state = 'authority second slash';
  5632. } else {
  5633. err('Expected \'/\', got: ' + c);
  5634. state = 'authority ignore slashes';
  5635. continue;
  5636. }
  5637. break;
  5638. case 'authority second slash':
  5639. state = 'authority ignore slashes';
  5640. if ('/' !== c) {
  5641. err('Expected \'/\', got: ' + c);
  5642. continue;
  5643. }
  5644. break;
  5645. case 'authority ignore slashes':
  5646. if ('/' !== c && '\\' !== c) {
  5647. state = 'authority';
  5648. continue;
  5649. } else {
  5650. err('Expected authority, got: ' + c);
  5651. }
  5652. break;
  5653. case 'authority':
  5654. if ('@' === c) {
  5655. if (seenAt) {
  5656. err('@ already seen.');
  5657. buffer += '%40';
  5658. }
  5659. seenAt = true;
  5660. for (var i = 0; i < buffer.length; i++) {
  5661. var cp = buffer[i];
  5662. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  5663. err('Invalid whitespace in authority.');
  5664. continue;
  5665. }
  5666. // XXX check URL code points
  5667. if (':' === cp && null === this._password) {
  5668. this._password = '';
  5669. continue;
  5670. }
  5671. var tempC = percentEscape(cp);
  5672. if (null !== this._password) {
  5673. this._password += tempC;
  5674. } else {
  5675. this._username += tempC;
  5676. }
  5677. }
  5678. buffer = '';
  5679. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5680. cursor -= buffer.length;
  5681. buffer = '';
  5682. state = 'host';
  5683. continue;
  5684. } else {
  5685. buffer += c;
  5686. }
  5687. break;
  5688. case 'file host':
  5689. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5690. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  5691. state = 'relative path';
  5692. } else if (buffer.length === 0) {
  5693. state = 'relative path start';
  5694. } else {
  5695. this._host = IDNAToASCII.call(this, buffer);
  5696. buffer = '';
  5697. state = 'relative path start';
  5698. }
  5699. continue;
  5700. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5701. err('Invalid whitespace in file host.');
  5702. } else {
  5703. buffer += c;
  5704. }
  5705. break;
  5706. case 'host':
  5707. case 'hostname':
  5708. if (':' === c && !seenBracket) {
  5709. // XXX host parsing
  5710. this._host = IDNAToASCII.call(this, buffer);
  5711. buffer = '';
  5712. state = 'port';
  5713. if ('hostname' === stateOverride) {
  5714. break loop;
  5715. }
  5716. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5717. this._host = IDNAToASCII.call(this, buffer);
  5718. buffer = '';
  5719. state = 'relative path start';
  5720. if (stateOverride) {
  5721. break loop;
  5722. }
  5723. continue;
  5724. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5725. if ('[' === c) {
  5726. seenBracket = true;
  5727. } else if (']' === c) {
  5728. seenBracket = false;
  5729. }
  5730. buffer += c;
  5731. } else {
  5732. err('Invalid code point in host/hostname: ' + c);
  5733. }
  5734. break;
  5735. case 'port':
  5736. if (/[0-9]/.test(c)) {
  5737. buffer += c;
  5738. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c || stateOverride) {
  5739. if ('' !== buffer) {
  5740. var temp = parseInt(buffer, 10);
  5741. if (temp !== relative[this._scheme]) {
  5742. this._port = temp + '';
  5743. }
  5744. buffer = '';
  5745. }
  5746. if (stateOverride) {
  5747. break loop;
  5748. }
  5749. state = 'relative path start';
  5750. continue;
  5751. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5752. err('Invalid code point in port: ' + c);
  5753. } else {
  5754. invalid.call(this);
  5755. }
  5756. break;
  5757. case 'relative path start':
  5758. if ('\\' === c) {
  5759. err('\'\\\' not allowed in path.');
  5760. }
  5761. state = 'relative path';
  5762. if ('/' !== c && '\\' !== c) {
  5763. continue;
  5764. }
  5765. break;
  5766. case 'relative path':
  5767. if (EOF === c || '/' === c || '\\' === c || !stateOverride && ('?' === c || '#' === c)) {
  5768. if ('\\' === c) {
  5769. err('\\ not allowed in relative path.');
  5770. }
  5771. var tmp;
  5772. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  5773. buffer = tmp;
  5774. }
  5775. if ('..' === buffer) {
  5776. this._path.pop();
  5777. if ('/' !== c && '\\' !== c) {
  5778. this._path.push('');
  5779. }
  5780. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  5781. this._path.push('');
  5782. } else if ('.' !== buffer) {
  5783. if ('file' === this._scheme && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  5784. buffer = buffer[0] + ':';
  5785. }
  5786. this._path.push(buffer);
  5787. }
  5788. buffer = '';
  5789. if ('?' === c) {
  5790. this._query = '?';
  5791. state = 'query';
  5792. } else if ('#' === c) {
  5793. this._fragment = '#';
  5794. state = 'fragment';
  5795. }
  5796. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5797. buffer += percentEscape(c);
  5798. }
  5799. break;
  5800. case 'query':
  5801. if (!stateOverride && '#' === c) {
  5802. this._fragment = '#';
  5803. state = 'fragment';
  5804. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5805. this._query += percentEscapeQuery(c);
  5806. }
  5807. break;
  5808. case 'fragment':
  5809. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5810. this._fragment += c;
  5811. }
  5812. break;
  5813. }
  5814. cursor++;
  5815. }
  5816. }
  5817. function clear() {
  5818. this._scheme = '';
  5819. this._schemeData = '';
  5820. this._username = '';
  5821. this._password = null;
  5822. this._host = '';
  5823. this._port = '';
  5824. this._path = [];
  5825. this._query = '';
  5826. this._fragment = '';
  5827. this._isInvalid = false;
  5828. this._isRelative = false;
  5829. }
  5830. // Does not process domain names or IP addresses.
  5831. // Does not handle encoding for the query parameter.
  5832. function JURL(url, base)
  5833. /* , encoding */
  5834. {
  5835. if (base !== undefined && !(base instanceof JURL)) {
  5836. base = new JURL(String(base));
  5837. }
  5838. this._url = url;
  5839. clear.call(this);
  5840. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  5841. // encoding = encoding || 'utf-8'
  5842. parse.call(this, input, null, base);
  5843. }
  5844. JURL.prototype = {
  5845. toString: function () {
  5846. return this.href;
  5847. },
  5848. get href() {
  5849. if (this._isInvalid) {
  5850. return this._url;
  5851. }
  5852. var authority = '';
  5853. if ('' !== this._username || null !== this._password) {
  5854. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  5855. }
  5856. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  5857. },
  5858. set href(href) {
  5859. clear.call(this);
  5860. parse.call(this, href);
  5861. },
  5862. get protocol() {
  5863. return this._scheme + ':';
  5864. },
  5865. set protocol(protocol) {
  5866. if (this._isInvalid) {
  5867. return;
  5868. }
  5869. parse.call(this, protocol + ':', 'scheme start');
  5870. },
  5871. get host() {
  5872. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  5873. },
  5874. set host(host) {
  5875. if (this._isInvalid || !this._isRelative) {
  5876. return;
  5877. }
  5878. parse.call(this, host, 'host');
  5879. },
  5880. get hostname() {
  5881. return this._host;
  5882. },
  5883. set hostname(hostname) {
  5884. if (this._isInvalid || !this._isRelative) {
  5885. return;
  5886. }
  5887. parse.call(this, hostname, 'hostname');
  5888. },
  5889. get port() {
  5890. return this._port;
  5891. },
  5892. set port(port) {
  5893. if (this._isInvalid || !this._isRelative) {
  5894. return;
  5895. }
  5896. parse.call(this, port, 'port');
  5897. },
  5898. get pathname() {
  5899. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  5900. },
  5901. set pathname(pathname) {
  5902. if (this._isInvalid || !this._isRelative) {
  5903. return;
  5904. }
  5905. this._path = [];
  5906. parse.call(this, pathname, 'relative path start');
  5907. },
  5908. get search() {
  5909. return this._isInvalid || !this._query || '?' === this._query ? '' : this._query;
  5910. },
  5911. set search(search) {
  5912. if (this._isInvalid || !this._isRelative) {
  5913. return;
  5914. }
  5915. this._query = '?';
  5916. if ('?' === search[0]) {
  5917. search = search.slice(1);
  5918. }
  5919. parse.call(this, search, 'query');
  5920. },
  5921. get hash() {
  5922. return this._isInvalid || !this._fragment || '#' === this._fragment ? '' : this._fragment;
  5923. },
  5924. set hash(hash) {
  5925. if (this._isInvalid) {
  5926. return;
  5927. }
  5928. this._fragment = '#';
  5929. if ('#' === hash[0]) {
  5930. hash = hash.slice(1);
  5931. }
  5932. parse.call(this, hash, 'fragment');
  5933. },
  5934. get origin() {
  5935. var host;
  5936. if (this._isInvalid || !this._scheme) {
  5937. return '';
  5938. }
  5939. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  5940. // Gecko throws error for "data://"
  5941. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  5942. // Gecko returns String("") for file: mailto:
  5943. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  5944. switch (this._scheme) {
  5945. case 'data':
  5946. case 'file':
  5947. case 'javascript':
  5948. case 'mailto':
  5949. return 'null';
  5950. }
  5951. host = this.host;
  5952. if (!host) {
  5953. return '';
  5954. }
  5955. return this._scheme + '://' + host;
  5956. }
  5957. };
  5958. // Copy over the static methods
  5959. var OriginalURL = scope.URL;
  5960. if (OriginalURL) {
  5961. JURL.createObjectURL = function (blob) {
  5962. // IE extension allows a second optional options argument.
  5963. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  5964. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  5965. };
  5966. JURL.revokeObjectURL = function (url) {
  5967. OriginalURL.revokeObjectURL(url);
  5968. };
  5969. }
  5970. scope.URL = JURL;
  5971. }(globalScope));
  5972. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  5973. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  5974. exports.OPS = OPS;
  5975. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  5976. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  5977. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  5978. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  5979. exports.AnnotationFlag = AnnotationFlag;
  5980. exports.AnnotationType = AnnotationType;
  5981. exports.FontType = FontType;
  5982. exports.ImageKind = ImageKind;
  5983. exports.InvalidPDFException = InvalidPDFException;
  5984. exports.MessageHandler = MessageHandler;
  5985. exports.MissingDataException = MissingDataException;
  5986. exports.MissingPDFException = MissingPDFException;
  5987. exports.NotImplementedException = NotImplementedException;
  5988. exports.PageViewport = PageViewport;
  5989. exports.PasswordException = PasswordException;
  5990. exports.PasswordResponses = PasswordResponses;
  5991. exports.StatTimer = StatTimer;
  5992. exports.StreamType = StreamType;
  5993. exports.TextRenderingMode = TextRenderingMode;
  5994. exports.UnexpectedResponseException = UnexpectedResponseException;
  5995. exports.UnknownErrorException = UnknownErrorException;
  5996. exports.Util = Util;
  5997. exports.XRefParseException = XRefParseException;
  5998. exports.arrayByteLength = arrayByteLength;
  5999. exports.arraysToBytes = arraysToBytes;
  6000. exports.assert = assert;
  6001. exports.bytesToString = bytesToString;
  6002. exports.createBlob = createBlob;
  6003. exports.createPromiseCapability = createPromiseCapability;
  6004. exports.createObjectURL = createObjectURL;
  6005. exports.deprecated = deprecated;
  6006. exports.error = error;
  6007. exports.getLookupTableFactory = getLookupTableFactory;
  6008. exports.getVerbosityLevel = getVerbosityLevel;
  6009. exports.globalScope = globalScope;
  6010. exports.info = info;
  6011. exports.isArray = isArray;
  6012. exports.isArrayBuffer = isArrayBuffer;
  6013. exports.isBool = isBool;
  6014. exports.isEmptyObj = isEmptyObj;
  6015. exports.isInt = isInt;
  6016. exports.isNum = isNum;
  6017. exports.isString = isString;
  6018. exports.isSpace = isSpace;
  6019. exports.isSameOrigin = isSameOrigin;
  6020. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  6021. exports.isLittleEndian = isLittleEndian;
  6022. exports.isEvalSupported = isEvalSupported;
  6023. exports.loadJpegStream = loadJpegStream;
  6024. exports.log2 = log2;
  6025. exports.readInt8 = readInt8;
  6026. exports.readUint16 = readUint16;
  6027. exports.readUint32 = readUint32;
  6028. exports.removeNullCharacters = removeNullCharacters;
  6029. exports.setVerbosityLevel = setVerbosityLevel;
  6030. exports.shadow = shadow;
  6031. exports.string32 = string32;
  6032. exports.stringToBytes = stringToBytes;
  6033. exports.stringToPDFString = stringToPDFString;
  6034. exports.stringToUTF8String = stringToUTF8String;
  6035. exports.utf8StringToString = utf8StringToString;
  6036. exports.warn = warn;
  6037. }));
  6038. (function (root, factory) {
  6039. factory(root.pdfjsCoreCFFParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  6040. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  6041. var error = sharedUtil.error;
  6042. var info = sharedUtil.info;
  6043. var bytesToString = sharedUtil.bytesToString;
  6044. var warn = sharedUtil.warn;
  6045. var isArray = sharedUtil.isArray;
  6046. var Util = sharedUtil.Util;
  6047. var stringToBytes = sharedUtil.stringToBytes;
  6048. var assert = sharedUtil.assert;
  6049. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  6050. var ExpertCharset = coreCharsets.ExpertCharset;
  6051. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  6052. var StandardEncoding = coreEncodings.StandardEncoding;
  6053. var ExpertEncoding = coreEncodings.ExpertEncoding;
  6054. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  6055. var MAX_SUBR_NESTING = 10;
  6056. /**
  6057. * The CFF class takes a Type1 file and wrap it into a
  6058. * 'Compact Font Format' which itself embed Type2 charstrings.
  6059. */
  6060. var CFFStandardStrings = [
  6061. '.notdef',
  6062. 'space',
  6063. 'exclam',
  6064. 'quotedbl',
  6065. 'numbersign',
  6066. 'dollar',
  6067. 'percent',
  6068. 'ampersand',
  6069. 'quoteright',
  6070. 'parenleft',
  6071. 'parenright',
  6072. 'asterisk',
  6073. 'plus',
  6074. 'comma',
  6075. 'hyphen',
  6076. 'period',
  6077. 'slash',
  6078. 'zero',
  6079. 'one',
  6080. 'two',
  6081. 'three',
  6082. 'four',
  6083. 'five',
  6084. 'six',
  6085. 'seven',
  6086. 'eight',
  6087. 'nine',
  6088. 'colon',
  6089. 'semicolon',
  6090. 'less',
  6091. 'equal',
  6092. 'greater',
  6093. 'question',
  6094. 'at',
  6095. 'A',
  6096. 'B',
  6097. 'C',
  6098. 'D',
  6099. 'E',
  6100. 'F',
  6101. 'G',
  6102. 'H',
  6103. 'I',
  6104. 'J',
  6105. 'K',
  6106. 'L',
  6107. 'M',
  6108. 'N',
  6109. 'O',
  6110. 'P',
  6111. 'Q',
  6112. 'R',
  6113. 'S',
  6114. 'T',
  6115. 'U',
  6116. 'V',
  6117. 'W',
  6118. 'X',
  6119. 'Y',
  6120. 'Z',
  6121. 'bracketleft',
  6122. 'backslash',
  6123. 'bracketright',
  6124. 'asciicircum',
  6125. 'underscore',
  6126. 'quoteleft',
  6127. 'a',
  6128. 'b',
  6129. 'c',
  6130. 'd',
  6131. 'e',
  6132. 'f',
  6133. 'g',
  6134. 'h',
  6135. 'i',
  6136. 'j',
  6137. 'k',
  6138. 'l',
  6139. 'm',
  6140. 'n',
  6141. 'o',
  6142. 'p',
  6143. 'q',
  6144. 'r',
  6145. 's',
  6146. 't',
  6147. 'u',
  6148. 'v',
  6149. 'w',
  6150. 'x',
  6151. 'y',
  6152. 'z',
  6153. 'braceleft',
  6154. 'bar',
  6155. 'braceright',
  6156. 'asciitilde',
  6157. 'exclamdown',
  6158. 'cent',
  6159. 'sterling',
  6160. 'fraction',
  6161. 'yen',
  6162. 'florin',
  6163. 'section',
  6164. 'currency',
  6165. 'quotesingle',
  6166. 'quotedblleft',
  6167. 'guillemotleft',
  6168. 'guilsinglleft',
  6169. 'guilsinglright',
  6170. 'fi',
  6171. 'fl',
  6172. 'endash',
  6173. 'dagger',
  6174. 'daggerdbl',
  6175. 'periodcentered',
  6176. 'paragraph',
  6177. 'bullet',
  6178. 'quotesinglbase',
  6179. 'quotedblbase',
  6180. 'quotedblright',
  6181. 'guillemotright',
  6182. 'ellipsis',
  6183. 'perthousand',
  6184. 'questiondown',
  6185. 'grave',
  6186. 'acute',
  6187. 'circumflex',
  6188. 'tilde',
  6189. 'macron',
  6190. 'breve',
  6191. 'dotaccent',
  6192. 'dieresis',
  6193. 'ring',
  6194. 'cedilla',
  6195. 'hungarumlaut',
  6196. 'ogonek',
  6197. 'caron',
  6198. 'emdash',
  6199. 'AE',
  6200. 'ordfeminine',
  6201. 'Lslash',
  6202. 'Oslash',
  6203. 'OE',
  6204. 'ordmasculine',
  6205. 'ae',
  6206. 'dotlessi',
  6207. 'lslash',
  6208. 'oslash',
  6209. 'oe',
  6210. 'germandbls',
  6211. 'onesuperior',
  6212. 'logicalnot',
  6213. 'mu',
  6214. 'trademark',
  6215. 'Eth',
  6216. 'onehalf',
  6217. 'plusminus',
  6218. 'Thorn',
  6219. 'onequarter',
  6220. 'divide',
  6221. 'brokenbar',
  6222. 'degree',
  6223. 'thorn',
  6224. 'threequarters',
  6225. 'twosuperior',
  6226. 'registered',
  6227. 'minus',
  6228. 'eth',
  6229. 'multiply',
  6230. 'threesuperior',
  6231. 'copyright',
  6232. 'Aacute',
  6233. 'Acircumflex',
  6234. 'Adieresis',
  6235. 'Agrave',
  6236. 'Aring',
  6237. 'Atilde',
  6238. 'Ccedilla',
  6239. 'Eacute',
  6240. 'Ecircumflex',
  6241. 'Edieresis',
  6242. 'Egrave',
  6243. 'Iacute',
  6244. 'Icircumflex',
  6245. 'Idieresis',
  6246. 'Igrave',
  6247. 'Ntilde',
  6248. 'Oacute',
  6249. 'Ocircumflex',
  6250. 'Odieresis',
  6251. 'Ograve',
  6252. 'Otilde',
  6253. 'Scaron',
  6254. 'Uacute',
  6255. 'Ucircumflex',
  6256. 'Udieresis',
  6257. 'Ugrave',
  6258. 'Yacute',
  6259. 'Ydieresis',
  6260. 'Zcaron',
  6261. 'aacute',
  6262. 'acircumflex',
  6263. 'adieresis',
  6264. 'agrave',
  6265. 'aring',
  6266. 'atilde',
  6267. 'ccedilla',
  6268. 'eacute',
  6269. 'ecircumflex',
  6270. 'edieresis',
  6271. 'egrave',
  6272. 'iacute',
  6273. 'icircumflex',
  6274. 'idieresis',
  6275. 'igrave',
  6276. 'ntilde',
  6277. 'oacute',
  6278. 'ocircumflex',
  6279. 'odieresis',
  6280. 'ograve',
  6281. 'otilde',
  6282. 'scaron',
  6283. 'uacute',
  6284. 'ucircumflex',
  6285. 'udieresis',
  6286. 'ugrave',
  6287. 'yacute',
  6288. 'ydieresis',
  6289. 'zcaron',
  6290. 'exclamsmall',
  6291. 'Hungarumlautsmall',
  6292. 'dollaroldstyle',
  6293. 'dollarsuperior',
  6294. 'ampersandsmall',
  6295. 'Acutesmall',
  6296. 'parenleftsuperior',
  6297. 'parenrightsuperior',
  6298. 'twodotenleader',
  6299. 'onedotenleader',
  6300. 'zerooldstyle',
  6301. 'oneoldstyle',
  6302. 'twooldstyle',
  6303. 'threeoldstyle',
  6304. 'fouroldstyle',
  6305. 'fiveoldstyle',
  6306. 'sixoldstyle',
  6307. 'sevenoldstyle',
  6308. 'eightoldstyle',
  6309. 'nineoldstyle',
  6310. 'commasuperior',
  6311. 'threequartersemdash',
  6312. 'periodsuperior',
  6313. 'questionsmall',
  6314. 'asuperior',
  6315. 'bsuperior',
  6316. 'centsuperior',
  6317. 'dsuperior',
  6318. 'esuperior',
  6319. 'isuperior',
  6320. 'lsuperior',
  6321. 'msuperior',
  6322. 'nsuperior',
  6323. 'osuperior',
  6324. 'rsuperior',
  6325. 'ssuperior',
  6326. 'tsuperior',
  6327. 'ff',
  6328. 'ffi',
  6329. 'ffl',
  6330. 'parenleftinferior',
  6331. 'parenrightinferior',
  6332. 'Circumflexsmall',
  6333. 'hyphensuperior',
  6334. 'Gravesmall',
  6335. 'Asmall',
  6336. 'Bsmall',
  6337. 'Csmall',
  6338. 'Dsmall',
  6339. 'Esmall',
  6340. 'Fsmall',
  6341. 'Gsmall',
  6342. 'Hsmall',
  6343. 'Ismall',
  6344. 'Jsmall',
  6345. 'Ksmall',
  6346. 'Lsmall',
  6347. 'Msmall',
  6348. 'Nsmall',
  6349. 'Osmall',
  6350. 'Psmall',
  6351. 'Qsmall',
  6352. 'Rsmall',
  6353. 'Ssmall',
  6354. 'Tsmall',
  6355. 'Usmall',
  6356. 'Vsmall',
  6357. 'Wsmall',
  6358. 'Xsmall',
  6359. 'Ysmall',
  6360. 'Zsmall',
  6361. 'colonmonetary',
  6362. 'onefitted',
  6363. 'rupiah',
  6364. 'Tildesmall',
  6365. 'exclamdownsmall',
  6366. 'centoldstyle',
  6367. 'Lslashsmall',
  6368. 'Scaronsmall',
  6369. 'Zcaronsmall',
  6370. 'Dieresissmall',
  6371. 'Brevesmall',
  6372. 'Caronsmall',
  6373. 'Dotaccentsmall',
  6374. 'Macronsmall',
  6375. 'figuredash',
  6376. 'hypheninferior',
  6377. 'Ogoneksmall',
  6378. 'Ringsmall',
  6379. 'Cedillasmall',
  6380. 'questiondownsmall',
  6381. 'oneeighth',
  6382. 'threeeighths',
  6383. 'fiveeighths',
  6384. 'seveneighths',
  6385. 'onethird',
  6386. 'twothirds',
  6387. 'zerosuperior',
  6388. 'foursuperior',
  6389. 'fivesuperior',
  6390. 'sixsuperior',
  6391. 'sevensuperior',
  6392. 'eightsuperior',
  6393. 'ninesuperior',
  6394. 'zeroinferior',
  6395. 'oneinferior',
  6396. 'twoinferior',
  6397. 'threeinferior',
  6398. 'fourinferior',
  6399. 'fiveinferior',
  6400. 'sixinferior',
  6401. 'seveninferior',
  6402. 'eightinferior',
  6403. 'nineinferior',
  6404. 'centinferior',
  6405. 'dollarinferior',
  6406. 'periodinferior',
  6407. 'commainferior',
  6408. 'Agravesmall',
  6409. 'Aacutesmall',
  6410. 'Acircumflexsmall',
  6411. 'Atildesmall',
  6412. 'Adieresissmall',
  6413. 'Aringsmall',
  6414. 'AEsmall',
  6415. 'Ccedillasmall',
  6416. 'Egravesmall',
  6417. 'Eacutesmall',
  6418. 'Ecircumflexsmall',
  6419. 'Edieresissmall',
  6420. 'Igravesmall',
  6421. 'Iacutesmall',
  6422. 'Icircumflexsmall',
  6423. 'Idieresissmall',
  6424. 'Ethsmall',
  6425. 'Ntildesmall',
  6426. 'Ogravesmall',
  6427. 'Oacutesmall',
  6428. 'Ocircumflexsmall',
  6429. 'Otildesmall',
  6430. 'Odieresissmall',
  6431. 'OEsmall',
  6432. 'Oslashsmall',
  6433. 'Ugravesmall',
  6434. 'Uacutesmall',
  6435. 'Ucircumflexsmall',
  6436. 'Udieresissmall',
  6437. 'Yacutesmall',
  6438. 'Thornsmall',
  6439. 'Ydieresissmall',
  6440. '001.000',
  6441. '001.001',
  6442. '001.002',
  6443. '001.003',
  6444. 'Black',
  6445. 'Bold',
  6446. 'Book',
  6447. 'Light',
  6448. 'Medium',
  6449. 'Regular',
  6450. 'Roman',
  6451. 'Semibold'
  6452. ];
  6453. var CFFParser = function CFFParserClosure() {
  6454. var CharstringValidationData = [
  6455. null,
  6456. {
  6457. id: 'hstem',
  6458. min: 2,
  6459. stackClearing: true,
  6460. stem: true
  6461. },
  6462. null,
  6463. {
  6464. id: 'vstem',
  6465. min: 2,
  6466. stackClearing: true,
  6467. stem: true
  6468. },
  6469. {
  6470. id: 'vmoveto',
  6471. min: 1,
  6472. stackClearing: true
  6473. },
  6474. {
  6475. id: 'rlineto',
  6476. min: 2,
  6477. resetStack: true
  6478. },
  6479. {
  6480. id: 'hlineto',
  6481. min: 1,
  6482. resetStack: true
  6483. },
  6484. {
  6485. id: 'vlineto',
  6486. min: 1,
  6487. resetStack: true
  6488. },
  6489. {
  6490. id: 'rrcurveto',
  6491. min: 6,
  6492. resetStack: true
  6493. },
  6494. null,
  6495. {
  6496. id: 'callsubr',
  6497. min: 1,
  6498. undefStack: true
  6499. },
  6500. {
  6501. id: 'return',
  6502. min: 0,
  6503. undefStack: true
  6504. },
  6505. null,
  6506. // 12
  6507. null,
  6508. {
  6509. id: 'endchar',
  6510. min: 0,
  6511. stackClearing: true
  6512. },
  6513. null,
  6514. null,
  6515. null,
  6516. {
  6517. id: 'hstemhm',
  6518. min: 2,
  6519. stackClearing: true,
  6520. stem: true
  6521. },
  6522. {
  6523. id: 'hintmask',
  6524. min: 0,
  6525. stackClearing: true
  6526. },
  6527. {
  6528. id: 'cntrmask',
  6529. min: 0,
  6530. stackClearing: true
  6531. },
  6532. {
  6533. id: 'rmoveto',
  6534. min: 2,
  6535. stackClearing: true
  6536. },
  6537. {
  6538. id: 'hmoveto',
  6539. min: 1,
  6540. stackClearing: true
  6541. },
  6542. {
  6543. id: 'vstemhm',
  6544. min: 2,
  6545. stackClearing: true,
  6546. stem: true
  6547. },
  6548. {
  6549. id: 'rcurveline',
  6550. min: 8,
  6551. resetStack: true
  6552. },
  6553. {
  6554. id: 'rlinecurve',
  6555. min: 8,
  6556. resetStack: true
  6557. },
  6558. {
  6559. id: 'vvcurveto',
  6560. min: 4,
  6561. resetStack: true
  6562. },
  6563. {
  6564. id: 'hhcurveto',
  6565. min: 4,
  6566. resetStack: true
  6567. },
  6568. null,
  6569. // shortint
  6570. {
  6571. id: 'callgsubr',
  6572. min: 1,
  6573. undefStack: true
  6574. },
  6575. {
  6576. id: 'vhcurveto',
  6577. min: 4,
  6578. resetStack: true
  6579. },
  6580. {
  6581. id: 'hvcurveto',
  6582. min: 4,
  6583. resetStack: true
  6584. }
  6585. ];
  6586. var CharstringValidationData12 = [
  6587. null,
  6588. null,
  6589. null,
  6590. {
  6591. id: 'and',
  6592. min: 2,
  6593. stackDelta: -1
  6594. },
  6595. {
  6596. id: 'or',
  6597. min: 2,
  6598. stackDelta: -1
  6599. },
  6600. {
  6601. id: 'not',
  6602. min: 1,
  6603. stackDelta: 0
  6604. },
  6605. null,
  6606. null,
  6607. null,
  6608. {
  6609. id: 'abs',
  6610. min: 1,
  6611. stackDelta: 0
  6612. },
  6613. {
  6614. id: 'add',
  6615. min: 2,
  6616. stackDelta: -1,
  6617. stackFn: function stack_div(stack, index) {
  6618. stack[index - 2] = stack[index - 2] + stack[index - 1];
  6619. }
  6620. },
  6621. {
  6622. id: 'sub',
  6623. min: 2,
  6624. stackDelta: -1,
  6625. stackFn: function stack_div(stack, index) {
  6626. stack[index - 2] = stack[index - 2] - stack[index - 1];
  6627. }
  6628. },
  6629. {
  6630. id: 'div',
  6631. min: 2,
  6632. stackDelta: -1,
  6633. stackFn: function stack_div(stack, index) {
  6634. stack[index - 2] = stack[index - 2] / stack[index - 1];
  6635. }
  6636. },
  6637. null,
  6638. {
  6639. id: 'neg',
  6640. min: 1,
  6641. stackDelta: 0,
  6642. stackFn: function stack_div(stack, index) {
  6643. stack[index - 1] = -stack[index - 1];
  6644. }
  6645. },
  6646. {
  6647. id: 'eq',
  6648. min: 2,
  6649. stackDelta: -1
  6650. },
  6651. null,
  6652. null,
  6653. {
  6654. id: 'drop',
  6655. min: 1,
  6656. stackDelta: -1
  6657. },
  6658. null,
  6659. {
  6660. id: 'put',
  6661. min: 2,
  6662. stackDelta: -2
  6663. },
  6664. {
  6665. id: 'get',
  6666. min: 1,
  6667. stackDelta: 0
  6668. },
  6669. {
  6670. id: 'ifelse',
  6671. min: 4,
  6672. stackDelta: -3
  6673. },
  6674. {
  6675. id: 'random',
  6676. min: 0,
  6677. stackDelta: 1
  6678. },
  6679. {
  6680. id: 'mul',
  6681. min: 2,
  6682. stackDelta: -1,
  6683. stackFn: function stack_div(stack, index) {
  6684. stack[index - 2] = stack[index - 2] * stack[index - 1];
  6685. }
  6686. },
  6687. null,
  6688. {
  6689. id: 'sqrt',
  6690. min: 1,
  6691. stackDelta: 0
  6692. },
  6693. {
  6694. id: 'dup',
  6695. min: 1,
  6696. stackDelta: 1
  6697. },
  6698. {
  6699. id: 'exch',
  6700. min: 2,
  6701. stackDelta: 0
  6702. },
  6703. {
  6704. id: 'index',
  6705. min: 2,
  6706. stackDelta: 0
  6707. },
  6708. {
  6709. id: 'roll',
  6710. min: 3,
  6711. stackDelta: -2
  6712. },
  6713. null,
  6714. null,
  6715. null,
  6716. {
  6717. id: 'hflex',
  6718. min: 7,
  6719. resetStack: true
  6720. },
  6721. {
  6722. id: 'flex',
  6723. min: 13,
  6724. resetStack: true
  6725. },
  6726. {
  6727. id: 'hflex1',
  6728. min: 9,
  6729. resetStack: true
  6730. },
  6731. {
  6732. id: 'flex1',
  6733. min: 11,
  6734. resetStack: true
  6735. }
  6736. ];
  6737. function CFFParser(file, properties, seacAnalysisEnabled) {
  6738. this.bytes = file.getBytes();
  6739. this.properties = properties;
  6740. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  6741. }
  6742. CFFParser.prototype = {
  6743. parse: function CFFParser_parse() {
  6744. var properties = this.properties;
  6745. var cff = new CFF();
  6746. this.cff = cff;
  6747. // The first five sections must be in order, all the others are reached
  6748. // via offsets contained in one of the below.
  6749. var header = this.parseHeader();
  6750. var nameIndex = this.parseIndex(header.endPos);
  6751. var topDictIndex = this.parseIndex(nameIndex.endPos);
  6752. var stringIndex = this.parseIndex(topDictIndex.endPos);
  6753. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  6754. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  6755. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  6756. cff.header = header.obj;
  6757. cff.names = this.parseNameIndex(nameIndex.obj);
  6758. cff.strings = this.parseStringIndex(stringIndex.obj);
  6759. cff.topDict = topDict;
  6760. cff.globalSubrIndex = globalSubrIndex.obj;
  6761. this.parsePrivateDict(cff.topDict);
  6762. cff.isCIDFont = topDict.hasName('ROS');
  6763. var charStringOffset = topDict.getByName('CharStrings');
  6764. var charStringIndex = this.parseIndex(charStringOffset).obj;
  6765. var fontMatrix = topDict.getByName('FontMatrix');
  6766. if (fontMatrix) {
  6767. properties.fontMatrix = fontMatrix;
  6768. }
  6769. var fontBBox = topDict.getByName('FontBBox');
  6770. if (fontBBox) {
  6771. // adjusting ascent/descent
  6772. properties.ascent = fontBBox[3];
  6773. properties.descent = fontBBox[1];
  6774. properties.ascentScaled = true;
  6775. }
  6776. var charset, encoding;
  6777. if (cff.isCIDFont) {
  6778. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  6779. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  6780. var dictRaw = fdArrayIndex.get(i);
  6781. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  6782. this.parsePrivateDict(fontDict);
  6783. cff.fdArray.push(fontDict);
  6784. }
  6785. // cid fonts don't have an encoding
  6786. encoding = null;
  6787. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, true);
  6788. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'), charStringIndex.count);
  6789. } else {
  6790. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, false);
  6791. encoding = this.parseEncoding(topDict.getByName('Encoding'), properties, cff.strings, charset.charset);
  6792. }
  6793. cff.charset = charset;
  6794. cff.encoding = encoding;
  6795. var charStringsAndSeacs = this.parseCharStrings(charStringIndex, topDict.privateDict.subrsIndex, globalSubrIndex.obj, cff.fdSelect, cff.fdArray);
  6796. cff.charStrings = charStringsAndSeacs.charStrings;
  6797. cff.seacs = charStringsAndSeacs.seacs;
  6798. cff.widths = charStringsAndSeacs.widths;
  6799. return cff;
  6800. },
  6801. parseHeader: function CFFParser_parseHeader() {
  6802. var bytes = this.bytes;
  6803. var bytesLength = bytes.length;
  6804. var offset = 0;
  6805. // Prevent an infinite loop, by checking that the offset is within the
  6806. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  6807. while (offset < bytesLength && bytes[offset] !== 1) {
  6808. ++offset;
  6809. }
  6810. if (offset >= bytesLength) {
  6811. error('Invalid CFF header');
  6812. } else if (offset !== 0) {
  6813. info('cff data is shifted');
  6814. bytes = bytes.subarray(offset);
  6815. this.bytes = bytes;
  6816. }
  6817. var major = bytes[0];
  6818. var minor = bytes[1];
  6819. var hdrSize = bytes[2];
  6820. var offSize = bytes[3];
  6821. var header = new CFFHeader(major, minor, hdrSize, offSize);
  6822. return {
  6823. obj: header,
  6824. endPos: hdrSize
  6825. };
  6826. },
  6827. parseDict: function CFFParser_parseDict(dict) {
  6828. var pos = 0;
  6829. function parseOperand() {
  6830. var value = dict[pos++];
  6831. if (value === 30) {
  6832. return parseFloatOperand();
  6833. } else if (value === 28) {
  6834. value = dict[pos++];
  6835. value = (value << 24 | dict[pos++] << 16) >> 16;
  6836. return value;
  6837. } else if (value === 29) {
  6838. value = dict[pos++];
  6839. value = value << 8 | dict[pos++];
  6840. value = value << 8 | dict[pos++];
  6841. value = value << 8 | dict[pos++];
  6842. return value;
  6843. } else if (value >= 32 && value <= 246) {
  6844. return value - 139;
  6845. } else if (value >= 247 && value <= 250) {
  6846. return (value - 247) * 256 + dict[pos++] + 108;
  6847. } else if (value >= 251 && value <= 254) {
  6848. return -((value - 251) * 256) - dict[pos++] - 108;
  6849. } else {
  6850. error('255 is not a valid DICT command');
  6851. }
  6852. return -1;
  6853. }
  6854. function parseFloatOperand() {
  6855. var str = '';
  6856. var eof = 15;
  6857. var lookup = [
  6858. '0',
  6859. '1',
  6860. '2',
  6861. '3',
  6862. '4',
  6863. '5',
  6864. '6',
  6865. '7',
  6866. '8',
  6867. '9',
  6868. '.',
  6869. 'E',
  6870. 'E-',
  6871. null,
  6872. '-'
  6873. ];
  6874. var length = dict.length;
  6875. while (pos < length) {
  6876. var b = dict[pos++];
  6877. var b1 = b >> 4;
  6878. var b2 = b & 15;
  6879. if (b1 === eof) {
  6880. break;
  6881. }
  6882. str += lookup[b1];
  6883. if (b2 === eof) {
  6884. break;
  6885. }
  6886. str += lookup[b2];
  6887. }
  6888. return parseFloat(str);
  6889. }
  6890. var operands = [];
  6891. var entries = [];
  6892. pos = 0;
  6893. var end = dict.length;
  6894. while (pos < end) {
  6895. var b = dict[pos];
  6896. if (b <= 21) {
  6897. if (b === 12) {
  6898. b = b << 8 | dict[++pos];
  6899. }
  6900. entries.push([
  6901. b,
  6902. operands
  6903. ]);
  6904. operands = [];
  6905. ++pos;
  6906. } else {
  6907. operands.push(parseOperand());
  6908. }
  6909. }
  6910. return entries;
  6911. },
  6912. parseIndex: function CFFParser_parseIndex(pos) {
  6913. var cffIndex = new CFFIndex();
  6914. var bytes = this.bytes;
  6915. var count = bytes[pos++] << 8 | bytes[pos++];
  6916. var offsets = [];
  6917. var end = pos;
  6918. var i, ii;
  6919. if (count !== 0) {
  6920. var offsetSize = bytes[pos++];
  6921. // add 1 for offset to determine size of last object
  6922. var startPos = pos + (count + 1) * offsetSize - 1;
  6923. for (i = 0, ii = count + 1; i < ii; ++i) {
  6924. var offset = 0;
  6925. for (var j = 0; j < offsetSize; ++j) {
  6926. offset <<= 8;
  6927. offset += bytes[pos++];
  6928. }
  6929. offsets.push(startPos + offset);
  6930. }
  6931. end = offsets[count];
  6932. }
  6933. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  6934. var offsetStart = offsets[i];
  6935. var offsetEnd = offsets[i + 1];
  6936. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  6937. }
  6938. return {
  6939. obj: cffIndex,
  6940. endPos: end
  6941. };
  6942. },
  6943. parseNameIndex: function CFFParser_parseNameIndex(index) {
  6944. var names = [];
  6945. for (var i = 0, ii = index.count; i < ii; ++i) {
  6946. var name = index.get(i);
  6947. // OTS doesn't allow names to be over 127 characters.
  6948. var length = Math.min(name.length, 127);
  6949. var data = [];
  6950. // OTS also only permits certain characters in the name.
  6951. for (var j = 0; j < length; ++j) {
  6952. var c = name[j];
  6953. if (j === 0 && c === 0) {
  6954. data[j] = c;
  6955. continue;
  6956. }
  6957. if (c < 33 || c > 126 || c === 91 || /* [ */
  6958. c === 93 || /* ] */
  6959. c === 40 || /* ( */
  6960. c === 41 || /* ) */
  6961. c === 123 || /* { */
  6962. c === 125 || /* } */
  6963. c === 60 || /* < */
  6964. c === 62 || /* > */
  6965. c === 47 || /* / */
  6966. c === 37 || /* % */
  6967. c === 35)
  6968. /* # */
  6969. {
  6970. data[j] = 95;
  6971. continue;
  6972. }
  6973. data[j] = c;
  6974. }
  6975. names.push(bytesToString(data));
  6976. }
  6977. return names;
  6978. },
  6979. parseStringIndex: function CFFParser_parseStringIndex(index) {
  6980. var strings = new CFFStrings();
  6981. for (var i = 0, ii = index.count; i < ii; ++i) {
  6982. var data = index.get(i);
  6983. strings.add(bytesToString(data));
  6984. }
  6985. return strings;
  6986. },
  6987. createDict: function CFFParser_createDict(Type, dict, strings) {
  6988. var cffDict = new Type(strings);
  6989. for (var i = 0, ii = dict.length; i < ii; ++i) {
  6990. var pair = dict[i];
  6991. var key = pair[0];
  6992. var value = pair[1];
  6993. cffDict.setByKey(key, value);
  6994. }
  6995. return cffDict;
  6996. },
  6997. parseCharString: function CFFParser_parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  6998. if (state.callDepth > MAX_SUBR_NESTING) {
  6999. return false;
  7000. }
  7001. var stackSize = state.stackSize;
  7002. var stack = state.stack;
  7003. var length = data.length;
  7004. for (var j = 0; j < length;) {
  7005. var value = data[j++];
  7006. var validationCommand = null;
  7007. if (value === 12) {
  7008. var q = data[j++];
  7009. if (q === 0) {
  7010. // The CFF specification state that the 'dotsection' command
  7011. // (12, 0) is deprecated and treated as a no-op, but all Type2
  7012. // charstrings processors should support them. Unfortunately
  7013. // the font sanitizer don't. As a workaround the sequence (12, 0)
  7014. // is replaced by a useless (0, hmoveto).
  7015. data[j - 2] = 139;
  7016. data[j - 1] = 22;
  7017. stackSize = 0;
  7018. } else {
  7019. validationCommand = CharstringValidationData12[q];
  7020. }
  7021. } else if (value === 28) {
  7022. // number (16 bit)
  7023. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  7024. j += 2;
  7025. stackSize++;
  7026. } else if (value === 14) {
  7027. if (stackSize >= 4) {
  7028. stackSize -= 4;
  7029. if (this.seacAnalysisEnabled) {
  7030. state.seac = stack.slice(stackSize, stackSize + 4);
  7031. return false;
  7032. }
  7033. }
  7034. validationCommand = CharstringValidationData[value];
  7035. } else if (value >= 32 && value <= 246) {
  7036. // number
  7037. stack[stackSize] = value - 139;
  7038. stackSize++;
  7039. } else if (value >= 247 && value <= 254) {
  7040. // number (+1 bytes)
  7041. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  7042. j++;
  7043. stackSize++;
  7044. } else if (value === 255) {
  7045. // number (32 bit)
  7046. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  7047. j += 4;
  7048. stackSize++;
  7049. } else if (value === 19 || value === 20) {
  7050. state.hints += stackSize >> 1;
  7051. // skipping right amount of hints flag data
  7052. j += state.hints + 7 >> 3;
  7053. stackSize %= 2;
  7054. validationCommand = CharstringValidationData[value];
  7055. } else if (value === 10 || value === 29) {
  7056. var subrsIndex;
  7057. if (value === 10) {
  7058. subrsIndex = localSubrIndex;
  7059. } else {
  7060. subrsIndex = globalSubrIndex;
  7061. }
  7062. if (!subrsIndex) {
  7063. validationCommand = CharstringValidationData[value];
  7064. warn('Missing subrsIndex for ' + validationCommand.id);
  7065. return false;
  7066. }
  7067. var bias = 32768;
  7068. if (subrsIndex.count < 1240) {
  7069. bias = 107;
  7070. } else if (subrsIndex.count < 33900) {
  7071. bias = 1131;
  7072. }
  7073. var subrNumber = stack[--stackSize] + bias;
  7074. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  7075. validationCommand = CharstringValidationData[value];
  7076. warn('Out of bounds subrIndex for ' + validationCommand.id);
  7077. return false;
  7078. }
  7079. state.stackSize = stackSize;
  7080. state.callDepth++;
  7081. var valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  7082. if (!valid) {
  7083. return false;
  7084. }
  7085. state.callDepth--;
  7086. stackSize = state.stackSize;
  7087. continue;
  7088. } else if (value === 11) {
  7089. state.stackSize = stackSize;
  7090. return true;
  7091. } else {
  7092. validationCommand = CharstringValidationData[value];
  7093. }
  7094. if (validationCommand) {
  7095. if (validationCommand.stem) {
  7096. state.hints += stackSize >> 1;
  7097. }
  7098. if ('min' in validationCommand) {
  7099. if (!state.undefStack && stackSize < validationCommand.min) {
  7100. warn('Not enough parameters for ' + validationCommand.id + '; actual: ' + stackSize + ', expected: ' + validationCommand.min);
  7101. return false;
  7102. }
  7103. }
  7104. if (state.firstStackClearing && validationCommand.stackClearing) {
  7105. state.firstStackClearing = false;
  7106. // the optional character width can be found before the first
  7107. // stack-clearing command arguments
  7108. stackSize -= validationCommand.min;
  7109. if (stackSize >= 2 && validationCommand.stem) {
  7110. // there are even amount of arguments for stem commands
  7111. stackSize %= 2;
  7112. } else if (stackSize > 1) {
  7113. warn('Found too many parameters for stack-clearing command');
  7114. }
  7115. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  7116. state.width = stack[stackSize - 1];
  7117. }
  7118. }
  7119. if ('stackDelta' in validationCommand) {
  7120. if ('stackFn' in validationCommand) {
  7121. validationCommand.stackFn(stack, stackSize);
  7122. }
  7123. stackSize += validationCommand.stackDelta;
  7124. } else if (validationCommand.stackClearing) {
  7125. stackSize = 0;
  7126. } else if (validationCommand.resetStack) {
  7127. stackSize = 0;
  7128. state.undefStack = false;
  7129. } else if (validationCommand.undefStack) {
  7130. stackSize = 0;
  7131. state.undefStack = true;
  7132. state.firstStackClearing = false;
  7133. }
  7134. }
  7135. }
  7136. state.stackSize = stackSize;
  7137. return true;
  7138. },
  7139. parseCharStrings: function CFFParser_parseCharStrings(charStrings, localSubrIndex, globalSubrIndex, fdSelect, fdArray) {
  7140. var seacs = [];
  7141. var widths = [];
  7142. var count = charStrings.count;
  7143. for (var i = 0; i < count; i++) {
  7144. var charstring = charStrings.get(i);
  7145. var state = {
  7146. callDepth: 0,
  7147. stackSize: 0,
  7148. stack: [],
  7149. undefStack: true,
  7150. hints: 0,
  7151. firstStackClearing: true,
  7152. seac: null,
  7153. width: null
  7154. };
  7155. var valid = true;
  7156. var localSubrToUse = null;
  7157. if (fdSelect && fdArray.length) {
  7158. var fdIndex = fdSelect.getFDIndex(i);
  7159. if (fdIndex === -1) {
  7160. warn('Glyph index is not in fd select.');
  7161. valid = false;
  7162. }
  7163. if (fdIndex >= fdArray.length) {
  7164. warn('Invalid fd index for glyph index.');
  7165. valid = false;
  7166. }
  7167. if (valid) {
  7168. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  7169. }
  7170. } else if (localSubrIndex) {
  7171. localSubrToUse = localSubrIndex;
  7172. }
  7173. if (valid) {
  7174. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  7175. }
  7176. if (state.width !== null) {
  7177. widths[i] = state.width;
  7178. }
  7179. if (state.seac !== null) {
  7180. seacs[i] = state.seac;
  7181. }
  7182. if (!valid) {
  7183. // resetting invalid charstring to single 'endchar'
  7184. charStrings.set(i, new Uint8Array([14]));
  7185. }
  7186. }
  7187. return {
  7188. charStrings: charStrings,
  7189. seacs: seacs,
  7190. widths: widths
  7191. };
  7192. },
  7193. emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) {
  7194. var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  7195. parentDict.setByKey(18, [
  7196. 0,
  7197. 0
  7198. ]);
  7199. parentDict.privateDict = privateDict;
  7200. },
  7201. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  7202. // no private dict, do nothing
  7203. if (!parentDict.hasName('Private')) {
  7204. this.emptyPrivateDictionary(parentDict);
  7205. return;
  7206. }
  7207. var privateOffset = parentDict.getByName('Private');
  7208. // make sure the params are formatted correctly
  7209. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  7210. parentDict.removeByName('Private');
  7211. return;
  7212. }
  7213. var size = privateOffset[0];
  7214. var offset = privateOffset[1];
  7215. // remove empty dicts or ones that refer to invalid location
  7216. if (size === 0 || offset >= this.bytes.length) {
  7217. this.emptyPrivateDictionary(parentDict);
  7218. return;
  7219. }
  7220. var privateDictEnd = offset + size;
  7221. var dictData = this.bytes.subarray(offset, privateDictEnd);
  7222. var dict = this.parseDict(dictData);
  7223. var privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  7224. parentDict.privateDict = privateDict;
  7225. // Parse the Subrs index also since it's relative to the private dict.
  7226. if (!privateDict.getByName('Subrs')) {
  7227. return;
  7228. }
  7229. var subrsOffset = privateDict.getByName('Subrs');
  7230. var relativeOffset = offset + subrsOffset;
  7231. // Validate the offset.
  7232. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  7233. this.emptyPrivateDictionary(parentDict);
  7234. return;
  7235. }
  7236. var subrsIndex = this.parseIndex(relativeOffset);
  7237. privateDict.subrsIndex = subrsIndex.obj;
  7238. },
  7239. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  7240. if (pos === 0) {
  7241. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  7242. } else if (pos === 1) {
  7243. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  7244. } else if (pos === 2) {
  7245. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  7246. }
  7247. var bytes = this.bytes;
  7248. var start = pos;
  7249. var format = bytes[pos++];
  7250. var charset = ['.notdef'];
  7251. var id, count, i;
  7252. // subtract 1 for the .notdef glyph
  7253. length -= 1;
  7254. switch (format) {
  7255. case 0:
  7256. for (i = 0; i < length; i++) {
  7257. id = bytes[pos++] << 8 | bytes[pos++];
  7258. charset.push(cid ? id : strings.get(id));
  7259. }
  7260. break;
  7261. case 1:
  7262. while (charset.length <= length) {
  7263. id = bytes[pos++] << 8 | bytes[pos++];
  7264. count = bytes[pos++];
  7265. for (i = 0; i <= count; i++) {
  7266. charset.push(cid ? id++ : strings.get(id++));
  7267. }
  7268. }
  7269. break;
  7270. case 2:
  7271. while (charset.length <= length) {
  7272. id = bytes[pos++] << 8 | bytes[pos++];
  7273. count = bytes[pos++] << 8 | bytes[pos++];
  7274. for (i = 0; i <= count; i++) {
  7275. charset.push(cid ? id++ : strings.get(id++));
  7276. }
  7277. }
  7278. break;
  7279. default:
  7280. error('Unknown charset format');
  7281. }
  7282. // Raw won't be needed if we actually compile the charset.
  7283. var end = pos;
  7284. var raw = bytes.subarray(start, end);
  7285. return new CFFCharset(false, format, charset, raw);
  7286. },
  7287. parseEncoding: function CFFParser_parseEncoding(pos, properties, strings, charset) {
  7288. var encoding = Object.create(null);
  7289. var bytes = this.bytes;
  7290. var predefined = false;
  7291. var hasSupplement = false;
  7292. var format, i, ii;
  7293. var raw = null;
  7294. function readSupplement() {
  7295. var supplementsCount = bytes[pos++];
  7296. for (i = 0; i < supplementsCount; i++) {
  7297. var code = bytes[pos++];
  7298. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  7299. encoding[code] = charset.indexOf(strings.get(sid));
  7300. }
  7301. }
  7302. if (pos === 0 || pos === 1) {
  7303. predefined = true;
  7304. format = pos;
  7305. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  7306. for (i = 0, ii = charset.length; i < ii; i++) {
  7307. var index = baseEncoding.indexOf(charset[i]);
  7308. if (index !== -1) {
  7309. encoding[index] = i;
  7310. }
  7311. }
  7312. } else {
  7313. var dataStart = pos;
  7314. format = bytes[pos++];
  7315. switch (format & 0x7f) {
  7316. case 0:
  7317. var glyphsCount = bytes[pos++];
  7318. for (i = 1; i <= glyphsCount; i++) {
  7319. encoding[bytes[pos++]] = i;
  7320. }
  7321. break;
  7322. case 1:
  7323. var rangesCount = bytes[pos++];
  7324. var gid = 1;
  7325. for (i = 0; i < rangesCount; i++) {
  7326. var start = bytes[pos++];
  7327. var left = bytes[pos++];
  7328. for (var j = start; j <= start + left; j++) {
  7329. encoding[j] = gid++;
  7330. }
  7331. }
  7332. break;
  7333. default:
  7334. error('Unknown encoding format: ' + format + ' in CFF');
  7335. break;
  7336. }
  7337. var dataEnd = pos;
  7338. if (format & 0x80) {
  7339. // The font sanitizer does not support CFF encoding with a
  7340. // supplement, since the encoding is not really used to map
  7341. // between gid to glyph, let's overwrite what is declared in
  7342. // the top dictionary to let the sanitizer think the font use
  7343. // StandardEncoding, that's a lie but that's ok.
  7344. bytes[dataStart] &= 0x7f;
  7345. readSupplement();
  7346. hasSupplement = true;
  7347. }
  7348. raw = bytes.subarray(dataStart, dataEnd);
  7349. }
  7350. format = format & 0x7f;
  7351. return new CFFEncoding(predefined, format, encoding, raw);
  7352. },
  7353. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  7354. var start = pos;
  7355. var bytes = this.bytes;
  7356. var format = bytes[pos++];
  7357. var fdSelect = [], rawBytes;
  7358. var i, invalidFirstGID = false;
  7359. switch (format) {
  7360. case 0:
  7361. for (i = 0; i < length; ++i) {
  7362. var id = bytes[pos++];
  7363. fdSelect.push(id);
  7364. }
  7365. rawBytes = bytes.subarray(start, pos);
  7366. break;
  7367. case 3:
  7368. var rangesCount = bytes[pos++] << 8 | bytes[pos++];
  7369. for (i = 0; i < rangesCount; ++i) {
  7370. var first = bytes[pos++] << 8 | bytes[pos++];
  7371. if (i === 0 && first !== 0) {
  7372. warn('parseFDSelect: The first range must have a first GID of 0' + ' -- trying to recover.');
  7373. invalidFirstGID = true;
  7374. first = 0;
  7375. }
  7376. var fdIndex = bytes[pos++];
  7377. var next = bytes[pos] << 8 | bytes[pos + 1];
  7378. for (var j = first; j < next; ++j) {
  7379. fdSelect.push(fdIndex);
  7380. }
  7381. }
  7382. // Advance past the sentinel(next).
  7383. pos += 2;
  7384. rawBytes = bytes.subarray(start, pos);
  7385. if (invalidFirstGID) {
  7386. rawBytes[3] = rawBytes[4] = 0;
  7387. }
  7388. // Adjust the first range, first GID.
  7389. break;
  7390. default:
  7391. error('parseFDSelect: Unknown format "' + format + '".');
  7392. break;
  7393. }
  7394. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  7395. return new CFFFDSelect(fdSelect, rawBytes);
  7396. }
  7397. };
  7398. return CFFParser;
  7399. }();
  7400. // Compact Font Format
  7401. var CFF = function CFFClosure() {
  7402. function CFF() {
  7403. this.header = null;
  7404. this.names = [];
  7405. this.topDict = null;
  7406. this.strings = new CFFStrings();
  7407. this.globalSubrIndex = null;
  7408. // The following could really be per font, but since we only have one font
  7409. // store them here.
  7410. this.encoding = null;
  7411. this.charset = null;
  7412. this.charStrings = null;
  7413. this.fdArray = [];
  7414. this.fdSelect = null;
  7415. this.isCIDFont = false;
  7416. }
  7417. return CFF;
  7418. }();
  7419. var CFFHeader = function CFFHeaderClosure() {
  7420. function CFFHeader(major, minor, hdrSize, offSize) {
  7421. this.major = major;
  7422. this.minor = minor;
  7423. this.hdrSize = hdrSize;
  7424. this.offSize = offSize;
  7425. }
  7426. return CFFHeader;
  7427. }();
  7428. var CFFStrings = function CFFStringsClosure() {
  7429. function CFFStrings() {
  7430. this.strings = [];
  7431. }
  7432. CFFStrings.prototype = {
  7433. get: function CFFStrings_get(index) {
  7434. if (index >= 0 && index <= 390) {
  7435. return CFFStandardStrings[index];
  7436. }
  7437. if (index - 391 <= this.strings.length) {
  7438. return this.strings[index - 391];
  7439. }
  7440. return CFFStandardStrings[0];
  7441. },
  7442. add: function CFFStrings_add(value) {
  7443. this.strings.push(value);
  7444. },
  7445. get count() {
  7446. return this.strings.length;
  7447. }
  7448. };
  7449. return CFFStrings;
  7450. }();
  7451. var CFFIndex = function CFFIndexClosure() {
  7452. function CFFIndex() {
  7453. this.objects = [];
  7454. this.length = 0;
  7455. }
  7456. CFFIndex.prototype = {
  7457. add: function CFFIndex_add(data) {
  7458. this.length += data.length;
  7459. this.objects.push(data);
  7460. },
  7461. set: function CFFIndex_set(index, data) {
  7462. this.length += data.length - this.objects[index].length;
  7463. this.objects[index] = data;
  7464. },
  7465. get: function CFFIndex_get(index) {
  7466. return this.objects[index];
  7467. },
  7468. get count() {
  7469. return this.objects.length;
  7470. }
  7471. };
  7472. return CFFIndex;
  7473. }();
  7474. var CFFDict = function CFFDictClosure() {
  7475. function CFFDict(tables, strings) {
  7476. this.keyToNameMap = tables.keyToNameMap;
  7477. this.nameToKeyMap = tables.nameToKeyMap;
  7478. this.defaults = tables.defaults;
  7479. this.types = tables.types;
  7480. this.opcodes = tables.opcodes;
  7481. this.order = tables.order;
  7482. this.strings = strings;
  7483. this.values = Object.create(null);
  7484. }
  7485. CFFDict.prototype = {
  7486. // value should always be an array
  7487. setByKey: function CFFDict_setByKey(key, value) {
  7488. if (!(key in this.keyToNameMap)) {
  7489. return false;
  7490. }
  7491. // ignore empty values
  7492. if (value.length === 0) {
  7493. return true;
  7494. }
  7495. var type = this.types[key];
  7496. // remove the array wrapping these types of values
  7497. if (type === 'num' || type === 'sid' || type === 'offset') {
  7498. value = value[0];
  7499. // Ignore invalid values (fixes bug 1068432).
  7500. if (isNaN(value)) {
  7501. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  7502. return true;
  7503. }
  7504. }
  7505. this.values[key] = value;
  7506. return true;
  7507. },
  7508. setByName: function CFFDict_setByName(name, value) {
  7509. if (!(name in this.nameToKeyMap)) {
  7510. error('Invalid dictionary name "' + name + '"');
  7511. }
  7512. this.values[this.nameToKeyMap[name]] = value;
  7513. },
  7514. hasName: function CFFDict_hasName(name) {
  7515. return this.nameToKeyMap[name] in this.values;
  7516. },
  7517. getByName: function CFFDict_getByName(name) {
  7518. if (!(name in this.nameToKeyMap)) {
  7519. error('Invalid dictionary name "' + name + '"');
  7520. }
  7521. var key = this.nameToKeyMap[name];
  7522. if (!(key in this.values)) {
  7523. return this.defaults[key];
  7524. }
  7525. return this.values[key];
  7526. },
  7527. removeByName: function CFFDict_removeByName(name) {
  7528. delete this.values[this.nameToKeyMap[name]];
  7529. }
  7530. };
  7531. CFFDict.createTables = function CFFDict_createTables(layout) {
  7532. var tables = {
  7533. keyToNameMap: {},
  7534. nameToKeyMap: {},
  7535. defaults: {},
  7536. types: {},
  7537. opcodes: {},
  7538. order: []
  7539. };
  7540. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7541. var entry = layout[i];
  7542. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7543. tables.keyToNameMap[key] = entry[1];
  7544. tables.nameToKeyMap[entry[1]] = key;
  7545. tables.types[key] = entry[2];
  7546. tables.defaults[key] = entry[3];
  7547. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7548. tables.order.push(key);
  7549. }
  7550. return tables;
  7551. };
  7552. return CFFDict;
  7553. }();
  7554. var CFFTopDict = function CFFTopDictClosure() {
  7555. var layout = [
  7556. [
  7557. [
  7558. 12,
  7559. 30
  7560. ],
  7561. 'ROS',
  7562. [
  7563. 'sid',
  7564. 'sid',
  7565. 'num'
  7566. ],
  7567. null
  7568. ],
  7569. [
  7570. [
  7571. 12,
  7572. 20
  7573. ],
  7574. 'SyntheticBase',
  7575. 'num',
  7576. null
  7577. ],
  7578. [
  7579. 0,
  7580. 'version',
  7581. 'sid',
  7582. null
  7583. ],
  7584. [
  7585. 1,
  7586. 'Notice',
  7587. 'sid',
  7588. null
  7589. ],
  7590. [
  7591. [
  7592. 12,
  7593. 0
  7594. ],
  7595. 'Copyright',
  7596. 'sid',
  7597. null
  7598. ],
  7599. [
  7600. 2,
  7601. 'FullName',
  7602. 'sid',
  7603. null
  7604. ],
  7605. [
  7606. 3,
  7607. 'FamilyName',
  7608. 'sid',
  7609. null
  7610. ],
  7611. [
  7612. 4,
  7613. 'Weight',
  7614. 'sid',
  7615. null
  7616. ],
  7617. [
  7618. [
  7619. 12,
  7620. 1
  7621. ],
  7622. 'isFixedPitch',
  7623. 'num',
  7624. 0
  7625. ],
  7626. [
  7627. [
  7628. 12,
  7629. 2
  7630. ],
  7631. 'ItalicAngle',
  7632. 'num',
  7633. 0
  7634. ],
  7635. [
  7636. [
  7637. 12,
  7638. 3
  7639. ],
  7640. 'UnderlinePosition',
  7641. 'num',
  7642. -100
  7643. ],
  7644. [
  7645. [
  7646. 12,
  7647. 4
  7648. ],
  7649. 'UnderlineThickness',
  7650. 'num',
  7651. 50
  7652. ],
  7653. [
  7654. [
  7655. 12,
  7656. 5
  7657. ],
  7658. 'PaintType',
  7659. 'num',
  7660. 0
  7661. ],
  7662. [
  7663. [
  7664. 12,
  7665. 6
  7666. ],
  7667. 'CharstringType',
  7668. 'num',
  7669. 2
  7670. ],
  7671. [
  7672. [
  7673. 12,
  7674. 7
  7675. ],
  7676. 'FontMatrix',
  7677. [
  7678. 'num',
  7679. 'num',
  7680. 'num',
  7681. 'num',
  7682. 'num',
  7683. 'num'
  7684. ],
  7685. [
  7686. 0.001,
  7687. 0,
  7688. 0,
  7689. 0.001,
  7690. 0,
  7691. 0
  7692. ]
  7693. ],
  7694. [
  7695. 13,
  7696. 'UniqueID',
  7697. 'num',
  7698. null
  7699. ],
  7700. [
  7701. 5,
  7702. 'FontBBox',
  7703. [
  7704. 'num',
  7705. 'num',
  7706. 'num',
  7707. 'num'
  7708. ],
  7709. [
  7710. 0,
  7711. 0,
  7712. 0,
  7713. 0
  7714. ]
  7715. ],
  7716. [
  7717. [
  7718. 12,
  7719. 8
  7720. ],
  7721. 'StrokeWidth',
  7722. 'num',
  7723. 0
  7724. ],
  7725. [
  7726. 14,
  7727. 'XUID',
  7728. 'array',
  7729. null
  7730. ],
  7731. [
  7732. 15,
  7733. 'charset',
  7734. 'offset',
  7735. 0
  7736. ],
  7737. [
  7738. 16,
  7739. 'Encoding',
  7740. 'offset',
  7741. 0
  7742. ],
  7743. [
  7744. 17,
  7745. 'CharStrings',
  7746. 'offset',
  7747. 0
  7748. ],
  7749. [
  7750. 18,
  7751. 'Private',
  7752. [
  7753. 'offset',
  7754. 'offset'
  7755. ],
  7756. null
  7757. ],
  7758. [
  7759. [
  7760. 12,
  7761. 21
  7762. ],
  7763. 'PostScript',
  7764. 'sid',
  7765. null
  7766. ],
  7767. [
  7768. [
  7769. 12,
  7770. 22
  7771. ],
  7772. 'BaseFontName',
  7773. 'sid',
  7774. null
  7775. ],
  7776. [
  7777. [
  7778. 12,
  7779. 23
  7780. ],
  7781. 'BaseFontBlend',
  7782. 'delta',
  7783. null
  7784. ],
  7785. [
  7786. [
  7787. 12,
  7788. 31
  7789. ],
  7790. 'CIDFontVersion',
  7791. 'num',
  7792. 0
  7793. ],
  7794. [
  7795. [
  7796. 12,
  7797. 32
  7798. ],
  7799. 'CIDFontRevision',
  7800. 'num',
  7801. 0
  7802. ],
  7803. [
  7804. [
  7805. 12,
  7806. 33
  7807. ],
  7808. 'CIDFontType',
  7809. 'num',
  7810. 0
  7811. ],
  7812. [
  7813. [
  7814. 12,
  7815. 34
  7816. ],
  7817. 'CIDCount',
  7818. 'num',
  7819. 8720
  7820. ],
  7821. [
  7822. [
  7823. 12,
  7824. 35
  7825. ],
  7826. 'UIDBase',
  7827. 'num',
  7828. null
  7829. ],
  7830. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7831. // before FDArray.
  7832. [
  7833. [
  7834. 12,
  7835. 37
  7836. ],
  7837. 'FDSelect',
  7838. 'offset',
  7839. null
  7840. ],
  7841. [
  7842. [
  7843. 12,
  7844. 36
  7845. ],
  7846. 'FDArray',
  7847. 'offset',
  7848. null
  7849. ],
  7850. [
  7851. [
  7852. 12,
  7853. 38
  7854. ],
  7855. 'FontName',
  7856. 'sid',
  7857. null
  7858. ]
  7859. ];
  7860. var tables = null;
  7861. function CFFTopDict(strings) {
  7862. if (tables === null) {
  7863. tables = CFFDict.createTables(layout);
  7864. }
  7865. CFFDict.call(this, tables, strings);
  7866. this.privateDict = null;
  7867. }
  7868. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7869. return CFFTopDict;
  7870. }();
  7871. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7872. var layout = [
  7873. [
  7874. 6,
  7875. 'BlueValues',
  7876. 'delta',
  7877. null
  7878. ],
  7879. [
  7880. 7,
  7881. 'OtherBlues',
  7882. 'delta',
  7883. null
  7884. ],
  7885. [
  7886. 8,
  7887. 'FamilyBlues',
  7888. 'delta',
  7889. null
  7890. ],
  7891. [
  7892. 9,
  7893. 'FamilyOtherBlues',
  7894. 'delta',
  7895. null
  7896. ],
  7897. [
  7898. [
  7899. 12,
  7900. 9
  7901. ],
  7902. 'BlueScale',
  7903. 'num',
  7904. 0.039625
  7905. ],
  7906. [
  7907. [
  7908. 12,
  7909. 10
  7910. ],
  7911. 'BlueShift',
  7912. 'num',
  7913. 7
  7914. ],
  7915. [
  7916. [
  7917. 12,
  7918. 11
  7919. ],
  7920. 'BlueFuzz',
  7921. 'num',
  7922. 1
  7923. ],
  7924. [
  7925. 10,
  7926. 'StdHW',
  7927. 'num',
  7928. null
  7929. ],
  7930. [
  7931. 11,
  7932. 'StdVW',
  7933. 'num',
  7934. null
  7935. ],
  7936. [
  7937. [
  7938. 12,
  7939. 12
  7940. ],
  7941. 'StemSnapH',
  7942. 'delta',
  7943. null
  7944. ],
  7945. [
  7946. [
  7947. 12,
  7948. 13
  7949. ],
  7950. 'StemSnapV',
  7951. 'delta',
  7952. null
  7953. ],
  7954. [
  7955. [
  7956. 12,
  7957. 14
  7958. ],
  7959. 'ForceBold',
  7960. 'num',
  7961. 0
  7962. ],
  7963. [
  7964. [
  7965. 12,
  7966. 17
  7967. ],
  7968. 'LanguageGroup',
  7969. 'num',
  7970. 0
  7971. ],
  7972. [
  7973. [
  7974. 12,
  7975. 18
  7976. ],
  7977. 'ExpansionFactor',
  7978. 'num',
  7979. 0.06
  7980. ],
  7981. [
  7982. [
  7983. 12,
  7984. 19
  7985. ],
  7986. 'initialRandomSeed',
  7987. 'num',
  7988. 0
  7989. ],
  7990. [
  7991. 20,
  7992. 'defaultWidthX',
  7993. 'num',
  7994. 0
  7995. ],
  7996. [
  7997. 21,
  7998. 'nominalWidthX',
  7999. 'num',
  8000. 0
  8001. ],
  8002. [
  8003. 19,
  8004. 'Subrs',
  8005. 'offset',
  8006. null
  8007. ]
  8008. ];
  8009. var tables = null;
  8010. function CFFPrivateDict(strings) {
  8011. if (tables === null) {
  8012. tables = CFFDict.createTables(layout);
  8013. }
  8014. CFFDict.call(this, tables, strings);
  8015. this.subrsIndex = null;
  8016. }
  8017. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8018. return CFFPrivateDict;
  8019. }();
  8020. var CFFCharsetPredefinedTypes = {
  8021. ISO_ADOBE: 0,
  8022. EXPERT: 1,
  8023. EXPERT_SUBSET: 2
  8024. };
  8025. var CFFCharset = function CFFCharsetClosure() {
  8026. function CFFCharset(predefined, format, charset, raw) {
  8027. this.predefined = predefined;
  8028. this.format = format;
  8029. this.charset = charset;
  8030. this.raw = raw;
  8031. }
  8032. return CFFCharset;
  8033. }();
  8034. var CFFEncoding = function CFFEncodingClosure() {
  8035. function CFFEncoding(predefined, format, encoding, raw) {
  8036. this.predefined = predefined;
  8037. this.format = format;
  8038. this.encoding = encoding;
  8039. this.raw = raw;
  8040. }
  8041. return CFFEncoding;
  8042. }();
  8043. var CFFFDSelect = function CFFFDSelectClosure() {
  8044. function CFFFDSelect(fdSelect, raw) {
  8045. this.fdSelect = fdSelect;
  8046. this.raw = raw;
  8047. }
  8048. CFFFDSelect.prototype = {
  8049. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8050. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8051. return -1;
  8052. }
  8053. return this.fdSelect[glyphIndex];
  8054. }
  8055. };
  8056. return CFFFDSelect;
  8057. }();
  8058. // Helper class to keep track of where an offset is within the data and helps
  8059. // filling in that offset once it's known.
  8060. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8061. function CFFOffsetTracker() {
  8062. this.offsets = Object.create(null);
  8063. }
  8064. CFFOffsetTracker.prototype = {
  8065. isTracking: function CFFOffsetTracker_isTracking(key) {
  8066. return key in this.offsets;
  8067. },
  8068. track: function CFFOffsetTracker_track(key, location) {
  8069. if (key in this.offsets) {
  8070. error('Already tracking location of ' + key);
  8071. }
  8072. this.offsets[key] = location;
  8073. },
  8074. offset: function CFFOffsetTracker_offset(value) {
  8075. for (var key in this.offsets) {
  8076. this.offsets[key] += value;
  8077. }
  8078. },
  8079. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8080. if (!(key in this.offsets)) {
  8081. error('Not tracking location of ' + key);
  8082. }
  8083. var data = output.data;
  8084. var dataOffset = this.offsets[key];
  8085. var size = 5;
  8086. for (var i = 0, ii = values.length; i < ii; ++i) {
  8087. var offset0 = i * size + dataOffset;
  8088. var offset1 = offset0 + 1;
  8089. var offset2 = offset0 + 2;
  8090. var offset3 = offset0 + 3;
  8091. var offset4 = offset0 + 4;
  8092. // It's easy to screw up offsets so perform this sanity check.
  8093. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8094. error('writing to an offset that is not empty');
  8095. }
  8096. var value = values[i];
  8097. data[offset0] = 0x1d;
  8098. data[offset1] = value >> 24 & 0xFF;
  8099. data[offset2] = value >> 16 & 0xFF;
  8100. data[offset3] = value >> 8 & 0xFF;
  8101. data[offset4] = value & 0xFF;
  8102. }
  8103. }
  8104. };
  8105. return CFFOffsetTracker;
  8106. }();
  8107. // Takes a CFF and converts it to the binary representation.
  8108. var CFFCompiler = function CFFCompilerClosure() {
  8109. function CFFCompiler(cff) {
  8110. this.cff = cff;
  8111. }
  8112. CFFCompiler.prototype = {
  8113. compile: function CFFCompiler_compile() {
  8114. var cff = this.cff;
  8115. var output = {
  8116. data: [],
  8117. length: 0,
  8118. add: function CFFCompiler_add(data) {
  8119. this.data = this.data.concat(data);
  8120. this.length = this.data.length;
  8121. }
  8122. };
  8123. // Compile the five entries that must be in order.
  8124. var header = this.compileHeader(cff.header);
  8125. output.add(header);
  8126. var nameIndex = this.compileNameIndex(cff.names);
  8127. output.add(nameIndex);
  8128. if (cff.isCIDFont) {
  8129. // The spec is unclear on how font matrices should relate to each other
  8130. // when there is one in the main top dict and the sub top dicts.
  8131. // Windows handles this differently than linux and osx so we have to
  8132. // normalize to work on all.
  8133. // Rules based off of some mailing list discussions:
  8134. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8135. // - If no main font matrix and there is a subfont matrix, use the
  8136. // subfont matrix.
  8137. // - If both have matrices, concat together.
  8138. // - If neither have matrices, use default.
  8139. // To make this work on all platforms we move the top matrix into each
  8140. // sub top dict and concat if necessary.
  8141. if (cff.topDict.hasName('FontMatrix')) {
  8142. var base = cff.topDict.getByName('FontMatrix');
  8143. cff.topDict.removeByName('FontMatrix');
  8144. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8145. var subDict = cff.fdArray[i];
  8146. var matrix = base.slice(0);
  8147. if (subDict.hasName('FontMatrix')) {
  8148. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8149. }
  8150. subDict.setByName('FontMatrix', matrix);
  8151. }
  8152. }
  8153. }
  8154. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8155. output.add(compiled.output);
  8156. var topDictTracker = compiled.trackers[0];
  8157. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8158. output.add(stringIndex);
  8159. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8160. output.add(globalSubrIndex);
  8161. // Now start on the other entries that have no specific order.
  8162. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8163. if (cff.encoding.predefined) {
  8164. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8165. } else {
  8166. var encoding = this.compileEncoding(cff.encoding);
  8167. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8168. output.add(encoding);
  8169. }
  8170. }
  8171. if (cff.charset && cff.topDict.hasName('charset')) {
  8172. if (cff.charset.predefined) {
  8173. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8174. } else {
  8175. var charset = this.compileCharset(cff.charset);
  8176. topDictTracker.setEntryLocation('charset', [output.length], output);
  8177. output.add(charset);
  8178. }
  8179. }
  8180. var charStrings = this.compileCharStrings(cff.charStrings);
  8181. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8182. output.add(charStrings);
  8183. if (cff.isCIDFont) {
  8184. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8185. // and linux don't seem to care.
  8186. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8187. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8188. output.add(fdSelect);
  8189. // It is unclear if the sub font dictionary can have CID related
  8190. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8191. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8192. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8193. output.add(compiled.output);
  8194. var fontDictTrackers = compiled.trackers;
  8195. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8196. }
  8197. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8198. // If the font data ends with INDEX whose object data is zero-length,
  8199. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8200. output.add([0]);
  8201. return output.data;
  8202. },
  8203. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8204. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8205. // isInt
  8206. return this.encodeInteger(value);
  8207. } else {
  8208. return this.encodeFloat(value);
  8209. }
  8210. },
  8211. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8212. var value = num.toString();
  8213. // rounding inaccurate doubles
  8214. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8215. if (m) {
  8216. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8217. value = (Math.round(num * epsilon) / epsilon).toString();
  8218. }
  8219. var nibbles = '';
  8220. var i, ii;
  8221. for (i = 0, ii = value.length; i < ii; ++i) {
  8222. var a = value[i];
  8223. if (a === 'e') {
  8224. nibbles += value[++i] === '-' ? 'c' : 'b';
  8225. } else if (a === '.') {
  8226. nibbles += 'a';
  8227. } else if (a === '-') {
  8228. nibbles += 'e';
  8229. } else {
  8230. nibbles += a;
  8231. }
  8232. }
  8233. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8234. var out = [30];
  8235. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8236. out.push(parseInt(nibbles.substr(i, 2), 16));
  8237. }
  8238. return out;
  8239. },
  8240. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8241. var code;
  8242. if (value >= -107 && value <= 107) {
  8243. code = [value + 139];
  8244. } else if (value >= 108 && value <= 1131) {
  8245. value = value - 108;
  8246. code = [
  8247. (value >> 8) + 247,
  8248. value & 0xFF
  8249. ];
  8250. } else if (value >= -1131 && value <= -108) {
  8251. value = -value - 108;
  8252. code = [
  8253. (value >> 8) + 251,
  8254. value & 0xFF
  8255. ];
  8256. } else if (value >= -32768 && value <= 32767) {
  8257. code = [
  8258. 0x1c,
  8259. value >> 8 & 0xFF,
  8260. value & 0xFF
  8261. ];
  8262. } else {
  8263. code = [
  8264. 0x1d,
  8265. value >> 24 & 0xFF,
  8266. value >> 16 & 0xFF,
  8267. value >> 8 & 0xFF,
  8268. value & 0xFF
  8269. ];
  8270. }
  8271. return code;
  8272. },
  8273. compileHeader: function CFFCompiler_compileHeader(header) {
  8274. return [
  8275. header.major,
  8276. header.minor,
  8277. header.hdrSize,
  8278. header.offSize
  8279. ];
  8280. },
  8281. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8282. var nameIndex = new CFFIndex();
  8283. for (var i = 0, ii = names.length; i < ii; ++i) {
  8284. nameIndex.add(stringToBytes(names[i]));
  8285. }
  8286. return this.compileIndex(nameIndex);
  8287. },
  8288. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8289. var fontDictTrackers = [];
  8290. var fdArrayIndex = new CFFIndex();
  8291. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8292. var fontDict = dicts[i];
  8293. if (removeCidKeys) {
  8294. fontDict.removeByName('CIDFontVersion');
  8295. fontDict.removeByName('CIDFontRevision');
  8296. fontDict.removeByName('CIDFontType');
  8297. fontDict.removeByName('CIDCount');
  8298. fontDict.removeByName('UIDBase');
  8299. }
  8300. var fontDictTracker = new CFFOffsetTracker();
  8301. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8302. fontDictTrackers.push(fontDictTracker);
  8303. fdArrayIndex.add(fontDictData);
  8304. fontDictTracker.offset(length);
  8305. }
  8306. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8307. return {
  8308. trackers: fontDictTrackers,
  8309. output: fdArrayIndex
  8310. };
  8311. },
  8312. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8313. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8314. var fontDict = dicts[i];
  8315. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8316. var privateDict = fontDict.privateDict;
  8317. var privateDictTracker = new CFFOffsetTracker();
  8318. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8319. var outputLength = output.length;
  8320. privateDictTracker.offset(outputLength);
  8321. if (!privateDictData.length) {
  8322. // The private dictionary was empty, set the output length to zero to
  8323. // ensure the offset length isn't out of bounds in the eyes of the
  8324. // sanitizer.
  8325. outputLength = 0;
  8326. }
  8327. trackers[i].setEntryLocation('Private', [
  8328. privateDictData.length,
  8329. outputLength
  8330. ], output);
  8331. output.add(privateDictData);
  8332. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8333. var subrs = this.compileIndex(privateDict.subrsIndex);
  8334. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8335. output.add(subrs);
  8336. }
  8337. }
  8338. },
  8339. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8340. var out = [];
  8341. // The dictionary keys must be in a certain order.
  8342. var order = dict.order;
  8343. for (var i = 0; i < order.length; ++i) {
  8344. var key = order[i];
  8345. if (!(key in dict.values)) {
  8346. continue;
  8347. }
  8348. var values = dict.values[key];
  8349. var types = dict.types[key];
  8350. if (!isArray(types)) {
  8351. types = [types];
  8352. }
  8353. if (!isArray(values)) {
  8354. values = [values];
  8355. }
  8356. // Remove any empty dict values.
  8357. if (values.length === 0) {
  8358. continue;
  8359. }
  8360. for (var j = 0, jj = types.length; j < jj; ++j) {
  8361. var type = types[j];
  8362. var value = values[j];
  8363. switch (type) {
  8364. case 'num':
  8365. case 'sid':
  8366. out = out.concat(this.encodeNumber(value));
  8367. break;
  8368. case 'offset':
  8369. // For offsets we just insert a 32bit integer so we don't have to
  8370. // deal with figuring out the length of the offset when it gets
  8371. // replaced later on by the compiler.
  8372. var name = dict.keyToNameMap[key];
  8373. // Some offsets have the offset and the length, so just record the
  8374. // position of the first one.
  8375. if (!offsetTracker.isTracking(name)) {
  8376. offsetTracker.track(name, out.length);
  8377. }
  8378. out = out.concat([
  8379. 0x1d,
  8380. 0,
  8381. 0,
  8382. 0,
  8383. 0
  8384. ]);
  8385. break;
  8386. case 'array':
  8387. case 'delta':
  8388. out = out.concat(this.encodeNumber(value));
  8389. for (var k = 1, kk = values.length; k < kk; ++k) {
  8390. out = out.concat(this.encodeNumber(values[k]));
  8391. }
  8392. break;
  8393. default:
  8394. error('Unknown data type of ' + type);
  8395. break;
  8396. }
  8397. }
  8398. out = out.concat(dict.opcodes[key]);
  8399. }
  8400. return out;
  8401. },
  8402. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8403. var stringIndex = new CFFIndex();
  8404. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8405. stringIndex.add(stringToBytes(strings[i]));
  8406. }
  8407. return this.compileIndex(stringIndex);
  8408. },
  8409. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8410. var globalSubrIndex = this.cff.globalSubrIndex;
  8411. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8412. },
  8413. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8414. return this.compileIndex(charStrings);
  8415. },
  8416. compileCharset: function CFFCompiler_compileCharset(charset) {
  8417. return this.compileTypedArray(charset.raw);
  8418. },
  8419. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8420. return this.compileTypedArray(encoding.raw);
  8421. },
  8422. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8423. return this.compileTypedArray(fdSelect);
  8424. },
  8425. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8426. var out = [];
  8427. for (var i = 0, ii = data.length; i < ii; ++i) {
  8428. out[i] = data[i];
  8429. }
  8430. return out;
  8431. },
  8432. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8433. trackers = trackers || [];
  8434. var objects = index.objects;
  8435. // First 2 bytes contains the number of objects contained into this index
  8436. var count = objects.length;
  8437. // If there is no object, just create an index. This technically
  8438. // should just be [0, 0] but OTS has an issue with that.
  8439. if (count === 0) {
  8440. return [
  8441. 0,
  8442. 0,
  8443. 0
  8444. ];
  8445. }
  8446. var data = [
  8447. count >> 8 & 0xFF,
  8448. count & 0xff
  8449. ];
  8450. var lastOffset = 1, i;
  8451. for (i = 0; i < count; ++i) {
  8452. lastOffset += objects[i].length;
  8453. }
  8454. var offsetSize;
  8455. if (lastOffset < 0x100) {
  8456. offsetSize = 1;
  8457. } else if (lastOffset < 0x10000) {
  8458. offsetSize = 2;
  8459. } else if (lastOffset < 0x1000000) {
  8460. offsetSize = 3;
  8461. } else {
  8462. offsetSize = 4;
  8463. }
  8464. // Next byte contains the offset size use to reference object in the file
  8465. data.push(offsetSize);
  8466. // Add another offset after this one because we need a new offset
  8467. var relativeOffset = 1;
  8468. for (i = 0; i < count + 1; i++) {
  8469. if (offsetSize === 1) {
  8470. data.push(relativeOffset & 0xFF);
  8471. } else if (offsetSize === 2) {
  8472. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8473. } else if (offsetSize === 3) {
  8474. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8475. } else {
  8476. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8477. }
  8478. if (objects[i]) {
  8479. relativeOffset += objects[i].length;
  8480. }
  8481. }
  8482. for (i = 0; i < count; i++) {
  8483. // Notify the tracker where the object will be offset in the data.
  8484. if (trackers[i]) {
  8485. trackers[i].offset(data.length);
  8486. }
  8487. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8488. data.push(objects[i][j]);
  8489. }
  8490. }
  8491. return data;
  8492. }
  8493. };
  8494. return CFFCompiler;
  8495. }();
  8496. exports.CFFStandardStrings = CFFStandardStrings;
  8497. exports.CFFParser = CFFParser;
  8498. exports.CFF = CFF;
  8499. exports.CFFHeader = CFFHeader;
  8500. exports.CFFStrings = CFFStrings;
  8501. exports.CFFIndex = CFFIndex;
  8502. exports.CFFCharset = CFFCharset;
  8503. exports.CFFTopDict = CFFTopDict;
  8504. exports.CFFPrivateDict = CFFPrivateDict;
  8505. exports.CFFCompiler = CFFCompiler;
  8506. }));
  8507. (function (root, factory) {
  8508. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8509. }(this, function (exports, sharedUtil) {
  8510. var MissingDataException = sharedUtil.MissingDataException;
  8511. var arrayByteLength = sharedUtil.arrayByteLength;
  8512. var arraysToBytes = sharedUtil.arraysToBytes;
  8513. var assert = sharedUtil.assert;
  8514. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8515. var isInt = sharedUtil.isInt;
  8516. var isEmptyObj = sharedUtil.isEmptyObj;
  8517. var ChunkedStream = function ChunkedStreamClosure() {
  8518. function ChunkedStream(length, chunkSize, manager) {
  8519. this.bytes = new Uint8Array(length);
  8520. this.start = 0;
  8521. this.pos = 0;
  8522. this.end = length;
  8523. this.chunkSize = chunkSize;
  8524. this.loadedChunks = [];
  8525. this.numChunksLoaded = 0;
  8526. this.numChunks = Math.ceil(length / chunkSize);
  8527. this.manager = manager;
  8528. this.progressiveDataLength = 0;
  8529. this.lastSuccessfulEnsureByteChunk = -1;
  8530. }
  8531. // a single-entry cache
  8532. // required methods for a stream. if a particular stream does not
  8533. // implement these, an error should be thrown
  8534. ChunkedStream.prototype = {
  8535. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8536. var chunks = [];
  8537. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8538. if (!this.loadedChunks[chunk]) {
  8539. chunks.push(chunk);
  8540. }
  8541. }
  8542. return chunks;
  8543. },
  8544. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8545. return [this];
  8546. },
  8547. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8548. return this.numChunksLoaded === this.numChunks;
  8549. },
  8550. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8551. var end = begin + chunk.byteLength;
  8552. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8553. // Using this.length is inaccurate here since this.start can be moved
  8554. // See ChunkedStream.moveStart()
  8555. var length = this.bytes.length;
  8556. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8557. this.bytes.set(new Uint8Array(chunk), begin);
  8558. var chunkSize = this.chunkSize;
  8559. var beginChunk = Math.floor(begin / chunkSize);
  8560. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8561. var curChunk;
  8562. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8563. if (!this.loadedChunks[curChunk]) {
  8564. this.loadedChunks[curChunk] = true;
  8565. ++this.numChunksLoaded;
  8566. }
  8567. }
  8568. },
  8569. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8570. var position = this.progressiveDataLength;
  8571. var beginChunk = Math.floor(position / this.chunkSize);
  8572. this.bytes.set(new Uint8Array(data), position);
  8573. position += data.byteLength;
  8574. this.progressiveDataLength = position;
  8575. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8576. var curChunk;
  8577. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8578. if (!this.loadedChunks[curChunk]) {
  8579. this.loadedChunks[curChunk] = true;
  8580. ++this.numChunksLoaded;
  8581. }
  8582. }
  8583. },
  8584. ensureByte: function ChunkedStream_ensureByte(pos) {
  8585. var chunk = Math.floor(pos / this.chunkSize);
  8586. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8587. return;
  8588. }
  8589. if (!this.loadedChunks[chunk]) {
  8590. throw new MissingDataException(pos, pos + 1);
  8591. }
  8592. this.lastSuccessfulEnsureByteChunk = chunk;
  8593. },
  8594. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8595. if (begin >= end) {
  8596. return;
  8597. }
  8598. if (end <= this.progressiveDataLength) {
  8599. return;
  8600. }
  8601. var chunkSize = this.chunkSize;
  8602. var beginChunk = Math.floor(begin / chunkSize);
  8603. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8604. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8605. if (!this.loadedChunks[chunk]) {
  8606. throw new MissingDataException(begin, end);
  8607. }
  8608. }
  8609. },
  8610. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8611. var chunk, numChunks = this.numChunks;
  8612. for (var i = 0; i < numChunks; ++i) {
  8613. chunk = (beginChunk + i) % numChunks;
  8614. // Wrap around to beginning
  8615. if (!this.loadedChunks[chunk]) {
  8616. return chunk;
  8617. }
  8618. }
  8619. return null;
  8620. },
  8621. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8622. return !!this.loadedChunks[chunk];
  8623. },
  8624. get length() {
  8625. return this.end - this.start;
  8626. },
  8627. get isEmpty() {
  8628. return this.length === 0;
  8629. },
  8630. getByte: function ChunkedStream_getByte() {
  8631. var pos = this.pos;
  8632. if (pos >= this.end) {
  8633. return -1;
  8634. }
  8635. this.ensureByte(pos);
  8636. return this.bytes[this.pos++];
  8637. },
  8638. getUint16: function ChunkedStream_getUint16() {
  8639. var b0 = this.getByte();
  8640. var b1 = this.getByte();
  8641. if (b0 === -1 || b1 === -1) {
  8642. return -1;
  8643. }
  8644. return (b0 << 8) + b1;
  8645. },
  8646. getInt32: function ChunkedStream_getInt32() {
  8647. var b0 = this.getByte();
  8648. var b1 = this.getByte();
  8649. var b2 = this.getByte();
  8650. var b3 = this.getByte();
  8651. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8652. },
  8653. // returns subarray of original buffer
  8654. // should only be read
  8655. getBytes: function ChunkedStream_getBytes(length) {
  8656. var bytes = this.bytes;
  8657. var pos = this.pos;
  8658. var strEnd = this.end;
  8659. if (!length) {
  8660. this.ensureRange(pos, strEnd);
  8661. return bytes.subarray(pos, strEnd);
  8662. }
  8663. var end = pos + length;
  8664. if (end > strEnd) {
  8665. end = strEnd;
  8666. }
  8667. this.ensureRange(pos, end);
  8668. this.pos = end;
  8669. return bytes.subarray(pos, end);
  8670. },
  8671. peekByte: function ChunkedStream_peekByte() {
  8672. var peekedByte = this.getByte();
  8673. this.pos--;
  8674. return peekedByte;
  8675. },
  8676. peekBytes: function ChunkedStream_peekBytes(length) {
  8677. var bytes = this.getBytes(length);
  8678. this.pos -= bytes.length;
  8679. return bytes;
  8680. },
  8681. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8682. this.ensureRange(begin, end);
  8683. return this.bytes.subarray(begin, end);
  8684. },
  8685. skip: function ChunkedStream_skip(n) {
  8686. if (!n) {
  8687. n = 1;
  8688. }
  8689. this.pos += n;
  8690. },
  8691. reset: function ChunkedStream_reset() {
  8692. this.pos = this.start;
  8693. },
  8694. moveStart: function ChunkedStream_moveStart() {
  8695. this.start = this.pos;
  8696. },
  8697. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8698. this.ensureRange(start, start + length);
  8699. function ChunkedStreamSubstream() {
  8700. }
  8701. ChunkedStreamSubstream.prototype = Object.create(this);
  8702. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8703. var chunkSize = this.chunkSize;
  8704. var beginChunk = Math.floor(this.start / chunkSize);
  8705. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8706. var missingChunks = [];
  8707. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8708. if (!this.loadedChunks[chunk]) {
  8709. missingChunks.push(chunk);
  8710. }
  8711. }
  8712. return missingChunks;
  8713. };
  8714. var subStream = new ChunkedStreamSubstream();
  8715. subStream.pos = subStream.start = start;
  8716. subStream.end = start + length || this.end;
  8717. subStream.dict = dict;
  8718. return subStream;
  8719. },
  8720. isStream: true
  8721. };
  8722. return ChunkedStream;
  8723. }();
  8724. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8725. function ChunkedStreamManager(pdfNetworkStream, args) {
  8726. var chunkSize = args.rangeChunkSize;
  8727. var length = args.length;
  8728. this.stream = new ChunkedStream(length, chunkSize, this);
  8729. this.length = length;
  8730. this.chunkSize = chunkSize;
  8731. this.pdfNetworkStream = pdfNetworkStream;
  8732. this.url = args.url;
  8733. this.disableAutoFetch = args.disableAutoFetch;
  8734. this.msgHandler = args.msgHandler;
  8735. this.currRequestId = 0;
  8736. this.chunksNeededByRequest = Object.create(null);
  8737. this.requestsByChunk = Object.create(null);
  8738. this.promisesByRequest = Object.create(null);
  8739. this.progressiveDataLength = 0;
  8740. this.aborted = false;
  8741. this._loadedStreamCapability = createPromiseCapability();
  8742. }
  8743. ChunkedStreamManager.prototype = {
  8744. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8745. return this._loadedStreamCapability.promise;
  8746. },
  8747. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8748. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8749. if (!rangeReader.isStreamingSupported) {
  8750. rangeReader.onProgress = this.onProgress.bind(this);
  8751. }
  8752. var chunks = [], loaded = 0;
  8753. var manager = this;
  8754. var promise = new Promise(function (resolve, reject) {
  8755. var readChunk = function (chunk) {
  8756. try {
  8757. if (!chunk.done) {
  8758. var data = chunk.value;
  8759. chunks.push(data);
  8760. loaded += arrayByteLength(data);
  8761. if (rangeReader.isStreamingSupported) {
  8762. manager.onProgress({ loaded: loaded });
  8763. }
  8764. rangeReader.read().then(readChunk, reject);
  8765. return;
  8766. }
  8767. var chunkData = arraysToBytes(chunks);
  8768. chunks = null;
  8769. resolve(chunkData);
  8770. } catch (e) {
  8771. reject(e);
  8772. }
  8773. };
  8774. rangeReader.read().then(readChunk, reject);
  8775. });
  8776. promise.then(function (data) {
  8777. if (this.aborted) {
  8778. return;
  8779. }
  8780. // ignoring any data after abort
  8781. this.onReceiveData({
  8782. chunk: data,
  8783. begin: begin
  8784. });
  8785. }.bind(this));
  8786. },
  8787. // TODO check errors
  8788. // Get all the chunks that are not yet loaded and groups them into
  8789. // contiguous ranges to load in as few requests as possible
  8790. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8791. var missingChunks = this.stream.getMissingChunks();
  8792. this._requestChunks(missingChunks);
  8793. return this._loadedStreamCapability.promise;
  8794. },
  8795. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8796. var requestId = this.currRequestId++;
  8797. var i, ii;
  8798. var chunksNeeded = Object.create(null);
  8799. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8800. for (i = 0, ii = chunks.length; i < ii; i++) {
  8801. if (!this.stream.hasChunk(chunks[i])) {
  8802. chunksNeeded[chunks[i]] = true;
  8803. }
  8804. }
  8805. if (isEmptyObj(chunksNeeded)) {
  8806. return Promise.resolve();
  8807. }
  8808. var capability = createPromiseCapability();
  8809. this.promisesByRequest[requestId] = capability;
  8810. var chunksToRequest = [];
  8811. for (var chunk in chunksNeeded) {
  8812. chunk = chunk | 0;
  8813. if (!(chunk in this.requestsByChunk)) {
  8814. this.requestsByChunk[chunk] = [];
  8815. chunksToRequest.push(chunk);
  8816. }
  8817. this.requestsByChunk[chunk].push(requestId);
  8818. }
  8819. if (!chunksToRequest.length) {
  8820. return capability.promise;
  8821. }
  8822. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8823. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8824. var groupedChunk = groupedChunksToRequest[i];
  8825. var begin = groupedChunk.beginChunk * this.chunkSize;
  8826. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8827. this.sendRequest(begin, end);
  8828. }
  8829. return capability.promise;
  8830. },
  8831. getStream: function ChunkedStreamManager_getStream() {
  8832. return this.stream;
  8833. },
  8834. // Loads any chunks in the requested range that are not yet loaded
  8835. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8836. end = Math.min(end, this.length);
  8837. var beginChunk = this.getBeginChunk(begin);
  8838. var endChunk = this.getEndChunk(end);
  8839. var chunks = [];
  8840. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8841. chunks.push(chunk);
  8842. }
  8843. return this._requestChunks(chunks);
  8844. },
  8845. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8846. ranges = ranges || [];
  8847. var chunksToRequest = [];
  8848. for (var i = 0; i < ranges.length; i++) {
  8849. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8850. var endChunk = this.getEndChunk(ranges[i].end);
  8851. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8852. if (chunksToRequest.indexOf(chunk) < 0) {
  8853. chunksToRequest.push(chunk);
  8854. }
  8855. }
  8856. }
  8857. chunksToRequest.sort(function (a, b) {
  8858. return a - b;
  8859. });
  8860. return this._requestChunks(chunksToRequest);
  8861. },
  8862. // Groups a sorted array of chunks into as few contiguous larger
  8863. // chunks as possible
  8864. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8865. var groupedChunks = [];
  8866. var beginChunk = -1;
  8867. var prevChunk = -1;
  8868. for (var i = 0; i < chunks.length; ++i) {
  8869. var chunk = chunks[i];
  8870. if (beginChunk < 0) {
  8871. beginChunk = chunk;
  8872. }
  8873. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8874. groupedChunks.push({
  8875. beginChunk: beginChunk,
  8876. endChunk: prevChunk + 1
  8877. });
  8878. beginChunk = chunk;
  8879. }
  8880. if (i + 1 === chunks.length) {
  8881. groupedChunks.push({
  8882. beginChunk: beginChunk,
  8883. endChunk: chunk + 1
  8884. });
  8885. }
  8886. prevChunk = chunk;
  8887. }
  8888. return groupedChunks;
  8889. },
  8890. onProgress: function ChunkedStreamManager_onProgress(args) {
  8891. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8892. this.msgHandler.send('DocProgress', {
  8893. loaded: bytesLoaded,
  8894. total: this.length
  8895. });
  8896. },
  8897. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8898. var chunk = args.chunk;
  8899. var isProgressive = args.begin === undefined;
  8900. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8901. var end = begin + chunk.byteLength;
  8902. var beginChunk = Math.floor(begin / this.chunkSize);
  8903. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8904. if (isProgressive) {
  8905. this.stream.onReceiveProgressiveData(chunk);
  8906. this.progressiveDataLength = end;
  8907. } else {
  8908. this.stream.onReceiveData(begin, chunk);
  8909. }
  8910. if (this.stream.allChunksLoaded()) {
  8911. this._loadedStreamCapability.resolve(this.stream);
  8912. }
  8913. var loadedRequests = [];
  8914. var i, requestId;
  8915. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8916. // The server might return more chunks than requested
  8917. var requestIds = this.requestsByChunk[chunk] || [];
  8918. delete this.requestsByChunk[chunk];
  8919. for (i = 0; i < requestIds.length; ++i) {
  8920. requestId = requestIds[i];
  8921. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8922. if (chunk in chunksNeeded) {
  8923. delete chunksNeeded[chunk];
  8924. }
  8925. if (!isEmptyObj(chunksNeeded)) {
  8926. continue;
  8927. }
  8928. loadedRequests.push(requestId);
  8929. }
  8930. }
  8931. // If there are no pending requests, automatically fetch the next
  8932. // unfetched chunk of the PDF
  8933. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8934. var nextEmptyChunk;
  8935. if (this.stream.numChunksLoaded === 1) {
  8936. // This is a special optimization so that after fetching the first
  8937. // chunk, rather than fetching the second chunk, we fetch the last
  8938. // chunk.
  8939. var lastChunk = this.stream.numChunks - 1;
  8940. if (!this.stream.hasChunk(lastChunk)) {
  8941. nextEmptyChunk = lastChunk;
  8942. }
  8943. } else {
  8944. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8945. }
  8946. if (isInt(nextEmptyChunk)) {
  8947. this._requestChunks([nextEmptyChunk]);
  8948. }
  8949. }
  8950. for (i = 0; i < loadedRequests.length; ++i) {
  8951. requestId = loadedRequests[i];
  8952. var capability = this.promisesByRequest[requestId];
  8953. delete this.promisesByRequest[requestId];
  8954. capability.resolve();
  8955. }
  8956. this.msgHandler.send('DocProgress', {
  8957. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8958. total: this.length
  8959. });
  8960. },
  8961. onError: function ChunkedStreamManager_onError(err) {
  8962. this._loadedStreamCapability.reject(err);
  8963. },
  8964. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8965. var chunk = Math.floor(begin / this.chunkSize);
  8966. return chunk;
  8967. },
  8968. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8969. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8970. return chunk;
  8971. },
  8972. abort: function ChunkedStreamManager_abort() {
  8973. this.aborted = true;
  8974. if (this.pdfNetworkStream) {
  8975. this.pdfNetworkStream.cancelAllRequests('abort');
  8976. }
  8977. for (var requestId in this.promisesByRequest) {
  8978. var capability = this.promisesByRequest[requestId];
  8979. capability.reject(new Error('Request was aborted'));
  8980. }
  8981. }
  8982. };
  8983. return ChunkedStreamManager;
  8984. }();
  8985. exports.ChunkedStream = ChunkedStream;
  8986. exports.ChunkedStreamManager = ChunkedStreamManager;
  8987. }));
  8988. (function (root, factory) {
  8989. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8990. }(this, function (exports, sharedUtil) {
  8991. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8992. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8993. t['A'] = 0x0041;
  8994. t['AE'] = 0x00C6;
  8995. t['AEacute'] = 0x01FC;
  8996. t['AEmacron'] = 0x01E2;
  8997. t['AEsmall'] = 0xF7E6;
  8998. t['Aacute'] = 0x00C1;
  8999. t['Aacutesmall'] = 0xF7E1;
  9000. t['Abreve'] = 0x0102;
  9001. t['Abreveacute'] = 0x1EAE;
  9002. t['Abrevecyrillic'] = 0x04D0;
  9003. t['Abrevedotbelow'] = 0x1EB6;
  9004. t['Abrevegrave'] = 0x1EB0;
  9005. t['Abrevehookabove'] = 0x1EB2;
  9006. t['Abrevetilde'] = 0x1EB4;
  9007. t['Acaron'] = 0x01CD;
  9008. t['Acircle'] = 0x24B6;
  9009. t['Acircumflex'] = 0x00C2;
  9010. t['Acircumflexacute'] = 0x1EA4;
  9011. t['Acircumflexdotbelow'] = 0x1EAC;
  9012. t['Acircumflexgrave'] = 0x1EA6;
  9013. t['Acircumflexhookabove'] = 0x1EA8;
  9014. t['Acircumflexsmall'] = 0xF7E2;
  9015. t['Acircumflextilde'] = 0x1EAA;
  9016. t['Acute'] = 0xF6C9;
  9017. t['Acutesmall'] = 0xF7B4;
  9018. t['Acyrillic'] = 0x0410;
  9019. t['Adblgrave'] = 0x0200;
  9020. t['Adieresis'] = 0x00C4;
  9021. t['Adieresiscyrillic'] = 0x04D2;
  9022. t['Adieresismacron'] = 0x01DE;
  9023. t['Adieresissmall'] = 0xF7E4;
  9024. t['Adotbelow'] = 0x1EA0;
  9025. t['Adotmacron'] = 0x01E0;
  9026. t['Agrave'] = 0x00C0;
  9027. t['Agravesmall'] = 0xF7E0;
  9028. t['Ahookabove'] = 0x1EA2;
  9029. t['Aiecyrillic'] = 0x04D4;
  9030. t['Ainvertedbreve'] = 0x0202;
  9031. t['Alpha'] = 0x0391;
  9032. t['Alphatonos'] = 0x0386;
  9033. t['Amacron'] = 0x0100;
  9034. t['Amonospace'] = 0xFF21;
  9035. t['Aogonek'] = 0x0104;
  9036. t['Aring'] = 0x00C5;
  9037. t['Aringacute'] = 0x01FA;
  9038. t['Aringbelow'] = 0x1E00;
  9039. t['Aringsmall'] = 0xF7E5;
  9040. t['Asmall'] = 0xF761;
  9041. t['Atilde'] = 0x00C3;
  9042. t['Atildesmall'] = 0xF7E3;
  9043. t['Aybarmenian'] = 0x0531;
  9044. t['B'] = 0x0042;
  9045. t['Bcircle'] = 0x24B7;
  9046. t['Bdotaccent'] = 0x1E02;
  9047. t['Bdotbelow'] = 0x1E04;
  9048. t['Becyrillic'] = 0x0411;
  9049. t['Benarmenian'] = 0x0532;
  9050. t['Beta'] = 0x0392;
  9051. t['Bhook'] = 0x0181;
  9052. t['Blinebelow'] = 0x1E06;
  9053. t['Bmonospace'] = 0xFF22;
  9054. t['Brevesmall'] = 0xF6F4;
  9055. t['Bsmall'] = 0xF762;
  9056. t['Btopbar'] = 0x0182;
  9057. t['C'] = 0x0043;
  9058. t['Caarmenian'] = 0x053E;
  9059. t['Cacute'] = 0x0106;
  9060. t['Caron'] = 0xF6CA;
  9061. t['Caronsmall'] = 0xF6F5;
  9062. t['Ccaron'] = 0x010C;
  9063. t['Ccedilla'] = 0x00C7;
  9064. t['Ccedillaacute'] = 0x1E08;
  9065. t['Ccedillasmall'] = 0xF7E7;
  9066. t['Ccircle'] = 0x24B8;
  9067. t['Ccircumflex'] = 0x0108;
  9068. t['Cdot'] = 0x010A;
  9069. t['Cdotaccent'] = 0x010A;
  9070. t['Cedillasmall'] = 0xF7B8;
  9071. t['Chaarmenian'] = 0x0549;
  9072. t['Cheabkhasiancyrillic'] = 0x04BC;
  9073. t['Checyrillic'] = 0x0427;
  9074. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9075. t['Chedescendercyrillic'] = 0x04B6;
  9076. t['Chedieresiscyrillic'] = 0x04F4;
  9077. t['Cheharmenian'] = 0x0543;
  9078. t['Chekhakassiancyrillic'] = 0x04CB;
  9079. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9080. t['Chi'] = 0x03A7;
  9081. t['Chook'] = 0x0187;
  9082. t['Circumflexsmall'] = 0xF6F6;
  9083. t['Cmonospace'] = 0xFF23;
  9084. t['Coarmenian'] = 0x0551;
  9085. t['Csmall'] = 0xF763;
  9086. t['D'] = 0x0044;
  9087. t['DZ'] = 0x01F1;
  9088. t['DZcaron'] = 0x01C4;
  9089. t['Daarmenian'] = 0x0534;
  9090. t['Dafrican'] = 0x0189;
  9091. t['Dcaron'] = 0x010E;
  9092. t['Dcedilla'] = 0x1E10;
  9093. t['Dcircle'] = 0x24B9;
  9094. t['Dcircumflexbelow'] = 0x1E12;
  9095. t['Dcroat'] = 0x0110;
  9096. t['Ddotaccent'] = 0x1E0A;
  9097. t['Ddotbelow'] = 0x1E0C;
  9098. t['Decyrillic'] = 0x0414;
  9099. t['Deicoptic'] = 0x03EE;
  9100. t['Delta'] = 0x2206;
  9101. t['Deltagreek'] = 0x0394;
  9102. t['Dhook'] = 0x018A;
  9103. t['Dieresis'] = 0xF6CB;
  9104. t['DieresisAcute'] = 0xF6CC;
  9105. t['DieresisGrave'] = 0xF6CD;
  9106. t['Dieresissmall'] = 0xF7A8;
  9107. t['Digammagreek'] = 0x03DC;
  9108. t['Djecyrillic'] = 0x0402;
  9109. t['Dlinebelow'] = 0x1E0E;
  9110. t['Dmonospace'] = 0xFF24;
  9111. t['Dotaccentsmall'] = 0xF6F7;
  9112. t['Dslash'] = 0x0110;
  9113. t['Dsmall'] = 0xF764;
  9114. t['Dtopbar'] = 0x018B;
  9115. t['Dz'] = 0x01F2;
  9116. t['Dzcaron'] = 0x01C5;
  9117. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9118. t['Dzecyrillic'] = 0x0405;
  9119. t['Dzhecyrillic'] = 0x040F;
  9120. t['E'] = 0x0045;
  9121. t['Eacute'] = 0x00C9;
  9122. t['Eacutesmall'] = 0xF7E9;
  9123. t['Ebreve'] = 0x0114;
  9124. t['Ecaron'] = 0x011A;
  9125. t['Ecedillabreve'] = 0x1E1C;
  9126. t['Echarmenian'] = 0x0535;
  9127. t['Ecircle'] = 0x24BA;
  9128. t['Ecircumflex'] = 0x00CA;
  9129. t['Ecircumflexacute'] = 0x1EBE;
  9130. t['Ecircumflexbelow'] = 0x1E18;
  9131. t['Ecircumflexdotbelow'] = 0x1EC6;
  9132. t['Ecircumflexgrave'] = 0x1EC0;
  9133. t['Ecircumflexhookabove'] = 0x1EC2;
  9134. t['Ecircumflexsmall'] = 0xF7EA;
  9135. t['Ecircumflextilde'] = 0x1EC4;
  9136. t['Ecyrillic'] = 0x0404;
  9137. t['Edblgrave'] = 0x0204;
  9138. t['Edieresis'] = 0x00CB;
  9139. t['Edieresissmall'] = 0xF7EB;
  9140. t['Edot'] = 0x0116;
  9141. t['Edotaccent'] = 0x0116;
  9142. t['Edotbelow'] = 0x1EB8;
  9143. t['Efcyrillic'] = 0x0424;
  9144. t['Egrave'] = 0x00C8;
  9145. t['Egravesmall'] = 0xF7E8;
  9146. t['Eharmenian'] = 0x0537;
  9147. t['Ehookabove'] = 0x1EBA;
  9148. t['Eightroman'] = 0x2167;
  9149. t['Einvertedbreve'] = 0x0206;
  9150. t['Eiotifiedcyrillic'] = 0x0464;
  9151. t['Elcyrillic'] = 0x041B;
  9152. t['Elevenroman'] = 0x216A;
  9153. t['Emacron'] = 0x0112;
  9154. t['Emacronacute'] = 0x1E16;
  9155. t['Emacrongrave'] = 0x1E14;
  9156. t['Emcyrillic'] = 0x041C;
  9157. t['Emonospace'] = 0xFF25;
  9158. t['Encyrillic'] = 0x041D;
  9159. t['Endescendercyrillic'] = 0x04A2;
  9160. t['Eng'] = 0x014A;
  9161. t['Enghecyrillic'] = 0x04A4;
  9162. t['Enhookcyrillic'] = 0x04C7;
  9163. t['Eogonek'] = 0x0118;
  9164. t['Eopen'] = 0x0190;
  9165. t['Epsilon'] = 0x0395;
  9166. t['Epsilontonos'] = 0x0388;
  9167. t['Ercyrillic'] = 0x0420;
  9168. t['Ereversed'] = 0x018E;
  9169. t['Ereversedcyrillic'] = 0x042D;
  9170. t['Escyrillic'] = 0x0421;
  9171. t['Esdescendercyrillic'] = 0x04AA;
  9172. t['Esh'] = 0x01A9;
  9173. t['Esmall'] = 0xF765;
  9174. t['Eta'] = 0x0397;
  9175. t['Etarmenian'] = 0x0538;
  9176. t['Etatonos'] = 0x0389;
  9177. t['Eth'] = 0x00D0;
  9178. t['Ethsmall'] = 0xF7F0;
  9179. t['Etilde'] = 0x1EBC;
  9180. t['Etildebelow'] = 0x1E1A;
  9181. t['Euro'] = 0x20AC;
  9182. t['Ezh'] = 0x01B7;
  9183. t['Ezhcaron'] = 0x01EE;
  9184. t['Ezhreversed'] = 0x01B8;
  9185. t['F'] = 0x0046;
  9186. t['Fcircle'] = 0x24BB;
  9187. t['Fdotaccent'] = 0x1E1E;
  9188. t['Feharmenian'] = 0x0556;
  9189. t['Feicoptic'] = 0x03E4;
  9190. t['Fhook'] = 0x0191;
  9191. t['Fitacyrillic'] = 0x0472;
  9192. t['Fiveroman'] = 0x2164;
  9193. t['Fmonospace'] = 0xFF26;
  9194. t['Fourroman'] = 0x2163;
  9195. t['Fsmall'] = 0xF766;
  9196. t['G'] = 0x0047;
  9197. t['GBsquare'] = 0x3387;
  9198. t['Gacute'] = 0x01F4;
  9199. t['Gamma'] = 0x0393;
  9200. t['Gammaafrican'] = 0x0194;
  9201. t['Gangiacoptic'] = 0x03EA;
  9202. t['Gbreve'] = 0x011E;
  9203. t['Gcaron'] = 0x01E6;
  9204. t['Gcedilla'] = 0x0122;
  9205. t['Gcircle'] = 0x24BC;
  9206. t['Gcircumflex'] = 0x011C;
  9207. t['Gcommaaccent'] = 0x0122;
  9208. t['Gdot'] = 0x0120;
  9209. t['Gdotaccent'] = 0x0120;
  9210. t['Gecyrillic'] = 0x0413;
  9211. t['Ghadarmenian'] = 0x0542;
  9212. t['Ghemiddlehookcyrillic'] = 0x0494;
  9213. t['Ghestrokecyrillic'] = 0x0492;
  9214. t['Gheupturncyrillic'] = 0x0490;
  9215. t['Ghook'] = 0x0193;
  9216. t['Gimarmenian'] = 0x0533;
  9217. t['Gjecyrillic'] = 0x0403;
  9218. t['Gmacron'] = 0x1E20;
  9219. t['Gmonospace'] = 0xFF27;
  9220. t['Grave'] = 0xF6CE;
  9221. t['Gravesmall'] = 0xF760;
  9222. t['Gsmall'] = 0xF767;
  9223. t['Gsmallhook'] = 0x029B;
  9224. t['Gstroke'] = 0x01E4;
  9225. t['H'] = 0x0048;
  9226. t['H18533'] = 0x25CF;
  9227. t['H18543'] = 0x25AA;
  9228. t['H18551'] = 0x25AB;
  9229. t['H22073'] = 0x25A1;
  9230. t['HPsquare'] = 0x33CB;
  9231. t['Haabkhasiancyrillic'] = 0x04A8;
  9232. t['Hadescendercyrillic'] = 0x04B2;
  9233. t['Hardsigncyrillic'] = 0x042A;
  9234. t['Hbar'] = 0x0126;
  9235. t['Hbrevebelow'] = 0x1E2A;
  9236. t['Hcedilla'] = 0x1E28;
  9237. t['Hcircle'] = 0x24BD;
  9238. t['Hcircumflex'] = 0x0124;
  9239. t['Hdieresis'] = 0x1E26;
  9240. t['Hdotaccent'] = 0x1E22;
  9241. t['Hdotbelow'] = 0x1E24;
  9242. t['Hmonospace'] = 0xFF28;
  9243. t['Hoarmenian'] = 0x0540;
  9244. t['Horicoptic'] = 0x03E8;
  9245. t['Hsmall'] = 0xF768;
  9246. t['Hungarumlaut'] = 0xF6CF;
  9247. t['Hungarumlautsmall'] = 0xF6F8;
  9248. t['Hzsquare'] = 0x3390;
  9249. t['I'] = 0x0049;
  9250. t['IAcyrillic'] = 0x042F;
  9251. t['IJ'] = 0x0132;
  9252. t['IUcyrillic'] = 0x042E;
  9253. t['Iacute'] = 0x00CD;
  9254. t['Iacutesmall'] = 0xF7ED;
  9255. t['Ibreve'] = 0x012C;
  9256. t['Icaron'] = 0x01CF;
  9257. t['Icircle'] = 0x24BE;
  9258. t['Icircumflex'] = 0x00CE;
  9259. t['Icircumflexsmall'] = 0xF7EE;
  9260. t['Icyrillic'] = 0x0406;
  9261. t['Idblgrave'] = 0x0208;
  9262. t['Idieresis'] = 0x00CF;
  9263. t['Idieresisacute'] = 0x1E2E;
  9264. t['Idieresiscyrillic'] = 0x04E4;
  9265. t['Idieresissmall'] = 0xF7EF;
  9266. t['Idot'] = 0x0130;
  9267. t['Idotaccent'] = 0x0130;
  9268. t['Idotbelow'] = 0x1ECA;
  9269. t['Iebrevecyrillic'] = 0x04D6;
  9270. t['Iecyrillic'] = 0x0415;
  9271. t['Ifraktur'] = 0x2111;
  9272. t['Igrave'] = 0x00CC;
  9273. t['Igravesmall'] = 0xF7EC;
  9274. t['Ihookabove'] = 0x1EC8;
  9275. t['Iicyrillic'] = 0x0418;
  9276. t['Iinvertedbreve'] = 0x020A;
  9277. t['Iishortcyrillic'] = 0x0419;
  9278. t['Imacron'] = 0x012A;
  9279. t['Imacroncyrillic'] = 0x04E2;
  9280. t['Imonospace'] = 0xFF29;
  9281. t['Iniarmenian'] = 0x053B;
  9282. t['Iocyrillic'] = 0x0401;
  9283. t['Iogonek'] = 0x012E;
  9284. t['Iota'] = 0x0399;
  9285. t['Iotaafrican'] = 0x0196;
  9286. t['Iotadieresis'] = 0x03AA;
  9287. t['Iotatonos'] = 0x038A;
  9288. t['Ismall'] = 0xF769;
  9289. t['Istroke'] = 0x0197;
  9290. t['Itilde'] = 0x0128;
  9291. t['Itildebelow'] = 0x1E2C;
  9292. t['Izhitsacyrillic'] = 0x0474;
  9293. t['Izhitsadblgravecyrillic'] = 0x0476;
  9294. t['J'] = 0x004A;
  9295. t['Jaarmenian'] = 0x0541;
  9296. t['Jcircle'] = 0x24BF;
  9297. t['Jcircumflex'] = 0x0134;
  9298. t['Jecyrillic'] = 0x0408;
  9299. t['Jheharmenian'] = 0x054B;
  9300. t['Jmonospace'] = 0xFF2A;
  9301. t['Jsmall'] = 0xF76A;
  9302. t['K'] = 0x004B;
  9303. t['KBsquare'] = 0x3385;
  9304. t['KKsquare'] = 0x33CD;
  9305. t['Kabashkircyrillic'] = 0x04A0;
  9306. t['Kacute'] = 0x1E30;
  9307. t['Kacyrillic'] = 0x041A;
  9308. t['Kadescendercyrillic'] = 0x049A;
  9309. t['Kahookcyrillic'] = 0x04C3;
  9310. t['Kappa'] = 0x039A;
  9311. t['Kastrokecyrillic'] = 0x049E;
  9312. t['Kaverticalstrokecyrillic'] = 0x049C;
  9313. t['Kcaron'] = 0x01E8;
  9314. t['Kcedilla'] = 0x0136;
  9315. t['Kcircle'] = 0x24C0;
  9316. t['Kcommaaccent'] = 0x0136;
  9317. t['Kdotbelow'] = 0x1E32;
  9318. t['Keharmenian'] = 0x0554;
  9319. t['Kenarmenian'] = 0x053F;
  9320. t['Khacyrillic'] = 0x0425;
  9321. t['Kheicoptic'] = 0x03E6;
  9322. t['Khook'] = 0x0198;
  9323. t['Kjecyrillic'] = 0x040C;
  9324. t['Klinebelow'] = 0x1E34;
  9325. t['Kmonospace'] = 0xFF2B;
  9326. t['Koppacyrillic'] = 0x0480;
  9327. t['Koppagreek'] = 0x03DE;
  9328. t['Ksicyrillic'] = 0x046E;
  9329. t['Ksmall'] = 0xF76B;
  9330. t['L'] = 0x004C;
  9331. t['LJ'] = 0x01C7;
  9332. t['LL'] = 0xF6BF;
  9333. t['Lacute'] = 0x0139;
  9334. t['Lambda'] = 0x039B;
  9335. t['Lcaron'] = 0x013D;
  9336. t['Lcedilla'] = 0x013B;
  9337. t['Lcircle'] = 0x24C1;
  9338. t['Lcircumflexbelow'] = 0x1E3C;
  9339. t['Lcommaaccent'] = 0x013B;
  9340. t['Ldot'] = 0x013F;
  9341. t['Ldotaccent'] = 0x013F;
  9342. t['Ldotbelow'] = 0x1E36;
  9343. t['Ldotbelowmacron'] = 0x1E38;
  9344. t['Liwnarmenian'] = 0x053C;
  9345. t['Lj'] = 0x01C8;
  9346. t['Ljecyrillic'] = 0x0409;
  9347. t['Llinebelow'] = 0x1E3A;
  9348. t['Lmonospace'] = 0xFF2C;
  9349. t['Lslash'] = 0x0141;
  9350. t['Lslashsmall'] = 0xF6F9;
  9351. t['Lsmall'] = 0xF76C;
  9352. t['M'] = 0x004D;
  9353. t['MBsquare'] = 0x3386;
  9354. t['Macron'] = 0xF6D0;
  9355. t['Macronsmall'] = 0xF7AF;
  9356. t['Macute'] = 0x1E3E;
  9357. t['Mcircle'] = 0x24C2;
  9358. t['Mdotaccent'] = 0x1E40;
  9359. t['Mdotbelow'] = 0x1E42;
  9360. t['Menarmenian'] = 0x0544;
  9361. t['Mmonospace'] = 0xFF2D;
  9362. t['Msmall'] = 0xF76D;
  9363. t['Mturned'] = 0x019C;
  9364. t['Mu'] = 0x039C;
  9365. t['N'] = 0x004E;
  9366. t['NJ'] = 0x01CA;
  9367. t['Nacute'] = 0x0143;
  9368. t['Ncaron'] = 0x0147;
  9369. t['Ncedilla'] = 0x0145;
  9370. t['Ncircle'] = 0x24C3;
  9371. t['Ncircumflexbelow'] = 0x1E4A;
  9372. t['Ncommaaccent'] = 0x0145;
  9373. t['Ndotaccent'] = 0x1E44;
  9374. t['Ndotbelow'] = 0x1E46;
  9375. t['Nhookleft'] = 0x019D;
  9376. t['Nineroman'] = 0x2168;
  9377. t['Nj'] = 0x01CB;
  9378. t['Njecyrillic'] = 0x040A;
  9379. t['Nlinebelow'] = 0x1E48;
  9380. t['Nmonospace'] = 0xFF2E;
  9381. t['Nowarmenian'] = 0x0546;
  9382. t['Nsmall'] = 0xF76E;
  9383. t['Ntilde'] = 0x00D1;
  9384. t['Ntildesmall'] = 0xF7F1;
  9385. t['Nu'] = 0x039D;
  9386. t['O'] = 0x004F;
  9387. t['OE'] = 0x0152;
  9388. t['OEsmall'] = 0xF6FA;
  9389. t['Oacute'] = 0x00D3;
  9390. t['Oacutesmall'] = 0xF7F3;
  9391. t['Obarredcyrillic'] = 0x04E8;
  9392. t['Obarreddieresiscyrillic'] = 0x04EA;
  9393. t['Obreve'] = 0x014E;
  9394. t['Ocaron'] = 0x01D1;
  9395. t['Ocenteredtilde'] = 0x019F;
  9396. t['Ocircle'] = 0x24C4;
  9397. t['Ocircumflex'] = 0x00D4;
  9398. t['Ocircumflexacute'] = 0x1ED0;
  9399. t['Ocircumflexdotbelow'] = 0x1ED8;
  9400. t['Ocircumflexgrave'] = 0x1ED2;
  9401. t['Ocircumflexhookabove'] = 0x1ED4;
  9402. t['Ocircumflexsmall'] = 0xF7F4;
  9403. t['Ocircumflextilde'] = 0x1ED6;
  9404. t['Ocyrillic'] = 0x041E;
  9405. t['Odblacute'] = 0x0150;
  9406. t['Odblgrave'] = 0x020C;
  9407. t['Odieresis'] = 0x00D6;
  9408. t['Odieresiscyrillic'] = 0x04E6;
  9409. t['Odieresissmall'] = 0xF7F6;
  9410. t['Odotbelow'] = 0x1ECC;
  9411. t['Ogoneksmall'] = 0xF6FB;
  9412. t['Ograve'] = 0x00D2;
  9413. t['Ogravesmall'] = 0xF7F2;
  9414. t['Oharmenian'] = 0x0555;
  9415. t['Ohm'] = 0x2126;
  9416. t['Ohookabove'] = 0x1ECE;
  9417. t['Ohorn'] = 0x01A0;
  9418. t['Ohornacute'] = 0x1EDA;
  9419. t['Ohorndotbelow'] = 0x1EE2;
  9420. t['Ohorngrave'] = 0x1EDC;
  9421. t['Ohornhookabove'] = 0x1EDE;
  9422. t['Ohorntilde'] = 0x1EE0;
  9423. t['Ohungarumlaut'] = 0x0150;
  9424. t['Oi'] = 0x01A2;
  9425. t['Oinvertedbreve'] = 0x020E;
  9426. t['Omacron'] = 0x014C;
  9427. t['Omacronacute'] = 0x1E52;
  9428. t['Omacrongrave'] = 0x1E50;
  9429. t['Omega'] = 0x2126;
  9430. t['Omegacyrillic'] = 0x0460;
  9431. t['Omegagreek'] = 0x03A9;
  9432. t['Omegaroundcyrillic'] = 0x047A;
  9433. t['Omegatitlocyrillic'] = 0x047C;
  9434. t['Omegatonos'] = 0x038F;
  9435. t['Omicron'] = 0x039F;
  9436. t['Omicrontonos'] = 0x038C;
  9437. t['Omonospace'] = 0xFF2F;
  9438. t['Oneroman'] = 0x2160;
  9439. t['Oogonek'] = 0x01EA;
  9440. t['Oogonekmacron'] = 0x01EC;
  9441. t['Oopen'] = 0x0186;
  9442. t['Oslash'] = 0x00D8;
  9443. t['Oslashacute'] = 0x01FE;
  9444. t['Oslashsmall'] = 0xF7F8;
  9445. t['Osmall'] = 0xF76F;
  9446. t['Ostrokeacute'] = 0x01FE;
  9447. t['Otcyrillic'] = 0x047E;
  9448. t['Otilde'] = 0x00D5;
  9449. t['Otildeacute'] = 0x1E4C;
  9450. t['Otildedieresis'] = 0x1E4E;
  9451. t['Otildesmall'] = 0xF7F5;
  9452. t['P'] = 0x0050;
  9453. t['Pacute'] = 0x1E54;
  9454. t['Pcircle'] = 0x24C5;
  9455. t['Pdotaccent'] = 0x1E56;
  9456. t['Pecyrillic'] = 0x041F;
  9457. t['Peharmenian'] = 0x054A;
  9458. t['Pemiddlehookcyrillic'] = 0x04A6;
  9459. t['Phi'] = 0x03A6;
  9460. t['Phook'] = 0x01A4;
  9461. t['Pi'] = 0x03A0;
  9462. t['Piwrarmenian'] = 0x0553;
  9463. t['Pmonospace'] = 0xFF30;
  9464. t['Psi'] = 0x03A8;
  9465. t['Psicyrillic'] = 0x0470;
  9466. t['Psmall'] = 0xF770;
  9467. t['Q'] = 0x0051;
  9468. t['Qcircle'] = 0x24C6;
  9469. t['Qmonospace'] = 0xFF31;
  9470. t['Qsmall'] = 0xF771;
  9471. t['R'] = 0x0052;
  9472. t['Raarmenian'] = 0x054C;
  9473. t['Racute'] = 0x0154;
  9474. t['Rcaron'] = 0x0158;
  9475. t['Rcedilla'] = 0x0156;
  9476. t['Rcircle'] = 0x24C7;
  9477. t['Rcommaaccent'] = 0x0156;
  9478. t['Rdblgrave'] = 0x0210;
  9479. t['Rdotaccent'] = 0x1E58;
  9480. t['Rdotbelow'] = 0x1E5A;
  9481. t['Rdotbelowmacron'] = 0x1E5C;
  9482. t['Reharmenian'] = 0x0550;
  9483. t['Rfraktur'] = 0x211C;
  9484. t['Rho'] = 0x03A1;
  9485. t['Ringsmall'] = 0xF6FC;
  9486. t['Rinvertedbreve'] = 0x0212;
  9487. t['Rlinebelow'] = 0x1E5E;
  9488. t['Rmonospace'] = 0xFF32;
  9489. t['Rsmall'] = 0xF772;
  9490. t['Rsmallinverted'] = 0x0281;
  9491. t['Rsmallinvertedsuperior'] = 0x02B6;
  9492. t['S'] = 0x0053;
  9493. t['SF010000'] = 0x250C;
  9494. t['SF020000'] = 0x2514;
  9495. t['SF030000'] = 0x2510;
  9496. t['SF040000'] = 0x2518;
  9497. t['SF050000'] = 0x253C;
  9498. t['SF060000'] = 0x252C;
  9499. t['SF070000'] = 0x2534;
  9500. t['SF080000'] = 0x251C;
  9501. t['SF090000'] = 0x2524;
  9502. t['SF100000'] = 0x2500;
  9503. t['SF110000'] = 0x2502;
  9504. t['SF190000'] = 0x2561;
  9505. t['SF200000'] = 0x2562;
  9506. t['SF210000'] = 0x2556;
  9507. t['SF220000'] = 0x2555;
  9508. t['SF230000'] = 0x2563;
  9509. t['SF240000'] = 0x2551;
  9510. t['SF250000'] = 0x2557;
  9511. t['SF260000'] = 0x255D;
  9512. t['SF270000'] = 0x255C;
  9513. t['SF280000'] = 0x255B;
  9514. t['SF360000'] = 0x255E;
  9515. t['SF370000'] = 0x255F;
  9516. t['SF380000'] = 0x255A;
  9517. t['SF390000'] = 0x2554;
  9518. t['SF400000'] = 0x2569;
  9519. t['SF410000'] = 0x2566;
  9520. t['SF420000'] = 0x2560;
  9521. t['SF430000'] = 0x2550;
  9522. t['SF440000'] = 0x256C;
  9523. t['SF450000'] = 0x2567;
  9524. t['SF460000'] = 0x2568;
  9525. t['SF470000'] = 0x2564;
  9526. t['SF480000'] = 0x2565;
  9527. t['SF490000'] = 0x2559;
  9528. t['SF500000'] = 0x2558;
  9529. t['SF510000'] = 0x2552;
  9530. t['SF520000'] = 0x2553;
  9531. t['SF530000'] = 0x256B;
  9532. t['SF540000'] = 0x256A;
  9533. t['Sacute'] = 0x015A;
  9534. t['Sacutedotaccent'] = 0x1E64;
  9535. t['Sampigreek'] = 0x03E0;
  9536. t['Scaron'] = 0x0160;
  9537. t['Scarondotaccent'] = 0x1E66;
  9538. t['Scaronsmall'] = 0xF6FD;
  9539. t['Scedilla'] = 0x015E;
  9540. t['Schwa'] = 0x018F;
  9541. t['Schwacyrillic'] = 0x04D8;
  9542. t['Schwadieresiscyrillic'] = 0x04DA;
  9543. t['Scircle'] = 0x24C8;
  9544. t['Scircumflex'] = 0x015C;
  9545. t['Scommaaccent'] = 0x0218;
  9546. t['Sdotaccent'] = 0x1E60;
  9547. t['Sdotbelow'] = 0x1E62;
  9548. t['Sdotbelowdotaccent'] = 0x1E68;
  9549. t['Seharmenian'] = 0x054D;
  9550. t['Sevenroman'] = 0x2166;
  9551. t['Shaarmenian'] = 0x0547;
  9552. t['Shacyrillic'] = 0x0428;
  9553. t['Shchacyrillic'] = 0x0429;
  9554. t['Sheicoptic'] = 0x03E2;
  9555. t['Shhacyrillic'] = 0x04BA;
  9556. t['Shimacoptic'] = 0x03EC;
  9557. t['Sigma'] = 0x03A3;
  9558. t['Sixroman'] = 0x2165;
  9559. t['Smonospace'] = 0xFF33;
  9560. t['Softsigncyrillic'] = 0x042C;
  9561. t['Ssmall'] = 0xF773;
  9562. t['Stigmagreek'] = 0x03DA;
  9563. t['T'] = 0x0054;
  9564. t['Tau'] = 0x03A4;
  9565. t['Tbar'] = 0x0166;
  9566. t['Tcaron'] = 0x0164;
  9567. t['Tcedilla'] = 0x0162;
  9568. t['Tcircle'] = 0x24C9;
  9569. t['Tcircumflexbelow'] = 0x1E70;
  9570. t['Tcommaaccent'] = 0x0162;
  9571. t['Tdotaccent'] = 0x1E6A;
  9572. t['Tdotbelow'] = 0x1E6C;
  9573. t['Tecyrillic'] = 0x0422;
  9574. t['Tedescendercyrillic'] = 0x04AC;
  9575. t['Tenroman'] = 0x2169;
  9576. t['Tetsecyrillic'] = 0x04B4;
  9577. t['Theta'] = 0x0398;
  9578. t['Thook'] = 0x01AC;
  9579. t['Thorn'] = 0x00DE;
  9580. t['Thornsmall'] = 0xF7FE;
  9581. t['Threeroman'] = 0x2162;
  9582. t['Tildesmall'] = 0xF6FE;
  9583. t['Tiwnarmenian'] = 0x054F;
  9584. t['Tlinebelow'] = 0x1E6E;
  9585. t['Tmonospace'] = 0xFF34;
  9586. t['Toarmenian'] = 0x0539;
  9587. t['Tonefive'] = 0x01BC;
  9588. t['Tonesix'] = 0x0184;
  9589. t['Tonetwo'] = 0x01A7;
  9590. t['Tretroflexhook'] = 0x01AE;
  9591. t['Tsecyrillic'] = 0x0426;
  9592. t['Tshecyrillic'] = 0x040B;
  9593. t['Tsmall'] = 0xF774;
  9594. t['Twelveroman'] = 0x216B;
  9595. t['Tworoman'] = 0x2161;
  9596. t['U'] = 0x0055;
  9597. t['Uacute'] = 0x00DA;
  9598. t['Uacutesmall'] = 0xF7FA;
  9599. t['Ubreve'] = 0x016C;
  9600. t['Ucaron'] = 0x01D3;
  9601. t['Ucircle'] = 0x24CA;
  9602. t['Ucircumflex'] = 0x00DB;
  9603. t['Ucircumflexbelow'] = 0x1E76;
  9604. t['Ucircumflexsmall'] = 0xF7FB;
  9605. t['Ucyrillic'] = 0x0423;
  9606. t['Udblacute'] = 0x0170;
  9607. t['Udblgrave'] = 0x0214;
  9608. t['Udieresis'] = 0x00DC;
  9609. t['Udieresisacute'] = 0x01D7;
  9610. t['Udieresisbelow'] = 0x1E72;
  9611. t['Udieresiscaron'] = 0x01D9;
  9612. t['Udieresiscyrillic'] = 0x04F0;
  9613. t['Udieresisgrave'] = 0x01DB;
  9614. t['Udieresismacron'] = 0x01D5;
  9615. t['Udieresissmall'] = 0xF7FC;
  9616. t['Udotbelow'] = 0x1EE4;
  9617. t['Ugrave'] = 0x00D9;
  9618. t['Ugravesmall'] = 0xF7F9;
  9619. t['Uhookabove'] = 0x1EE6;
  9620. t['Uhorn'] = 0x01AF;
  9621. t['Uhornacute'] = 0x1EE8;
  9622. t['Uhorndotbelow'] = 0x1EF0;
  9623. t['Uhorngrave'] = 0x1EEA;
  9624. t['Uhornhookabove'] = 0x1EEC;
  9625. t['Uhorntilde'] = 0x1EEE;
  9626. t['Uhungarumlaut'] = 0x0170;
  9627. t['Uhungarumlautcyrillic'] = 0x04F2;
  9628. t['Uinvertedbreve'] = 0x0216;
  9629. t['Ukcyrillic'] = 0x0478;
  9630. t['Umacron'] = 0x016A;
  9631. t['Umacroncyrillic'] = 0x04EE;
  9632. t['Umacrondieresis'] = 0x1E7A;
  9633. t['Umonospace'] = 0xFF35;
  9634. t['Uogonek'] = 0x0172;
  9635. t['Upsilon'] = 0x03A5;
  9636. t['Upsilon1'] = 0x03D2;
  9637. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9638. t['Upsilonafrican'] = 0x01B1;
  9639. t['Upsilondieresis'] = 0x03AB;
  9640. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9641. t['Upsilonhooksymbol'] = 0x03D2;
  9642. t['Upsilontonos'] = 0x038E;
  9643. t['Uring'] = 0x016E;
  9644. t['Ushortcyrillic'] = 0x040E;
  9645. t['Usmall'] = 0xF775;
  9646. t['Ustraightcyrillic'] = 0x04AE;
  9647. t['Ustraightstrokecyrillic'] = 0x04B0;
  9648. t['Utilde'] = 0x0168;
  9649. t['Utildeacute'] = 0x1E78;
  9650. t['Utildebelow'] = 0x1E74;
  9651. t['V'] = 0x0056;
  9652. t['Vcircle'] = 0x24CB;
  9653. t['Vdotbelow'] = 0x1E7E;
  9654. t['Vecyrillic'] = 0x0412;
  9655. t['Vewarmenian'] = 0x054E;
  9656. t['Vhook'] = 0x01B2;
  9657. t['Vmonospace'] = 0xFF36;
  9658. t['Voarmenian'] = 0x0548;
  9659. t['Vsmall'] = 0xF776;
  9660. t['Vtilde'] = 0x1E7C;
  9661. t['W'] = 0x0057;
  9662. t['Wacute'] = 0x1E82;
  9663. t['Wcircle'] = 0x24CC;
  9664. t['Wcircumflex'] = 0x0174;
  9665. t['Wdieresis'] = 0x1E84;
  9666. t['Wdotaccent'] = 0x1E86;
  9667. t['Wdotbelow'] = 0x1E88;
  9668. t['Wgrave'] = 0x1E80;
  9669. t['Wmonospace'] = 0xFF37;
  9670. t['Wsmall'] = 0xF777;
  9671. t['X'] = 0x0058;
  9672. t['Xcircle'] = 0x24CD;
  9673. t['Xdieresis'] = 0x1E8C;
  9674. t['Xdotaccent'] = 0x1E8A;
  9675. t['Xeharmenian'] = 0x053D;
  9676. t['Xi'] = 0x039E;
  9677. t['Xmonospace'] = 0xFF38;
  9678. t['Xsmall'] = 0xF778;
  9679. t['Y'] = 0x0059;
  9680. t['Yacute'] = 0x00DD;
  9681. t['Yacutesmall'] = 0xF7FD;
  9682. t['Yatcyrillic'] = 0x0462;
  9683. t['Ycircle'] = 0x24CE;
  9684. t['Ycircumflex'] = 0x0176;
  9685. t['Ydieresis'] = 0x0178;
  9686. t['Ydieresissmall'] = 0xF7FF;
  9687. t['Ydotaccent'] = 0x1E8E;
  9688. t['Ydotbelow'] = 0x1EF4;
  9689. t['Yericyrillic'] = 0x042B;
  9690. t['Yerudieresiscyrillic'] = 0x04F8;
  9691. t['Ygrave'] = 0x1EF2;
  9692. t['Yhook'] = 0x01B3;
  9693. t['Yhookabove'] = 0x1EF6;
  9694. t['Yiarmenian'] = 0x0545;
  9695. t['Yicyrillic'] = 0x0407;
  9696. t['Yiwnarmenian'] = 0x0552;
  9697. t['Ymonospace'] = 0xFF39;
  9698. t['Ysmall'] = 0xF779;
  9699. t['Ytilde'] = 0x1EF8;
  9700. t['Yusbigcyrillic'] = 0x046A;
  9701. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9702. t['Yuslittlecyrillic'] = 0x0466;
  9703. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9704. t['Z'] = 0x005A;
  9705. t['Zaarmenian'] = 0x0536;
  9706. t['Zacute'] = 0x0179;
  9707. t['Zcaron'] = 0x017D;
  9708. t['Zcaronsmall'] = 0xF6FF;
  9709. t['Zcircle'] = 0x24CF;
  9710. t['Zcircumflex'] = 0x1E90;
  9711. t['Zdot'] = 0x017B;
  9712. t['Zdotaccent'] = 0x017B;
  9713. t['Zdotbelow'] = 0x1E92;
  9714. t['Zecyrillic'] = 0x0417;
  9715. t['Zedescendercyrillic'] = 0x0498;
  9716. t['Zedieresiscyrillic'] = 0x04DE;
  9717. t['Zeta'] = 0x0396;
  9718. t['Zhearmenian'] = 0x053A;
  9719. t['Zhebrevecyrillic'] = 0x04C1;
  9720. t['Zhecyrillic'] = 0x0416;
  9721. t['Zhedescendercyrillic'] = 0x0496;
  9722. t['Zhedieresiscyrillic'] = 0x04DC;
  9723. t['Zlinebelow'] = 0x1E94;
  9724. t['Zmonospace'] = 0xFF3A;
  9725. t['Zsmall'] = 0xF77A;
  9726. t['Zstroke'] = 0x01B5;
  9727. t['a'] = 0x0061;
  9728. t['aabengali'] = 0x0986;
  9729. t['aacute'] = 0x00E1;
  9730. t['aadeva'] = 0x0906;
  9731. t['aagujarati'] = 0x0A86;
  9732. t['aagurmukhi'] = 0x0A06;
  9733. t['aamatragurmukhi'] = 0x0A3E;
  9734. t['aarusquare'] = 0x3303;
  9735. t['aavowelsignbengali'] = 0x09BE;
  9736. t['aavowelsigndeva'] = 0x093E;
  9737. t['aavowelsigngujarati'] = 0x0ABE;
  9738. t['abbreviationmarkarmenian'] = 0x055F;
  9739. t['abbreviationsigndeva'] = 0x0970;
  9740. t['abengali'] = 0x0985;
  9741. t['abopomofo'] = 0x311A;
  9742. t['abreve'] = 0x0103;
  9743. t['abreveacute'] = 0x1EAF;
  9744. t['abrevecyrillic'] = 0x04D1;
  9745. t['abrevedotbelow'] = 0x1EB7;
  9746. t['abrevegrave'] = 0x1EB1;
  9747. t['abrevehookabove'] = 0x1EB3;
  9748. t['abrevetilde'] = 0x1EB5;
  9749. t['acaron'] = 0x01CE;
  9750. t['acircle'] = 0x24D0;
  9751. t['acircumflex'] = 0x00E2;
  9752. t['acircumflexacute'] = 0x1EA5;
  9753. t['acircumflexdotbelow'] = 0x1EAD;
  9754. t['acircumflexgrave'] = 0x1EA7;
  9755. t['acircumflexhookabove'] = 0x1EA9;
  9756. t['acircumflextilde'] = 0x1EAB;
  9757. t['acute'] = 0x00B4;
  9758. t['acutebelowcmb'] = 0x0317;
  9759. t['acutecmb'] = 0x0301;
  9760. t['acutecomb'] = 0x0301;
  9761. t['acutedeva'] = 0x0954;
  9762. t['acutelowmod'] = 0x02CF;
  9763. t['acutetonecmb'] = 0x0341;
  9764. t['acyrillic'] = 0x0430;
  9765. t['adblgrave'] = 0x0201;
  9766. t['addakgurmukhi'] = 0x0A71;
  9767. t['adeva'] = 0x0905;
  9768. t['adieresis'] = 0x00E4;
  9769. t['adieresiscyrillic'] = 0x04D3;
  9770. t['adieresismacron'] = 0x01DF;
  9771. t['adotbelow'] = 0x1EA1;
  9772. t['adotmacron'] = 0x01E1;
  9773. t['ae'] = 0x00E6;
  9774. t['aeacute'] = 0x01FD;
  9775. t['aekorean'] = 0x3150;
  9776. t['aemacron'] = 0x01E3;
  9777. t['afii00208'] = 0x2015;
  9778. t['afii08941'] = 0x20A4;
  9779. t['afii10017'] = 0x0410;
  9780. t['afii10018'] = 0x0411;
  9781. t['afii10019'] = 0x0412;
  9782. t['afii10020'] = 0x0413;
  9783. t['afii10021'] = 0x0414;
  9784. t['afii10022'] = 0x0415;
  9785. t['afii10023'] = 0x0401;
  9786. t['afii10024'] = 0x0416;
  9787. t['afii10025'] = 0x0417;
  9788. t['afii10026'] = 0x0418;
  9789. t['afii10027'] = 0x0419;
  9790. t['afii10028'] = 0x041A;
  9791. t['afii10029'] = 0x041B;
  9792. t['afii10030'] = 0x041C;
  9793. t['afii10031'] = 0x041D;
  9794. t['afii10032'] = 0x041E;
  9795. t['afii10033'] = 0x041F;
  9796. t['afii10034'] = 0x0420;
  9797. t['afii10035'] = 0x0421;
  9798. t['afii10036'] = 0x0422;
  9799. t['afii10037'] = 0x0423;
  9800. t['afii10038'] = 0x0424;
  9801. t['afii10039'] = 0x0425;
  9802. t['afii10040'] = 0x0426;
  9803. t['afii10041'] = 0x0427;
  9804. t['afii10042'] = 0x0428;
  9805. t['afii10043'] = 0x0429;
  9806. t['afii10044'] = 0x042A;
  9807. t['afii10045'] = 0x042B;
  9808. t['afii10046'] = 0x042C;
  9809. t['afii10047'] = 0x042D;
  9810. t['afii10048'] = 0x042E;
  9811. t['afii10049'] = 0x042F;
  9812. t['afii10050'] = 0x0490;
  9813. t['afii10051'] = 0x0402;
  9814. t['afii10052'] = 0x0403;
  9815. t['afii10053'] = 0x0404;
  9816. t['afii10054'] = 0x0405;
  9817. t['afii10055'] = 0x0406;
  9818. t['afii10056'] = 0x0407;
  9819. t['afii10057'] = 0x0408;
  9820. t['afii10058'] = 0x0409;
  9821. t['afii10059'] = 0x040A;
  9822. t['afii10060'] = 0x040B;
  9823. t['afii10061'] = 0x040C;
  9824. t['afii10062'] = 0x040E;
  9825. t['afii10063'] = 0xF6C4;
  9826. t['afii10064'] = 0xF6C5;
  9827. t['afii10065'] = 0x0430;
  9828. t['afii10066'] = 0x0431;
  9829. t['afii10067'] = 0x0432;
  9830. t['afii10068'] = 0x0433;
  9831. t['afii10069'] = 0x0434;
  9832. t['afii10070'] = 0x0435;
  9833. t['afii10071'] = 0x0451;
  9834. t['afii10072'] = 0x0436;
  9835. t['afii10073'] = 0x0437;
  9836. t['afii10074'] = 0x0438;
  9837. t['afii10075'] = 0x0439;
  9838. t['afii10076'] = 0x043A;
  9839. t['afii10077'] = 0x043B;
  9840. t['afii10078'] = 0x043C;
  9841. t['afii10079'] = 0x043D;
  9842. t['afii10080'] = 0x043E;
  9843. t['afii10081'] = 0x043F;
  9844. t['afii10082'] = 0x0440;
  9845. t['afii10083'] = 0x0441;
  9846. t['afii10084'] = 0x0442;
  9847. t['afii10085'] = 0x0443;
  9848. t['afii10086'] = 0x0444;
  9849. t['afii10087'] = 0x0445;
  9850. t['afii10088'] = 0x0446;
  9851. t['afii10089'] = 0x0447;
  9852. t['afii10090'] = 0x0448;
  9853. t['afii10091'] = 0x0449;
  9854. t['afii10092'] = 0x044A;
  9855. t['afii10093'] = 0x044B;
  9856. t['afii10094'] = 0x044C;
  9857. t['afii10095'] = 0x044D;
  9858. t['afii10096'] = 0x044E;
  9859. t['afii10097'] = 0x044F;
  9860. t['afii10098'] = 0x0491;
  9861. t['afii10099'] = 0x0452;
  9862. t['afii10100'] = 0x0453;
  9863. t['afii10101'] = 0x0454;
  9864. t['afii10102'] = 0x0455;
  9865. t['afii10103'] = 0x0456;
  9866. t['afii10104'] = 0x0457;
  9867. t['afii10105'] = 0x0458;
  9868. t['afii10106'] = 0x0459;
  9869. t['afii10107'] = 0x045A;
  9870. t['afii10108'] = 0x045B;
  9871. t['afii10109'] = 0x045C;
  9872. t['afii10110'] = 0x045E;
  9873. t['afii10145'] = 0x040F;
  9874. t['afii10146'] = 0x0462;
  9875. t['afii10147'] = 0x0472;
  9876. t['afii10148'] = 0x0474;
  9877. t['afii10192'] = 0xF6C6;
  9878. t['afii10193'] = 0x045F;
  9879. t['afii10194'] = 0x0463;
  9880. t['afii10195'] = 0x0473;
  9881. t['afii10196'] = 0x0475;
  9882. t['afii10831'] = 0xF6C7;
  9883. t['afii10832'] = 0xF6C8;
  9884. t['afii10846'] = 0x04D9;
  9885. t['afii299'] = 0x200E;
  9886. t['afii300'] = 0x200F;
  9887. t['afii301'] = 0x200D;
  9888. t['afii57381'] = 0x066A;
  9889. t['afii57388'] = 0x060C;
  9890. t['afii57392'] = 0x0660;
  9891. t['afii57393'] = 0x0661;
  9892. t['afii57394'] = 0x0662;
  9893. t['afii57395'] = 0x0663;
  9894. t['afii57396'] = 0x0664;
  9895. t['afii57397'] = 0x0665;
  9896. t['afii57398'] = 0x0666;
  9897. t['afii57399'] = 0x0667;
  9898. t['afii57400'] = 0x0668;
  9899. t['afii57401'] = 0x0669;
  9900. t['afii57403'] = 0x061B;
  9901. t['afii57407'] = 0x061F;
  9902. t['afii57409'] = 0x0621;
  9903. t['afii57410'] = 0x0622;
  9904. t['afii57411'] = 0x0623;
  9905. t['afii57412'] = 0x0624;
  9906. t['afii57413'] = 0x0625;
  9907. t['afii57414'] = 0x0626;
  9908. t['afii57415'] = 0x0627;
  9909. t['afii57416'] = 0x0628;
  9910. t['afii57417'] = 0x0629;
  9911. t['afii57418'] = 0x062A;
  9912. t['afii57419'] = 0x062B;
  9913. t['afii57420'] = 0x062C;
  9914. t['afii57421'] = 0x062D;
  9915. t['afii57422'] = 0x062E;
  9916. t['afii57423'] = 0x062F;
  9917. t['afii57424'] = 0x0630;
  9918. t['afii57425'] = 0x0631;
  9919. t['afii57426'] = 0x0632;
  9920. t['afii57427'] = 0x0633;
  9921. t['afii57428'] = 0x0634;
  9922. t['afii57429'] = 0x0635;
  9923. t['afii57430'] = 0x0636;
  9924. t['afii57431'] = 0x0637;
  9925. t['afii57432'] = 0x0638;
  9926. t['afii57433'] = 0x0639;
  9927. t['afii57434'] = 0x063A;
  9928. t['afii57440'] = 0x0640;
  9929. t['afii57441'] = 0x0641;
  9930. t['afii57442'] = 0x0642;
  9931. t['afii57443'] = 0x0643;
  9932. t['afii57444'] = 0x0644;
  9933. t['afii57445'] = 0x0645;
  9934. t['afii57446'] = 0x0646;
  9935. t['afii57448'] = 0x0648;
  9936. t['afii57449'] = 0x0649;
  9937. t['afii57450'] = 0x064A;
  9938. t['afii57451'] = 0x064B;
  9939. t['afii57452'] = 0x064C;
  9940. t['afii57453'] = 0x064D;
  9941. t['afii57454'] = 0x064E;
  9942. t['afii57455'] = 0x064F;
  9943. t['afii57456'] = 0x0650;
  9944. t['afii57457'] = 0x0651;
  9945. t['afii57458'] = 0x0652;
  9946. t['afii57470'] = 0x0647;
  9947. t['afii57505'] = 0x06A4;
  9948. t['afii57506'] = 0x067E;
  9949. t['afii57507'] = 0x0686;
  9950. t['afii57508'] = 0x0698;
  9951. t['afii57509'] = 0x06AF;
  9952. t['afii57511'] = 0x0679;
  9953. t['afii57512'] = 0x0688;
  9954. t['afii57513'] = 0x0691;
  9955. t['afii57514'] = 0x06BA;
  9956. t['afii57519'] = 0x06D2;
  9957. t['afii57534'] = 0x06D5;
  9958. t['afii57636'] = 0x20AA;
  9959. t['afii57645'] = 0x05BE;
  9960. t['afii57658'] = 0x05C3;
  9961. t['afii57664'] = 0x05D0;
  9962. t['afii57665'] = 0x05D1;
  9963. t['afii57666'] = 0x05D2;
  9964. t['afii57667'] = 0x05D3;
  9965. t['afii57668'] = 0x05D4;
  9966. t['afii57669'] = 0x05D5;
  9967. t['afii57670'] = 0x05D6;
  9968. t['afii57671'] = 0x05D7;
  9969. t['afii57672'] = 0x05D8;
  9970. t['afii57673'] = 0x05D9;
  9971. t['afii57674'] = 0x05DA;
  9972. t['afii57675'] = 0x05DB;
  9973. t['afii57676'] = 0x05DC;
  9974. t['afii57677'] = 0x05DD;
  9975. t['afii57678'] = 0x05DE;
  9976. t['afii57679'] = 0x05DF;
  9977. t['afii57680'] = 0x05E0;
  9978. t['afii57681'] = 0x05E1;
  9979. t['afii57682'] = 0x05E2;
  9980. t['afii57683'] = 0x05E3;
  9981. t['afii57684'] = 0x05E4;
  9982. t['afii57685'] = 0x05E5;
  9983. t['afii57686'] = 0x05E6;
  9984. t['afii57687'] = 0x05E7;
  9985. t['afii57688'] = 0x05E8;
  9986. t['afii57689'] = 0x05E9;
  9987. t['afii57690'] = 0x05EA;
  9988. t['afii57694'] = 0xFB2A;
  9989. t['afii57695'] = 0xFB2B;
  9990. t['afii57700'] = 0xFB4B;
  9991. t['afii57705'] = 0xFB1F;
  9992. t['afii57716'] = 0x05F0;
  9993. t['afii57717'] = 0x05F1;
  9994. t['afii57718'] = 0x05F2;
  9995. t['afii57723'] = 0xFB35;
  9996. t['afii57793'] = 0x05B4;
  9997. t['afii57794'] = 0x05B5;
  9998. t['afii57795'] = 0x05B6;
  9999. t['afii57796'] = 0x05BB;
  10000. t['afii57797'] = 0x05B8;
  10001. t['afii57798'] = 0x05B7;
  10002. t['afii57799'] = 0x05B0;
  10003. t['afii57800'] = 0x05B2;
  10004. t['afii57801'] = 0x05B1;
  10005. t['afii57802'] = 0x05B3;
  10006. t['afii57803'] = 0x05C2;
  10007. t['afii57804'] = 0x05C1;
  10008. t['afii57806'] = 0x05B9;
  10009. t['afii57807'] = 0x05BC;
  10010. t['afii57839'] = 0x05BD;
  10011. t['afii57841'] = 0x05BF;
  10012. t['afii57842'] = 0x05C0;
  10013. t['afii57929'] = 0x02BC;
  10014. t['afii61248'] = 0x2105;
  10015. t['afii61289'] = 0x2113;
  10016. t['afii61352'] = 0x2116;
  10017. t['afii61573'] = 0x202C;
  10018. t['afii61574'] = 0x202D;
  10019. t['afii61575'] = 0x202E;
  10020. t['afii61664'] = 0x200C;
  10021. t['afii63167'] = 0x066D;
  10022. t['afii64937'] = 0x02BD;
  10023. t['agrave'] = 0x00E0;
  10024. t['agujarati'] = 0x0A85;
  10025. t['agurmukhi'] = 0x0A05;
  10026. t['ahiragana'] = 0x3042;
  10027. t['ahookabove'] = 0x1EA3;
  10028. t['aibengali'] = 0x0990;
  10029. t['aibopomofo'] = 0x311E;
  10030. t['aideva'] = 0x0910;
  10031. t['aiecyrillic'] = 0x04D5;
  10032. t['aigujarati'] = 0x0A90;
  10033. t['aigurmukhi'] = 0x0A10;
  10034. t['aimatragurmukhi'] = 0x0A48;
  10035. t['ainarabic'] = 0x0639;
  10036. t['ainfinalarabic'] = 0xFECA;
  10037. t['aininitialarabic'] = 0xFECB;
  10038. t['ainmedialarabic'] = 0xFECC;
  10039. t['ainvertedbreve'] = 0x0203;
  10040. t['aivowelsignbengali'] = 0x09C8;
  10041. t['aivowelsigndeva'] = 0x0948;
  10042. t['aivowelsigngujarati'] = 0x0AC8;
  10043. t['akatakana'] = 0x30A2;
  10044. t['akatakanahalfwidth'] = 0xFF71;
  10045. t['akorean'] = 0x314F;
  10046. t['alef'] = 0x05D0;
  10047. t['alefarabic'] = 0x0627;
  10048. t['alefdageshhebrew'] = 0xFB30;
  10049. t['aleffinalarabic'] = 0xFE8E;
  10050. t['alefhamzaabovearabic'] = 0x0623;
  10051. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10052. t['alefhamzabelowarabic'] = 0x0625;
  10053. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10054. t['alefhebrew'] = 0x05D0;
  10055. t['aleflamedhebrew'] = 0xFB4F;
  10056. t['alefmaddaabovearabic'] = 0x0622;
  10057. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10058. t['alefmaksuraarabic'] = 0x0649;
  10059. t['alefmaksurafinalarabic'] = 0xFEF0;
  10060. t['alefmaksurainitialarabic'] = 0xFEF3;
  10061. t['alefmaksuramedialarabic'] = 0xFEF4;
  10062. t['alefpatahhebrew'] = 0xFB2E;
  10063. t['alefqamatshebrew'] = 0xFB2F;
  10064. t['aleph'] = 0x2135;
  10065. t['allequal'] = 0x224C;
  10066. t['alpha'] = 0x03B1;
  10067. t['alphatonos'] = 0x03AC;
  10068. t['amacron'] = 0x0101;
  10069. t['amonospace'] = 0xFF41;
  10070. t['ampersand'] = 0x0026;
  10071. t['ampersandmonospace'] = 0xFF06;
  10072. t['ampersandsmall'] = 0xF726;
  10073. t['amsquare'] = 0x33C2;
  10074. t['anbopomofo'] = 0x3122;
  10075. t['angbopomofo'] = 0x3124;
  10076. t['angbracketleft'] = 0x3008;
  10077. // Glyph is missing from Adobe's original list.
  10078. t['angbracketright'] = 0x3009;
  10079. // Glyph is missing from Adobe's original list.
  10080. t['angkhankhuthai'] = 0x0E5A;
  10081. t['angle'] = 0x2220;
  10082. t['anglebracketleft'] = 0x3008;
  10083. t['anglebracketleftvertical'] = 0xFE3F;
  10084. t['anglebracketright'] = 0x3009;
  10085. t['anglebracketrightvertical'] = 0xFE40;
  10086. t['angleleft'] = 0x2329;
  10087. t['angleright'] = 0x232A;
  10088. t['angstrom'] = 0x212B;
  10089. t['anoteleia'] = 0x0387;
  10090. t['anudattadeva'] = 0x0952;
  10091. t['anusvarabengali'] = 0x0982;
  10092. t['anusvaradeva'] = 0x0902;
  10093. t['anusvaragujarati'] = 0x0A82;
  10094. t['aogonek'] = 0x0105;
  10095. t['apaatosquare'] = 0x3300;
  10096. t['aparen'] = 0x249C;
  10097. t['apostrophearmenian'] = 0x055A;
  10098. t['apostrophemod'] = 0x02BC;
  10099. t['apple'] = 0xF8FF;
  10100. t['approaches'] = 0x2250;
  10101. t['approxequal'] = 0x2248;
  10102. t['approxequalorimage'] = 0x2252;
  10103. t['approximatelyequal'] = 0x2245;
  10104. t['araeaekorean'] = 0x318E;
  10105. t['araeakorean'] = 0x318D;
  10106. t['arc'] = 0x2312;
  10107. t['arighthalfring'] = 0x1E9A;
  10108. t['aring'] = 0x00E5;
  10109. t['aringacute'] = 0x01FB;
  10110. t['aringbelow'] = 0x1E01;
  10111. t['arrowboth'] = 0x2194;
  10112. t['arrowdashdown'] = 0x21E3;
  10113. t['arrowdashleft'] = 0x21E0;
  10114. t['arrowdashright'] = 0x21E2;
  10115. t['arrowdashup'] = 0x21E1;
  10116. t['arrowdblboth'] = 0x21D4;
  10117. t['arrowdbldown'] = 0x21D3;
  10118. t['arrowdblleft'] = 0x21D0;
  10119. t['arrowdblright'] = 0x21D2;
  10120. t['arrowdblup'] = 0x21D1;
  10121. t['arrowdown'] = 0x2193;
  10122. t['arrowdownleft'] = 0x2199;
  10123. t['arrowdownright'] = 0x2198;
  10124. t['arrowdownwhite'] = 0x21E9;
  10125. t['arrowheaddownmod'] = 0x02C5;
  10126. t['arrowheadleftmod'] = 0x02C2;
  10127. t['arrowheadrightmod'] = 0x02C3;
  10128. t['arrowheadupmod'] = 0x02C4;
  10129. t['arrowhorizex'] = 0xF8E7;
  10130. t['arrowleft'] = 0x2190;
  10131. t['arrowleftdbl'] = 0x21D0;
  10132. t['arrowleftdblstroke'] = 0x21CD;
  10133. t['arrowleftoverright'] = 0x21C6;
  10134. t['arrowleftwhite'] = 0x21E6;
  10135. t['arrowright'] = 0x2192;
  10136. t['arrowrightdblstroke'] = 0x21CF;
  10137. t['arrowrightheavy'] = 0x279E;
  10138. t['arrowrightoverleft'] = 0x21C4;
  10139. t['arrowrightwhite'] = 0x21E8;
  10140. t['arrowtableft'] = 0x21E4;
  10141. t['arrowtabright'] = 0x21E5;
  10142. t['arrowup'] = 0x2191;
  10143. t['arrowupdn'] = 0x2195;
  10144. t['arrowupdnbse'] = 0x21A8;
  10145. t['arrowupdownbase'] = 0x21A8;
  10146. t['arrowupleft'] = 0x2196;
  10147. t['arrowupleftofdown'] = 0x21C5;
  10148. t['arrowupright'] = 0x2197;
  10149. t['arrowupwhite'] = 0x21E7;
  10150. t['arrowvertex'] = 0xF8E6;
  10151. t['asciicircum'] = 0x005E;
  10152. t['asciicircummonospace'] = 0xFF3E;
  10153. t['asciitilde'] = 0x007E;
  10154. t['asciitildemonospace'] = 0xFF5E;
  10155. t['ascript'] = 0x0251;
  10156. t['ascriptturned'] = 0x0252;
  10157. t['asmallhiragana'] = 0x3041;
  10158. t['asmallkatakana'] = 0x30A1;
  10159. t['asmallkatakanahalfwidth'] = 0xFF67;
  10160. t['asterisk'] = 0x002A;
  10161. t['asteriskaltonearabic'] = 0x066D;
  10162. t['asteriskarabic'] = 0x066D;
  10163. t['asteriskmath'] = 0x2217;
  10164. t['asteriskmonospace'] = 0xFF0A;
  10165. t['asterisksmall'] = 0xFE61;
  10166. t['asterism'] = 0x2042;
  10167. t['asuperior'] = 0xF6E9;
  10168. t['asymptoticallyequal'] = 0x2243;
  10169. t['at'] = 0x0040;
  10170. t['atilde'] = 0x00E3;
  10171. t['atmonospace'] = 0xFF20;
  10172. t['atsmall'] = 0xFE6B;
  10173. t['aturned'] = 0x0250;
  10174. t['aubengali'] = 0x0994;
  10175. t['aubopomofo'] = 0x3120;
  10176. t['audeva'] = 0x0914;
  10177. t['augujarati'] = 0x0A94;
  10178. t['augurmukhi'] = 0x0A14;
  10179. t['aulengthmarkbengali'] = 0x09D7;
  10180. t['aumatragurmukhi'] = 0x0A4C;
  10181. t['auvowelsignbengali'] = 0x09CC;
  10182. t['auvowelsigndeva'] = 0x094C;
  10183. t['auvowelsigngujarati'] = 0x0ACC;
  10184. t['avagrahadeva'] = 0x093D;
  10185. t['aybarmenian'] = 0x0561;
  10186. t['ayin'] = 0x05E2;
  10187. t['ayinaltonehebrew'] = 0xFB20;
  10188. t['ayinhebrew'] = 0x05E2;
  10189. t['b'] = 0x0062;
  10190. t['babengali'] = 0x09AC;
  10191. t['backslash'] = 0x005C;
  10192. t['backslashmonospace'] = 0xFF3C;
  10193. t['badeva'] = 0x092C;
  10194. t['bagujarati'] = 0x0AAC;
  10195. t['bagurmukhi'] = 0x0A2C;
  10196. t['bahiragana'] = 0x3070;
  10197. t['bahtthai'] = 0x0E3F;
  10198. t['bakatakana'] = 0x30D0;
  10199. t['bar'] = 0x007C;
  10200. t['barmonospace'] = 0xFF5C;
  10201. t['bbopomofo'] = 0x3105;
  10202. t['bcircle'] = 0x24D1;
  10203. t['bdotaccent'] = 0x1E03;
  10204. t['bdotbelow'] = 0x1E05;
  10205. t['beamedsixteenthnotes'] = 0x266C;
  10206. t['because'] = 0x2235;
  10207. t['becyrillic'] = 0x0431;
  10208. t['beharabic'] = 0x0628;
  10209. t['behfinalarabic'] = 0xFE90;
  10210. t['behinitialarabic'] = 0xFE91;
  10211. t['behiragana'] = 0x3079;
  10212. t['behmedialarabic'] = 0xFE92;
  10213. t['behmeeminitialarabic'] = 0xFC9F;
  10214. t['behmeemisolatedarabic'] = 0xFC08;
  10215. t['behnoonfinalarabic'] = 0xFC6D;
  10216. t['bekatakana'] = 0x30D9;
  10217. t['benarmenian'] = 0x0562;
  10218. t['bet'] = 0x05D1;
  10219. t['beta'] = 0x03B2;
  10220. t['betasymbolgreek'] = 0x03D0;
  10221. t['betdagesh'] = 0xFB31;
  10222. t['betdageshhebrew'] = 0xFB31;
  10223. t['bethebrew'] = 0x05D1;
  10224. t['betrafehebrew'] = 0xFB4C;
  10225. t['bhabengali'] = 0x09AD;
  10226. t['bhadeva'] = 0x092D;
  10227. t['bhagujarati'] = 0x0AAD;
  10228. t['bhagurmukhi'] = 0x0A2D;
  10229. t['bhook'] = 0x0253;
  10230. t['bihiragana'] = 0x3073;
  10231. t['bikatakana'] = 0x30D3;
  10232. t['bilabialclick'] = 0x0298;
  10233. t['bindigurmukhi'] = 0x0A02;
  10234. t['birusquare'] = 0x3331;
  10235. t['blackcircle'] = 0x25CF;
  10236. t['blackdiamond'] = 0x25C6;
  10237. t['blackdownpointingtriangle'] = 0x25BC;
  10238. t['blackleftpointingpointer'] = 0x25C4;
  10239. t['blackleftpointingtriangle'] = 0x25C0;
  10240. t['blacklenticularbracketleft'] = 0x3010;
  10241. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10242. t['blacklenticularbracketright'] = 0x3011;
  10243. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10244. t['blacklowerlefttriangle'] = 0x25E3;
  10245. t['blacklowerrighttriangle'] = 0x25E2;
  10246. t['blackrectangle'] = 0x25AC;
  10247. t['blackrightpointingpointer'] = 0x25BA;
  10248. t['blackrightpointingtriangle'] = 0x25B6;
  10249. t['blacksmallsquare'] = 0x25AA;
  10250. t['blacksmilingface'] = 0x263B;
  10251. t['blacksquare'] = 0x25A0;
  10252. t['blackstar'] = 0x2605;
  10253. t['blackupperlefttriangle'] = 0x25E4;
  10254. t['blackupperrighttriangle'] = 0x25E5;
  10255. t['blackuppointingsmalltriangle'] = 0x25B4;
  10256. t['blackuppointingtriangle'] = 0x25B2;
  10257. t['blank'] = 0x2423;
  10258. t['blinebelow'] = 0x1E07;
  10259. t['block'] = 0x2588;
  10260. t['bmonospace'] = 0xFF42;
  10261. t['bobaimaithai'] = 0x0E1A;
  10262. t['bohiragana'] = 0x307C;
  10263. t['bokatakana'] = 0x30DC;
  10264. t['bparen'] = 0x249D;
  10265. t['bqsquare'] = 0x33C3;
  10266. t['braceex'] = 0xF8F4;
  10267. t['braceleft'] = 0x007B;
  10268. t['braceleftbt'] = 0xF8F3;
  10269. t['braceleftmid'] = 0xF8F2;
  10270. t['braceleftmonospace'] = 0xFF5B;
  10271. t['braceleftsmall'] = 0xFE5B;
  10272. t['bracelefttp'] = 0xF8F1;
  10273. t['braceleftvertical'] = 0xFE37;
  10274. t['braceright'] = 0x007D;
  10275. t['bracerightbt'] = 0xF8FE;
  10276. t['bracerightmid'] = 0xF8FD;
  10277. t['bracerightmonospace'] = 0xFF5D;
  10278. t['bracerightsmall'] = 0xFE5C;
  10279. t['bracerighttp'] = 0xF8FC;
  10280. t['bracerightvertical'] = 0xFE38;
  10281. t['bracketleft'] = 0x005B;
  10282. t['bracketleftbt'] = 0xF8F0;
  10283. t['bracketleftex'] = 0xF8EF;
  10284. t['bracketleftmonospace'] = 0xFF3B;
  10285. t['bracketlefttp'] = 0xF8EE;
  10286. t['bracketright'] = 0x005D;
  10287. t['bracketrightbt'] = 0xF8FB;
  10288. t['bracketrightex'] = 0xF8FA;
  10289. t['bracketrightmonospace'] = 0xFF3D;
  10290. t['bracketrighttp'] = 0xF8F9;
  10291. t['breve'] = 0x02D8;
  10292. t['brevebelowcmb'] = 0x032E;
  10293. t['brevecmb'] = 0x0306;
  10294. t['breveinvertedbelowcmb'] = 0x032F;
  10295. t['breveinvertedcmb'] = 0x0311;
  10296. t['breveinverteddoublecmb'] = 0x0361;
  10297. t['bridgebelowcmb'] = 0x032A;
  10298. t['bridgeinvertedbelowcmb'] = 0x033A;
  10299. t['brokenbar'] = 0x00A6;
  10300. t['bstroke'] = 0x0180;
  10301. t['bsuperior'] = 0xF6EA;
  10302. t['btopbar'] = 0x0183;
  10303. t['buhiragana'] = 0x3076;
  10304. t['bukatakana'] = 0x30D6;
  10305. t['bullet'] = 0x2022;
  10306. t['bulletinverse'] = 0x25D8;
  10307. t['bulletoperator'] = 0x2219;
  10308. t['bullseye'] = 0x25CE;
  10309. t['c'] = 0x0063;
  10310. t['caarmenian'] = 0x056E;
  10311. t['cabengali'] = 0x099A;
  10312. t['cacute'] = 0x0107;
  10313. t['cadeva'] = 0x091A;
  10314. t['cagujarati'] = 0x0A9A;
  10315. t['cagurmukhi'] = 0x0A1A;
  10316. t['calsquare'] = 0x3388;
  10317. t['candrabindubengali'] = 0x0981;
  10318. t['candrabinducmb'] = 0x0310;
  10319. t['candrabindudeva'] = 0x0901;
  10320. t['candrabindugujarati'] = 0x0A81;
  10321. t['capslock'] = 0x21EA;
  10322. t['careof'] = 0x2105;
  10323. t['caron'] = 0x02C7;
  10324. t['caronbelowcmb'] = 0x032C;
  10325. t['caroncmb'] = 0x030C;
  10326. t['carriagereturn'] = 0x21B5;
  10327. t['cbopomofo'] = 0x3118;
  10328. t['ccaron'] = 0x010D;
  10329. t['ccedilla'] = 0x00E7;
  10330. t['ccedillaacute'] = 0x1E09;
  10331. t['ccircle'] = 0x24D2;
  10332. t['ccircumflex'] = 0x0109;
  10333. t['ccurl'] = 0x0255;
  10334. t['cdot'] = 0x010B;
  10335. t['cdotaccent'] = 0x010B;
  10336. t['cdsquare'] = 0x33C5;
  10337. t['cedilla'] = 0x00B8;
  10338. t['cedillacmb'] = 0x0327;
  10339. t['cent'] = 0x00A2;
  10340. t['centigrade'] = 0x2103;
  10341. t['centinferior'] = 0xF6DF;
  10342. t['centmonospace'] = 0xFFE0;
  10343. t['centoldstyle'] = 0xF7A2;
  10344. t['centsuperior'] = 0xF6E0;
  10345. t['chaarmenian'] = 0x0579;
  10346. t['chabengali'] = 0x099B;
  10347. t['chadeva'] = 0x091B;
  10348. t['chagujarati'] = 0x0A9B;
  10349. t['chagurmukhi'] = 0x0A1B;
  10350. t['chbopomofo'] = 0x3114;
  10351. t['cheabkhasiancyrillic'] = 0x04BD;
  10352. t['checkmark'] = 0x2713;
  10353. t['checyrillic'] = 0x0447;
  10354. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10355. t['chedescendercyrillic'] = 0x04B7;
  10356. t['chedieresiscyrillic'] = 0x04F5;
  10357. t['cheharmenian'] = 0x0573;
  10358. t['chekhakassiancyrillic'] = 0x04CC;
  10359. t['cheverticalstrokecyrillic'] = 0x04B9;
  10360. t['chi'] = 0x03C7;
  10361. t['chieuchacirclekorean'] = 0x3277;
  10362. t['chieuchaparenkorean'] = 0x3217;
  10363. t['chieuchcirclekorean'] = 0x3269;
  10364. t['chieuchkorean'] = 0x314A;
  10365. t['chieuchparenkorean'] = 0x3209;
  10366. t['chochangthai'] = 0x0E0A;
  10367. t['chochanthai'] = 0x0E08;
  10368. t['chochingthai'] = 0x0E09;
  10369. t['chochoethai'] = 0x0E0C;
  10370. t['chook'] = 0x0188;
  10371. t['cieucacirclekorean'] = 0x3276;
  10372. t['cieucaparenkorean'] = 0x3216;
  10373. t['cieuccirclekorean'] = 0x3268;
  10374. t['cieuckorean'] = 0x3148;
  10375. t['cieucparenkorean'] = 0x3208;
  10376. t['cieucuparenkorean'] = 0x321C;
  10377. t['circle'] = 0x25CB;
  10378. t['circlecopyrt'] = 0x00A9;
  10379. // Glyph is missing from Adobe's original list.
  10380. t['circlemultiply'] = 0x2297;
  10381. t['circleot'] = 0x2299;
  10382. t['circleplus'] = 0x2295;
  10383. t['circlepostalmark'] = 0x3036;
  10384. t['circlewithlefthalfblack'] = 0x25D0;
  10385. t['circlewithrighthalfblack'] = 0x25D1;
  10386. t['circumflex'] = 0x02C6;
  10387. t['circumflexbelowcmb'] = 0x032D;
  10388. t['circumflexcmb'] = 0x0302;
  10389. t['clear'] = 0x2327;
  10390. t['clickalveolar'] = 0x01C2;
  10391. t['clickdental'] = 0x01C0;
  10392. t['clicklateral'] = 0x01C1;
  10393. t['clickretroflex'] = 0x01C3;
  10394. t['club'] = 0x2663;
  10395. t['clubsuitblack'] = 0x2663;
  10396. t['clubsuitwhite'] = 0x2667;
  10397. t['cmcubedsquare'] = 0x33A4;
  10398. t['cmonospace'] = 0xFF43;
  10399. t['cmsquaredsquare'] = 0x33A0;
  10400. t['coarmenian'] = 0x0581;
  10401. t['colon'] = 0x003A;
  10402. t['colonmonetary'] = 0x20A1;
  10403. t['colonmonospace'] = 0xFF1A;
  10404. t['colonsign'] = 0x20A1;
  10405. t['colonsmall'] = 0xFE55;
  10406. t['colontriangularhalfmod'] = 0x02D1;
  10407. t['colontriangularmod'] = 0x02D0;
  10408. t['comma'] = 0x002C;
  10409. t['commaabovecmb'] = 0x0313;
  10410. t['commaaboverightcmb'] = 0x0315;
  10411. t['commaaccent'] = 0xF6C3;
  10412. t['commaarabic'] = 0x060C;
  10413. t['commaarmenian'] = 0x055D;
  10414. t['commainferior'] = 0xF6E1;
  10415. t['commamonospace'] = 0xFF0C;
  10416. t['commareversedabovecmb'] = 0x0314;
  10417. t['commareversedmod'] = 0x02BD;
  10418. t['commasmall'] = 0xFE50;
  10419. t['commasuperior'] = 0xF6E2;
  10420. t['commaturnedabovecmb'] = 0x0312;
  10421. t['commaturnedmod'] = 0x02BB;
  10422. t['compass'] = 0x263C;
  10423. t['congruent'] = 0x2245;
  10424. t['contourintegral'] = 0x222E;
  10425. t['control'] = 0x2303;
  10426. t['controlACK'] = 0x0006;
  10427. t['controlBEL'] = 0x0007;
  10428. t['controlBS'] = 0x0008;
  10429. t['controlCAN'] = 0x0018;
  10430. t['controlCR'] = 0x000D;
  10431. t['controlDC1'] = 0x0011;
  10432. t['controlDC2'] = 0x0012;
  10433. t['controlDC3'] = 0x0013;
  10434. t['controlDC4'] = 0x0014;
  10435. t['controlDEL'] = 0x007F;
  10436. t['controlDLE'] = 0x0010;
  10437. t['controlEM'] = 0x0019;
  10438. t['controlENQ'] = 0x0005;
  10439. t['controlEOT'] = 0x0004;
  10440. t['controlESC'] = 0x001B;
  10441. t['controlETB'] = 0x0017;
  10442. t['controlETX'] = 0x0003;
  10443. t['controlFF'] = 0x000C;
  10444. t['controlFS'] = 0x001C;
  10445. t['controlGS'] = 0x001D;
  10446. t['controlHT'] = 0x0009;
  10447. t['controlLF'] = 0x000A;
  10448. t['controlNAK'] = 0x0015;
  10449. t['controlRS'] = 0x001E;
  10450. t['controlSI'] = 0x000F;
  10451. t['controlSO'] = 0x000E;
  10452. t['controlSOT'] = 0x0002;
  10453. t['controlSTX'] = 0x0001;
  10454. t['controlSUB'] = 0x001A;
  10455. t['controlSYN'] = 0x0016;
  10456. t['controlUS'] = 0x001F;
  10457. t['controlVT'] = 0x000B;
  10458. t['copyright'] = 0x00A9;
  10459. t['copyrightsans'] = 0xF8E9;
  10460. t['copyrightserif'] = 0xF6D9;
  10461. t['cornerbracketleft'] = 0x300C;
  10462. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10463. t['cornerbracketleftvertical'] = 0xFE41;
  10464. t['cornerbracketright'] = 0x300D;
  10465. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10466. t['cornerbracketrightvertical'] = 0xFE42;
  10467. t['corporationsquare'] = 0x337F;
  10468. t['cosquare'] = 0x33C7;
  10469. t['coverkgsquare'] = 0x33C6;
  10470. t['cparen'] = 0x249E;
  10471. t['cruzeiro'] = 0x20A2;
  10472. t['cstretched'] = 0x0297;
  10473. t['curlyand'] = 0x22CF;
  10474. t['curlyor'] = 0x22CE;
  10475. t['currency'] = 0x00A4;
  10476. t['cyrBreve'] = 0xF6D1;
  10477. t['cyrFlex'] = 0xF6D2;
  10478. t['cyrbreve'] = 0xF6D4;
  10479. t['cyrflex'] = 0xF6D5;
  10480. t['d'] = 0x0064;
  10481. t['daarmenian'] = 0x0564;
  10482. t['dabengali'] = 0x09A6;
  10483. t['dadarabic'] = 0x0636;
  10484. t['dadeva'] = 0x0926;
  10485. t['dadfinalarabic'] = 0xFEBE;
  10486. t['dadinitialarabic'] = 0xFEBF;
  10487. t['dadmedialarabic'] = 0xFEC0;
  10488. t['dagesh'] = 0x05BC;
  10489. t['dageshhebrew'] = 0x05BC;
  10490. t['dagger'] = 0x2020;
  10491. t['daggerdbl'] = 0x2021;
  10492. t['dagujarati'] = 0x0AA6;
  10493. t['dagurmukhi'] = 0x0A26;
  10494. t['dahiragana'] = 0x3060;
  10495. t['dakatakana'] = 0x30C0;
  10496. t['dalarabic'] = 0x062F;
  10497. t['dalet'] = 0x05D3;
  10498. t['daletdagesh'] = 0xFB33;
  10499. t['daletdageshhebrew'] = 0xFB33;
  10500. t['dalethebrew'] = 0x05D3;
  10501. t['dalfinalarabic'] = 0xFEAA;
  10502. t['dammaarabic'] = 0x064F;
  10503. t['dammalowarabic'] = 0x064F;
  10504. t['dammatanaltonearabic'] = 0x064C;
  10505. t['dammatanarabic'] = 0x064C;
  10506. t['danda'] = 0x0964;
  10507. t['dargahebrew'] = 0x05A7;
  10508. t['dargalefthebrew'] = 0x05A7;
  10509. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10510. t['dblGrave'] = 0xF6D3;
  10511. t['dblanglebracketleft'] = 0x300A;
  10512. t['dblanglebracketleftvertical'] = 0xFE3D;
  10513. t['dblanglebracketright'] = 0x300B;
  10514. t['dblanglebracketrightvertical'] = 0xFE3E;
  10515. t['dblarchinvertedbelowcmb'] = 0x032B;
  10516. t['dblarrowleft'] = 0x21D4;
  10517. t['dblarrowright'] = 0x21D2;
  10518. t['dbldanda'] = 0x0965;
  10519. t['dblgrave'] = 0xF6D6;
  10520. t['dblgravecmb'] = 0x030F;
  10521. t['dblintegral'] = 0x222C;
  10522. t['dbllowline'] = 0x2017;
  10523. t['dbllowlinecmb'] = 0x0333;
  10524. t['dbloverlinecmb'] = 0x033F;
  10525. t['dblprimemod'] = 0x02BA;
  10526. t['dblverticalbar'] = 0x2016;
  10527. t['dblverticallineabovecmb'] = 0x030E;
  10528. t['dbopomofo'] = 0x3109;
  10529. t['dbsquare'] = 0x33C8;
  10530. t['dcaron'] = 0x010F;
  10531. t['dcedilla'] = 0x1E11;
  10532. t['dcircle'] = 0x24D3;
  10533. t['dcircumflexbelow'] = 0x1E13;
  10534. t['dcroat'] = 0x0111;
  10535. t['ddabengali'] = 0x09A1;
  10536. t['ddadeva'] = 0x0921;
  10537. t['ddagujarati'] = 0x0AA1;
  10538. t['ddagurmukhi'] = 0x0A21;
  10539. t['ddalarabic'] = 0x0688;
  10540. t['ddalfinalarabic'] = 0xFB89;
  10541. t['dddhadeva'] = 0x095C;
  10542. t['ddhabengali'] = 0x09A2;
  10543. t['ddhadeva'] = 0x0922;
  10544. t['ddhagujarati'] = 0x0AA2;
  10545. t['ddhagurmukhi'] = 0x0A22;
  10546. t['ddotaccent'] = 0x1E0B;
  10547. t['ddotbelow'] = 0x1E0D;
  10548. t['decimalseparatorarabic'] = 0x066B;
  10549. t['decimalseparatorpersian'] = 0x066B;
  10550. t['decyrillic'] = 0x0434;
  10551. t['degree'] = 0x00B0;
  10552. t['dehihebrew'] = 0x05AD;
  10553. t['dehiragana'] = 0x3067;
  10554. t['deicoptic'] = 0x03EF;
  10555. t['dekatakana'] = 0x30C7;
  10556. t['deleteleft'] = 0x232B;
  10557. t['deleteright'] = 0x2326;
  10558. t['delta'] = 0x03B4;
  10559. t['deltaturned'] = 0x018D;
  10560. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10561. t['dezh'] = 0x02A4;
  10562. t['dhabengali'] = 0x09A7;
  10563. t['dhadeva'] = 0x0927;
  10564. t['dhagujarati'] = 0x0AA7;
  10565. t['dhagurmukhi'] = 0x0A27;
  10566. t['dhook'] = 0x0257;
  10567. t['dialytikatonos'] = 0x0385;
  10568. t['dialytikatonoscmb'] = 0x0344;
  10569. t['diamond'] = 0x2666;
  10570. t['diamondsuitwhite'] = 0x2662;
  10571. t['dieresis'] = 0x00A8;
  10572. t['dieresisacute'] = 0xF6D7;
  10573. t['dieresisbelowcmb'] = 0x0324;
  10574. t['dieresiscmb'] = 0x0308;
  10575. t['dieresisgrave'] = 0xF6D8;
  10576. t['dieresistonos'] = 0x0385;
  10577. t['dihiragana'] = 0x3062;
  10578. t['dikatakana'] = 0x30C2;
  10579. t['dittomark'] = 0x3003;
  10580. t['divide'] = 0x00F7;
  10581. t['divides'] = 0x2223;
  10582. t['divisionslash'] = 0x2215;
  10583. t['djecyrillic'] = 0x0452;
  10584. t['dkshade'] = 0x2593;
  10585. t['dlinebelow'] = 0x1E0F;
  10586. t['dlsquare'] = 0x3397;
  10587. t['dmacron'] = 0x0111;
  10588. t['dmonospace'] = 0xFF44;
  10589. t['dnblock'] = 0x2584;
  10590. t['dochadathai'] = 0x0E0E;
  10591. t['dodekthai'] = 0x0E14;
  10592. t['dohiragana'] = 0x3069;
  10593. t['dokatakana'] = 0x30C9;
  10594. t['dollar'] = 0x0024;
  10595. t['dollarinferior'] = 0xF6E3;
  10596. t['dollarmonospace'] = 0xFF04;
  10597. t['dollaroldstyle'] = 0xF724;
  10598. t['dollarsmall'] = 0xFE69;
  10599. t['dollarsuperior'] = 0xF6E4;
  10600. t['dong'] = 0x20AB;
  10601. t['dorusquare'] = 0x3326;
  10602. t['dotaccent'] = 0x02D9;
  10603. t['dotaccentcmb'] = 0x0307;
  10604. t['dotbelowcmb'] = 0x0323;
  10605. t['dotbelowcomb'] = 0x0323;
  10606. t['dotkatakana'] = 0x30FB;
  10607. t['dotlessi'] = 0x0131;
  10608. t['dotlessj'] = 0xF6BE;
  10609. t['dotlessjstrokehook'] = 0x0284;
  10610. t['dotmath'] = 0x22C5;
  10611. t['dottedcircle'] = 0x25CC;
  10612. t['doubleyodpatah'] = 0xFB1F;
  10613. t['doubleyodpatahhebrew'] = 0xFB1F;
  10614. t['downtackbelowcmb'] = 0x031E;
  10615. t['downtackmod'] = 0x02D5;
  10616. t['dparen'] = 0x249F;
  10617. t['dsuperior'] = 0xF6EB;
  10618. t['dtail'] = 0x0256;
  10619. t['dtopbar'] = 0x018C;
  10620. t['duhiragana'] = 0x3065;
  10621. t['dukatakana'] = 0x30C5;
  10622. t['dz'] = 0x01F3;
  10623. t['dzaltone'] = 0x02A3;
  10624. t['dzcaron'] = 0x01C6;
  10625. t['dzcurl'] = 0x02A5;
  10626. t['dzeabkhasiancyrillic'] = 0x04E1;
  10627. t['dzecyrillic'] = 0x0455;
  10628. t['dzhecyrillic'] = 0x045F;
  10629. t['e'] = 0x0065;
  10630. t['eacute'] = 0x00E9;
  10631. t['earth'] = 0x2641;
  10632. t['ebengali'] = 0x098F;
  10633. t['ebopomofo'] = 0x311C;
  10634. t['ebreve'] = 0x0115;
  10635. t['ecandradeva'] = 0x090D;
  10636. t['ecandragujarati'] = 0x0A8D;
  10637. t['ecandravowelsigndeva'] = 0x0945;
  10638. t['ecandravowelsigngujarati'] = 0x0AC5;
  10639. t['ecaron'] = 0x011B;
  10640. t['ecedillabreve'] = 0x1E1D;
  10641. t['echarmenian'] = 0x0565;
  10642. t['echyiwnarmenian'] = 0x0587;
  10643. t['ecircle'] = 0x24D4;
  10644. t['ecircumflex'] = 0x00EA;
  10645. t['ecircumflexacute'] = 0x1EBF;
  10646. t['ecircumflexbelow'] = 0x1E19;
  10647. t['ecircumflexdotbelow'] = 0x1EC7;
  10648. t['ecircumflexgrave'] = 0x1EC1;
  10649. t['ecircumflexhookabove'] = 0x1EC3;
  10650. t['ecircumflextilde'] = 0x1EC5;
  10651. t['ecyrillic'] = 0x0454;
  10652. t['edblgrave'] = 0x0205;
  10653. t['edeva'] = 0x090F;
  10654. t['edieresis'] = 0x00EB;
  10655. t['edot'] = 0x0117;
  10656. t['edotaccent'] = 0x0117;
  10657. t['edotbelow'] = 0x1EB9;
  10658. t['eegurmukhi'] = 0x0A0F;
  10659. t['eematragurmukhi'] = 0x0A47;
  10660. t['efcyrillic'] = 0x0444;
  10661. t['egrave'] = 0x00E8;
  10662. t['egujarati'] = 0x0A8F;
  10663. t['eharmenian'] = 0x0567;
  10664. t['ehbopomofo'] = 0x311D;
  10665. t['ehiragana'] = 0x3048;
  10666. t['ehookabove'] = 0x1EBB;
  10667. t['eibopomofo'] = 0x311F;
  10668. t['eight'] = 0x0038;
  10669. t['eightarabic'] = 0x0668;
  10670. t['eightbengali'] = 0x09EE;
  10671. t['eightcircle'] = 0x2467;
  10672. t['eightcircleinversesansserif'] = 0x2791;
  10673. t['eightdeva'] = 0x096E;
  10674. t['eighteencircle'] = 0x2471;
  10675. t['eighteenparen'] = 0x2485;
  10676. t['eighteenperiod'] = 0x2499;
  10677. t['eightgujarati'] = 0x0AEE;
  10678. t['eightgurmukhi'] = 0x0A6E;
  10679. t['eighthackarabic'] = 0x0668;
  10680. t['eighthangzhou'] = 0x3028;
  10681. t['eighthnotebeamed'] = 0x266B;
  10682. t['eightideographicparen'] = 0x3227;
  10683. t['eightinferior'] = 0x2088;
  10684. t['eightmonospace'] = 0xFF18;
  10685. t['eightoldstyle'] = 0xF738;
  10686. t['eightparen'] = 0x247B;
  10687. t['eightperiod'] = 0x248F;
  10688. t['eightpersian'] = 0x06F8;
  10689. t['eightroman'] = 0x2177;
  10690. t['eightsuperior'] = 0x2078;
  10691. t['eightthai'] = 0x0E58;
  10692. t['einvertedbreve'] = 0x0207;
  10693. t['eiotifiedcyrillic'] = 0x0465;
  10694. t['ekatakana'] = 0x30A8;
  10695. t['ekatakanahalfwidth'] = 0xFF74;
  10696. t['ekonkargurmukhi'] = 0x0A74;
  10697. t['ekorean'] = 0x3154;
  10698. t['elcyrillic'] = 0x043B;
  10699. t['element'] = 0x2208;
  10700. t['elevencircle'] = 0x246A;
  10701. t['elevenparen'] = 0x247E;
  10702. t['elevenperiod'] = 0x2492;
  10703. t['elevenroman'] = 0x217A;
  10704. t['ellipsis'] = 0x2026;
  10705. t['ellipsisvertical'] = 0x22EE;
  10706. t['emacron'] = 0x0113;
  10707. t['emacronacute'] = 0x1E17;
  10708. t['emacrongrave'] = 0x1E15;
  10709. t['emcyrillic'] = 0x043C;
  10710. t['emdash'] = 0x2014;
  10711. t['emdashvertical'] = 0xFE31;
  10712. t['emonospace'] = 0xFF45;
  10713. t['emphasismarkarmenian'] = 0x055B;
  10714. t['emptyset'] = 0x2205;
  10715. t['enbopomofo'] = 0x3123;
  10716. t['encyrillic'] = 0x043D;
  10717. t['endash'] = 0x2013;
  10718. t['endashvertical'] = 0xFE32;
  10719. t['endescendercyrillic'] = 0x04A3;
  10720. t['eng'] = 0x014B;
  10721. t['engbopomofo'] = 0x3125;
  10722. t['enghecyrillic'] = 0x04A5;
  10723. t['enhookcyrillic'] = 0x04C8;
  10724. t['enspace'] = 0x2002;
  10725. t['eogonek'] = 0x0119;
  10726. t['eokorean'] = 0x3153;
  10727. t['eopen'] = 0x025B;
  10728. t['eopenclosed'] = 0x029A;
  10729. t['eopenreversed'] = 0x025C;
  10730. t['eopenreversedclosed'] = 0x025E;
  10731. t['eopenreversedhook'] = 0x025D;
  10732. t['eparen'] = 0x24A0;
  10733. t['epsilon'] = 0x03B5;
  10734. t['epsilontonos'] = 0x03AD;
  10735. t['equal'] = 0x003D;
  10736. t['equalmonospace'] = 0xFF1D;
  10737. t['equalsmall'] = 0xFE66;
  10738. t['equalsuperior'] = 0x207C;
  10739. t['equivalence'] = 0x2261;
  10740. t['erbopomofo'] = 0x3126;
  10741. t['ercyrillic'] = 0x0440;
  10742. t['ereversed'] = 0x0258;
  10743. t['ereversedcyrillic'] = 0x044D;
  10744. t['escyrillic'] = 0x0441;
  10745. t['esdescendercyrillic'] = 0x04AB;
  10746. t['esh'] = 0x0283;
  10747. t['eshcurl'] = 0x0286;
  10748. t['eshortdeva'] = 0x090E;
  10749. t['eshortvowelsigndeva'] = 0x0946;
  10750. t['eshreversedloop'] = 0x01AA;
  10751. t['eshsquatreversed'] = 0x0285;
  10752. t['esmallhiragana'] = 0x3047;
  10753. t['esmallkatakana'] = 0x30A7;
  10754. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10755. t['estimated'] = 0x212E;
  10756. t['esuperior'] = 0xF6EC;
  10757. t['eta'] = 0x03B7;
  10758. t['etarmenian'] = 0x0568;
  10759. t['etatonos'] = 0x03AE;
  10760. t['eth'] = 0x00F0;
  10761. t['etilde'] = 0x1EBD;
  10762. t['etildebelow'] = 0x1E1B;
  10763. t['etnahtafoukhhebrew'] = 0x0591;
  10764. t['etnahtafoukhlefthebrew'] = 0x0591;
  10765. t['etnahtahebrew'] = 0x0591;
  10766. t['etnahtalefthebrew'] = 0x0591;
  10767. t['eturned'] = 0x01DD;
  10768. t['eukorean'] = 0x3161;
  10769. t['euro'] = 0x20AC;
  10770. t['evowelsignbengali'] = 0x09C7;
  10771. t['evowelsigndeva'] = 0x0947;
  10772. t['evowelsigngujarati'] = 0x0AC7;
  10773. t['exclam'] = 0x0021;
  10774. t['exclamarmenian'] = 0x055C;
  10775. t['exclamdbl'] = 0x203C;
  10776. t['exclamdown'] = 0x00A1;
  10777. t['exclamdownsmall'] = 0xF7A1;
  10778. t['exclammonospace'] = 0xFF01;
  10779. t['exclamsmall'] = 0xF721;
  10780. t['existential'] = 0x2203;
  10781. t['ezh'] = 0x0292;
  10782. t['ezhcaron'] = 0x01EF;
  10783. t['ezhcurl'] = 0x0293;
  10784. t['ezhreversed'] = 0x01B9;
  10785. t['ezhtail'] = 0x01BA;
  10786. t['f'] = 0x0066;
  10787. t['fadeva'] = 0x095E;
  10788. t['fagurmukhi'] = 0x0A5E;
  10789. t['fahrenheit'] = 0x2109;
  10790. t['fathaarabic'] = 0x064E;
  10791. t['fathalowarabic'] = 0x064E;
  10792. t['fathatanarabic'] = 0x064B;
  10793. t['fbopomofo'] = 0x3108;
  10794. t['fcircle'] = 0x24D5;
  10795. t['fdotaccent'] = 0x1E1F;
  10796. t['feharabic'] = 0x0641;
  10797. t['feharmenian'] = 0x0586;
  10798. t['fehfinalarabic'] = 0xFED2;
  10799. t['fehinitialarabic'] = 0xFED3;
  10800. t['fehmedialarabic'] = 0xFED4;
  10801. t['feicoptic'] = 0x03E5;
  10802. t['female'] = 0x2640;
  10803. t['ff'] = 0xFB00;
  10804. t['ffi'] = 0xFB03;
  10805. t['ffl'] = 0xFB04;
  10806. t['fi'] = 0xFB01;
  10807. t['fifteencircle'] = 0x246E;
  10808. t['fifteenparen'] = 0x2482;
  10809. t['fifteenperiod'] = 0x2496;
  10810. t['figuredash'] = 0x2012;
  10811. t['filledbox'] = 0x25A0;
  10812. t['filledrect'] = 0x25AC;
  10813. t['finalkaf'] = 0x05DA;
  10814. t['finalkafdagesh'] = 0xFB3A;
  10815. t['finalkafdageshhebrew'] = 0xFB3A;
  10816. t['finalkafhebrew'] = 0x05DA;
  10817. t['finalmem'] = 0x05DD;
  10818. t['finalmemhebrew'] = 0x05DD;
  10819. t['finalnun'] = 0x05DF;
  10820. t['finalnunhebrew'] = 0x05DF;
  10821. t['finalpe'] = 0x05E3;
  10822. t['finalpehebrew'] = 0x05E3;
  10823. t['finaltsadi'] = 0x05E5;
  10824. t['finaltsadihebrew'] = 0x05E5;
  10825. t['firsttonechinese'] = 0x02C9;
  10826. t['fisheye'] = 0x25C9;
  10827. t['fitacyrillic'] = 0x0473;
  10828. t['five'] = 0x0035;
  10829. t['fivearabic'] = 0x0665;
  10830. t['fivebengali'] = 0x09EB;
  10831. t['fivecircle'] = 0x2464;
  10832. t['fivecircleinversesansserif'] = 0x278E;
  10833. t['fivedeva'] = 0x096B;
  10834. t['fiveeighths'] = 0x215D;
  10835. t['fivegujarati'] = 0x0AEB;
  10836. t['fivegurmukhi'] = 0x0A6B;
  10837. t['fivehackarabic'] = 0x0665;
  10838. t['fivehangzhou'] = 0x3025;
  10839. t['fiveideographicparen'] = 0x3224;
  10840. t['fiveinferior'] = 0x2085;
  10841. t['fivemonospace'] = 0xFF15;
  10842. t['fiveoldstyle'] = 0xF735;
  10843. t['fiveparen'] = 0x2478;
  10844. t['fiveperiod'] = 0x248C;
  10845. t['fivepersian'] = 0x06F5;
  10846. t['fiveroman'] = 0x2174;
  10847. t['fivesuperior'] = 0x2075;
  10848. t['fivethai'] = 0x0E55;
  10849. t['fl'] = 0xFB02;
  10850. t['florin'] = 0x0192;
  10851. t['fmonospace'] = 0xFF46;
  10852. t['fmsquare'] = 0x3399;
  10853. t['fofanthai'] = 0x0E1F;
  10854. t['fofathai'] = 0x0E1D;
  10855. t['fongmanthai'] = 0x0E4F;
  10856. t['forall'] = 0x2200;
  10857. t['four'] = 0x0034;
  10858. t['fourarabic'] = 0x0664;
  10859. t['fourbengali'] = 0x09EA;
  10860. t['fourcircle'] = 0x2463;
  10861. t['fourcircleinversesansserif'] = 0x278D;
  10862. t['fourdeva'] = 0x096A;
  10863. t['fourgujarati'] = 0x0AEA;
  10864. t['fourgurmukhi'] = 0x0A6A;
  10865. t['fourhackarabic'] = 0x0664;
  10866. t['fourhangzhou'] = 0x3024;
  10867. t['fourideographicparen'] = 0x3223;
  10868. t['fourinferior'] = 0x2084;
  10869. t['fourmonospace'] = 0xFF14;
  10870. t['fournumeratorbengali'] = 0x09F7;
  10871. t['fouroldstyle'] = 0xF734;
  10872. t['fourparen'] = 0x2477;
  10873. t['fourperiod'] = 0x248B;
  10874. t['fourpersian'] = 0x06F4;
  10875. t['fourroman'] = 0x2173;
  10876. t['foursuperior'] = 0x2074;
  10877. t['fourteencircle'] = 0x246D;
  10878. t['fourteenparen'] = 0x2481;
  10879. t['fourteenperiod'] = 0x2495;
  10880. t['fourthai'] = 0x0E54;
  10881. t['fourthtonechinese'] = 0x02CB;
  10882. t['fparen'] = 0x24A1;
  10883. t['fraction'] = 0x2044;
  10884. t['franc'] = 0x20A3;
  10885. t['g'] = 0x0067;
  10886. t['gabengali'] = 0x0997;
  10887. t['gacute'] = 0x01F5;
  10888. t['gadeva'] = 0x0917;
  10889. t['gafarabic'] = 0x06AF;
  10890. t['gaffinalarabic'] = 0xFB93;
  10891. t['gafinitialarabic'] = 0xFB94;
  10892. t['gafmedialarabic'] = 0xFB95;
  10893. t['gagujarati'] = 0x0A97;
  10894. t['gagurmukhi'] = 0x0A17;
  10895. t['gahiragana'] = 0x304C;
  10896. t['gakatakana'] = 0x30AC;
  10897. t['gamma'] = 0x03B3;
  10898. t['gammalatinsmall'] = 0x0263;
  10899. t['gammasuperior'] = 0x02E0;
  10900. t['gangiacoptic'] = 0x03EB;
  10901. t['gbopomofo'] = 0x310D;
  10902. t['gbreve'] = 0x011F;
  10903. t['gcaron'] = 0x01E7;
  10904. t['gcedilla'] = 0x0123;
  10905. t['gcircle'] = 0x24D6;
  10906. t['gcircumflex'] = 0x011D;
  10907. t['gcommaaccent'] = 0x0123;
  10908. t['gdot'] = 0x0121;
  10909. t['gdotaccent'] = 0x0121;
  10910. t['gecyrillic'] = 0x0433;
  10911. t['gehiragana'] = 0x3052;
  10912. t['gekatakana'] = 0x30B2;
  10913. t['geometricallyequal'] = 0x2251;
  10914. t['gereshaccenthebrew'] = 0x059C;
  10915. t['gereshhebrew'] = 0x05F3;
  10916. t['gereshmuqdamhebrew'] = 0x059D;
  10917. t['germandbls'] = 0x00DF;
  10918. t['gershayimaccenthebrew'] = 0x059E;
  10919. t['gershayimhebrew'] = 0x05F4;
  10920. t['getamark'] = 0x3013;
  10921. t['ghabengali'] = 0x0998;
  10922. t['ghadarmenian'] = 0x0572;
  10923. t['ghadeva'] = 0x0918;
  10924. t['ghagujarati'] = 0x0A98;
  10925. t['ghagurmukhi'] = 0x0A18;
  10926. t['ghainarabic'] = 0x063A;
  10927. t['ghainfinalarabic'] = 0xFECE;
  10928. t['ghaininitialarabic'] = 0xFECF;
  10929. t['ghainmedialarabic'] = 0xFED0;
  10930. t['ghemiddlehookcyrillic'] = 0x0495;
  10931. t['ghestrokecyrillic'] = 0x0493;
  10932. t['gheupturncyrillic'] = 0x0491;
  10933. t['ghhadeva'] = 0x095A;
  10934. t['ghhagurmukhi'] = 0x0A5A;
  10935. t['ghook'] = 0x0260;
  10936. t['ghzsquare'] = 0x3393;
  10937. t['gihiragana'] = 0x304E;
  10938. t['gikatakana'] = 0x30AE;
  10939. t['gimarmenian'] = 0x0563;
  10940. t['gimel'] = 0x05D2;
  10941. t['gimeldagesh'] = 0xFB32;
  10942. t['gimeldageshhebrew'] = 0xFB32;
  10943. t['gimelhebrew'] = 0x05D2;
  10944. t['gjecyrillic'] = 0x0453;
  10945. t['glottalinvertedstroke'] = 0x01BE;
  10946. t['glottalstop'] = 0x0294;
  10947. t['glottalstopinverted'] = 0x0296;
  10948. t['glottalstopmod'] = 0x02C0;
  10949. t['glottalstopreversed'] = 0x0295;
  10950. t['glottalstopreversedmod'] = 0x02C1;
  10951. t['glottalstopreversedsuperior'] = 0x02E4;
  10952. t['glottalstopstroke'] = 0x02A1;
  10953. t['glottalstopstrokereversed'] = 0x02A2;
  10954. t['gmacron'] = 0x1E21;
  10955. t['gmonospace'] = 0xFF47;
  10956. t['gohiragana'] = 0x3054;
  10957. t['gokatakana'] = 0x30B4;
  10958. t['gparen'] = 0x24A2;
  10959. t['gpasquare'] = 0x33AC;
  10960. t['gradient'] = 0x2207;
  10961. t['grave'] = 0x0060;
  10962. t['gravebelowcmb'] = 0x0316;
  10963. t['gravecmb'] = 0x0300;
  10964. t['gravecomb'] = 0x0300;
  10965. t['gravedeva'] = 0x0953;
  10966. t['gravelowmod'] = 0x02CE;
  10967. t['gravemonospace'] = 0xFF40;
  10968. t['gravetonecmb'] = 0x0340;
  10969. t['greater'] = 0x003E;
  10970. t['greaterequal'] = 0x2265;
  10971. t['greaterequalorless'] = 0x22DB;
  10972. t['greatermonospace'] = 0xFF1E;
  10973. t['greaterorequivalent'] = 0x2273;
  10974. t['greaterorless'] = 0x2277;
  10975. t['greateroverequal'] = 0x2267;
  10976. t['greatersmall'] = 0xFE65;
  10977. t['gscript'] = 0x0261;
  10978. t['gstroke'] = 0x01E5;
  10979. t['guhiragana'] = 0x3050;
  10980. t['guillemotleft'] = 0x00AB;
  10981. t['guillemotright'] = 0x00BB;
  10982. t['guilsinglleft'] = 0x2039;
  10983. t['guilsinglright'] = 0x203A;
  10984. t['gukatakana'] = 0x30B0;
  10985. t['guramusquare'] = 0x3318;
  10986. t['gysquare'] = 0x33C9;
  10987. t['h'] = 0x0068;
  10988. t['haabkhasiancyrillic'] = 0x04A9;
  10989. t['haaltonearabic'] = 0x06C1;
  10990. t['habengali'] = 0x09B9;
  10991. t['hadescendercyrillic'] = 0x04B3;
  10992. t['hadeva'] = 0x0939;
  10993. t['hagujarati'] = 0x0AB9;
  10994. t['hagurmukhi'] = 0x0A39;
  10995. t['haharabic'] = 0x062D;
  10996. t['hahfinalarabic'] = 0xFEA2;
  10997. t['hahinitialarabic'] = 0xFEA3;
  10998. t['hahiragana'] = 0x306F;
  10999. t['hahmedialarabic'] = 0xFEA4;
  11000. t['haitusquare'] = 0x332A;
  11001. t['hakatakana'] = 0x30CF;
  11002. t['hakatakanahalfwidth'] = 0xFF8A;
  11003. t['halantgurmukhi'] = 0x0A4D;
  11004. t['hamzaarabic'] = 0x0621;
  11005. t['hamzalowarabic'] = 0x0621;
  11006. t['hangulfiller'] = 0x3164;
  11007. t['hardsigncyrillic'] = 0x044A;
  11008. t['harpoonleftbarbup'] = 0x21BC;
  11009. t['harpoonrightbarbup'] = 0x21C0;
  11010. t['hasquare'] = 0x33CA;
  11011. t['hatafpatah'] = 0x05B2;
  11012. t['hatafpatah16'] = 0x05B2;
  11013. t['hatafpatah23'] = 0x05B2;
  11014. t['hatafpatah2f'] = 0x05B2;
  11015. t['hatafpatahhebrew'] = 0x05B2;
  11016. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11017. t['hatafpatahquarterhebrew'] = 0x05B2;
  11018. t['hatafpatahwidehebrew'] = 0x05B2;
  11019. t['hatafqamats'] = 0x05B3;
  11020. t['hatafqamats1b'] = 0x05B3;
  11021. t['hatafqamats28'] = 0x05B3;
  11022. t['hatafqamats34'] = 0x05B3;
  11023. t['hatafqamatshebrew'] = 0x05B3;
  11024. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11025. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11026. t['hatafqamatswidehebrew'] = 0x05B3;
  11027. t['hatafsegol'] = 0x05B1;
  11028. t['hatafsegol17'] = 0x05B1;
  11029. t['hatafsegol24'] = 0x05B1;
  11030. t['hatafsegol30'] = 0x05B1;
  11031. t['hatafsegolhebrew'] = 0x05B1;
  11032. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11033. t['hatafsegolquarterhebrew'] = 0x05B1;
  11034. t['hatafsegolwidehebrew'] = 0x05B1;
  11035. t['hbar'] = 0x0127;
  11036. t['hbopomofo'] = 0x310F;
  11037. t['hbrevebelow'] = 0x1E2B;
  11038. t['hcedilla'] = 0x1E29;
  11039. t['hcircle'] = 0x24D7;
  11040. t['hcircumflex'] = 0x0125;
  11041. t['hdieresis'] = 0x1E27;
  11042. t['hdotaccent'] = 0x1E23;
  11043. t['hdotbelow'] = 0x1E25;
  11044. t['he'] = 0x05D4;
  11045. t['heart'] = 0x2665;
  11046. t['heartsuitblack'] = 0x2665;
  11047. t['heartsuitwhite'] = 0x2661;
  11048. t['hedagesh'] = 0xFB34;
  11049. t['hedageshhebrew'] = 0xFB34;
  11050. t['hehaltonearabic'] = 0x06C1;
  11051. t['heharabic'] = 0x0647;
  11052. t['hehebrew'] = 0x05D4;
  11053. t['hehfinalaltonearabic'] = 0xFBA7;
  11054. t['hehfinalalttwoarabic'] = 0xFEEA;
  11055. t['hehfinalarabic'] = 0xFEEA;
  11056. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11057. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11058. t['hehinitialaltonearabic'] = 0xFBA8;
  11059. t['hehinitialarabic'] = 0xFEEB;
  11060. t['hehiragana'] = 0x3078;
  11061. t['hehmedialaltonearabic'] = 0xFBA9;
  11062. t['hehmedialarabic'] = 0xFEEC;
  11063. t['heiseierasquare'] = 0x337B;
  11064. t['hekatakana'] = 0x30D8;
  11065. t['hekatakanahalfwidth'] = 0xFF8D;
  11066. t['hekutaarusquare'] = 0x3336;
  11067. t['henghook'] = 0x0267;
  11068. t['herutusquare'] = 0x3339;
  11069. t['het'] = 0x05D7;
  11070. t['hethebrew'] = 0x05D7;
  11071. t['hhook'] = 0x0266;
  11072. t['hhooksuperior'] = 0x02B1;
  11073. t['hieuhacirclekorean'] = 0x327B;
  11074. t['hieuhaparenkorean'] = 0x321B;
  11075. t['hieuhcirclekorean'] = 0x326D;
  11076. t['hieuhkorean'] = 0x314E;
  11077. t['hieuhparenkorean'] = 0x320D;
  11078. t['hihiragana'] = 0x3072;
  11079. t['hikatakana'] = 0x30D2;
  11080. t['hikatakanahalfwidth'] = 0xFF8B;
  11081. t['hiriq'] = 0x05B4;
  11082. t['hiriq14'] = 0x05B4;
  11083. t['hiriq21'] = 0x05B4;
  11084. t['hiriq2d'] = 0x05B4;
  11085. t['hiriqhebrew'] = 0x05B4;
  11086. t['hiriqnarrowhebrew'] = 0x05B4;
  11087. t['hiriqquarterhebrew'] = 0x05B4;
  11088. t['hiriqwidehebrew'] = 0x05B4;
  11089. t['hlinebelow'] = 0x1E96;
  11090. t['hmonospace'] = 0xFF48;
  11091. t['hoarmenian'] = 0x0570;
  11092. t['hohipthai'] = 0x0E2B;
  11093. t['hohiragana'] = 0x307B;
  11094. t['hokatakana'] = 0x30DB;
  11095. t['hokatakanahalfwidth'] = 0xFF8E;
  11096. t['holam'] = 0x05B9;
  11097. t['holam19'] = 0x05B9;
  11098. t['holam26'] = 0x05B9;
  11099. t['holam32'] = 0x05B9;
  11100. t['holamhebrew'] = 0x05B9;
  11101. t['holamnarrowhebrew'] = 0x05B9;
  11102. t['holamquarterhebrew'] = 0x05B9;
  11103. t['holamwidehebrew'] = 0x05B9;
  11104. t['honokhukthai'] = 0x0E2E;
  11105. t['hookabovecomb'] = 0x0309;
  11106. t['hookcmb'] = 0x0309;
  11107. t['hookpalatalizedbelowcmb'] = 0x0321;
  11108. t['hookretroflexbelowcmb'] = 0x0322;
  11109. t['hoonsquare'] = 0x3342;
  11110. t['horicoptic'] = 0x03E9;
  11111. t['horizontalbar'] = 0x2015;
  11112. t['horncmb'] = 0x031B;
  11113. t['hotsprings'] = 0x2668;
  11114. t['house'] = 0x2302;
  11115. t['hparen'] = 0x24A3;
  11116. t['hsuperior'] = 0x02B0;
  11117. t['hturned'] = 0x0265;
  11118. t['huhiragana'] = 0x3075;
  11119. t['huiitosquare'] = 0x3333;
  11120. t['hukatakana'] = 0x30D5;
  11121. t['hukatakanahalfwidth'] = 0xFF8C;
  11122. t['hungarumlaut'] = 0x02DD;
  11123. t['hungarumlautcmb'] = 0x030B;
  11124. t['hv'] = 0x0195;
  11125. t['hyphen'] = 0x002D;
  11126. t['hypheninferior'] = 0xF6E5;
  11127. t['hyphenmonospace'] = 0xFF0D;
  11128. t['hyphensmall'] = 0xFE63;
  11129. t['hyphensuperior'] = 0xF6E6;
  11130. t['hyphentwo'] = 0x2010;
  11131. t['i'] = 0x0069;
  11132. t['iacute'] = 0x00ED;
  11133. t['iacyrillic'] = 0x044F;
  11134. t['ibengali'] = 0x0987;
  11135. t['ibopomofo'] = 0x3127;
  11136. t['ibreve'] = 0x012D;
  11137. t['icaron'] = 0x01D0;
  11138. t['icircle'] = 0x24D8;
  11139. t['icircumflex'] = 0x00EE;
  11140. t['icyrillic'] = 0x0456;
  11141. t['idblgrave'] = 0x0209;
  11142. t['ideographearthcircle'] = 0x328F;
  11143. t['ideographfirecircle'] = 0x328B;
  11144. t['ideographicallianceparen'] = 0x323F;
  11145. t['ideographiccallparen'] = 0x323A;
  11146. t['ideographiccentrecircle'] = 0x32A5;
  11147. t['ideographicclose'] = 0x3006;
  11148. t['ideographiccomma'] = 0x3001;
  11149. t['ideographiccommaleft'] = 0xFF64;
  11150. t['ideographiccongratulationparen'] = 0x3237;
  11151. t['ideographiccorrectcircle'] = 0x32A3;
  11152. t['ideographicearthparen'] = 0x322F;
  11153. t['ideographicenterpriseparen'] = 0x323D;
  11154. t['ideographicexcellentcircle'] = 0x329D;
  11155. t['ideographicfestivalparen'] = 0x3240;
  11156. t['ideographicfinancialcircle'] = 0x3296;
  11157. t['ideographicfinancialparen'] = 0x3236;
  11158. t['ideographicfireparen'] = 0x322B;
  11159. t['ideographichaveparen'] = 0x3232;
  11160. t['ideographichighcircle'] = 0x32A4;
  11161. t['ideographiciterationmark'] = 0x3005;
  11162. t['ideographiclaborcircle'] = 0x3298;
  11163. t['ideographiclaborparen'] = 0x3238;
  11164. t['ideographicleftcircle'] = 0x32A7;
  11165. t['ideographiclowcircle'] = 0x32A6;
  11166. t['ideographicmedicinecircle'] = 0x32A9;
  11167. t['ideographicmetalparen'] = 0x322E;
  11168. t['ideographicmoonparen'] = 0x322A;
  11169. t['ideographicnameparen'] = 0x3234;
  11170. t['ideographicperiod'] = 0x3002;
  11171. t['ideographicprintcircle'] = 0x329E;
  11172. t['ideographicreachparen'] = 0x3243;
  11173. t['ideographicrepresentparen'] = 0x3239;
  11174. t['ideographicresourceparen'] = 0x323E;
  11175. t['ideographicrightcircle'] = 0x32A8;
  11176. t['ideographicsecretcircle'] = 0x3299;
  11177. t['ideographicselfparen'] = 0x3242;
  11178. t['ideographicsocietyparen'] = 0x3233;
  11179. t['ideographicspace'] = 0x3000;
  11180. t['ideographicspecialparen'] = 0x3235;
  11181. t['ideographicstockparen'] = 0x3231;
  11182. t['ideographicstudyparen'] = 0x323B;
  11183. t['ideographicsunparen'] = 0x3230;
  11184. t['ideographicsuperviseparen'] = 0x323C;
  11185. t['ideographicwaterparen'] = 0x322C;
  11186. t['ideographicwoodparen'] = 0x322D;
  11187. t['ideographiczero'] = 0x3007;
  11188. t['ideographmetalcircle'] = 0x328E;
  11189. t['ideographmooncircle'] = 0x328A;
  11190. t['ideographnamecircle'] = 0x3294;
  11191. t['ideographsuncircle'] = 0x3290;
  11192. t['ideographwatercircle'] = 0x328C;
  11193. t['ideographwoodcircle'] = 0x328D;
  11194. t['ideva'] = 0x0907;
  11195. t['idieresis'] = 0x00EF;
  11196. t['idieresisacute'] = 0x1E2F;
  11197. t['idieresiscyrillic'] = 0x04E5;
  11198. t['idotbelow'] = 0x1ECB;
  11199. t['iebrevecyrillic'] = 0x04D7;
  11200. t['iecyrillic'] = 0x0435;
  11201. t['ieungacirclekorean'] = 0x3275;
  11202. t['ieungaparenkorean'] = 0x3215;
  11203. t['ieungcirclekorean'] = 0x3267;
  11204. t['ieungkorean'] = 0x3147;
  11205. t['ieungparenkorean'] = 0x3207;
  11206. t['igrave'] = 0x00EC;
  11207. t['igujarati'] = 0x0A87;
  11208. t['igurmukhi'] = 0x0A07;
  11209. t['ihiragana'] = 0x3044;
  11210. t['ihookabove'] = 0x1EC9;
  11211. t['iibengali'] = 0x0988;
  11212. t['iicyrillic'] = 0x0438;
  11213. t['iideva'] = 0x0908;
  11214. t['iigujarati'] = 0x0A88;
  11215. t['iigurmukhi'] = 0x0A08;
  11216. t['iimatragurmukhi'] = 0x0A40;
  11217. t['iinvertedbreve'] = 0x020B;
  11218. t['iishortcyrillic'] = 0x0439;
  11219. t['iivowelsignbengali'] = 0x09C0;
  11220. t['iivowelsigndeva'] = 0x0940;
  11221. t['iivowelsigngujarati'] = 0x0AC0;
  11222. t['ij'] = 0x0133;
  11223. t['ikatakana'] = 0x30A4;
  11224. t['ikatakanahalfwidth'] = 0xFF72;
  11225. t['ikorean'] = 0x3163;
  11226. t['ilde'] = 0x02DC;
  11227. t['iluyhebrew'] = 0x05AC;
  11228. t['imacron'] = 0x012B;
  11229. t['imacroncyrillic'] = 0x04E3;
  11230. t['imageorapproximatelyequal'] = 0x2253;
  11231. t['imatragurmukhi'] = 0x0A3F;
  11232. t['imonospace'] = 0xFF49;
  11233. t['increment'] = 0x2206;
  11234. t['infinity'] = 0x221E;
  11235. t['iniarmenian'] = 0x056B;
  11236. t['integral'] = 0x222B;
  11237. t['integralbottom'] = 0x2321;
  11238. t['integralbt'] = 0x2321;
  11239. t['integralex'] = 0xF8F5;
  11240. t['integraltop'] = 0x2320;
  11241. t['integraltp'] = 0x2320;
  11242. t['intersection'] = 0x2229;
  11243. t['intisquare'] = 0x3305;
  11244. t['invbullet'] = 0x25D8;
  11245. t['invcircle'] = 0x25D9;
  11246. t['invsmileface'] = 0x263B;
  11247. t['iocyrillic'] = 0x0451;
  11248. t['iogonek'] = 0x012F;
  11249. t['iota'] = 0x03B9;
  11250. t['iotadieresis'] = 0x03CA;
  11251. t['iotadieresistonos'] = 0x0390;
  11252. t['iotalatin'] = 0x0269;
  11253. t['iotatonos'] = 0x03AF;
  11254. t['iparen'] = 0x24A4;
  11255. t['irigurmukhi'] = 0x0A72;
  11256. t['ismallhiragana'] = 0x3043;
  11257. t['ismallkatakana'] = 0x30A3;
  11258. t['ismallkatakanahalfwidth'] = 0xFF68;
  11259. t['issharbengali'] = 0x09FA;
  11260. t['istroke'] = 0x0268;
  11261. t['isuperior'] = 0xF6ED;
  11262. t['iterationhiragana'] = 0x309D;
  11263. t['iterationkatakana'] = 0x30FD;
  11264. t['itilde'] = 0x0129;
  11265. t['itildebelow'] = 0x1E2D;
  11266. t['iubopomofo'] = 0x3129;
  11267. t['iucyrillic'] = 0x044E;
  11268. t['ivowelsignbengali'] = 0x09BF;
  11269. t['ivowelsigndeva'] = 0x093F;
  11270. t['ivowelsigngujarati'] = 0x0ABF;
  11271. t['izhitsacyrillic'] = 0x0475;
  11272. t['izhitsadblgravecyrillic'] = 0x0477;
  11273. t['j'] = 0x006A;
  11274. t['jaarmenian'] = 0x0571;
  11275. t['jabengali'] = 0x099C;
  11276. t['jadeva'] = 0x091C;
  11277. t['jagujarati'] = 0x0A9C;
  11278. t['jagurmukhi'] = 0x0A1C;
  11279. t['jbopomofo'] = 0x3110;
  11280. t['jcaron'] = 0x01F0;
  11281. t['jcircle'] = 0x24D9;
  11282. t['jcircumflex'] = 0x0135;
  11283. t['jcrossedtail'] = 0x029D;
  11284. t['jdotlessstroke'] = 0x025F;
  11285. t['jecyrillic'] = 0x0458;
  11286. t['jeemarabic'] = 0x062C;
  11287. t['jeemfinalarabic'] = 0xFE9E;
  11288. t['jeeminitialarabic'] = 0xFE9F;
  11289. t['jeemmedialarabic'] = 0xFEA0;
  11290. t['jeharabic'] = 0x0698;
  11291. t['jehfinalarabic'] = 0xFB8B;
  11292. t['jhabengali'] = 0x099D;
  11293. t['jhadeva'] = 0x091D;
  11294. t['jhagujarati'] = 0x0A9D;
  11295. t['jhagurmukhi'] = 0x0A1D;
  11296. t['jheharmenian'] = 0x057B;
  11297. t['jis'] = 0x3004;
  11298. t['jmonospace'] = 0xFF4A;
  11299. t['jparen'] = 0x24A5;
  11300. t['jsuperior'] = 0x02B2;
  11301. t['k'] = 0x006B;
  11302. t['kabashkircyrillic'] = 0x04A1;
  11303. t['kabengali'] = 0x0995;
  11304. t['kacute'] = 0x1E31;
  11305. t['kacyrillic'] = 0x043A;
  11306. t['kadescendercyrillic'] = 0x049B;
  11307. t['kadeva'] = 0x0915;
  11308. t['kaf'] = 0x05DB;
  11309. t['kafarabic'] = 0x0643;
  11310. t['kafdagesh'] = 0xFB3B;
  11311. t['kafdageshhebrew'] = 0xFB3B;
  11312. t['kaffinalarabic'] = 0xFEDA;
  11313. t['kafhebrew'] = 0x05DB;
  11314. t['kafinitialarabic'] = 0xFEDB;
  11315. t['kafmedialarabic'] = 0xFEDC;
  11316. t['kafrafehebrew'] = 0xFB4D;
  11317. t['kagujarati'] = 0x0A95;
  11318. t['kagurmukhi'] = 0x0A15;
  11319. t['kahiragana'] = 0x304B;
  11320. t['kahookcyrillic'] = 0x04C4;
  11321. t['kakatakana'] = 0x30AB;
  11322. t['kakatakanahalfwidth'] = 0xFF76;
  11323. t['kappa'] = 0x03BA;
  11324. t['kappasymbolgreek'] = 0x03F0;
  11325. t['kapyeounmieumkorean'] = 0x3171;
  11326. t['kapyeounphieuphkorean'] = 0x3184;
  11327. t['kapyeounpieupkorean'] = 0x3178;
  11328. t['kapyeounssangpieupkorean'] = 0x3179;
  11329. t['karoriisquare'] = 0x330D;
  11330. t['kashidaautoarabic'] = 0x0640;
  11331. t['kashidaautonosidebearingarabic'] = 0x0640;
  11332. t['kasmallkatakana'] = 0x30F5;
  11333. t['kasquare'] = 0x3384;
  11334. t['kasraarabic'] = 0x0650;
  11335. t['kasratanarabic'] = 0x064D;
  11336. t['kastrokecyrillic'] = 0x049F;
  11337. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11338. t['kaverticalstrokecyrillic'] = 0x049D;
  11339. t['kbopomofo'] = 0x310E;
  11340. t['kcalsquare'] = 0x3389;
  11341. t['kcaron'] = 0x01E9;
  11342. t['kcedilla'] = 0x0137;
  11343. t['kcircle'] = 0x24DA;
  11344. t['kcommaaccent'] = 0x0137;
  11345. t['kdotbelow'] = 0x1E33;
  11346. t['keharmenian'] = 0x0584;
  11347. t['kehiragana'] = 0x3051;
  11348. t['kekatakana'] = 0x30B1;
  11349. t['kekatakanahalfwidth'] = 0xFF79;
  11350. t['kenarmenian'] = 0x056F;
  11351. t['kesmallkatakana'] = 0x30F6;
  11352. t['kgreenlandic'] = 0x0138;
  11353. t['khabengali'] = 0x0996;
  11354. t['khacyrillic'] = 0x0445;
  11355. t['khadeva'] = 0x0916;
  11356. t['khagujarati'] = 0x0A96;
  11357. t['khagurmukhi'] = 0x0A16;
  11358. t['khaharabic'] = 0x062E;
  11359. t['khahfinalarabic'] = 0xFEA6;
  11360. t['khahinitialarabic'] = 0xFEA7;
  11361. t['khahmedialarabic'] = 0xFEA8;
  11362. t['kheicoptic'] = 0x03E7;
  11363. t['khhadeva'] = 0x0959;
  11364. t['khhagurmukhi'] = 0x0A59;
  11365. t['khieukhacirclekorean'] = 0x3278;
  11366. t['khieukhaparenkorean'] = 0x3218;
  11367. t['khieukhcirclekorean'] = 0x326A;
  11368. t['khieukhkorean'] = 0x314B;
  11369. t['khieukhparenkorean'] = 0x320A;
  11370. t['khokhaithai'] = 0x0E02;
  11371. t['khokhonthai'] = 0x0E05;
  11372. t['khokhuatthai'] = 0x0E03;
  11373. t['khokhwaithai'] = 0x0E04;
  11374. t['khomutthai'] = 0x0E5B;
  11375. t['khook'] = 0x0199;
  11376. t['khorakhangthai'] = 0x0E06;
  11377. t['khzsquare'] = 0x3391;
  11378. t['kihiragana'] = 0x304D;
  11379. t['kikatakana'] = 0x30AD;
  11380. t['kikatakanahalfwidth'] = 0xFF77;
  11381. t['kiroguramusquare'] = 0x3315;
  11382. t['kiromeetorusquare'] = 0x3316;
  11383. t['kirosquare'] = 0x3314;
  11384. t['kiyeokacirclekorean'] = 0x326E;
  11385. t['kiyeokaparenkorean'] = 0x320E;
  11386. t['kiyeokcirclekorean'] = 0x3260;
  11387. t['kiyeokkorean'] = 0x3131;
  11388. t['kiyeokparenkorean'] = 0x3200;
  11389. t['kiyeoksioskorean'] = 0x3133;
  11390. t['kjecyrillic'] = 0x045C;
  11391. t['klinebelow'] = 0x1E35;
  11392. t['klsquare'] = 0x3398;
  11393. t['kmcubedsquare'] = 0x33A6;
  11394. t['kmonospace'] = 0xFF4B;
  11395. t['kmsquaredsquare'] = 0x33A2;
  11396. t['kohiragana'] = 0x3053;
  11397. t['kohmsquare'] = 0x33C0;
  11398. t['kokaithai'] = 0x0E01;
  11399. t['kokatakana'] = 0x30B3;
  11400. t['kokatakanahalfwidth'] = 0xFF7A;
  11401. t['kooposquare'] = 0x331E;
  11402. t['koppacyrillic'] = 0x0481;
  11403. t['koreanstandardsymbol'] = 0x327F;
  11404. t['koroniscmb'] = 0x0343;
  11405. t['kparen'] = 0x24A6;
  11406. t['kpasquare'] = 0x33AA;
  11407. t['ksicyrillic'] = 0x046F;
  11408. t['ktsquare'] = 0x33CF;
  11409. t['kturned'] = 0x029E;
  11410. t['kuhiragana'] = 0x304F;
  11411. t['kukatakana'] = 0x30AF;
  11412. t['kukatakanahalfwidth'] = 0xFF78;
  11413. t['kvsquare'] = 0x33B8;
  11414. t['kwsquare'] = 0x33BE;
  11415. t['l'] = 0x006C;
  11416. t['labengali'] = 0x09B2;
  11417. t['lacute'] = 0x013A;
  11418. t['ladeva'] = 0x0932;
  11419. t['lagujarati'] = 0x0AB2;
  11420. t['lagurmukhi'] = 0x0A32;
  11421. t['lakkhangyaothai'] = 0x0E45;
  11422. t['lamaleffinalarabic'] = 0xFEFC;
  11423. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11424. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11425. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11426. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11427. t['lamalefisolatedarabic'] = 0xFEFB;
  11428. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11429. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11430. t['lamarabic'] = 0x0644;
  11431. t['lambda'] = 0x03BB;
  11432. t['lambdastroke'] = 0x019B;
  11433. t['lamed'] = 0x05DC;
  11434. t['lameddagesh'] = 0xFB3C;
  11435. t['lameddageshhebrew'] = 0xFB3C;
  11436. t['lamedhebrew'] = 0x05DC;
  11437. t['lamfinalarabic'] = 0xFEDE;
  11438. t['lamhahinitialarabic'] = 0xFCCA;
  11439. t['laminitialarabic'] = 0xFEDF;
  11440. t['lamjeeminitialarabic'] = 0xFCC9;
  11441. t['lamkhahinitialarabic'] = 0xFCCB;
  11442. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11443. t['lammedialarabic'] = 0xFEE0;
  11444. t['lammeemhahinitialarabic'] = 0xFD88;
  11445. t['lammeeminitialarabic'] = 0xFCCC;
  11446. t['largecircle'] = 0x25EF;
  11447. t['lbar'] = 0x019A;
  11448. t['lbelt'] = 0x026C;
  11449. t['lbopomofo'] = 0x310C;
  11450. t['lcaron'] = 0x013E;
  11451. t['lcedilla'] = 0x013C;
  11452. t['lcircle'] = 0x24DB;
  11453. t['lcircumflexbelow'] = 0x1E3D;
  11454. t['lcommaaccent'] = 0x013C;
  11455. t['ldot'] = 0x0140;
  11456. t['ldotaccent'] = 0x0140;
  11457. t['ldotbelow'] = 0x1E37;
  11458. t['ldotbelowmacron'] = 0x1E39;
  11459. t['leftangleabovecmb'] = 0x031A;
  11460. t['lefttackbelowcmb'] = 0x0318;
  11461. t['less'] = 0x003C;
  11462. t['lessequal'] = 0x2264;
  11463. t['lessequalorgreater'] = 0x22DA;
  11464. t['lessmonospace'] = 0xFF1C;
  11465. t['lessorequivalent'] = 0x2272;
  11466. t['lessorgreater'] = 0x2276;
  11467. t['lessoverequal'] = 0x2266;
  11468. t['lesssmall'] = 0xFE64;
  11469. t['lezh'] = 0x026E;
  11470. t['lfblock'] = 0x258C;
  11471. t['lhookretroflex'] = 0x026D;
  11472. t['lira'] = 0x20A4;
  11473. t['liwnarmenian'] = 0x056C;
  11474. t['lj'] = 0x01C9;
  11475. t['ljecyrillic'] = 0x0459;
  11476. t['ll'] = 0xF6C0;
  11477. t['lladeva'] = 0x0933;
  11478. t['llagujarati'] = 0x0AB3;
  11479. t['llinebelow'] = 0x1E3B;
  11480. t['llladeva'] = 0x0934;
  11481. t['llvocalicbengali'] = 0x09E1;
  11482. t['llvocalicdeva'] = 0x0961;
  11483. t['llvocalicvowelsignbengali'] = 0x09E3;
  11484. t['llvocalicvowelsigndeva'] = 0x0963;
  11485. t['lmiddletilde'] = 0x026B;
  11486. t['lmonospace'] = 0xFF4C;
  11487. t['lmsquare'] = 0x33D0;
  11488. t['lochulathai'] = 0x0E2C;
  11489. t['logicaland'] = 0x2227;
  11490. t['logicalnot'] = 0x00AC;
  11491. t['logicalnotreversed'] = 0x2310;
  11492. t['logicalor'] = 0x2228;
  11493. t['lolingthai'] = 0x0E25;
  11494. t['longs'] = 0x017F;
  11495. t['lowlinecenterline'] = 0xFE4E;
  11496. t['lowlinecmb'] = 0x0332;
  11497. t['lowlinedashed'] = 0xFE4D;
  11498. t['lozenge'] = 0x25CA;
  11499. t['lparen'] = 0x24A7;
  11500. t['lslash'] = 0x0142;
  11501. t['lsquare'] = 0x2113;
  11502. t['lsuperior'] = 0xF6EE;
  11503. t['ltshade'] = 0x2591;
  11504. t['luthai'] = 0x0E26;
  11505. t['lvocalicbengali'] = 0x098C;
  11506. t['lvocalicdeva'] = 0x090C;
  11507. t['lvocalicvowelsignbengali'] = 0x09E2;
  11508. t['lvocalicvowelsigndeva'] = 0x0962;
  11509. t['lxsquare'] = 0x33D3;
  11510. t['m'] = 0x006D;
  11511. t['mabengali'] = 0x09AE;
  11512. t['macron'] = 0x00AF;
  11513. t['macronbelowcmb'] = 0x0331;
  11514. t['macroncmb'] = 0x0304;
  11515. t['macronlowmod'] = 0x02CD;
  11516. t['macronmonospace'] = 0xFFE3;
  11517. t['macute'] = 0x1E3F;
  11518. t['madeva'] = 0x092E;
  11519. t['magujarati'] = 0x0AAE;
  11520. t['magurmukhi'] = 0x0A2E;
  11521. t['mahapakhhebrew'] = 0x05A4;
  11522. t['mahapakhlefthebrew'] = 0x05A4;
  11523. t['mahiragana'] = 0x307E;
  11524. t['maichattawalowleftthai'] = 0xF895;
  11525. t['maichattawalowrightthai'] = 0xF894;
  11526. t['maichattawathai'] = 0x0E4B;
  11527. t['maichattawaupperleftthai'] = 0xF893;
  11528. t['maieklowleftthai'] = 0xF88C;
  11529. t['maieklowrightthai'] = 0xF88B;
  11530. t['maiekthai'] = 0x0E48;
  11531. t['maiekupperleftthai'] = 0xF88A;
  11532. t['maihanakatleftthai'] = 0xF884;
  11533. t['maihanakatthai'] = 0x0E31;
  11534. t['maitaikhuleftthai'] = 0xF889;
  11535. t['maitaikhuthai'] = 0x0E47;
  11536. t['maitholowleftthai'] = 0xF88F;
  11537. t['maitholowrightthai'] = 0xF88E;
  11538. t['maithothai'] = 0x0E49;
  11539. t['maithoupperleftthai'] = 0xF88D;
  11540. t['maitrilowleftthai'] = 0xF892;
  11541. t['maitrilowrightthai'] = 0xF891;
  11542. t['maitrithai'] = 0x0E4A;
  11543. t['maitriupperleftthai'] = 0xF890;
  11544. t['maiyamokthai'] = 0x0E46;
  11545. t['makatakana'] = 0x30DE;
  11546. t['makatakanahalfwidth'] = 0xFF8F;
  11547. t['male'] = 0x2642;
  11548. t['mansyonsquare'] = 0x3347;
  11549. t['maqafhebrew'] = 0x05BE;
  11550. t['mars'] = 0x2642;
  11551. t['masoracirclehebrew'] = 0x05AF;
  11552. t['masquare'] = 0x3383;
  11553. t['mbopomofo'] = 0x3107;
  11554. t['mbsquare'] = 0x33D4;
  11555. t['mcircle'] = 0x24DC;
  11556. t['mcubedsquare'] = 0x33A5;
  11557. t['mdotaccent'] = 0x1E41;
  11558. t['mdotbelow'] = 0x1E43;
  11559. t['meemarabic'] = 0x0645;
  11560. t['meemfinalarabic'] = 0xFEE2;
  11561. t['meeminitialarabic'] = 0xFEE3;
  11562. t['meemmedialarabic'] = 0xFEE4;
  11563. t['meemmeeminitialarabic'] = 0xFCD1;
  11564. t['meemmeemisolatedarabic'] = 0xFC48;
  11565. t['meetorusquare'] = 0x334D;
  11566. t['mehiragana'] = 0x3081;
  11567. t['meizierasquare'] = 0x337E;
  11568. t['mekatakana'] = 0x30E1;
  11569. t['mekatakanahalfwidth'] = 0xFF92;
  11570. t['mem'] = 0x05DE;
  11571. t['memdagesh'] = 0xFB3E;
  11572. t['memdageshhebrew'] = 0xFB3E;
  11573. t['memhebrew'] = 0x05DE;
  11574. t['menarmenian'] = 0x0574;
  11575. t['merkhahebrew'] = 0x05A5;
  11576. t['merkhakefulahebrew'] = 0x05A6;
  11577. t['merkhakefulalefthebrew'] = 0x05A6;
  11578. t['merkhalefthebrew'] = 0x05A5;
  11579. t['mhook'] = 0x0271;
  11580. t['mhzsquare'] = 0x3392;
  11581. t['middledotkatakanahalfwidth'] = 0xFF65;
  11582. t['middot'] = 0x00B7;
  11583. t['mieumacirclekorean'] = 0x3272;
  11584. t['mieumaparenkorean'] = 0x3212;
  11585. t['mieumcirclekorean'] = 0x3264;
  11586. t['mieumkorean'] = 0x3141;
  11587. t['mieumpansioskorean'] = 0x3170;
  11588. t['mieumparenkorean'] = 0x3204;
  11589. t['mieumpieupkorean'] = 0x316E;
  11590. t['mieumsioskorean'] = 0x316F;
  11591. t['mihiragana'] = 0x307F;
  11592. t['mikatakana'] = 0x30DF;
  11593. t['mikatakanahalfwidth'] = 0xFF90;
  11594. t['minus'] = 0x2212;
  11595. t['minusbelowcmb'] = 0x0320;
  11596. t['minuscircle'] = 0x2296;
  11597. t['minusmod'] = 0x02D7;
  11598. t['minusplus'] = 0x2213;
  11599. t['minute'] = 0x2032;
  11600. t['miribaarusquare'] = 0x334A;
  11601. t['mirisquare'] = 0x3349;
  11602. t['mlonglegturned'] = 0x0270;
  11603. t['mlsquare'] = 0x3396;
  11604. t['mmcubedsquare'] = 0x33A3;
  11605. t['mmonospace'] = 0xFF4D;
  11606. t['mmsquaredsquare'] = 0x339F;
  11607. t['mohiragana'] = 0x3082;
  11608. t['mohmsquare'] = 0x33C1;
  11609. t['mokatakana'] = 0x30E2;
  11610. t['mokatakanahalfwidth'] = 0xFF93;
  11611. t['molsquare'] = 0x33D6;
  11612. t['momathai'] = 0x0E21;
  11613. t['moverssquare'] = 0x33A7;
  11614. t['moverssquaredsquare'] = 0x33A8;
  11615. t['mparen'] = 0x24A8;
  11616. t['mpasquare'] = 0x33AB;
  11617. t['mssquare'] = 0x33B3;
  11618. t['msuperior'] = 0xF6EF;
  11619. t['mturned'] = 0x026F;
  11620. t['mu'] = 0x00B5;
  11621. t['mu1'] = 0x00B5;
  11622. t['muasquare'] = 0x3382;
  11623. t['muchgreater'] = 0x226B;
  11624. t['muchless'] = 0x226A;
  11625. t['mufsquare'] = 0x338C;
  11626. t['mugreek'] = 0x03BC;
  11627. t['mugsquare'] = 0x338D;
  11628. t['muhiragana'] = 0x3080;
  11629. t['mukatakana'] = 0x30E0;
  11630. t['mukatakanahalfwidth'] = 0xFF91;
  11631. t['mulsquare'] = 0x3395;
  11632. t['multiply'] = 0x00D7;
  11633. t['mumsquare'] = 0x339B;
  11634. t['munahhebrew'] = 0x05A3;
  11635. t['munahlefthebrew'] = 0x05A3;
  11636. t['musicalnote'] = 0x266A;
  11637. t['musicalnotedbl'] = 0x266B;
  11638. t['musicflatsign'] = 0x266D;
  11639. t['musicsharpsign'] = 0x266F;
  11640. t['mussquare'] = 0x33B2;
  11641. t['muvsquare'] = 0x33B6;
  11642. t['muwsquare'] = 0x33BC;
  11643. t['mvmegasquare'] = 0x33B9;
  11644. t['mvsquare'] = 0x33B7;
  11645. t['mwmegasquare'] = 0x33BF;
  11646. t['mwsquare'] = 0x33BD;
  11647. t['n'] = 0x006E;
  11648. t['nabengali'] = 0x09A8;
  11649. t['nabla'] = 0x2207;
  11650. t['nacute'] = 0x0144;
  11651. t['nadeva'] = 0x0928;
  11652. t['nagujarati'] = 0x0AA8;
  11653. t['nagurmukhi'] = 0x0A28;
  11654. t['nahiragana'] = 0x306A;
  11655. t['nakatakana'] = 0x30CA;
  11656. t['nakatakanahalfwidth'] = 0xFF85;
  11657. t['napostrophe'] = 0x0149;
  11658. t['nasquare'] = 0x3381;
  11659. t['nbopomofo'] = 0x310B;
  11660. t['nbspace'] = 0x00A0;
  11661. t['ncaron'] = 0x0148;
  11662. t['ncedilla'] = 0x0146;
  11663. t['ncircle'] = 0x24DD;
  11664. t['ncircumflexbelow'] = 0x1E4B;
  11665. t['ncommaaccent'] = 0x0146;
  11666. t['ndotaccent'] = 0x1E45;
  11667. t['ndotbelow'] = 0x1E47;
  11668. t['nehiragana'] = 0x306D;
  11669. t['nekatakana'] = 0x30CD;
  11670. t['nekatakanahalfwidth'] = 0xFF88;
  11671. t['newsheqelsign'] = 0x20AA;
  11672. t['nfsquare'] = 0x338B;
  11673. t['ngabengali'] = 0x0999;
  11674. t['ngadeva'] = 0x0919;
  11675. t['ngagujarati'] = 0x0A99;
  11676. t['ngagurmukhi'] = 0x0A19;
  11677. t['ngonguthai'] = 0x0E07;
  11678. t['nhiragana'] = 0x3093;
  11679. t['nhookleft'] = 0x0272;
  11680. t['nhookretroflex'] = 0x0273;
  11681. t['nieunacirclekorean'] = 0x326F;
  11682. t['nieunaparenkorean'] = 0x320F;
  11683. t['nieuncieuckorean'] = 0x3135;
  11684. t['nieuncirclekorean'] = 0x3261;
  11685. t['nieunhieuhkorean'] = 0x3136;
  11686. t['nieunkorean'] = 0x3134;
  11687. t['nieunpansioskorean'] = 0x3168;
  11688. t['nieunparenkorean'] = 0x3201;
  11689. t['nieunsioskorean'] = 0x3167;
  11690. t['nieuntikeutkorean'] = 0x3166;
  11691. t['nihiragana'] = 0x306B;
  11692. t['nikatakana'] = 0x30CB;
  11693. t['nikatakanahalfwidth'] = 0xFF86;
  11694. t['nikhahitleftthai'] = 0xF899;
  11695. t['nikhahitthai'] = 0x0E4D;
  11696. t['nine'] = 0x0039;
  11697. t['ninearabic'] = 0x0669;
  11698. t['ninebengali'] = 0x09EF;
  11699. t['ninecircle'] = 0x2468;
  11700. t['ninecircleinversesansserif'] = 0x2792;
  11701. t['ninedeva'] = 0x096F;
  11702. t['ninegujarati'] = 0x0AEF;
  11703. t['ninegurmukhi'] = 0x0A6F;
  11704. t['ninehackarabic'] = 0x0669;
  11705. t['ninehangzhou'] = 0x3029;
  11706. t['nineideographicparen'] = 0x3228;
  11707. t['nineinferior'] = 0x2089;
  11708. t['ninemonospace'] = 0xFF19;
  11709. t['nineoldstyle'] = 0xF739;
  11710. t['nineparen'] = 0x247C;
  11711. t['nineperiod'] = 0x2490;
  11712. t['ninepersian'] = 0x06F9;
  11713. t['nineroman'] = 0x2178;
  11714. t['ninesuperior'] = 0x2079;
  11715. t['nineteencircle'] = 0x2472;
  11716. t['nineteenparen'] = 0x2486;
  11717. t['nineteenperiod'] = 0x249A;
  11718. t['ninethai'] = 0x0E59;
  11719. t['nj'] = 0x01CC;
  11720. t['njecyrillic'] = 0x045A;
  11721. t['nkatakana'] = 0x30F3;
  11722. t['nkatakanahalfwidth'] = 0xFF9D;
  11723. t['nlegrightlong'] = 0x019E;
  11724. t['nlinebelow'] = 0x1E49;
  11725. t['nmonospace'] = 0xFF4E;
  11726. t['nmsquare'] = 0x339A;
  11727. t['nnabengali'] = 0x09A3;
  11728. t['nnadeva'] = 0x0923;
  11729. t['nnagujarati'] = 0x0AA3;
  11730. t['nnagurmukhi'] = 0x0A23;
  11731. t['nnnadeva'] = 0x0929;
  11732. t['nohiragana'] = 0x306E;
  11733. t['nokatakana'] = 0x30CE;
  11734. t['nokatakanahalfwidth'] = 0xFF89;
  11735. t['nonbreakingspace'] = 0x00A0;
  11736. t['nonenthai'] = 0x0E13;
  11737. t['nonuthai'] = 0x0E19;
  11738. t['noonarabic'] = 0x0646;
  11739. t['noonfinalarabic'] = 0xFEE6;
  11740. t['noonghunnaarabic'] = 0x06BA;
  11741. t['noonghunnafinalarabic'] = 0xFB9F;
  11742. t['nooninitialarabic'] = 0xFEE7;
  11743. t['noonjeeminitialarabic'] = 0xFCD2;
  11744. t['noonjeemisolatedarabic'] = 0xFC4B;
  11745. t['noonmedialarabic'] = 0xFEE8;
  11746. t['noonmeeminitialarabic'] = 0xFCD5;
  11747. t['noonmeemisolatedarabic'] = 0xFC4E;
  11748. t['noonnoonfinalarabic'] = 0xFC8D;
  11749. t['notcontains'] = 0x220C;
  11750. t['notelement'] = 0x2209;
  11751. t['notelementof'] = 0x2209;
  11752. t['notequal'] = 0x2260;
  11753. t['notgreater'] = 0x226F;
  11754. t['notgreaternorequal'] = 0x2271;
  11755. t['notgreaternorless'] = 0x2279;
  11756. t['notidentical'] = 0x2262;
  11757. t['notless'] = 0x226E;
  11758. t['notlessnorequal'] = 0x2270;
  11759. t['notparallel'] = 0x2226;
  11760. t['notprecedes'] = 0x2280;
  11761. t['notsubset'] = 0x2284;
  11762. t['notsucceeds'] = 0x2281;
  11763. t['notsuperset'] = 0x2285;
  11764. t['nowarmenian'] = 0x0576;
  11765. t['nparen'] = 0x24A9;
  11766. t['nssquare'] = 0x33B1;
  11767. t['nsuperior'] = 0x207F;
  11768. t['ntilde'] = 0x00F1;
  11769. t['nu'] = 0x03BD;
  11770. t['nuhiragana'] = 0x306C;
  11771. t['nukatakana'] = 0x30CC;
  11772. t['nukatakanahalfwidth'] = 0xFF87;
  11773. t['nuktabengali'] = 0x09BC;
  11774. t['nuktadeva'] = 0x093C;
  11775. t['nuktagujarati'] = 0x0ABC;
  11776. t['nuktagurmukhi'] = 0x0A3C;
  11777. t['numbersign'] = 0x0023;
  11778. t['numbersignmonospace'] = 0xFF03;
  11779. t['numbersignsmall'] = 0xFE5F;
  11780. t['numeralsigngreek'] = 0x0374;
  11781. t['numeralsignlowergreek'] = 0x0375;
  11782. t['numero'] = 0x2116;
  11783. t['nun'] = 0x05E0;
  11784. t['nundagesh'] = 0xFB40;
  11785. t['nundageshhebrew'] = 0xFB40;
  11786. t['nunhebrew'] = 0x05E0;
  11787. t['nvsquare'] = 0x33B5;
  11788. t['nwsquare'] = 0x33BB;
  11789. t['nyabengali'] = 0x099E;
  11790. t['nyadeva'] = 0x091E;
  11791. t['nyagujarati'] = 0x0A9E;
  11792. t['nyagurmukhi'] = 0x0A1E;
  11793. t['o'] = 0x006F;
  11794. t['oacute'] = 0x00F3;
  11795. t['oangthai'] = 0x0E2D;
  11796. t['obarred'] = 0x0275;
  11797. t['obarredcyrillic'] = 0x04E9;
  11798. t['obarreddieresiscyrillic'] = 0x04EB;
  11799. t['obengali'] = 0x0993;
  11800. t['obopomofo'] = 0x311B;
  11801. t['obreve'] = 0x014F;
  11802. t['ocandradeva'] = 0x0911;
  11803. t['ocandragujarati'] = 0x0A91;
  11804. t['ocandravowelsigndeva'] = 0x0949;
  11805. t['ocandravowelsigngujarati'] = 0x0AC9;
  11806. t['ocaron'] = 0x01D2;
  11807. t['ocircle'] = 0x24DE;
  11808. t['ocircumflex'] = 0x00F4;
  11809. t['ocircumflexacute'] = 0x1ED1;
  11810. t['ocircumflexdotbelow'] = 0x1ED9;
  11811. t['ocircumflexgrave'] = 0x1ED3;
  11812. t['ocircumflexhookabove'] = 0x1ED5;
  11813. t['ocircumflextilde'] = 0x1ED7;
  11814. t['ocyrillic'] = 0x043E;
  11815. t['odblacute'] = 0x0151;
  11816. t['odblgrave'] = 0x020D;
  11817. t['odeva'] = 0x0913;
  11818. t['odieresis'] = 0x00F6;
  11819. t['odieresiscyrillic'] = 0x04E7;
  11820. t['odotbelow'] = 0x1ECD;
  11821. t['oe'] = 0x0153;
  11822. t['oekorean'] = 0x315A;
  11823. t['ogonek'] = 0x02DB;
  11824. t['ogonekcmb'] = 0x0328;
  11825. t['ograve'] = 0x00F2;
  11826. t['ogujarati'] = 0x0A93;
  11827. t['oharmenian'] = 0x0585;
  11828. t['ohiragana'] = 0x304A;
  11829. t['ohookabove'] = 0x1ECF;
  11830. t['ohorn'] = 0x01A1;
  11831. t['ohornacute'] = 0x1EDB;
  11832. t['ohorndotbelow'] = 0x1EE3;
  11833. t['ohorngrave'] = 0x1EDD;
  11834. t['ohornhookabove'] = 0x1EDF;
  11835. t['ohorntilde'] = 0x1EE1;
  11836. t['ohungarumlaut'] = 0x0151;
  11837. t['oi'] = 0x01A3;
  11838. t['oinvertedbreve'] = 0x020F;
  11839. t['okatakana'] = 0x30AA;
  11840. t['okatakanahalfwidth'] = 0xFF75;
  11841. t['okorean'] = 0x3157;
  11842. t['olehebrew'] = 0x05AB;
  11843. t['omacron'] = 0x014D;
  11844. t['omacronacute'] = 0x1E53;
  11845. t['omacrongrave'] = 0x1E51;
  11846. t['omdeva'] = 0x0950;
  11847. t['omega'] = 0x03C9;
  11848. t['omega1'] = 0x03D6;
  11849. t['omegacyrillic'] = 0x0461;
  11850. t['omegalatinclosed'] = 0x0277;
  11851. t['omegaroundcyrillic'] = 0x047B;
  11852. t['omegatitlocyrillic'] = 0x047D;
  11853. t['omegatonos'] = 0x03CE;
  11854. t['omgujarati'] = 0x0AD0;
  11855. t['omicron'] = 0x03BF;
  11856. t['omicrontonos'] = 0x03CC;
  11857. t['omonospace'] = 0xFF4F;
  11858. t['one'] = 0x0031;
  11859. t['onearabic'] = 0x0661;
  11860. t['onebengali'] = 0x09E7;
  11861. t['onecircle'] = 0x2460;
  11862. t['onecircleinversesansserif'] = 0x278A;
  11863. t['onedeva'] = 0x0967;
  11864. t['onedotenleader'] = 0x2024;
  11865. t['oneeighth'] = 0x215B;
  11866. t['onefitted'] = 0xF6DC;
  11867. t['onegujarati'] = 0x0AE7;
  11868. t['onegurmukhi'] = 0x0A67;
  11869. t['onehackarabic'] = 0x0661;
  11870. t['onehalf'] = 0x00BD;
  11871. t['onehangzhou'] = 0x3021;
  11872. t['oneideographicparen'] = 0x3220;
  11873. t['oneinferior'] = 0x2081;
  11874. t['onemonospace'] = 0xFF11;
  11875. t['onenumeratorbengali'] = 0x09F4;
  11876. t['oneoldstyle'] = 0xF731;
  11877. t['oneparen'] = 0x2474;
  11878. t['oneperiod'] = 0x2488;
  11879. t['onepersian'] = 0x06F1;
  11880. t['onequarter'] = 0x00BC;
  11881. t['oneroman'] = 0x2170;
  11882. t['onesuperior'] = 0x00B9;
  11883. t['onethai'] = 0x0E51;
  11884. t['onethird'] = 0x2153;
  11885. t['oogonek'] = 0x01EB;
  11886. t['oogonekmacron'] = 0x01ED;
  11887. t['oogurmukhi'] = 0x0A13;
  11888. t['oomatragurmukhi'] = 0x0A4B;
  11889. t['oopen'] = 0x0254;
  11890. t['oparen'] = 0x24AA;
  11891. t['openbullet'] = 0x25E6;
  11892. t['option'] = 0x2325;
  11893. t['ordfeminine'] = 0x00AA;
  11894. t['ordmasculine'] = 0x00BA;
  11895. t['orthogonal'] = 0x221F;
  11896. t['oshortdeva'] = 0x0912;
  11897. t['oshortvowelsigndeva'] = 0x094A;
  11898. t['oslash'] = 0x00F8;
  11899. t['oslashacute'] = 0x01FF;
  11900. t['osmallhiragana'] = 0x3049;
  11901. t['osmallkatakana'] = 0x30A9;
  11902. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11903. t['ostrokeacute'] = 0x01FF;
  11904. t['osuperior'] = 0xF6F0;
  11905. t['otcyrillic'] = 0x047F;
  11906. t['otilde'] = 0x00F5;
  11907. t['otildeacute'] = 0x1E4D;
  11908. t['otildedieresis'] = 0x1E4F;
  11909. t['oubopomofo'] = 0x3121;
  11910. t['overline'] = 0x203E;
  11911. t['overlinecenterline'] = 0xFE4A;
  11912. t['overlinecmb'] = 0x0305;
  11913. t['overlinedashed'] = 0xFE49;
  11914. t['overlinedblwavy'] = 0xFE4C;
  11915. t['overlinewavy'] = 0xFE4B;
  11916. t['overscore'] = 0x00AF;
  11917. t['ovowelsignbengali'] = 0x09CB;
  11918. t['ovowelsigndeva'] = 0x094B;
  11919. t['ovowelsigngujarati'] = 0x0ACB;
  11920. t['p'] = 0x0070;
  11921. t['paampssquare'] = 0x3380;
  11922. t['paasentosquare'] = 0x332B;
  11923. t['pabengali'] = 0x09AA;
  11924. t['pacute'] = 0x1E55;
  11925. t['padeva'] = 0x092A;
  11926. t['pagedown'] = 0x21DF;
  11927. t['pageup'] = 0x21DE;
  11928. t['pagujarati'] = 0x0AAA;
  11929. t['pagurmukhi'] = 0x0A2A;
  11930. t['pahiragana'] = 0x3071;
  11931. t['paiyannoithai'] = 0x0E2F;
  11932. t['pakatakana'] = 0x30D1;
  11933. t['palatalizationcyrilliccmb'] = 0x0484;
  11934. t['palochkacyrillic'] = 0x04C0;
  11935. t['pansioskorean'] = 0x317F;
  11936. t['paragraph'] = 0x00B6;
  11937. t['parallel'] = 0x2225;
  11938. t['parenleft'] = 0x0028;
  11939. t['parenleftaltonearabic'] = 0xFD3E;
  11940. t['parenleftbt'] = 0xF8ED;
  11941. t['parenleftex'] = 0xF8EC;
  11942. t['parenleftinferior'] = 0x208D;
  11943. t['parenleftmonospace'] = 0xFF08;
  11944. t['parenleftsmall'] = 0xFE59;
  11945. t['parenleftsuperior'] = 0x207D;
  11946. t['parenlefttp'] = 0xF8EB;
  11947. t['parenleftvertical'] = 0xFE35;
  11948. t['parenright'] = 0x0029;
  11949. t['parenrightaltonearabic'] = 0xFD3F;
  11950. t['parenrightbt'] = 0xF8F8;
  11951. t['parenrightex'] = 0xF8F7;
  11952. t['parenrightinferior'] = 0x208E;
  11953. t['parenrightmonospace'] = 0xFF09;
  11954. t['parenrightsmall'] = 0xFE5A;
  11955. t['parenrightsuperior'] = 0x207E;
  11956. t['parenrighttp'] = 0xF8F6;
  11957. t['parenrightvertical'] = 0xFE36;
  11958. t['partialdiff'] = 0x2202;
  11959. t['paseqhebrew'] = 0x05C0;
  11960. t['pashtahebrew'] = 0x0599;
  11961. t['pasquare'] = 0x33A9;
  11962. t['patah'] = 0x05B7;
  11963. t['patah11'] = 0x05B7;
  11964. t['patah1d'] = 0x05B7;
  11965. t['patah2a'] = 0x05B7;
  11966. t['patahhebrew'] = 0x05B7;
  11967. t['patahnarrowhebrew'] = 0x05B7;
  11968. t['patahquarterhebrew'] = 0x05B7;
  11969. t['patahwidehebrew'] = 0x05B7;
  11970. t['pazerhebrew'] = 0x05A1;
  11971. t['pbopomofo'] = 0x3106;
  11972. t['pcircle'] = 0x24DF;
  11973. t['pdotaccent'] = 0x1E57;
  11974. t['pe'] = 0x05E4;
  11975. t['pecyrillic'] = 0x043F;
  11976. t['pedagesh'] = 0xFB44;
  11977. t['pedageshhebrew'] = 0xFB44;
  11978. t['peezisquare'] = 0x333B;
  11979. t['pefinaldageshhebrew'] = 0xFB43;
  11980. t['peharabic'] = 0x067E;
  11981. t['peharmenian'] = 0x057A;
  11982. t['pehebrew'] = 0x05E4;
  11983. t['pehfinalarabic'] = 0xFB57;
  11984. t['pehinitialarabic'] = 0xFB58;
  11985. t['pehiragana'] = 0x307A;
  11986. t['pehmedialarabic'] = 0xFB59;
  11987. t['pekatakana'] = 0x30DA;
  11988. t['pemiddlehookcyrillic'] = 0x04A7;
  11989. t['perafehebrew'] = 0xFB4E;
  11990. t['percent'] = 0x0025;
  11991. t['percentarabic'] = 0x066A;
  11992. t['percentmonospace'] = 0xFF05;
  11993. t['percentsmall'] = 0xFE6A;
  11994. t['period'] = 0x002E;
  11995. t['periodarmenian'] = 0x0589;
  11996. t['periodcentered'] = 0x00B7;
  11997. t['periodhalfwidth'] = 0xFF61;
  11998. t['periodinferior'] = 0xF6E7;
  11999. t['periodmonospace'] = 0xFF0E;
  12000. t['periodsmall'] = 0xFE52;
  12001. t['periodsuperior'] = 0xF6E8;
  12002. t['perispomenigreekcmb'] = 0x0342;
  12003. t['perpendicular'] = 0x22A5;
  12004. t['perthousand'] = 0x2030;
  12005. t['peseta'] = 0x20A7;
  12006. t['pfsquare'] = 0x338A;
  12007. t['phabengali'] = 0x09AB;
  12008. t['phadeva'] = 0x092B;
  12009. t['phagujarati'] = 0x0AAB;
  12010. t['phagurmukhi'] = 0x0A2B;
  12011. t['phi'] = 0x03C6;
  12012. t['phi1'] = 0x03D5;
  12013. t['phieuphacirclekorean'] = 0x327A;
  12014. t['phieuphaparenkorean'] = 0x321A;
  12015. t['phieuphcirclekorean'] = 0x326C;
  12016. t['phieuphkorean'] = 0x314D;
  12017. t['phieuphparenkorean'] = 0x320C;
  12018. t['philatin'] = 0x0278;
  12019. t['phinthuthai'] = 0x0E3A;
  12020. t['phisymbolgreek'] = 0x03D5;
  12021. t['phook'] = 0x01A5;
  12022. t['phophanthai'] = 0x0E1E;
  12023. t['phophungthai'] = 0x0E1C;
  12024. t['phosamphaothai'] = 0x0E20;
  12025. t['pi'] = 0x03C0;
  12026. t['pieupacirclekorean'] = 0x3273;
  12027. t['pieupaparenkorean'] = 0x3213;
  12028. t['pieupcieuckorean'] = 0x3176;
  12029. t['pieupcirclekorean'] = 0x3265;
  12030. t['pieupkiyeokkorean'] = 0x3172;
  12031. t['pieupkorean'] = 0x3142;
  12032. t['pieupparenkorean'] = 0x3205;
  12033. t['pieupsioskiyeokkorean'] = 0x3174;
  12034. t['pieupsioskorean'] = 0x3144;
  12035. t['pieupsiostikeutkorean'] = 0x3175;
  12036. t['pieupthieuthkorean'] = 0x3177;
  12037. t['pieuptikeutkorean'] = 0x3173;
  12038. t['pihiragana'] = 0x3074;
  12039. t['pikatakana'] = 0x30D4;
  12040. t['pisymbolgreek'] = 0x03D6;
  12041. t['piwrarmenian'] = 0x0583;
  12042. t['plus'] = 0x002B;
  12043. t['plusbelowcmb'] = 0x031F;
  12044. t['pluscircle'] = 0x2295;
  12045. t['plusminus'] = 0x00B1;
  12046. t['plusmod'] = 0x02D6;
  12047. t['plusmonospace'] = 0xFF0B;
  12048. t['plussmall'] = 0xFE62;
  12049. t['plussuperior'] = 0x207A;
  12050. t['pmonospace'] = 0xFF50;
  12051. t['pmsquare'] = 0x33D8;
  12052. t['pohiragana'] = 0x307D;
  12053. t['pointingindexdownwhite'] = 0x261F;
  12054. t['pointingindexleftwhite'] = 0x261C;
  12055. t['pointingindexrightwhite'] = 0x261E;
  12056. t['pointingindexupwhite'] = 0x261D;
  12057. t['pokatakana'] = 0x30DD;
  12058. t['poplathai'] = 0x0E1B;
  12059. t['postalmark'] = 0x3012;
  12060. t['postalmarkface'] = 0x3020;
  12061. t['pparen'] = 0x24AB;
  12062. t['precedes'] = 0x227A;
  12063. t['prescription'] = 0x211E;
  12064. t['primemod'] = 0x02B9;
  12065. t['primereversed'] = 0x2035;
  12066. t['product'] = 0x220F;
  12067. t['projective'] = 0x2305;
  12068. t['prolongedkana'] = 0x30FC;
  12069. t['propellor'] = 0x2318;
  12070. t['propersubset'] = 0x2282;
  12071. t['propersuperset'] = 0x2283;
  12072. t['proportion'] = 0x2237;
  12073. t['proportional'] = 0x221D;
  12074. t['psi'] = 0x03C8;
  12075. t['psicyrillic'] = 0x0471;
  12076. t['psilipneumatacyrilliccmb'] = 0x0486;
  12077. t['pssquare'] = 0x33B0;
  12078. t['puhiragana'] = 0x3077;
  12079. t['pukatakana'] = 0x30D7;
  12080. t['pvsquare'] = 0x33B4;
  12081. t['pwsquare'] = 0x33BA;
  12082. t['q'] = 0x0071;
  12083. t['qadeva'] = 0x0958;
  12084. t['qadmahebrew'] = 0x05A8;
  12085. t['qafarabic'] = 0x0642;
  12086. t['qaffinalarabic'] = 0xFED6;
  12087. t['qafinitialarabic'] = 0xFED7;
  12088. t['qafmedialarabic'] = 0xFED8;
  12089. t['qamats'] = 0x05B8;
  12090. t['qamats10'] = 0x05B8;
  12091. t['qamats1a'] = 0x05B8;
  12092. t['qamats1c'] = 0x05B8;
  12093. t['qamats27'] = 0x05B8;
  12094. t['qamats29'] = 0x05B8;
  12095. t['qamats33'] = 0x05B8;
  12096. t['qamatsde'] = 0x05B8;
  12097. t['qamatshebrew'] = 0x05B8;
  12098. t['qamatsnarrowhebrew'] = 0x05B8;
  12099. t['qamatsqatanhebrew'] = 0x05B8;
  12100. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12101. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12102. t['qamatsqatanwidehebrew'] = 0x05B8;
  12103. t['qamatsquarterhebrew'] = 0x05B8;
  12104. t['qamatswidehebrew'] = 0x05B8;
  12105. t['qarneyparahebrew'] = 0x059F;
  12106. t['qbopomofo'] = 0x3111;
  12107. t['qcircle'] = 0x24E0;
  12108. t['qhook'] = 0x02A0;
  12109. t['qmonospace'] = 0xFF51;
  12110. t['qof'] = 0x05E7;
  12111. t['qofdagesh'] = 0xFB47;
  12112. t['qofdageshhebrew'] = 0xFB47;
  12113. t['qofhebrew'] = 0x05E7;
  12114. t['qparen'] = 0x24AC;
  12115. t['quarternote'] = 0x2669;
  12116. t['qubuts'] = 0x05BB;
  12117. t['qubuts18'] = 0x05BB;
  12118. t['qubuts25'] = 0x05BB;
  12119. t['qubuts31'] = 0x05BB;
  12120. t['qubutshebrew'] = 0x05BB;
  12121. t['qubutsnarrowhebrew'] = 0x05BB;
  12122. t['qubutsquarterhebrew'] = 0x05BB;
  12123. t['qubutswidehebrew'] = 0x05BB;
  12124. t['question'] = 0x003F;
  12125. t['questionarabic'] = 0x061F;
  12126. t['questionarmenian'] = 0x055E;
  12127. t['questiondown'] = 0x00BF;
  12128. t['questiondownsmall'] = 0xF7BF;
  12129. t['questiongreek'] = 0x037E;
  12130. t['questionmonospace'] = 0xFF1F;
  12131. t['questionsmall'] = 0xF73F;
  12132. t['quotedbl'] = 0x0022;
  12133. t['quotedblbase'] = 0x201E;
  12134. t['quotedblleft'] = 0x201C;
  12135. t['quotedblmonospace'] = 0xFF02;
  12136. t['quotedblprime'] = 0x301E;
  12137. t['quotedblprimereversed'] = 0x301D;
  12138. t['quotedblright'] = 0x201D;
  12139. t['quoteleft'] = 0x2018;
  12140. t['quoteleftreversed'] = 0x201B;
  12141. t['quotereversed'] = 0x201B;
  12142. t['quoteright'] = 0x2019;
  12143. t['quoterightn'] = 0x0149;
  12144. t['quotesinglbase'] = 0x201A;
  12145. t['quotesingle'] = 0x0027;
  12146. t['quotesinglemonospace'] = 0xFF07;
  12147. t['r'] = 0x0072;
  12148. t['raarmenian'] = 0x057C;
  12149. t['rabengali'] = 0x09B0;
  12150. t['racute'] = 0x0155;
  12151. t['radeva'] = 0x0930;
  12152. t['radical'] = 0x221A;
  12153. t['radicalex'] = 0xF8E5;
  12154. t['radoverssquare'] = 0x33AE;
  12155. t['radoverssquaredsquare'] = 0x33AF;
  12156. t['radsquare'] = 0x33AD;
  12157. t['rafe'] = 0x05BF;
  12158. t['rafehebrew'] = 0x05BF;
  12159. t['ragujarati'] = 0x0AB0;
  12160. t['ragurmukhi'] = 0x0A30;
  12161. t['rahiragana'] = 0x3089;
  12162. t['rakatakana'] = 0x30E9;
  12163. t['rakatakanahalfwidth'] = 0xFF97;
  12164. t['ralowerdiagonalbengali'] = 0x09F1;
  12165. t['ramiddlediagonalbengali'] = 0x09F0;
  12166. t['ramshorn'] = 0x0264;
  12167. t['ratio'] = 0x2236;
  12168. t['rbopomofo'] = 0x3116;
  12169. t['rcaron'] = 0x0159;
  12170. t['rcedilla'] = 0x0157;
  12171. t['rcircle'] = 0x24E1;
  12172. t['rcommaaccent'] = 0x0157;
  12173. t['rdblgrave'] = 0x0211;
  12174. t['rdotaccent'] = 0x1E59;
  12175. t['rdotbelow'] = 0x1E5B;
  12176. t['rdotbelowmacron'] = 0x1E5D;
  12177. t['referencemark'] = 0x203B;
  12178. t['reflexsubset'] = 0x2286;
  12179. t['reflexsuperset'] = 0x2287;
  12180. t['registered'] = 0x00AE;
  12181. t['registersans'] = 0xF8E8;
  12182. t['registerserif'] = 0xF6DA;
  12183. t['reharabic'] = 0x0631;
  12184. t['reharmenian'] = 0x0580;
  12185. t['rehfinalarabic'] = 0xFEAE;
  12186. t['rehiragana'] = 0x308C;
  12187. t['rekatakana'] = 0x30EC;
  12188. t['rekatakanahalfwidth'] = 0xFF9A;
  12189. t['resh'] = 0x05E8;
  12190. t['reshdageshhebrew'] = 0xFB48;
  12191. t['reshhebrew'] = 0x05E8;
  12192. t['reversedtilde'] = 0x223D;
  12193. t['reviahebrew'] = 0x0597;
  12194. t['reviamugrashhebrew'] = 0x0597;
  12195. t['revlogicalnot'] = 0x2310;
  12196. t['rfishhook'] = 0x027E;
  12197. t['rfishhookreversed'] = 0x027F;
  12198. t['rhabengali'] = 0x09DD;
  12199. t['rhadeva'] = 0x095D;
  12200. t['rho'] = 0x03C1;
  12201. t['rhook'] = 0x027D;
  12202. t['rhookturned'] = 0x027B;
  12203. t['rhookturnedsuperior'] = 0x02B5;
  12204. t['rhosymbolgreek'] = 0x03F1;
  12205. t['rhotichookmod'] = 0x02DE;
  12206. t['rieulacirclekorean'] = 0x3271;
  12207. t['rieulaparenkorean'] = 0x3211;
  12208. t['rieulcirclekorean'] = 0x3263;
  12209. t['rieulhieuhkorean'] = 0x3140;
  12210. t['rieulkiyeokkorean'] = 0x313A;
  12211. t['rieulkiyeoksioskorean'] = 0x3169;
  12212. t['rieulkorean'] = 0x3139;
  12213. t['rieulmieumkorean'] = 0x313B;
  12214. t['rieulpansioskorean'] = 0x316C;
  12215. t['rieulparenkorean'] = 0x3203;
  12216. t['rieulphieuphkorean'] = 0x313F;
  12217. t['rieulpieupkorean'] = 0x313C;
  12218. t['rieulpieupsioskorean'] = 0x316B;
  12219. t['rieulsioskorean'] = 0x313D;
  12220. t['rieulthieuthkorean'] = 0x313E;
  12221. t['rieultikeutkorean'] = 0x316A;
  12222. t['rieulyeorinhieuhkorean'] = 0x316D;
  12223. t['rightangle'] = 0x221F;
  12224. t['righttackbelowcmb'] = 0x0319;
  12225. t['righttriangle'] = 0x22BF;
  12226. t['rihiragana'] = 0x308A;
  12227. t['rikatakana'] = 0x30EA;
  12228. t['rikatakanahalfwidth'] = 0xFF98;
  12229. t['ring'] = 0x02DA;
  12230. t['ringbelowcmb'] = 0x0325;
  12231. t['ringcmb'] = 0x030A;
  12232. t['ringhalfleft'] = 0x02BF;
  12233. t['ringhalfleftarmenian'] = 0x0559;
  12234. t['ringhalfleftbelowcmb'] = 0x031C;
  12235. t['ringhalfleftcentered'] = 0x02D3;
  12236. t['ringhalfright'] = 0x02BE;
  12237. t['ringhalfrightbelowcmb'] = 0x0339;
  12238. t['ringhalfrightcentered'] = 0x02D2;
  12239. t['rinvertedbreve'] = 0x0213;
  12240. t['rittorusquare'] = 0x3351;
  12241. t['rlinebelow'] = 0x1E5F;
  12242. t['rlongleg'] = 0x027C;
  12243. t['rlonglegturned'] = 0x027A;
  12244. t['rmonospace'] = 0xFF52;
  12245. t['rohiragana'] = 0x308D;
  12246. t['rokatakana'] = 0x30ED;
  12247. t['rokatakanahalfwidth'] = 0xFF9B;
  12248. t['roruathai'] = 0x0E23;
  12249. t['rparen'] = 0x24AD;
  12250. t['rrabengali'] = 0x09DC;
  12251. t['rradeva'] = 0x0931;
  12252. t['rragurmukhi'] = 0x0A5C;
  12253. t['rreharabic'] = 0x0691;
  12254. t['rrehfinalarabic'] = 0xFB8D;
  12255. t['rrvocalicbengali'] = 0x09E0;
  12256. t['rrvocalicdeva'] = 0x0960;
  12257. t['rrvocalicgujarati'] = 0x0AE0;
  12258. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12259. t['rrvocalicvowelsigndeva'] = 0x0944;
  12260. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12261. t['rsuperior'] = 0xF6F1;
  12262. t['rtblock'] = 0x2590;
  12263. t['rturned'] = 0x0279;
  12264. t['rturnedsuperior'] = 0x02B4;
  12265. t['ruhiragana'] = 0x308B;
  12266. t['rukatakana'] = 0x30EB;
  12267. t['rukatakanahalfwidth'] = 0xFF99;
  12268. t['rupeemarkbengali'] = 0x09F2;
  12269. t['rupeesignbengali'] = 0x09F3;
  12270. t['rupiah'] = 0xF6DD;
  12271. t['ruthai'] = 0x0E24;
  12272. t['rvocalicbengali'] = 0x098B;
  12273. t['rvocalicdeva'] = 0x090B;
  12274. t['rvocalicgujarati'] = 0x0A8B;
  12275. t['rvocalicvowelsignbengali'] = 0x09C3;
  12276. t['rvocalicvowelsigndeva'] = 0x0943;
  12277. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12278. t['s'] = 0x0073;
  12279. t['sabengali'] = 0x09B8;
  12280. t['sacute'] = 0x015B;
  12281. t['sacutedotaccent'] = 0x1E65;
  12282. t['sadarabic'] = 0x0635;
  12283. t['sadeva'] = 0x0938;
  12284. t['sadfinalarabic'] = 0xFEBA;
  12285. t['sadinitialarabic'] = 0xFEBB;
  12286. t['sadmedialarabic'] = 0xFEBC;
  12287. t['sagujarati'] = 0x0AB8;
  12288. t['sagurmukhi'] = 0x0A38;
  12289. t['sahiragana'] = 0x3055;
  12290. t['sakatakana'] = 0x30B5;
  12291. t['sakatakanahalfwidth'] = 0xFF7B;
  12292. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12293. t['samekh'] = 0x05E1;
  12294. t['samekhdagesh'] = 0xFB41;
  12295. t['samekhdageshhebrew'] = 0xFB41;
  12296. t['samekhhebrew'] = 0x05E1;
  12297. t['saraaathai'] = 0x0E32;
  12298. t['saraaethai'] = 0x0E41;
  12299. t['saraaimaimalaithai'] = 0x0E44;
  12300. t['saraaimaimuanthai'] = 0x0E43;
  12301. t['saraamthai'] = 0x0E33;
  12302. t['saraathai'] = 0x0E30;
  12303. t['saraethai'] = 0x0E40;
  12304. t['saraiileftthai'] = 0xF886;
  12305. t['saraiithai'] = 0x0E35;
  12306. t['saraileftthai'] = 0xF885;
  12307. t['saraithai'] = 0x0E34;
  12308. t['saraothai'] = 0x0E42;
  12309. t['saraueeleftthai'] = 0xF888;
  12310. t['saraueethai'] = 0x0E37;
  12311. t['saraueleftthai'] = 0xF887;
  12312. t['sarauethai'] = 0x0E36;
  12313. t['sarauthai'] = 0x0E38;
  12314. t['sarauuthai'] = 0x0E39;
  12315. t['sbopomofo'] = 0x3119;
  12316. t['scaron'] = 0x0161;
  12317. t['scarondotaccent'] = 0x1E67;
  12318. t['scedilla'] = 0x015F;
  12319. t['schwa'] = 0x0259;
  12320. t['schwacyrillic'] = 0x04D9;
  12321. t['schwadieresiscyrillic'] = 0x04DB;
  12322. t['schwahook'] = 0x025A;
  12323. t['scircle'] = 0x24E2;
  12324. t['scircumflex'] = 0x015D;
  12325. t['scommaaccent'] = 0x0219;
  12326. t['sdotaccent'] = 0x1E61;
  12327. t['sdotbelow'] = 0x1E63;
  12328. t['sdotbelowdotaccent'] = 0x1E69;
  12329. t['seagullbelowcmb'] = 0x033C;
  12330. t['second'] = 0x2033;
  12331. t['secondtonechinese'] = 0x02CA;
  12332. t['section'] = 0x00A7;
  12333. t['seenarabic'] = 0x0633;
  12334. t['seenfinalarabic'] = 0xFEB2;
  12335. t['seeninitialarabic'] = 0xFEB3;
  12336. t['seenmedialarabic'] = 0xFEB4;
  12337. t['segol'] = 0x05B6;
  12338. t['segol13'] = 0x05B6;
  12339. t['segol1f'] = 0x05B6;
  12340. t['segol2c'] = 0x05B6;
  12341. t['segolhebrew'] = 0x05B6;
  12342. t['segolnarrowhebrew'] = 0x05B6;
  12343. t['segolquarterhebrew'] = 0x05B6;
  12344. t['segoltahebrew'] = 0x0592;
  12345. t['segolwidehebrew'] = 0x05B6;
  12346. t['seharmenian'] = 0x057D;
  12347. t['sehiragana'] = 0x305B;
  12348. t['sekatakana'] = 0x30BB;
  12349. t['sekatakanahalfwidth'] = 0xFF7E;
  12350. t['semicolon'] = 0x003B;
  12351. t['semicolonarabic'] = 0x061B;
  12352. t['semicolonmonospace'] = 0xFF1B;
  12353. t['semicolonsmall'] = 0xFE54;
  12354. t['semivoicedmarkkana'] = 0x309C;
  12355. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12356. t['sentisquare'] = 0x3322;
  12357. t['sentosquare'] = 0x3323;
  12358. t['seven'] = 0x0037;
  12359. t['sevenarabic'] = 0x0667;
  12360. t['sevenbengali'] = 0x09ED;
  12361. t['sevencircle'] = 0x2466;
  12362. t['sevencircleinversesansserif'] = 0x2790;
  12363. t['sevendeva'] = 0x096D;
  12364. t['seveneighths'] = 0x215E;
  12365. t['sevengujarati'] = 0x0AED;
  12366. t['sevengurmukhi'] = 0x0A6D;
  12367. t['sevenhackarabic'] = 0x0667;
  12368. t['sevenhangzhou'] = 0x3027;
  12369. t['sevenideographicparen'] = 0x3226;
  12370. t['seveninferior'] = 0x2087;
  12371. t['sevenmonospace'] = 0xFF17;
  12372. t['sevenoldstyle'] = 0xF737;
  12373. t['sevenparen'] = 0x247A;
  12374. t['sevenperiod'] = 0x248E;
  12375. t['sevenpersian'] = 0x06F7;
  12376. t['sevenroman'] = 0x2176;
  12377. t['sevensuperior'] = 0x2077;
  12378. t['seventeencircle'] = 0x2470;
  12379. t['seventeenparen'] = 0x2484;
  12380. t['seventeenperiod'] = 0x2498;
  12381. t['seventhai'] = 0x0E57;
  12382. t['sfthyphen'] = 0x00AD;
  12383. t['shaarmenian'] = 0x0577;
  12384. t['shabengali'] = 0x09B6;
  12385. t['shacyrillic'] = 0x0448;
  12386. t['shaddaarabic'] = 0x0651;
  12387. t['shaddadammaarabic'] = 0xFC61;
  12388. t['shaddadammatanarabic'] = 0xFC5E;
  12389. t['shaddafathaarabic'] = 0xFC60;
  12390. t['shaddakasraarabic'] = 0xFC62;
  12391. t['shaddakasratanarabic'] = 0xFC5F;
  12392. t['shade'] = 0x2592;
  12393. t['shadedark'] = 0x2593;
  12394. t['shadelight'] = 0x2591;
  12395. t['shademedium'] = 0x2592;
  12396. t['shadeva'] = 0x0936;
  12397. t['shagujarati'] = 0x0AB6;
  12398. t['shagurmukhi'] = 0x0A36;
  12399. t['shalshelethebrew'] = 0x0593;
  12400. t['shbopomofo'] = 0x3115;
  12401. t['shchacyrillic'] = 0x0449;
  12402. t['sheenarabic'] = 0x0634;
  12403. t['sheenfinalarabic'] = 0xFEB6;
  12404. t['sheeninitialarabic'] = 0xFEB7;
  12405. t['sheenmedialarabic'] = 0xFEB8;
  12406. t['sheicoptic'] = 0x03E3;
  12407. t['sheqel'] = 0x20AA;
  12408. t['sheqelhebrew'] = 0x20AA;
  12409. t['sheva'] = 0x05B0;
  12410. t['sheva115'] = 0x05B0;
  12411. t['sheva15'] = 0x05B0;
  12412. t['sheva22'] = 0x05B0;
  12413. t['sheva2e'] = 0x05B0;
  12414. t['shevahebrew'] = 0x05B0;
  12415. t['shevanarrowhebrew'] = 0x05B0;
  12416. t['shevaquarterhebrew'] = 0x05B0;
  12417. t['shevawidehebrew'] = 0x05B0;
  12418. t['shhacyrillic'] = 0x04BB;
  12419. t['shimacoptic'] = 0x03ED;
  12420. t['shin'] = 0x05E9;
  12421. t['shindagesh'] = 0xFB49;
  12422. t['shindageshhebrew'] = 0xFB49;
  12423. t['shindageshshindot'] = 0xFB2C;
  12424. t['shindageshshindothebrew'] = 0xFB2C;
  12425. t['shindageshsindot'] = 0xFB2D;
  12426. t['shindageshsindothebrew'] = 0xFB2D;
  12427. t['shindothebrew'] = 0x05C1;
  12428. t['shinhebrew'] = 0x05E9;
  12429. t['shinshindot'] = 0xFB2A;
  12430. t['shinshindothebrew'] = 0xFB2A;
  12431. t['shinsindot'] = 0xFB2B;
  12432. t['shinsindothebrew'] = 0xFB2B;
  12433. t['shook'] = 0x0282;
  12434. t['sigma'] = 0x03C3;
  12435. t['sigma1'] = 0x03C2;
  12436. t['sigmafinal'] = 0x03C2;
  12437. t['sigmalunatesymbolgreek'] = 0x03F2;
  12438. t['sihiragana'] = 0x3057;
  12439. t['sikatakana'] = 0x30B7;
  12440. t['sikatakanahalfwidth'] = 0xFF7C;
  12441. t['siluqhebrew'] = 0x05BD;
  12442. t['siluqlefthebrew'] = 0x05BD;
  12443. t['similar'] = 0x223C;
  12444. t['sindothebrew'] = 0x05C2;
  12445. t['siosacirclekorean'] = 0x3274;
  12446. t['siosaparenkorean'] = 0x3214;
  12447. t['sioscieuckorean'] = 0x317E;
  12448. t['sioscirclekorean'] = 0x3266;
  12449. t['sioskiyeokkorean'] = 0x317A;
  12450. t['sioskorean'] = 0x3145;
  12451. t['siosnieunkorean'] = 0x317B;
  12452. t['siosparenkorean'] = 0x3206;
  12453. t['siospieupkorean'] = 0x317D;
  12454. t['siostikeutkorean'] = 0x317C;
  12455. t['six'] = 0x0036;
  12456. t['sixarabic'] = 0x0666;
  12457. t['sixbengali'] = 0x09EC;
  12458. t['sixcircle'] = 0x2465;
  12459. t['sixcircleinversesansserif'] = 0x278F;
  12460. t['sixdeva'] = 0x096C;
  12461. t['sixgujarati'] = 0x0AEC;
  12462. t['sixgurmukhi'] = 0x0A6C;
  12463. t['sixhackarabic'] = 0x0666;
  12464. t['sixhangzhou'] = 0x3026;
  12465. t['sixideographicparen'] = 0x3225;
  12466. t['sixinferior'] = 0x2086;
  12467. t['sixmonospace'] = 0xFF16;
  12468. t['sixoldstyle'] = 0xF736;
  12469. t['sixparen'] = 0x2479;
  12470. t['sixperiod'] = 0x248D;
  12471. t['sixpersian'] = 0x06F6;
  12472. t['sixroman'] = 0x2175;
  12473. t['sixsuperior'] = 0x2076;
  12474. t['sixteencircle'] = 0x246F;
  12475. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12476. t['sixteenparen'] = 0x2483;
  12477. t['sixteenperiod'] = 0x2497;
  12478. t['sixthai'] = 0x0E56;
  12479. t['slash'] = 0x002F;
  12480. t['slashmonospace'] = 0xFF0F;
  12481. t['slong'] = 0x017F;
  12482. t['slongdotaccent'] = 0x1E9B;
  12483. t['smileface'] = 0x263A;
  12484. t['smonospace'] = 0xFF53;
  12485. t['sofpasuqhebrew'] = 0x05C3;
  12486. t['softhyphen'] = 0x00AD;
  12487. t['softsigncyrillic'] = 0x044C;
  12488. t['sohiragana'] = 0x305D;
  12489. t['sokatakana'] = 0x30BD;
  12490. t['sokatakanahalfwidth'] = 0xFF7F;
  12491. t['soliduslongoverlaycmb'] = 0x0338;
  12492. t['solidusshortoverlaycmb'] = 0x0337;
  12493. t['sorusithai'] = 0x0E29;
  12494. t['sosalathai'] = 0x0E28;
  12495. t['sosothai'] = 0x0E0B;
  12496. t['sosuathai'] = 0x0E2A;
  12497. t['space'] = 0x0020;
  12498. t['spacehackarabic'] = 0x0020;
  12499. t['spade'] = 0x2660;
  12500. t['spadesuitblack'] = 0x2660;
  12501. t['spadesuitwhite'] = 0x2664;
  12502. t['sparen'] = 0x24AE;
  12503. t['squarebelowcmb'] = 0x033B;
  12504. t['squarecc'] = 0x33C4;
  12505. t['squarecm'] = 0x339D;
  12506. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12507. t['squarehorizontalfill'] = 0x25A4;
  12508. t['squarekg'] = 0x338F;
  12509. t['squarekm'] = 0x339E;
  12510. t['squarekmcapital'] = 0x33CE;
  12511. t['squareln'] = 0x33D1;
  12512. t['squarelog'] = 0x33D2;
  12513. t['squaremg'] = 0x338E;
  12514. t['squaremil'] = 0x33D5;
  12515. t['squaremm'] = 0x339C;
  12516. t['squaremsquared'] = 0x33A1;
  12517. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12518. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12519. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12520. t['squareverticalfill'] = 0x25A5;
  12521. t['squarewhitewithsmallblack'] = 0x25A3;
  12522. t['srsquare'] = 0x33DB;
  12523. t['ssabengali'] = 0x09B7;
  12524. t['ssadeva'] = 0x0937;
  12525. t['ssagujarati'] = 0x0AB7;
  12526. t['ssangcieuckorean'] = 0x3149;
  12527. t['ssanghieuhkorean'] = 0x3185;
  12528. t['ssangieungkorean'] = 0x3180;
  12529. t['ssangkiyeokkorean'] = 0x3132;
  12530. t['ssangnieunkorean'] = 0x3165;
  12531. t['ssangpieupkorean'] = 0x3143;
  12532. t['ssangsioskorean'] = 0x3146;
  12533. t['ssangtikeutkorean'] = 0x3138;
  12534. t['ssuperior'] = 0xF6F2;
  12535. t['sterling'] = 0x00A3;
  12536. t['sterlingmonospace'] = 0xFFE1;
  12537. t['strokelongoverlaycmb'] = 0x0336;
  12538. t['strokeshortoverlaycmb'] = 0x0335;
  12539. t['subset'] = 0x2282;
  12540. t['subsetnotequal'] = 0x228A;
  12541. t['subsetorequal'] = 0x2286;
  12542. t['succeeds'] = 0x227B;
  12543. t['suchthat'] = 0x220B;
  12544. t['suhiragana'] = 0x3059;
  12545. t['sukatakana'] = 0x30B9;
  12546. t['sukatakanahalfwidth'] = 0xFF7D;
  12547. t['sukunarabic'] = 0x0652;
  12548. t['summation'] = 0x2211;
  12549. t['sun'] = 0x263C;
  12550. t['superset'] = 0x2283;
  12551. t['supersetnotequal'] = 0x228B;
  12552. t['supersetorequal'] = 0x2287;
  12553. t['svsquare'] = 0x33DC;
  12554. t['syouwaerasquare'] = 0x337C;
  12555. t['t'] = 0x0074;
  12556. t['tabengali'] = 0x09A4;
  12557. t['tackdown'] = 0x22A4;
  12558. t['tackleft'] = 0x22A3;
  12559. t['tadeva'] = 0x0924;
  12560. t['tagujarati'] = 0x0AA4;
  12561. t['tagurmukhi'] = 0x0A24;
  12562. t['taharabic'] = 0x0637;
  12563. t['tahfinalarabic'] = 0xFEC2;
  12564. t['tahinitialarabic'] = 0xFEC3;
  12565. t['tahiragana'] = 0x305F;
  12566. t['tahmedialarabic'] = 0xFEC4;
  12567. t['taisyouerasquare'] = 0x337D;
  12568. t['takatakana'] = 0x30BF;
  12569. t['takatakanahalfwidth'] = 0xFF80;
  12570. t['tatweelarabic'] = 0x0640;
  12571. t['tau'] = 0x03C4;
  12572. t['tav'] = 0x05EA;
  12573. t['tavdages'] = 0xFB4A;
  12574. t['tavdagesh'] = 0xFB4A;
  12575. t['tavdageshhebrew'] = 0xFB4A;
  12576. t['tavhebrew'] = 0x05EA;
  12577. t['tbar'] = 0x0167;
  12578. t['tbopomofo'] = 0x310A;
  12579. t['tcaron'] = 0x0165;
  12580. t['tccurl'] = 0x02A8;
  12581. t['tcedilla'] = 0x0163;
  12582. t['tcheharabic'] = 0x0686;
  12583. t['tchehfinalarabic'] = 0xFB7B;
  12584. t['tchehinitialarabic'] = 0xFB7C;
  12585. t['tchehmedialarabic'] = 0xFB7D;
  12586. t['tcircle'] = 0x24E3;
  12587. t['tcircumflexbelow'] = 0x1E71;
  12588. t['tcommaaccent'] = 0x0163;
  12589. t['tdieresis'] = 0x1E97;
  12590. t['tdotaccent'] = 0x1E6B;
  12591. t['tdotbelow'] = 0x1E6D;
  12592. t['tecyrillic'] = 0x0442;
  12593. t['tedescendercyrillic'] = 0x04AD;
  12594. t['teharabic'] = 0x062A;
  12595. t['tehfinalarabic'] = 0xFE96;
  12596. t['tehhahinitialarabic'] = 0xFCA2;
  12597. t['tehhahisolatedarabic'] = 0xFC0C;
  12598. t['tehinitialarabic'] = 0xFE97;
  12599. t['tehiragana'] = 0x3066;
  12600. t['tehjeeminitialarabic'] = 0xFCA1;
  12601. t['tehjeemisolatedarabic'] = 0xFC0B;
  12602. t['tehmarbutaarabic'] = 0x0629;
  12603. t['tehmarbutafinalarabic'] = 0xFE94;
  12604. t['tehmedialarabic'] = 0xFE98;
  12605. t['tehmeeminitialarabic'] = 0xFCA4;
  12606. t['tehmeemisolatedarabic'] = 0xFC0E;
  12607. t['tehnoonfinalarabic'] = 0xFC73;
  12608. t['tekatakana'] = 0x30C6;
  12609. t['tekatakanahalfwidth'] = 0xFF83;
  12610. t['telephone'] = 0x2121;
  12611. t['telephoneblack'] = 0x260E;
  12612. t['telishagedolahebrew'] = 0x05A0;
  12613. t['telishaqetanahebrew'] = 0x05A9;
  12614. t['tencircle'] = 0x2469;
  12615. t['tenideographicparen'] = 0x3229;
  12616. t['tenparen'] = 0x247D;
  12617. t['tenperiod'] = 0x2491;
  12618. t['tenroman'] = 0x2179;
  12619. t['tesh'] = 0x02A7;
  12620. t['tet'] = 0x05D8;
  12621. t['tetdagesh'] = 0xFB38;
  12622. t['tetdageshhebrew'] = 0xFB38;
  12623. t['tethebrew'] = 0x05D8;
  12624. t['tetsecyrillic'] = 0x04B5;
  12625. t['tevirhebrew'] = 0x059B;
  12626. t['tevirlefthebrew'] = 0x059B;
  12627. t['thabengali'] = 0x09A5;
  12628. t['thadeva'] = 0x0925;
  12629. t['thagujarati'] = 0x0AA5;
  12630. t['thagurmukhi'] = 0x0A25;
  12631. t['thalarabic'] = 0x0630;
  12632. t['thalfinalarabic'] = 0xFEAC;
  12633. t['thanthakhatlowleftthai'] = 0xF898;
  12634. t['thanthakhatlowrightthai'] = 0xF897;
  12635. t['thanthakhatthai'] = 0x0E4C;
  12636. t['thanthakhatupperleftthai'] = 0xF896;
  12637. t['theharabic'] = 0x062B;
  12638. t['thehfinalarabic'] = 0xFE9A;
  12639. t['thehinitialarabic'] = 0xFE9B;
  12640. t['thehmedialarabic'] = 0xFE9C;
  12641. t['thereexists'] = 0x2203;
  12642. t['therefore'] = 0x2234;
  12643. t['theta'] = 0x03B8;
  12644. t['theta1'] = 0x03D1;
  12645. t['thetasymbolgreek'] = 0x03D1;
  12646. t['thieuthacirclekorean'] = 0x3279;
  12647. t['thieuthaparenkorean'] = 0x3219;
  12648. t['thieuthcirclekorean'] = 0x326B;
  12649. t['thieuthkorean'] = 0x314C;
  12650. t['thieuthparenkorean'] = 0x320B;
  12651. t['thirteencircle'] = 0x246C;
  12652. t['thirteenparen'] = 0x2480;
  12653. t['thirteenperiod'] = 0x2494;
  12654. t['thonangmonthothai'] = 0x0E11;
  12655. t['thook'] = 0x01AD;
  12656. t['thophuthaothai'] = 0x0E12;
  12657. t['thorn'] = 0x00FE;
  12658. t['thothahanthai'] = 0x0E17;
  12659. t['thothanthai'] = 0x0E10;
  12660. t['thothongthai'] = 0x0E18;
  12661. t['thothungthai'] = 0x0E16;
  12662. t['thousandcyrillic'] = 0x0482;
  12663. t['thousandsseparatorarabic'] = 0x066C;
  12664. t['thousandsseparatorpersian'] = 0x066C;
  12665. t['three'] = 0x0033;
  12666. t['threearabic'] = 0x0663;
  12667. t['threebengali'] = 0x09E9;
  12668. t['threecircle'] = 0x2462;
  12669. t['threecircleinversesansserif'] = 0x278C;
  12670. t['threedeva'] = 0x0969;
  12671. t['threeeighths'] = 0x215C;
  12672. t['threegujarati'] = 0x0AE9;
  12673. t['threegurmukhi'] = 0x0A69;
  12674. t['threehackarabic'] = 0x0663;
  12675. t['threehangzhou'] = 0x3023;
  12676. t['threeideographicparen'] = 0x3222;
  12677. t['threeinferior'] = 0x2083;
  12678. t['threemonospace'] = 0xFF13;
  12679. t['threenumeratorbengali'] = 0x09F6;
  12680. t['threeoldstyle'] = 0xF733;
  12681. t['threeparen'] = 0x2476;
  12682. t['threeperiod'] = 0x248A;
  12683. t['threepersian'] = 0x06F3;
  12684. t['threequarters'] = 0x00BE;
  12685. t['threequartersemdash'] = 0xF6DE;
  12686. t['threeroman'] = 0x2172;
  12687. t['threesuperior'] = 0x00B3;
  12688. t['threethai'] = 0x0E53;
  12689. t['thzsquare'] = 0x3394;
  12690. t['tihiragana'] = 0x3061;
  12691. t['tikatakana'] = 0x30C1;
  12692. t['tikatakanahalfwidth'] = 0xFF81;
  12693. t['tikeutacirclekorean'] = 0x3270;
  12694. t['tikeutaparenkorean'] = 0x3210;
  12695. t['tikeutcirclekorean'] = 0x3262;
  12696. t['tikeutkorean'] = 0x3137;
  12697. t['tikeutparenkorean'] = 0x3202;
  12698. t['tilde'] = 0x02DC;
  12699. t['tildebelowcmb'] = 0x0330;
  12700. t['tildecmb'] = 0x0303;
  12701. t['tildecomb'] = 0x0303;
  12702. t['tildedoublecmb'] = 0x0360;
  12703. t['tildeoperator'] = 0x223C;
  12704. t['tildeoverlaycmb'] = 0x0334;
  12705. t['tildeverticalcmb'] = 0x033E;
  12706. t['timescircle'] = 0x2297;
  12707. t['tipehahebrew'] = 0x0596;
  12708. t['tipehalefthebrew'] = 0x0596;
  12709. t['tippigurmukhi'] = 0x0A70;
  12710. t['titlocyrilliccmb'] = 0x0483;
  12711. t['tiwnarmenian'] = 0x057F;
  12712. t['tlinebelow'] = 0x1E6F;
  12713. t['tmonospace'] = 0xFF54;
  12714. t['toarmenian'] = 0x0569;
  12715. t['tohiragana'] = 0x3068;
  12716. t['tokatakana'] = 0x30C8;
  12717. t['tokatakanahalfwidth'] = 0xFF84;
  12718. t['tonebarextrahighmod'] = 0x02E5;
  12719. t['tonebarextralowmod'] = 0x02E9;
  12720. t['tonebarhighmod'] = 0x02E6;
  12721. t['tonebarlowmod'] = 0x02E8;
  12722. t['tonebarmidmod'] = 0x02E7;
  12723. t['tonefive'] = 0x01BD;
  12724. t['tonesix'] = 0x0185;
  12725. t['tonetwo'] = 0x01A8;
  12726. t['tonos'] = 0x0384;
  12727. t['tonsquare'] = 0x3327;
  12728. t['topatakthai'] = 0x0E0F;
  12729. t['tortoiseshellbracketleft'] = 0x3014;
  12730. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12731. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12732. t['tortoiseshellbracketright'] = 0x3015;
  12733. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12734. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12735. t['totaothai'] = 0x0E15;
  12736. t['tpalatalhook'] = 0x01AB;
  12737. t['tparen'] = 0x24AF;
  12738. t['trademark'] = 0x2122;
  12739. t['trademarksans'] = 0xF8EA;
  12740. t['trademarkserif'] = 0xF6DB;
  12741. t['tretroflexhook'] = 0x0288;
  12742. t['triagdn'] = 0x25BC;
  12743. t['triaglf'] = 0x25C4;
  12744. t['triagrt'] = 0x25BA;
  12745. t['triagup'] = 0x25B2;
  12746. t['ts'] = 0x02A6;
  12747. t['tsadi'] = 0x05E6;
  12748. t['tsadidagesh'] = 0xFB46;
  12749. t['tsadidageshhebrew'] = 0xFB46;
  12750. t['tsadihebrew'] = 0x05E6;
  12751. t['tsecyrillic'] = 0x0446;
  12752. t['tsere'] = 0x05B5;
  12753. t['tsere12'] = 0x05B5;
  12754. t['tsere1e'] = 0x05B5;
  12755. t['tsere2b'] = 0x05B5;
  12756. t['tserehebrew'] = 0x05B5;
  12757. t['tserenarrowhebrew'] = 0x05B5;
  12758. t['tserequarterhebrew'] = 0x05B5;
  12759. t['tserewidehebrew'] = 0x05B5;
  12760. t['tshecyrillic'] = 0x045B;
  12761. t['tsuperior'] = 0xF6F3;
  12762. t['ttabengali'] = 0x099F;
  12763. t['ttadeva'] = 0x091F;
  12764. t['ttagujarati'] = 0x0A9F;
  12765. t['ttagurmukhi'] = 0x0A1F;
  12766. t['tteharabic'] = 0x0679;
  12767. t['ttehfinalarabic'] = 0xFB67;
  12768. t['ttehinitialarabic'] = 0xFB68;
  12769. t['ttehmedialarabic'] = 0xFB69;
  12770. t['tthabengali'] = 0x09A0;
  12771. t['tthadeva'] = 0x0920;
  12772. t['tthagujarati'] = 0x0AA0;
  12773. t['tthagurmukhi'] = 0x0A20;
  12774. t['tturned'] = 0x0287;
  12775. t['tuhiragana'] = 0x3064;
  12776. t['tukatakana'] = 0x30C4;
  12777. t['tukatakanahalfwidth'] = 0xFF82;
  12778. t['tusmallhiragana'] = 0x3063;
  12779. t['tusmallkatakana'] = 0x30C3;
  12780. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12781. t['twelvecircle'] = 0x246B;
  12782. t['twelveparen'] = 0x247F;
  12783. t['twelveperiod'] = 0x2493;
  12784. t['twelveroman'] = 0x217B;
  12785. t['twentycircle'] = 0x2473;
  12786. t['twentyhangzhou'] = 0x5344;
  12787. t['twentyparen'] = 0x2487;
  12788. t['twentyperiod'] = 0x249B;
  12789. t['two'] = 0x0032;
  12790. t['twoarabic'] = 0x0662;
  12791. t['twobengali'] = 0x09E8;
  12792. t['twocircle'] = 0x2461;
  12793. t['twocircleinversesansserif'] = 0x278B;
  12794. t['twodeva'] = 0x0968;
  12795. t['twodotenleader'] = 0x2025;
  12796. t['twodotleader'] = 0x2025;
  12797. t['twodotleadervertical'] = 0xFE30;
  12798. t['twogujarati'] = 0x0AE8;
  12799. t['twogurmukhi'] = 0x0A68;
  12800. t['twohackarabic'] = 0x0662;
  12801. t['twohangzhou'] = 0x3022;
  12802. t['twoideographicparen'] = 0x3221;
  12803. t['twoinferior'] = 0x2082;
  12804. t['twomonospace'] = 0xFF12;
  12805. t['twonumeratorbengali'] = 0x09F5;
  12806. t['twooldstyle'] = 0xF732;
  12807. t['twoparen'] = 0x2475;
  12808. t['twoperiod'] = 0x2489;
  12809. t['twopersian'] = 0x06F2;
  12810. t['tworoman'] = 0x2171;
  12811. t['twostroke'] = 0x01BB;
  12812. t['twosuperior'] = 0x00B2;
  12813. t['twothai'] = 0x0E52;
  12814. t['twothirds'] = 0x2154;
  12815. t['u'] = 0x0075;
  12816. t['uacute'] = 0x00FA;
  12817. t['ubar'] = 0x0289;
  12818. t['ubengali'] = 0x0989;
  12819. t['ubopomofo'] = 0x3128;
  12820. t['ubreve'] = 0x016D;
  12821. t['ucaron'] = 0x01D4;
  12822. t['ucircle'] = 0x24E4;
  12823. t['ucircumflex'] = 0x00FB;
  12824. t['ucircumflexbelow'] = 0x1E77;
  12825. t['ucyrillic'] = 0x0443;
  12826. t['udattadeva'] = 0x0951;
  12827. t['udblacute'] = 0x0171;
  12828. t['udblgrave'] = 0x0215;
  12829. t['udeva'] = 0x0909;
  12830. t['udieresis'] = 0x00FC;
  12831. t['udieresisacute'] = 0x01D8;
  12832. t['udieresisbelow'] = 0x1E73;
  12833. t['udieresiscaron'] = 0x01DA;
  12834. t['udieresiscyrillic'] = 0x04F1;
  12835. t['udieresisgrave'] = 0x01DC;
  12836. t['udieresismacron'] = 0x01D6;
  12837. t['udotbelow'] = 0x1EE5;
  12838. t['ugrave'] = 0x00F9;
  12839. t['ugujarati'] = 0x0A89;
  12840. t['ugurmukhi'] = 0x0A09;
  12841. t['uhiragana'] = 0x3046;
  12842. t['uhookabove'] = 0x1EE7;
  12843. t['uhorn'] = 0x01B0;
  12844. t['uhornacute'] = 0x1EE9;
  12845. t['uhorndotbelow'] = 0x1EF1;
  12846. t['uhorngrave'] = 0x1EEB;
  12847. t['uhornhookabove'] = 0x1EED;
  12848. t['uhorntilde'] = 0x1EEF;
  12849. t['uhungarumlaut'] = 0x0171;
  12850. t['uhungarumlautcyrillic'] = 0x04F3;
  12851. t['uinvertedbreve'] = 0x0217;
  12852. t['ukatakana'] = 0x30A6;
  12853. t['ukatakanahalfwidth'] = 0xFF73;
  12854. t['ukcyrillic'] = 0x0479;
  12855. t['ukorean'] = 0x315C;
  12856. t['umacron'] = 0x016B;
  12857. t['umacroncyrillic'] = 0x04EF;
  12858. t['umacrondieresis'] = 0x1E7B;
  12859. t['umatragurmukhi'] = 0x0A41;
  12860. t['umonospace'] = 0xFF55;
  12861. t['underscore'] = 0x005F;
  12862. t['underscoredbl'] = 0x2017;
  12863. t['underscoremonospace'] = 0xFF3F;
  12864. t['underscorevertical'] = 0xFE33;
  12865. t['underscorewavy'] = 0xFE4F;
  12866. t['union'] = 0x222A;
  12867. t['universal'] = 0x2200;
  12868. t['uogonek'] = 0x0173;
  12869. t['uparen'] = 0x24B0;
  12870. t['upblock'] = 0x2580;
  12871. t['upperdothebrew'] = 0x05C4;
  12872. t['upsilon'] = 0x03C5;
  12873. t['upsilondieresis'] = 0x03CB;
  12874. t['upsilondieresistonos'] = 0x03B0;
  12875. t['upsilonlatin'] = 0x028A;
  12876. t['upsilontonos'] = 0x03CD;
  12877. t['uptackbelowcmb'] = 0x031D;
  12878. t['uptackmod'] = 0x02D4;
  12879. t['uragurmukhi'] = 0x0A73;
  12880. t['uring'] = 0x016F;
  12881. t['ushortcyrillic'] = 0x045E;
  12882. t['usmallhiragana'] = 0x3045;
  12883. t['usmallkatakana'] = 0x30A5;
  12884. t['usmallkatakanahalfwidth'] = 0xFF69;
  12885. t['ustraightcyrillic'] = 0x04AF;
  12886. t['ustraightstrokecyrillic'] = 0x04B1;
  12887. t['utilde'] = 0x0169;
  12888. t['utildeacute'] = 0x1E79;
  12889. t['utildebelow'] = 0x1E75;
  12890. t['uubengali'] = 0x098A;
  12891. t['uudeva'] = 0x090A;
  12892. t['uugujarati'] = 0x0A8A;
  12893. t['uugurmukhi'] = 0x0A0A;
  12894. t['uumatragurmukhi'] = 0x0A42;
  12895. t['uuvowelsignbengali'] = 0x09C2;
  12896. t['uuvowelsigndeva'] = 0x0942;
  12897. t['uuvowelsigngujarati'] = 0x0AC2;
  12898. t['uvowelsignbengali'] = 0x09C1;
  12899. t['uvowelsigndeva'] = 0x0941;
  12900. t['uvowelsigngujarati'] = 0x0AC1;
  12901. t['v'] = 0x0076;
  12902. t['vadeva'] = 0x0935;
  12903. t['vagujarati'] = 0x0AB5;
  12904. t['vagurmukhi'] = 0x0A35;
  12905. t['vakatakana'] = 0x30F7;
  12906. t['vav'] = 0x05D5;
  12907. t['vavdagesh'] = 0xFB35;
  12908. t['vavdagesh65'] = 0xFB35;
  12909. t['vavdageshhebrew'] = 0xFB35;
  12910. t['vavhebrew'] = 0x05D5;
  12911. t['vavholam'] = 0xFB4B;
  12912. t['vavholamhebrew'] = 0xFB4B;
  12913. t['vavvavhebrew'] = 0x05F0;
  12914. t['vavyodhebrew'] = 0x05F1;
  12915. t['vcircle'] = 0x24E5;
  12916. t['vdotbelow'] = 0x1E7F;
  12917. t['vecyrillic'] = 0x0432;
  12918. t['veharabic'] = 0x06A4;
  12919. t['vehfinalarabic'] = 0xFB6B;
  12920. t['vehinitialarabic'] = 0xFB6C;
  12921. t['vehmedialarabic'] = 0xFB6D;
  12922. t['vekatakana'] = 0x30F9;
  12923. t['venus'] = 0x2640;
  12924. t['verticalbar'] = 0x007C;
  12925. t['verticallineabovecmb'] = 0x030D;
  12926. t['verticallinebelowcmb'] = 0x0329;
  12927. t['verticallinelowmod'] = 0x02CC;
  12928. t['verticallinemod'] = 0x02C8;
  12929. t['vewarmenian'] = 0x057E;
  12930. t['vhook'] = 0x028B;
  12931. t['vikatakana'] = 0x30F8;
  12932. t['viramabengali'] = 0x09CD;
  12933. t['viramadeva'] = 0x094D;
  12934. t['viramagujarati'] = 0x0ACD;
  12935. t['visargabengali'] = 0x0983;
  12936. t['visargadeva'] = 0x0903;
  12937. t['visargagujarati'] = 0x0A83;
  12938. t['vmonospace'] = 0xFF56;
  12939. t['voarmenian'] = 0x0578;
  12940. t['voicediterationhiragana'] = 0x309E;
  12941. t['voicediterationkatakana'] = 0x30FE;
  12942. t['voicedmarkkana'] = 0x309B;
  12943. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12944. t['vokatakana'] = 0x30FA;
  12945. t['vparen'] = 0x24B1;
  12946. t['vtilde'] = 0x1E7D;
  12947. t['vturned'] = 0x028C;
  12948. t['vuhiragana'] = 0x3094;
  12949. t['vukatakana'] = 0x30F4;
  12950. t['w'] = 0x0077;
  12951. t['wacute'] = 0x1E83;
  12952. t['waekorean'] = 0x3159;
  12953. t['wahiragana'] = 0x308F;
  12954. t['wakatakana'] = 0x30EF;
  12955. t['wakatakanahalfwidth'] = 0xFF9C;
  12956. t['wakorean'] = 0x3158;
  12957. t['wasmallhiragana'] = 0x308E;
  12958. t['wasmallkatakana'] = 0x30EE;
  12959. t['wattosquare'] = 0x3357;
  12960. t['wavedash'] = 0x301C;
  12961. t['wavyunderscorevertical'] = 0xFE34;
  12962. t['wawarabic'] = 0x0648;
  12963. t['wawfinalarabic'] = 0xFEEE;
  12964. t['wawhamzaabovearabic'] = 0x0624;
  12965. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12966. t['wbsquare'] = 0x33DD;
  12967. t['wcircle'] = 0x24E6;
  12968. t['wcircumflex'] = 0x0175;
  12969. t['wdieresis'] = 0x1E85;
  12970. t['wdotaccent'] = 0x1E87;
  12971. t['wdotbelow'] = 0x1E89;
  12972. t['wehiragana'] = 0x3091;
  12973. t['weierstrass'] = 0x2118;
  12974. t['wekatakana'] = 0x30F1;
  12975. t['wekorean'] = 0x315E;
  12976. t['weokorean'] = 0x315D;
  12977. t['wgrave'] = 0x1E81;
  12978. t['whitebullet'] = 0x25E6;
  12979. t['whitecircle'] = 0x25CB;
  12980. t['whitecircleinverse'] = 0x25D9;
  12981. t['whitecornerbracketleft'] = 0x300E;
  12982. t['whitecornerbracketleftvertical'] = 0xFE43;
  12983. t['whitecornerbracketright'] = 0x300F;
  12984. t['whitecornerbracketrightvertical'] = 0xFE44;
  12985. t['whitediamond'] = 0x25C7;
  12986. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12987. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12988. t['whitedownpointingtriangle'] = 0x25BD;
  12989. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12990. t['whiteleftpointingtriangle'] = 0x25C1;
  12991. t['whitelenticularbracketleft'] = 0x3016;
  12992. t['whitelenticularbracketright'] = 0x3017;
  12993. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12994. t['whiterightpointingtriangle'] = 0x25B7;
  12995. t['whitesmallsquare'] = 0x25AB;
  12996. t['whitesmilingface'] = 0x263A;
  12997. t['whitesquare'] = 0x25A1;
  12998. t['whitestar'] = 0x2606;
  12999. t['whitetelephone'] = 0x260F;
  13000. t['whitetortoiseshellbracketleft'] = 0x3018;
  13001. t['whitetortoiseshellbracketright'] = 0x3019;
  13002. t['whiteuppointingsmalltriangle'] = 0x25B5;
  13003. t['whiteuppointingtriangle'] = 0x25B3;
  13004. t['wihiragana'] = 0x3090;
  13005. t['wikatakana'] = 0x30F0;
  13006. t['wikorean'] = 0x315F;
  13007. t['wmonospace'] = 0xFF57;
  13008. t['wohiragana'] = 0x3092;
  13009. t['wokatakana'] = 0x30F2;
  13010. t['wokatakanahalfwidth'] = 0xFF66;
  13011. t['won'] = 0x20A9;
  13012. t['wonmonospace'] = 0xFFE6;
  13013. t['wowaenthai'] = 0x0E27;
  13014. t['wparen'] = 0x24B2;
  13015. t['wring'] = 0x1E98;
  13016. t['wsuperior'] = 0x02B7;
  13017. t['wturned'] = 0x028D;
  13018. t['wynn'] = 0x01BF;
  13019. t['x'] = 0x0078;
  13020. t['xabovecmb'] = 0x033D;
  13021. t['xbopomofo'] = 0x3112;
  13022. t['xcircle'] = 0x24E7;
  13023. t['xdieresis'] = 0x1E8D;
  13024. t['xdotaccent'] = 0x1E8B;
  13025. t['xeharmenian'] = 0x056D;
  13026. t['xi'] = 0x03BE;
  13027. t['xmonospace'] = 0xFF58;
  13028. t['xparen'] = 0x24B3;
  13029. t['xsuperior'] = 0x02E3;
  13030. t['y'] = 0x0079;
  13031. t['yaadosquare'] = 0x334E;
  13032. t['yabengali'] = 0x09AF;
  13033. t['yacute'] = 0x00FD;
  13034. t['yadeva'] = 0x092F;
  13035. t['yaekorean'] = 0x3152;
  13036. t['yagujarati'] = 0x0AAF;
  13037. t['yagurmukhi'] = 0x0A2F;
  13038. t['yahiragana'] = 0x3084;
  13039. t['yakatakana'] = 0x30E4;
  13040. t['yakatakanahalfwidth'] = 0xFF94;
  13041. t['yakorean'] = 0x3151;
  13042. t['yamakkanthai'] = 0x0E4E;
  13043. t['yasmallhiragana'] = 0x3083;
  13044. t['yasmallkatakana'] = 0x30E3;
  13045. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13046. t['yatcyrillic'] = 0x0463;
  13047. t['ycircle'] = 0x24E8;
  13048. t['ycircumflex'] = 0x0177;
  13049. t['ydieresis'] = 0x00FF;
  13050. t['ydotaccent'] = 0x1E8F;
  13051. t['ydotbelow'] = 0x1EF5;
  13052. t['yeharabic'] = 0x064A;
  13053. t['yehbarreearabic'] = 0x06D2;
  13054. t['yehbarreefinalarabic'] = 0xFBAF;
  13055. t['yehfinalarabic'] = 0xFEF2;
  13056. t['yehhamzaabovearabic'] = 0x0626;
  13057. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13058. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13059. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13060. t['yehinitialarabic'] = 0xFEF3;
  13061. t['yehmedialarabic'] = 0xFEF4;
  13062. t['yehmeeminitialarabic'] = 0xFCDD;
  13063. t['yehmeemisolatedarabic'] = 0xFC58;
  13064. t['yehnoonfinalarabic'] = 0xFC94;
  13065. t['yehthreedotsbelowarabic'] = 0x06D1;
  13066. t['yekorean'] = 0x3156;
  13067. t['yen'] = 0x00A5;
  13068. t['yenmonospace'] = 0xFFE5;
  13069. t['yeokorean'] = 0x3155;
  13070. t['yeorinhieuhkorean'] = 0x3186;
  13071. t['yerahbenyomohebrew'] = 0x05AA;
  13072. t['yerahbenyomolefthebrew'] = 0x05AA;
  13073. t['yericyrillic'] = 0x044B;
  13074. t['yerudieresiscyrillic'] = 0x04F9;
  13075. t['yesieungkorean'] = 0x3181;
  13076. t['yesieungpansioskorean'] = 0x3183;
  13077. t['yesieungsioskorean'] = 0x3182;
  13078. t['yetivhebrew'] = 0x059A;
  13079. t['ygrave'] = 0x1EF3;
  13080. t['yhook'] = 0x01B4;
  13081. t['yhookabove'] = 0x1EF7;
  13082. t['yiarmenian'] = 0x0575;
  13083. t['yicyrillic'] = 0x0457;
  13084. t['yikorean'] = 0x3162;
  13085. t['yinyang'] = 0x262F;
  13086. t['yiwnarmenian'] = 0x0582;
  13087. t['ymonospace'] = 0xFF59;
  13088. t['yod'] = 0x05D9;
  13089. t['yoddagesh'] = 0xFB39;
  13090. t['yoddageshhebrew'] = 0xFB39;
  13091. t['yodhebrew'] = 0x05D9;
  13092. t['yodyodhebrew'] = 0x05F2;
  13093. t['yodyodpatahhebrew'] = 0xFB1F;
  13094. t['yohiragana'] = 0x3088;
  13095. t['yoikorean'] = 0x3189;
  13096. t['yokatakana'] = 0x30E8;
  13097. t['yokatakanahalfwidth'] = 0xFF96;
  13098. t['yokorean'] = 0x315B;
  13099. t['yosmallhiragana'] = 0x3087;
  13100. t['yosmallkatakana'] = 0x30E7;
  13101. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13102. t['yotgreek'] = 0x03F3;
  13103. t['yoyaekorean'] = 0x3188;
  13104. t['yoyakorean'] = 0x3187;
  13105. t['yoyakthai'] = 0x0E22;
  13106. t['yoyingthai'] = 0x0E0D;
  13107. t['yparen'] = 0x24B4;
  13108. t['ypogegrammeni'] = 0x037A;
  13109. t['ypogegrammenigreekcmb'] = 0x0345;
  13110. t['yr'] = 0x01A6;
  13111. t['yring'] = 0x1E99;
  13112. t['ysuperior'] = 0x02B8;
  13113. t['ytilde'] = 0x1EF9;
  13114. t['yturned'] = 0x028E;
  13115. t['yuhiragana'] = 0x3086;
  13116. t['yuikorean'] = 0x318C;
  13117. t['yukatakana'] = 0x30E6;
  13118. t['yukatakanahalfwidth'] = 0xFF95;
  13119. t['yukorean'] = 0x3160;
  13120. t['yusbigcyrillic'] = 0x046B;
  13121. t['yusbigiotifiedcyrillic'] = 0x046D;
  13122. t['yuslittlecyrillic'] = 0x0467;
  13123. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13124. t['yusmallhiragana'] = 0x3085;
  13125. t['yusmallkatakana'] = 0x30E5;
  13126. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13127. t['yuyekorean'] = 0x318B;
  13128. t['yuyeokorean'] = 0x318A;
  13129. t['yyabengali'] = 0x09DF;
  13130. t['yyadeva'] = 0x095F;
  13131. t['z'] = 0x007A;
  13132. t['zaarmenian'] = 0x0566;
  13133. t['zacute'] = 0x017A;
  13134. t['zadeva'] = 0x095B;
  13135. t['zagurmukhi'] = 0x0A5B;
  13136. t['zaharabic'] = 0x0638;
  13137. t['zahfinalarabic'] = 0xFEC6;
  13138. t['zahinitialarabic'] = 0xFEC7;
  13139. t['zahiragana'] = 0x3056;
  13140. t['zahmedialarabic'] = 0xFEC8;
  13141. t['zainarabic'] = 0x0632;
  13142. t['zainfinalarabic'] = 0xFEB0;
  13143. t['zakatakana'] = 0x30B6;
  13144. t['zaqefgadolhebrew'] = 0x0595;
  13145. t['zaqefqatanhebrew'] = 0x0594;
  13146. t['zarqahebrew'] = 0x0598;
  13147. t['zayin'] = 0x05D6;
  13148. t['zayindagesh'] = 0xFB36;
  13149. t['zayindageshhebrew'] = 0xFB36;
  13150. t['zayinhebrew'] = 0x05D6;
  13151. t['zbopomofo'] = 0x3117;
  13152. t['zcaron'] = 0x017E;
  13153. t['zcircle'] = 0x24E9;
  13154. t['zcircumflex'] = 0x1E91;
  13155. t['zcurl'] = 0x0291;
  13156. t['zdot'] = 0x017C;
  13157. t['zdotaccent'] = 0x017C;
  13158. t['zdotbelow'] = 0x1E93;
  13159. t['zecyrillic'] = 0x0437;
  13160. t['zedescendercyrillic'] = 0x0499;
  13161. t['zedieresiscyrillic'] = 0x04DF;
  13162. t['zehiragana'] = 0x305C;
  13163. t['zekatakana'] = 0x30BC;
  13164. t['zero'] = 0x0030;
  13165. t['zeroarabic'] = 0x0660;
  13166. t['zerobengali'] = 0x09E6;
  13167. t['zerodeva'] = 0x0966;
  13168. t['zerogujarati'] = 0x0AE6;
  13169. t['zerogurmukhi'] = 0x0A66;
  13170. t['zerohackarabic'] = 0x0660;
  13171. t['zeroinferior'] = 0x2080;
  13172. t['zeromonospace'] = 0xFF10;
  13173. t['zerooldstyle'] = 0xF730;
  13174. t['zeropersian'] = 0x06F0;
  13175. t['zerosuperior'] = 0x2070;
  13176. t['zerothai'] = 0x0E50;
  13177. t['zerowidthjoiner'] = 0xFEFF;
  13178. t['zerowidthnonjoiner'] = 0x200C;
  13179. t['zerowidthspace'] = 0x200B;
  13180. t['zeta'] = 0x03B6;
  13181. t['zhbopomofo'] = 0x3113;
  13182. t['zhearmenian'] = 0x056A;
  13183. t['zhebrevecyrillic'] = 0x04C2;
  13184. t['zhecyrillic'] = 0x0436;
  13185. t['zhedescendercyrillic'] = 0x0497;
  13186. t['zhedieresiscyrillic'] = 0x04DD;
  13187. t['zihiragana'] = 0x3058;
  13188. t['zikatakana'] = 0x30B8;
  13189. t['zinorhebrew'] = 0x05AE;
  13190. t['zlinebelow'] = 0x1E95;
  13191. t['zmonospace'] = 0xFF5A;
  13192. t['zohiragana'] = 0x305E;
  13193. t['zokatakana'] = 0x30BE;
  13194. t['zparen'] = 0x24B5;
  13195. t['zretroflexhook'] = 0x0290;
  13196. t['zstroke'] = 0x01B6;
  13197. t['zuhiragana'] = 0x305A;
  13198. t['zukatakana'] = 0x30BA;
  13199. t['.notdef'] = 0x0000;
  13200. });
  13201. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13202. t['space'] = 0x0020;
  13203. t['a1'] = 0x2701;
  13204. t['a2'] = 0x2702;
  13205. t['a202'] = 0x2703;
  13206. t['a3'] = 0x2704;
  13207. t['a4'] = 0x260E;
  13208. t['a5'] = 0x2706;
  13209. t['a119'] = 0x2707;
  13210. t['a118'] = 0x2708;
  13211. t['a117'] = 0x2709;
  13212. t['a11'] = 0x261B;
  13213. t['a12'] = 0x261E;
  13214. t['a13'] = 0x270C;
  13215. t['a14'] = 0x270D;
  13216. t['a15'] = 0x270E;
  13217. t['a16'] = 0x270F;
  13218. t['a105'] = 0x2710;
  13219. t['a17'] = 0x2711;
  13220. t['a18'] = 0x2712;
  13221. t['a19'] = 0x2713;
  13222. t['a20'] = 0x2714;
  13223. t['a21'] = 0x2715;
  13224. t['a22'] = 0x2716;
  13225. t['a23'] = 0x2717;
  13226. t['a24'] = 0x2718;
  13227. t['a25'] = 0x2719;
  13228. t['a26'] = 0x271A;
  13229. t['a27'] = 0x271B;
  13230. t['a28'] = 0x271C;
  13231. t['a6'] = 0x271D;
  13232. t['a7'] = 0x271E;
  13233. t['a8'] = 0x271F;
  13234. t['a9'] = 0x2720;
  13235. t['a10'] = 0x2721;
  13236. t['a29'] = 0x2722;
  13237. t['a30'] = 0x2723;
  13238. t['a31'] = 0x2724;
  13239. t['a32'] = 0x2725;
  13240. t['a33'] = 0x2726;
  13241. t['a34'] = 0x2727;
  13242. t['a35'] = 0x2605;
  13243. t['a36'] = 0x2729;
  13244. t['a37'] = 0x272A;
  13245. t['a38'] = 0x272B;
  13246. t['a39'] = 0x272C;
  13247. t['a40'] = 0x272D;
  13248. t['a41'] = 0x272E;
  13249. t['a42'] = 0x272F;
  13250. t['a43'] = 0x2730;
  13251. t['a44'] = 0x2731;
  13252. t['a45'] = 0x2732;
  13253. t['a46'] = 0x2733;
  13254. t['a47'] = 0x2734;
  13255. t['a48'] = 0x2735;
  13256. t['a49'] = 0x2736;
  13257. t['a50'] = 0x2737;
  13258. t['a51'] = 0x2738;
  13259. t['a52'] = 0x2739;
  13260. t['a53'] = 0x273A;
  13261. t['a54'] = 0x273B;
  13262. t['a55'] = 0x273C;
  13263. t['a56'] = 0x273D;
  13264. t['a57'] = 0x273E;
  13265. t['a58'] = 0x273F;
  13266. t['a59'] = 0x2740;
  13267. t['a60'] = 0x2741;
  13268. t['a61'] = 0x2742;
  13269. t['a62'] = 0x2743;
  13270. t['a63'] = 0x2744;
  13271. t['a64'] = 0x2745;
  13272. t['a65'] = 0x2746;
  13273. t['a66'] = 0x2747;
  13274. t['a67'] = 0x2748;
  13275. t['a68'] = 0x2749;
  13276. t['a69'] = 0x274A;
  13277. t['a70'] = 0x274B;
  13278. t['a71'] = 0x25CF;
  13279. t['a72'] = 0x274D;
  13280. t['a73'] = 0x25A0;
  13281. t['a74'] = 0x274F;
  13282. t['a203'] = 0x2750;
  13283. t['a75'] = 0x2751;
  13284. t['a204'] = 0x2752;
  13285. t['a76'] = 0x25B2;
  13286. t['a77'] = 0x25BC;
  13287. t['a78'] = 0x25C6;
  13288. t['a79'] = 0x2756;
  13289. t['a81'] = 0x25D7;
  13290. t['a82'] = 0x2758;
  13291. t['a83'] = 0x2759;
  13292. t['a84'] = 0x275A;
  13293. t['a97'] = 0x275B;
  13294. t['a98'] = 0x275C;
  13295. t['a99'] = 0x275D;
  13296. t['a100'] = 0x275E;
  13297. t['a101'] = 0x2761;
  13298. t['a102'] = 0x2762;
  13299. t['a103'] = 0x2763;
  13300. t['a104'] = 0x2764;
  13301. t['a106'] = 0x2765;
  13302. t['a107'] = 0x2766;
  13303. t['a108'] = 0x2767;
  13304. t['a112'] = 0x2663;
  13305. t['a111'] = 0x2666;
  13306. t['a110'] = 0x2665;
  13307. t['a109'] = 0x2660;
  13308. t['a120'] = 0x2460;
  13309. t['a121'] = 0x2461;
  13310. t['a122'] = 0x2462;
  13311. t['a123'] = 0x2463;
  13312. t['a124'] = 0x2464;
  13313. t['a125'] = 0x2465;
  13314. t['a126'] = 0x2466;
  13315. t['a127'] = 0x2467;
  13316. t['a128'] = 0x2468;
  13317. t['a129'] = 0x2469;
  13318. t['a130'] = 0x2776;
  13319. t['a131'] = 0x2777;
  13320. t['a132'] = 0x2778;
  13321. t['a133'] = 0x2779;
  13322. t['a134'] = 0x277A;
  13323. t['a135'] = 0x277B;
  13324. t['a136'] = 0x277C;
  13325. t['a137'] = 0x277D;
  13326. t['a138'] = 0x277E;
  13327. t['a139'] = 0x277F;
  13328. t['a140'] = 0x2780;
  13329. t['a141'] = 0x2781;
  13330. t['a142'] = 0x2782;
  13331. t['a143'] = 0x2783;
  13332. t['a144'] = 0x2784;
  13333. t['a145'] = 0x2785;
  13334. t['a146'] = 0x2786;
  13335. t['a147'] = 0x2787;
  13336. t['a148'] = 0x2788;
  13337. t['a149'] = 0x2789;
  13338. t['a150'] = 0x278A;
  13339. t['a151'] = 0x278B;
  13340. t['a152'] = 0x278C;
  13341. t['a153'] = 0x278D;
  13342. t['a154'] = 0x278E;
  13343. t['a155'] = 0x278F;
  13344. t['a156'] = 0x2790;
  13345. t['a157'] = 0x2791;
  13346. t['a158'] = 0x2792;
  13347. t['a159'] = 0x2793;
  13348. t['a160'] = 0x2794;
  13349. t['a161'] = 0x2192;
  13350. t['a163'] = 0x2194;
  13351. t['a164'] = 0x2195;
  13352. t['a196'] = 0x2798;
  13353. t['a165'] = 0x2799;
  13354. t['a192'] = 0x279A;
  13355. t['a166'] = 0x279B;
  13356. t['a167'] = 0x279C;
  13357. t['a168'] = 0x279D;
  13358. t['a169'] = 0x279E;
  13359. t['a170'] = 0x279F;
  13360. t['a171'] = 0x27A0;
  13361. t['a172'] = 0x27A1;
  13362. t['a173'] = 0x27A2;
  13363. t['a162'] = 0x27A3;
  13364. t['a174'] = 0x27A4;
  13365. t['a175'] = 0x27A5;
  13366. t['a176'] = 0x27A6;
  13367. t['a177'] = 0x27A7;
  13368. t['a178'] = 0x27A8;
  13369. t['a179'] = 0x27A9;
  13370. t['a193'] = 0x27AA;
  13371. t['a180'] = 0x27AB;
  13372. t['a199'] = 0x27AC;
  13373. t['a181'] = 0x27AD;
  13374. t['a200'] = 0x27AE;
  13375. t['a182'] = 0x27AF;
  13376. t['a201'] = 0x27B1;
  13377. t['a183'] = 0x27B2;
  13378. t['a184'] = 0x27B3;
  13379. t['a197'] = 0x27B4;
  13380. t['a185'] = 0x27B5;
  13381. t['a194'] = 0x27B6;
  13382. t['a198'] = 0x27B7;
  13383. t['a186'] = 0x27B8;
  13384. t['a195'] = 0x27B9;
  13385. t['a187'] = 0x27BA;
  13386. t['a188'] = 0x27BB;
  13387. t['a189'] = 0x27BC;
  13388. t['a190'] = 0x27BD;
  13389. t['a191'] = 0x27BE;
  13390. t['a89'] = 0x2768;
  13391. // 0xF8D7
  13392. t['a90'] = 0x2769;
  13393. // 0xF8D8
  13394. t['a93'] = 0x276A;
  13395. // 0xF8D9
  13396. t['a94'] = 0x276B;
  13397. // 0xF8DA
  13398. t['a91'] = 0x276C;
  13399. // 0xF8DB
  13400. t['a92'] = 0x276D;
  13401. // 0xF8DC
  13402. t['a205'] = 0x276E;
  13403. // 0xF8DD
  13404. t['a85'] = 0x276F;
  13405. // 0xF8DE
  13406. t['a206'] = 0x2770;
  13407. // 0xF8DF
  13408. t['a86'] = 0x2771;
  13409. // 0xF8E0
  13410. t['a87'] = 0x2772;
  13411. // 0xF8E1
  13412. t['a88'] = 0x2773;
  13413. // 0xF8E2
  13414. t['a95'] = 0x2774;
  13415. // 0xF8E3
  13416. t['a96'] = 0x2775;
  13417. // 0xF8E4
  13418. t['.notdef'] = 0x0000;
  13419. });
  13420. exports.getGlyphsUnicode = getGlyphsUnicode;
  13421. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13422. }));
  13423. (function (root, factory) {
  13424. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13425. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13426. var error = sharedUtil.error;
  13427. var log2 = sharedUtil.log2;
  13428. var readInt8 = sharedUtil.readInt8;
  13429. var readUint16 = sharedUtil.readUint16;
  13430. var readUint32 = sharedUtil.readUint32;
  13431. var shadow = sharedUtil.shadow;
  13432. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13433. var Jbig2Image = function Jbig2ImageClosure() {
  13434. // Utility data structures
  13435. function ContextCache() {
  13436. }
  13437. ContextCache.prototype = {
  13438. getContexts: function (id) {
  13439. if (id in this) {
  13440. return this[id];
  13441. }
  13442. return this[id] = new Int8Array(1 << 16);
  13443. }
  13444. };
  13445. function DecodingContext(data, start, end) {
  13446. this.data = data;
  13447. this.start = start;
  13448. this.end = end;
  13449. }
  13450. DecodingContext.prototype = {
  13451. get decoder() {
  13452. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13453. return shadow(this, 'decoder', decoder);
  13454. },
  13455. get contextCache() {
  13456. var cache = new ContextCache();
  13457. return shadow(this, 'contextCache', cache);
  13458. }
  13459. };
  13460. // Annex A. Arithmetic Integer Decoding Procedure
  13461. // A.2 Procedure for decoding values
  13462. function decodeInteger(contextCache, procedure, decoder) {
  13463. var contexts = contextCache.getContexts(procedure);
  13464. var prev = 1;
  13465. function readBits(length) {
  13466. var v = 0;
  13467. for (var i = 0; i < length; i++) {
  13468. var bit = decoder.readBit(contexts, prev);
  13469. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13470. v = v << 1 | bit;
  13471. }
  13472. return v >>> 0;
  13473. }
  13474. var sign = readBits(1);
  13475. var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
  13476. return sign === 0 ? value : value > 0 ? -value : null;
  13477. }
  13478. // A.3 The IAID decoding procedure
  13479. function decodeIAID(contextCache, decoder, codeLength) {
  13480. var contexts = contextCache.getContexts('IAID');
  13481. var prev = 1;
  13482. for (var i = 0; i < codeLength; i++) {
  13483. var bit = decoder.readBit(contexts, prev);
  13484. prev = prev << 1 | bit;
  13485. }
  13486. if (codeLength < 31) {
  13487. return prev & (1 << codeLength) - 1;
  13488. }
  13489. return prev & 0x7FFFFFFF;
  13490. }
  13491. // 7.3 Segment types
  13492. var SegmentTypes = [
  13493. 'SymbolDictionary',
  13494. null,
  13495. null,
  13496. null,
  13497. 'IntermediateTextRegion',
  13498. null,
  13499. 'ImmediateTextRegion',
  13500. 'ImmediateLosslessTextRegion',
  13501. null,
  13502. null,
  13503. null,
  13504. null,
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. 'patternDictionary',
  13510. null,
  13511. null,
  13512. null,
  13513. 'IntermediateHalftoneRegion',
  13514. null,
  13515. 'ImmediateHalftoneRegion',
  13516. 'ImmediateLosslessHalftoneRegion',
  13517. null,
  13518. null,
  13519. null,
  13520. null,
  13521. null,
  13522. null,
  13523. null,
  13524. null,
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. 'IntermediateGenericRegion',
  13530. null,
  13531. 'ImmediateGenericRegion',
  13532. 'ImmediateLosslessGenericRegion',
  13533. 'IntermediateGenericRefinementRegion',
  13534. null,
  13535. 'ImmediateGenericRefinementRegion',
  13536. 'ImmediateLosslessGenericRefinementRegion',
  13537. null,
  13538. null,
  13539. null,
  13540. null,
  13541. 'PageInformation',
  13542. 'EndOfPage',
  13543. 'EndOfStripe',
  13544. 'EndOfFile',
  13545. 'Profiles',
  13546. 'Tables',
  13547. null,
  13548. null,
  13549. null,
  13550. null,
  13551. null,
  13552. null,
  13553. null,
  13554. null,
  13555. 'Extension'
  13556. ];
  13557. var CodingTemplates = [
  13558. [
  13559. {
  13560. x: -1,
  13561. y: -2
  13562. },
  13563. {
  13564. x: 0,
  13565. y: -2
  13566. },
  13567. {
  13568. x: 1,
  13569. y: -2
  13570. },
  13571. {
  13572. x: -2,
  13573. y: -1
  13574. },
  13575. {
  13576. x: -1,
  13577. y: -1
  13578. },
  13579. {
  13580. x: 0,
  13581. y: -1
  13582. },
  13583. {
  13584. x: 1,
  13585. y: -1
  13586. },
  13587. {
  13588. x: 2,
  13589. y: -1
  13590. },
  13591. {
  13592. x: -4,
  13593. y: 0
  13594. },
  13595. {
  13596. x: -3,
  13597. y: 0
  13598. },
  13599. {
  13600. x: -2,
  13601. y: 0
  13602. },
  13603. {
  13604. x: -1,
  13605. y: 0
  13606. }
  13607. ],
  13608. [
  13609. {
  13610. x: -1,
  13611. y: -2
  13612. },
  13613. {
  13614. x: 0,
  13615. y: -2
  13616. },
  13617. {
  13618. x: 1,
  13619. y: -2
  13620. },
  13621. {
  13622. x: 2,
  13623. y: -2
  13624. },
  13625. {
  13626. x: -2,
  13627. y: -1
  13628. },
  13629. {
  13630. x: -1,
  13631. y: -1
  13632. },
  13633. {
  13634. x: 0,
  13635. y: -1
  13636. },
  13637. {
  13638. x: 1,
  13639. y: -1
  13640. },
  13641. {
  13642. x: 2,
  13643. y: -1
  13644. },
  13645. {
  13646. x: -3,
  13647. y: 0
  13648. },
  13649. {
  13650. x: -2,
  13651. y: 0
  13652. },
  13653. {
  13654. x: -1,
  13655. y: 0
  13656. }
  13657. ],
  13658. [
  13659. {
  13660. x: -1,
  13661. y: -2
  13662. },
  13663. {
  13664. x: 0,
  13665. y: -2
  13666. },
  13667. {
  13668. x: 1,
  13669. y: -2
  13670. },
  13671. {
  13672. x: -2,
  13673. y: -1
  13674. },
  13675. {
  13676. x: -1,
  13677. y: -1
  13678. },
  13679. {
  13680. x: 0,
  13681. y: -1
  13682. },
  13683. {
  13684. x: 1,
  13685. y: -1
  13686. },
  13687. {
  13688. x: -2,
  13689. y: 0
  13690. },
  13691. {
  13692. x: -1,
  13693. y: 0
  13694. }
  13695. ],
  13696. [
  13697. {
  13698. x: -3,
  13699. y: -1
  13700. },
  13701. {
  13702. x: -2,
  13703. y: -1
  13704. },
  13705. {
  13706. x: -1,
  13707. y: -1
  13708. },
  13709. {
  13710. x: 0,
  13711. y: -1
  13712. },
  13713. {
  13714. x: 1,
  13715. y: -1
  13716. },
  13717. {
  13718. x: -4,
  13719. y: 0
  13720. },
  13721. {
  13722. x: -3,
  13723. y: 0
  13724. },
  13725. {
  13726. x: -2,
  13727. y: 0
  13728. },
  13729. {
  13730. x: -1,
  13731. y: 0
  13732. }
  13733. ]
  13734. ];
  13735. var RefinementTemplates = [
  13736. {
  13737. coding: [
  13738. {
  13739. x: 0,
  13740. y: -1
  13741. },
  13742. {
  13743. x: 1,
  13744. y: -1
  13745. },
  13746. {
  13747. x: -1,
  13748. y: 0
  13749. }
  13750. ],
  13751. reference: [
  13752. {
  13753. x: 0,
  13754. y: -1
  13755. },
  13756. {
  13757. x: 1,
  13758. y: -1
  13759. },
  13760. {
  13761. x: -1,
  13762. y: 0
  13763. },
  13764. {
  13765. x: 0,
  13766. y: 0
  13767. },
  13768. {
  13769. x: 1,
  13770. y: 0
  13771. },
  13772. {
  13773. x: -1,
  13774. y: 1
  13775. },
  13776. {
  13777. x: 0,
  13778. y: 1
  13779. },
  13780. {
  13781. x: 1,
  13782. y: 1
  13783. }
  13784. ]
  13785. },
  13786. {
  13787. coding: [
  13788. {
  13789. x: -1,
  13790. y: -1
  13791. },
  13792. {
  13793. x: 0,
  13794. y: -1
  13795. },
  13796. {
  13797. x: 1,
  13798. y: -1
  13799. },
  13800. {
  13801. x: -1,
  13802. y: 0
  13803. }
  13804. ],
  13805. reference: [
  13806. {
  13807. x: 0,
  13808. y: -1
  13809. },
  13810. {
  13811. x: -1,
  13812. y: 0
  13813. },
  13814. {
  13815. x: 0,
  13816. y: 0
  13817. },
  13818. {
  13819. x: 1,
  13820. y: 0
  13821. },
  13822. {
  13823. x: 0,
  13824. y: 1
  13825. },
  13826. {
  13827. x: 1,
  13828. y: 1
  13829. }
  13830. ]
  13831. }
  13832. ];
  13833. // See 6.2.5.7 Decoding the bitmap.
  13834. var ReusedContexts = [
  13835. 0x9B25,
  13836. // 10011 0110010 0101
  13837. 0x0795,
  13838. // 0011 110010 101
  13839. 0x00E5,
  13840. // 001 11001 01
  13841. 0x0195
  13842. ];
  13843. // 011001 0101
  13844. var RefinementReusedContexts = [
  13845. 0x0020,
  13846. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13847. 0x0008
  13848. ];
  13849. // '0000' + '001000'
  13850. function decodeBitmapTemplate0(width, height, decodingContext) {
  13851. var decoder = decodingContext.decoder;
  13852. var contexts = decodingContext.contextCache.getContexts('GB');
  13853. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13854. // ...ooooo....
  13855. // ..ooooooo... Context template for current pixel (X)
  13856. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13857. var OLD_PIXEL_MASK = 0x7BF7;
  13858. // 01111 0111111 0111
  13859. for (i = 0; i < height; i++) {
  13860. row = bitmap[i] = new Uint8Array(width);
  13861. row1 = i < 1 ? row : bitmap[i - 1];
  13862. row2 = i < 2 ? row : bitmap[i - 2];
  13863. // At the beginning of each row:
  13864. // Fill contextLabel with pixels that are above/right of (X)
  13865. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13866. for (j = 0; j < width; j++) {
  13867. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13868. // At each pixel: Clear contextLabel pixels that are shifted
  13869. // out of the context, then add new ones.
  13870. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13871. }
  13872. }
  13873. return bitmap;
  13874. }
  13875. // 6.2 Generic Region Decoding Procedure
  13876. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13877. if (mmr) {
  13878. error('JBIG2 error: MMR encoding is not supported');
  13879. }
  13880. // Use optimized version for the most common case
  13881. if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  13882. return decodeBitmapTemplate0(width, height, decodingContext);
  13883. }
  13884. var useskip = !!skip;
  13885. var template = CodingTemplates[templateIndex].concat(at);
  13886. // Sorting is non-standard, and it is not required. But sorting increases
  13887. // the number of template bits that can be reused from the previous
  13888. // contextLabel in the main loop.
  13889. template.sort(function (a, b) {
  13890. return a.y - b.y || a.x - b.x;
  13891. });
  13892. var templateLength = template.length;
  13893. var templateX = new Int8Array(templateLength);
  13894. var templateY = new Int8Array(templateLength);
  13895. var changingTemplateEntries = [];
  13896. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13897. var c, k;
  13898. for (k = 0; k < templateLength; k++) {
  13899. templateX[k] = template[k].x;
  13900. templateY[k] = template[k].y;
  13901. minX = Math.min(minX, template[k].x);
  13902. maxX = Math.max(maxX, template[k].x);
  13903. minY = Math.min(minY, template[k].y);
  13904. // Check if the template pixel appears in two consecutive context labels,
  13905. // so it can be reused. Otherwise, we add it to the list of changing
  13906. // template entries.
  13907. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13908. reuseMask |= 1 << templateLength - 1 - k;
  13909. } else {
  13910. changingTemplateEntries.push(k);
  13911. }
  13912. }
  13913. var changingEntriesLength = changingTemplateEntries.length;
  13914. var changingTemplateX = new Int8Array(changingEntriesLength);
  13915. var changingTemplateY = new Int8Array(changingEntriesLength);
  13916. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13917. for (c = 0; c < changingEntriesLength; c++) {
  13918. k = changingTemplateEntries[c];
  13919. changingTemplateX[c] = template[k].x;
  13920. changingTemplateY[c] = template[k].y;
  13921. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13922. }
  13923. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13924. var sbb_left = -minX;
  13925. var sbb_top = -minY;
  13926. var sbb_right = width - maxX;
  13927. var pseudoPixelContext = ReusedContexts[templateIndex];
  13928. var row = new Uint8Array(width);
  13929. var bitmap = [];
  13930. var decoder = decodingContext.decoder;
  13931. var contexts = decodingContext.contextCache.getContexts('GB');
  13932. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13933. for (var i = 0; i < height; i++) {
  13934. if (prediction) {
  13935. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13936. ltp ^= sltp;
  13937. if (ltp) {
  13938. bitmap.push(row);
  13939. // duplicate previous row
  13940. continue;
  13941. }
  13942. }
  13943. row = new Uint8Array(row);
  13944. bitmap.push(row);
  13945. for (j = 0; j < width; j++) {
  13946. if (useskip && skip[i][j]) {
  13947. row[j] = 0;
  13948. continue;
  13949. }
  13950. // Are we in the middle of a scanline, so we can reuse contextLabel
  13951. // bits?
  13952. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13953. // If yes, we can just shift the bits that are reusable and only
  13954. // fetch the remaining ones.
  13955. contextLabel = contextLabel << 1 & reuseMask;
  13956. for (k = 0; k < changingEntriesLength; k++) {
  13957. i0 = i + changingTemplateY[k];
  13958. j0 = j + changingTemplateX[k];
  13959. bit = bitmap[i0][j0];
  13960. if (bit) {
  13961. bit = changingTemplateBit[k];
  13962. contextLabel |= bit;
  13963. }
  13964. }
  13965. } else {
  13966. // compute the contextLabel from scratch
  13967. contextLabel = 0;
  13968. shift = templateLength - 1;
  13969. for (k = 0; k < templateLength; k++, shift--) {
  13970. j0 = j + templateX[k];
  13971. if (j0 >= 0 && j0 < width) {
  13972. i0 = i + templateY[k];
  13973. if (i0 >= 0) {
  13974. bit = bitmap[i0][j0];
  13975. if (bit) {
  13976. contextLabel |= bit << shift;
  13977. }
  13978. }
  13979. }
  13980. }
  13981. }
  13982. var pixel = decoder.readBit(contexts, contextLabel);
  13983. row[j] = pixel;
  13984. }
  13985. }
  13986. return bitmap;
  13987. }
  13988. // 6.3.2 Generic Refinement Region Decoding Procedure
  13989. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13990. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13991. if (templateIndex === 0) {
  13992. codingTemplate = codingTemplate.concat([at[0]]);
  13993. }
  13994. var codingTemplateLength = codingTemplate.length;
  13995. var codingTemplateX = new Int32Array(codingTemplateLength);
  13996. var codingTemplateY = new Int32Array(codingTemplateLength);
  13997. var k;
  13998. for (k = 0; k < codingTemplateLength; k++) {
  13999. codingTemplateX[k] = codingTemplate[k].x;
  14000. codingTemplateY[k] = codingTemplate[k].y;
  14001. }
  14002. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  14003. if (templateIndex === 0) {
  14004. referenceTemplate = referenceTemplate.concat([at[1]]);
  14005. }
  14006. var referenceTemplateLength = referenceTemplate.length;
  14007. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  14008. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  14009. for (k = 0; k < referenceTemplateLength; k++) {
  14010. referenceTemplateX[k] = referenceTemplate[k].x;
  14011. referenceTemplateY[k] = referenceTemplate[k].y;
  14012. }
  14013. var referenceWidth = referenceBitmap[0].length;
  14014. var referenceHeight = referenceBitmap.length;
  14015. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14016. var bitmap = [];
  14017. var decoder = decodingContext.decoder;
  14018. var contexts = decodingContext.contextCache.getContexts('GR');
  14019. var ltp = 0;
  14020. for (var i = 0; i < height; i++) {
  14021. if (prediction) {
  14022. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14023. ltp ^= sltp;
  14024. if (ltp) {
  14025. error('JBIG2 error: prediction is not supported');
  14026. }
  14027. }
  14028. var row = new Uint8Array(width);
  14029. bitmap.push(row);
  14030. for (var j = 0; j < width; j++) {
  14031. var i0, j0;
  14032. var contextLabel = 0;
  14033. for (k = 0; k < codingTemplateLength; k++) {
  14034. i0 = i + codingTemplateY[k];
  14035. j0 = j + codingTemplateX[k];
  14036. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14037. contextLabel <<= 1;
  14038. } else
  14039. // out of bound pixel
  14040. {
  14041. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14042. }
  14043. }
  14044. for (k = 0; k < referenceTemplateLength; k++) {
  14045. i0 = i + referenceTemplateY[k] + offsetY;
  14046. j0 = j + referenceTemplateX[k] + offsetX;
  14047. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14048. contextLabel <<= 1;
  14049. } else
  14050. // out of bound pixel
  14051. {
  14052. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14053. }
  14054. }
  14055. var pixel = decoder.readBit(contexts, contextLabel);
  14056. row[j] = pixel;
  14057. }
  14058. }
  14059. return bitmap;
  14060. }
  14061. // 6.5.5 Decoding the symbol dictionary
  14062. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14063. if (huffman) {
  14064. error('JBIG2 error: huffman is not supported');
  14065. }
  14066. var newSymbols = [];
  14067. var currentHeight = 0;
  14068. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14069. var decoder = decodingContext.decoder;
  14070. var contextCache = decodingContext.contextCache;
  14071. while (newSymbols.length < numberOfNewSymbols) {
  14072. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14073. // 6.5.6
  14074. currentHeight += deltaHeight;
  14075. var currentWidth = 0;
  14076. var totalWidth = 0;
  14077. while (true) {
  14078. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14079. // 6.5.7
  14080. if (deltaWidth === null) {
  14081. break;
  14082. }
  14083. // OOB
  14084. currentWidth += deltaWidth;
  14085. totalWidth += currentWidth;
  14086. var bitmap;
  14087. if (refinement) {
  14088. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14089. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14090. if (numberOfInstances > 1) {
  14091. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14092. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14093. 0, //ds offset
  14094. 1, //top left 7.4.3.1.1
  14095. 0, //OR operator
  14096. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14097. } else {
  14098. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14099. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14100. // 6.4.11.3
  14101. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14102. // 6.4.11.4
  14103. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14104. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14105. }
  14106. } else {
  14107. // 6.5.8.1 Direct-coded symbol bitmap
  14108. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14109. }
  14110. newSymbols.push(bitmap);
  14111. }
  14112. }
  14113. // 6.5.10 Exported symbols
  14114. var exportedSymbols = [];
  14115. var flags = [], currentFlag = false;
  14116. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14117. while (flags.length < totalSymbolsLength) {
  14118. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14119. while (runLength--) {
  14120. flags.push(currentFlag);
  14121. }
  14122. currentFlag = !currentFlag;
  14123. }
  14124. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14125. if (flags[i]) {
  14126. exportedSymbols.push(symbols[i]);
  14127. }
  14128. }
  14129. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14130. if (flags[i]) {
  14131. exportedSymbols.push(newSymbols[j]);
  14132. }
  14133. }
  14134. return exportedSymbols;
  14135. }
  14136. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14137. if (huffman) {
  14138. error('JBIG2 error: huffman is not supported');
  14139. }
  14140. // Prepare bitmap
  14141. var bitmap = [];
  14142. var i, row;
  14143. for (i = 0; i < height; i++) {
  14144. row = new Uint8Array(width);
  14145. if (defaultPixelValue) {
  14146. for (var j = 0; j < width; j++) {
  14147. row[j] = defaultPixelValue;
  14148. }
  14149. }
  14150. bitmap.push(row);
  14151. }
  14152. var decoder = decodingContext.decoder;
  14153. var contextCache = decodingContext.contextCache;
  14154. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14155. // 6.4.6
  14156. var firstS = 0;
  14157. i = 0;
  14158. while (i < numberOfSymbolInstances) {
  14159. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14160. // 6.4.6
  14161. stripT += deltaT;
  14162. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14163. // 6.4.7
  14164. firstS += deltaFirstS;
  14165. var currentS = firstS;
  14166. do {
  14167. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14168. // 6.4.9
  14169. var t = stripSize * stripT + currentT;
  14170. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14171. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14172. var symbolBitmap = inputSymbols[symbolId];
  14173. var symbolWidth = symbolBitmap[0].length;
  14174. var symbolHeight = symbolBitmap.length;
  14175. if (applyRefinement) {
  14176. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14177. // 6.4.11.1
  14178. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14179. // 6.4.11.2
  14180. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14181. // 6.4.11.3
  14182. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14183. // 6.4.11.4
  14184. symbolWidth += rdw;
  14185. symbolHeight += rdh;
  14186. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14187. }
  14188. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14189. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14190. var s2, t2, symbolRow;
  14191. if (transposed) {
  14192. // Place Symbol Bitmap from T1,S1
  14193. for (s2 = 0; s2 < symbolHeight; s2++) {
  14194. row = bitmap[offsetS + s2];
  14195. if (!row) {
  14196. continue;
  14197. }
  14198. symbolRow = symbolBitmap[s2];
  14199. // To ignore Parts of Symbol bitmap which goes
  14200. // outside bitmap region
  14201. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14202. switch (combinationOperator) {
  14203. case 0:
  14204. // OR
  14205. for (t2 = 0; t2 < maxWidth; t2++) {
  14206. row[offsetT + t2] |= symbolRow[t2];
  14207. }
  14208. break;
  14209. case 2:
  14210. // XOR
  14211. for (t2 = 0; t2 < maxWidth; t2++) {
  14212. row[offsetT + t2] ^= symbolRow[t2];
  14213. }
  14214. break;
  14215. default:
  14216. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14217. }
  14218. }
  14219. currentS += symbolHeight - 1;
  14220. } else {
  14221. for (t2 = 0; t2 < symbolHeight; t2++) {
  14222. row = bitmap[offsetT + t2];
  14223. if (!row) {
  14224. continue;
  14225. }
  14226. symbolRow = symbolBitmap[t2];
  14227. switch (combinationOperator) {
  14228. case 0:
  14229. // OR
  14230. for (s2 = 0; s2 < symbolWidth; s2++) {
  14231. row[offsetS + s2] |= symbolRow[s2];
  14232. }
  14233. break;
  14234. case 2:
  14235. // XOR
  14236. for (s2 = 0; s2 < symbolWidth; s2++) {
  14237. row[offsetS + s2] ^= symbolRow[s2];
  14238. }
  14239. break;
  14240. default:
  14241. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14242. }
  14243. }
  14244. currentS += symbolWidth - 1;
  14245. }
  14246. i++;
  14247. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14248. // 6.4.8
  14249. if (deltaS === null) {
  14250. break;
  14251. }
  14252. // OOB
  14253. currentS += deltaS + dsOffset;
  14254. } while (true);
  14255. }
  14256. return bitmap;
  14257. }
  14258. function readSegmentHeader(data, start) {
  14259. var segmentHeader = {};
  14260. segmentHeader.number = readUint32(data, start);
  14261. var flags = data[start + 4];
  14262. var segmentType = flags & 0x3F;
  14263. if (!SegmentTypes[segmentType]) {
  14264. error('JBIG2 error: invalid segment type: ' + segmentType);
  14265. }
  14266. segmentHeader.type = segmentType;
  14267. segmentHeader.typeName = SegmentTypes[segmentType];
  14268. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14269. var pageAssociationFieldSize = !!(flags & 0x40);
  14270. var referredFlags = data[start + 5];
  14271. var referredToCount = referredFlags >> 5 & 7;
  14272. var retainBits = [referredFlags & 31];
  14273. var position = start + 6;
  14274. if (referredFlags === 7) {
  14275. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14276. position += 3;
  14277. var bytes = referredToCount + 7 >> 3;
  14278. retainBits[0] = data[position++];
  14279. while (--bytes > 0) {
  14280. retainBits.push(data[position++]);
  14281. }
  14282. } else if (referredFlags === 5 || referredFlags === 6) {
  14283. error('JBIG2 error: invalid referred-to flags');
  14284. }
  14285. segmentHeader.retainBits = retainBits;
  14286. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14287. var referredTo = [];
  14288. var i, ii;
  14289. for (i = 0; i < referredToCount; i++) {
  14290. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14291. referredTo.push(number);
  14292. position += referredToSegmentNumberSize;
  14293. }
  14294. segmentHeader.referredTo = referredTo;
  14295. if (!pageAssociationFieldSize) {
  14296. segmentHeader.pageAssociation = data[position++];
  14297. } else {
  14298. segmentHeader.pageAssociation = readUint32(data, position);
  14299. position += 4;
  14300. }
  14301. segmentHeader.length = readUint32(data, position);
  14302. position += 4;
  14303. if (segmentHeader.length === 0xFFFFFFFF) {
  14304. // 7.2.7 Segment data length, unknown segment length
  14305. if (segmentType === 38) {
  14306. // ImmediateGenericRegion
  14307. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14308. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14309. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14310. // searching for the segment end
  14311. var searchPatternLength = 6;
  14312. var searchPattern = new Uint8Array(searchPatternLength);
  14313. if (!genericRegionMmr) {
  14314. searchPattern[0] = 0xFF;
  14315. searchPattern[1] = 0xAC;
  14316. }
  14317. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14318. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14319. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14320. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14321. for (i = position, ii = data.length; i < ii; i++) {
  14322. var j = 0;
  14323. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14324. j++;
  14325. }
  14326. if (j === searchPatternLength) {
  14327. segmentHeader.length = i + searchPatternLength;
  14328. break;
  14329. }
  14330. }
  14331. if (segmentHeader.length === 0xFFFFFFFF) {
  14332. error('JBIG2 error: segment end was not found');
  14333. }
  14334. } else {
  14335. error('JBIG2 error: invalid unknown segment length');
  14336. }
  14337. }
  14338. segmentHeader.headerEnd = position;
  14339. return segmentHeader;
  14340. }
  14341. function readSegments(header, data, start, end) {
  14342. var segments = [];
  14343. var position = start;
  14344. while (position < end) {
  14345. var segmentHeader = readSegmentHeader(data, position);
  14346. position = segmentHeader.headerEnd;
  14347. var segment = {
  14348. header: segmentHeader,
  14349. data: data
  14350. };
  14351. if (!header.randomAccess) {
  14352. segment.start = position;
  14353. position += segmentHeader.length;
  14354. segment.end = position;
  14355. }
  14356. segments.push(segment);
  14357. if (segmentHeader.type === 51) {
  14358. break;
  14359. }
  14360. }
  14361. // end of file is found
  14362. if (header.randomAccess) {
  14363. for (var i = 0, ii = segments.length; i < ii; i++) {
  14364. segments[i].start = position;
  14365. position += segments[i].header.length;
  14366. segments[i].end = position;
  14367. }
  14368. }
  14369. return segments;
  14370. }
  14371. // 7.4.1 Region segment information field
  14372. function readRegionSegmentInformation(data, start) {
  14373. return {
  14374. width: readUint32(data, start),
  14375. height: readUint32(data, start + 4),
  14376. x: readUint32(data, start + 8),
  14377. y: readUint32(data, start + 12),
  14378. combinationOperator: data[start + 16] & 7
  14379. };
  14380. }
  14381. var RegionSegmentInformationFieldLength = 17;
  14382. function processSegment(segment, visitor) {
  14383. var header = segment.header;
  14384. var data = segment.data, position = segment.start, end = segment.end;
  14385. var args, at, i, atLength;
  14386. switch (header.type) {
  14387. case 0:
  14388. // SymbolDictionary
  14389. // 7.4.2 Symbol dictionary segment syntax
  14390. var dictionary = {};
  14391. var dictionaryFlags = readUint16(data, position);
  14392. // 7.4.2.1.1
  14393. dictionary.huffman = !!(dictionaryFlags & 1);
  14394. dictionary.refinement = !!(dictionaryFlags & 2);
  14395. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14396. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14397. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14398. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14399. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14400. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14401. dictionary.template = dictionaryFlags >> 10 & 3;
  14402. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14403. position += 2;
  14404. if (!dictionary.huffman) {
  14405. atLength = dictionary.template === 0 ? 4 : 1;
  14406. at = [];
  14407. for (i = 0; i < atLength; i++) {
  14408. at.push({
  14409. x: readInt8(data, position),
  14410. y: readInt8(data, position + 1)
  14411. });
  14412. position += 2;
  14413. }
  14414. dictionary.at = at;
  14415. }
  14416. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14417. at = [];
  14418. for (i = 0; i < 2; i++) {
  14419. at.push({
  14420. x: readInt8(data, position),
  14421. y: readInt8(data, position + 1)
  14422. });
  14423. position += 2;
  14424. }
  14425. dictionary.refinementAt = at;
  14426. }
  14427. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14428. position += 4;
  14429. dictionary.numberOfNewSymbols = readUint32(data, position);
  14430. position += 4;
  14431. args = [
  14432. dictionary,
  14433. header.number,
  14434. header.referredTo,
  14435. data,
  14436. position,
  14437. end
  14438. ];
  14439. break;
  14440. case 6:
  14441. // ImmediateTextRegion
  14442. case 7:
  14443. // ImmediateLosslessTextRegion
  14444. var textRegion = {};
  14445. textRegion.info = readRegionSegmentInformation(data, position);
  14446. position += RegionSegmentInformationFieldLength;
  14447. var textRegionSegmentFlags = readUint16(data, position);
  14448. position += 2;
  14449. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14450. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14451. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14452. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14453. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14454. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14455. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14456. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14457. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14458. if (textRegion.huffman) {
  14459. var textRegionHuffmanFlags = readUint16(data, position);
  14460. position += 2;
  14461. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14462. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14463. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14464. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14465. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14466. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14467. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14468. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14469. }
  14470. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14471. at = [];
  14472. for (i = 0; i < 2; i++) {
  14473. at.push({
  14474. x: readInt8(data, position),
  14475. y: readInt8(data, position + 1)
  14476. });
  14477. position += 2;
  14478. }
  14479. textRegion.refinementAt = at;
  14480. }
  14481. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14482. position += 4;
  14483. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14484. if (textRegion.huffman) {
  14485. error('JBIG2 error: huffman is not supported');
  14486. }
  14487. args = [
  14488. textRegion,
  14489. header.referredTo,
  14490. data,
  14491. position,
  14492. end
  14493. ];
  14494. break;
  14495. case 38:
  14496. // ImmediateGenericRegion
  14497. case 39:
  14498. // ImmediateLosslessGenericRegion
  14499. var genericRegion = {};
  14500. genericRegion.info = readRegionSegmentInformation(data, position);
  14501. position += RegionSegmentInformationFieldLength;
  14502. var genericRegionSegmentFlags = data[position++];
  14503. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14504. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14505. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14506. if (!genericRegion.mmr) {
  14507. atLength = genericRegion.template === 0 ? 4 : 1;
  14508. at = [];
  14509. for (i = 0; i < atLength; i++) {
  14510. at.push({
  14511. x: readInt8(data, position),
  14512. y: readInt8(data, position + 1)
  14513. });
  14514. position += 2;
  14515. }
  14516. genericRegion.at = at;
  14517. }
  14518. args = [
  14519. genericRegion,
  14520. data,
  14521. position,
  14522. end
  14523. ];
  14524. break;
  14525. case 48:
  14526. // PageInformation
  14527. var pageInfo = {
  14528. width: readUint32(data, position),
  14529. height: readUint32(data, position + 4),
  14530. resolutionX: readUint32(data, position + 8),
  14531. resolutionY: readUint32(data, position + 12)
  14532. };
  14533. if (pageInfo.height === 0xFFFFFFFF) {
  14534. delete pageInfo.height;
  14535. }
  14536. var pageSegmentFlags = data[position + 16];
  14537. var pageStripingInformation = readUint16(data, position + 17);
  14538. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14539. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14540. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14541. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14542. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14543. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14544. args = [pageInfo];
  14545. break;
  14546. case 49:
  14547. // EndOfPage
  14548. break;
  14549. case 50:
  14550. // EndOfStripe
  14551. break;
  14552. case 51:
  14553. // EndOfFile
  14554. break;
  14555. case 62:
  14556. // 7.4.15 defines 2 extension types which
  14557. // are comments and can be ignored.
  14558. break;
  14559. default:
  14560. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14561. }
  14562. var callbackName = 'on' + header.typeName;
  14563. if (callbackName in visitor) {
  14564. visitor[callbackName].apply(visitor, args);
  14565. }
  14566. }
  14567. function processSegments(segments, visitor) {
  14568. for (var i = 0, ii = segments.length; i < ii; i++) {
  14569. processSegment(segments[i], visitor);
  14570. }
  14571. }
  14572. function parseJbig2(data, start, end) {
  14573. var position = start;
  14574. if (data[position] !== 0x97 || data[position + 1] !== 0x4A || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0D || data[position + 5] !== 0x0A || data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  14575. error('JBIG2 error: invalid header');
  14576. }
  14577. var header = {};
  14578. position += 8;
  14579. var flags = data[position++];
  14580. header.randomAccess = !(flags & 1);
  14581. if (!(flags & 2)) {
  14582. header.numberOfPages = readUint32(data, position);
  14583. position += 4;
  14584. }
  14585. var segments = readSegments(header, data, position, end);
  14586. error('Not implemented');
  14587. }
  14588. // processSegments(segments, new SimpleSegmentVisitor());
  14589. function parseJbig2Chunks(chunks) {
  14590. var visitor = new SimpleSegmentVisitor();
  14591. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14592. var chunk = chunks[i];
  14593. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14594. processSegments(segments, visitor);
  14595. }
  14596. return visitor.buffer;
  14597. }
  14598. function SimpleSegmentVisitor() {
  14599. }
  14600. SimpleSegmentVisitor.prototype = {
  14601. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14602. this.currentPageInfo = info;
  14603. var rowSize = info.width + 7 >> 3;
  14604. var buffer = new Uint8Array(rowSize * info.height);
  14605. // The contents of ArrayBuffers are initialized to 0.
  14606. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14607. if (info.defaultPixelValue) {
  14608. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14609. buffer[i] = 0xFF;
  14610. }
  14611. }
  14612. this.buffer = buffer;
  14613. },
  14614. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14615. var pageInfo = this.currentPageInfo;
  14616. var width = regionInfo.width, height = regionInfo.height;
  14617. var rowSize = pageInfo.width + 7 >> 3;
  14618. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14619. var buffer = this.buffer;
  14620. var mask0 = 128 >> (regionInfo.x & 7);
  14621. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14622. var i, j, mask, offset;
  14623. switch (combinationOperator) {
  14624. case 0:
  14625. // OR
  14626. for (i = 0; i < height; i++) {
  14627. mask = mask0;
  14628. offset = offset0;
  14629. for (j = 0; j < width; j++) {
  14630. if (bitmap[i][j]) {
  14631. buffer[offset] |= mask;
  14632. }
  14633. mask >>= 1;
  14634. if (!mask) {
  14635. mask = 128;
  14636. offset++;
  14637. }
  14638. }
  14639. offset0 += rowSize;
  14640. }
  14641. break;
  14642. case 2:
  14643. // XOR
  14644. for (i = 0; i < height; i++) {
  14645. mask = mask0;
  14646. offset = offset0;
  14647. for (j = 0; j < width; j++) {
  14648. if (bitmap[i][j]) {
  14649. buffer[offset] ^= mask;
  14650. }
  14651. mask >>= 1;
  14652. if (!mask) {
  14653. mask = 128;
  14654. offset++;
  14655. }
  14656. }
  14657. offset0 += rowSize;
  14658. }
  14659. break;
  14660. default:
  14661. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14662. }
  14663. },
  14664. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14665. var regionInfo = region.info;
  14666. var decodingContext = new DecodingContext(data, start, end);
  14667. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14668. this.drawBitmap(regionInfo, bitmap);
  14669. },
  14670. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14671. this.onImmediateGenericRegion.apply(this, arguments);
  14672. },
  14673. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14674. var huffmanTables;
  14675. if (dictionary.huffman) {
  14676. error('JBIG2 error: huffman is not supported');
  14677. }
  14678. // Combines exported symbols from all referred segments
  14679. var symbols = this.symbols;
  14680. if (!symbols) {
  14681. this.symbols = symbols = {};
  14682. }
  14683. var inputSymbols = [];
  14684. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14685. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14686. }
  14687. var decodingContext = new DecodingContext(data, start, end);
  14688. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14689. },
  14690. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14691. var regionInfo = region.info;
  14692. var huffmanTables;
  14693. // Combines exported symbols from all referred segments
  14694. var symbols = this.symbols;
  14695. var inputSymbols = [];
  14696. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14697. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14698. }
  14699. var symbolCodeLength = log2(inputSymbols.length);
  14700. var decodingContext = new DecodingContext(data, start, end);
  14701. var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext);
  14702. this.drawBitmap(regionInfo, bitmap);
  14703. },
  14704. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14705. this.onImmediateTextRegion.apply(this, arguments);
  14706. }
  14707. };
  14708. function Jbig2Image() {
  14709. }
  14710. Jbig2Image.prototype = {
  14711. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14712. return parseJbig2Chunks(chunks);
  14713. }
  14714. };
  14715. return Jbig2Image;
  14716. }();
  14717. exports.Jbig2Image = Jbig2Image;
  14718. }));
  14719. (function (root, factory) {
  14720. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14721. }(this, function (exports, sharedUtil) {
  14722. var error = sharedUtil.error;
  14723. /**
  14724. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14725. * The original version was created by GitHub user notmasteryet.
  14726. *
  14727. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14728. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14729. * - The JFIF specification can be found in the JPEG File Interchange Format
  14730. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14731. * - The Adobe Application-Specific JPEG markers in the
  14732. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14733. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14734. */
  14735. var JpegImage = function JpegImageClosure() {
  14736. var dctZigZag = new Uint8Array([
  14737. 0,
  14738. 1,
  14739. 8,
  14740. 16,
  14741. 9,
  14742. 2,
  14743. 3,
  14744. 10,
  14745. 17,
  14746. 24,
  14747. 32,
  14748. 25,
  14749. 18,
  14750. 11,
  14751. 4,
  14752. 5,
  14753. 12,
  14754. 19,
  14755. 26,
  14756. 33,
  14757. 40,
  14758. 48,
  14759. 41,
  14760. 34,
  14761. 27,
  14762. 20,
  14763. 13,
  14764. 6,
  14765. 7,
  14766. 14,
  14767. 21,
  14768. 28,
  14769. 35,
  14770. 42,
  14771. 49,
  14772. 56,
  14773. 57,
  14774. 50,
  14775. 43,
  14776. 36,
  14777. 29,
  14778. 22,
  14779. 15,
  14780. 23,
  14781. 30,
  14782. 37,
  14783. 44,
  14784. 51,
  14785. 58,
  14786. 59,
  14787. 52,
  14788. 45,
  14789. 38,
  14790. 31,
  14791. 39,
  14792. 46,
  14793. 53,
  14794. 60,
  14795. 61,
  14796. 54,
  14797. 47,
  14798. 55,
  14799. 62,
  14800. 63
  14801. ]);
  14802. var dctCos1 = 4017;
  14803. // cos(pi/16)
  14804. var dctSin1 = 799;
  14805. // sin(pi/16)
  14806. var dctCos3 = 3406;
  14807. // cos(3*pi/16)
  14808. var dctSin3 = 2276;
  14809. // sin(3*pi/16)
  14810. var dctCos6 = 1567;
  14811. // cos(6*pi/16)
  14812. var dctSin6 = 3784;
  14813. // sin(6*pi/16)
  14814. var dctSqrt2 = 5793;
  14815. // sqrt(2)
  14816. var dctSqrt1d2 = 2896;
  14817. // sqrt(2) / 2
  14818. function JpegImage() {
  14819. this.decodeTransform = null;
  14820. this.colorTransform = -1;
  14821. }
  14822. function buildHuffmanTable(codeLengths, values) {
  14823. var k = 0, code = [], i, j, length = 16;
  14824. while (length > 0 && !codeLengths[length - 1]) {
  14825. length--;
  14826. }
  14827. code.push({
  14828. children: [],
  14829. index: 0
  14830. });
  14831. var p = code[0], q;
  14832. for (i = 0; i < length; i++) {
  14833. for (j = 0; j < codeLengths[i]; j++) {
  14834. p = code.pop();
  14835. p.children[p.index] = values[k];
  14836. while (p.index > 0) {
  14837. p = code.pop();
  14838. }
  14839. p.index++;
  14840. code.push(p);
  14841. while (code.length <= i) {
  14842. code.push(q = {
  14843. children: [],
  14844. index: 0
  14845. });
  14846. p.children[p.index] = q.children;
  14847. p = q;
  14848. }
  14849. k++;
  14850. }
  14851. if (i + 1 < length) {
  14852. // p here points to last code
  14853. code.push(q = {
  14854. children: [],
  14855. index: 0
  14856. });
  14857. p.children[p.index] = q.children;
  14858. p = q;
  14859. }
  14860. }
  14861. return code[0].children;
  14862. }
  14863. function getBlockBufferOffset(component, row, col) {
  14864. return 64 * ((component.blocksPerLine + 1) * row + col);
  14865. }
  14866. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14867. var mcusPerLine = frame.mcusPerLine;
  14868. var progressive = frame.progressive;
  14869. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14870. function readBit() {
  14871. if (bitsCount > 0) {
  14872. bitsCount--;
  14873. return bitsData >> bitsCount & 1;
  14874. }
  14875. bitsData = data[offset++];
  14876. if (bitsData === 0xFF) {
  14877. var nextByte = data[offset++];
  14878. if (nextByte) {
  14879. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14880. }
  14881. }
  14882. // unstuff 0
  14883. bitsCount = 7;
  14884. return bitsData >>> 7;
  14885. }
  14886. function decodeHuffman(tree) {
  14887. var node = tree;
  14888. while (true) {
  14889. node = node[readBit()];
  14890. if (typeof node === 'number') {
  14891. return node;
  14892. }
  14893. if (typeof node !== 'object') {
  14894. error('JPEG error: invalid huffman sequence');
  14895. }
  14896. }
  14897. }
  14898. function receive(length) {
  14899. var n = 0;
  14900. while (length > 0) {
  14901. n = n << 1 | readBit();
  14902. length--;
  14903. }
  14904. return n;
  14905. }
  14906. function receiveAndExtend(length) {
  14907. if (length === 1) {
  14908. return readBit() === 1 ? 1 : -1;
  14909. }
  14910. var n = receive(length);
  14911. if (n >= 1 << length - 1) {
  14912. return n;
  14913. }
  14914. return n + (-1 << length) + 1;
  14915. }
  14916. function decodeBaseline(component, offset) {
  14917. var t = decodeHuffman(component.huffmanTableDC);
  14918. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14919. component.blockData[offset] = component.pred += diff;
  14920. var k = 1;
  14921. while (k < 64) {
  14922. var rs = decodeHuffman(component.huffmanTableAC);
  14923. var s = rs & 15, r = rs >> 4;
  14924. if (s === 0) {
  14925. if (r < 15) {
  14926. break;
  14927. }
  14928. k += 16;
  14929. continue;
  14930. }
  14931. k += r;
  14932. var z = dctZigZag[k];
  14933. component.blockData[offset + z] = receiveAndExtend(s);
  14934. k++;
  14935. }
  14936. }
  14937. function decodeDCFirst(component, offset) {
  14938. var t = decodeHuffman(component.huffmanTableDC);
  14939. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14940. component.blockData[offset] = component.pred += diff;
  14941. }
  14942. function decodeDCSuccessive(component, offset) {
  14943. component.blockData[offset] |= readBit() << successive;
  14944. }
  14945. var eobrun = 0;
  14946. function decodeACFirst(component, offset) {
  14947. if (eobrun > 0) {
  14948. eobrun--;
  14949. return;
  14950. }
  14951. var k = spectralStart, e = spectralEnd;
  14952. while (k <= e) {
  14953. var rs = decodeHuffman(component.huffmanTableAC);
  14954. var s = rs & 15, r = rs >> 4;
  14955. if (s === 0) {
  14956. if (r < 15) {
  14957. eobrun = receive(r) + (1 << r) - 1;
  14958. break;
  14959. }
  14960. k += 16;
  14961. continue;
  14962. }
  14963. k += r;
  14964. var z = dctZigZag[k];
  14965. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14966. k++;
  14967. }
  14968. }
  14969. var successiveACState = 0, successiveACNextValue;
  14970. function decodeACSuccessive(component, offset) {
  14971. var k = spectralStart;
  14972. var e = spectralEnd;
  14973. var r = 0;
  14974. var s;
  14975. var rs;
  14976. while (k <= e) {
  14977. var z = dctZigZag[k];
  14978. switch (successiveACState) {
  14979. case 0:
  14980. // initial state
  14981. rs = decodeHuffman(component.huffmanTableAC);
  14982. s = rs & 15;
  14983. r = rs >> 4;
  14984. if (s === 0) {
  14985. if (r < 15) {
  14986. eobrun = receive(r) + (1 << r);
  14987. successiveACState = 4;
  14988. } else {
  14989. r = 16;
  14990. successiveACState = 1;
  14991. }
  14992. } else {
  14993. if (s !== 1) {
  14994. error('JPEG error: invalid ACn encoding');
  14995. }
  14996. successiveACNextValue = receiveAndExtend(s);
  14997. successiveACState = r ? 2 : 3;
  14998. }
  14999. continue;
  15000. case 1:
  15001. // skipping r zero items
  15002. case 2:
  15003. if (component.blockData[offset + z]) {
  15004. component.blockData[offset + z] += readBit() << successive;
  15005. } else {
  15006. r--;
  15007. if (r === 0) {
  15008. successiveACState = successiveACState === 2 ? 3 : 0;
  15009. }
  15010. }
  15011. break;
  15012. case 3:
  15013. // set value for a zero item
  15014. if (component.blockData[offset + z]) {
  15015. component.blockData[offset + z] += readBit() << successive;
  15016. } else {
  15017. component.blockData[offset + z] = successiveACNextValue << successive;
  15018. successiveACState = 0;
  15019. }
  15020. break;
  15021. case 4:
  15022. // eob
  15023. if (component.blockData[offset + z]) {
  15024. component.blockData[offset + z] += readBit() << successive;
  15025. }
  15026. break;
  15027. }
  15028. k++;
  15029. }
  15030. if (successiveACState === 4) {
  15031. eobrun--;
  15032. if (eobrun === 0) {
  15033. successiveACState = 0;
  15034. }
  15035. }
  15036. }
  15037. function decodeMcu(component, decode, mcu, row, col) {
  15038. var mcuRow = mcu / mcusPerLine | 0;
  15039. var mcuCol = mcu % mcusPerLine;
  15040. var blockRow = mcuRow * component.v + row;
  15041. var blockCol = mcuCol * component.h + col;
  15042. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15043. decode(component, offset);
  15044. }
  15045. function decodeBlock(component, decode, mcu) {
  15046. var blockRow = mcu / component.blocksPerLine | 0;
  15047. var blockCol = mcu % component.blocksPerLine;
  15048. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15049. decode(component, offset);
  15050. }
  15051. var componentsLength = components.length;
  15052. var component, i, j, k, n;
  15053. var decodeFn;
  15054. if (progressive) {
  15055. if (spectralStart === 0) {
  15056. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15057. } else {
  15058. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15059. }
  15060. } else {
  15061. decodeFn = decodeBaseline;
  15062. }
  15063. var mcu = 0, marker;
  15064. var mcuExpected;
  15065. if (componentsLength === 1) {
  15066. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15067. } else {
  15068. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15069. }
  15070. if (!resetInterval) {
  15071. resetInterval = mcuExpected;
  15072. }
  15073. var h, v;
  15074. while (mcu < mcuExpected) {
  15075. // reset interval stuff
  15076. for (i = 0; i < componentsLength; i++) {
  15077. components[i].pred = 0;
  15078. }
  15079. eobrun = 0;
  15080. if (componentsLength === 1) {
  15081. component = components[0];
  15082. for (n = 0; n < resetInterval; n++) {
  15083. decodeBlock(component, decodeFn, mcu);
  15084. mcu++;
  15085. }
  15086. } else {
  15087. for (n = 0; n < resetInterval; n++) {
  15088. for (i = 0; i < componentsLength; i++) {
  15089. component = components[i];
  15090. h = component.h;
  15091. v = component.v;
  15092. for (j = 0; j < v; j++) {
  15093. for (k = 0; k < h; k++) {
  15094. decodeMcu(component, decodeFn, mcu, j, k);
  15095. }
  15096. }
  15097. }
  15098. mcu++;
  15099. }
  15100. }
  15101. // find marker
  15102. bitsCount = 0;
  15103. marker = data[offset] << 8 | data[offset + 1];
  15104. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15105. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15106. while (data[offset] === 0x00 && offset < data.length - 1) {
  15107. offset++;
  15108. marker = data[offset] << 8 | data[offset + 1];
  15109. }
  15110. if (marker <= 0xFF00) {
  15111. error('JPEG error: marker was not found');
  15112. }
  15113. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15114. // RSTx
  15115. offset += 2;
  15116. } else {
  15117. break;
  15118. }
  15119. }
  15120. return offset - startOffset;
  15121. }
  15122. // A port of poppler's IDCT method which in turn is taken from:
  15123. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15124. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15125. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15126. // 988-991.
  15127. function quantizeAndInverse(component, blockBufferOffset, p) {
  15128. var qt = component.quantizationTable, blockData = component.blockData;
  15129. var v0, v1, v2, v3, v4, v5, v6, v7;
  15130. var p0, p1, p2, p3, p4, p5, p6, p7;
  15131. var t;
  15132. if (!qt) {
  15133. error('JPEG error: missing required Quantization Table.');
  15134. }
  15135. // inverse DCT on rows
  15136. for (var row = 0; row < 64; row += 8) {
  15137. // gather block data
  15138. p0 = blockData[blockBufferOffset + row];
  15139. p1 = blockData[blockBufferOffset + row + 1];
  15140. p2 = blockData[blockBufferOffset + row + 2];
  15141. p3 = blockData[blockBufferOffset + row + 3];
  15142. p4 = blockData[blockBufferOffset + row + 4];
  15143. p5 = blockData[blockBufferOffset + row + 5];
  15144. p6 = blockData[blockBufferOffset + row + 6];
  15145. p7 = blockData[blockBufferOffset + row + 7];
  15146. // dequant p0
  15147. p0 *= qt[row];
  15148. // check for all-zero AC coefficients
  15149. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15150. t = dctSqrt2 * p0 + 512 >> 10;
  15151. p[row] = t;
  15152. p[row + 1] = t;
  15153. p[row + 2] = t;
  15154. p[row + 3] = t;
  15155. p[row + 4] = t;
  15156. p[row + 5] = t;
  15157. p[row + 6] = t;
  15158. p[row + 7] = t;
  15159. continue;
  15160. }
  15161. // dequant p1 ... p7
  15162. p1 *= qt[row + 1];
  15163. p2 *= qt[row + 2];
  15164. p3 *= qt[row + 3];
  15165. p4 *= qt[row + 4];
  15166. p5 *= qt[row + 5];
  15167. p6 *= qt[row + 6];
  15168. p7 *= qt[row + 7];
  15169. // stage 4
  15170. v0 = dctSqrt2 * p0 + 128 >> 8;
  15171. v1 = dctSqrt2 * p4 + 128 >> 8;
  15172. v2 = p2;
  15173. v3 = p6;
  15174. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15175. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15176. v5 = p3 << 4;
  15177. v6 = p5 << 4;
  15178. // stage 3
  15179. v0 = v0 + v1 + 1 >> 1;
  15180. v1 = v0 - v1;
  15181. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15182. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15183. v3 = t;
  15184. v4 = v4 + v6 + 1 >> 1;
  15185. v6 = v4 - v6;
  15186. v7 = v7 + v5 + 1 >> 1;
  15187. v5 = v7 - v5;
  15188. // stage 2
  15189. v0 = v0 + v3 + 1 >> 1;
  15190. v3 = v0 - v3;
  15191. v1 = v1 + v2 + 1 >> 1;
  15192. v2 = v1 - v2;
  15193. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15194. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15195. v7 = t;
  15196. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15197. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15198. v6 = t;
  15199. // stage 1
  15200. p[row] = v0 + v7;
  15201. p[row + 7] = v0 - v7;
  15202. p[row + 1] = v1 + v6;
  15203. p[row + 6] = v1 - v6;
  15204. p[row + 2] = v2 + v5;
  15205. p[row + 5] = v2 - v5;
  15206. p[row + 3] = v3 + v4;
  15207. p[row + 4] = v3 - v4;
  15208. }
  15209. // inverse DCT on columns
  15210. for (var col = 0; col < 8; ++col) {
  15211. p0 = p[col];
  15212. p1 = p[col + 8];
  15213. p2 = p[col + 16];
  15214. p3 = p[col + 24];
  15215. p4 = p[col + 32];
  15216. p5 = p[col + 40];
  15217. p6 = p[col + 48];
  15218. p7 = p[col + 56];
  15219. // check for all-zero AC coefficients
  15220. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15221. t = dctSqrt2 * p0 + 8192 >> 14;
  15222. // convert to 8 bit
  15223. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15224. blockData[blockBufferOffset + col] = t;
  15225. blockData[blockBufferOffset + col + 8] = t;
  15226. blockData[blockBufferOffset + col + 16] = t;
  15227. blockData[blockBufferOffset + col + 24] = t;
  15228. blockData[blockBufferOffset + col + 32] = t;
  15229. blockData[blockBufferOffset + col + 40] = t;
  15230. blockData[blockBufferOffset + col + 48] = t;
  15231. blockData[blockBufferOffset + col + 56] = t;
  15232. continue;
  15233. }
  15234. // stage 4
  15235. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15236. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15237. v2 = p2;
  15238. v3 = p6;
  15239. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15240. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15241. v5 = p3;
  15242. v6 = p5;
  15243. // stage 3
  15244. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15245. // converting to UInt8 range later.
  15246. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15247. v1 = v0 - v1;
  15248. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15249. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15250. v3 = t;
  15251. v4 = v4 + v6 + 1 >> 1;
  15252. v6 = v4 - v6;
  15253. v7 = v7 + v5 + 1 >> 1;
  15254. v5 = v7 - v5;
  15255. // stage 2
  15256. v0 = v0 + v3 + 1 >> 1;
  15257. v3 = v0 - v3;
  15258. v1 = v1 + v2 + 1 >> 1;
  15259. v2 = v1 - v2;
  15260. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15261. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15262. v7 = t;
  15263. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15264. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15265. v6 = t;
  15266. // stage 1
  15267. p0 = v0 + v7;
  15268. p7 = v0 - v7;
  15269. p1 = v1 + v6;
  15270. p6 = v1 - v6;
  15271. p2 = v2 + v5;
  15272. p5 = v2 - v5;
  15273. p3 = v3 + v4;
  15274. p4 = v3 - v4;
  15275. // convert to 8-bit integers
  15276. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15277. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15278. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15279. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15280. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15281. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15282. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15283. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15284. // store block data
  15285. blockData[blockBufferOffset + col] = p0;
  15286. blockData[blockBufferOffset + col + 8] = p1;
  15287. blockData[blockBufferOffset + col + 16] = p2;
  15288. blockData[blockBufferOffset + col + 24] = p3;
  15289. blockData[blockBufferOffset + col + 32] = p4;
  15290. blockData[blockBufferOffset + col + 40] = p5;
  15291. blockData[blockBufferOffset + col + 48] = p6;
  15292. blockData[blockBufferOffset + col + 56] = p7;
  15293. }
  15294. }
  15295. function buildComponentData(frame, component) {
  15296. var blocksPerLine = component.blocksPerLine;
  15297. var blocksPerColumn = component.blocksPerColumn;
  15298. var computationBuffer = new Int16Array(64);
  15299. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15300. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15301. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15302. quantizeAndInverse(component, offset, computationBuffer);
  15303. }
  15304. }
  15305. return component.blockData;
  15306. }
  15307. function clamp0to255(a) {
  15308. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15309. }
  15310. JpegImage.prototype = {
  15311. parse: function parse(data) {
  15312. function readUint16() {
  15313. var value = data[offset] << 8 | data[offset + 1];
  15314. offset += 2;
  15315. return value;
  15316. }
  15317. function readDataBlock() {
  15318. var length = readUint16();
  15319. var array = data.subarray(offset, offset + length - 2);
  15320. offset += array.length;
  15321. return array;
  15322. }
  15323. function prepareComponents(frame) {
  15324. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15325. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15326. for (var i = 0; i < frame.components.length; i++) {
  15327. component = frame.components[i];
  15328. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15329. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15330. var blocksPerLineForMcu = mcusPerLine * component.h;
  15331. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15332. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15333. component.blockData = new Int16Array(blocksBufferSize);
  15334. component.blocksPerLine = blocksPerLine;
  15335. component.blocksPerColumn = blocksPerColumn;
  15336. }
  15337. frame.mcusPerLine = mcusPerLine;
  15338. frame.mcusPerColumn = mcusPerColumn;
  15339. }
  15340. var offset = 0;
  15341. var jfif = null;
  15342. var adobe = null;
  15343. var frame, resetInterval;
  15344. var quantizationTables = [];
  15345. var huffmanTablesAC = [], huffmanTablesDC = [];
  15346. var fileMarker = readUint16();
  15347. if (fileMarker !== 0xFFD8) {
  15348. // SOI (Start of Image)
  15349. error('JPEG error: SOI not found');
  15350. }
  15351. fileMarker = readUint16();
  15352. while (fileMarker !== 0xFFD9) {
  15353. // EOI (End of image)
  15354. var i, j, l;
  15355. switch (fileMarker) {
  15356. case 0xFFE0:
  15357. // APP0 (Application Specific)
  15358. case 0xFFE1:
  15359. // APP1
  15360. case 0xFFE2:
  15361. // APP2
  15362. case 0xFFE3:
  15363. // APP3
  15364. case 0xFFE4:
  15365. // APP4
  15366. case 0xFFE5:
  15367. // APP5
  15368. case 0xFFE6:
  15369. // APP6
  15370. case 0xFFE7:
  15371. // APP7
  15372. case 0xFFE8:
  15373. // APP8
  15374. case 0xFFE9:
  15375. // APP9
  15376. case 0xFFEA:
  15377. // APP10
  15378. case 0xFFEB:
  15379. // APP11
  15380. case 0xFFEC:
  15381. // APP12
  15382. case 0xFFED:
  15383. // APP13
  15384. case 0xFFEE:
  15385. // APP14
  15386. case 0xFFEF:
  15387. // APP15
  15388. case 0xFFFE:
  15389. // COM (Comment)
  15390. var appData = readDataBlock();
  15391. if (fileMarker === 0xFFE0) {
  15392. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15393. // 'JFIF\x00'
  15394. jfif = {
  15395. version: {
  15396. major: appData[5],
  15397. minor: appData[6]
  15398. },
  15399. densityUnits: appData[7],
  15400. xDensity: appData[8] << 8 | appData[9],
  15401. yDensity: appData[10] << 8 | appData[11],
  15402. thumbWidth: appData[12],
  15403. thumbHeight: appData[13],
  15404. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15405. };
  15406. }
  15407. }
  15408. // TODO APP1 - Exif
  15409. if (fileMarker === 0xFFEE) {
  15410. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15411. // 'Adobe'
  15412. adobe = {
  15413. version: appData[5] << 8 | appData[6],
  15414. flags0: appData[7] << 8 | appData[8],
  15415. flags1: appData[9] << 8 | appData[10],
  15416. transformCode: appData[11]
  15417. };
  15418. }
  15419. }
  15420. break;
  15421. case 0xFFDB:
  15422. // DQT (Define Quantization Tables)
  15423. var quantizationTablesLength = readUint16();
  15424. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15425. var z;
  15426. while (offset < quantizationTablesEnd) {
  15427. var quantizationTableSpec = data[offset++];
  15428. var tableData = new Uint16Array(64);
  15429. if (quantizationTableSpec >> 4 === 0) {
  15430. // 8 bit values
  15431. for (j = 0; j < 64; j++) {
  15432. z = dctZigZag[j];
  15433. tableData[z] = data[offset++];
  15434. }
  15435. } else if (quantizationTableSpec >> 4 === 1) {
  15436. //16 bit
  15437. for (j = 0; j < 64; j++) {
  15438. z = dctZigZag[j];
  15439. tableData[z] = readUint16();
  15440. }
  15441. } else {
  15442. error('JPEG error: DQT - invalid table spec');
  15443. }
  15444. quantizationTables[quantizationTableSpec & 15] = tableData;
  15445. }
  15446. break;
  15447. case 0xFFC0:
  15448. // SOF0 (Start of Frame, Baseline DCT)
  15449. case 0xFFC1:
  15450. // SOF1 (Start of Frame, Extended DCT)
  15451. case 0xFFC2:
  15452. // SOF2 (Start of Frame, Progressive DCT)
  15453. if (frame) {
  15454. error('JPEG error: Only single frame JPEGs supported');
  15455. }
  15456. readUint16();
  15457. // skip data length
  15458. frame = {};
  15459. frame.extended = fileMarker === 0xFFC1;
  15460. frame.progressive = fileMarker === 0xFFC2;
  15461. frame.precision = data[offset++];
  15462. frame.scanLines = readUint16();
  15463. frame.samplesPerLine = readUint16();
  15464. frame.components = [];
  15465. frame.componentIds = {};
  15466. var componentsCount = data[offset++], componentId;
  15467. var maxH = 0, maxV = 0;
  15468. for (i = 0; i < componentsCount; i++) {
  15469. componentId = data[offset];
  15470. var h = data[offset + 1] >> 4;
  15471. var v = data[offset + 1] & 15;
  15472. if (maxH < h) {
  15473. maxH = h;
  15474. }
  15475. if (maxV < v) {
  15476. maxV = v;
  15477. }
  15478. var qId = data[offset + 2];
  15479. l = frame.components.push({
  15480. h: h,
  15481. v: v,
  15482. quantizationId: qId,
  15483. quantizationTable: null
  15484. });
  15485. // See comment below.
  15486. frame.componentIds[componentId] = l - 1;
  15487. offset += 3;
  15488. }
  15489. frame.maxH = maxH;
  15490. frame.maxV = maxV;
  15491. prepareComponents(frame);
  15492. break;
  15493. case 0xFFC4:
  15494. // DHT (Define Huffman Tables)
  15495. var huffmanLength = readUint16();
  15496. for (i = 2; i < huffmanLength;) {
  15497. var huffmanTableSpec = data[offset++];
  15498. var codeLengths = new Uint8Array(16);
  15499. var codeLengthSum = 0;
  15500. for (j = 0; j < 16; j++, offset++) {
  15501. codeLengthSum += codeLengths[j] = data[offset];
  15502. }
  15503. var huffmanValues = new Uint8Array(codeLengthSum);
  15504. for (j = 0; j < codeLengthSum; j++, offset++) {
  15505. huffmanValues[j] = data[offset];
  15506. }
  15507. i += 17 + codeLengthSum;
  15508. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15509. }
  15510. break;
  15511. case 0xFFDD:
  15512. // DRI (Define Restart Interval)
  15513. readUint16();
  15514. // skip data length
  15515. resetInterval = readUint16();
  15516. break;
  15517. case 0xFFDA:
  15518. // SOS (Start of Scan)
  15519. var scanLength = readUint16();
  15520. var selectorsCount = data[offset++];
  15521. var components = [], component;
  15522. for (i = 0; i < selectorsCount; i++) {
  15523. var componentIndex = frame.componentIds[data[offset++]];
  15524. component = frame.components[componentIndex];
  15525. var tableSpec = data[offset++];
  15526. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15527. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15528. components.push(component);
  15529. }
  15530. var spectralStart = data[offset++];
  15531. var spectralEnd = data[offset++];
  15532. var successiveApproximation = data[offset++];
  15533. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15534. offset += processed;
  15535. break;
  15536. case 0xFFFF:
  15537. // Fill bytes
  15538. if (data[offset] !== 0xFF) {
  15539. // Avoid skipping a valid marker.
  15540. offset--;
  15541. }
  15542. break;
  15543. default:
  15544. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15545. // could be incorrect encoding -- last 0xFF byte of the previous
  15546. // block was eaten by the encoder
  15547. offset -= 3;
  15548. break;
  15549. }
  15550. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15551. }
  15552. fileMarker = readUint16();
  15553. }
  15554. this.width = frame.samplesPerLine;
  15555. this.height = frame.scanLines;
  15556. this.jfif = jfif;
  15557. this.adobe = adobe;
  15558. this.components = [];
  15559. for (i = 0; i < frame.components.length; i++) {
  15560. component = frame.components[i];
  15561. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15562. // by assigning the `quantizationTable` entry after the entire image
  15563. // has been parsed (fixes issue7406.pdf).
  15564. var quantizationTable = quantizationTables[component.quantizationId];
  15565. if (quantizationTable) {
  15566. component.quantizationTable = quantizationTable;
  15567. }
  15568. this.components.push({
  15569. output: buildComponentData(frame, component),
  15570. scaleX: component.h / frame.maxH,
  15571. scaleY: component.v / frame.maxV,
  15572. blocksPerLine: component.blocksPerLine,
  15573. blocksPerColumn: component.blocksPerColumn
  15574. });
  15575. }
  15576. this.numComponents = this.components.length;
  15577. },
  15578. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15579. var scaleX = this.width / width, scaleY = this.height / height;
  15580. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15581. var x, y, i, j, k;
  15582. var index;
  15583. var offset = 0;
  15584. var output;
  15585. var numComponents = this.components.length;
  15586. var dataLength = width * height * numComponents;
  15587. var data = new Uint8Array(dataLength);
  15588. var xScaleBlockOffset = new Uint32Array(width);
  15589. var mask3LSB = 0xfffffff8;
  15590. // used to clear the 3 LSBs
  15591. for (i = 0; i < numComponents; i++) {
  15592. component = this.components[i];
  15593. componentScaleX = component.scaleX * scaleX;
  15594. componentScaleY = component.scaleY * scaleY;
  15595. offset = i;
  15596. output = component.output;
  15597. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15598. // precalculate the xScaleBlockOffset
  15599. for (x = 0; x < width; x++) {
  15600. j = 0 | x * componentScaleX;
  15601. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15602. }
  15603. // linearize the blocks of the component
  15604. for (y = 0; y < height; y++) {
  15605. j = 0 | y * componentScaleY;
  15606. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15607. for (x = 0; x < width; x++) {
  15608. data[offset] = output[index + xScaleBlockOffset[x]];
  15609. offset += numComponents;
  15610. }
  15611. }
  15612. }
  15613. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15614. var transform = this.decodeTransform;
  15615. if (transform) {
  15616. for (i = 0; i < dataLength;) {
  15617. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15618. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15619. }
  15620. }
  15621. }
  15622. return data;
  15623. },
  15624. _isColorConversionNeeded: function isColorConversionNeeded() {
  15625. if (this.adobe && this.adobe.transformCode) {
  15626. // The adobe transform marker overrides any previous setting
  15627. return true;
  15628. } else if (this.numComponents === 3) {
  15629. if (!this.adobe && this.colorTransform === 0) {
  15630. // If the Adobe transform marker is not present and the image
  15631. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15632. // then the colours should *not* be transformed.
  15633. return false;
  15634. }
  15635. return true;
  15636. } else {
  15637. // `this.numComponents !== 3`
  15638. if (!this.adobe && this.colorTransform === 1) {
  15639. // If the Adobe transform marker is not present and the image
  15640. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15641. // then the colours should be transformed.
  15642. return true;
  15643. }
  15644. return false;
  15645. }
  15646. },
  15647. _convertYccToRgb: function convertYccToRgb(data) {
  15648. var Y, Cb, Cr;
  15649. for (var i = 0, length = data.length; i < length; i += 3) {
  15650. Y = data[i];
  15651. Cb = data[i + 1];
  15652. Cr = data[i + 2];
  15653. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15654. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15655. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15656. }
  15657. return data;
  15658. },
  15659. _convertYcckToRgb: function convertYcckToRgb(data) {
  15660. var Y, Cb, Cr, k;
  15661. var offset = 0;
  15662. for (var i = 0, length = data.length; i < length; i += 4) {
  15663. Y = data[i];
  15664. Cb = data[i + 1];
  15665. Cr = data[i + 2];
  15666. k = data[i + 3];
  15667. var r = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
  15668. var g = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
  15669. var b = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
  15670. data[offset++] = clamp0to255(r);
  15671. data[offset++] = clamp0to255(g);
  15672. data[offset++] = clamp0to255(b);
  15673. }
  15674. return data;
  15675. },
  15676. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15677. var Y, Cb, Cr;
  15678. for (var i = 0, length = data.length; i < length; i += 4) {
  15679. Y = data[i];
  15680. Cb = data[i + 1];
  15681. Cr = data[i + 2];
  15682. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15683. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15684. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15685. }
  15686. // K in data[i + 3] is unchanged
  15687. return data;
  15688. },
  15689. _convertCmykToRgb: function convertCmykToRgb(data) {
  15690. var c, m, y, k;
  15691. var offset = 0;
  15692. var min = -255 * 255 * 255;
  15693. var scale = 1 / 255 / 255;
  15694. for (var i = 0, length = data.length; i < length; i += 4) {
  15695. c = data[i];
  15696. m = data[i + 1];
  15697. y = data[i + 2];
  15698. k = data[i + 3];
  15699. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k - 72734.4411664936) + m * (1.7149763477362134 * m - 5.6096736904047315 * y - 17.873870861415444 * k - 1401.7366389350734) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 4465.541406466231) - k * (21.86122147463605 * k + 48317.86113160301);
  15700. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 20220.756542821975) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 48691.05921601825) + y * (4.444339102852739 * y + 9.8632861493405 * k - 6341.191035517494) - k * (20.737325471181034 * k + 47890.15695978492);
  15701. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k - 3616.812083916688) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 28620.90484698408) + y * (0.03296041114873217 * y + 115.60384449646641 * k - 49363.43385999684) - k * (22.33816807309886 * k + 45932.16563550634);
  15702. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15703. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15704. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15705. }
  15706. return data;
  15707. },
  15708. getData: function getData(width, height, forceRGBoutput) {
  15709. if (this.numComponents > 4) {
  15710. error('JPEG error: Unsupported color mode');
  15711. }
  15712. // type of data: Uint8Array(width * height * numComponents)
  15713. var data = this._getLinearizedBlockData(width, height);
  15714. if (this.numComponents === 1 && forceRGBoutput) {
  15715. var dataLength = data.length;
  15716. var rgbData = new Uint8Array(dataLength * 3);
  15717. var offset = 0;
  15718. for (var i = 0; i < dataLength; i++) {
  15719. var grayColor = data[i];
  15720. rgbData[offset++] = grayColor;
  15721. rgbData[offset++] = grayColor;
  15722. rgbData[offset++] = grayColor;
  15723. }
  15724. return rgbData;
  15725. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15726. return this._convertYccToRgb(data);
  15727. } else if (this.numComponents === 4) {
  15728. if (this._isColorConversionNeeded()) {
  15729. if (forceRGBoutput) {
  15730. return this._convertYcckToRgb(data);
  15731. } else {
  15732. return this._convertYcckToCmyk(data);
  15733. }
  15734. } else if (forceRGBoutput) {
  15735. return this._convertCmykToRgb(data);
  15736. }
  15737. }
  15738. return data;
  15739. }
  15740. };
  15741. return JpegImage;
  15742. }();
  15743. exports.JpegImage = JpegImage;
  15744. }));
  15745. (function (root, factory) {
  15746. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15747. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15748. var info = sharedUtil.info;
  15749. var warn = sharedUtil.warn;
  15750. var error = sharedUtil.error;
  15751. var log2 = sharedUtil.log2;
  15752. var readUint16 = sharedUtil.readUint16;
  15753. var readUint32 = sharedUtil.readUint32;
  15754. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15755. var JpxImage = function JpxImageClosure() {
  15756. // Table E.1
  15757. var SubbandsGainLog2 = {
  15758. 'LL': 0,
  15759. 'LH': 1,
  15760. 'HL': 1,
  15761. 'HH': 2
  15762. };
  15763. function JpxImage() {
  15764. this.failOnCorruptedImage = false;
  15765. }
  15766. JpxImage.prototype = {
  15767. parse: function JpxImage_parse(data) {
  15768. var head = readUint16(data, 0);
  15769. // No box header, immediate start of codestream (SOC)
  15770. if (head === 0xFF4F) {
  15771. this.parseCodestream(data, 0, data.length);
  15772. return;
  15773. }
  15774. var position = 0, length = data.length;
  15775. while (position < length) {
  15776. var headerSize = 8;
  15777. var lbox = readUint32(data, position);
  15778. var tbox = readUint32(data, position + 4);
  15779. position += headerSize;
  15780. if (lbox === 1) {
  15781. // XLBox: read UInt64 according to spec.
  15782. // JavaScript's int precision of 53 bit should be sufficient here.
  15783. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15784. position += 8;
  15785. headerSize += 8;
  15786. }
  15787. if (lbox === 0) {
  15788. lbox = length - position + headerSize;
  15789. }
  15790. if (lbox < headerSize) {
  15791. error('JPX Error: Invalid box field size');
  15792. }
  15793. var dataLength = lbox - headerSize;
  15794. var jumpDataLength = true;
  15795. switch (tbox) {
  15796. case 0x6A703268:
  15797. // 'jp2h'
  15798. jumpDataLength = false;
  15799. // parsing child boxes
  15800. break;
  15801. case 0x636F6C72:
  15802. // 'colr'
  15803. // Colorspaces are not used, the CS from the PDF is used.
  15804. var method = data[position];
  15805. if (method === 1) {
  15806. // enumerated colorspace
  15807. var colorspace = readUint32(data, position + 3);
  15808. switch (colorspace) {
  15809. case 16:
  15810. // this indicates a sRGB colorspace
  15811. case 17:
  15812. // this indicates a grayscale colorspace
  15813. case 18:
  15814. // this indicates a YUV colorspace
  15815. break;
  15816. default:
  15817. warn('Unknown colorspace ' + colorspace);
  15818. break;
  15819. }
  15820. } else if (method === 2) {
  15821. info('ICC profile not supported');
  15822. }
  15823. break;
  15824. case 0x6A703263:
  15825. // 'jp2c'
  15826. this.parseCodestream(data, position, position + dataLength);
  15827. break;
  15828. case 0x6A502020:
  15829. // 'jP\024\024'
  15830. if (0x0d0a870a !== readUint32(data, position)) {
  15831. warn('Invalid JP2 signature');
  15832. }
  15833. break;
  15834. // The following header types are valid but currently not used:
  15835. case 0x6A501A1A:
  15836. // 'jP\032\032'
  15837. case 0x66747970:
  15838. // 'ftyp'
  15839. case 0x72726571:
  15840. // 'rreq'
  15841. case 0x72657320:
  15842. // 'res '
  15843. case 0x69686472:
  15844. // 'ihdr'
  15845. break;
  15846. default:
  15847. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15848. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15849. break;
  15850. }
  15851. if (jumpDataLength) {
  15852. position += dataLength;
  15853. }
  15854. }
  15855. },
  15856. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15857. var newByte = stream.getByte();
  15858. while (newByte >= 0) {
  15859. var oldByte = newByte;
  15860. newByte = stream.getByte();
  15861. var code = oldByte << 8 | newByte;
  15862. // Image and tile size (SIZ)
  15863. if (code === 0xFF51) {
  15864. stream.skip(4);
  15865. var Xsiz = stream.getInt32() >>> 0;
  15866. // Byte 4
  15867. var Ysiz = stream.getInt32() >>> 0;
  15868. // Byte 8
  15869. var XOsiz = stream.getInt32() >>> 0;
  15870. // Byte 12
  15871. var YOsiz = stream.getInt32() >>> 0;
  15872. // Byte 16
  15873. stream.skip(16);
  15874. var Csiz = stream.getUint16();
  15875. // Byte 36
  15876. this.width = Xsiz - XOsiz;
  15877. this.height = Ysiz - YOsiz;
  15878. this.componentsCount = Csiz;
  15879. // Results are always returned as Uint8Arrays
  15880. this.bitsPerComponent = 8;
  15881. return;
  15882. }
  15883. }
  15884. error('JPX Error: No size marker found in JPX stream');
  15885. },
  15886. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15887. var context = {};
  15888. var doNotRecover = false;
  15889. try {
  15890. var position = start;
  15891. while (position + 1 < end) {
  15892. var code = readUint16(data, position);
  15893. position += 2;
  15894. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15895. switch (code) {
  15896. case 0xFF4F:
  15897. // Start of codestream (SOC)
  15898. context.mainHeader = true;
  15899. break;
  15900. case 0xFFD9:
  15901. // End of codestream (EOC)
  15902. break;
  15903. case 0xFF51:
  15904. // Image and tile size (SIZ)
  15905. length = readUint16(data, position);
  15906. var siz = {};
  15907. siz.Xsiz = readUint32(data, position + 4);
  15908. siz.Ysiz = readUint32(data, position + 8);
  15909. siz.XOsiz = readUint32(data, position + 12);
  15910. siz.YOsiz = readUint32(data, position + 16);
  15911. siz.XTsiz = readUint32(data, position + 20);
  15912. siz.YTsiz = readUint32(data, position + 24);
  15913. siz.XTOsiz = readUint32(data, position + 28);
  15914. siz.YTOsiz = readUint32(data, position + 32);
  15915. var componentsCount = readUint16(data, position + 36);
  15916. siz.Csiz = componentsCount;
  15917. var components = [];
  15918. j = position + 38;
  15919. for (var i = 0; i < componentsCount; i++) {
  15920. var component = {
  15921. precision: (data[j] & 0x7F) + 1,
  15922. isSigned: !!(data[j] & 0x80),
  15923. XRsiz: data[j + 1],
  15924. YRsiz: data[j + 1]
  15925. };
  15926. calculateComponentDimensions(component, siz);
  15927. components.push(component);
  15928. }
  15929. context.SIZ = siz;
  15930. context.components = components;
  15931. calculateTileGrids(context, components);
  15932. context.QCC = [];
  15933. context.COC = [];
  15934. break;
  15935. case 0xFF5C:
  15936. // Quantization default (QCD)
  15937. length = readUint16(data, position);
  15938. var qcd = {};
  15939. j = position + 2;
  15940. sqcd = data[j++];
  15941. switch (sqcd & 0x1F) {
  15942. case 0:
  15943. spqcdSize = 8;
  15944. scalarExpounded = true;
  15945. break;
  15946. case 1:
  15947. spqcdSize = 16;
  15948. scalarExpounded = false;
  15949. break;
  15950. case 2:
  15951. spqcdSize = 16;
  15952. scalarExpounded = true;
  15953. break;
  15954. default:
  15955. throw new Error('Invalid SQcd value ' + sqcd);
  15956. }
  15957. qcd.noQuantization = spqcdSize === 8;
  15958. qcd.scalarExpounded = scalarExpounded;
  15959. qcd.guardBits = sqcd >> 5;
  15960. spqcds = [];
  15961. while (j < length + position) {
  15962. var spqcd = {};
  15963. if (spqcdSize === 8) {
  15964. spqcd.epsilon = data[j++] >> 3;
  15965. spqcd.mu = 0;
  15966. } else {
  15967. spqcd.epsilon = data[j] >> 3;
  15968. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15969. j += 2;
  15970. }
  15971. spqcds.push(spqcd);
  15972. }
  15973. qcd.SPqcds = spqcds;
  15974. if (context.mainHeader) {
  15975. context.QCD = qcd;
  15976. } else {
  15977. context.currentTile.QCD = qcd;
  15978. context.currentTile.QCC = [];
  15979. }
  15980. break;
  15981. case 0xFF5D:
  15982. // Quantization component (QCC)
  15983. length = readUint16(data, position);
  15984. var qcc = {};
  15985. j = position + 2;
  15986. var cqcc;
  15987. if (context.SIZ.Csiz < 257) {
  15988. cqcc = data[j++];
  15989. } else {
  15990. cqcc = readUint16(data, j);
  15991. j += 2;
  15992. }
  15993. sqcd = data[j++];
  15994. switch (sqcd & 0x1F) {
  15995. case 0:
  15996. spqcdSize = 8;
  15997. scalarExpounded = true;
  15998. break;
  15999. case 1:
  16000. spqcdSize = 16;
  16001. scalarExpounded = false;
  16002. break;
  16003. case 2:
  16004. spqcdSize = 16;
  16005. scalarExpounded = true;
  16006. break;
  16007. default:
  16008. throw new Error('Invalid SQcd value ' + sqcd);
  16009. }
  16010. qcc.noQuantization = spqcdSize === 8;
  16011. qcc.scalarExpounded = scalarExpounded;
  16012. qcc.guardBits = sqcd >> 5;
  16013. spqcds = [];
  16014. while (j < length + position) {
  16015. spqcd = {};
  16016. if (spqcdSize === 8) {
  16017. spqcd.epsilon = data[j++] >> 3;
  16018. spqcd.mu = 0;
  16019. } else {
  16020. spqcd.epsilon = data[j] >> 3;
  16021. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16022. j += 2;
  16023. }
  16024. spqcds.push(spqcd);
  16025. }
  16026. qcc.SPqcds = spqcds;
  16027. if (context.mainHeader) {
  16028. context.QCC[cqcc] = qcc;
  16029. } else {
  16030. context.currentTile.QCC[cqcc] = qcc;
  16031. }
  16032. break;
  16033. case 0xFF52:
  16034. // Coding style default (COD)
  16035. length = readUint16(data, position);
  16036. var cod = {};
  16037. j = position + 2;
  16038. var scod = data[j++];
  16039. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16040. cod.sopMarkerUsed = !!(scod & 2);
  16041. cod.ephMarkerUsed = !!(scod & 4);
  16042. cod.progressionOrder = data[j++];
  16043. cod.layersCount = readUint16(data, j);
  16044. j += 2;
  16045. cod.multipleComponentTransform = data[j++];
  16046. cod.decompositionLevelsCount = data[j++];
  16047. cod.xcb = (data[j++] & 0xF) + 2;
  16048. cod.ycb = (data[j++] & 0xF) + 2;
  16049. var blockStyle = data[j++];
  16050. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16051. cod.resetContextProbabilities = !!(blockStyle & 2);
  16052. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16053. cod.verticalyStripe = !!(blockStyle & 8);
  16054. cod.predictableTermination = !!(blockStyle & 16);
  16055. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16056. cod.reversibleTransformation = data[j++];
  16057. if (cod.entropyCoderWithCustomPrecincts) {
  16058. var precinctsSizes = [];
  16059. while (j < length + position) {
  16060. var precinctsSize = data[j++];
  16061. precinctsSizes.push({
  16062. PPx: precinctsSize & 0xF,
  16063. PPy: precinctsSize >> 4
  16064. });
  16065. }
  16066. cod.precinctsSizes = precinctsSizes;
  16067. }
  16068. var unsupported = [];
  16069. if (cod.selectiveArithmeticCodingBypass) {
  16070. unsupported.push('selectiveArithmeticCodingBypass');
  16071. }
  16072. if (cod.resetContextProbabilities) {
  16073. unsupported.push('resetContextProbabilities');
  16074. }
  16075. if (cod.terminationOnEachCodingPass) {
  16076. unsupported.push('terminationOnEachCodingPass');
  16077. }
  16078. if (cod.verticalyStripe) {
  16079. unsupported.push('verticalyStripe');
  16080. }
  16081. if (cod.predictableTermination) {
  16082. unsupported.push('predictableTermination');
  16083. }
  16084. if (unsupported.length > 0) {
  16085. doNotRecover = true;
  16086. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16087. }
  16088. if (context.mainHeader) {
  16089. context.COD = cod;
  16090. } else {
  16091. context.currentTile.COD = cod;
  16092. context.currentTile.COC = [];
  16093. }
  16094. break;
  16095. case 0xFF90:
  16096. // Start of tile-part (SOT)
  16097. length = readUint16(data, position);
  16098. tile = {};
  16099. tile.index = readUint16(data, position + 2);
  16100. tile.length = readUint32(data, position + 4);
  16101. tile.dataEnd = tile.length + position - 2;
  16102. tile.partIndex = data[position + 8];
  16103. tile.partsCount = data[position + 9];
  16104. context.mainHeader = false;
  16105. if (tile.partIndex === 0) {
  16106. // reset component specific settings
  16107. tile.COD = context.COD;
  16108. tile.COC = context.COC.slice(0);
  16109. // clone of the global COC
  16110. tile.QCD = context.QCD;
  16111. tile.QCC = context.QCC.slice(0);
  16112. }
  16113. // clone of the global COC
  16114. context.currentTile = tile;
  16115. break;
  16116. case 0xFF93:
  16117. // Start of data (SOD)
  16118. tile = context.currentTile;
  16119. if (tile.partIndex === 0) {
  16120. initializeTile(context, tile.index);
  16121. buildPackets(context);
  16122. }
  16123. // moving to the end of the data
  16124. length = tile.dataEnd - position;
  16125. parseTilePackets(context, data, position, length);
  16126. break;
  16127. case 0xFF55:
  16128. // Tile-part lengths, main header (TLM)
  16129. case 0xFF57:
  16130. // Packet length, main header (PLM)
  16131. case 0xFF58:
  16132. // Packet length, tile-part header (PLT)
  16133. case 0xFF64:
  16134. // Comment (COM)
  16135. length = readUint16(data, position);
  16136. // skipping content
  16137. break;
  16138. case 0xFF53:
  16139. // Coding style component (COC)
  16140. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16141. default:
  16142. throw new Error('Unknown codestream code: ' + code.toString(16));
  16143. }
  16144. position += length;
  16145. }
  16146. } catch (e) {
  16147. if (doNotRecover || this.failOnCorruptedImage) {
  16148. error('JPX Error: ' + e.message);
  16149. } else {
  16150. warn('JPX: Trying to recover from: ' + e.message);
  16151. }
  16152. }
  16153. this.tiles = transformComponents(context);
  16154. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16155. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16156. this.componentsCount = context.SIZ.Csiz;
  16157. }
  16158. };
  16159. function calculateComponentDimensions(component, siz) {
  16160. // Section B.2 Component mapping
  16161. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16162. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16163. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16164. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16165. component.width = component.x1 - component.x0;
  16166. component.height = component.y1 - component.y0;
  16167. }
  16168. function calculateTileGrids(context, components) {
  16169. var siz = context.SIZ;
  16170. // Section B.3 Division into tile and tile-components
  16171. var tile, tiles = [];
  16172. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16173. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16174. for (var q = 0; q < numYtiles; q++) {
  16175. for (var p = 0; p < numXtiles; p++) {
  16176. tile = {};
  16177. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16178. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16179. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16180. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16181. tile.width = tile.tx1 - tile.tx0;
  16182. tile.height = tile.ty1 - tile.ty0;
  16183. tile.components = [];
  16184. tiles.push(tile);
  16185. }
  16186. }
  16187. context.tiles = tiles;
  16188. var componentsCount = siz.Csiz;
  16189. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16190. var component = components[i];
  16191. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16192. var tileComponent = {};
  16193. tile = tiles[j];
  16194. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16195. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16196. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16197. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16198. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16199. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16200. tile.components[i] = tileComponent;
  16201. }
  16202. }
  16203. }
  16204. function getBlocksDimensions(context, component, r) {
  16205. var codOrCoc = component.codingStyleParameters;
  16206. var result = {};
  16207. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16208. result.PPx = 15;
  16209. result.PPy = 15;
  16210. } else {
  16211. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16212. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16213. }
  16214. // calculate codeblock size as described in section B.7
  16215. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16216. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16217. return result;
  16218. }
  16219. function buildPrecincts(context, resolution, dimensions) {
  16220. // Section B.6 Division resolution to precincts
  16221. var precinctWidth = 1 << dimensions.PPx;
  16222. var precinctHeight = 1 << dimensions.PPy;
  16223. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16224. // to precincts. Precinct partition divides a resolution according to width
  16225. // and height parameters. The subband that belongs to the resolution level
  16226. // has a different size than the level, unless it is the zero resolution.
  16227. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16228. // The precinct partitioning for a particular subband is derived from a
  16229. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16230. // resolution level)... The LL band associated with each resolution level is
  16231. // divided into precincts... Each of the resulting precinct regions is then
  16232. // mapped into its child subbands (if any) at the next lower resolution
  16233. // level. This is accomplished by using the coordinate transformation
  16234. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16235. // coordinates of a point in the LL band and child subband, respectively.
  16236. var isZeroRes = resolution.resLevel === 0;
  16237. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16238. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16239. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16240. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16241. var numprecincts = numprecinctswide * numprecinctshigh;
  16242. resolution.precinctParameters = {
  16243. precinctWidth: precinctWidth,
  16244. precinctHeight: precinctHeight,
  16245. numprecinctswide: numprecinctswide,
  16246. numprecinctshigh: numprecinctshigh,
  16247. numprecincts: numprecincts,
  16248. precinctWidthInSubband: precinctWidthInSubband,
  16249. precinctHeightInSubband: precinctHeightInSubband
  16250. };
  16251. }
  16252. function buildCodeblocks(context, subband, dimensions) {
  16253. // Section B.7 Division sub-band into code-blocks
  16254. var xcb_ = dimensions.xcb_;
  16255. var ycb_ = dimensions.ycb_;
  16256. var codeblockWidth = 1 << xcb_;
  16257. var codeblockHeight = 1 << ycb_;
  16258. var cbx0 = subband.tbx0 >> xcb_;
  16259. var cby0 = subband.tby0 >> ycb_;
  16260. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16261. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16262. var precinctParameters = subband.resolution.precinctParameters;
  16263. var codeblocks = [];
  16264. var precincts = [];
  16265. var i, j, codeblock, precinctNumber;
  16266. for (j = cby0; j < cby1; j++) {
  16267. for (i = cbx0; i < cbx1; i++) {
  16268. codeblock = {
  16269. cbx: i,
  16270. cby: j,
  16271. tbx0: codeblockWidth * i,
  16272. tby0: codeblockHeight * j,
  16273. tbx1: codeblockWidth * (i + 1),
  16274. tby1: codeblockHeight * (j + 1)
  16275. };
  16276. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16277. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16278. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16279. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16280. // Calculate precinct number for this codeblock, codeblock position
  16281. // should be relative to its subband, use actual dimension and position
  16282. // See comment about codeblock group width and height
  16283. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16284. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16285. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16286. codeblock.precinctNumber = precinctNumber;
  16287. codeblock.subbandType = subband.type;
  16288. codeblock.Lblock = 3;
  16289. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16290. continue;
  16291. }
  16292. codeblocks.push(codeblock);
  16293. // building precinct for the sub-band
  16294. var precinct = precincts[precinctNumber];
  16295. if (precinct !== undefined) {
  16296. if (i < precinct.cbxMin) {
  16297. precinct.cbxMin = i;
  16298. } else if (i > precinct.cbxMax) {
  16299. precinct.cbxMax = i;
  16300. }
  16301. if (j < precinct.cbyMin) {
  16302. precinct.cbxMin = j;
  16303. } else if (j > precinct.cbyMax) {
  16304. precinct.cbyMax = j;
  16305. }
  16306. } else {
  16307. precincts[precinctNumber] = precinct = {
  16308. cbxMin: i,
  16309. cbyMin: j,
  16310. cbxMax: i,
  16311. cbyMax: j
  16312. };
  16313. }
  16314. codeblock.precinct = precinct;
  16315. }
  16316. }
  16317. subband.codeblockParameters = {
  16318. codeblockWidth: xcb_,
  16319. codeblockHeight: ycb_,
  16320. numcodeblockwide: cbx1 - cbx0 + 1,
  16321. numcodeblockhigh: cby1 - cby0 + 1
  16322. };
  16323. subband.codeblocks = codeblocks;
  16324. subband.precincts = precincts;
  16325. }
  16326. function createPacket(resolution, precinctNumber, layerNumber) {
  16327. var precinctCodeblocks = [];
  16328. // Section B.10.8 Order of info in packet
  16329. var subbands = resolution.subbands;
  16330. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16331. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16332. var subband = subbands[i];
  16333. var codeblocks = subband.codeblocks;
  16334. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16335. var codeblock = codeblocks[j];
  16336. if (codeblock.precinctNumber !== precinctNumber) {
  16337. continue;
  16338. }
  16339. precinctCodeblocks.push(codeblock);
  16340. }
  16341. }
  16342. return {
  16343. layerNumber: layerNumber,
  16344. codeblocks: precinctCodeblocks
  16345. };
  16346. }
  16347. function LayerResolutionComponentPositionIterator(context) {
  16348. var siz = context.SIZ;
  16349. var tileIndex = context.currentTile.index;
  16350. var tile = context.tiles[tileIndex];
  16351. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16352. var componentsCount = siz.Csiz;
  16353. var maxDecompositionLevelsCount = 0;
  16354. for (var q = 0; q < componentsCount; q++) {
  16355. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16356. }
  16357. var l = 0, r = 0, i = 0, k = 0;
  16358. this.nextPacket = function JpxImage_nextPacket() {
  16359. // Section B.12.1.1 Layer-resolution-component-position
  16360. for (; l < layersCount; l++) {
  16361. for (; r <= maxDecompositionLevelsCount; r++) {
  16362. for (; i < componentsCount; i++) {
  16363. var component = tile.components[i];
  16364. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16365. continue;
  16366. }
  16367. var resolution = component.resolutions[r];
  16368. var numprecincts = resolution.precinctParameters.numprecincts;
  16369. for (; k < numprecincts;) {
  16370. var packet = createPacket(resolution, k, l);
  16371. k++;
  16372. return packet;
  16373. }
  16374. k = 0;
  16375. }
  16376. i = 0;
  16377. }
  16378. r = 0;
  16379. }
  16380. error('JPX Error: Out of packets');
  16381. };
  16382. }
  16383. function ResolutionLayerComponentPositionIterator(context) {
  16384. var siz = context.SIZ;
  16385. var tileIndex = context.currentTile.index;
  16386. var tile = context.tiles[tileIndex];
  16387. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16388. var componentsCount = siz.Csiz;
  16389. var maxDecompositionLevelsCount = 0;
  16390. for (var q = 0; q < componentsCount; q++) {
  16391. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16392. }
  16393. var r = 0, l = 0, i = 0, k = 0;
  16394. this.nextPacket = function JpxImage_nextPacket() {
  16395. // Section B.12.1.2 Resolution-layer-component-position
  16396. for (; r <= maxDecompositionLevelsCount; r++) {
  16397. for (; l < layersCount; l++) {
  16398. for (; i < componentsCount; i++) {
  16399. var component = tile.components[i];
  16400. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16401. continue;
  16402. }
  16403. var resolution = component.resolutions[r];
  16404. var numprecincts = resolution.precinctParameters.numprecincts;
  16405. for (; k < numprecincts;) {
  16406. var packet = createPacket(resolution, k, l);
  16407. k++;
  16408. return packet;
  16409. }
  16410. k = 0;
  16411. }
  16412. i = 0;
  16413. }
  16414. l = 0;
  16415. }
  16416. error('JPX Error: Out of packets');
  16417. };
  16418. }
  16419. function ResolutionPositionComponentLayerIterator(context) {
  16420. var siz = context.SIZ;
  16421. var tileIndex = context.currentTile.index;
  16422. var tile = context.tiles[tileIndex];
  16423. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16424. var componentsCount = siz.Csiz;
  16425. var l, r, c, p;
  16426. var maxDecompositionLevelsCount = 0;
  16427. for (c = 0; c < componentsCount; c++) {
  16428. var component = tile.components[c];
  16429. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16430. }
  16431. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16432. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16433. var maxNumPrecincts = 0;
  16434. for (c = 0; c < componentsCount; ++c) {
  16435. var resolutions = tile.components[c].resolutions;
  16436. if (r < resolutions.length) {
  16437. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16438. }
  16439. }
  16440. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16441. }
  16442. l = 0;
  16443. r = 0;
  16444. c = 0;
  16445. p = 0;
  16446. this.nextPacket = function JpxImage_nextPacket() {
  16447. // Section B.12.1.3 Resolution-position-component-layer
  16448. for (; r <= maxDecompositionLevelsCount; r++) {
  16449. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16450. for (; c < componentsCount; c++) {
  16451. var component = tile.components[c];
  16452. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16453. continue;
  16454. }
  16455. var resolution = component.resolutions[r];
  16456. var numprecincts = resolution.precinctParameters.numprecincts;
  16457. if (p >= numprecincts) {
  16458. continue;
  16459. }
  16460. for (; l < layersCount;) {
  16461. var packet = createPacket(resolution, p, l);
  16462. l++;
  16463. return packet;
  16464. }
  16465. l = 0;
  16466. }
  16467. c = 0;
  16468. }
  16469. p = 0;
  16470. }
  16471. error('JPX Error: Out of packets');
  16472. };
  16473. }
  16474. function PositionComponentResolutionLayerIterator(context) {
  16475. var siz = context.SIZ;
  16476. var tileIndex = context.currentTile.index;
  16477. var tile = context.tiles[tileIndex];
  16478. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16479. var componentsCount = siz.Csiz;
  16480. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16481. var precinctsIterationSizes = precinctsSizes;
  16482. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16483. this.nextPacket = function JpxImage_nextPacket() {
  16484. // Section B.12.1.4 Position-component-resolution-layer
  16485. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16486. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16487. for (; c < componentsCount; c++) {
  16488. var component = tile.components[c];
  16489. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16490. for (; r <= decompositionLevelsCount; r++) {
  16491. var resolution = component.resolutions[r];
  16492. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16493. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16494. if (k === null) {
  16495. continue;
  16496. }
  16497. for (; l < layersCount;) {
  16498. var packet = createPacket(resolution, k, l);
  16499. l++;
  16500. return packet;
  16501. }
  16502. l = 0;
  16503. }
  16504. r = 0;
  16505. }
  16506. c = 0;
  16507. }
  16508. px = 0;
  16509. }
  16510. error('JPX Error: Out of packets');
  16511. };
  16512. }
  16513. function ComponentPositionResolutionLayerIterator(context) {
  16514. var siz = context.SIZ;
  16515. var tileIndex = context.currentTile.index;
  16516. var tile = context.tiles[tileIndex];
  16517. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16518. var componentsCount = siz.Csiz;
  16519. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16520. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16521. this.nextPacket = function JpxImage_nextPacket() {
  16522. // Section B.12.1.5 Component-position-resolution-layer
  16523. for (; c < componentsCount; ++c) {
  16524. var component = tile.components[c];
  16525. var precinctsIterationSizes = precinctsSizes.components[c];
  16526. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16527. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16528. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16529. for (; r <= decompositionLevelsCount; r++) {
  16530. var resolution = component.resolutions[r];
  16531. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16532. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16533. if (k === null) {
  16534. continue;
  16535. }
  16536. for (; l < layersCount;) {
  16537. var packet = createPacket(resolution, k, l);
  16538. l++;
  16539. return packet;
  16540. }
  16541. l = 0;
  16542. }
  16543. r = 0;
  16544. }
  16545. px = 0;
  16546. }
  16547. py = 0;
  16548. }
  16549. error('JPX Error: Out of packets');
  16550. };
  16551. }
  16552. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16553. var posX = pxIndex * precinctIterationSizes.minWidth;
  16554. var posY = pyIndex * precinctIterationSizes.minHeight;
  16555. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16556. return null;
  16557. }
  16558. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16559. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16560. }
  16561. function getPrecinctSizesInImageScale(tile) {
  16562. var componentsCount = tile.components.length;
  16563. var minWidth = Number.MAX_VALUE;
  16564. var minHeight = Number.MAX_VALUE;
  16565. var maxNumWide = 0;
  16566. var maxNumHigh = 0;
  16567. var sizePerComponent = new Array(componentsCount);
  16568. for (var c = 0; c < componentsCount; c++) {
  16569. var component = tile.components[c];
  16570. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16571. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16572. var minWidthCurrentComponent = Number.MAX_VALUE;
  16573. var minHeightCurrentComponent = Number.MAX_VALUE;
  16574. var maxNumWideCurrentComponent = 0;
  16575. var maxNumHighCurrentComponent = 0;
  16576. var scale = 1;
  16577. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16578. var resolution = component.resolutions[r];
  16579. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16580. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16581. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16582. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16583. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16584. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16585. sizePerResolution[r] = {
  16586. width: widthCurrentResolution,
  16587. height: heightCurrentResolution
  16588. };
  16589. scale <<= 1;
  16590. }
  16591. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16592. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16593. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16594. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16595. sizePerComponent[c] = {
  16596. resolutions: sizePerResolution,
  16597. minWidth: minWidthCurrentComponent,
  16598. minHeight: minHeightCurrentComponent,
  16599. maxNumWide: maxNumWideCurrentComponent,
  16600. maxNumHigh: maxNumHighCurrentComponent
  16601. };
  16602. }
  16603. return {
  16604. components: sizePerComponent,
  16605. minWidth: minWidth,
  16606. minHeight: minHeight,
  16607. maxNumWide: maxNumWide,
  16608. maxNumHigh: maxNumHigh
  16609. };
  16610. }
  16611. function buildPackets(context) {
  16612. var siz = context.SIZ;
  16613. var tileIndex = context.currentTile.index;
  16614. var tile = context.tiles[tileIndex];
  16615. var componentsCount = siz.Csiz;
  16616. // Creating resolutions and sub-bands for each component
  16617. for (var c = 0; c < componentsCount; c++) {
  16618. var component = tile.components[c];
  16619. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16620. // Section B.5 Resolution levels and sub-bands
  16621. var resolutions = [];
  16622. var subbands = [];
  16623. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16624. var blocksDimensions = getBlocksDimensions(context, component, r);
  16625. var resolution = {};
  16626. var scale = 1 << decompositionLevelsCount - r;
  16627. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16628. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16629. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16630. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16631. resolution.resLevel = r;
  16632. buildPrecincts(context, resolution, blocksDimensions);
  16633. resolutions.push(resolution);
  16634. var subband;
  16635. if (r === 0) {
  16636. // one sub-band (LL) with last decomposition
  16637. subband = {};
  16638. subband.type = 'LL';
  16639. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16640. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16641. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16642. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16643. subband.resolution = resolution;
  16644. buildCodeblocks(context, subband, blocksDimensions);
  16645. subbands.push(subband);
  16646. resolution.subbands = [subband];
  16647. } else {
  16648. var bscale = 1 << decompositionLevelsCount - r + 1;
  16649. var resolutionSubbands = [];
  16650. // three sub-bands (HL, LH and HH) with rest of decompositions
  16651. subband = {};
  16652. subband.type = 'HL';
  16653. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16654. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16655. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16656. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16657. subband.resolution = resolution;
  16658. buildCodeblocks(context, subband, blocksDimensions);
  16659. subbands.push(subband);
  16660. resolutionSubbands.push(subband);
  16661. subband = {};
  16662. subband.type = 'LH';
  16663. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16664. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16665. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16666. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16667. subband.resolution = resolution;
  16668. buildCodeblocks(context, subband, blocksDimensions);
  16669. subbands.push(subband);
  16670. resolutionSubbands.push(subband);
  16671. subband = {};
  16672. subband.type = 'HH';
  16673. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16674. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16675. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16676. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16677. subband.resolution = resolution;
  16678. buildCodeblocks(context, subband, blocksDimensions);
  16679. subbands.push(subband);
  16680. resolutionSubbands.push(subband);
  16681. resolution.subbands = resolutionSubbands;
  16682. }
  16683. }
  16684. component.resolutions = resolutions;
  16685. component.subbands = subbands;
  16686. }
  16687. // Generate the packets sequence
  16688. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16689. switch (progressionOrder) {
  16690. case 0:
  16691. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16692. break;
  16693. case 1:
  16694. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16695. break;
  16696. case 2:
  16697. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16698. break;
  16699. case 3:
  16700. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16701. break;
  16702. case 4:
  16703. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16704. break;
  16705. default:
  16706. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16707. }
  16708. }
  16709. function parseTilePackets(context, data, offset, dataLength) {
  16710. var position = 0;
  16711. var buffer, bufferSize = 0, skipNextBit = false;
  16712. function readBits(count) {
  16713. while (bufferSize < count) {
  16714. var b = data[offset + position];
  16715. position++;
  16716. if (skipNextBit) {
  16717. buffer = buffer << 7 | b;
  16718. bufferSize += 7;
  16719. skipNextBit = false;
  16720. } else {
  16721. buffer = buffer << 8 | b;
  16722. bufferSize += 8;
  16723. }
  16724. if (b === 0xFF) {
  16725. skipNextBit = true;
  16726. }
  16727. }
  16728. bufferSize -= count;
  16729. return buffer >>> bufferSize & (1 << count) - 1;
  16730. }
  16731. function skipMarkerIfEqual(value) {
  16732. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16733. skipBytes(1);
  16734. return true;
  16735. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16736. skipBytes(2);
  16737. return true;
  16738. }
  16739. return false;
  16740. }
  16741. function skipBytes(count) {
  16742. position += count;
  16743. }
  16744. function alignToByte() {
  16745. bufferSize = 0;
  16746. if (skipNextBit) {
  16747. position++;
  16748. skipNextBit = false;
  16749. }
  16750. }
  16751. function readCodingpasses() {
  16752. if (readBits(1) === 0) {
  16753. return 1;
  16754. }
  16755. if (readBits(1) === 0) {
  16756. return 2;
  16757. }
  16758. var value = readBits(2);
  16759. if (value < 3) {
  16760. return value + 3;
  16761. }
  16762. value = readBits(5);
  16763. if (value < 31) {
  16764. return value + 6;
  16765. }
  16766. value = readBits(7);
  16767. return value + 37;
  16768. }
  16769. var tileIndex = context.currentTile.index;
  16770. var tile = context.tiles[tileIndex];
  16771. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16772. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16773. var packetsIterator = tile.packetsIterator;
  16774. while (position < dataLength) {
  16775. alignToByte();
  16776. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16777. // Skip also marker segment length and packet sequence ID
  16778. skipBytes(4);
  16779. }
  16780. var packet = packetsIterator.nextPacket();
  16781. if (!readBits(1)) {
  16782. continue;
  16783. }
  16784. var layerNumber = packet.layerNumber;
  16785. var queue = [], codeblock;
  16786. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16787. codeblock = packet.codeblocks[i];
  16788. var precinct = codeblock.precinct;
  16789. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16790. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16791. var codeblockIncluded = false;
  16792. var firstTimeInclusion = false;
  16793. var valueReady;
  16794. if (codeblock['included'] !== undefined) {
  16795. codeblockIncluded = !!readBits(1);
  16796. } else {
  16797. // reading inclusion tree
  16798. precinct = codeblock.precinct;
  16799. var inclusionTree, zeroBitPlanesTree;
  16800. if (precinct['inclusionTree'] !== undefined) {
  16801. inclusionTree = precinct.inclusionTree;
  16802. } else {
  16803. // building inclusion and zero bit-planes trees
  16804. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16805. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16806. inclusionTree = new InclusionTree(width, height, layerNumber);
  16807. zeroBitPlanesTree = new TagTree(width, height);
  16808. precinct.inclusionTree = inclusionTree;
  16809. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16810. }
  16811. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16812. while (true) {
  16813. if (readBits(1)) {
  16814. valueReady = !inclusionTree.nextLevel();
  16815. if (valueReady) {
  16816. codeblock.included = true;
  16817. codeblockIncluded = firstTimeInclusion = true;
  16818. break;
  16819. }
  16820. } else {
  16821. inclusionTree.incrementValue(layerNumber);
  16822. break;
  16823. }
  16824. }
  16825. }
  16826. }
  16827. if (!codeblockIncluded) {
  16828. continue;
  16829. }
  16830. if (firstTimeInclusion) {
  16831. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16832. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16833. while (true) {
  16834. if (readBits(1)) {
  16835. valueReady = !zeroBitPlanesTree.nextLevel();
  16836. if (valueReady) {
  16837. break;
  16838. }
  16839. } else {
  16840. zeroBitPlanesTree.incrementValue();
  16841. }
  16842. }
  16843. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16844. }
  16845. var codingpasses = readCodingpasses();
  16846. while (readBits(1)) {
  16847. codeblock.Lblock++;
  16848. }
  16849. var codingpassesLog2 = log2(codingpasses);
  16850. // rounding down log2
  16851. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16852. var codedDataLength = readBits(bits);
  16853. queue.push({
  16854. codeblock: codeblock,
  16855. codingpasses: codingpasses,
  16856. dataLength: codedDataLength
  16857. });
  16858. }
  16859. alignToByte();
  16860. if (ephMarkerUsed) {
  16861. skipMarkerIfEqual(0x92);
  16862. }
  16863. while (queue.length > 0) {
  16864. var packetItem = queue.shift();
  16865. codeblock = packetItem.codeblock;
  16866. if (codeblock['data'] === undefined) {
  16867. codeblock.data = [];
  16868. }
  16869. codeblock.data.push({
  16870. data: data,
  16871. start: offset + position,
  16872. end: offset + position + packetItem.dataLength,
  16873. codingpasses: packetItem.codingpasses
  16874. });
  16875. position += packetItem.dataLength;
  16876. }
  16877. }
  16878. return position;
  16879. }
  16880. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16881. var x0 = subband.tbx0;
  16882. var y0 = subband.tby0;
  16883. var width = subband.tbx1 - subband.tbx0;
  16884. var codeblocks = subband.codeblocks;
  16885. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16886. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16887. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16888. var codeblock = codeblocks[i];
  16889. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16890. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16891. if (blockWidth === 0 || blockHeight === 0) {
  16892. continue;
  16893. }
  16894. if (codeblock['data'] === undefined) {
  16895. continue;
  16896. }
  16897. var bitModel, currentCodingpassType;
  16898. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16899. currentCodingpassType = 2;
  16900. // first bit plane starts from cleanup
  16901. // collect data
  16902. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16903. var j, jj, dataItem;
  16904. for (j = 0, jj = data.length; j < jj; j++) {
  16905. dataItem = data[j];
  16906. totalLength += dataItem.end - dataItem.start;
  16907. codingpasses += dataItem.codingpasses;
  16908. }
  16909. var encodedData = new Uint8Array(totalLength);
  16910. var position = 0;
  16911. for (j = 0, jj = data.length; j < jj; j++) {
  16912. dataItem = data[j];
  16913. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16914. encodedData.set(chunk, position);
  16915. position += chunk.length;
  16916. }
  16917. // decoding the item
  16918. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16919. bitModel.setDecoder(decoder);
  16920. for (j = 0; j < codingpasses; j++) {
  16921. switch (currentCodingpassType) {
  16922. case 0:
  16923. bitModel.runSignificancePropagationPass();
  16924. break;
  16925. case 1:
  16926. bitModel.runMagnitudeRefinementPass();
  16927. break;
  16928. case 2:
  16929. bitModel.runCleanupPass();
  16930. if (segmentationSymbolUsed) {
  16931. bitModel.checkSegmentationSymbol();
  16932. }
  16933. break;
  16934. }
  16935. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16936. }
  16937. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16938. var sign = bitModel.coefficentsSign;
  16939. var magnitude = bitModel.coefficentsMagnitude;
  16940. var bitsDecoded = bitModel.bitsDecoded;
  16941. var magnitudeCorrection = reversible ? 0 : 0.5;
  16942. var k, n, nb;
  16943. position = 0;
  16944. // Do the interleaving of Section F.3.3 here, so we do not need
  16945. // to copy later. LL level is not interleaved, just copied.
  16946. var interleave = subband.type !== 'LL';
  16947. for (j = 0; j < blockHeight; j++) {
  16948. var row = offset / width | 0;
  16949. // row in the non-interleaved subband
  16950. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16951. for (k = 0; k < blockWidth; k++) {
  16952. n = magnitude[position];
  16953. if (n !== 0) {
  16954. n = (n + magnitudeCorrection) * delta;
  16955. if (sign[position] !== 0) {
  16956. n = -n;
  16957. }
  16958. nb = bitsDecoded[position];
  16959. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16960. if (reversible && nb >= mb) {
  16961. coefficients[pos] = n;
  16962. } else {
  16963. coefficients[pos] = n * (1 << mb - nb);
  16964. }
  16965. }
  16966. offset++;
  16967. position++;
  16968. }
  16969. offset += width - blockWidth;
  16970. }
  16971. }
  16972. }
  16973. function transformTile(context, tile, c) {
  16974. var component = tile.components[c];
  16975. var codingStyleParameters = component.codingStyleParameters;
  16976. var quantizationParameters = component.quantizationParameters;
  16977. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16978. var spqcds = quantizationParameters.SPqcds;
  16979. var scalarExpounded = quantizationParameters.scalarExpounded;
  16980. var guardBits = quantizationParameters.guardBits;
  16981. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16982. var precision = context.components[c].precision;
  16983. var reversible = codingStyleParameters.reversibleTransformation;
  16984. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16985. var subbandCoefficients = [];
  16986. var b = 0;
  16987. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16988. var resolution = component.resolutions[i];
  16989. var width = resolution.trx1 - resolution.trx0;
  16990. var height = resolution.try1 - resolution.try0;
  16991. // Allocate space for the whole sublevel.
  16992. var coefficients = new Float32Array(width * height);
  16993. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16994. var mu, epsilon;
  16995. if (!scalarExpounded) {
  16996. // formula E-5
  16997. mu = spqcds[0].mu;
  16998. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  16999. } else {
  17000. mu = spqcds[b].mu;
  17001. epsilon = spqcds[b].epsilon;
  17002. b++;
  17003. }
  17004. var subband = resolution.subbands[j];
  17005. var gainLog2 = SubbandsGainLog2[subband.type];
  17006. // calculate quantization coefficient (Section E.1.1.1)
  17007. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  17008. var mb = guardBits + epsilon - 1;
  17009. // In the first resolution level, copyCoefficients will fill the
  17010. // whole array with coefficients. In the succeeding passes,
  17011. // copyCoefficients will consecutively fill in the values that belong
  17012. // to the interleaved positions of the HL, LH, and HH coefficients.
  17013. // The LL coefficients will then be interleaved in Transform.iterate().
  17014. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17015. }
  17016. subbandCoefficients.push({
  17017. width: width,
  17018. height: height,
  17019. items: coefficients
  17020. });
  17021. }
  17022. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17023. return {
  17024. left: component.tcx0,
  17025. top: component.tcy0,
  17026. width: result.width,
  17027. height: result.height,
  17028. items: result.items
  17029. };
  17030. }
  17031. function transformComponents(context) {
  17032. var siz = context.SIZ;
  17033. var components = context.components;
  17034. var componentsCount = siz.Csiz;
  17035. var resultImages = [];
  17036. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17037. var tile = context.tiles[i];
  17038. var transformedTiles = [];
  17039. var c;
  17040. for (c = 0; c < componentsCount; c++) {
  17041. transformedTiles[c] = transformTile(context, tile, c);
  17042. }
  17043. var tile0 = transformedTiles[0];
  17044. var out = new Uint8Array(tile0.items.length * componentsCount);
  17045. var result = {
  17046. left: tile0.left,
  17047. top: tile0.top,
  17048. width: tile0.width,
  17049. height: tile0.height,
  17050. items: out
  17051. };
  17052. // Section G.2.2 Inverse multi component transform
  17053. var shift, offset, max, min, maxK;
  17054. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17055. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17056. var fourComponents = componentsCount === 4;
  17057. var y0items = transformedTiles[0].items;
  17058. var y1items = transformedTiles[1].items;
  17059. var y2items = transformedTiles[2].items;
  17060. var y3items = fourComponents ? transformedTiles[3].items : null;
  17061. // HACK: The multiple component transform formulas below assume that
  17062. // all components have the same precision. With this in mind, we
  17063. // compute shift and offset only once.
  17064. shift = components[0].precision - 8;
  17065. offset = (128 << shift) + 0.5;
  17066. max = 255 * (1 << shift);
  17067. maxK = max * 0.5;
  17068. min = -maxK;
  17069. var component0 = tile.components[0];
  17070. var alpha01 = componentsCount - 3;
  17071. jj = y0items.length;
  17072. if (!component0.codingStyleParameters.reversibleTransformation) {
  17073. // inverse irreversible multiple component transform
  17074. for (j = 0; j < jj; j++, pos += alpha01) {
  17075. y0 = y0items[j] + offset;
  17076. y1 = y1items[j];
  17077. y2 = y2items[j];
  17078. r = y0 + 1.402 * y2;
  17079. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17080. b = y0 + 1.772 * y1;
  17081. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17082. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17083. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17084. }
  17085. } else {
  17086. // inverse reversible multiple component transform
  17087. for (j = 0; j < jj; j++, pos += alpha01) {
  17088. y0 = y0items[j] + offset;
  17089. y1 = y1items[j];
  17090. y2 = y2items[j];
  17091. g = y0 - (y2 + y1 >> 2);
  17092. r = g + y2;
  17093. b = g + y1;
  17094. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17095. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17096. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17097. }
  17098. }
  17099. if (fourComponents) {
  17100. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17101. k = y3items[j];
  17102. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17103. }
  17104. }
  17105. } else {
  17106. // no multi-component transform
  17107. for (c = 0; c < componentsCount; c++) {
  17108. var items = transformedTiles[c].items;
  17109. shift = components[c].precision - 8;
  17110. offset = (128 << shift) + 0.5;
  17111. max = 127.5 * (1 << shift);
  17112. min = -max;
  17113. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17114. val = items[j];
  17115. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17116. pos += componentsCount;
  17117. }
  17118. }
  17119. }
  17120. resultImages.push(result);
  17121. }
  17122. return resultImages;
  17123. }
  17124. function initializeTile(context, tileIndex) {
  17125. var siz = context.SIZ;
  17126. var componentsCount = siz.Csiz;
  17127. var tile = context.tiles[tileIndex];
  17128. for (var c = 0; c < componentsCount; c++) {
  17129. var component = tile.components[c];
  17130. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17131. component.quantizationParameters = qcdOrQcc;
  17132. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17133. component.codingStyleParameters = codOrCoc;
  17134. }
  17135. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17136. }
  17137. // Section B.10.2 Tag trees
  17138. var TagTree = function TagTreeClosure() {
  17139. function TagTree(width, height) {
  17140. var levelsLength = log2(Math.max(width, height)) + 1;
  17141. this.levels = [];
  17142. for (var i = 0; i < levelsLength; i++) {
  17143. var level = {
  17144. width: width,
  17145. height: height,
  17146. items: []
  17147. };
  17148. this.levels.push(level);
  17149. width = Math.ceil(width / 2);
  17150. height = Math.ceil(height / 2);
  17151. }
  17152. }
  17153. TagTree.prototype = {
  17154. reset: function TagTree_reset(i, j) {
  17155. var currentLevel = 0, value = 0, level;
  17156. while (currentLevel < this.levels.length) {
  17157. level = this.levels[currentLevel];
  17158. var index = i + j * level.width;
  17159. if (level.items[index] !== undefined) {
  17160. value = level.items[index];
  17161. break;
  17162. }
  17163. level.index = index;
  17164. i >>= 1;
  17165. j >>= 1;
  17166. currentLevel++;
  17167. }
  17168. currentLevel--;
  17169. level = this.levels[currentLevel];
  17170. level.items[level.index] = value;
  17171. this.currentLevel = currentLevel;
  17172. delete this.value;
  17173. },
  17174. incrementValue: function TagTree_incrementValue() {
  17175. var level = this.levels[this.currentLevel];
  17176. level.items[level.index]++;
  17177. },
  17178. nextLevel: function TagTree_nextLevel() {
  17179. var currentLevel = this.currentLevel;
  17180. var level = this.levels[currentLevel];
  17181. var value = level.items[level.index];
  17182. currentLevel--;
  17183. if (currentLevel < 0) {
  17184. this.value = value;
  17185. return false;
  17186. }
  17187. this.currentLevel = currentLevel;
  17188. level = this.levels[currentLevel];
  17189. level.items[level.index] = value;
  17190. return true;
  17191. }
  17192. };
  17193. return TagTree;
  17194. }();
  17195. var InclusionTree = function InclusionTreeClosure() {
  17196. function InclusionTree(width, height, defaultValue) {
  17197. var levelsLength = log2(Math.max(width, height)) + 1;
  17198. this.levels = [];
  17199. for (var i = 0; i < levelsLength; i++) {
  17200. var items = new Uint8Array(width * height);
  17201. for (var j = 0, jj = items.length; j < jj; j++) {
  17202. items[j] = defaultValue;
  17203. }
  17204. var level = {
  17205. width: width,
  17206. height: height,
  17207. items: items
  17208. };
  17209. this.levels.push(level);
  17210. width = Math.ceil(width / 2);
  17211. height = Math.ceil(height / 2);
  17212. }
  17213. }
  17214. InclusionTree.prototype = {
  17215. reset: function InclusionTree_reset(i, j, stopValue) {
  17216. var currentLevel = 0;
  17217. while (currentLevel < this.levels.length) {
  17218. var level = this.levels[currentLevel];
  17219. var index = i + j * level.width;
  17220. level.index = index;
  17221. var value = level.items[index];
  17222. if (value === 0xFF) {
  17223. break;
  17224. }
  17225. if (value > stopValue) {
  17226. this.currentLevel = currentLevel;
  17227. // already know about this one, propagating the value to top levels
  17228. this.propagateValues();
  17229. return false;
  17230. }
  17231. i >>= 1;
  17232. j >>= 1;
  17233. currentLevel++;
  17234. }
  17235. this.currentLevel = currentLevel - 1;
  17236. return true;
  17237. },
  17238. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17239. var level = this.levels[this.currentLevel];
  17240. level.items[level.index] = stopValue + 1;
  17241. this.propagateValues();
  17242. },
  17243. propagateValues: function InclusionTree_propagateValues() {
  17244. var levelIndex = this.currentLevel;
  17245. var level = this.levels[levelIndex];
  17246. var currentValue = level.items[level.index];
  17247. while (--levelIndex >= 0) {
  17248. level = this.levels[levelIndex];
  17249. level.items[level.index] = currentValue;
  17250. }
  17251. },
  17252. nextLevel: function InclusionTree_nextLevel() {
  17253. var currentLevel = this.currentLevel;
  17254. var level = this.levels[currentLevel];
  17255. var value = level.items[level.index];
  17256. level.items[level.index] = 0xFF;
  17257. currentLevel--;
  17258. if (currentLevel < 0) {
  17259. return false;
  17260. }
  17261. this.currentLevel = currentLevel;
  17262. level = this.levels[currentLevel];
  17263. level.items[level.index] = value;
  17264. return true;
  17265. }
  17266. };
  17267. return InclusionTree;
  17268. }();
  17269. // Section D. Coefficient bit modeling
  17270. var BitModel = function BitModelClosure() {
  17271. var UNIFORM_CONTEXT = 17;
  17272. var RUNLENGTH_CONTEXT = 18;
  17273. // Table D-1
  17274. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17275. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17276. var LLAndLHContextsLabel = new Uint8Array([
  17277. 0,
  17278. 5,
  17279. 8,
  17280. 0,
  17281. 3,
  17282. 7,
  17283. 8,
  17284. 0,
  17285. 4,
  17286. 7,
  17287. 8,
  17288. 0,
  17289. 0,
  17290. 0,
  17291. 0,
  17292. 0,
  17293. 1,
  17294. 6,
  17295. 8,
  17296. 0,
  17297. 3,
  17298. 7,
  17299. 8,
  17300. 0,
  17301. 4,
  17302. 7,
  17303. 8,
  17304. 0,
  17305. 0,
  17306. 0,
  17307. 0,
  17308. 0,
  17309. 2,
  17310. 6,
  17311. 8,
  17312. 0,
  17313. 3,
  17314. 7,
  17315. 8,
  17316. 0,
  17317. 4,
  17318. 7,
  17319. 8,
  17320. 0,
  17321. 0,
  17322. 0,
  17323. 0,
  17324. 0,
  17325. 2,
  17326. 6,
  17327. 8,
  17328. 0,
  17329. 3,
  17330. 7,
  17331. 8,
  17332. 0,
  17333. 4,
  17334. 7,
  17335. 8,
  17336. 0,
  17337. 0,
  17338. 0,
  17339. 0,
  17340. 0,
  17341. 2,
  17342. 6,
  17343. 8,
  17344. 0,
  17345. 3,
  17346. 7,
  17347. 8,
  17348. 0,
  17349. 4,
  17350. 7,
  17351. 8
  17352. ]);
  17353. var HLContextLabel = new Uint8Array([
  17354. 0,
  17355. 3,
  17356. 4,
  17357. 0,
  17358. 5,
  17359. 7,
  17360. 7,
  17361. 0,
  17362. 8,
  17363. 8,
  17364. 8,
  17365. 0,
  17366. 0,
  17367. 0,
  17368. 0,
  17369. 0,
  17370. 1,
  17371. 3,
  17372. 4,
  17373. 0,
  17374. 6,
  17375. 7,
  17376. 7,
  17377. 0,
  17378. 8,
  17379. 8,
  17380. 8,
  17381. 0,
  17382. 0,
  17383. 0,
  17384. 0,
  17385. 0,
  17386. 2,
  17387. 3,
  17388. 4,
  17389. 0,
  17390. 6,
  17391. 7,
  17392. 7,
  17393. 0,
  17394. 8,
  17395. 8,
  17396. 8,
  17397. 0,
  17398. 0,
  17399. 0,
  17400. 0,
  17401. 0,
  17402. 2,
  17403. 3,
  17404. 4,
  17405. 0,
  17406. 6,
  17407. 7,
  17408. 7,
  17409. 0,
  17410. 8,
  17411. 8,
  17412. 8,
  17413. 0,
  17414. 0,
  17415. 0,
  17416. 0,
  17417. 0,
  17418. 2,
  17419. 3,
  17420. 4,
  17421. 0,
  17422. 6,
  17423. 7,
  17424. 7,
  17425. 0,
  17426. 8,
  17427. 8,
  17428. 8
  17429. ]);
  17430. var HHContextLabel = new Uint8Array([
  17431. 0,
  17432. 1,
  17433. 2,
  17434. 0,
  17435. 1,
  17436. 2,
  17437. 2,
  17438. 0,
  17439. 2,
  17440. 2,
  17441. 2,
  17442. 0,
  17443. 0,
  17444. 0,
  17445. 0,
  17446. 0,
  17447. 3,
  17448. 4,
  17449. 5,
  17450. 0,
  17451. 4,
  17452. 5,
  17453. 5,
  17454. 0,
  17455. 5,
  17456. 5,
  17457. 5,
  17458. 0,
  17459. 0,
  17460. 0,
  17461. 0,
  17462. 0,
  17463. 6,
  17464. 7,
  17465. 7,
  17466. 0,
  17467. 7,
  17468. 7,
  17469. 7,
  17470. 0,
  17471. 7,
  17472. 7,
  17473. 7,
  17474. 0,
  17475. 0,
  17476. 0,
  17477. 0,
  17478. 0,
  17479. 8,
  17480. 8,
  17481. 8,
  17482. 0,
  17483. 8,
  17484. 8,
  17485. 8,
  17486. 0,
  17487. 8,
  17488. 8,
  17489. 8,
  17490. 0,
  17491. 0,
  17492. 0,
  17493. 0,
  17494. 0,
  17495. 8,
  17496. 8,
  17497. 8,
  17498. 0,
  17499. 8,
  17500. 8,
  17501. 8,
  17502. 0,
  17503. 8,
  17504. 8,
  17505. 8
  17506. ]);
  17507. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17508. this.width = width;
  17509. this.height = height;
  17510. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17511. var coefficientCount = width * height;
  17512. // coefficients outside the encoding region treated as insignificant
  17513. // add border state cells for significanceState
  17514. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17515. this.coefficentsSign = new Uint8Array(coefficientCount);
  17516. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17517. this.processingFlags = new Uint8Array(coefficientCount);
  17518. var bitsDecoded = new Uint8Array(coefficientCount);
  17519. if (zeroBitPlanes !== 0) {
  17520. for (var i = 0; i < coefficientCount; i++) {
  17521. bitsDecoded[i] = zeroBitPlanes;
  17522. }
  17523. }
  17524. this.bitsDecoded = bitsDecoded;
  17525. this.reset();
  17526. }
  17527. BitModel.prototype = {
  17528. setDecoder: function BitModel_setDecoder(decoder) {
  17529. this.decoder = decoder;
  17530. },
  17531. reset: function BitModel_reset() {
  17532. // We have 17 contexts that are accessed via context labels,
  17533. // plus the uniform and runlength context.
  17534. this.contexts = new Int8Array(19);
  17535. // Contexts are packed into 1 byte:
  17536. // highest 7 bits carry the index, lowest bit carries mps
  17537. this.contexts[0] = 4 << 1 | 0;
  17538. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17539. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17540. },
  17541. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17542. var neighborsSignificance = this.neighborsSignificance;
  17543. var width = this.width, height = this.height;
  17544. var left = column > 0;
  17545. var right = column + 1 < width;
  17546. var i;
  17547. if (row > 0) {
  17548. i = index - width;
  17549. if (left) {
  17550. neighborsSignificance[i - 1] += 0x10;
  17551. }
  17552. if (right) {
  17553. neighborsSignificance[i + 1] += 0x10;
  17554. }
  17555. neighborsSignificance[i] += 0x04;
  17556. }
  17557. if (row + 1 < height) {
  17558. i = index + width;
  17559. if (left) {
  17560. neighborsSignificance[i - 1] += 0x10;
  17561. }
  17562. if (right) {
  17563. neighborsSignificance[i + 1] += 0x10;
  17564. }
  17565. neighborsSignificance[i] += 0x04;
  17566. }
  17567. if (left) {
  17568. neighborsSignificance[index - 1] += 0x01;
  17569. }
  17570. if (right) {
  17571. neighborsSignificance[index + 1] += 0x01;
  17572. }
  17573. neighborsSignificance[index] |= 0x80;
  17574. },
  17575. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17576. var decoder = this.decoder;
  17577. var width = this.width, height = this.height;
  17578. var coefficentsMagnitude = this.coefficentsMagnitude;
  17579. var coefficentsSign = this.coefficentsSign;
  17580. var neighborsSignificance = this.neighborsSignificance;
  17581. var processingFlags = this.processingFlags;
  17582. var contexts = this.contexts;
  17583. var labels = this.contextLabelTable;
  17584. var bitsDecoded = this.bitsDecoded;
  17585. var processedInverseMask = ~1;
  17586. var processedMask = 1;
  17587. var firstMagnitudeBitMask = 2;
  17588. for (var i0 = 0; i0 < height; i0 += 4) {
  17589. for (var j = 0; j < width; j++) {
  17590. var index = i0 * width + j;
  17591. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17592. var i = i0 + i1;
  17593. if (i >= height) {
  17594. break;
  17595. }
  17596. // clear processed flag first
  17597. processingFlags[index] &= processedInverseMask;
  17598. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17599. continue;
  17600. }
  17601. var contextLabel = labels[neighborsSignificance[index]];
  17602. var decision = decoder.readBit(contexts, contextLabel);
  17603. if (decision) {
  17604. var sign = this.decodeSignBit(i, j, index);
  17605. coefficentsSign[index] = sign;
  17606. coefficentsMagnitude[index] = 1;
  17607. this.setNeighborsSignificance(i, j, index);
  17608. processingFlags[index] |= firstMagnitudeBitMask;
  17609. }
  17610. bitsDecoded[index]++;
  17611. processingFlags[index] |= processedMask;
  17612. }
  17613. }
  17614. }
  17615. },
  17616. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17617. var width = this.width, height = this.height;
  17618. var coefficentsMagnitude = this.coefficentsMagnitude;
  17619. var coefficentsSign = this.coefficentsSign;
  17620. var contribution, sign0, sign1, significance1;
  17621. var contextLabel, decoded;
  17622. // calculate horizontal contribution
  17623. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17624. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17625. sign1 = coefficentsSign[index + 1];
  17626. if (significance1) {
  17627. sign0 = coefficentsSign[index - 1];
  17628. contribution = 1 - sign1 - sign0;
  17629. } else {
  17630. contribution = 1 - sign1 - sign1;
  17631. }
  17632. } else if (significance1) {
  17633. sign0 = coefficentsSign[index - 1];
  17634. contribution = 1 - sign0 - sign0;
  17635. } else {
  17636. contribution = 0;
  17637. }
  17638. var horizontalContribution = 3 * contribution;
  17639. // calculate vertical contribution and combine with the horizontal
  17640. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17641. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17642. sign1 = coefficentsSign[index + width];
  17643. if (significance1) {
  17644. sign0 = coefficentsSign[index - width];
  17645. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17646. } else {
  17647. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17648. }
  17649. } else if (significance1) {
  17650. sign0 = coefficentsSign[index - width];
  17651. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17652. } else {
  17653. contribution = horizontalContribution;
  17654. }
  17655. if (contribution >= 0) {
  17656. contextLabel = 9 + contribution;
  17657. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17658. } else {
  17659. contextLabel = 9 - contribution;
  17660. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17661. }
  17662. return decoded;
  17663. },
  17664. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17665. var decoder = this.decoder;
  17666. var width = this.width, height = this.height;
  17667. var coefficentsMagnitude = this.coefficentsMagnitude;
  17668. var neighborsSignificance = this.neighborsSignificance;
  17669. var contexts = this.contexts;
  17670. var bitsDecoded = this.bitsDecoded;
  17671. var processingFlags = this.processingFlags;
  17672. var processedMask = 1;
  17673. var firstMagnitudeBitMask = 2;
  17674. var length = width * height;
  17675. var width4 = width * 4;
  17676. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17677. indexNext = Math.min(length, index0 + width4);
  17678. for (var j = 0; j < width; j++) {
  17679. for (var index = index0 + j; index < indexNext; index += width) {
  17680. // significant but not those that have just become
  17681. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17682. continue;
  17683. }
  17684. var contextLabel = 16;
  17685. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17686. processingFlags[index] ^= firstMagnitudeBitMask;
  17687. // first refinement
  17688. var significance = neighborsSignificance[index] & 127;
  17689. contextLabel = significance === 0 ? 15 : 14;
  17690. }
  17691. var bit = decoder.readBit(contexts, contextLabel);
  17692. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17693. bitsDecoded[index]++;
  17694. processingFlags[index] |= processedMask;
  17695. }
  17696. }
  17697. }
  17698. },
  17699. runCleanupPass: function BitModel_runCleanupPass() {
  17700. var decoder = this.decoder;
  17701. var width = this.width, height = this.height;
  17702. var neighborsSignificance = this.neighborsSignificance;
  17703. var coefficentsMagnitude = this.coefficentsMagnitude;
  17704. var coefficentsSign = this.coefficentsSign;
  17705. var contexts = this.contexts;
  17706. var labels = this.contextLabelTable;
  17707. var bitsDecoded = this.bitsDecoded;
  17708. var processingFlags = this.processingFlags;
  17709. var processedMask = 1;
  17710. var firstMagnitudeBitMask = 2;
  17711. var oneRowDown = width;
  17712. var twoRowsDown = width * 2;
  17713. var threeRowsDown = width * 3;
  17714. var iNext;
  17715. for (var i0 = 0; i0 < height; i0 = iNext) {
  17716. iNext = Math.min(i0 + 4, height);
  17717. var indexBase = i0 * width;
  17718. var checkAllEmpty = i0 + 3 < height;
  17719. for (var j = 0; j < width; j++) {
  17720. var index0 = indexBase + j;
  17721. // using the property: labels[neighborsSignificance[index]] === 0
  17722. // when neighborsSignificance[index] === 0
  17723. var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
  17724. var i1 = 0, index = index0;
  17725. var i = i0, sign;
  17726. if (allEmpty) {
  17727. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17728. if (!hasSignificantCoefficent) {
  17729. bitsDecoded[index0]++;
  17730. bitsDecoded[index0 + oneRowDown]++;
  17731. bitsDecoded[index0 + twoRowsDown]++;
  17732. bitsDecoded[index0 + threeRowsDown]++;
  17733. continue;
  17734. }
  17735. // next column
  17736. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17737. if (i1 !== 0) {
  17738. i = i0 + i1;
  17739. index += i1 * width;
  17740. }
  17741. sign = this.decodeSignBit(i, j, index);
  17742. coefficentsSign[index] = sign;
  17743. coefficentsMagnitude[index] = 1;
  17744. this.setNeighborsSignificance(i, j, index);
  17745. processingFlags[index] |= firstMagnitudeBitMask;
  17746. index = index0;
  17747. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17748. bitsDecoded[index]++;
  17749. }
  17750. i1++;
  17751. }
  17752. for (i = i0 + i1; i < iNext; i++, index += width) {
  17753. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17754. continue;
  17755. }
  17756. var contextLabel = labels[neighborsSignificance[index]];
  17757. var decision = decoder.readBit(contexts, contextLabel);
  17758. if (decision === 1) {
  17759. sign = this.decodeSignBit(i, j, index);
  17760. coefficentsSign[index] = sign;
  17761. coefficentsMagnitude[index] = 1;
  17762. this.setNeighborsSignificance(i, j, index);
  17763. processingFlags[index] |= firstMagnitudeBitMask;
  17764. }
  17765. bitsDecoded[index]++;
  17766. }
  17767. }
  17768. }
  17769. },
  17770. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17771. var decoder = this.decoder;
  17772. var contexts = this.contexts;
  17773. var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17774. if (symbol !== 0xA) {
  17775. error('JPX Error: Invalid segmentation symbol');
  17776. }
  17777. }
  17778. };
  17779. return BitModel;
  17780. }();
  17781. // Section F, Discrete wavelet transformation
  17782. var Transform = function TransformClosure() {
  17783. function Transform() {
  17784. }
  17785. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17786. var ll = subbands[0];
  17787. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17788. ll = this.iterate(ll, subbands[i], u0, v0);
  17789. }
  17790. return ll;
  17791. };
  17792. Transform.prototype.extend = function extend(buffer, offset, size) {
  17793. // Section F.3.7 extending... using max extension of 4
  17794. var i1 = offset - 1, j1 = offset + 1;
  17795. var i2 = offset + size - 2, j2 = offset + size;
  17796. buffer[i1--] = buffer[j1++];
  17797. buffer[j2++] = buffer[i2--];
  17798. buffer[i1--] = buffer[j1++];
  17799. buffer[j2++] = buffer[i2--];
  17800. buffer[i1--] = buffer[j1++];
  17801. buffer[j2++] = buffer[i2--];
  17802. buffer[i1] = buffer[j1];
  17803. buffer[j2] = buffer[i2];
  17804. };
  17805. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17806. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17807. var width = hl_lh_hh.width;
  17808. var height = hl_lh_hh.height;
  17809. var items = hl_lh_hh.items;
  17810. var i, j, k, l, u, v;
  17811. // Interleave LL according to Section F.3.3
  17812. for (k = 0, i = 0; i < llHeight; i++) {
  17813. l = i * 2 * width;
  17814. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17815. items[l] = llItems[k];
  17816. }
  17817. }
  17818. // The LL band is not needed anymore.
  17819. llItems = ll.items = null;
  17820. var bufferPadding = 4;
  17821. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17822. // Section F.3.4 HOR_SR
  17823. if (width === 1) {
  17824. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17825. if ((u0 & 1) !== 0) {
  17826. for (v = 0, k = 0; v < height; v++, k += width) {
  17827. items[k] *= 0.5;
  17828. }
  17829. }
  17830. } else {
  17831. for (v = 0, k = 0; v < height; v++, k += width) {
  17832. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17833. this.extend(rowBuffer, bufferPadding, width);
  17834. this.filter(rowBuffer, bufferPadding, width);
  17835. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17836. }
  17837. }
  17838. // Accesses to the items array can take long, because it may not fit into
  17839. // CPU cache and has to be fetched from main memory. Since subsequent
  17840. // accesses to the items array are not local when reading columns, we
  17841. // have a cache miss every time. To reduce cache misses, get up to
  17842. // 'numBuffers' items at a time and store them into the individual
  17843. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17844. var numBuffers = 16;
  17845. var colBuffers = [];
  17846. for (i = 0; i < numBuffers; i++) {
  17847. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17848. }
  17849. var b, currentBuffer = 0;
  17850. ll = bufferPadding + height;
  17851. // Section F.3.5 VER_SR
  17852. if (height === 1) {
  17853. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17854. if ((v0 & 1) !== 0) {
  17855. for (u = 0; u < width; u++) {
  17856. items[u] *= 0.5;
  17857. }
  17858. }
  17859. } else {
  17860. for (u = 0; u < width; u++) {
  17861. // if we ran out of buffers, copy several image columns at once
  17862. if (currentBuffer === 0) {
  17863. numBuffers = Math.min(width - u, numBuffers);
  17864. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17865. for (b = 0; b < numBuffers; b++) {
  17866. colBuffers[b][l] = items[k + b];
  17867. }
  17868. }
  17869. currentBuffer = numBuffers;
  17870. }
  17871. currentBuffer--;
  17872. var buffer = colBuffers[currentBuffer];
  17873. this.extend(buffer, bufferPadding, height);
  17874. this.filter(buffer, bufferPadding, height);
  17875. // If this is last buffer in this group of buffers, flush all buffers.
  17876. if (currentBuffer === 0) {
  17877. k = u - numBuffers + 1;
  17878. for (l = bufferPadding; l < ll; k += width, l++) {
  17879. for (b = 0; b < numBuffers; b++) {
  17880. items[k + b] = colBuffers[b][l];
  17881. }
  17882. }
  17883. }
  17884. }
  17885. }
  17886. return {
  17887. width: width,
  17888. height: height,
  17889. items: items
  17890. };
  17891. };
  17892. return Transform;
  17893. }();
  17894. // Section 3.8.2 Irreversible 9-7 filter
  17895. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17896. function IrreversibleTransform() {
  17897. Transform.call(this);
  17898. }
  17899. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17900. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17901. var len = length >> 1;
  17902. offset = offset | 0;
  17903. var j, n, current, next;
  17904. var alpha = -1.586134342059924;
  17905. var beta = -0.052980118572961;
  17906. var gamma = 0.882911075530934;
  17907. var delta = 0.443506852043971;
  17908. var K = 1.230174104914001;
  17909. var K_ = 1 / K;
  17910. // step 1 is combined with step 3
  17911. // step 2
  17912. j = offset - 3;
  17913. for (n = len + 4; n--; j += 2) {
  17914. x[j] *= K_;
  17915. }
  17916. // step 1 & 3
  17917. j = offset - 2;
  17918. current = delta * x[j - 1];
  17919. for (n = len + 3; n--; j += 2) {
  17920. next = delta * x[j + 1];
  17921. x[j] = K * x[j] - current - next;
  17922. if (n--) {
  17923. j += 2;
  17924. current = delta * x[j + 1];
  17925. x[j] = K * x[j] - current - next;
  17926. } else {
  17927. break;
  17928. }
  17929. }
  17930. // step 4
  17931. j = offset - 1;
  17932. current = gamma * x[j - 1];
  17933. for (n = len + 2; n--; j += 2) {
  17934. next = gamma * x[j + 1];
  17935. x[j] -= current + next;
  17936. if (n--) {
  17937. j += 2;
  17938. current = gamma * x[j + 1];
  17939. x[j] -= current + next;
  17940. } else {
  17941. break;
  17942. }
  17943. }
  17944. // step 5
  17945. j = offset;
  17946. current = beta * x[j - 1];
  17947. for (n = len + 1; n--; j += 2) {
  17948. next = beta * x[j + 1];
  17949. x[j] -= current + next;
  17950. if (n--) {
  17951. j += 2;
  17952. current = beta * x[j + 1];
  17953. x[j] -= current + next;
  17954. } else {
  17955. break;
  17956. }
  17957. }
  17958. // step 6
  17959. if (len !== 0) {
  17960. j = offset + 1;
  17961. current = alpha * x[j - 1];
  17962. for (n = len; n--; j += 2) {
  17963. next = alpha * x[j + 1];
  17964. x[j] -= current + next;
  17965. if (n--) {
  17966. j += 2;
  17967. current = alpha * x[j + 1];
  17968. x[j] -= current + next;
  17969. } else {
  17970. break;
  17971. }
  17972. }
  17973. }
  17974. };
  17975. return IrreversibleTransform;
  17976. }();
  17977. // Section 3.8.1 Reversible 5-3 filter
  17978. var ReversibleTransform = function ReversibleTransformClosure() {
  17979. function ReversibleTransform() {
  17980. Transform.call(this);
  17981. }
  17982. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17983. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17984. var len = length >> 1;
  17985. offset = offset | 0;
  17986. var j, n;
  17987. for (j = offset, n = len + 1; n--; j += 2) {
  17988. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17989. }
  17990. for (j = offset + 1, n = len; n--; j += 2) {
  17991. x[j] += x[j - 1] + x[j + 1] >> 1;
  17992. }
  17993. };
  17994. return ReversibleTransform;
  17995. }();
  17996. return JpxImage;
  17997. }();
  17998. exports.JpxImage = JpxImage;
  17999. }));
  18000. (function (root, factory) {
  18001. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  18002. }(this, function (exports, sharedUtil) {
  18003. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  18004. // The Metrics object contains glyph widths (in glyph space units).
  18005. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  18006. // space unit corresponds to 1/1000th of text space unit.
  18007. var getMetrics = getLookupTableFactory(function (t) {
  18008. t['Courier'] = 600;
  18009. t['Courier-Bold'] = 600;
  18010. t['Courier-BoldOblique'] = 600;
  18011. t['Courier-Oblique'] = 600;
  18012. t['Helvetica'] = getLookupTableFactory(function (t) {
  18013. t['space'] = 278;
  18014. t['exclam'] = 278;
  18015. t['quotedbl'] = 355;
  18016. t['numbersign'] = 556;
  18017. t['dollar'] = 556;
  18018. t['percent'] = 889;
  18019. t['ampersand'] = 667;
  18020. t['quoteright'] = 222;
  18021. t['parenleft'] = 333;
  18022. t['parenright'] = 333;
  18023. t['asterisk'] = 389;
  18024. t['plus'] = 584;
  18025. t['comma'] = 278;
  18026. t['hyphen'] = 333;
  18027. t['period'] = 278;
  18028. t['slash'] = 278;
  18029. t['zero'] = 556;
  18030. t['one'] = 556;
  18031. t['two'] = 556;
  18032. t['three'] = 556;
  18033. t['four'] = 556;
  18034. t['five'] = 556;
  18035. t['six'] = 556;
  18036. t['seven'] = 556;
  18037. t['eight'] = 556;
  18038. t['nine'] = 556;
  18039. t['colon'] = 278;
  18040. t['semicolon'] = 278;
  18041. t['less'] = 584;
  18042. t['equal'] = 584;
  18043. t['greater'] = 584;
  18044. t['question'] = 556;
  18045. t['at'] = 1015;
  18046. t['A'] = 667;
  18047. t['B'] = 667;
  18048. t['C'] = 722;
  18049. t['D'] = 722;
  18050. t['E'] = 667;
  18051. t['F'] = 611;
  18052. t['G'] = 778;
  18053. t['H'] = 722;
  18054. t['I'] = 278;
  18055. t['J'] = 500;
  18056. t['K'] = 667;
  18057. t['L'] = 556;
  18058. t['M'] = 833;
  18059. t['N'] = 722;
  18060. t['O'] = 778;
  18061. t['P'] = 667;
  18062. t['Q'] = 778;
  18063. t['R'] = 722;
  18064. t['S'] = 667;
  18065. t['T'] = 611;
  18066. t['U'] = 722;
  18067. t['V'] = 667;
  18068. t['W'] = 944;
  18069. t['X'] = 667;
  18070. t['Y'] = 667;
  18071. t['Z'] = 611;
  18072. t['bracketleft'] = 278;
  18073. t['backslash'] = 278;
  18074. t['bracketright'] = 278;
  18075. t['asciicircum'] = 469;
  18076. t['underscore'] = 556;
  18077. t['quoteleft'] = 222;
  18078. t['a'] = 556;
  18079. t['b'] = 556;
  18080. t['c'] = 500;
  18081. t['d'] = 556;
  18082. t['e'] = 556;
  18083. t['f'] = 278;
  18084. t['g'] = 556;
  18085. t['h'] = 556;
  18086. t['i'] = 222;
  18087. t['j'] = 222;
  18088. t['k'] = 500;
  18089. t['l'] = 222;
  18090. t['m'] = 833;
  18091. t['n'] = 556;
  18092. t['o'] = 556;
  18093. t['p'] = 556;
  18094. t['q'] = 556;
  18095. t['r'] = 333;
  18096. t['s'] = 500;
  18097. t['t'] = 278;
  18098. t['u'] = 556;
  18099. t['v'] = 500;
  18100. t['w'] = 722;
  18101. t['x'] = 500;
  18102. t['y'] = 500;
  18103. t['z'] = 500;
  18104. t['braceleft'] = 334;
  18105. t['bar'] = 260;
  18106. t['braceright'] = 334;
  18107. t['asciitilde'] = 584;
  18108. t['exclamdown'] = 333;
  18109. t['cent'] = 556;
  18110. t['sterling'] = 556;
  18111. t['fraction'] = 167;
  18112. t['yen'] = 556;
  18113. t['florin'] = 556;
  18114. t['section'] = 556;
  18115. t['currency'] = 556;
  18116. t['quotesingle'] = 191;
  18117. t['quotedblleft'] = 333;
  18118. t['guillemotleft'] = 556;
  18119. t['guilsinglleft'] = 333;
  18120. t['guilsinglright'] = 333;
  18121. t['fi'] = 500;
  18122. t['fl'] = 500;
  18123. t['endash'] = 556;
  18124. t['dagger'] = 556;
  18125. t['daggerdbl'] = 556;
  18126. t['periodcentered'] = 278;
  18127. t['paragraph'] = 537;
  18128. t['bullet'] = 350;
  18129. t['quotesinglbase'] = 222;
  18130. t['quotedblbase'] = 333;
  18131. t['quotedblright'] = 333;
  18132. t['guillemotright'] = 556;
  18133. t['ellipsis'] = 1000;
  18134. t['perthousand'] = 1000;
  18135. t['questiondown'] = 611;
  18136. t['grave'] = 333;
  18137. t['acute'] = 333;
  18138. t['circumflex'] = 333;
  18139. t['tilde'] = 333;
  18140. t['macron'] = 333;
  18141. t['breve'] = 333;
  18142. t['dotaccent'] = 333;
  18143. t['dieresis'] = 333;
  18144. t['ring'] = 333;
  18145. t['cedilla'] = 333;
  18146. t['hungarumlaut'] = 333;
  18147. t['ogonek'] = 333;
  18148. t['caron'] = 333;
  18149. t['emdash'] = 1000;
  18150. t['AE'] = 1000;
  18151. t['ordfeminine'] = 370;
  18152. t['Lslash'] = 556;
  18153. t['Oslash'] = 778;
  18154. t['OE'] = 1000;
  18155. t['ordmasculine'] = 365;
  18156. t['ae'] = 889;
  18157. t['dotlessi'] = 278;
  18158. t['lslash'] = 222;
  18159. t['oslash'] = 611;
  18160. t['oe'] = 944;
  18161. t['germandbls'] = 611;
  18162. t['Idieresis'] = 278;
  18163. t['eacute'] = 556;
  18164. t['abreve'] = 556;
  18165. t['uhungarumlaut'] = 556;
  18166. t['ecaron'] = 556;
  18167. t['Ydieresis'] = 667;
  18168. t['divide'] = 584;
  18169. t['Yacute'] = 667;
  18170. t['Acircumflex'] = 667;
  18171. t['aacute'] = 556;
  18172. t['Ucircumflex'] = 722;
  18173. t['yacute'] = 500;
  18174. t['scommaaccent'] = 500;
  18175. t['ecircumflex'] = 556;
  18176. t['Uring'] = 722;
  18177. t['Udieresis'] = 722;
  18178. t['aogonek'] = 556;
  18179. t['Uacute'] = 722;
  18180. t['uogonek'] = 556;
  18181. t['Edieresis'] = 667;
  18182. t['Dcroat'] = 722;
  18183. t['commaaccent'] = 250;
  18184. t['copyright'] = 737;
  18185. t['Emacron'] = 667;
  18186. t['ccaron'] = 500;
  18187. t['aring'] = 556;
  18188. t['Ncommaaccent'] = 722;
  18189. t['lacute'] = 222;
  18190. t['agrave'] = 556;
  18191. t['Tcommaaccent'] = 611;
  18192. t['Cacute'] = 722;
  18193. t['atilde'] = 556;
  18194. t['Edotaccent'] = 667;
  18195. t['scaron'] = 500;
  18196. t['scedilla'] = 500;
  18197. t['iacute'] = 278;
  18198. t['lozenge'] = 471;
  18199. t['Rcaron'] = 722;
  18200. t['Gcommaaccent'] = 778;
  18201. t['ucircumflex'] = 556;
  18202. t['acircumflex'] = 556;
  18203. t['Amacron'] = 667;
  18204. t['rcaron'] = 333;
  18205. t['ccedilla'] = 500;
  18206. t['Zdotaccent'] = 611;
  18207. t['Thorn'] = 667;
  18208. t['Omacron'] = 778;
  18209. t['Racute'] = 722;
  18210. t['Sacute'] = 667;
  18211. t['dcaron'] = 643;
  18212. t['Umacron'] = 722;
  18213. t['uring'] = 556;
  18214. t['threesuperior'] = 333;
  18215. t['Ograve'] = 778;
  18216. t['Agrave'] = 667;
  18217. t['Abreve'] = 667;
  18218. t['multiply'] = 584;
  18219. t['uacute'] = 556;
  18220. t['Tcaron'] = 611;
  18221. t['partialdiff'] = 476;
  18222. t['ydieresis'] = 500;
  18223. t['Nacute'] = 722;
  18224. t['icircumflex'] = 278;
  18225. t['Ecircumflex'] = 667;
  18226. t['adieresis'] = 556;
  18227. t['edieresis'] = 556;
  18228. t['cacute'] = 500;
  18229. t['nacute'] = 556;
  18230. t['umacron'] = 556;
  18231. t['Ncaron'] = 722;
  18232. t['Iacute'] = 278;
  18233. t['plusminus'] = 584;
  18234. t['brokenbar'] = 260;
  18235. t['registered'] = 737;
  18236. t['Gbreve'] = 778;
  18237. t['Idotaccent'] = 278;
  18238. t['summation'] = 600;
  18239. t['Egrave'] = 667;
  18240. t['racute'] = 333;
  18241. t['omacron'] = 556;
  18242. t['Zacute'] = 611;
  18243. t['Zcaron'] = 611;
  18244. t['greaterequal'] = 549;
  18245. t['Eth'] = 722;
  18246. t['Ccedilla'] = 722;
  18247. t['lcommaaccent'] = 222;
  18248. t['tcaron'] = 317;
  18249. t['eogonek'] = 556;
  18250. t['Uogonek'] = 722;
  18251. t['Aacute'] = 667;
  18252. t['Adieresis'] = 667;
  18253. t['egrave'] = 556;
  18254. t['zacute'] = 500;
  18255. t['iogonek'] = 222;
  18256. t['Oacute'] = 778;
  18257. t['oacute'] = 556;
  18258. t['amacron'] = 556;
  18259. t['sacute'] = 500;
  18260. t['idieresis'] = 278;
  18261. t['Ocircumflex'] = 778;
  18262. t['Ugrave'] = 722;
  18263. t['Delta'] = 612;
  18264. t['thorn'] = 556;
  18265. t['twosuperior'] = 333;
  18266. t['Odieresis'] = 778;
  18267. t['mu'] = 556;
  18268. t['igrave'] = 278;
  18269. t['ohungarumlaut'] = 556;
  18270. t['Eogonek'] = 667;
  18271. t['dcroat'] = 556;
  18272. t['threequarters'] = 834;
  18273. t['Scedilla'] = 667;
  18274. t['lcaron'] = 299;
  18275. t['Kcommaaccent'] = 667;
  18276. t['Lacute'] = 556;
  18277. t['trademark'] = 1000;
  18278. t['edotaccent'] = 556;
  18279. t['Igrave'] = 278;
  18280. t['Imacron'] = 278;
  18281. t['Lcaron'] = 556;
  18282. t['onehalf'] = 834;
  18283. t['lessequal'] = 549;
  18284. t['ocircumflex'] = 556;
  18285. t['ntilde'] = 556;
  18286. t['Uhungarumlaut'] = 722;
  18287. t['Eacute'] = 667;
  18288. t['emacron'] = 556;
  18289. t['gbreve'] = 556;
  18290. t['onequarter'] = 834;
  18291. t['Scaron'] = 667;
  18292. t['Scommaaccent'] = 667;
  18293. t['Ohungarumlaut'] = 778;
  18294. t['degree'] = 400;
  18295. t['ograve'] = 556;
  18296. t['Ccaron'] = 722;
  18297. t['ugrave'] = 556;
  18298. t['radical'] = 453;
  18299. t['Dcaron'] = 722;
  18300. t['rcommaaccent'] = 333;
  18301. t['Ntilde'] = 722;
  18302. t['otilde'] = 556;
  18303. t['Rcommaaccent'] = 722;
  18304. t['Lcommaaccent'] = 556;
  18305. t['Atilde'] = 667;
  18306. t['Aogonek'] = 667;
  18307. t['Aring'] = 667;
  18308. t['Otilde'] = 778;
  18309. t['zdotaccent'] = 500;
  18310. t['Ecaron'] = 667;
  18311. t['Iogonek'] = 278;
  18312. t['kcommaaccent'] = 500;
  18313. t['minus'] = 584;
  18314. t['Icircumflex'] = 278;
  18315. t['ncaron'] = 556;
  18316. t['tcommaaccent'] = 278;
  18317. t['logicalnot'] = 584;
  18318. t['odieresis'] = 556;
  18319. t['udieresis'] = 556;
  18320. t['notequal'] = 549;
  18321. t['gcommaaccent'] = 556;
  18322. t['eth'] = 556;
  18323. t['zcaron'] = 500;
  18324. t['ncommaaccent'] = 556;
  18325. t['onesuperior'] = 333;
  18326. t['imacron'] = 278;
  18327. t['Euro'] = 556;
  18328. });
  18329. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18330. t['space'] = 278;
  18331. t['exclam'] = 333;
  18332. t['quotedbl'] = 474;
  18333. t['numbersign'] = 556;
  18334. t['dollar'] = 556;
  18335. t['percent'] = 889;
  18336. t['ampersand'] = 722;
  18337. t['quoteright'] = 278;
  18338. t['parenleft'] = 333;
  18339. t['parenright'] = 333;
  18340. t['asterisk'] = 389;
  18341. t['plus'] = 584;
  18342. t['comma'] = 278;
  18343. t['hyphen'] = 333;
  18344. t['period'] = 278;
  18345. t['slash'] = 278;
  18346. t['zero'] = 556;
  18347. t['one'] = 556;
  18348. t['two'] = 556;
  18349. t['three'] = 556;
  18350. t['four'] = 556;
  18351. t['five'] = 556;
  18352. t['six'] = 556;
  18353. t['seven'] = 556;
  18354. t['eight'] = 556;
  18355. t['nine'] = 556;
  18356. t['colon'] = 333;
  18357. t['semicolon'] = 333;
  18358. t['less'] = 584;
  18359. t['equal'] = 584;
  18360. t['greater'] = 584;
  18361. t['question'] = 611;
  18362. t['at'] = 975;
  18363. t['A'] = 722;
  18364. t['B'] = 722;
  18365. t['C'] = 722;
  18366. t['D'] = 722;
  18367. t['E'] = 667;
  18368. t['F'] = 611;
  18369. t['G'] = 778;
  18370. t['H'] = 722;
  18371. t['I'] = 278;
  18372. t['J'] = 556;
  18373. t['K'] = 722;
  18374. t['L'] = 611;
  18375. t['M'] = 833;
  18376. t['N'] = 722;
  18377. t['O'] = 778;
  18378. t['P'] = 667;
  18379. t['Q'] = 778;
  18380. t['R'] = 722;
  18381. t['S'] = 667;
  18382. t['T'] = 611;
  18383. t['U'] = 722;
  18384. t['V'] = 667;
  18385. t['W'] = 944;
  18386. t['X'] = 667;
  18387. t['Y'] = 667;
  18388. t['Z'] = 611;
  18389. t['bracketleft'] = 333;
  18390. t['backslash'] = 278;
  18391. t['bracketright'] = 333;
  18392. t['asciicircum'] = 584;
  18393. t['underscore'] = 556;
  18394. t['quoteleft'] = 278;
  18395. t['a'] = 556;
  18396. t['b'] = 611;
  18397. t['c'] = 556;
  18398. t['d'] = 611;
  18399. t['e'] = 556;
  18400. t['f'] = 333;
  18401. t['g'] = 611;
  18402. t['h'] = 611;
  18403. t['i'] = 278;
  18404. t['j'] = 278;
  18405. t['k'] = 556;
  18406. t['l'] = 278;
  18407. t['m'] = 889;
  18408. t['n'] = 611;
  18409. t['o'] = 611;
  18410. t['p'] = 611;
  18411. t['q'] = 611;
  18412. t['r'] = 389;
  18413. t['s'] = 556;
  18414. t['t'] = 333;
  18415. t['u'] = 611;
  18416. t['v'] = 556;
  18417. t['w'] = 778;
  18418. t['x'] = 556;
  18419. t['y'] = 556;
  18420. t['z'] = 500;
  18421. t['braceleft'] = 389;
  18422. t['bar'] = 280;
  18423. t['braceright'] = 389;
  18424. t['asciitilde'] = 584;
  18425. t['exclamdown'] = 333;
  18426. t['cent'] = 556;
  18427. t['sterling'] = 556;
  18428. t['fraction'] = 167;
  18429. t['yen'] = 556;
  18430. t['florin'] = 556;
  18431. t['section'] = 556;
  18432. t['currency'] = 556;
  18433. t['quotesingle'] = 238;
  18434. t['quotedblleft'] = 500;
  18435. t['guillemotleft'] = 556;
  18436. t['guilsinglleft'] = 333;
  18437. t['guilsinglright'] = 333;
  18438. t['fi'] = 611;
  18439. t['fl'] = 611;
  18440. t['endash'] = 556;
  18441. t['dagger'] = 556;
  18442. t['daggerdbl'] = 556;
  18443. t['periodcentered'] = 278;
  18444. t['paragraph'] = 556;
  18445. t['bullet'] = 350;
  18446. t['quotesinglbase'] = 278;
  18447. t['quotedblbase'] = 500;
  18448. t['quotedblright'] = 500;
  18449. t['guillemotright'] = 556;
  18450. t['ellipsis'] = 1000;
  18451. t['perthousand'] = 1000;
  18452. t['questiondown'] = 611;
  18453. t['grave'] = 333;
  18454. t['acute'] = 333;
  18455. t['circumflex'] = 333;
  18456. t['tilde'] = 333;
  18457. t['macron'] = 333;
  18458. t['breve'] = 333;
  18459. t['dotaccent'] = 333;
  18460. t['dieresis'] = 333;
  18461. t['ring'] = 333;
  18462. t['cedilla'] = 333;
  18463. t['hungarumlaut'] = 333;
  18464. t['ogonek'] = 333;
  18465. t['caron'] = 333;
  18466. t['emdash'] = 1000;
  18467. t['AE'] = 1000;
  18468. t['ordfeminine'] = 370;
  18469. t['Lslash'] = 611;
  18470. t['Oslash'] = 778;
  18471. t['OE'] = 1000;
  18472. t['ordmasculine'] = 365;
  18473. t['ae'] = 889;
  18474. t['dotlessi'] = 278;
  18475. t['lslash'] = 278;
  18476. t['oslash'] = 611;
  18477. t['oe'] = 944;
  18478. t['germandbls'] = 611;
  18479. t['Idieresis'] = 278;
  18480. t['eacute'] = 556;
  18481. t['abreve'] = 556;
  18482. t['uhungarumlaut'] = 611;
  18483. t['ecaron'] = 556;
  18484. t['Ydieresis'] = 667;
  18485. t['divide'] = 584;
  18486. t['Yacute'] = 667;
  18487. t['Acircumflex'] = 722;
  18488. t['aacute'] = 556;
  18489. t['Ucircumflex'] = 722;
  18490. t['yacute'] = 556;
  18491. t['scommaaccent'] = 556;
  18492. t['ecircumflex'] = 556;
  18493. t['Uring'] = 722;
  18494. t['Udieresis'] = 722;
  18495. t['aogonek'] = 556;
  18496. t['Uacute'] = 722;
  18497. t['uogonek'] = 611;
  18498. t['Edieresis'] = 667;
  18499. t['Dcroat'] = 722;
  18500. t['commaaccent'] = 250;
  18501. t['copyright'] = 737;
  18502. t['Emacron'] = 667;
  18503. t['ccaron'] = 556;
  18504. t['aring'] = 556;
  18505. t['Ncommaaccent'] = 722;
  18506. t['lacute'] = 278;
  18507. t['agrave'] = 556;
  18508. t['Tcommaaccent'] = 611;
  18509. t['Cacute'] = 722;
  18510. t['atilde'] = 556;
  18511. t['Edotaccent'] = 667;
  18512. t['scaron'] = 556;
  18513. t['scedilla'] = 556;
  18514. t['iacute'] = 278;
  18515. t['lozenge'] = 494;
  18516. t['Rcaron'] = 722;
  18517. t['Gcommaaccent'] = 778;
  18518. t['ucircumflex'] = 611;
  18519. t['acircumflex'] = 556;
  18520. t['Amacron'] = 722;
  18521. t['rcaron'] = 389;
  18522. t['ccedilla'] = 556;
  18523. t['Zdotaccent'] = 611;
  18524. t['Thorn'] = 667;
  18525. t['Omacron'] = 778;
  18526. t['Racute'] = 722;
  18527. t['Sacute'] = 667;
  18528. t['dcaron'] = 743;
  18529. t['Umacron'] = 722;
  18530. t['uring'] = 611;
  18531. t['threesuperior'] = 333;
  18532. t['Ograve'] = 778;
  18533. t['Agrave'] = 722;
  18534. t['Abreve'] = 722;
  18535. t['multiply'] = 584;
  18536. t['uacute'] = 611;
  18537. t['Tcaron'] = 611;
  18538. t['partialdiff'] = 494;
  18539. t['ydieresis'] = 556;
  18540. t['Nacute'] = 722;
  18541. t['icircumflex'] = 278;
  18542. t['Ecircumflex'] = 667;
  18543. t['adieresis'] = 556;
  18544. t['edieresis'] = 556;
  18545. t['cacute'] = 556;
  18546. t['nacute'] = 611;
  18547. t['umacron'] = 611;
  18548. t['Ncaron'] = 722;
  18549. t['Iacute'] = 278;
  18550. t['plusminus'] = 584;
  18551. t['brokenbar'] = 280;
  18552. t['registered'] = 737;
  18553. t['Gbreve'] = 778;
  18554. t['Idotaccent'] = 278;
  18555. t['summation'] = 600;
  18556. t['Egrave'] = 667;
  18557. t['racute'] = 389;
  18558. t['omacron'] = 611;
  18559. t['Zacute'] = 611;
  18560. t['Zcaron'] = 611;
  18561. t['greaterequal'] = 549;
  18562. t['Eth'] = 722;
  18563. t['Ccedilla'] = 722;
  18564. t['lcommaaccent'] = 278;
  18565. t['tcaron'] = 389;
  18566. t['eogonek'] = 556;
  18567. t['Uogonek'] = 722;
  18568. t['Aacute'] = 722;
  18569. t['Adieresis'] = 722;
  18570. t['egrave'] = 556;
  18571. t['zacute'] = 500;
  18572. t['iogonek'] = 278;
  18573. t['Oacute'] = 778;
  18574. t['oacute'] = 611;
  18575. t['amacron'] = 556;
  18576. t['sacute'] = 556;
  18577. t['idieresis'] = 278;
  18578. t['Ocircumflex'] = 778;
  18579. t['Ugrave'] = 722;
  18580. t['Delta'] = 612;
  18581. t['thorn'] = 611;
  18582. t['twosuperior'] = 333;
  18583. t['Odieresis'] = 778;
  18584. t['mu'] = 611;
  18585. t['igrave'] = 278;
  18586. t['ohungarumlaut'] = 611;
  18587. t['Eogonek'] = 667;
  18588. t['dcroat'] = 611;
  18589. t['threequarters'] = 834;
  18590. t['Scedilla'] = 667;
  18591. t['lcaron'] = 400;
  18592. t['Kcommaaccent'] = 722;
  18593. t['Lacute'] = 611;
  18594. t['trademark'] = 1000;
  18595. t['edotaccent'] = 556;
  18596. t['Igrave'] = 278;
  18597. t['Imacron'] = 278;
  18598. t['Lcaron'] = 611;
  18599. t['onehalf'] = 834;
  18600. t['lessequal'] = 549;
  18601. t['ocircumflex'] = 611;
  18602. t['ntilde'] = 611;
  18603. t['Uhungarumlaut'] = 722;
  18604. t['Eacute'] = 667;
  18605. t['emacron'] = 556;
  18606. t['gbreve'] = 611;
  18607. t['onequarter'] = 834;
  18608. t['Scaron'] = 667;
  18609. t['Scommaaccent'] = 667;
  18610. t['Ohungarumlaut'] = 778;
  18611. t['degree'] = 400;
  18612. t['ograve'] = 611;
  18613. t['Ccaron'] = 722;
  18614. t['ugrave'] = 611;
  18615. t['radical'] = 549;
  18616. t['Dcaron'] = 722;
  18617. t['rcommaaccent'] = 389;
  18618. t['Ntilde'] = 722;
  18619. t['otilde'] = 611;
  18620. t['Rcommaaccent'] = 722;
  18621. t['Lcommaaccent'] = 611;
  18622. t['Atilde'] = 722;
  18623. t['Aogonek'] = 722;
  18624. t['Aring'] = 722;
  18625. t['Otilde'] = 778;
  18626. t['zdotaccent'] = 500;
  18627. t['Ecaron'] = 667;
  18628. t['Iogonek'] = 278;
  18629. t['kcommaaccent'] = 556;
  18630. t['minus'] = 584;
  18631. t['Icircumflex'] = 278;
  18632. t['ncaron'] = 611;
  18633. t['tcommaaccent'] = 333;
  18634. t['logicalnot'] = 584;
  18635. t['odieresis'] = 611;
  18636. t['udieresis'] = 611;
  18637. t['notequal'] = 549;
  18638. t['gcommaaccent'] = 611;
  18639. t['eth'] = 611;
  18640. t['zcaron'] = 500;
  18641. t['ncommaaccent'] = 611;
  18642. t['onesuperior'] = 333;
  18643. t['imacron'] = 278;
  18644. t['Euro'] = 556;
  18645. });
  18646. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18647. t['space'] = 278;
  18648. t['exclam'] = 333;
  18649. t['quotedbl'] = 474;
  18650. t['numbersign'] = 556;
  18651. t['dollar'] = 556;
  18652. t['percent'] = 889;
  18653. t['ampersand'] = 722;
  18654. t['quoteright'] = 278;
  18655. t['parenleft'] = 333;
  18656. t['parenright'] = 333;
  18657. t['asterisk'] = 389;
  18658. t['plus'] = 584;
  18659. t['comma'] = 278;
  18660. t['hyphen'] = 333;
  18661. t['period'] = 278;
  18662. t['slash'] = 278;
  18663. t['zero'] = 556;
  18664. t['one'] = 556;
  18665. t['two'] = 556;
  18666. t['three'] = 556;
  18667. t['four'] = 556;
  18668. t['five'] = 556;
  18669. t['six'] = 556;
  18670. t['seven'] = 556;
  18671. t['eight'] = 556;
  18672. t['nine'] = 556;
  18673. t['colon'] = 333;
  18674. t['semicolon'] = 333;
  18675. t['less'] = 584;
  18676. t['equal'] = 584;
  18677. t['greater'] = 584;
  18678. t['question'] = 611;
  18679. t['at'] = 975;
  18680. t['A'] = 722;
  18681. t['B'] = 722;
  18682. t['C'] = 722;
  18683. t['D'] = 722;
  18684. t['E'] = 667;
  18685. t['F'] = 611;
  18686. t['G'] = 778;
  18687. t['H'] = 722;
  18688. t['I'] = 278;
  18689. t['J'] = 556;
  18690. t['K'] = 722;
  18691. t['L'] = 611;
  18692. t['M'] = 833;
  18693. t['N'] = 722;
  18694. t['O'] = 778;
  18695. t['P'] = 667;
  18696. t['Q'] = 778;
  18697. t['R'] = 722;
  18698. t['S'] = 667;
  18699. t['T'] = 611;
  18700. t['U'] = 722;
  18701. t['V'] = 667;
  18702. t['W'] = 944;
  18703. t['X'] = 667;
  18704. t['Y'] = 667;
  18705. t['Z'] = 611;
  18706. t['bracketleft'] = 333;
  18707. t['backslash'] = 278;
  18708. t['bracketright'] = 333;
  18709. t['asciicircum'] = 584;
  18710. t['underscore'] = 556;
  18711. t['quoteleft'] = 278;
  18712. t['a'] = 556;
  18713. t['b'] = 611;
  18714. t['c'] = 556;
  18715. t['d'] = 611;
  18716. t['e'] = 556;
  18717. t['f'] = 333;
  18718. t['g'] = 611;
  18719. t['h'] = 611;
  18720. t['i'] = 278;
  18721. t['j'] = 278;
  18722. t['k'] = 556;
  18723. t['l'] = 278;
  18724. t['m'] = 889;
  18725. t['n'] = 611;
  18726. t['o'] = 611;
  18727. t['p'] = 611;
  18728. t['q'] = 611;
  18729. t['r'] = 389;
  18730. t['s'] = 556;
  18731. t['t'] = 333;
  18732. t['u'] = 611;
  18733. t['v'] = 556;
  18734. t['w'] = 778;
  18735. t['x'] = 556;
  18736. t['y'] = 556;
  18737. t['z'] = 500;
  18738. t['braceleft'] = 389;
  18739. t['bar'] = 280;
  18740. t['braceright'] = 389;
  18741. t['asciitilde'] = 584;
  18742. t['exclamdown'] = 333;
  18743. t['cent'] = 556;
  18744. t['sterling'] = 556;
  18745. t['fraction'] = 167;
  18746. t['yen'] = 556;
  18747. t['florin'] = 556;
  18748. t['section'] = 556;
  18749. t['currency'] = 556;
  18750. t['quotesingle'] = 238;
  18751. t['quotedblleft'] = 500;
  18752. t['guillemotleft'] = 556;
  18753. t['guilsinglleft'] = 333;
  18754. t['guilsinglright'] = 333;
  18755. t['fi'] = 611;
  18756. t['fl'] = 611;
  18757. t['endash'] = 556;
  18758. t['dagger'] = 556;
  18759. t['daggerdbl'] = 556;
  18760. t['periodcentered'] = 278;
  18761. t['paragraph'] = 556;
  18762. t['bullet'] = 350;
  18763. t['quotesinglbase'] = 278;
  18764. t['quotedblbase'] = 500;
  18765. t['quotedblright'] = 500;
  18766. t['guillemotright'] = 556;
  18767. t['ellipsis'] = 1000;
  18768. t['perthousand'] = 1000;
  18769. t['questiondown'] = 611;
  18770. t['grave'] = 333;
  18771. t['acute'] = 333;
  18772. t['circumflex'] = 333;
  18773. t['tilde'] = 333;
  18774. t['macron'] = 333;
  18775. t['breve'] = 333;
  18776. t['dotaccent'] = 333;
  18777. t['dieresis'] = 333;
  18778. t['ring'] = 333;
  18779. t['cedilla'] = 333;
  18780. t['hungarumlaut'] = 333;
  18781. t['ogonek'] = 333;
  18782. t['caron'] = 333;
  18783. t['emdash'] = 1000;
  18784. t['AE'] = 1000;
  18785. t['ordfeminine'] = 370;
  18786. t['Lslash'] = 611;
  18787. t['Oslash'] = 778;
  18788. t['OE'] = 1000;
  18789. t['ordmasculine'] = 365;
  18790. t['ae'] = 889;
  18791. t['dotlessi'] = 278;
  18792. t['lslash'] = 278;
  18793. t['oslash'] = 611;
  18794. t['oe'] = 944;
  18795. t['germandbls'] = 611;
  18796. t['Idieresis'] = 278;
  18797. t['eacute'] = 556;
  18798. t['abreve'] = 556;
  18799. t['uhungarumlaut'] = 611;
  18800. t['ecaron'] = 556;
  18801. t['Ydieresis'] = 667;
  18802. t['divide'] = 584;
  18803. t['Yacute'] = 667;
  18804. t['Acircumflex'] = 722;
  18805. t['aacute'] = 556;
  18806. t['Ucircumflex'] = 722;
  18807. t['yacute'] = 556;
  18808. t['scommaaccent'] = 556;
  18809. t['ecircumflex'] = 556;
  18810. t['Uring'] = 722;
  18811. t['Udieresis'] = 722;
  18812. t['aogonek'] = 556;
  18813. t['Uacute'] = 722;
  18814. t['uogonek'] = 611;
  18815. t['Edieresis'] = 667;
  18816. t['Dcroat'] = 722;
  18817. t['commaaccent'] = 250;
  18818. t['copyright'] = 737;
  18819. t['Emacron'] = 667;
  18820. t['ccaron'] = 556;
  18821. t['aring'] = 556;
  18822. t['Ncommaaccent'] = 722;
  18823. t['lacute'] = 278;
  18824. t['agrave'] = 556;
  18825. t['Tcommaaccent'] = 611;
  18826. t['Cacute'] = 722;
  18827. t['atilde'] = 556;
  18828. t['Edotaccent'] = 667;
  18829. t['scaron'] = 556;
  18830. t['scedilla'] = 556;
  18831. t['iacute'] = 278;
  18832. t['lozenge'] = 494;
  18833. t['Rcaron'] = 722;
  18834. t['Gcommaaccent'] = 778;
  18835. t['ucircumflex'] = 611;
  18836. t['acircumflex'] = 556;
  18837. t['Amacron'] = 722;
  18838. t['rcaron'] = 389;
  18839. t['ccedilla'] = 556;
  18840. t['Zdotaccent'] = 611;
  18841. t['Thorn'] = 667;
  18842. t['Omacron'] = 778;
  18843. t['Racute'] = 722;
  18844. t['Sacute'] = 667;
  18845. t['dcaron'] = 743;
  18846. t['Umacron'] = 722;
  18847. t['uring'] = 611;
  18848. t['threesuperior'] = 333;
  18849. t['Ograve'] = 778;
  18850. t['Agrave'] = 722;
  18851. t['Abreve'] = 722;
  18852. t['multiply'] = 584;
  18853. t['uacute'] = 611;
  18854. t['Tcaron'] = 611;
  18855. t['partialdiff'] = 494;
  18856. t['ydieresis'] = 556;
  18857. t['Nacute'] = 722;
  18858. t['icircumflex'] = 278;
  18859. t['Ecircumflex'] = 667;
  18860. t['adieresis'] = 556;
  18861. t['edieresis'] = 556;
  18862. t['cacute'] = 556;
  18863. t['nacute'] = 611;
  18864. t['umacron'] = 611;
  18865. t['Ncaron'] = 722;
  18866. t['Iacute'] = 278;
  18867. t['plusminus'] = 584;
  18868. t['brokenbar'] = 280;
  18869. t['registered'] = 737;
  18870. t['Gbreve'] = 778;
  18871. t['Idotaccent'] = 278;
  18872. t['summation'] = 600;
  18873. t['Egrave'] = 667;
  18874. t['racute'] = 389;
  18875. t['omacron'] = 611;
  18876. t['Zacute'] = 611;
  18877. t['Zcaron'] = 611;
  18878. t['greaterequal'] = 549;
  18879. t['Eth'] = 722;
  18880. t['Ccedilla'] = 722;
  18881. t['lcommaaccent'] = 278;
  18882. t['tcaron'] = 389;
  18883. t['eogonek'] = 556;
  18884. t['Uogonek'] = 722;
  18885. t['Aacute'] = 722;
  18886. t['Adieresis'] = 722;
  18887. t['egrave'] = 556;
  18888. t['zacute'] = 500;
  18889. t['iogonek'] = 278;
  18890. t['Oacute'] = 778;
  18891. t['oacute'] = 611;
  18892. t['amacron'] = 556;
  18893. t['sacute'] = 556;
  18894. t['idieresis'] = 278;
  18895. t['Ocircumflex'] = 778;
  18896. t['Ugrave'] = 722;
  18897. t['Delta'] = 612;
  18898. t['thorn'] = 611;
  18899. t['twosuperior'] = 333;
  18900. t['Odieresis'] = 778;
  18901. t['mu'] = 611;
  18902. t['igrave'] = 278;
  18903. t['ohungarumlaut'] = 611;
  18904. t['Eogonek'] = 667;
  18905. t['dcroat'] = 611;
  18906. t['threequarters'] = 834;
  18907. t['Scedilla'] = 667;
  18908. t['lcaron'] = 400;
  18909. t['Kcommaaccent'] = 722;
  18910. t['Lacute'] = 611;
  18911. t['trademark'] = 1000;
  18912. t['edotaccent'] = 556;
  18913. t['Igrave'] = 278;
  18914. t['Imacron'] = 278;
  18915. t['Lcaron'] = 611;
  18916. t['onehalf'] = 834;
  18917. t['lessequal'] = 549;
  18918. t['ocircumflex'] = 611;
  18919. t['ntilde'] = 611;
  18920. t['Uhungarumlaut'] = 722;
  18921. t['Eacute'] = 667;
  18922. t['emacron'] = 556;
  18923. t['gbreve'] = 611;
  18924. t['onequarter'] = 834;
  18925. t['Scaron'] = 667;
  18926. t['Scommaaccent'] = 667;
  18927. t['Ohungarumlaut'] = 778;
  18928. t['degree'] = 400;
  18929. t['ograve'] = 611;
  18930. t['Ccaron'] = 722;
  18931. t['ugrave'] = 611;
  18932. t['radical'] = 549;
  18933. t['Dcaron'] = 722;
  18934. t['rcommaaccent'] = 389;
  18935. t['Ntilde'] = 722;
  18936. t['otilde'] = 611;
  18937. t['Rcommaaccent'] = 722;
  18938. t['Lcommaaccent'] = 611;
  18939. t['Atilde'] = 722;
  18940. t['Aogonek'] = 722;
  18941. t['Aring'] = 722;
  18942. t['Otilde'] = 778;
  18943. t['zdotaccent'] = 500;
  18944. t['Ecaron'] = 667;
  18945. t['Iogonek'] = 278;
  18946. t['kcommaaccent'] = 556;
  18947. t['minus'] = 584;
  18948. t['Icircumflex'] = 278;
  18949. t['ncaron'] = 611;
  18950. t['tcommaaccent'] = 333;
  18951. t['logicalnot'] = 584;
  18952. t['odieresis'] = 611;
  18953. t['udieresis'] = 611;
  18954. t['notequal'] = 549;
  18955. t['gcommaaccent'] = 611;
  18956. t['eth'] = 611;
  18957. t['zcaron'] = 500;
  18958. t['ncommaaccent'] = 611;
  18959. t['onesuperior'] = 333;
  18960. t['imacron'] = 278;
  18961. t['Euro'] = 556;
  18962. });
  18963. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18964. t['space'] = 278;
  18965. t['exclam'] = 278;
  18966. t['quotedbl'] = 355;
  18967. t['numbersign'] = 556;
  18968. t['dollar'] = 556;
  18969. t['percent'] = 889;
  18970. t['ampersand'] = 667;
  18971. t['quoteright'] = 222;
  18972. t['parenleft'] = 333;
  18973. t['parenright'] = 333;
  18974. t['asterisk'] = 389;
  18975. t['plus'] = 584;
  18976. t['comma'] = 278;
  18977. t['hyphen'] = 333;
  18978. t['period'] = 278;
  18979. t['slash'] = 278;
  18980. t['zero'] = 556;
  18981. t['one'] = 556;
  18982. t['two'] = 556;
  18983. t['three'] = 556;
  18984. t['four'] = 556;
  18985. t['five'] = 556;
  18986. t['six'] = 556;
  18987. t['seven'] = 556;
  18988. t['eight'] = 556;
  18989. t['nine'] = 556;
  18990. t['colon'] = 278;
  18991. t['semicolon'] = 278;
  18992. t['less'] = 584;
  18993. t['equal'] = 584;
  18994. t['greater'] = 584;
  18995. t['question'] = 556;
  18996. t['at'] = 1015;
  18997. t['A'] = 667;
  18998. t['B'] = 667;
  18999. t['C'] = 722;
  19000. t['D'] = 722;
  19001. t['E'] = 667;
  19002. t['F'] = 611;
  19003. t['G'] = 778;
  19004. t['H'] = 722;
  19005. t['I'] = 278;
  19006. t['J'] = 500;
  19007. t['K'] = 667;
  19008. t['L'] = 556;
  19009. t['M'] = 833;
  19010. t['N'] = 722;
  19011. t['O'] = 778;
  19012. t['P'] = 667;
  19013. t['Q'] = 778;
  19014. t['R'] = 722;
  19015. t['S'] = 667;
  19016. t['T'] = 611;
  19017. t['U'] = 722;
  19018. t['V'] = 667;
  19019. t['W'] = 944;
  19020. t['X'] = 667;
  19021. t['Y'] = 667;
  19022. t['Z'] = 611;
  19023. t['bracketleft'] = 278;
  19024. t['backslash'] = 278;
  19025. t['bracketright'] = 278;
  19026. t['asciicircum'] = 469;
  19027. t['underscore'] = 556;
  19028. t['quoteleft'] = 222;
  19029. t['a'] = 556;
  19030. t['b'] = 556;
  19031. t['c'] = 500;
  19032. t['d'] = 556;
  19033. t['e'] = 556;
  19034. t['f'] = 278;
  19035. t['g'] = 556;
  19036. t['h'] = 556;
  19037. t['i'] = 222;
  19038. t['j'] = 222;
  19039. t['k'] = 500;
  19040. t['l'] = 222;
  19041. t['m'] = 833;
  19042. t['n'] = 556;
  19043. t['o'] = 556;
  19044. t['p'] = 556;
  19045. t['q'] = 556;
  19046. t['r'] = 333;
  19047. t['s'] = 500;
  19048. t['t'] = 278;
  19049. t['u'] = 556;
  19050. t['v'] = 500;
  19051. t['w'] = 722;
  19052. t['x'] = 500;
  19053. t['y'] = 500;
  19054. t['z'] = 500;
  19055. t['braceleft'] = 334;
  19056. t['bar'] = 260;
  19057. t['braceright'] = 334;
  19058. t['asciitilde'] = 584;
  19059. t['exclamdown'] = 333;
  19060. t['cent'] = 556;
  19061. t['sterling'] = 556;
  19062. t['fraction'] = 167;
  19063. t['yen'] = 556;
  19064. t['florin'] = 556;
  19065. t['section'] = 556;
  19066. t['currency'] = 556;
  19067. t['quotesingle'] = 191;
  19068. t['quotedblleft'] = 333;
  19069. t['guillemotleft'] = 556;
  19070. t['guilsinglleft'] = 333;
  19071. t['guilsinglright'] = 333;
  19072. t['fi'] = 500;
  19073. t['fl'] = 500;
  19074. t['endash'] = 556;
  19075. t['dagger'] = 556;
  19076. t['daggerdbl'] = 556;
  19077. t['periodcentered'] = 278;
  19078. t['paragraph'] = 537;
  19079. t['bullet'] = 350;
  19080. t['quotesinglbase'] = 222;
  19081. t['quotedblbase'] = 333;
  19082. t['quotedblright'] = 333;
  19083. t['guillemotright'] = 556;
  19084. t['ellipsis'] = 1000;
  19085. t['perthousand'] = 1000;
  19086. t['questiondown'] = 611;
  19087. t['grave'] = 333;
  19088. t['acute'] = 333;
  19089. t['circumflex'] = 333;
  19090. t['tilde'] = 333;
  19091. t['macron'] = 333;
  19092. t['breve'] = 333;
  19093. t['dotaccent'] = 333;
  19094. t['dieresis'] = 333;
  19095. t['ring'] = 333;
  19096. t['cedilla'] = 333;
  19097. t['hungarumlaut'] = 333;
  19098. t['ogonek'] = 333;
  19099. t['caron'] = 333;
  19100. t['emdash'] = 1000;
  19101. t['AE'] = 1000;
  19102. t['ordfeminine'] = 370;
  19103. t['Lslash'] = 556;
  19104. t['Oslash'] = 778;
  19105. t['OE'] = 1000;
  19106. t['ordmasculine'] = 365;
  19107. t['ae'] = 889;
  19108. t['dotlessi'] = 278;
  19109. t['lslash'] = 222;
  19110. t['oslash'] = 611;
  19111. t['oe'] = 944;
  19112. t['germandbls'] = 611;
  19113. t['Idieresis'] = 278;
  19114. t['eacute'] = 556;
  19115. t['abreve'] = 556;
  19116. t['uhungarumlaut'] = 556;
  19117. t['ecaron'] = 556;
  19118. t['Ydieresis'] = 667;
  19119. t['divide'] = 584;
  19120. t['Yacute'] = 667;
  19121. t['Acircumflex'] = 667;
  19122. t['aacute'] = 556;
  19123. t['Ucircumflex'] = 722;
  19124. t['yacute'] = 500;
  19125. t['scommaaccent'] = 500;
  19126. t['ecircumflex'] = 556;
  19127. t['Uring'] = 722;
  19128. t['Udieresis'] = 722;
  19129. t['aogonek'] = 556;
  19130. t['Uacute'] = 722;
  19131. t['uogonek'] = 556;
  19132. t['Edieresis'] = 667;
  19133. t['Dcroat'] = 722;
  19134. t['commaaccent'] = 250;
  19135. t['copyright'] = 737;
  19136. t['Emacron'] = 667;
  19137. t['ccaron'] = 500;
  19138. t['aring'] = 556;
  19139. t['Ncommaaccent'] = 722;
  19140. t['lacute'] = 222;
  19141. t['agrave'] = 556;
  19142. t['Tcommaaccent'] = 611;
  19143. t['Cacute'] = 722;
  19144. t['atilde'] = 556;
  19145. t['Edotaccent'] = 667;
  19146. t['scaron'] = 500;
  19147. t['scedilla'] = 500;
  19148. t['iacute'] = 278;
  19149. t['lozenge'] = 471;
  19150. t['Rcaron'] = 722;
  19151. t['Gcommaaccent'] = 778;
  19152. t['ucircumflex'] = 556;
  19153. t['acircumflex'] = 556;
  19154. t['Amacron'] = 667;
  19155. t['rcaron'] = 333;
  19156. t['ccedilla'] = 500;
  19157. t['Zdotaccent'] = 611;
  19158. t['Thorn'] = 667;
  19159. t['Omacron'] = 778;
  19160. t['Racute'] = 722;
  19161. t['Sacute'] = 667;
  19162. t['dcaron'] = 643;
  19163. t['Umacron'] = 722;
  19164. t['uring'] = 556;
  19165. t['threesuperior'] = 333;
  19166. t['Ograve'] = 778;
  19167. t['Agrave'] = 667;
  19168. t['Abreve'] = 667;
  19169. t['multiply'] = 584;
  19170. t['uacute'] = 556;
  19171. t['Tcaron'] = 611;
  19172. t['partialdiff'] = 476;
  19173. t['ydieresis'] = 500;
  19174. t['Nacute'] = 722;
  19175. t['icircumflex'] = 278;
  19176. t['Ecircumflex'] = 667;
  19177. t['adieresis'] = 556;
  19178. t['edieresis'] = 556;
  19179. t['cacute'] = 500;
  19180. t['nacute'] = 556;
  19181. t['umacron'] = 556;
  19182. t['Ncaron'] = 722;
  19183. t['Iacute'] = 278;
  19184. t['plusminus'] = 584;
  19185. t['brokenbar'] = 260;
  19186. t['registered'] = 737;
  19187. t['Gbreve'] = 778;
  19188. t['Idotaccent'] = 278;
  19189. t['summation'] = 600;
  19190. t['Egrave'] = 667;
  19191. t['racute'] = 333;
  19192. t['omacron'] = 556;
  19193. t['Zacute'] = 611;
  19194. t['Zcaron'] = 611;
  19195. t['greaterequal'] = 549;
  19196. t['Eth'] = 722;
  19197. t['Ccedilla'] = 722;
  19198. t['lcommaaccent'] = 222;
  19199. t['tcaron'] = 317;
  19200. t['eogonek'] = 556;
  19201. t['Uogonek'] = 722;
  19202. t['Aacute'] = 667;
  19203. t['Adieresis'] = 667;
  19204. t['egrave'] = 556;
  19205. t['zacute'] = 500;
  19206. t['iogonek'] = 222;
  19207. t['Oacute'] = 778;
  19208. t['oacute'] = 556;
  19209. t['amacron'] = 556;
  19210. t['sacute'] = 500;
  19211. t['idieresis'] = 278;
  19212. t['Ocircumflex'] = 778;
  19213. t['Ugrave'] = 722;
  19214. t['Delta'] = 612;
  19215. t['thorn'] = 556;
  19216. t['twosuperior'] = 333;
  19217. t['Odieresis'] = 778;
  19218. t['mu'] = 556;
  19219. t['igrave'] = 278;
  19220. t['ohungarumlaut'] = 556;
  19221. t['Eogonek'] = 667;
  19222. t['dcroat'] = 556;
  19223. t['threequarters'] = 834;
  19224. t['Scedilla'] = 667;
  19225. t['lcaron'] = 299;
  19226. t['Kcommaaccent'] = 667;
  19227. t['Lacute'] = 556;
  19228. t['trademark'] = 1000;
  19229. t['edotaccent'] = 556;
  19230. t['Igrave'] = 278;
  19231. t['Imacron'] = 278;
  19232. t['Lcaron'] = 556;
  19233. t['onehalf'] = 834;
  19234. t['lessequal'] = 549;
  19235. t['ocircumflex'] = 556;
  19236. t['ntilde'] = 556;
  19237. t['Uhungarumlaut'] = 722;
  19238. t['Eacute'] = 667;
  19239. t['emacron'] = 556;
  19240. t['gbreve'] = 556;
  19241. t['onequarter'] = 834;
  19242. t['Scaron'] = 667;
  19243. t['Scommaaccent'] = 667;
  19244. t['Ohungarumlaut'] = 778;
  19245. t['degree'] = 400;
  19246. t['ograve'] = 556;
  19247. t['Ccaron'] = 722;
  19248. t['ugrave'] = 556;
  19249. t['radical'] = 453;
  19250. t['Dcaron'] = 722;
  19251. t['rcommaaccent'] = 333;
  19252. t['Ntilde'] = 722;
  19253. t['otilde'] = 556;
  19254. t['Rcommaaccent'] = 722;
  19255. t['Lcommaaccent'] = 556;
  19256. t['Atilde'] = 667;
  19257. t['Aogonek'] = 667;
  19258. t['Aring'] = 667;
  19259. t['Otilde'] = 778;
  19260. t['zdotaccent'] = 500;
  19261. t['Ecaron'] = 667;
  19262. t['Iogonek'] = 278;
  19263. t['kcommaaccent'] = 500;
  19264. t['minus'] = 584;
  19265. t['Icircumflex'] = 278;
  19266. t['ncaron'] = 556;
  19267. t['tcommaaccent'] = 278;
  19268. t['logicalnot'] = 584;
  19269. t['odieresis'] = 556;
  19270. t['udieresis'] = 556;
  19271. t['notequal'] = 549;
  19272. t['gcommaaccent'] = 556;
  19273. t['eth'] = 556;
  19274. t['zcaron'] = 500;
  19275. t['ncommaaccent'] = 556;
  19276. t['onesuperior'] = 333;
  19277. t['imacron'] = 278;
  19278. t['Euro'] = 556;
  19279. });
  19280. t['Symbol'] = getLookupTableFactory(function (t) {
  19281. t['space'] = 250;
  19282. t['exclam'] = 333;
  19283. t['universal'] = 713;
  19284. t['numbersign'] = 500;
  19285. t['existential'] = 549;
  19286. t['percent'] = 833;
  19287. t['ampersand'] = 778;
  19288. t['suchthat'] = 439;
  19289. t['parenleft'] = 333;
  19290. t['parenright'] = 333;
  19291. t['asteriskmath'] = 500;
  19292. t['plus'] = 549;
  19293. t['comma'] = 250;
  19294. t['minus'] = 549;
  19295. t['period'] = 250;
  19296. t['slash'] = 278;
  19297. t['zero'] = 500;
  19298. t['one'] = 500;
  19299. t['two'] = 500;
  19300. t['three'] = 500;
  19301. t['four'] = 500;
  19302. t['five'] = 500;
  19303. t['six'] = 500;
  19304. t['seven'] = 500;
  19305. t['eight'] = 500;
  19306. t['nine'] = 500;
  19307. t['colon'] = 278;
  19308. t['semicolon'] = 278;
  19309. t['less'] = 549;
  19310. t['equal'] = 549;
  19311. t['greater'] = 549;
  19312. t['question'] = 444;
  19313. t['congruent'] = 549;
  19314. t['Alpha'] = 722;
  19315. t['Beta'] = 667;
  19316. t['Chi'] = 722;
  19317. t['Delta'] = 612;
  19318. t['Epsilon'] = 611;
  19319. t['Phi'] = 763;
  19320. t['Gamma'] = 603;
  19321. t['Eta'] = 722;
  19322. t['Iota'] = 333;
  19323. t['theta1'] = 631;
  19324. t['Kappa'] = 722;
  19325. t['Lambda'] = 686;
  19326. t['Mu'] = 889;
  19327. t['Nu'] = 722;
  19328. t['Omicron'] = 722;
  19329. t['Pi'] = 768;
  19330. t['Theta'] = 741;
  19331. t['Rho'] = 556;
  19332. t['Sigma'] = 592;
  19333. t['Tau'] = 611;
  19334. t['Upsilon'] = 690;
  19335. t['sigma1'] = 439;
  19336. t['Omega'] = 768;
  19337. t['Xi'] = 645;
  19338. t['Psi'] = 795;
  19339. t['Zeta'] = 611;
  19340. t['bracketleft'] = 333;
  19341. t['therefore'] = 863;
  19342. t['bracketright'] = 333;
  19343. t['perpendicular'] = 658;
  19344. t['underscore'] = 500;
  19345. t['radicalex'] = 500;
  19346. t['alpha'] = 631;
  19347. t['beta'] = 549;
  19348. t['chi'] = 549;
  19349. t['delta'] = 494;
  19350. t['epsilon'] = 439;
  19351. t['phi'] = 521;
  19352. t['gamma'] = 411;
  19353. t['eta'] = 603;
  19354. t['iota'] = 329;
  19355. t['phi1'] = 603;
  19356. t['kappa'] = 549;
  19357. t['lambda'] = 549;
  19358. t['mu'] = 576;
  19359. t['nu'] = 521;
  19360. t['omicron'] = 549;
  19361. t['pi'] = 549;
  19362. t['theta'] = 521;
  19363. t['rho'] = 549;
  19364. t['sigma'] = 603;
  19365. t['tau'] = 439;
  19366. t['upsilon'] = 576;
  19367. t['omega1'] = 713;
  19368. t['omega'] = 686;
  19369. t['xi'] = 493;
  19370. t['psi'] = 686;
  19371. t['zeta'] = 494;
  19372. t['braceleft'] = 480;
  19373. t['bar'] = 200;
  19374. t['braceright'] = 480;
  19375. t['similar'] = 549;
  19376. t['Euro'] = 750;
  19377. t['Upsilon1'] = 620;
  19378. t['minute'] = 247;
  19379. t['lessequal'] = 549;
  19380. t['fraction'] = 167;
  19381. t['infinity'] = 713;
  19382. t['florin'] = 500;
  19383. t['club'] = 753;
  19384. t['diamond'] = 753;
  19385. t['heart'] = 753;
  19386. t['spade'] = 753;
  19387. t['arrowboth'] = 1042;
  19388. t['arrowleft'] = 987;
  19389. t['arrowup'] = 603;
  19390. t['arrowright'] = 987;
  19391. t['arrowdown'] = 603;
  19392. t['degree'] = 400;
  19393. t['plusminus'] = 549;
  19394. t['second'] = 411;
  19395. t['greaterequal'] = 549;
  19396. t['multiply'] = 549;
  19397. t['proportional'] = 713;
  19398. t['partialdiff'] = 494;
  19399. t['bullet'] = 460;
  19400. t['divide'] = 549;
  19401. t['notequal'] = 549;
  19402. t['equivalence'] = 549;
  19403. t['approxequal'] = 549;
  19404. t['ellipsis'] = 1000;
  19405. t['arrowvertex'] = 603;
  19406. t['arrowhorizex'] = 1000;
  19407. t['carriagereturn'] = 658;
  19408. t['aleph'] = 823;
  19409. t['Ifraktur'] = 686;
  19410. t['Rfraktur'] = 795;
  19411. t['weierstrass'] = 987;
  19412. t['circlemultiply'] = 768;
  19413. t['circleplus'] = 768;
  19414. t['emptyset'] = 823;
  19415. t['intersection'] = 768;
  19416. t['union'] = 768;
  19417. t['propersuperset'] = 713;
  19418. t['reflexsuperset'] = 713;
  19419. t['notsubset'] = 713;
  19420. t['propersubset'] = 713;
  19421. t['reflexsubset'] = 713;
  19422. t['element'] = 713;
  19423. t['notelement'] = 713;
  19424. t['angle'] = 768;
  19425. t['gradient'] = 713;
  19426. t['registerserif'] = 790;
  19427. t['copyrightserif'] = 790;
  19428. t['trademarkserif'] = 890;
  19429. t['product'] = 823;
  19430. t['radical'] = 549;
  19431. t['dotmath'] = 250;
  19432. t['logicalnot'] = 713;
  19433. t['logicaland'] = 603;
  19434. t['logicalor'] = 603;
  19435. t['arrowdblboth'] = 1042;
  19436. t['arrowdblleft'] = 987;
  19437. t['arrowdblup'] = 603;
  19438. t['arrowdblright'] = 987;
  19439. t['arrowdbldown'] = 603;
  19440. t['lozenge'] = 494;
  19441. t['angleleft'] = 329;
  19442. t['registersans'] = 790;
  19443. t['copyrightsans'] = 790;
  19444. t['trademarksans'] = 786;
  19445. t['summation'] = 713;
  19446. t['parenlefttp'] = 384;
  19447. t['parenleftex'] = 384;
  19448. t['parenleftbt'] = 384;
  19449. t['bracketlefttp'] = 384;
  19450. t['bracketleftex'] = 384;
  19451. t['bracketleftbt'] = 384;
  19452. t['bracelefttp'] = 494;
  19453. t['braceleftmid'] = 494;
  19454. t['braceleftbt'] = 494;
  19455. t['braceex'] = 494;
  19456. t['angleright'] = 329;
  19457. t['integral'] = 274;
  19458. t['integraltp'] = 686;
  19459. t['integralex'] = 686;
  19460. t['integralbt'] = 686;
  19461. t['parenrighttp'] = 384;
  19462. t['parenrightex'] = 384;
  19463. t['parenrightbt'] = 384;
  19464. t['bracketrighttp'] = 384;
  19465. t['bracketrightex'] = 384;
  19466. t['bracketrightbt'] = 384;
  19467. t['bracerighttp'] = 494;
  19468. t['bracerightmid'] = 494;
  19469. t['bracerightbt'] = 494;
  19470. t['apple'] = 790;
  19471. });
  19472. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19473. t['space'] = 250;
  19474. t['exclam'] = 333;
  19475. t['quotedbl'] = 408;
  19476. t['numbersign'] = 500;
  19477. t['dollar'] = 500;
  19478. t['percent'] = 833;
  19479. t['ampersand'] = 778;
  19480. t['quoteright'] = 333;
  19481. t['parenleft'] = 333;
  19482. t['parenright'] = 333;
  19483. t['asterisk'] = 500;
  19484. t['plus'] = 564;
  19485. t['comma'] = 250;
  19486. t['hyphen'] = 333;
  19487. t['period'] = 250;
  19488. t['slash'] = 278;
  19489. t['zero'] = 500;
  19490. t['one'] = 500;
  19491. t['two'] = 500;
  19492. t['three'] = 500;
  19493. t['four'] = 500;
  19494. t['five'] = 500;
  19495. t['six'] = 500;
  19496. t['seven'] = 500;
  19497. t['eight'] = 500;
  19498. t['nine'] = 500;
  19499. t['colon'] = 278;
  19500. t['semicolon'] = 278;
  19501. t['less'] = 564;
  19502. t['equal'] = 564;
  19503. t['greater'] = 564;
  19504. t['question'] = 444;
  19505. t['at'] = 921;
  19506. t['A'] = 722;
  19507. t['B'] = 667;
  19508. t['C'] = 667;
  19509. t['D'] = 722;
  19510. t['E'] = 611;
  19511. t['F'] = 556;
  19512. t['G'] = 722;
  19513. t['H'] = 722;
  19514. t['I'] = 333;
  19515. t['J'] = 389;
  19516. t['K'] = 722;
  19517. t['L'] = 611;
  19518. t['M'] = 889;
  19519. t['N'] = 722;
  19520. t['O'] = 722;
  19521. t['P'] = 556;
  19522. t['Q'] = 722;
  19523. t['R'] = 667;
  19524. t['S'] = 556;
  19525. t['T'] = 611;
  19526. t['U'] = 722;
  19527. t['V'] = 722;
  19528. t['W'] = 944;
  19529. t['X'] = 722;
  19530. t['Y'] = 722;
  19531. t['Z'] = 611;
  19532. t['bracketleft'] = 333;
  19533. t['backslash'] = 278;
  19534. t['bracketright'] = 333;
  19535. t['asciicircum'] = 469;
  19536. t['underscore'] = 500;
  19537. t['quoteleft'] = 333;
  19538. t['a'] = 444;
  19539. t['b'] = 500;
  19540. t['c'] = 444;
  19541. t['d'] = 500;
  19542. t['e'] = 444;
  19543. t['f'] = 333;
  19544. t['g'] = 500;
  19545. t['h'] = 500;
  19546. t['i'] = 278;
  19547. t['j'] = 278;
  19548. t['k'] = 500;
  19549. t['l'] = 278;
  19550. t['m'] = 778;
  19551. t['n'] = 500;
  19552. t['o'] = 500;
  19553. t['p'] = 500;
  19554. t['q'] = 500;
  19555. t['r'] = 333;
  19556. t['s'] = 389;
  19557. t['t'] = 278;
  19558. t['u'] = 500;
  19559. t['v'] = 500;
  19560. t['w'] = 722;
  19561. t['x'] = 500;
  19562. t['y'] = 500;
  19563. t['z'] = 444;
  19564. t['braceleft'] = 480;
  19565. t['bar'] = 200;
  19566. t['braceright'] = 480;
  19567. t['asciitilde'] = 541;
  19568. t['exclamdown'] = 333;
  19569. t['cent'] = 500;
  19570. t['sterling'] = 500;
  19571. t['fraction'] = 167;
  19572. t['yen'] = 500;
  19573. t['florin'] = 500;
  19574. t['section'] = 500;
  19575. t['currency'] = 500;
  19576. t['quotesingle'] = 180;
  19577. t['quotedblleft'] = 444;
  19578. t['guillemotleft'] = 500;
  19579. t['guilsinglleft'] = 333;
  19580. t['guilsinglright'] = 333;
  19581. t['fi'] = 556;
  19582. t['fl'] = 556;
  19583. t['endash'] = 500;
  19584. t['dagger'] = 500;
  19585. t['daggerdbl'] = 500;
  19586. t['periodcentered'] = 250;
  19587. t['paragraph'] = 453;
  19588. t['bullet'] = 350;
  19589. t['quotesinglbase'] = 333;
  19590. t['quotedblbase'] = 444;
  19591. t['quotedblright'] = 444;
  19592. t['guillemotright'] = 500;
  19593. t['ellipsis'] = 1000;
  19594. t['perthousand'] = 1000;
  19595. t['questiondown'] = 444;
  19596. t['grave'] = 333;
  19597. t['acute'] = 333;
  19598. t['circumflex'] = 333;
  19599. t['tilde'] = 333;
  19600. t['macron'] = 333;
  19601. t['breve'] = 333;
  19602. t['dotaccent'] = 333;
  19603. t['dieresis'] = 333;
  19604. t['ring'] = 333;
  19605. t['cedilla'] = 333;
  19606. t['hungarumlaut'] = 333;
  19607. t['ogonek'] = 333;
  19608. t['caron'] = 333;
  19609. t['emdash'] = 1000;
  19610. t['AE'] = 889;
  19611. t['ordfeminine'] = 276;
  19612. t['Lslash'] = 611;
  19613. t['Oslash'] = 722;
  19614. t['OE'] = 889;
  19615. t['ordmasculine'] = 310;
  19616. t['ae'] = 667;
  19617. t['dotlessi'] = 278;
  19618. t['lslash'] = 278;
  19619. t['oslash'] = 500;
  19620. t['oe'] = 722;
  19621. t['germandbls'] = 500;
  19622. t['Idieresis'] = 333;
  19623. t['eacute'] = 444;
  19624. t['abreve'] = 444;
  19625. t['uhungarumlaut'] = 500;
  19626. t['ecaron'] = 444;
  19627. t['Ydieresis'] = 722;
  19628. t['divide'] = 564;
  19629. t['Yacute'] = 722;
  19630. t['Acircumflex'] = 722;
  19631. t['aacute'] = 444;
  19632. t['Ucircumflex'] = 722;
  19633. t['yacute'] = 500;
  19634. t['scommaaccent'] = 389;
  19635. t['ecircumflex'] = 444;
  19636. t['Uring'] = 722;
  19637. t['Udieresis'] = 722;
  19638. t['aogonek'] = 444;
  19639. t['Uacute'] = 722;
  19640. t['uogonek'] = 500;
  19641. t['Edieresis'] = 611;
  19642. t['Dcroat'] = 722;
  19643. t['commaaccent'] = 250;
  19644. t['copyright'] = 760;
  19645. t['Emacron'] = 611;
  19646. t['ccaron'] = 444;
  19647. t['aring'] = 444;
  19648. t['Ncommaaccent'] = 722;
  19649. t['lacute'] = 278;
  19650. t['agrave'] = 444;
  19651. t['Tcommaaccent'] = 611;
  19652. t['Cacute'] = 667;
  19653. t['atilde'] = 444;
  19654. t['Edotaccent'] = 611;
  19655. t['scaron'] = 389;
  19656. t['scedilla'] = 389;
  19657. t['iacute'] = 278;
  19658. t['lozenge'] = 471;
  19659. t['Rcaron'] = 667;
  19660. t['Gcommaaccent'] = 722;
  19661. t['ucircumflex'] = 500;
  19662. t['acircumflex'] = 444;
  19663. t['Amacron'] = 722;
  19664. t['rcaron'] = 333;
  19665. t['ccedilla'] = 444;
  19666. t['Zdotaccent'] = 611;
  19667. t['Thorn'] = 556;
  19668. t['Omacron'] = 722;
  19669. t['Racute'] = 667;
  19670. t['Sacute'] = 556;
  19671. t['dcaron'] = 588;
  19672. t['Umacron'] = 722;
  19673. t['uring'] = 500;
  19674. t['threesuperior'] = 300;
  19675. t['Ograve'] = 722;
  19676. t['Agrave'] = 722;
  19677. t['Abreve'] = 722;
  19678. t['multiply'] = 564;
  19679. t['uacute'] = 500;
  19680. t['Tcaron'] = 611;
  19681. t['partialdiff'] = 476;
  19682. t['ydieresis'] = 500;
  19683. t['Nacute'] = 722;
  19684. t['icircumflex'] = 278;
  19685. t['Ecircumflex'] = 611;
  19686. t['adieresis'] = 444;
  19687. t['edieresis'] = 444;
  19688. t['cacute'] = 444;
  19689. t['nacute'] = 500;
  19690. t['umacron'] = 500;
  19691. t['Ncaron'] = 722;
  19692. t['Iacute'] = 333;
  19693. t['plusminus'] = 564;
  19694. t['brokenbar'] = 200;
  19695. t['registered'] = 760;
  19696. t['Gbreve'] = 722;
  19697. t['Idotaccent'] = 333;
  19698. t['summation'] = 600;
  19699. t['Egrave'] = 611;
  19700. t['racute'] = 333;
  19701. t['omacron'] = 500;
  19702. t['Zacute'] = 611;
  19703. t['Zcaron'] = 611;
  19704. t['greaterequal'] = 549;
  19705. t['Eth'] = 722;
  19706. t['Ccedilla'] = 667;
  19707. t['lcommaaccent'] = 278;
  19708. t['tcaron'] = 326;
  19709. t['eogonek'] = 444;
  19710. t['Uogonek'] = 722;
  19711. t['Aacute'] = 722;
  19712. t['Adieresis'] = 722;
  19713. t['egrave'] = 444;
  19714. t['zacute'] = 444;
  19715. t['iogonek'] = 278;
  19716. t['Oacute'] = 722;
  19717. t['oacute'] = 500;
  19718. t['amacron'] = 444;
  19719. t['sacute'] = 389;
  19720. t['idieresis'] = 278;
  19721. t['Ocircumflex'] = 722;
  19722. t['Ugrave'] = 722;
  19723. t['Delta'] = 612;
  19724. t['thorn'] = 500;
  19725. t['twosuperior'] = 300;
  19726. t['Odieresis'] = 722;
  19727. t['mu'] = 500;
  19728. t['igrave'] = 278;
  19729. t['ohungarumlaut'] = 500;
  19730. t['Eogonek'] = 611;
  19731. t['dcroat'] = 500;
  19732. t['threequarters'] = 750;
  19733. t['Scedilla'] = 556;
  19734. t['lcaron'] = 344;
  19735. t['Kcommaaccent'] = 722;
  19736. t['Lacute'] = 611;
  19737. t['trademark'] = 980;
  19738. t['edotaccent'] = 444;
  19739. t['Igrave'] = 333;
  19740. t['Imacron'] = 333;
  19741. t['Lcaron'] = 611;
  19742. t['onehalf'] = 750;
  19743. t['lessequal'] = 549;
  19744. t['ocircumflex'] = 500;
  19745. t['ntilde'] = 500;
  19746. t['Uhungarumlaut'] = 722;
  19747. t['Eacute'] = 611;
  19748. t['emacron'] = 444;
  19749. t['gbreve'] = 500;
  19750. t['onequarter'] = 750;
  19751. t['Scaron'] = 556;
  19752. t['Scommaaccent'] = 556;
  19753. t['Ohungarumlaut'] = 722;
  19754. t['degree'] = 400;
  19755. t['ograve'] = 500;
  19756. t['Ccaron'] = 667;
  19757. t['ugrave'] = 500;
  19758. t['radical'] = 453;
  19759. t['Dcaron'] = 722;
  19760. t['rcommaaccent'] = 333;
  19761. t['Ntilde'] = 722;
  19762. t['otilde'] = 500;
  19763. t['Rcommaaccent'] = 667;
  19764. t['Lcommaaccent'] = 611;
  19765. t['Atilde'] = 722;
  19766. t['Aogonek'] = 722;
  19767. t['Aring'] = 722;
  19768. t['Otilde'] = 722;
  19769. t['zdotaccent'] = 444;
  19770. t['Ecaron'] = 611;
  19771. t['Iogonek'] = 333;
  19772. t['kcommaaccent'] = 500;
  19773. t['minus'] = 564;
  19774. t['Icircumflex'] = 333;
  19775. t['ncaron'] = 500;
  19776. t['tcommaaccent'] = 278;
  19777. t['logicalnot'] = 564;
  19778. t['odieresis'] = 500;
  19779. t['udieresis'] = 500;
  19780. t['notequal'] = 549;
  19781. t['gcommaaccent'] = 500;
  19782. t['eth'] = 500;
  19783. t['zcaron'] = 444;
  19784. t['ncommaaccent'] = 500;
  19785. t['onesuperior'] = 300;
  19786. t['imacron'] = 278;
  19787. t['Euro'] = 500;
  19788. });
  19789. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19790. t['space'] = 250;
  19791. t['exclam'] = 333;
  19792. t['quotedbl'] = 555;
  19793. t['numbersign'] = 500;
  19794. t['dollar'] = 500;
  19795. t['percent'] = 1000;
  19796. t['ampersand'] = 833;
  19797. t['quoteright'] = 333;
  19798. t['parenleft'] = 333;
  19799. t['parenright'] = 333;
  19800. t['asterisk'] = 500;
  19801. t['plus'] = 570;
  19802. t['comma'] = 250;
  19803. t['hyphen'] = 333;
  19804. t['period'] = 250;
  19805. t['slash'] = 278;
  19806. t['zero'] = 500;
  19807. t['one'] = 500;
  19808. t['two'] = 500;
  19809. t['three'] = 500;
  19810. t['four'] = 500;
  19811. t['five'] = 500;
  19812. t['six'] = 500;
  19813. t['seven'] = 500;
  19814. t['eight'] = 500;
  19815. t['nine'] = 500;
  19816. t['colon'] = 333;
  19817. t['semicolon'] = 333;
  19818. t['less'] = 570;
  19819. t['equal'] = 570;
  19820. t['greater'] = 570;
  19821. t['question'] = 500;
  19822. t['at'] = 930;
  19823. t['A'] = 722;
  19824. t['B'] = 667;
  19825. t['C'] = 722;
  19826. t['D'] = 722;
  19827. t['E'] = 667;
  19828. t['F'] = 611;
  19829. t['G'] = 778;
  19830. t['H'] = 778;
  19831. t['I'] = 389;
  19832. t['J'] = 500;
  19833. t['K'] = 778;
  19834. t['L'] = 667;
  19835. t['M'] = 944;
  19836. t['N'] = 722;
  19837. t['O'] = 778;
  19838. t['P'] = 611;
  19839. t['Q'] = 778;
  19840. t['R'] = 722;
  19841. t['S'] = 556;
  19842. t['T'] = 667;
  19843. t['U'] = 722;
  19844. t['V'] = 722;
  19845. t['W'] = 1000;
  19846. t['X'] = 722;
  19847. t['Y'] = 722;
  19848. t['Z'] = 667;
  19849. t['bracketleft'] = 333;
  19850. t['backslash'] = 278;
  19851. t['bracketright'] = 333;
  19852. t['asciicircum'] = 581;
  19853. t['underscore'] = 500;
  19854. t['quoteleft'] = 333;
  19855. t['a'] = 500;
  19856. t['b'] = 556;
  19857. t['c'] = 444;
  19858. t['d'] = 556;
  19859. t['e'] = 444;
  19860. t['f'] = 333;
  19861. t['g'] = 500;
  19862. t['h'] = 556;
  19863. t['i'] = 278;
  19864. t['j'] = 333;
  19865. t['k'] = 556;
  19866. t['l'] = 278;
  19867. t['m'] = 833;
  19868. t['n'] = 556;
  19869. t['o'] = 500;
  19870. t['p'] = 556;
  19871. t['q'] = 556;
  19872. t['r'] = 444;
  19873. t['s'] = 389;
  19874. t['t'] = 333;
  19875. t['u'] = 556;
  19876. t['v'] = 500;
  19877. t['w'] = 722;
  19878. t['x'] = 500;
  19879. t['y'] = 500;
  19880. t['z'] = 444;
  19881. t['braceleft'] = 394;
  19882. t['bar'] = 220;
  19883. t['braceright'] = 394;
  19884. t['asciitilde'] = 520;
  19885. t['exclamdown'] = 333;
  19886. t['cent'] = 500;
  19887. t['sterling'] = 500;
  19888. t['fraction'] = 167;
  19889. t['yen'] = 500;
  19890. t['florin'] = 500;
  19891. t['section'] = 500;
  19892. t['currency'] = 500;
  19893. t['quotesingle'] = 278;
  19894. t['quotedblleft'] = 500;
  19895. t['guillemotleft'] = 500;
  19896. t['guilsinglleft'] = 333;
  19897. t['guilsinglright'] = 333;
  19898. t['fi'] = 556;
  19899. t['fl'] = 556;
  19900. t['endash'] = 500;
  19901. t['dagger'] = 500;
  19902. t['daggerdbl'] = 500;
  19903. t['periodcentered'] = 250;
  19904. t['paragraph'] = 540;
  19905. t['bullet'] = 350;
  19906. t['quotesinglbase'] = 333;
  19907. t['quotedblbase'] = 500;
  19908. t['quotedblright'] = 500;
  19909. t['guillemotright'] = 500;
  19910. t['ellipsis'] = 1000;
  19911. t['perthousand'] = 1000;
  19912. t['questiondown'] = 500;
  19913. t['grave'] = 333;
  19914. t['acute'] = 333;
  19915. t['circumflex'] = 333;
  19916. t['tilde'] = 333;
  19917. t['macron'] = 333;
  19918. t['breve'] = 333;
  19919. t['dotaccent'] = 333;
  19920. t['dieresis'] = 333;
  19921. t['ring'] = 333;
  19922. t['cedilla'] = 333;
  19923. t['hungarumlaut'] = 333;
  19924. t['ogonek'] = 333;
  19925. t['caron'] = 333;
  19926. t['emdash'] = 1000;
  19927. t['AE'] = 1000;
  19928. t['ordfeminine'] = 300;
  19929. t['Lslash'] = 667;
  19930. t['Oslash'] = 778;
  19931. t['OE'] = 1000;
  19932. t['ordmasculine'] = 330;
  19933. t['ae'] = 722;
  19934. t['dotlessi'] = 278;
  19935. t['lslash'] = 278;
  19936. t['oslash'] = 500;
  19937. t['oe'] = 722;
  19938. t['germandbls'] = 556;
  19939. t['Idieresis'] = 389;
  19940. t['eacute'] = 444;
  19941. t['abreve'] = 500;
  19942. t['uhungarumlaut'] = 556;
  19943. t['ecaron'] = 444;
  19944. t['Ydieresis'] = 722;
  19945. t['divide'] = 570;
  19946. t['Yacute'] = 722;
  19947. t['Acircumflex'] = 722;
  19948. t['aacute'] = 500;
  19949. t['Ucircumflex'] = 722;
  19950. t['yacute'] = 500;
  19951. t['scommaaccent'] = 389;
  19952. t['ecircumflex'] = 444;
  19953. t['Uring'] = 722;
  19954. t['Udieresis'] = 722;
  19955. t['aogonek'] = 500;
  19956. t['Uacute'] = 722;
  19957. t['uogonek'] = 556;
  19958. t['Edieresis'] = 667;
  19959. t['Dcroat'] = 722;
  19960. t['commaaccent'] = 250;
  19961. t['copyright'] = 747;
  19962. t['Emacron'] = 667;
  19963. t['ccaron'] = 444;
  19964. t['aring'] = 500;
  19965. t['Ncommaaccent'] = 722;
  19966. t['lacute'] = 278;
  19967. t['agrave'] = 500;
  19968. t['Tcommaaccent'] = 667;
  19969. t['Cacute'] = 722;
  19970. t['atilde'] = 500;
  19971. t['Edotaccent'] = 667;
  19972. t['scaron'] = 389;
  19973. t['scedilla'] = 389;
  19974. t['iacute'] = 278;
  19975. t['lozenge'] = 494;
  19976. t['Rcaron'] = 722;
  19977. t['Gcommaaccent'] = 778;
  19978. t['ucircumflex'] = 556;
  19979. t['acircumflex'] = 500;
  19980. t['Amacron'] = 722;
  19981. t['rcaron'] = 444;
  19982. t['ccedilla'] = 444;
  19983. t['Zdotaccent'] = 667;
  19984. t['Thorn'] = 611;
  19985. t['Omacron'] = 778;
  19986. t['Racute'] = 722;
  19987. t['Sacute'] = 556;
  19988. t['dcaron'] = 672;
  19989. t['Umacron'] = 722;
  19990. t['uring'] = 556;
  19991. t['threesuperior'] = 300;
  19992. t['Ograve'] = 778;
  19993. t['Agrave'] = 722;
  19994. t['Abreve'] = 722;
  19995. t['multiply'] = 570;
  19996. t['uacute'] = 556;
  19997. t['Tcaron'] = 667;
  19998. t['partialdiff'] = 494;
  19999. t['ydieresis'] = 500;
  20000. t['Nacute'] = 722;
  20001. t['icircumflex'] = 278;
  20002. t['Ecircumflex'] = 667;
  20003. t['adieresis'] = 500;
  20004. t['edieresis'] = 444;
  20005. t['cacute'] = 444;
  20006. t['nacute'] = 556;
  20007. t['umacron'] = 556;
  20008. t['Ncaron'] = 722;
  20009. t['Iacute'] = 389;
  20010. t['plusminus'] = 570;
  20011. t['brokenbar'] = 220;
  20012. t['registered'] = 747;
  20013. t['Gbreve'] = 778;
  20014. t['Idotaccent'] = 389;
  20015. t['summation'] = 600;
  20016. t['Egrave'] = 667;
  20017. t['racute'] = 444;
  20018. t['omacron'] = 500;
  20019. t['Zacute'] = 667;
  20020. t['Zcaron'] = 667;
  20021. t['greaterequal'] = 549;
  20022. t['Eth'] = 722;
  20023. t['Ccedilla'] = 722;
  20024. t['lcommaaccent'] = 278;
  20025. t['tcaron'] = 416;
  20026. t['eogonek'] = 444;
  20027. t['Uogonek'] = 722;
  20028. t['Aacute'] = 722;
  20029. t['Adieresis'] = 722;
  20030. t['egrave'] = 444;
  20031. t['zacute'] = 444;
  20032. t['iogonek'] = 278;
  20033. t['Oacute'] = 778;
  20034. t['oacute'] = 500;
  20035. t['amacron'] = 500;
  20036. t['sacute'] = 389;
  20037. t['idieresis'] = 278;
  20038. t['Ocircumflex'] = 778;
  20039. t['Ugrave'] = 722;
  20040. t['Delta'] = 612;
  20041. t['thorn'] = 556;
  20042. t['twosuperior'] = 300;
  20043. t['Odieresis'] = 778;
  20044. t['mu'] = 556;
  20045. t['igrave'] = 278;
  20046. t['ohungarumlaut'] = 500;
  20047. t['Eogonek'] = 667;
  20048. t['dcroat'] = 556;
  20049. t['threequarters'] = 750;
  20050. t['Scedilla'] = 556;
  20051. t['lcaron'] = 394;
  20052. t['Kcommaaccent'] = 778;
  20053. t['Lacute'] = 667;
  20054. t['trademark'] = 1000;
  20055. t['edotaccent'] = 444;
  20056. t['Igrave'] = 389;
  20057. t['Imacron'] = 389;
  20058. t['Lcaron'] = 667;
  20059. t['onehalf'] = 750;
  20060. t['lessequal'] = 549;
  20061. t['ocircumflex'] = 500;
  20062. t['ntilde'] = 556;
  20063. t['Uhungarumlaut'] = 722;
  20064. t['Eacute'] = 667;
  20065. t['emacron'] = 444;
  20066. t['gbreve'] = 500;
  20067. t['onequarter'] = 750;
  20068. t['Scaron'] = 556;
  20069. t['Scommaaccent'] = 556;
  20070. t['Ohungarumlaut'] = 778;
  20071. t['degree'] = 400;
  20072. t['ograve'] = 500;
  20073. t['Ccaron'] = 722;
  20074. t['ugrave'] = 556;
  20075. t['radical'] = 549;
  20076. t['Dcaron'] = 722;
  20077. t['rcommaaccent'] = 444;
  20078. t['Ntilde'] = 722;
  20079. t['otilde'] = 500;
  20080. t['Rcommaaccent'] = 722;
  20081. t['Lcommaaccent'] = 667;
  20082. t['Atilde'] = 722;
  20083. t['Aogonek'] = 722;
  20084. t['Aring'] = 722;
  20085. t['Otilde'] = 778;
  20086. t['zdotaccent'] = 444;
  20087. t['Ecaron'] = 667;
  20088. t['Iogonek'] = 389;
  20089. t['kcommaaccent'] = 556;
  20090. t['minus'] = 570;
  20091. t['Icircumflex'] = 389;
  20092. t['ncaron'] = 556;
  20093. t['tcommaaccent'] = 333;
  20094. t['logicalnot'] = 570;
  20095. t['odieresis'] = 500;
  20096. t['udieresis'] = 556;
  20097. t['notequal'] = 549;
  20098. t['gcommaaccent'] = 500;
  20099. t['eth'] = 500;
  20100. t['zcaron'] = 444;
  20101. t['ncommaaccent'] = 556;
  20102. t['onesuperior'] = 300;
  20103. t['imacron'] = 278;
  20104. t['Euro'] = 500;
  20105. });
  20106. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20107. t['space'] = 250;
  20108. t['exclam'] = 389;
  20109. t['quotedbl'] = 555;
  20110. t['numbersign'] = 500;
  20111. t['dollar'] = 500;
  20112. t['percent'] = 833;
  20113. t['ampersand'] = 778;
  20114. t['quoteright'] = 333;
  20115. t['parenleft'] = 333;
  20116. t['parenright'] = 333;
  20117. t['asterisk'] = 500;
  20118. t['plus'] = 570;
  20119. t['comma'] = 250;
  20120. t['hyphen'] = 333;
  20121. t['period'] = 250;
  20122. t['slash'] = 278;
  20123. t['zero'] = 500;
  20124. t['one'] = 500;
  20125. t['two'] = 500;
  20126. t['three'] = 500;
  20127. t['four'] = 500;
  20128. t['five'] = 500;
  20129. t['six'] = 500;
  20130. t['seven'] = 500;
  20131. t['eight'] = 500;
  20132. t['nine'] = 500;
  20133. t['colon'] = 333;
  20134. t['semicolon'] = 333;
  20135. t['less'] = 570;
  20136. t['equal'] = 570;
  20137. t['greater'] = 570;
  20138. t['question'] = 500;
  20139. t['at'] = 832;
  20140. t['A'] = 667;
  20141. t['B'] = 667;
  20142. t['C'] = 667;
  20143. t['D'] = 722;
  20144. t['E'] = 667;
  20145. t['F'] = 667;
  20146. t['G'] = 722;
  20147. t['H'] = 778;
  20148. t['I'] = 389;
  20149. t['J'] = 500;
  20150. t['K'] = 667;
  20151. t['L'] = 611;
  20152. t['M'] = 889;
  20153. t['N'] = 722;
  20154. t['O'] = 722;
  20155. t['P'] = 611;
  20156. t['Q'] = 722;
  20157. t['R'] = 667;
  20158. t['S'] = 556;
  20159. t['T'] = 611;
  20160. t['U'] = 722;
  20161. t['V'] = 667;
  20162. t['W'] = 889;
  20163. t['X'] = 667;
  20164. t['Y'] = 611;
  20165. t['Z'] = 611;
  20166. t['bracketleft'] = 333;
  20167. t['backslash'] = 278;
  20168. t['bracketright'] = 333;
  20169. t['asciicircum'] = 570;
  20170. t['underscore'] = 500;
  20171. t['quoteleft'] = 333;
  20172. t['a'] = 500;
  20173. t['b'] = 500;
  20174. t['c'] = 444;
  20175. t['d'] = 500;
  20176. t['e'] = 444;
  20177. t['f'] = 333;
  20178. t['g'] = 500;
  20179. t['h'] = 556;
  20180. t['i'] = 278;
  20181. t['j'] = 278;
  20182. t['k'] = 500;
  20183. t['l'] = 278;
  20184. t['m'] = 778;
  20185. t['n'] = 556;
  20186. t['o'] = 500;
  20187. t['p'] = 500;
  20188. t['q'] = 500;
  20189. t['r'] = 389;
  20190. t['s'] = 389;
  20191. t['t'] = 278;
  20192. t['u'] = 556;
  20193. t['v'] = 444;
  20194. t['w'] = 667;
  20195. t['x'] = 500;
  20196. t['y'] = 444;
  20197. t['z'] = 389;
  20198. t['braceleft'] = 348;
  20199. t['bar'] = 220;
  20200. t['braceright'] = 348;
  20201. t['asciitilde'] = 570;
  20202. t['exclamdown'] = 389;
  20203. t['cent'] = 500;
  20204. t['sterling'] = 500;
  20205. t['fraction'] = 167;
  20206. t['yen'] = 500;
  20207. t['florin'] = 500;
  20208. t['section'] = 500;
  20209. t['currency'] = 500;
  20210. t['quotesingle'] = 278;
  20211. t['quotedblleft'] = 500;
  20212. t['guillemotleft'] = 500;
  20213. t['guilsinglleft'] = 333;
  20214. t['guilsinglright'] = 333;
  20215. t['fi'] = 556;
  20216. t['fl'] = 556;
  20217. t['endash'] = 500;
  20218. t['dagger'] = 500;
  20219. t['daggerdbl'] = 500;
  20220. t['periodcentered'] = 250;
  20221. t['paragraph'] = 500;
  20222. t['bullet'] = 350;
  20223. t['quotesinglbase'] = 333;
  20224. t['quotedblbase'] = 500;
  20225. t['quotedblright'] = 500;
  20226. t['guillemotright'] = 500;
  20227. t['ellipsis'] = 1000;
  20228. t['perthousand'] = 1000;
  20229. t['questiondown'] = 500;
  20230. t['grave'] = 333;
  20231. t['acute'] = 333;
  20232. t['circumflex'] = 333;
  20233. t['tilde'] = 333;
  20234. t['macron'] = 333;
  20235. t['breve'] = 333;
  20236. t['dotaccent'] = 333;
  20237. t['dieresis'] = 333;
  20238. t['ring'] = 333;
  20239. t['cedilla'] = 333;
  20240. t['hungarumlaut'] = 333;
  20241. t['ogonek'] = 333;
  20242. t['caron'] = 333;
  20243. t['emdash'] = 1000;
  20244. t['AE'] = 944;
  20245. t['ordfeminine'] = 266;
  20246. t['Lslash'] = 611;
  20247. t['Oslash'] = 722;
  20248. t['OE'] = 944;
  20249. t['ordmasculine'] = 300;
  20250. t['ae'] = 722;
  20251. t['dotlessi'] = 278;
  20252. t['lslash'] = 278;
  20253. t['oslash'] = 500;
  20254. t['oe'] = 722;
  20255. t['germandbls'] = 500;
  20256. t['Idieresis'] = 389;
  20257. t['eacute'] = 444;
  20258. t['abreve'] = 500;
  20259. t['uhungarumlaut'] = 556;
  20260. t['ecaron'] = 444;
  20261. t['Ydieresis'] = 611;
  20262. t['divide'] = 570;
  20263. t['Yacute'] = 611;
  20264. t['Acircumflex'] = 667;
  20265. t['aacute'] = 500;
  20266. t['Ucircumflex'] = 722;
  20267. t['yacute'] = 444;
  20268. t['scommaaccent'] = 389;
  20269. t['ecircumflex'] = 444;
  20270. t['Uring'] = 722;
  20271. t['Udieresis'] = 722;
  20272. t['aogonek'] = 500;
  20273. t['Uacute'] = 722;
  20274. t['uogonek'] = 556;
  20275. t['Edieresis'] = 667;
  20276. t['Dcroat'] = 722;
  20277. t['commaaccent'] = 250;
  20278. t['copyright'] = 747;
  20279. t['Emacron'] = 667;
  20280. t['ccaron'] = 444;
  20281. t['aring'] = 500;
  20282. t['Ncommaaccent'] = 722;
  20283. t['lacute'] = 278;
  20284. t['agrave'] = 500;
  20285. t['Tcommaaccent'] = 611;
  20286. t['Cacute'] = 667;
  20287. t['atilde'] = 500;
  20288. t['Edotaccent'] = 667;
  20289. t['scaron'] = 389;
  20290. t['scedilla'] = 389;
  20291. t['iacute'] = 278;
  20292. t['lozenge'] = 494;
  20293. t['Rcaron'] = 667;
  20294. t['Gcommaaccent'] = 722;
  20295. t['ucircumflex'] = 556;
  20296. t['acircumflex'] = 500;
  20297. t['Amacron'] = 667;
  20298. t['rcaron'] = 389;
  20299. t['ccedilla'] = 444;
  20300. t['Zdotaccent'] = 611;
  20301. t['Thorn'] = 611;
  20302. t['Omacron'] = 722;
  20303. t['Racute'] = 667;
  20304. t['Sacute'] = 556;
  20305. t['dcaron'] = 608;
  20306. t['Umacron'] = 722;
  20307. t['uring'] = 556;
  20308. t['threesuperior'] = 300;
  20309. t['Ograve'] = 722;
  20310. t['Agrave'] = 667;
  20311. t['Abreve'] = 667;
  20312. t['multiply'] = 570;
  20313. t['uacute'] = 556;
  20314. t['Tcaron'] = 611;
  20315. t['partialdiff'] = 494;
  20316. t['ydieresis'] = 444;
  20317. t['Nacute'] = 722;
  20318. t['icircumflex'] = 278;
  20319. t['Ecircumflex'] = 667;
  20320. t['adieresis'] = 500;
  20321. t['edieresis'] = 444;
  20322. t['cacute'] = 444;
  20323. t['nacute'] = 556;
  20324. t['umacron'] = 556;
  20325. t['Ncaron'] = 722;
  20326. t['Iacute'] = 389;
  20327. t['plusminus'] = 570;
  20328. t['brokenbar'] = 220;
  20329. t['registered'] = 747;
  20330. t['Gbreve'] = 722;
  20331. t['Idotaccent'] = 389;
  20332. t['summation'] = 600;
  20333. t['Egrave'] = 667;
  20334. t['racute'] = 389;
  20335. t['omacron'] = 500;
  20336. t['Zacute'] = 611;
  20337. t['Zcaron'] = 611;
  20338. t['greaterequal'] = 549;
  20339. t['Eth'] = 722;
  20340. t['Ccedilla'] = 667;
  20341. t['lcommaaccent'] = 278;
  20342. t['tcaron'] = 366;
  20343. t['eogonek'] = 444;
  20344. t['Uogonek'] = 722;
  20345. t['Aacute'] = 667;
  20346. t['Adieresis'] = 667;
  20347. t['egrave'] = 444;
  20348. t['zacute'] = 389;
  20349. t['iogonek'] = 278;
  20350. t['Oacute'] = 722;
  20351. t['oacute'] = 500;
  20352. t['amacron'] = 500;
  20353. t['sacute'] = 389;
  20354. t['idieresis'] = 278;
  20355. t['Ocircumflex'] = 722;
  20356. t['Ugrave'] = 722;
  20357. t['Delta'] = 612;
  20358. t['thorn'] = 500;
  20359. t['twosuperior'] = 300;
  20360. t['Odieresis'] = 722;
  20361. t['mu'] = 576;
  20362. t['igrave'] = 278;
  20363. t['ohungarumlaut'] = 500;
  20364. t['Eogonek'] = 667;
  20365. t['dcroat'] = 500;
  20366. t['threequarters'] = 750;
  20367. t['Scedilla'] = 556;
  20368. t['lcaron'] = 382;
  20369. t['Kcommaaccent'] = 667;
  20370. t['Lacute'] = 611;
  20371. t['trademark'] = 1000;
  20372. t['edotaccent'] = 444;
  20373. t['Igrave'] = 389;
  20374. t['Imacron'] = 389;
  20375. t['Lcaron'] = 611;
  20376. t['onehalf'] = 750;
  20377. t['lessequal'] = 549;
  20378. t['ocircumflex'] = 500;
  20379. t['ntilde'] = 556;
  20380. t['Uhungarumlaut'] = 722;
  20381. t['Eacute'] = 667;
  20382. t['emacron'] = 444;
  20383. t['gbreve'] = 500;
  20384. t['onequarter'] = 750;
  20385. t['Scaron'] = 556;
  20386. t['Scommaaccent'] = 556;
  20387. t['Ohungarumlaut'] = 722;
  20388. t['degree'] = 400;
  20389. t['ograve'] = 500;
  20390. t['Ccaron'] = 667;
  20391. t['ugrave'] = 556;
  20392. t['radical'] = 549;
  20393. t['Dcaron'] = 722;
  20394. t['rcommaaccent'] = 389;
  20395. t['Ntilde'] = 722;
  20396. t['otilde'] = 500;
  20397. t['Rcommaaccent'] = 667;
  20398. t['Lcommaaccent'] = 611;
  20399. t['Atilde'] = 667;
  20400. t['Aogonek'] = 667;
  20401. t['Aring'] = 667;
  20402. t['Otilde'] = 722;
  20403. t['zdotaccent'] = 389;
  20404. t['Ecaron'] = 667;
  20405. t['Iogonek'] = 389;
  20406. t['kcommaaccent'] = 500;
  20407. t['minus'] = 606;
  20408. t['Icircumflex'] = 389;
  20409. t['ncaron'] = 556;
  20410. t['tcommaaccent'] = 278;
  20411. t['logicalnot'] = 606;
  20412. t['odieresis'] = 500;
  20413. t['udieresis'] = 556;
  20414. t['notequal'] = 549;
  20415. t['gcommaaccent'] = 500;
  20416. t['eth'] = 500;
  20417. t['zcaron'] = 389;
  20418. t['ncommaaccent'] = 556;
  20419. t['onesuperior'] = 300;
  20420. t['imacron'] = 278;
  20421. t['Euro'] = 500;
  20422. });
  20423. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20424. t['space'] = 250;
  20425. t['exclam'] = 333;
  20426. t['quotedbl'] = 420;
  20427. t['numbersign'] = 500;
  20428. t['dollar'] = 500;
  20429. t['percent'] = 833;
  20430. t['ampersand'] = 778;
  20431. t['quoteright'] = 333;
  20432. t['parenleft'] = 333;
  20433. t['parenright'] = 333;
  20434. t['asterisk'] = 500;
  20435. t['plus'] = 675;
  20436. t['comma'] = 250;
  20437. t['hyphen'] = 333;
  20438. t['period'] = 250;
  20439. t['slash'] = 278;
  20440. t['zero'] = 500;
  20441. t['one'] = 500;
  20442. t['two'] = 500;
  20443. t['three'] = 500;
  20444. t['four'] = 500;
  20445. t['five'] = 500;
  20446. t['six'] = 500;
  20447. t['seven'] = 500;
  20448. t['eight'] = 500;
  20449. t['nine'] = 500;
  20450. t['colon'] = 333;
  20451. t['semicolon'] = 333;
  20452. t['less'] = 675;
  20453. t['equal'] = 675;
  20454. t['greater'] = 675;
  20455. t['question'] = 500;
  20456. t['at'] = 920;
  20457. t['A'] = 611;
  20458. t['B'] = 611;
  20459. t['C'] = 667;
  20460. t['D'] = 722;
  20461. t['E'] = 611;
  20462. t['F'] = 611;
  20463. t['G'] = 722;
  20464. t['H'] = 722;
  20465. t['I'] = 333;
  20466. t['J'] = 444;
  20467. t['K'] = 667;
  20468. t['L'] = 556;
  20469. t['M'] = 833;
  20470. t['N'] = 667;
  20471. t['O'] = 722;
  20472. t['P'] = 611;
  20473. t['Q'] = 722;
  20474. t['R'] = 611;
  20475. t['S'] = 500;
  20476. t['T'] = 556;
  20477. t['U'] = 722;
  20478. t['V'] = 611;
  20479. t['W'] = 833;
  20480. t['X'] = 611;
  20481. t['Y'] = 556;
  20482. t['Z'] = 556;
  20483. t['bracketleft'] = 389;
  20484. t['backslash'] = 278;
  20485. t['bracketright'] = 389;
  20486. t['asciicircum'] = 422;
  20487. t['underscore'] = 500;
  20488. t['quoteleft'] = 333;
  20489. t['a'] = 500;
  20490. t['b'] = 500;
  20491. t['c'] = 444;
  20492. t['d'] = 500;
  20493. t['e'] = 444;
  20494. t['f'] = 278;
  20495. t['g'] = 500;
  20496. t['h'] = 500;
  20497. t['i'] = 278;
  20498. t['j'] = 278;
  20499. t['k'] = 444;
  20500. t['l'] = 278;
  20501. t['m'] = 722;
  20502. t['n'] = 500;
  20503. t['o'] = 500;
  20504. t['p'] = 500;
  20505. t['q'] = 500;
  20506. t['r'] = 389;
  20507. t['s'] = 389;
  20508. t['t'] = 278;
  20509. t['u'] = 500;
  20510. t['v'] = 444;
  20511. t['w'] = 667;
  20512. t['x'] = 444;
  20513. t['y'] = 444;
  20514. t['z'] = 389;
  20515. t['braceleft'] = 400;
  20516. t['bar'] = 275;
  20517. t['braceright'] = 400;
  20518. t['asciitilde'] = 541;
  20519. t['exclamdown'] = 389;
  20520. t['cent'] = 500;
  20521. t['sterling'] = 500;
  20522. t['fraction'] = 167;
  20523. t['yen'] = 500;
  20524. t['florin'] = 500;
  20525. t['section'] = 500;
  20526. t['currency'] = 500;
  20527. t['quotesingle'] = 214;
  20528. t['quotedblleft'] = 556;
  20529. t['guillemotleft'] = 500;
  20530. t['guilsinglleft'] = 333;
  20531. t['guilsinglright'] = 333;
  20532. t['fi'] = 500;
  20533. t['fl'] = 500;
  20534. t['endash'] = 500;
  20535. t['dagger'] = 500;
  20536. t['daggerdbl'] = 500;
  20537. t['periodcentered'] = 250;
  20538. t['paragraph'] = 523;
  20539. t['bullet'] = 350;
  20540. t['quotesinglbase'] = 333;
  20541. t['quotedblbase'] = 556;
  20542. t['quotedblright'] = 556;
  20543. t['guillemotright'] = 500;
  20544. t['ellipsis'] = 889;
  20545. t['perthousand'] = 1000;
  20546. t['questiondown'] = 500;
  20547. t['grave'] = 333;
  20548. t['acute'] = 333;
  20549. t['circumflex'] = 333;
  20550. t['tilde'] = 333;
  20551. t['macron'] = 333;
  20552. t['breve'] = 333;
  20553. t['dotaccent'] = 333;
  20554. t['dieresis'] = 333;
  20555. t['ring'] = 333;
  20556. t['cedilla'] = 333;
  20557. t['hungarumlaut'] = 333;
  20558. t['ogonek'] = 333;
  20559. t['caron'] = 333;
  20560. t['emdash'] = 889;
  20561. t['AE'] = 889;
  20562. t['ordfeminine'] = 276;
  20563. t['Lslash'] = 556;
  20564. t['Oslash'] = 722;
  20565. t['OE'] = 944;
  20566. t['ordmasculine'] = 310;
  20567. t['ae'] = 667;
  20568. t['dotlessi'] = 278;
  20569. t['lslash'] = 278;
  20570. t['oslash'] = 500;
  20571. t['oe'] = 667;
  20572. t['germandbls'] = 500;
  20573. t['Idieresis'] = 333;
  20574. t['eacute'] = 444;
  20575. t['abreve'] = 500;
  20576. t['uhungarumlaut'] = 500;
  20577. t['ecaron'] = 444;
  20578. t['Ydieresis'] = 556;
  20579. t['divide'] = 675;
  20580. t['Yacute'] = 556;
  20581. t['Acircumflex'] = 611;
  20582. t['aacute'] = 500;
  20583. t['Ucircumflex'] = 722;
  20584. t['yacute'] = 444;
  20585. t['scommaaccent'] = 389;
  20586. t['ecircumflex'] = 444;
  20587. t['Uring'] = 722;
  20588. t['Udieresis'] = 722;
  20589. t['aogonek'] = 500;
  20590. t['Uacute'] = 722;
  20591. t['uogonek'] = 500;
  20592. t['Edieresis'] = 611;
  20593. t['Dcroat'] = 722;
  20594. t['commaaccent'] = 250;
  20595. t['copyright'] = 760;
  20596. t['Emacron'] = 611;
  20597. t['ccaron'] = 444;
  20598. t['aring'] = 500;
  20599. t['Ncommaaccent'] = 667;
  20600. t['lacute'] = 278;
  20601. t['agrave'] = 500;
  20602. t['Tcommaaccent'] = 556;
  20603. t['Cacute'] = 667;
  20604. t['atilde'] = 500;
  20605. t['Edotaccent'] = 611;
  20606. t['scaron'] = 389;
  20607. t['scedilla'] = 389;
  20608. t['iacute'] = 278;
  20609. t['lozenge'] = 471;
  20610. t['Rcaron'] = 611;
  20611. t['Gcommaaccent'] = 722;
  20612. t['ucircumflex'] = 500;
  20613. t['acircumflex'] = 500;
  20614. t['Amacron'] = 611;
  20615. t['rcaron'] = 389;
  20616. t['ccedilla'] = 444;
  20617. t['Zdotaccent'] = 556;
  20618. t['Thorn'] = 611;
  20619. t['Omacron'] = 722;
  20620. t['Racute'] = 611;
  20621. t['Sacute'] = 500;
  20622. t['dcaron'] = 544;
  20623. t['Umacron'] = 722;
  20624. t['uring'] = 500;
  20625. t['threesuperior'] = 300;
  20626. t['Ograve'] = 722;
  20627. t['Agrave'] = 611;
  20628. t['Abreve'] = 611;
  20629. t['multiply'] = 675;
  20630. t['uacute'] = 500;
  20631. t['Tcaron'] = 556;
  20632. t['partialdiff'] = 476;
  20633. t['ydieresis'] = 444;
  20634. t['Nacute'] = 667;
  20635. t['icircumflex'] = 278;
  20636. t['Ecircumflex'] = 611;
  20637. t['adieresis'] = 500;
  20638. t['edieresis'] = 444;
  20639. t['cacute'] = 444;
  20640. t['nacute'] = 500;
  20641. t['umacron'] = 500;
  20642. t['Ncaron'] = 667;
  20643. t['Iacute'] = 333;
  20644. t['plusminus'] = 675;
  20645. t['brokenbar'] = 275;
  20646. t['registered'] = 760;
  20647. t['Gbreve'] = 722;
  20648. t['Idotaccent'] = 333;
  20649. t['summation'] = 600;
  20650. t['Egrave'] = 611;
  20651. t['racute'] = 389;
  20652. t['omacron'] = 500;
  20653. t['Zacute'] = 556;
  20654. t['Zcaron'] = 556;
  20655. t['greaterequal'] = 549;
  20656. t['Eth'] = 722;
  20657. t['Ccedilla'] = 667;
  20658. t['lcommaaccent'] = 278;
  20659. t['tcaron'] = 300;
  20660. t['eogonek'] = 444;
  20661. t['Uogonek'] = 722;
  20662. t['Aacute'] = 611;
  20663. t['Adieresis'] = 611;
  20664. t['egrave'] = 444;
  20665. t['zacute'] = 389;
  20666. t['iogonek'] = 278;
  20667. t['Oacute'] = 722;
  20668. t['oacute'] = 500;
  20669. t['amacron'] = 500;
  20670. t['sacute'] = 389;
  20671. t['idieresis'] = 278;
  20672. t['Ocircumflex'] = 722;
  20673. t['Ugrave'] = 722;
  20674. t['Delta'] = 612;
  20675. t['thorn'] = 500;
  20676. t['twosuperior'] = 300;
  20677. t['Odieresis'] = 722;
  20678. t['mu'] = 500;
  20679. t['igrave'] = 278;
  20680. t['ohungarumlaut'] = 500;
  20681. t['Eogonek'] = 611;
  20682. t['dcroat'] = 500;
  20683. t['threequarters'] = 750;
  20684. t['Scedilla'] = 500;
  20685. t['lcaron'] = 300;
  20686. t['Kcommaaccent'] = 667;
  20687. t['Lacute'] = 556;
  20688. t['trademark'] = 980;
  20689. t['edotaccent'] = 444;
  20690. t['Igrave'] = 333;
  20691. t['Imacron'] = 333;
  20692. t['Lcaron'] = 611;
  20693. t['onehalf'] = 750;
  20694. t['lessequal'] = 549;
  20695. t['ocircumflex'] = 500;
  20696. t['ntilde'] = 500;
  20697. t['Uhungarumlaut'] = 722;
  20698. t['Eacute'] = 611;
  20699. t['emacron'] = 444;
  20700. t['gbreve'] = 500;
  20701. t['onequarter'] = 750;
  20702. t['Scaron'] = 500;
  20703. t['Scommaaccent'] = 500;
  20704. t['Ohungarumlaut'] = 722;
  20705. t['degree'] = 400;
  20706. t['ograve'] = 500;
  20707. t['Ccaron'] = 667;
  20708. t['ugrave'] = 500;
  20709. t['radical'] = 453;
  20710. t['Dcaron'] = 722;
  20711. t['rcommaaccent'] = 389;
  20712. t['Ntilde'] = 667;
  20713. t['otilde'] = 500;
  20714. t['Rcommaaccent'] = 611;
  20715. t['Lcommaaccent'] = 556;
  20716. t['Atilde'] = 611;
  20717. t['Aogonek'] = 611;
  20718. t['Aring'] = 611;
  20719. t['Otilde'] = 722;
  20720. t['zdotaccent'] = 389;
  20721. t['Ecaron'] = 611;
  20722. t['Iogonek'] = 333;
  20723. t['kcommaaccent'] = 444;
  20724. t['minus'] = 675;
  20725. t['Icircumflex'] = 333;
  20726. t['ncaron'] = 500;
  20727. t['tcommaaccent'] = 278;
  20728. t['logicalnot'] = 675;
  20729. t['odieresis'] = 500;
  20730. t['udieresis'] = 500;
  20731. t['notequal'] = 549;
  20732. t['gcommaaccent'] = 500;
  20733. t['eth'] = 500;
  20734. t['zcaron'] = 389;
  20735. t['ncommaaccent'] = 500;
  20736. t['onesuperior'] = 300;
  20737. t['imacron'] = 278;
  20738. t['Euro'] = 500;
  20739. });
  20740. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20741. t['space'] = 278;
  20742. t['a1'] = 974;
  20743. t['a2'] = 961;
  20744. t['a202'] = 974;
  20745. t['a3'] = 980;
  20746. t['a4'] = 719;
  20747. t['a5'] = 789;
  20748. t['a119'] = 790;
  20749. t['a118'] = 791;
  20750. t['a117'] = 690;
  20751. t['a11'] = 960;
  20752. t['a12'] = 939;
  20753. t['a13'] = 549;
  20754. t['a14'] = 855;
  20755. t['a15'] = 911;
  20756. t['a16'] = 933;
  20757. t['a105'] = 911;
  20758. t['a17'] = 945;
  20759. t['a18'] = 974;
  20760. t['a19'] = 755;
  20761. t['a20'] = 846;
  20762. t['a21'] = 762;
  20763. t['a22'] = 761;
  20764. t['a23'] = 571;
  20765. t['a24'] = 677;
  20766. t['a25'] = 763;
  20767. t['a26'] = 760;
  20768. t['a27'] = 759;
  20769. t['a28'] = 754;
  20770. t['a6'] = 494;
  20771. t['a7'] = 552;
  20772. t['a8'] = 537;
  20773. t['a9'] = 577;
  20774. t['a10'] = 692;
  20775. t['a29'] = 786;
  20776. t['a30'] = 788;
  20777. t['a31'] = 788;
  20778. t['a32'] = 790;
  20779. t['a33'] = 793;
  20780. t['a34'] = 794;
  20781. t['a35'] = 816;
  20782. t['a36'] = 823;
  20783. t['a37'] = 789;
  20784. t['a38'] = 841;
  20785. t['a39'] = 823;
  20786. t['a40'] = 833;
  20787. t['a41'] = 816;
  20788. t['a42'] = 831;
  20789. t['a43'] = 923;
  20790. t['a44'] = 744;
  20791. t['a45'] = 723;
  20792. t['a46'] = 749;
  20793. t['a47'] = 790;
  20794. t['a48'] = 792;
  20795. t['a49'] = 695;
  20796. t['a50'] = 776;
  20797. t['a51'] = 768;
  20798. t['a52'] = 792;
  20799. t['a53'] = 759;
  20800. t['a54'] = 707;
  20801. t['a55'] = 708;
  20802. t['a56'] = 682;
  20803. t['a57'] = 701;
  20804. t['a58'] = 826;
  20805. t['a59'] = 815;
  20806. t['a60'] = 789;
  20807. t['a61'] = 789;
  20808. t['a62'] = 707;
  20809. t['a63'] = 687;
  20810. t['a64'] = 696;
  20811. t['a65'] = 689;
  20812. t['a66'] = 786;
  20813. t['a67'] = 787;
  20814. t['a68'] = 713;
  20815. t['a69'] = 791;
  20816. t['a70'] = 785;
  20817. t['a71'] = 791;
  20818. t['a72'] = 873;
  20819. t['a73'] = 761;
  20820. t['a74'] = 762;
  20821. t['a203'] = 762;
  20822. t['a75'] = 759;
  20823. t['a204'] = 759;
  20824. t['a76'] = 892;
  20825. t['a77'] = 892;
  20826. t['a78'] = 788;
  20827. t['a79'] = 784;
  20828. t['a81'] = 438;
  20829. t['a82'] = 138;
  20830. t['a83'] = 277;
  20831. t['a84'] = 415;
  20832. t['a97'] = 392;
  20833. t['a98'] = 392;
  20834. t['a99'] = 668;
  20835. t['a100'] = 668;
  20836. t['a89'] = 390;
  20837. t['a90'] = 390;
  20838. t['a93'] = 317;
  20839. t['a94'] = 317;
  20840. t['a91'] = 276;
  20841. t['a92'] = 276;
  20842. t['a205'] = 509;
  20843. t['a85'] = 509;
  20844. t['a206'] = 410;
  20845. t['a86'] = 410;
  20846. t['a87'] = 234;
  20847. t['a88'] = 234;
  20848. t['a95'] = 334;
  20849. t['a96'] = 334;
  20850. t['a101'] = 732;
  20851. t['a102'] = 544;
  20852. t['a103'] = 544;
  20853. t['a104'] = 910;
  20854. t['a106'] = 667;
  20855. t['a107'] = 760;
  20856. t['a108'] = 760;
  20857. t['a112'] = 776;
  20858. t['a111'] = 595;
  20859. t['a110'] = 694;
  20860. t['a109'] = 626;
  20861. t['a120'] = 788;
  20862. t['a121'] = 788;
  20863. t['a122'] = 788;
  20864. t['a123'] = 788;
  20865. t['a124'] = 788;
  20866. t['a125'] = 788;
  20867. t['a126'] = 788;
  20868. t['a127'] = 788;
  20869. t['a128'] = 788;
  20870. t['a129'] = 788;
  20871. t['a130'] = 788;
  20872. t['a131'] = 788;
  20873. t['a132'] = 788;
  20874. t['a133'] = 788;
  20875. t['a134'] = 788;
  20876. t['a135'] = 788;
  20877. t['a136'] = 788;
  20878. t['a137'] = 788;
  20879. t['a138'] = 788;
  20880. t['a139'] = 788;
  20881. t['a140'] = 788;
  20882. t['a141'] = 788;
  20883. t['a142'] = 788;
  20884. t['a143'] = 788;
  20885. t['a144'] = 788;
  20886. t['a145'] = 788;
  20887. t['a146'] = 788;
  20888. t['a147'] = 788;
  20889. t['a148'] = 788;
  20890. t['a149'] = 788;
  20891. t['a150'] = 788;
  20892. t['a151'] = 788;
  20893. t['a152'] = 788;
  20894. t['a153'] = 788;
  20895. t['a154'] = 788;
  20896. t['a155'] = 788;
  20897. t['a156'] = 788;
  20898. t['a157'] = 788;
  20899. t['a158'] = 788;
  20900. t['a159'] = 788;
  20901. t['a160'] = 894;
  20902. t['a161'] = 838;
  20903. t['a163'] = 1016;
  20904. t['a164'] = 458;
  20905. t['a196'] = 748;
  20906. t['a165'] = 924;
  20907. t['a192'] = 748;
  20908. t['a166'] = 918;
  20909. t['a167'] = 927;
  20910. t['a168'] = 928;
  20911. t['a169'] = 928;
  20912. t['a170'] = 834;
  20913. t['a171'] = 873;
  20914. t['a172'] = 828;
  20915. t['a173'] = 924;
  20916. t['a162'] = 924;
  20917. t['a174'] = 917;
  20918. t['a175'] = 930;
  20919. t['a176'] = 931;
  20920. t['a177'] = 463;
  20921. t['a178'] = 883;
  20922. t['a179'] = 836;
  20923. t['a193'] = 836;
  20924. t['a180'] = 867;
  20925. t['a199'] = 867;
  20926. t['a181'] = 696;
  20927. t['a200'] = 696;
  20928. t['a182'] = 874;
  20929. t['a201'] = 874;
  20930. t['a183'] = 760;
  20931. t['a184'] = 946;
  20932. t['a197'] = 771;
  20933. t['a185'] = 865;
  20934. t['a194'] = 771;
  20935. t['a198'] = 888;
  20936. t['a186'] = 967;
  20937. t['a195'] = 888;
  20938. t['a187'] = 831;
  20939. t['a188'] = 873;
  20940. t['a189'] = 927;
  20941. t['a190'] = 970;
  20942. t['a191'] = 918;
  20943. });
  20944. });
  20945. exports.getMetrics = getMetrics;
  20946. }));
  20947. (function (root, factory) {
  20948. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20949. }(this, function (exports, sharedUtil) {
  20950. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20951. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20952. // Workaround for missing math precision in JS.
  20953. var MASK_HIGH = 0xffff0000;
  20954. var MASK_LOW = 0xffff;
  20955. function MurmurHash3_64(seed) {
  20956. var SEED = 0xc3d2e1f0;
  20957. this.h1 = seed ? seed & 0xffffffff : SEED;
  20958. this.h2 = seed ? seed & 0xffffffff : SEED;
  20959. }
  20960. var alwaysUseUint32ArrayView = false;
  20961. // old webkits have issues with non-aligned arrays
  20962. try {
  20963. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20964. } catch (e) {
  20965. alwaysUseUint32ArrayView = true;
  20966. }
  20967. MurmurHash3_64.prototype = {
  20968. update: function MurmurHash3_64_update(input) {
  20969. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20970. var i;
  20971. if (typeof input === 'string') {
  20972. var data = new Uint8Array(input.length * 2);
  20973. var length = 0;
  20974. for (i = 0; i < input.length; i++) {
  20975. var code = input.charCodeAt(i);
  20976. if (code <= 0xff) {
  20977. data[length++] = code;
  20978. } else {
  20979. data[length++] = code >>> 8;
  20980. data[length++] = code & 0xff;
  20981. }
  20982. }
  20983. } else if (input instanceof Uint8Array) {
  20984. data = input;
  20985. length = data.length;
  20986. } else if (typeof input === 'object' && 'length' in input) {
  20987. // processing regular arrays as well, e.g. for IE9
  20988. data = input;
  20989. length = data.length;
  20990. useUint32ArrayView = true;
  20991. } else {
  20992. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20993. }
  20994. var blockCounts = length >> 2;
  20995. var tailLength = length - blockCounts * 4;
  20996. // we don't care about endianness here
  20997. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  20998. var k1 = 0;
  20999. var k2 = 0;
  21000. var h1 = this.h1;
  21001. var h2 = this.h2;
  21002. var C1 = 0xcc9e2d51;
  21003. var C2 = 0x1b873593;
  21004. var C1_LOW = C1 & MASK_LOW;
  21005. var C2_LOW = C2 & MASK_LOW;
  21006. for (i = 0; i < blockCounts; i++) {
  21007. if (i & 1) {
  21008. k1 = dataUint32[i];
  21009. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21010. k1 = k1 << 15 | k1 >>> 17;
  21011. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21012. h1 ^= k1;
  21013. h1 = h1 << 13 | h1 >>> 19;
  21014. h1 = h1 * 5 + 0xe6546b64;
  21015. } else {
  21016. k2 = dataUint32[i];
  21017. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21018. k2 = k2 << 15 | k2 >>> 17;
  21019. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21020. h2 ^= k2;
  21021. h2 = h2 << 13 | h2 >>> 19;
  21022. h2 = h2 * 5 + 0xe6546b64;
  21023. }
  21024. }
  21025. k1 = 0;
  21026. switch (tailLength) {
  21027. case 3:
  21028. k1 ^= data[blockCounts * 4 + 2] << 16;
  21029. case 2:
  21030. k1 ^= data[blockCounts * 4 + 1] << 8;
  21031. case 1:
  21032. k1 ^= data[blockCounts * 4];
  21033. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21034. k1 = k1 << 15 | k1 >>> 17;
  21035. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21036. if (blockCounts & 1) {
  21037. h1 ^= k1;
  21038. } else {
  21039. h2 ^= k1;
  21040. }
  21041. }
  21042. this.h1 = h1;
  21043. this.h2 = h2;
  21044. return this;
  21045. },
  21046. hexdigest: function MurmurHash3_64_hexdigest() {
  21047. var h1 = this.h1;
  21048. var h2 = this.h2;
  21049. h1 ^= h2 >>> 1;
  21050. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21051. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21052. h1 ^= h2 >>> 1;
  21053. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21054. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21055. h1 ^= h2 >>> 1;
  21056. for (var i = 0, arr = [
  21057. h1,
  21058. h2
  21059. ], str = ''; i < arr.length; i++) {
  21060. var hex = (arr[i] >>> 0).toString(16);
  21061. while (hex.length < 8) {
  21062. hex = '0' + hex;
  21063. }
  21064. str += hex;
  21065. }
  21066. return str;
  21067. }
  21068. };
  21069. return MurmurHash3_64;
  21070. }();
  21071. exports.MurmurHash3_64 = MurmurHash3_64;
  21072. }));
  21073. (function (root, factory) {
  21074. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21075. }(this, function (exports, sharedUtil) {
  21076. var isArray = sharedUtil.isArray;
  21077. var Name = function NameClosure() {
  21078. function Name(name) {
  21079. this.name = name;
  21080. }
  21081. Name.prototype = {};
  21082. var nameCache = Object.create(null);
  21083. Name.get = function Name_get(name) {
  21084. var nameValue = nameCache[name];
  21085. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21086. };
  21087. return Name;
  21088. }();
  21089. var Cmd = function CmdClosure() {
  21090. function Cmd(cmd) {
  21091. this.cmd = cmd;
  21092. }
  21093. Cmd.prototype = {};
  21094. var cmdCache = Object.create(null);
  21095. Cmd.get = function Cmd_get(cmd) {
  21096. var cmdValue = cmdCache[cmd];
  21097. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21098. };
  21099. return Cmd;
  21100. }();
  21101. var Dict = function DictClosure() {
  21102. var nonSerializable = function nonSerializableClosure() {
  21103. return nonSerializable;
  21104. };
  21105. // creating closure on some variable
  21106. // xref is optional
  21107. function Dict(xref) {
  21108. // Map should only be used internally, use functions below to access.
  21109. this.map = Object.create(null);
  21110. this.xref = xref;
  21111. this.objId = null;
  21112. this.suppressEncryption = false;
  21113. this.__nonSerializable__ = nonSerializable;
  21114. }
  21115. // disable cloning of the Dict
  21116. Dict.prototype = {
  21117. assignXref: function Dict_assignXref(newXref) {
  21118. this.xref = newXref;
  21119. },
  21120. // automatically dereferences Ref objects
  21121. get: function Dict_get(key1, key2, key3) {
  21122. var value;
  21123. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21124. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21125. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21126. }
  21127. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21128. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21129. }
  21130. value = this.map[key3] || null;
  21131. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21132. },
  21133. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21134. getAsync: function Dict_getAsync(key1, key2, key3) {
  21135. var value;
  21136. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21137. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21138. if (xref) {
  21139. return xref.fetchIfRefAsync(value, suppressEncryption);
  21140. }
  21141. return Promise.resolve(value);
  21142. }
  21143. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21144. if (xref) {
  21145. return xref.fetchIfRefAsync(value, suppressEncryption);
  21146. }
  21147. return Promise.resolve(value);
  21148. }
  21149. value = this.map[key3] || null;
  21150. if (xref) {
  21151. return xref.fetchIfRefAsync(value, suppressEncryption);
  21152. }
  21153. return Promise.resolve(value);
  21154. },
  21155. // Same as get(), but dereferences all elements if the result is an Array.
  21156. getArray: function Dict_getArray(key1, key2, key3) {
  21157. var value = this.get(key1, key2, key3);
  21158. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21159. if (!isArray(value) || !xref) {
  21160. return value;
  21161. }
  21162. value = value.slice();
  21163. // Ensure that we don't modify the Dict data.
  21164. for (var i = 0, ii = value.length; i < ii; i++) {
  21165. if (!isRef(value[i])) {
  21166. continue;
  21167. }
  21168. value[i] = xref.fetch(value[i], suppressEncryption);
  21169. }
  21170. return value;
  21171. },
  21172. // no dereferencing
  21173. getRaw: function Dict_getRaw(key) {
  21174. return this.map[key];
  21175. },
  21176. getKeys: function Dict_getKeys() {
  21177. return Object.keys(this.map);
  21178. },
  21179. set: function Dict_set(key, value) {
  21180. this.map[key] = value;
  21181. },
  21182. has: function Dict_has(key) {
  21183. return key in this.map;
  21184. },
  21185. forEach: function Dict_forEach(callback) {
  21186. for (var key in this.map) {
  21187. callback(key, this.get(key));
  21188. }
  21189. }
  21190. };
  21191. Dict.empty = new Dict(null);
  21192. Dict.merge = function Dict_merge(xref, dictArray) {
  21193. var mergedDict = new Dict(xref);
  21194. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21195. var dict = dictArray[i];
  21196. if (!isDict(dict)) {
  21197. continue;
  21198. }
  21199. for (var keyName in dict.map) {
  21200. if (mergedDict.map[keyName]) {
  21201. continue;
  21202. }
  21203. mergedDict.map[keyName] = dict.map[keyName];
  21204. }
  21205. }
  21206. return mergedDict;
  21207. };
  21208. return Dict;
  21209. }();
  21210. var Ref = function RefClosure() {
  21211. function Ref(num, gen) {
  21212. this.num = num;
  21213. this.gen = gen;
  21214. }
  21215. Ref.prototype = {
  21216. toString: function Ref_toString() {
  21217. // This function is hot, so we make the string as compact as possible.
  21218. // |this.gen| is almost always zero, so we treat that case specially.
  21219. var str = this.num + 'R';
  21220. if (this.gen !== 0) {
  21221. str += this.gen;
  21222. }
  21223. return str;
  21224. }
  21225. };
  21226. return Ref;
  21227. }();
  21228. // The reference is identified by number and generation.
  21229. // This structure stores only one instance of the reference.
  21230. var RefSet = function RefSetClosure() {
  21231. function RefSet() {
  21232. this.dict = Object.create(null);
  21233. }
  21234. RefSet.prototype = {
  21235. has: function RefSet_has(ref) {
  21236. return ref.toString() in this.dict;
  21237. },
  21238. put: function RefSet_put(ref) {
  21239. this.dict[ref.toString()] = true;
  21240. },
  21241. remove: function RefSet_remove(ref) {
  21242. delete this.dict[ref.toString()];
  21243. }
  21244. };
  21245. return RefSet;
  21246. }();
  21247. var RefSetCache = function RefSetCacheClosure() {
  21248. function RefSetCache() {
  21249. this.dict = Object.create(null);
  21250. }
  21251. RefSetCache.prototype = {
  21252. get: function RefSetCache_get(ref) {
  21253. return this.dict[ref.toString()];
  21254. },
  21255. has: function RefSetCache_has(ref) {
  21256. return ref.toString() in this.dict;
  21257. },
  21258. put: function RefSetCache_put(ref, obj) {
  21259. this.dict[ref.toString()] = obj;
  21260. },
  21261. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21262. this.dict[ref.toString()] = this.get(aliasRef);
  21263. },
  21264. forEach: function RefSetCache_forEach(fn, thisArg) {
  21265. for (var i in this.dict) {
  21266. fn.call(thisArg, this.dict[i]);
  21267. }
  21268. },
  21269. clear: function RefSetCache_clear() {
  21270. this.dict = Object.create(null);
  21271. }
  21272. };
  21273. return RefSetCache;
  21274. }();
  21275. function isName(v, name) {
  21276. return v instanceof Name && (name === undefined || v.name === name);
  21277. }
  21278. function isCmd(v, cmd) {
  21279. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21280. }
  21281. function isDict(v, type) {
  21282. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21283. }
  21284. function isRef(v) {
  21285. return v instanceof Ref;
  21286. }
  21287. function isRefsEqual(v1, v2) {
  21288. return v1.num === v2.num && v1.gen === v2.gen;
  21289. }
  21290. function isStream(v) {
  21291. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21292. }
  21293. exports.Cmd = Cmd;
  21294. exports.Dict = Dict;
  21295. exports.Name = Name;
  21296. exports.Ref = Ref;
  21297. exports.RefSet = RefSet;
  21298. exports.RefSetCache = RefSetCache;
  21299. exports.isCmd = isCmd;
  21300. exports.isDict = isDict;
  21301. exports.isName = isName;
  21302. exports.isRef = isRef;
  21303. exports.isRefsEqual = isRefsEqual;
  21304. exports.isStream = isStream;
  21305. }));
  21306. (function (root, factory) {
  21307. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21308. }(this, function (exports, sharedUtil) {
  21309. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21310. /**
  21311. * Hold a map of decoded fonts and of the standard fourteen Type1
  21312. * fonts and their acronyms.
  21313. */
  21314. var getStdFontMap = getLookupTableFactory(function (t) {
  21315. t['ArialNarrow'] = 'Helvetica';
  21316. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21317. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21318. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21319. t['ArialBlack'] = 'Helvetica';
  21320. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21321. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21322. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21323. t['Arial'] = 'Helvetica';
  21324. t['Arial-Bold'] = 'Helvetica-Bold';
  21325. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21326. t['Arial-Italic'] = 'Helvetica-Oblique';
  21327. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21328. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21329. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21330. t['ArialMT'] = 'Helvetica';
  21331. t['Courier-Bold'] = 'Courier-Bold';
  21332. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21333. t['Courier-Italic'] = 'Courier-Oblique';
  21334. t['CourierNew'] = 'Courier';
  21335. t['CourierNew-Bold'] = 'Courier-Bold';
  21336. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21337. t['CourierNew-Italic'] = 'Courier-Oblique';
  21338. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21339. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21340. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21341. t['CourierNewPSMT'] = 'Courier';
  21342. t['Helvetica'] = 'Helvetica';
  21343. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21344. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21345. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21346. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21347. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21348. t['Symbol-Bold'] = 'Symbol';
  21349. t['Symbol-BoldItalic'] = 'Symbol';
  21350. t['Symbol-Italic'] = 'Symbol';
  21351. t['TimesNewRoman'] = 'Times-Roman';
  21352. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21353. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21354. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21355. t['TimesNewRomanPS'] = 'Times-Roman';
  21356. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21357. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21358. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21359. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21360. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21361. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21362. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21363. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21364. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21365. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21366. });
  21367. /**
  21368. * Holds the map of the non-standard fonts that might be included as
  21369. * a standard fonts without glyph data.
  21370. */
  21371. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21372. t['CenturyGothic'] = 'Helvetica';
  21373. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21374. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21375. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21376. t['ComicSansMS'] = 'Comic Sans MS';
  21377. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21378. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21379. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21380. t['LucidaConsole'] = 'Courier';
  21381. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21382. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21383. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21384. t['MS-Gothic'] = 'MS Gothic';
  21385. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21386. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21387. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21388. t['MS-Mincho'] = 'MS Mincho';
  21389. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21390. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21391. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21392. t['MS-PGothic'] = 'MS PGothic';
  21393. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21394. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21395. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21396. t['MS-PMincho'] = 'MS PMincho';
  21397. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21398. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21399. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21400. t['Wingdings'] = 'ZapfDingbats';
  21401. });
  21402. var getSerifFonts = getLookupTableFactory(function (t) {
  21403. t['Adobe Jenson'] = true;
  21404. t['Adobe Text'] = true;
  21405. t['Albertus'] = true;
  21406. t['Aldus'] = true;
  21407. t['Alexandria'] = true;
  21408. t['Algerian'] = true;
  21409. t['American Typewriter'] = true;
  21410. t['Antiqua'] = true;
  21411. t['Apex'] = true;
  21412. t['Arno'] = true;
  21413. t['Aster'] = true;
  21414. t['Aurora'] = true;
  21415. t['Baskerville'] = true;
  21416. t['Bell'] = true;
  21417. t['Bembo'] = true;
  21418. t['Bembo Schoolbook'] = true;
  21419. t['Benguiat'] = true;
  21420. t['Berkeley Old Style'] = true;
  21421. t['Bernhard Modern'] = true;
  21422. t['Berthold City'] = true;
  21423. t['Bodoni'] = true;
  21424. t['Bauer Bodoni'] = true;
  21425. t['Book Antiqua'] = true;
  21426. t['Bookman'] = true;
  21427. t['Bordeaux Roman'] = true;
  21428. t['Californian FB'] = true;
  21429. t['Calisto'] = true;
  21430. t['Calvert'] = true;
  21431. t['Capitals'] = true;
  21432. t['Cambria'] = true;
  21433. t['Cartier'] = true;
  21434. t['Caslon'] = true;
  21435. t['Catull'] = true;
  21436. t['Centaur'] = true;
  21437. t['Century Old Style'] = true;
  21438. t['Century Schoolbook'] = true;
  21439. t['Chaparral'] = true;
  21440. t['Charis SIL'] = true;
  21441. t['Cheltenham'] = true;
  21442. t['Cholla Slab'] = true;
  21443. t['Clarendon'] = true;
  21444. t['Clearface'] = true;
  21445. t['Cochin'] = true;
  21446. t['Colonna'] = true;
  21447. t['Computer Modern'] = true;
  21448. t['Concrete Roman'] = true;
  21449. t['Constantia'] = true;
  21450. t['Cooper Black'] = true;
  21451. t['Corona'] = true;
  21452. t['Ecotype'] = true;
  21453. t['Egyptienne'] = true;
  21454. t['Elephant'] = true;
  21455. t['Excelsior'] = true;
  21456. t['Fairfield'] = true;
  21457. t['FF Scala'] = true;
  21458. t['Folkard'] = true;
  21459. t['Footlight'] = true;
  21460. t['FreeSerif'] = true;
  21461. t['Friz Quadrata'] = true;
  21462. t['Garamond'] = true;
  21463. t['Gentium'] = true;
  21464. t['Georgia'] = true;
  21465. t['Gloucester'] = true;
  21466. t['Goudy Old Style'] = true;
  21467. t['Goudy Schoolbook'] = true;
  21468. t['Goudy Pro Font'] = true;
  21469. t['Granjon'] = true;
  21470. t['Guardian Egyptian'] = true;
  21471. t['Heather'] = true;
  21472. t['Hercules'] = true;
  21473. t['High Tower Text'] = true;
  21474. t['Hiroshige'] = true;
  21475. t['Hoefler Text'] = true;
  21476. t['Humana Serif'] = true;
  21477. t['Imprint'] = true;
  21478. t['Ionic No. 5'] = true;
  21479. t['Janson'] = true;
  21480. t['Joanna'] = true;
  21481. t['Korinna'] = true;
  21482. t['Lexicon'] = true;
  21483. t['Liberation Serif'] = true;
  21484. t['Linux Libertine'] = true;
  21485. t['Literaturnaya'] = true;
  21486. t['Lucida'] = true;
  21487. t['Lucida Bright'] = true;
  21488. t['Melior'] = true;
  21489. t['Memphis'] = true;
  21490. t['Miller'] = true;
  21491. t['Minion'] = true;
  21492. t['Modern'] = true;
  21493. t['Mona Lisa'] = true;
  21494. t['Mrs Eaves'] = true;
  21495. t['MS Serif'] = true;
  21496. t['Museo Slab'] = true;
  21497. t['New York'] = true;
  21498. t['Nimbus Roman'] = true;
  21499. t['NPS Rawlinson Roadway'] = true;
  21500. t['Palatino'] = true;
  21501. t['Perpetua'] = true;
  21502. t['Plantin'] = true;
  21503. t['Plantin Schoolbook'] = true;
  21504. t['Playbill'] = true;
  21505. t['Poor Richard'] = true;
  21506. t['Rawlinson Roadway'] = true;
  21507. t['Renault'] = true;
  21508. t['Requiem'] = true;
  21509. t['Rockwell'] = true;
  21510. t['Roman'] = true;
  21511. t['Rotis Serif'] = true;
  21512. t['Sabon'] = true;
  21513. t['Scala'] = true;
  21514. t['Seagull'] = true;
  21515. t['Sistina'] = true;
  21516. t['Souvenir'] = true;
  21517. t['STIX'] = true;
  21518. t['Stone Informal'] = true;
  21519. t['Stone Serif'] = true;
  21520. t['Sylfaen'] = true;
  21521. t['Times'] = true;
  21522. t['Trajan'] = true;
  21523. t['Trinité'] = true;
  21524. t['Trump Mediaeval'] = true;
  21525. t['Utopia'] = true;
  21526. t['Vale Type'] = true;
  21527. t['Bitstream Vera'] = true;
  21528. t['Vera Serif'] = true;
  21529. t['Versailles'] = true;
  21530. t['Wanted'] = true;
  21531. t['Weiss'] = true;
  21532. t['Wide Latin'] = true;
  21533. t['Windsor'] = true;
  21534. t['XITS'] = true;
  21535. });
  21536. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21537. t['Dingbats'] = true;
  21538. t['Symbol'] = true;
  21539. t['ZapfDingbats'] = true;
  21540. });
  21541. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21542. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21543. // for all glyphs, but common for some set of the standard fonts.
  21544. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21545. t[2] = 10;
  21546. t[3] = 32;
  21547. t[4] = 33;
  21548. t[5] = 34;
  21549. t[6] = 35;
  21550. t[7] = 36;
  21551. t[8] = 37;
  21552. t[9] = 38;
  21553. t[10] = 39;
  21554. t[11] = 40;
  21555. t[12] = 41;
  21556. t[13] = 42;
  21557. t[14] = 43;
  21558. t[15] = 44;
  21559. t[16] = 45;
  21560. t[17] = 46;
  21561. t[18] = 47;
  21562. t[19] = 48;
  21563. t[20] = 49;
  21564. t[21] = 50;
  21565. t[22] = 51;
  21566. t[23] = 52;
  21567. t[24] = 53;
  21568. t[25] = 54;
  21569. t[26] = 55;
  21570. t[27] = 56;
  21571. t[28] = 57;
  21572. t[29] = 58;
  21573. t[30] = 894;
  21574. t[31] = 60;
  21575. t[32] = 61;
  21576. t[33] = 62;
  21577. t[34] = 63;
  21578. t[35] = 64;
  21579. t[36] = 65;
  21580. t[37] = 66;
  21581. t[38] = 67;
  21582. t[39] = 68;
  21583. t[40] = 69;
  21584. t[41] = 70;
  21585. t[42] = 71;
  21586. t[43] = 72;
  21587. t[44] = 73;
  21588. t[45] = 74;
  21589. t[46] = 75;
  21590. t[47] = 76;
  21591. t[48] = 77;
  21592. t[49] = 78;
  21593. t[50] = 79;
  21594. t[51] = 80;
  21595. t[52] = 81;
  21596. t[53] = 82;
  21597. t[54] = 83;
  21598. t[55] = 84;
  21599. t[56] = 85;
  21600. t[57] = 86;
  21601. t[58] = 87;
  21602. t[59] = 88;
  21603. t[60] = 89;
  21604. t[61] = 90;
  21605. t[62] = 91;
  21606. t[63] = 92;
  21607. t[64] = 93;
  21608. t[65] = 94;
  21609. t[66] = 95;
  21610. t[67] = 96;
  21611. t[68] = 97;
  21612. t[69] = 98;
  21613. t[70] = 99;
  21614. t[71] = 100;
  21615. t[72] = 101;
  21616. t[73] = 102;
  21617. t[74] = 103;
  21618. t[75] = 104;
  21619. t[76] = 105;
  21620. t[77] = 106;
  21621. t[78] = 107;
  21622. t[79] = 108;
  21623. t[80] = 109;
  21624. t[81] = 110;
  21625. t[82] = 111;
  21626. t[83] = 112;
  21627. t[84] = 113;
  21628. t[85] = 114;
  21629. t[86] = 115;
  21630. t[87] = 116;
  21631. t[88] = 117;
  21632. t[89] = 118;
  21633. t[90] = 119;
  21634. t[91] = 120;
  21635. t[92] = 121;
  21636. t[93] = 122;
  21637. t[94] = 123;
  21638. t[95] = 124;
  21639. t[96] = 125;
  21640. t[97] = 126;
  21641. t[98] = 196;
  21642. t[99] = 197;
  21643. t[100] = 199;
  21644. t[101] = 201;
  21645. t[102] = 209;
  21646. t[103] = 214;
  21647. t[104] = 220;
  21648. t[105] = 225;
  21649. t[106] = 224;
  21650. t[107] = 226;
  21651. t[108] = 228;
  21652. t[109] = 227;
  21653. t[110] = 229;
  21654. t[111] = 231;
  21655. t[112] = 233;
  21656. t[113] = 232;
  21657. t[114] = 234;
  21658. t[115] = 235;
  21659. t[116] = 237;
  21660. t[117] = 236;
  21661. t[118] = 238;
  21662. t[119] = 239;
  21663. t[120] = 241;
  21664. t[121] = 243;
  21665. t[122] = 242;
  21666. t[123] = 244;
  21667. t[124] = 246;
  21668. t[125] = 245;
  21669. t[126] = 250;
  21670. t[127] = 249;
  21671. t[128] = 251;
  21672. t[129] = 252;
  21673. t[130] = 8224;
  21674. t[131] = 176;
  21675. t[132] = 162;
  21676. t[133] = 163;
  21677. t[134] = 167;
  21678. t[135] = 8226;
  21679. t[136] = 182;
  21680. t[137] = 223;
  21681. t[138] = 174;
  21682. t[139] = 169;
  21683. t[140] = 8482;
  21684. t[141] = 180;
  21685. t[142] = 168;
  21686. t[143] = 8800;
  21687. t[144] = 198;
  21688. t[145] = 216;
  21689. t[146] = 8734;
  21690. t[147] = 177;
  21691. t[148] = 8804;
  21692. t[149] = 8805;
  21693. t[150] = 165;
  21694. t[151] = 181;
  21695. t[152] = 8706;
  21696. t[153] = 8721;
  21697. t[154] = 8719;
  21698. t[156] = 8747;
  21699. t[157] = 170;
  21700. t[158] = 186;
  21701. t[159] = 8486;
  21702. t[160] = 230;
  21703. t[161] = 248;
  21704. t[162] = 191;
  21705. t[163] = 161;
  21706. t[164] = 172;
  21707. t[165] = 8730;
  21708. t[166] = 402;
  21709. t[167] = 8776;
  21710. t[168] = 8710;
  21711. t[169] = 171;
  21712. t[170] = 187;
  21713. t[171] = 8230;
  21714. t[210] = 218;
  21715. t[223] = 711;
  21716. t[224] = 321;
  21717. t[225] = 322;
  21718. t[227] = 353;
  21719. t[229] = 382;
  21720. t[234] = 253;
  21721. t[252] = 263;
  21722. t[253] = 268;
  21723. t[254] = 269;
  21724. t[258] = 258;
  21725. t[260] = 260;
  21726. t[261] = 261;
  21727. t[265] = 280;
  21728. t[266] = 281;
  21729. t[268] = 283;
  21730. t[269] = 313;
  21731. t[275] = 323;
  21732. t[276] = 324;
  21733. t[278] = 328;
  21734. t[284] = 345;
  21735. t[285] = 346;
  21736. t[286] = 347;
  21737. t[292] = 367;
  21738. t[295] = 377;
  21739. t[296] = 378;
  21740. t[298] = 380;
  21741. t[305] = 963;
  21742. t[306] = 964;
  21743. t[307] = 966;
  21744. t[308] = 8215;
  21745. t[309] = 8252;
  21746. t[310] = 8319;
  21747. t[311] = 8359;
  21748. t[312] = 8592;
  21749. t[313] = 8593;
  21750. t[337] = 9552;
  21751. t[493] = 1039;
  21752. t[494] = 1040;
  21753. t[705] = 1524;
  21754. t[706] = 8362;
  21755. t[710] = 64288;
  21756. t[711] = 64298;
  21757. t[759] = 1617;
  21758. t[761] = 1776;
  21759. t[763] = 1778;
  21760. t[775] = 1652;
  21761. t[777] = 1764;
  21762. t[778] = 1780;
  21763. t[779] = 1781;
  21764. t[780] = 1782;
  21765. t[782] = 771;
  21766. t[783] = 64726;
  21767. t[786] = 8363;
  21768. t[788] = 8532;
  21769. t[790] = 768;
  21770. t[791] = 769;
  21771. t[792] = 768;
  21772. t[795] = 803;
  21773. t[797] = 64336;
  21774. t[798] = 64337;
  21775. t[799] = 64342;
  21776. t[800] = 64343;
  21777. t[801] = 64344;
  21778. t[802] = 64345;
  21779. t[803] = 64362;
  21780. t[804] = 64363;
  21781. t[805] = 64364;
  21782. t[2424] = 7821;
  21783. t[2425] = 7822;
  21784. t[2426] = 7823;
  21785. t[2427] = 7824;
  21786. t[2428] = 7825;
  21787. t[2429] = 7826;
  21788. t[2430] = 7827;
  21789. t[2433] = 7682;
  21790. t[2678] = 8045;
  21791. t[2679] = 8046;
  21792. t[2830] = 1552;
  21793. t[2838] = 686;
  21794. t[2840] = 751;
  21795. t[2842] = 753;
  21796. t[2843] = 754;
  21797. t[2844] = 755;
  21798. t[2846] = 757;
  21799. t[2856] = 767;
  21800. t[2857] = 848;
  21801. t[2858] = 849;
  21802. t[2862] = 853;
  21803. t[2863] = 854;
  21804. t[2864] = 855;
  21805. t[2865] = 861;
  21806. t[2866] = 862;
  21807. t[2906] = 7460;
  21808. t[2908] = 7462;
  21809. t[2909] = 7463;
  21810. t[2910] = 7464;
  21811. t[2912] = 7466;
  21812. t[2913] = 7467;
  21813. t[2914] = 7468;
  21814. t[2916] = 7470;
  21815. t[2917] = 7471;
  21816. t[2918] = 7472;
  21817. t[2920] = 7474;
  21818. t[2921] = 7475;
  21819. t[2922] = 7476;
  21820. t[2924] = 7478;
  21821. t[2925] = 7479;
  21822. t[2926] = 7480;
  21823. t[2928] = 7482;
  21824. t[2929] = 7483;
  21825. t[2930] = 7484;
  21826. t[2932] = 7486;
  21827. t[2933] = 7487;
  21828. t[2934] = 7488;
  21829. t[2936] = 7490;
  21830. t[2937] = 7491;
  21831. t[2938] = 7492;
  21832. t[2940] = 7494;
  21833. t[2941] = 7495;
  21834. t[2942] = 7496;
  21835. t[2944] = 7498;
  21836. t[2946] = 7500;
  21837. t[2948] = 7502;
  21838. t[2950] = 7504;
  21839. t[2951] = 7505;
  21840. t[2952] = 7506;
  21841. t[2954] = 7508;
  21842. t[2955] = 7509;
  21843. t[2956] = 7510;
  21844. t[2958] = 7512;
  21845. t[2959] = 7513;
  21846. t[2960] = 7514;
  21847. t[2962] = 7516;
  21848. t[2963] = 7517;
  21849. t[2964] = 7518;
  21850. t[2966] = 7520;
  21851. t[2967] = 7521;
  21852. t[2968] = 7522;
  21853. t[2970] = 7524;
  21854. t[2971] = 7525;
  21855. t[2972] = 7526;
  21856. t[2974] = 7528;
  21857. t[2975] = 7529;
  21858. t[2976] = 7530;
  21859. t[2978] = 1537;
  21860. t[2979] = 1538;
  21861. t[2980] = 1539;
  21862. t[2982] = 1549;
  21863. t[2983] = 1551;
  21864. t[2984] = 1552;
  21865. t[2986] = 1554;
  21866. t[2987] = 1555;
  21867. t[2988] = 1556;
  21868. t[2990] = 1623;
  21869. t[2991] = 1624;
  21870. t[2995] = 1775;
  21871. t[2999] = 1791;
  21872. t[3002] = 64290;
  21873. t[3003] = 64291;
  21874. t[3004] = 64292;
  21875. t[3006] = 64294;
  21876. t[3007] = 64295;
  21877. t[3008] = 64296;
  21878. t[3011] = 1900;
  21879. t[3014] = 8223;
  21880. t[3015] = 8244;
  21881. t[3017] = 7532;
  21882. t[3018] = 7533;
  21883. t[3019] = 7534;
  21884. t[3075] = 7590;
  21885. t[3076] = 7591;
  21886. t[3079] = 7594;
  21887. t[3080] = 7595;
  21888. t[3083] = 7598;
  21889. t[3084] = 7599;
  21890. t[3087] = 7602;
  21891. t[3088] = 7603;
  21892. t[3091] = 7606;
  21893. t[3092] = 7607;
  21894. t[3095] = 7610;
  21895. t[3096] = 7611;
  21896. t[3099] = 7614;
  21897. t[3100] = 7615;
  21898. t[3103] = 7618;
  21899. t[3104] = 7619;
  21900. t[3107] = 8337;
  21901. t[3108] = 8338;
  21902. t[3116] = 1884;
  21903. t[3119] = 1885;
  21904. t[3120] = 1885;
  21905. t[3123] = 1886;
  21906. t[3124] = 1886;
  21907. t[3127] = 1887;
  21908. t[3128] = 1887;
  21909. t[3131] = 1888;
  21910. t[3132] = 1888;
  21911. t[3135] = 1889;
  21912. t[3136] = 1889;
  21913. t[3139] = 1890;
  21914. t[3140] = 1890;
  21915. t[3143] = 1891;
  21916. t[3144] = 1891;
  21917. t[3147] = 1892;
  21918. t[3148] = 1892;
  21919. t[3153] = 580;
  21920. t[3154] = 581;
  21921. t[3157] = 584;
  21922. t[3158] = 585;
  21923. t[3161] = 588;
  21924. t[3162] = 589;
  21925. t[3165] = 891;
  21926. t[3166] = 892;
  21927. t[3169] = 1274;
  21928. t[3170] = 1275;
  21929. t[3173] = 1278;
  21930. t[3174] = 1279;
  21931. t[3181] = 7622;
  21932. t[3182] = 7623;
  21933. t[3282] = 11799;
  21934. t[3316] = 578;
  21935. t[3379] = 42785;
  21936. t[3393] = 1159;
  21937. t[3416] = 8377;
  21938. });
  21939. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21940. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21941. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21942. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21943. t[227] = 322;
  21944. t[264] = 261;
  21945. t[291] = 346;
  21946. });
  21947. exports.getStdFontMap = getStdFontMap;
  21948. exports.getNonStdFontMap = getNonStdFontMap;
  21949. exports.getSerifFonts = getSerifFonts;
  21950. exports.getSymbolsFonts = getSymbolsFonts;
  21951. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21952. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21953. }));
  21954. (function (root, factory) {
  21955. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21956. }(this, function (exports, sharedUtil) {
  21957. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21958. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21959. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21960. // chars to the similar equivalents in the normal characters range.
  21961. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21962. t[63721] = 0x00A9;
  21963. // copyrightsans (0xF8E9) => copyright
  21964. t[63193] = 0x00A9;
  21965. // copyrightserif (0xF6D9) => copyright
  21966. t[63720] = 0x00AE;
  21967. // registersans (0xF8E8) => registered
  21968. t[63194] = 0x00AE;
  21969. // registerserif (0xF6DA) => registered
  21970. t[63722] = 0x2122;
  21971. // trademarksans (0xF8EA) => trademark
  21972. t[63195] = 0x2122;
  21973. // trademarkserif (0xF6DB) => trademark
  21974. t[63729] = 0x23A7;
  21975. // bracelefttp (0xF8F1)
  21976. t[63730] = 0x23A8;
  21977. // braceleftmid (0xF8F2)
  21978. t[63731] = 0x23A9;
  21979. // braceleftbt (0xF8F3)
  21980. t[63740] = 0x23AB;
  21981. // bracerighttp (0xF8FC)
  21982. t[63741] = 0x23AC;
  21983. // bracerightmid (0xF8FD)
  21984. t[63742] = 0x23AD;
  21985. // bracerightbt (0xF8FE)
  21986. t[63726] = 0x23A1;
  21987. // bracketlefttp (0xF8EE)
  21988. t[63727] = 0x23A2;
  21989. // bracketleftex (0xF8EF)
  21990. t[63728] = 0x23A3;
  21991. // bracketleftbt (0xF8F0)
  21992. t[63737] = 0x23A4;
  21993. // bracketrighttp (0xF8F9)
  21994. t[63738] = 0x23A5;
  21995. // bracketrightex (0xF8FA)
  21996. t[63739] = 0x23A6;
  21997. // bracketrightbt (0xF8FB)
  21998. t[63723] = 0x239B;
  21999. // parenlefttp (0xF8EB)
  22000. t[63724] = 0x239C;
  22001. // parenleftex (0xF8EC)
  22002. t[63725] = 0x239D;
  22003. // parenleftbt (0xF8ED)
  22004. t[63734] = 0x239E;
  22005. // parenrighttp (0xF8F6)
  22006. t[63735] = 0x239F;
  22007. // parenrightex (0xF8F7)
  22008. t[63736] = 0x23A0;
  22009. });
  22010. // parenrightbt (0xF8F8)
  22011. function mapSpecialUnicodeValues(code) {
  22012. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22013. // Specials unicode block.
  22014. return 0;
  22015. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22016. return getSpecialPUASymbols()[code] || code;
  22017. }
  22018. return code;
  22019. }
  22020. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22021. var unicode = glyphsUnicodeMap[name];
  22022. if (unicode !== undefined) {
  22023. return unicode;
  22024. }
  22025. if (!name) {
  22026. return -1;
  22027. }
  22028. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22029. if (name[0] === 'u') {
  22030. var nameLen = name.length, hexStr;
  22031. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22032. // 'uniXXXX'
  22033. hexStr = name.substr(3);
  22034. } else if (nameLen >= 5 && nameLen <= 7) {
  22035. // 'uXXXX{XX}'
  22036. hexStr = name.substr(1);
  22037. } else {
  22038. return -1;
  22039. }
  22040. // Check for upper-case hexadecimal characters, to avoid false positives.
  22041. if (hexStr === hexStr.toUpperCase()) {
  22042. unicode = parseInt(hexStr, 16);
  22043. if (unicode >= 0) {
  22044. return unicode;
  22045. }
  22046. }
  22047. }
  22048. return -1;
  22049. }
  22050. var UnicodeRanges = [
  22051. {
  22052. 'begin': 0x0000,
  22053. 'end': 0x007F
  22054. },
  22055. // Basic Latin
  22056. {
  22057. 'begin': 0x0080,
  22058. 'end': 0x00FF
  22059. },
  22060. // Latin-1 Supplement
  22061. {
  22062. 'begin': 0x0100,
  22063. 'end': 0x017F
  22064. },
  22065. // Latin Extended-A
  22066. {
  22067. 'begin': 0x0180,
  22068. 'end': 0x024F
  22069. },
  22070. // Latin Extended-B
  22071. {
  22072. 'begin': 0x0250,
  22073. 'end': 0x02AF
  22074. },
  22075. // IPA Extensions
  22076. {
  22077. 'begin': 0x02B0,
  22078. 'end': 0x02FF
  22079. },
  22080. // Spacing Modifier Letters
  22081. {
  22082. 'begin': 0x0300,
  22083. 'end': 0x036F
  22084. },
  22085. // Combining Diacritical Marks
  22086. {
  22087. 'begin': 0x0370,
  22088. 'end': 0x03FF
  22089. },
  22090. // Greek and Coptic
  22091. {
  22092. 'begin': 0x2C80,
  22093. 'end': 0x2CFF
  22094. },
  22095. // Coptic
  22096. {
  22097. 'begin': 0x0400,
  22098. 'end': 0x04FF
  22099. },
  22100. // Cyrillic
  22101. {
  22102. 'begin': 0x0530,
  22103. 'end': 0x058F
  22104. },
  22105. // Armenian
  22106. {
  22107. 'begin': 0x0590,
  22108. 'end': 0x05FF
  22109. },
  22110. // Hebrew
  22111. {
  22112. 'begin': 0xA500,
  22113. 'end': 0xA63F
  22114. },
  22115. // Vai
  22116. {
  22117. 'begin': 0x0600,
  22118. 'end': 0x06FF
  22119. },
  22120. // Arabic
  22121. {
  22122. 'begin': 0x07C0,
  22123. 'end': 0x07FF
  22124. },
  22125. // NKo
  22126. {
  22127. 'begin': 0x0900,
  22128. 'end': 0x097F
  22129. },
  22130. // Devanagari
  22131. {
  22132. 'begin': 0x0980,
  22133. 'end': 0x09FF
  22134. },
  22135. // Bengali
  22136. {
  22137. 'begin': 0x0A00,
  22138. 'end': 0x0A7F
  22139. },
  22140. // Gurmukhi
  22141. {
  22142. 'begin': 0x0A80,
  22143. 'end': 0x0AFF
  22144. },
  22145. // Gujarati
  22146. {
  22147. 'begin': 0x0B00,
  22148. 'end': 0x0B7F
  22149. },
  22150. // Oriya
  22151. {
  22152. 'begin': 0x0B80,
  22153. 'end': 0x0BFF
  22154. },
  22155. // Tamil
  22156. {
  22157. 'begin': 0x0C00,
  22158. 'end': 0x0C7F
  22159. },
  22160. // Telugu
  22161. {
  22162. 'begin': 0x0C80,
  22163. 'end': 0x0CFF
  22164. },
  22165. // Kannada
  22166. {
  22167. 'begin': 0x0D00,
  22168. 'end': 0x0D7F
  22169. },
  22170. // Malayalam
  22171. {
  22172. 'begin': 0x0E00,
  22173. 'end': 0x0E7F
  22174. },
  22175. // Thai
  22176. {
  22177. 'begin': 0x0E80,
  22178. 'end': 0x0EFF
  22179. },
  22180. // Lao
  22181. {
  22182. 'begin': 0x10A0,
  22183. 'end': 0x10FF
  22184. },
  22185. // Georgian
  22186. {
  22187. 'begin': 0x1B00,
  22188. 'end': 0x1B7F
  22189. },
  22190. // Balinese
  22191. {
  22192. 'begin': 0x1100,
  22193. 'end': 0x11FF
  22194. },
  22195. // Hangul Jamo
  22196. {
  22197. 'begin': 0x1E00,
  22198. 'end': 0x1EFF
  22199. },
  22200. // Latin Extended Additional
  22201. {
  22202. 'begin': 0x1F00,
  22203. 'end': 0x1FFF
  22204. },
  22205. // Greek Extended
  22206. {
  22207. 'begin': 0x2000,
  22208. 'end': 0x206F
  22209. },
  22210. // General Punctuation
  22211. {
  22212. 'begin': 0x2070,
  22213. 'end': 0x209F
  22214. },
  22215. // Superscripts And Subscripts
  22216. {
  22217. 'begin': 0x20A0,
  22218. 'end': 0x20CF
  22219. },
  22220. // Currency Symbol
  22221. {
  22222. 'begin': 0x20D0,
  22223. 'end': 0x20FF
  22224. },
  22225. // Combining Diacritical Marks
  22226. {
  22227. 'begin': 0x2100,
  22228. 'end': 0x214F
  22229. },
  22230. // Letterlike Symbols
  22231. {
  22232. 'begin': 0x2150,
  22233. 'end': 0x218F
  22234. },
  22235. // Number Forms
  22236. {
  22237. 'begin': 0x2190,
  22238. 'end': 0x21FF
  22239. },
  22240. // Arrows
  22241. {
  22242. 'begin': 0x2200,
  22243. 'end': 0x22FF
  22244. },
  22245. // Mathematical Operators
  22246. {
  22247. 'begin': 0x2300,
  22248. 'end': 0x23FF
  22249. },
  22250. // Miscellaneous Technical
  22251. {
  22252. 'begin': 0x2400,
  22253. 'end': 0x243F
  22254. },
  22255. // Control Pictures
  22256. {
  22257. 'begin': 0x2440,
  22258. 'end': 0x245F
  22259. },
  22260. // Optical Character Recognition
  22261. {
  22262. 'begin': 0x2460,
  22263. 'end': 0x24FF
  22264. },
  22265. // Enclosed Alphanumerics
  22266. {
  22267. 'begin': 0x2500,
  22268. 'end': 0x257F
  22269. },
  22270. // Box Drawing
  22271. {
  22272. 'begin': 0x2580,
  22273. 'end': 0x259F
  22274. },
  22275. // Block Elements
  22276. {
  22277. 'begin': 0x25A0,
  22278. 'end': 0x25FF
  22279. },
  22280. // Geometric Shapes
  22281. {
  22282. 'begin': 0x2600,
  22283. 'end': 0x26FF
  22284. },
  22285. // Miscellaneous Symbols
  22286. {
  22287. 'begin': 0x2700,
  22288. 'end': 0x27BF
  22289. },
  22290. // Dingbats
  22291. {
  22292. 'begin': 0x3000,
  22293. 'end': 0x303F
  22294. },
  22295. // CJK Symbols And Punctuation
  22296. {
  22297. 'begin': 0x3040,
  22298. 'end': 0x309F
  22299. },
  22300. // Hiragana
  22301. {
  22302. 'begin': 0x30A0,
  22303. 'end': 0x30FF
  22304. },
  22305. // Katakana
  22306. {
  22307. 'begin': 0x3100,
  22308. 'end': 0x312F
  22309. },
  22310. // Bopomofo
  22311. {
  22312. 'begin': 0x3130,
  22313. 'end': 0x318F
  22314. },
  22315. // Hangul Compatibility Jamo
  22316. {
  22317. 'begin': 0xA840,
  22318. 'end': 0xA87F
  22319. },
  22320. // Phags-pa
  22321. {
  22322. 'begin': 0x3200,
  22323. 'end': 0x32FF
  22324. },
  22325. // Enclosed CJK Letters And Months
  22326. {
  22327. 'begin': 0x3300,
  22328. 'end': 0x33FF
  22329. },
  22330. // CJK Compatibility
  22331. {
  22332. 'begin': 0xAC00,
  22333. 'end': 0xD7AF
  22334. },
  22335. // Hangul Syllables
  22336. {
  22337. 'begin': 0xD800,
  22338. 'end': 0xDFFF
  22339. },
  22340. // Non-Plane 0 *
  22341. {
  22342. 'begin': 0x10900,
  22343. 'end': 0x1091F
  22344. },
  22345. // Phoenicia
  22346. {
  22347. 'begin': 0x4E00,
  22348. 'end': 0x9FFF
  22349. },
  22350. // CJK Unified Ideographs
  22351. {
  22352. 'begin': 0xE000,
  22353. 'end': 0xF8FF
  22354. },
  22355. // Private Use Area (plane 0)
  22356. {
  22357. 'begin': 0x31C0,
  22358. 'end': 0x31EF
  22359. },
  22360. // CJK Strokes
  22361. {
  22362. 'begin': 0xFB00,
  22363. 'end': 0xFB4F
  22364. },
  22365. // Alphabetic Presentation Forms
  22366. {
  22367. 'begin': 0xFB50,
  22368. 'end': 0xFDFF
  22369. },
  22370. // Arabic Presentation Forms-A
  22371. {
  22372. 'begin': 0xFE20,
  22373. 'end': 0xFE2F
  22374. },
  22375. // Combining Half Marks
  22376. {
  22377. 'begin': 0xFE10,
  22378. 'end': 0xFE1F
  22379. },
  22380. // Vertical Forms
  22381. {
  22382. 'begin': 0xFE50,
  22383. 'end': 0xFE6F
  22384. },
  22385. // Small Form Variants
  22386. {
  22387. 'begin': 0xFE70,
  22388. 'end': 0xFEFF
  22389. },
  22390. // Arabic Presentation Forms-B
  22391. {
  22392. 'begin': 0xFF00,
  22393. 'end': 0xFFEF
  22394. },
  22395. // Halfwidth And Fullwidth Forms
  22396. {
  22397. 'begin': 0xFFF0,
  22398. 'end': 0xFFFF
  22399. },
  22400. // Specials
  22401. {
  22402. 'begin': 0x0F00,
  22403. 'end': 0x0FFF
  22404. },
  22405. // Tibetan
  22406. {
  22407. 'begin': 0x0700,
  22408. 'end': 0x074F
  22409. },
  22410. // Syriac
  22411. {
  22412. 'begin': 0x0780,
  22413. 'end': 0x07BF
  22414. },
  22415. // Thaana
  22416. {
  22417. 'begin': 0x0D80,
  22418. 'end': 0x0DFF
  22419. },
  22420. // Sinhala
  22421. {
  22422. 'begin': 0x1000,
  22423. 'end': 0x109F
  22424. },
  22425. // Myanmar
  22426. {
  22427. 'begin': 0x1200,
  22428. 'end': 0x137F
  22429. },
  22430. // Ethiopic
  22431. {
  22432. 'begin': 0x13A0,
  22433. 'end': 0x13FF
  22434. },
  22435. // Cherokee
  22436. {
  22437. 'begin': 0x1400,
  22438. 'end': 0x167F
  22439. },
  22440. // Unified Canadian Aboriginal Syllabics
  22441. {
  22442. 'begin': 0x1680,
  22443. 'end': 0x169F
  22444. },
  22445. // Ogham
  22446. {
  22447. 'begin': 0x16A0,
  22448. 'end': 0x16FF
  22449. },
  22450. // Runic
  22451. {
  22452. 'begin': 0x1780,
  22453. 'end': 0x17FF
  22454. },
  22455. // Khmer
  22456. {
  22457. 'begin': 0x1800,
  22458. 'end': 0x18AF
  22459. },
  22460. // Mongolian
  22461. {
  22462. 'begin': 0x2800,
  22463. 'end': 0x28FF
  22464. },
  22465. // Braille Patterns
  22466. {
  22467. 'begin': 0xA000,
  22468. 'end': 0xA48F
  22469. },
  22470. // Yi Syllables
  22471. {
  22472. 'begin': 0x1700,
  22473. 'end': 0x171F
  22474. },
  22475. // Tagalog
  22476. {
  22477. 'begin': 0x10300,
  22478. 'end': 0x1032F
  22479. },
  22480. // Old Italic
  22481. {
  22482. 'begin': 0x10330,
  22483. 'end': 0x1034F
  22484. },
  22485. // Gothic
  22486. {
  22487. 'begin': 0x10400,
  22488. 'end': 0x1044F
  22489. },
  22490. // Deseret
  22491. {
  22492. 'begin': 0x1D000,
  22493. 'end': 0x1D0FF
  22494. },
  22495. // Byzantine Musical Symbols
  22496. {
  22497. 'begin': 0x1D400,
  22498. 'end': 0x1D7FF
  22499. },
  22500. // Mathematical Alphanumeric Symbols
  22501. {
  22502. 'begin': 0xFF000,
  22503. 'end': 0xFFFFD
  22504. },
  22505. // Private Use (plane 15)
  22506. {
  22507. 'begin': 0xFE00,
  22508. 'end': 0xFE0F
  22509. },
  22510. // Variation Selectors
  22511. {
  22512. 'begin': 0xE0000,
  22513. 'end': 0xE007F
  22514. },
  22515. // Tags
  22516. {
  22517. 'begin': 0x1900,
  22518. 'end': 0x194F
  22519. },
  22520. // Limbu
  22521. {
  22522. 'begin': 0x1950,
  22523. 'end': 0x197F
  22524. },
  22525. // Tai Le
  22526. {
  22527. 'begin': 0x1980,
  22528. 'end': 0x19DF
  22529. },
  22530. // New Tai Lue
  22531. {
  22532. 'begin': 0x1A00,
  22533. 'end': 0x1A1F
  22534. },
  22535. // Buginese
  22536. {
  22537. 'begin': 0x2C00,
  22538. 'end': 0x2C5F
  22539. },
  22540. // Glagolitic
  22541. {
  22542. 'begin': 0x2D30,
  22543. 'end': 0x2D7F
  22544. },
  22545. // Tifinagh
  22546. {
  22547. 'begin': 0x4DC0,
  22548. 'end': 0x4DFF
  22549. },
  22550. // Yijing Hexagram Symbols
  22551. {
  22552. 'begin': 0xA800,
  22553. 'end': 0xA82F
  22554. },
  22555. // Syloti Nagri
  22556. {
  22557. 'begin': 0x10000,
  22558. 'end': 0x1007F
  22559. },
  22560. // Linear B Syllabary
  22561. {
  22562. 'begin': 0x10140,
  22563. 'end': 0x1018F
  22564. },
  22565. // Ancient Greek Numbers
  22566. {
  22567. 'begin': 0x10380,
  22568. 'end': 0x1039F
  22569. },
  22570. // Ugaritic
  22571. {
  22572. 'begin': 0x103A0,
  22573. 'end': 0x103DF
  22574. },
  22575. // Old Persian
  22576. {
  22577. 'begin': 0x10450,
  22578. 'end': 0x1047F
  22579. },
  22580. // Shavian
  22581. {
  22582. 'begin': 0x10480,
  22583. 'end': 0x104AF
  22584. },
  22585. // Osmanya
  22586. {
  22587. 'begin': 0x10800,
  22588. 'end': 0x1083F
  22589. },
  22590. // Cypriot Syllabary
  22591. {
  22592. 'begin': 0x10A00,
  22593. 'end': 0x10A5F
  22594. },
  22595. // Kharoshthi
  22596. {
  22597. 'begin': 0x1D300,
  22598. 'end': 0x1D35F
  22599. },
  22600. // Tai Xuan Jing Symbols
  22601. {
  22602. 'begin': 0x12000,
  22603. 'end': 0x123FF
  22604. },
  22605. // Cuneiform
  22606. {
  22607. 'begin': 0x1D360,
  22608. 'end': 0x1D37F
  22609. },
  22610. // Counting Rod Numerals
  22611. {
  22612. 'begin': 0x1B80,
  22613. 'end': 0x1BBF
  22614. },
  22615. // Sundanese
  22616. {
  22617. 'begin': 0x1C00,
  22618. 'end': 0x1C4F
  22619. },
  22620. // Lepcha
  22621. {
  22622. 'begin': 0x1C50,
  22623. 'end': 0x1C7F
  22624. },
  22625. // Ol Chiki
  22626. {
  22627. 'begin': 0xA880,
  22628. 'end': 0xA8DF
  22629. },
  22630. // Saurashtra
  22631. {
  22632. 'begin': 0xA900,
  22633. 'end': 0xA92F
  22634. },
  22635. // Kayah Li
  22636. {
  22637. 'begin': 0xA930,
  22638. 'end': 0xA95F
  22639. },
  22640. // Rejang
  22641. {
  22642. 'begin': 0xAA00,
  22643. 'end': 0xAA5F
  22644. },
  22645. // Cham
  22646. {
  22647. 'begin': 0x10190,
  22648. 'end': 0x101CF
  22649. },
  22650. // Ancient Symbols
  22651. {
  22652. 'begin': 0x101D0,
  22653. 'end': 0x101FF
  22654. },
  22655. // Phaistos Disc
  22656. {
  22657. 'begin': 0x102A0,
  22658. 'end': 0x102DF
  22659. },
  22660. // Carian
  22661. {
  22662. 'begin': 0x1F030,
  22663. 'end': 0x1F09F
  22664. }
  22665. ];
  22666. // Domino Tiles
  22667. function getUnicodeRangeFor(value) {
  22668. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22669. var range = UnicodeRanges[i];
  22670. if (value >= range.begin && value < range.end) {
  22671. return i;
  22672. }
  22673. }
  22674. return -1;
  22675. }
  22676. function isRTLRangeFor(value) {
  22677. var range = UnicodeRanges[13];
  22678. if (value >= range.begin && value < range.end) {
  22679. return true;
  22680. }
  22681. range = UnicodeRanges[11];
  22682. if (value >= range.begin && value < range.end) {
  22683. return true;
  22684. }
  22685. return false;
  22686. }
  22687. // The normalization table is obtained by filtering the Unicode characters
  22688. // database with <compat> entries.
  22689. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22690. t['\u00A8'] = '\u0020\u0308';
  22691. t['\u00AF'] = '\u0020\u0304';
  22692. t['\u00B4'] = '\u0020\u0301';
  22693. t['\u00B5'] = '\u03BC';
  22694. t['\u00B8'] = '\u0020\u0327';
  22695. t['\u0132'] = '\u0049\u004A';
  22696. t['\u0133'] = '\u0069\u006A';
  22697. t['\u013F'] = '\u004C\u00B7';
  22698. t['\u0140'] = '\u006C\u00B7';
  22699. t['\u0149'] = '\u02BC\u006E';
  22700. t['\u017F'] = '\u0073';
  22701. t['\u01C4'] = '\u0044\u017D';
  22702. t['\u01C5'] = '\u0044\u017E';
  22703. t['\u01C6'] = '\u0064\u017E';
  22704. t['\u01C7'] = '\u004C\u004A';
  22705. t['\u01C8'] = '\u004C\u006A';
  22706. t['\u01C9'] = '\u006C\u006A';
  22707. t['\u01CA'] = '\u004E\u004A';
  22708. t['\u01CB'] = '\u004E\u006A';
  22709. t['\u01CC'] = '\u006E\u006A';
  22710. t['\u01F1'] = '\u0044\u005A';
  22711. t['\u01F2'] = '\u0044\u007A';
  22712. t['\u01F3'] = '\u0064\u007A';
  22713. t['\u02D8'] = '\u0020\u0306';
  22714. t['\u02D9'] = '\u0020\u0307';
  22715. t['\u02DA'] = '\u0020\u030A';
  22716. t['\u02DB'] = '\u0020\u0328';
  22717. t['\u02DC'] = '\u0020\u0303';
  22718. t['\u02DD'] = '\u0020\u030B';
  22719. t['\u037A'] = '\u0020\u0345';
  22720. t['\u0384'] = '\u0020\u0301';
  22721. t['\u03D0'] = '\u03B2';
  22722. t['\u03D1'] = '\u03B8';
  22723. t['\u03D2'] = '\u03A5';
  22724. t['\u03D5'] = '\u03C6';
  22725. t['\u03D6'] = '\u03C0';
  22726. t['\u03F0'] = '\u03BA';
  22727. t['\u03F1'] = '\u03C1';
  22728. t['\u03F2'] = '\u03C2';
  22729. t['\u03F4'] = '\u0398';
  22730. t['\u03F5'] = '\u03B5';
  22731. t['\u03F9'] = '\u03A3';
  22732. t['\u0587'] = '\u0565\u0582';
  22733. t['\u0675'] = '\u0627\u0674';
  22734. t['\u0676'] = '\u0648\u0674';
  22735. t['\u0677'] = '\u06C7\u0674';
  22736. t['\u0678'] = '\u064A\u0674';
  22737. t['\u0E33'] = '\u0E4D\u0E32';
  22738. t['\u0EB3'] = '\u0ECD\u0EB2';
  22739. t['\u0EDC'] = '\u0EAB\u0E99';
  22740. t['\u0EDD'] = '\u0EAB\u0EA1';
  22741. t['\u0F77'] = '\u0FB2\u0F81';
  22742. t['\u0F79'] = '\u0FB3\u0F81';
  22743. t['\u1E9A'] = '\u0061\u02BE';
  22744. t['\u1FBD'] = '\u0020\u0313';
  22745. t['\u1FBF'] = '\u0020\u0313';
  22746. t['\u1FC0'] = '\u0020\u0342';
  22747. t['\u1FFE'] = '\u0020\u0314';
  22748. t['\u2002'] = '\u0020';
  22749. t['\u2003'] = '\u0020';
  22750. t['\u2004'] = '\u0020';
  22751. t['\u2005'] = '\u0020';
  22752. t['\u2006'] = '\u0020';
  22753. t['\u2008'] = '\u0020';
  22754. t['\u2009'] = '\u0020';
  22755. t['\u200A'] = '\u0020';
  22756. t['\u2017'] = '\u0020\u0333';
  22757. t['\u2024'] = '\u002E';
  22758. t['\u2025'] = '\u002E\u002E';
  22759. t['\u2026'] = '\u002E\u002E\u002E';
  22760. t['\u2033'] = '\u2032\u2032';
  22761. t['\u2034'] = '\u2032\u2032\u2032';
  22762. t['\u2036'] = '\u2035\u2035';
  22763. t['\u2037'] = '\u2035\u2035\u2035';
  22764. t['\u203C'] = '\u0021\u0021';
  22765. t['\u203E'] = '\u0020\u0305';
  22766. t['\u2047'] = '\u003F\u003F';
  22767. t['\u2048'] = '\u003F\u0021';
  22768. t['\u2049'] = '\u0021\u003F';
  22769. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22770. t['\u205F'] = '\u0020';
  22771. t['\u20A8'] = '\u0052\u0073';
  22772. t['\u2100'] = '\u0061\u002F\u0063';
  22773. t['\u2101'] = '\u0061\u002F\u0073';
  22774. t['\u2103'] = '\u00B0\u0043';
  22775. t['\u2105'] = '\u0063\u002F\u006F';
  22776. t['\u2106'] = '\u0063\u002F\u0075';
  22777. t['\u2107'] = '\u0190';
  22778. t['\u2109'] = '\u00B0\u0046';
  22779. t['\u2116'] = '\u004E\u006F';
  22780. t['\u2121'] = '\u0054\u0045\u004C';
  22781. t['\u2135'] = '\u05D0';
  22782. t['\u2136'] = '\u05D1';
  22783. t['\u2137'] = '\u05D2';
  22784. t['\u2138'] = '\u05D3';
  22785. t['\u213B'] = '\u0046\u0041\u0058';
  22786. t['\u2160'] = '\u0049';
  22787. t['\u2161'] = '\u0049\u0049';
  22788. t['\u2162'] = '\u0049\u0049\u0049';
  22789. t['\u2163'] = '\u0049\u0056';
  22790. t['\u2164'] = '\u0056';
  22791. t['\u2165'] = '\u0056\u0049';
  22792. t['\u2166'] = '\u0056\u0049\u0049';
  22793. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22794. t['\u2168'] = '\u0049\u0058';
  22795. t['\u2169'] = '\u0058';
  22796. t['\u216A'] = '\u0058\u0049';
  22797. t['\u216B'] = '\u0058\u0049\u0049';
  22798. t['\u216C'] = '\u004C';
  22799. t['\u216D'] = '\u0043';
  22800. t['\u216E'] = '\u0044';
  22801. t['\u216F'] = '\u004D';
  22802. t['\u2170'] = '\u0069';
  22803. t['\u2171'] = '\u0069\u0069';
  22804. t['\u2172'] = '\u0069\u0069\u0069';
  22805. t['\u2173'] = '\u0069\u0076';
  22806. t['\u2174'] = '\u0076';
  22807. t['\u2175'] = '\u0076\u0069';
  22808. t['\u2176'] = '\u0076\u0069\u0069';
  22809. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22810. t['\u2178'] = '\u0069\u0078';
  22811. t['\u2179'] = '\u0078';
  22812. t['\u217A'] = '\u0078\u0069';
  22813. t['\u217B'] = '\u0078\u0069\u0069';
  22814. t['\u217C'] = '\u006C';
  22815. t['\u217D'] = '\u0063';
  22816. t['\u217E'] = '\u0064';
  22817. t['\u217F'] = '\u006D';
  22818. t['\u222C'] = '\u222B\u222B';
  22819. t['\u222D'] = '\u222B\u222B\u222B';
  22820. t['\u222F'] = '\u222E\u222E';
  22821. t['\u2230'] = '\u222E\u222E\u222E';
  22822. t['\u2474'] = '\u0028\u0031\u0029';
  22823. t['\u2475'] = '\u0028\u0032\u0029';
  22824. t['\u2476'] = '\u0028\u0033\u0029';
  22825. t['\u2477'] = '\u0028\u0034\u0029';
  22826. t['\u2478'] = '\u0028\u0035\u0029';
  22827. t['\u2479'] = '\u0028\u0036\u0029';
  22828. t['\u247A'] = '\u0028\u0037\u0029';
  22829. t['\u247B'] = '\u0028\u0038\u0029';
  22830. t['\u247C'] = '\u0028\u0039\u0029';
  22831. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22832. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22833. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22834. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22835. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22836. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22837. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22838. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22839. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22840. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22841. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22842. t['\u2488'] = '\u0031\u002E';
  22843. t['\u2489'] = '\u0032\u002E';
  22844. t['\u248A'] = '\u0033\u002E';
  22845. t['\u248B'] = '\u0034\u002E';
  22846. t['\u248C'] = '\u0035\u002E';
  22847. t['\u248D'] = '\u0036\u002E';
  22848. t['\u248E'] = '\u0037\u002E';
  22849. t['\u248F'] = '\u0038\u002E';
  22850. t['\u2490'] = '\u0039\u002E';
  22851. t['\u2491'] = '\u0031\u0030\u002E';
  22852. t['\u2492'] = '\u0031\u0031\u002E';
  22853. t['\u2493'] = '\u0031\u0032\u002E';
  22854. t['\u2494'] = '\u0031\u0033\u002E';
  22855. t['\u2495'] = '\u0031\u0034\u002E';
  22856. t['\u2496'] = '\u0031\u0035\u002E';
  22857. t['\u2497'] = '\u0031\u0036\u002E';
  22858. t['\u2498'] = '\u0031\u0037\u002E';
  22859. t['\u2499'] = '\u0031\u0038\u002E';
  22860. t['\u249A'] = '\u0031\u0039\u002E';
  22861. t['\u249B'] = '\u0032\u0030\u002E';
  22862. t['\u249C'] = '\u0028\u0061\u0029';
  22863. t['\u249D'] = '\u0028\u0062\u0029';
  22864. t['\u249E'] = '\u0028\u0063\u0029';
  22865. t['\u249F'] = '\u0028\u0064\u0029';
  22866. t['\u24A0'] = '\u0028\u0065\u0029';
  22867. t['\u24A1'] = '\u0028\u0066\u0029';
  22868. t['\u24A2'] = '\u0028\u0067\u0029';
  22869. t['\u24A3'] = '\u0028\u0068\u0029';
  22870. t['\u24A4'] = '\u0028\u0069\u0029';
  22871. t['\u24A5'] = '\u0028\u006A\u0029';
  22872. t['\u24A6'] = '\u0028\u006B\u0029';
  22873. t['\u24A7'] = '\u0028\u006C\u0029';
  22874. t['\u24A8'] = '\u0028\u006D\u0029';
  22875. t['\u24A9'] = '\u0028\u006E\u0029';
  22876. t['\u24AA'] = '\u0028\u006F\u0029';
  22877. t['\u24AB'] = '\u0028\u0070\u0029';
  22878. t['\u24AC'] = '\u0028\u0071\u0029';
  22879. t['\u24AD'] = '\u0028\u0072\u0029';
  22880. t['\u24AE'] = '\u0028\u0073\u0029';
  22881. t['\u24AF'] = '\u0028\u0074\u0029';
  22882. t['\u24B0'] = '\u0028\u0075\u0029';
  22883. t['\u24B1'] = '\u0028\u0076\u0029';
  22884. t['\u24B2'] = '\u0028\u0077\u0029';
  22885. t['\u24B3'] = '\u0028\u0078\u0029';
  22886. t['\u24B4'] = '\u0028\u0079\u0029';
  22887. t['\u24B5'] = '\u0028\u007A\u0029';
  22888. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22889. t['\u2A74'] = '\u003A\u003A\u003D';
  22890. t['\u2A75'] = '\u003D\u003D';
  22891. t['\u2A76'] = '\u003D\u003D\u003D';
  22892. t['\u2E9F'] = '\u6BCD';
  22893. t['\u2EF3'] = '\u9F9F';
  22894. t['\u2F00'] = '\u4E00';
  22895. t['\u2F01'] = '\u4E28';
  22896. t['\u2F02'] = '\u4E36';
  22897. t['\u2F03'] = '\u4E3F';
  22898. t['\u2F04'] = '\u4E59';
  22899. t['\u2F05'] = '\u4E85';
  22900. t['\u2F06'] = '\u4E8C';
  22901. t['\u2F07'] = '\u4EA0';
  22902. t['\u2F08'] = '\u4EBA';
  22903. t['\u2F09'] = '\u513F';
  22904. t['\u2F0A'] = '\u5165';
  22905. t['\u2F0B'] = '\u516B';
  22906. t['\u2F0C'] = '\u5182';
  22907. t['\u2F0D'] = '\u5196';
  22908. t['\u2F0E'] = '\u51AB';
  22909. t['\u2F0F'] = '\u51E0';
  22910. t['\u2F10'] = '\u51F5';
  22911. t['\u2F11'] = '\u5200';
  22912. t['\u2F12'] = '\u529B';
  22913. t['\u2F13'] = '\u52F9';
  22914. t['\u2F14'] = '\u5315';
  22915. t['\u2F15'] = '\u531A';
  22916. t['\u2F16'] = '\u5338';
  22917. t['\u2F17'] = '\u5341';
  22918. t['\u2F18'] = '\u535C';
  22919. t['\u2F19'] = '\u5369';
  22920. t['\u2F1A'] = '\u5382';
  22921. t['\u2F1B'] = '\u53B6';
  22922. t['\u2F1C'] = '\u53C8';
  22923. t['\u2F1D'] = '\u53E3';
  22924. t['\u2F1E'] = '\u56D7';
  22925. t['\u2F1F'] = '\u571F';
  22926. t['\u2F20'] = '\u58EB';
  22927. t['\u2F21'] = '\u5902';
  22928. t['\u2F22'] = '\u590A';
  22929. t['\u2F23'] = '\u5915';
  22930. t['\u2F24'] = '\u5927';
  22931. t['\u2F25'] = '\u5973';
  22932. t['\u2F26'] = '\u5B50';
  22933. t['\u2F27'] = '\u5B80';
  22934. t['\u2F28'] = '\u5BF8';
  22935. t['\u2F29'] = '\u5C0F';
  22936. t['\u2F2A'] = '\u5C22';
  22937. t['\u2F2B'] = '\u5C38';
  22938. t['\u2F2C'] = '\u5C6E';
  22939. t['\u2F2D'] = '\u5C71';
  22940. t['\u2F2E'] = '\u5DDB';
  22941. t['\u2F2F'] = '\u5DE5';
  22942. t['\u2F30'] = '\u5DF1';
  22943. t['\u2F31'] = '\u5DFE';
  22944. t['\u2F32'] = '\u5E72';
  22945. t['\u2F33'] = '\u5E7A';
  22946. t['\u2F34'] = '\u5E7F';
  22947. t['\u2F35'] = '\u5EF4';
  22948. t['\u2F36'] = '\u5EFE';
  22949. t['\u2F37'] = '\u5F0B';
  22950. t['\u2F38'] = '\u5F13';
  22951. t['\u2F39'] = '\u5F50';
  22952. t['\u2F3A'] = '\u5F61';
  22953. t['\u2F3B'] = '\u5F73';
  22954. t['\u2F3C'] = '\u5FC3';
  22955. t['\u2F3D'] = '\u6208';
  22956. t['\u2F3E'] = '\u6236';
  22957. t['\u2F3F'] = '\u624B';
  22958. t['\u2F40'] = '\u652F';
  22959. t['\u2F41'] = '\u6534';
  22960. t['\u2F42'] = '\u6587';
  22961. t['\u2F43'] = '\u6597';
  22962. t['\u2F44'] = '\u65A4';
  22963. t['\u2F45'] = '\u65B9';
  22964. t['\u2F46'] = '\u65E0';
  22965. t['\u2F47'] = '\u65E5';
  22966. t['\u2F48'] = '\u66F0';
  22967. t['\u2F49'] = '\u6708';
  22968. t['\u2F4A'] = '\u6728';
  22969. t['\u2F4B'] = '\u6B20';
  22970. t['\u2F4C'] = '\u6B62';
  22971. t['\u2F4D'] = '\u6B79';
  22972. t['\u2F4E'] = '\u6BB3';
  22973. t['\u2F4F'] = '\u6BCB';
  22974. t['\u2F50'] = '\u6BD4';
  22975. t['\u2F51'] = '\u6BDB';
  22976. t['\u2F52'] = '\u6C0F';
  22977. t['\u2F53'] = '\u6C14';
  22978. t['\u2F54'] = '\u6C34';
  22979. t['\u2F55'] = '\u706B';
  22980. t['\u2F56'] = '\u722A';
  22981. t['\u2F57'] = '\u7236';
  22982. t['\u2F58'] = '\u723B';
  22983. t['\u2F59'] = '\u723F';
  22984. t['\u2F5A'] = '\u7247';
  22985. t['\u2F5B'] = '\u7259';
  22986. t['\u2F5C'] = '\u725B';
  22987. t['\u2F5D'] = '\u72AC';
  22988. t['\u2F5E'] = '\u7384';
  22989. t['\u2F5F'] = '\u7389';
  22990. t['\u2F60'] = '\u74DC';
  22991. t['\u2F61'] = '\u74E6';
  22992. t['\u2F62'] = '\u7518';
  22993. t['\u2F63'] = '\u751F';
  22994. t['\u2F64'] = '\u7528';
  22995. t['\u2F65'] = '\u7530';
  22996. t['\u2F66'] = '\u758B';
  22997. t['\u2F67'] = '\u7592';
  22998. t['\u2F68'] = '\u7676';
  22999. t['\u2F69'] = '\u767D';
  23000. t['\u2F6A'] = '\u76AE';
  23001. t['\u2F6B'] = '\u76BF';
  23002. t['\u2F6C'] = '\u76EE';
  23003. t['\u2F6D'] = '\u77DB';
  23004. t['\u2F6E'] = '\u77E2';
  23005. t['\u2F6F'] = '\u77F3';
  23006. t['\u2F70'] = '\u793A';
  23007. t['\u2F71'] = '\u79B8';
  23008. t['\u2F72'] = '\u79BE';
  23009. t['\u2F73'] = '\u7A74';
  23010. t['\u2F74'] = '\u7ACB';
  23011. t['\u2F75'] = '\u7AF9';
  23012. t['\u2F76'] = '\u7C73';
  23013. t['\u2F77'] = '\u7CF8';
  23014. t['\u2F78'] = '\u7F36';
  23015. t['\u2F79'] = '\u7F51';
  23016. t['\u2F7A'] = '\u7F8A';
  23017. t['\u2F7B'] = '\u7FBD';
  23018. t['\u2F7C'] = '\u8001';
  23019. t['\u2F7D'] = '\u800C';
  23020. t['\u2F7E'] = '\u8012';
  23021. t['\u2F7F'] = '\u8033';
  23022. t['\u2F80'] = '\u807F';
  23023. t['\u2F81'] = '\u8089';
  23024. t['\u2F82'] = '\u81E3';
  23025. t['\u2F83'] = '\u81EA';
  23026. t['\u2F84'] = '\u81F3';
  23027. t['\u2F85'] = '\u81FC';
  23028. t['\u2F86'] = '\u820C';
  23029. t['\u2F87'] = '\u821B';
  23030. t['\u2F88'] = '\u821F';
  23031. t['\u2F89'] = '\u826E';
  23032. t['\u2F8A'] = '\u8272';
  23033. t['\u2F8B'] = '\u8278';
  23034. t['\u2F8C'] = '\u864D';
  23035. t['\u2F8D'] = '\u866B';
  23036. t['\u2F8E'] = '\u8840';
  23037. t['\u2F8F'] = '\u884C';
  23038. t['\u2F90'] = '\u8863';
  23039. t['\u2F91'] = '\u897E';
  23040. t['\u2F92'] = '\u898B';
  23041. t['\u2F93'] = '\u89D2';
  23042. t['\u2F94'] = '\u8A00';
  23043. t['\u2F95'] = '\u8C37';
  23044. t['\u2F96'] = '\u8C46';
  23045. t['\u2F97'] = '\u8C55';
  23046. t['\u2F98'] = '\u8C78';
  23047. t['\u2F99'] = '\u8C9D';
  23048. t['\u2F9A'] = '\u8D64';
  23049. t['\u2F9B'] = '\u8D70';
  23050. t['\u2F9C'] = '\u8DB3';
  23051. t['\u2F9D'] = '\u8EAB';
  23052. t['\u2F9E'] = '\u8ECA';
  23053. t['\u2F9F'] = '\u8F9B';
  23054. t['\u2FA0'] = '\u8FB0';
  23055. t['\u2FA1'] = '\u8FB5';
  23056. t['\u2FA2'] = '\u9091';
  23057. t['\u2FA3'] = '\u9149';
  23058. t['\u2FA4'] = '\u91C6';
  23059. t['\u2FA5'] = '\u91CC';
  23060. t['\u2FA6'] = '\u91D1';
  23061. t['\u2FA7'] = '\u9577';
  23062. t['\u2FA8'] = '\u9580';
  23063. t['\u2FA9'] = '\u961C';
  23064. t['\u2FAA'] = '\u96B6';
  23065. t['\u2FAB'] = '\u96B9';
  23066. t['\u2FAC'] = '\u96E8';
  23067. t['\u2FAD'] = '\u9751';
  23068. t['\u2FAE'] = '\u975E';
  23069. t['\u2FAF'] = '\u9762';
  23070. t['\u2FB0'] = '\u9769';
  23071. t['\u2FB1'] = '\u97CB';
  23072. t['\u2FB2'] = '\u97ED';
  23073. t['\u2FB3'] = '\u97F3';
  23074. t['\u2FB4'] = '\u9801';
  23075. t['\u2FB5'] = '\u98A8';
  23076. t['\u2FB6'] = '\u98DB';
  23077. t['\u2FB7'] = '\u98DF';
  23078. t['\u2FB8'] = '\u9996';
  23079. t['\u2FB9'] = '\u9999';
  23080. t['\u2FBA'] = '\u99AC';
  23081. t['\u2FBB'] = '\u9AA8';
  23082. t['\u2FBC'] = '\u9AD8';
  23083. t['\u2FBD'] = '\u9ADF';
  23084. t['\u2FBE'] = '\u9B25';
  23085. t['\u2FBF'] = '\u9B2F';
  23086. t['\u2FC0'] = '\u9B32';
  23087. t['\u2FC1'] = '\u9B3C';
  23088. t['\u2FC2'] = '\u9B5A';
  23089. t['\u2FC3'] = '\u9CE5';
  23090. t['\u2FC4'] = '\u9E75';
  23091. t['\u2FC5'] = '\u9E7F';
  23092. t['\u2FC6'] = '\u9EA5';
  23093. t['\u2FC7'] = '\u9EBB';
  23094. t['\u2FC8'] = '\u9EC3';
  23095. t['\u2FC9'] = '\u9ECD';
  23096. t['\u2FCA'] = '\u9ED1';
  23097. t['\u2FCB'] = '\u9EF9';
  23098. t['\u2FCC'] = '\u9EFD';
  23099. t['\u2FCD'] = '\u9F0E';
  23100. t['\u2FCE'] = '\u9F13';
  23101. t['\u2FCF'] = '\u9F20';
  23102. t['\u2FD0'] = '\u9F3B';
  23103. t['\u2FD1'] = '\u9F4A';
  23104. t['\u2FD2'] = '\u9F52';
  23105. t['\u2FD3'] = '\u9F8D';
  23106. t['\u2FD4'] = '\u9F9C';
  23107. t['\u2FD5'] = '\u9FA0';
  23108. t['\u3036'] = '\u3012';
  23109. t['\u3038'] = '\u5341';
  23110. t['\u3039'] = '\u5344';
  23111. t['\u303A'] = '\u5345';
  23112. t['\u309B'] = '\u0020\u3099';
  23113. t['\u309C'] = '\u0020\u309A';
  23114. t['\u3131'] = '\u1100';
  23115. t['\u3132'] = '\u1101';
  23116. t['\u3133'] = '\u11AA';
  23117. t['\u3134'] = '\u1102';
  23118. t['\u3135'] = '\u11AC';
  23119. t['\u3136'] = '\u11AD';
  23120. t['\u3137'] = '\u1103';
  23121. t['\u3138'] = '\u1104';
  23122. t['\u3139'] = '\u1105';
  23123. t['\u313A'] = '\u11B0';
  23124. t['\u313B'] = '\u11B1';
  23125. t['\u313C'] = '\u11B2';
  23126. t['\u313D'] = '\u11B3';
  23127. t['\u313E'] = '\u11B4';
  23128. t['\u313F'] = '\u11B5';
  23129. t['\u3140'] = '\u111A';
  23130. t['\u3141'] = '\u1106';
  23131. t['\u3142'] = '\u1107';
  23132. t['\u3143'] = '\u1108';
  23133. t['\u3144'] = '\u1121';
  23134. t['\u3145'] = '\u1109';
  23135. t['\u3146'] = '\u110A';
  23136. t['\u3147'] = '\u110B';
  23137. t['\u3148'] = '\u110C';
  23138. t['\u3149'] = '\u110D';
  23139. t['\u314A'] = '\u110E';
  23140. t['\u314B'] = '\u110F';
  23141. t['\u314C'] = '\u1110';
  23142. t['\u314D'] = '\u1111';
  23143. t['\u314E'] = '\u1112';
  23144. t['\u314F'] = '\u1161';
  23145. t['\u3150'] = '\u1162';
  23146. t['\u3151'] = '\u1163';
  23147. t['\u3152'] = '\u1164';
  23148. t['\u3153'] = '\u1165';
  23149. t['\u3154'] = '\u1166';
  23150. t['\u3155'] = '\u1167';
  23151. t['\u3156'] = '\u1168';
  23152. t['\u3157'] = '\u1169';
  23153. t['\u3158'] = '\u116A';
  23154. t['\u3159'] = '\u116B';
  23155. t['\u315A'] = '\u116C';
  23156. t['\u315B'] = '\u116D';
  23157. t['\u315C'] = '\u116E';
  23158. t['\u315D'] = '\u116F';
  23159. t['\u315E'] = '\u1170';
  23160. t['\u315F'] = '\u1171';
  23161. t['\u3160'] = '\u1172';
  23162. t['\u3161'] = '\u1173';
  23163. t['\u3162'] = '\u1174';
  23164. t['\u3163'] = '\u1175';
  23165. t['\u3164'] = '\u1160';
  23166. t['\u3165'] = '\u1114';
  23167. t['\u3166'] = '\u1115';
  23168. t['\u3167'] = '\u11C7';
  23169. t['\u3168'] = '\u11C8';
  23170. t['\u3169'] = '\u11CC';
  23171. t['\u316A'] = '\u11CE';
  23172. t['\u316B'] = '\u11D3';
  23173. t['\u316C'] = '\u11D7';
  23174. t['\u316D'] = '\u11D9';
  23175. t['\u316E'] = '\u111C';
  23176. t['\u316F'] = '\u11DD';
  23177. t['\u3170'] = '\u11DF';
  23178. t['\u3171'] = '\u111D';
  23179. t['\u3172'] = '\u111E';
  23180. t['\u3173'] = '\u1120';
  23181. t['\u3174'] = '\u1122';
  23182. t['\u3175'] = '\u1123';
  23183. t['\u3176'] = '\u1127';
  23184. t['\u3177'] = '\u1129';
  23185. t['\u3178'] = '\u112B';
  23186. t['\u3179'] = '\u112C';
  23187. t['\u317A'] = '\u112D';
  23188. t['\u317B'] = '\u112E';
  23189. t['\u317C'] = '\u112F';
  23190. t['\u317D'] = '\u1132';
  23191. t['\u317E'] = '\u1136';
  23192. t['\u317F'] = '\u1140';
  23193. t['\u3180'] = '\u1147';
  23194. t['\u3181'] = '\u114C';
  23195. t['\u3182'] = '\u11F1';
  23196. t['\u3183'] = '\u11F2';
  23197. t['\u3184'] = '\u1157';
  23198. t['\u3185'] = '\u1158';
  23199. t['\u3186'] = '\u1159';
  23200. t['\u3187'] = '\u1184';
  23201. t['\u3188'] = '\u1185';
  23202. t['\u3189'] = '\u1188';
  23203. t['\u318A'] = '\u1191';
  23204. t['\u318B'] = '\u1192';
  23205. t['\u318C'] = '\u1194';
  23206. t['\u318D'] = '\u119E';
  23207. t['\u318E'] = '\u11A1';
  23208. t['\u3200'] = '\u0028\u1100\u0029';
  23209. t['\u3201'] = '\u0028\u1102\u0029';
  23210. t['\u3202'] = '\u0028\u1103\u0029';
  23211. t['\u3203'] = '\u0028\u1105\u0029';
  23212. t['\u3204'] = '\u0028\u1106\u0029';
  23213. t['\u3205'] = '\u0028\u1107\u0029';
  23214. t['\u3206'] = '\u0028\u1109\u0029';
  23215. t['\u3207'] = '\u0028\u110B\u0029';
  23216. t['\u3208'] = '\u0028\u110C\u0029';
  23217. t['\u3209'] = '\u0028\u110E\u0029';
  23218. t['\u320A'] = '\u0028\u110F\u0029';
  23219. t['\u320B'] = '\u0028\u1110\u0029';
  23220. t['\u320C'] = '\u0028\u1111\u0029';
  23221. t['\u320D'] = '\u0028\u1112\u0029';
  23222. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23223. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23224. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23225. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23226. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23227. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23228. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23229. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23230. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23231. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23232. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23233. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23234. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23235. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23236. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23237. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23238. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23239. t['\u3220'] = '\u0028\u4E00\u0029';
  23240. t['\u3221'] = '\u0028\u4E8C\u0029';
  23241. t['\u3222'] = '\u0028\u4E09\u0029';
  23242. t['\u3223'] = '\u0028\u56DB\u0029';
  23243. t['\u3224'] = '\u0028\u4E94\u0029';
  23244. t['\u3225'] = '\u0028\u516D\u0029';
  23245. t['\u3226'] = '\u0028\u4E03\u0029';
  23246. t['\u3227'] = '\u0028\u516B\u0029';
  23247. t['\u3228'] = '\u0028\u4E5D\u0029';
  23248. t['\u3229'] = '\u0028\u5341\u0029';
  23249. t['\u322A'] = '\u0028\u6708\u0029';
  23250. t['\u322B'] = '\u0028\u706B\u0029';
  23251. t['\u322C'] = '\u0028\u6C34\u0029';
  23252. t['\u322D'] = '\u0028\u6728\u0029';
  23253. t['\u322E'] = '\u0028\u91D1\u0029';
  23254. t['\u322F'] = '\u0028\u571F\u0029';
  23255. t['\u3230'] = '\u0028\u65E5\u0029';
  23256. t['\u3231'] = '\u0028\u682A\u0029';
  23257. t['\u3232'] = '\u0028\u6709\u0029';
  23258. t['\u3233'] = '\u0028\u793E\u0029';
  23259. t['\u3234'] = '\u0028\u540D\u0029';
  23260. t['\u3235'] = '\u0028\u7279\u0029';
  23261. t['\u3236'] = '\u0028\u8CA1\u0029';
  23262. t['\u3237'] = '\u0028\u795D\u0029';
  23263. t['\u3238'] = '\u0028\u52B4\u0029';
  23264. t['\u3239'] = '\u0028\u4EE3\u0029';
  23265. t['\u323A'] = '\u0028\u547C\u0029';
  23266. t['\u323B'] = '\u0028\u5B66\u0029';
  23267. t['\u323C'] = '\u0028\u76E3\u0029';
  23268. t['\u323D'] = '\u0028\u4F01\u0029';
  23269. t['\u323E'] = '\u0028\u8CC7\u0029';
  23270. t['\u323F'] = '\u0028\u5354\u0029';
  23271. t['\u3240'] = '\u0028\u796D\u0029';
  23272. t['\u3241'] = '\u0028\u4F11\u0029';
  23273. t['\u3242'] = '\u0028\u81EA\u0029';
  23274. t['\u3243'] = '\u0028\u81F3\u0029';
  23275. t['\u32C0'] = '\u0031\u6708';
  23276. t['\u32C1'] = '\u0032\u6708';
  23277. t['\u32C2'] = '\u0033\u6708';
  23278. t['\u32C3'] = '\u0034\u6708';
  23279. t['\u32C4'] = '\u0035\u6708';
  23280. t['\u32C5'] = '\u0036\u6708';
  23281. t['\u32C6'] = '\u0037\u6708';
  23282. t['\u32C7'] = '\u0038\u6708';
  23283. t['\u32C8'] = '\u0039\u6708';
  23284. t['\u32C9'] = '\u0031\u0030\u6708';
  23285. t['\u32CA'] = '\u0031\u0031\u6708';
  23286. t['\u32CB'] = '\u0031\u0032\u6708';
  23287. t['\u3358'] = '\u0030\u70B9';
  23288. t['\u3359'] = '\u0031\u70B9';
  23289. t['\u335A'] = '\u0032\u70B9';
  23290. t['\u335B'] = '\u0033\u70B9';
  23291. t['\u335C'] = '\u0034\u70B9';
  23292. t['\u335D'] = '\u0035\u70B9';
  23293. t['\u335E'] = '\u0036\u70B9';
  23294. t['\u335F'] = '\u0037\u70B9';
  23295. t['\u3360'] = '\u0038\u70B9';
  23296. t['\u3361'] = '\u0039\u70B9';
  23297. t['\u3362'] = '\u0031\u0030\u70B9';
  23298. t['\u3363'] = '\u0031\u0031\u70B9';
  23299. t['\u3364'] = '\u0031\u0032\u70B9';
  23300. t['\u3365'] = '\u0031\u0033\u70B9';
  23301. t['\u3366'] = '\u0031\u0034\u70B9';
  23302. t['\u3367'] = '\u0031\u0035\u70B9';
  23303. t['\u3368'] = '\u0031\u0036\u70B9';
  23304. t['\u3369'] = '\u0031\u0037\u70B9';
  23305. t['\u336A'] = '\u0031\u0038\u70B9';
  23306. t['\u336B'] = '\u0031\u0039\u70B9';
  23307. t['\u336C'] = '\u0032\u0030\u70B9';
  23308. t['\u336D'] = '\u0032\u0031\u70B9';
  23309. t['\u336E'] = '\u0032\u0032\u70B9';
  23310. t['\u336F'] = '\u0032\u0033\u70B9';
  23311. t['\u3370'] = '\u0032\u0034\u70B9';
  23312. t['\u33E0'] = '\u0031\u65E5';
  23313. t['\u33E1'] = '\u0032\u65E5';
  23314. t['\u33E2'] = '\u0033\u65E5';
  23315. t['\u33E3'] = '\u0034\u65E5';
  23316. t['\u33E4'] = '\u0035\u65E5';
  23317. t['\u33E5'] = '\u0036\u65E5';
  23318. t['\u33E6'] = '\u0037\u65E5';
  23319. t['\u33E7'] = '\u0038\u65E5';
  23320. t['\u33E8'] = '\u0039\u65E5';
  23321. t['\u33E9'] = '\u0031\u0030\u65E5';
  23322. t['\u33EA'] = '\u0031\u0031\u65E5';
  23323. t['\u33EB'] = '\u0031\u0032\u65E5';
  23324. t['\u33EC'] = '\u0031\u0033\u65E5';
  23325. t['\u33ED'] = '\u0031\u0034\u65E5';
  23326. t['\u33EE'] = '\u0031\u0035\u65E5';
  23327. t['\u33EF'] = '\u0031\u0036\u65E5';
  23328. t['\u33F0'] = '\u0031\u0037\u65E5';
  23329. t['\u33F1'] = '\u0031\u0038\u65E5';
  23330. t['\u33F2'] = '\u0031\u0039\u65E5';
  23331. t['\u33F3'] = '\u0032\u0030\u65E5';
  23332. t['\u33F4'] = '\u0032\u0031\u65E5';
  23333. t['\u33F5'] = '\u0032\u0032\u65E5';
  23334. t['\u33F6'] = '\u0032\u0033\u65E5';
  23335. t['\u33F7'] = '\u0032\u0034\u65E5';
  23336. t['\u33F8'] = '\u0032\u0035\u65E5';
  23337. t['\u33F9'] = '\u0032\u0036\u65E5';
  23338. t['\u33FA'] = '\u0032\u0037\u65E5';
  23339. t['\u33FB'] = '\u0032\u0038\u65E5';
  23340. t['\u33FC'] = '\u0032\u0039\u65E5';
  23341. t['\u33FD'] = '\u0033\u0030\u65E5';
  23342. t['\u33FE'] = '\u0033\u0031\u65E5';
  23343. t['\uFB00'] = '\u0066\u0066';
  23344. t['\uFB01'] = '\u0066\u0069';
  23345. t['\uFB02'] = '\u0066\u006C';
  23346. t['\uFB03'] = '\u0066\u0066\u0069';
  23347. t['\uFB04'] = '\u0066\u0066\u006C';
  23348. t['\uFB05'] = '\u017F\u0074';
  23349. t['\uFB06'] = '\u0073\u0074';
  23350. t['\uFB13'] = '\u0574\u0576';
  23351. t['\uFB14'] = '\u0574\u0565';
  23352. t['\uFB15'] = '\u0574\u056B';
  23353. t['\uFB16'] = '\u057E\u0576';
  23354. t['\uFB17'] = '\u0574\u056D';
  23355. t['\uFB4F'] = '\u05D0\u05DC';
  23356. t['\uFB50'] = '\u0671';
  23357. t['\uFB51'] = '\u0671';
  23358. t['\uFB52'] = '\u067B';
  23359. t['\uFB53'] = '\u067B';
  23360. t['\uFB54'] = '\u067B';
  23361. t['\uFB55'] = '\u067B';
  23362. t['\uFB56'] = '\u067E';
  23363. t['\uFB57'] = '\u067E';
  23364. t['\uFB58'] = '\u067E';
  23365. t['\uFB59'] = '\u067E';
  23366. t['\uFB5A'] = '\u0680';
  23367. t['\uFB5B'] = '\u0680';
  23368. t['\uFB5C'] = '\u0680';
  23369. t['\uFB5D'] = '\u0680';
  23370. t['\uFB5E'] = '\u067A';
  23371. t['\uFB5F'] = '\u067A';
  23372. t['\uFB60'] = '\u067A';
  23373. t['\uFB61'] = '\u067A';
  23374. t['\uFB62'] = '\u067F';
  23375. t['\uFB63'] = '\u067F';
  23376. t['\uFB64'] = '\u067F';
  23377. t['\uFB65'] = '\u067F';
  23378. t['\uFB66'] = '\u0679';
  23379. t['\uFB67'] = '\u0679';
  23380. t['\uFB68'] = '\u0679';
  23381. t['\uFB69'] = '\u0679';
  23382. t['\uFB6A'] = '\u06A4';
  23383. t['\uFB6B'] = '\u06A4';
  23384. t['\uFB6C'] = '\u06A4';
  23385. t['\uFB6D'] = '\u06A4';
  23386. t['\uFB6E'] = '\u06A6';
  23387. t['\uFB6F'] = '\u06A6';
  23388. t['\uFB70'] = '\u06A6';
  23389. t['\uFB71'] = '\u06A6';
  23390. t['\uFB72'] = '\u0684';
  23391. t['\uFB73'] = '\u0684';
  23392. t['\uFB74'] = '\u0684';
  23393. t['\uFB75'] = '\u0684';
  23394. t['\uFB76'] = '\u0683';
  23395. t['\uFB77'] = '\u0683';
  23396. t['\uFB78'] = '\u0683';
  23397. t['\uFB79'] = '\u0683';
  23398. t['\uFB7A'] = '\u0686';
  23399. t['\uFB7B'] = '\u0686';
  23400. t['\uFB7C'] = '\u0686';
  23401. t['\uFB7D'] = '\u0686';
  23402. t['\uFB7E'] = '\u0687';
  23403. t['\uFB7F'] = '\u0687';
  23404. t['\uFB80'] = '\u0687';
  23405. t['\uFB81'] = '\u0687';
  23406. t['\uFB82'] = '\u068D';
  23407. t['\uFB83'] = '\u068D';
  23408. t['\uFB84'] = '\u068C';
  23409. t['\uFB85'] = '\u068C';
  23410. t['\uFB86'] = '\u068E';
  23411. t['\uFB87'] = '\u068E';
  23412. t['\uFB88'] = '\u0688';
  23413. t['\uFB89'] = '\u0688';
  23414. t['\uFB8A'] = '\u0698';
  23415. t['\uFB8B'] = '\u0698';
  23416. t['\uFB8C'] = '\u0691';
  23417. t['\uFB8D'] = '\u0691';
  23418. t['\uFB8E'] = '\u06A9';
  23419. t['\uFB8F'] = '\u06A9';
  23420. t['\uFB90'] = '\u06A9';
  23421. t['\uFB91'] = '\u06A9';
  23422. t['\uFB92'] = '\u06AF';
  23423. t['\uFB93'] = '\u06AF';
  23424. t['\uFB94'] = '\u06AF';
  23425. t['\uFB95'] = '\u06AF';
  23426. t['\uFB96'] = '\u06B3';
  23427. t['\uFB97'] = '\u06B3';
  23428. t['\uFB98'] = '\u06B3';
  23429. t['\uFB99'] = '\u06B3';
  23430. t['\uFB9A'] = '\u06B1';
  23431. t['\uFB9B'] = '\u06B1';
  23432. t['\uFB9C'] = '\u06B1';
  23433. t['\uFB9D'] = '\u06B1';
  23434. t['\uFB9E'] = '\u06BA';
  23435. t['\uFB9F'] = '\u06BA';
  23436. t['\uFBA0'] = '\u06BB';
  23437. t['\uFBA1'] = '\u06BB';
  23438. t['\uFBA2'] = '\u06BB';
  23439. t['\uFBA3'] = '\u06BB';
  23440. t['\uFBA4'] = '\u06C0';
  23441. t['\uFBA5'] = '\u06C0';
  23442. t['\uFBA6'] = '\u06C1';
  23443. t['\uFBA7'] = '\u06C1';
  23444. t['\uFBA8'] = '\u06C1';
  23445. t['\uFBA9'] = '\u06C1';
  23446. t['\uFBAA'] = '\u06BE';
  23447. t['\uFBAB'] = '\u06BE';
  23448. t['\uFBAC'] = '\u06BE';
  23449. t['\uFBAD'] = '\u06BE';
  23450. t['\uFBAE'] = '\u06D2';
  23451. t['\uFBAF'] = '\u06D2';
  23452. t['\uFBB0'] = '\u06D3';
  23453. t['\uFBB1'] = '\u06D3';
  23454. t['\uFBD3'] = '\u06AD';
  23455. t['\uFBD4'] = '\u06AD';
  23456. t['\uFBD5'] = '\u06AD';
  23457. t['\uFBD6'] = '\u06AD';
  23458. t['\uFBD7'] = '\u06C7';
  23459. t['\uFBD8'] = '\u06C7';
  23460. t['\uFBD9'] = '\u06C6';
  23461. t['\uFBDA'] = '\u06C6';
  23462. t['\uFBDB'] = '\u06C8';
  23463. t['\uFBDC'] = '\u06C8';
  23464. t['\uFBDD'] = '\u0677';
  23465. t['\uFBDE'] = '\u06CB';
  23466. t['\uFBDF'] = '\u06CB';
  23467. t['\uFBE0'] = '\u06C5';
  23468. t['\uFBE1'] = '\u06C5';
  23469. t['\uFBE2'] = '\u06C9';
  23470. t['\uFBE3'] = '\u06C9';
  23471. t['\uFBE4'] = '\u06D0';
  23472. t['\uFBE5'] = '\u06D0';
  23473. t['\uFBE6'] = '\u06D0';
  23474. t['\uFBE7'] = '\u06D0';
  23475. t['\uFBE8'] = '\u0649';
  23476. t['\uFBE9'] = '\u0649';
  23477. t['\uFBEA'] = '\u0626\u0627';
  23478. t['\uFBEB'] = '\u0626\u0627';
  23479. t['\uFBEC'] = '\u0626\u06D5';
  23480. t['\uFBED'] = '\u0626\u06D5';
  23481. t['\uFBEE'] = '\u0626\u0648';
  23482. t['\uFBEF'] = '\u0626\u0648';
  23483. t['\uFBF0'] = '\u0626\u06C7';
  23484. t['\uFBF1'] = '\u0626\u06C7';
  23485. t['\uFBF2'] = '\u0626\u06C6';
  23486. t['\uFBF3'] = '\u0626\u06C6';
  23487. t['\uFBF4'] = '\u0626\u06C8';
  23488. t['\uFBF5'] = '\u0626\u06C8';
  23489. t['\uFBF6'] = '\u0626\u06D0';
  23490. t['\uFBF7'] = '\u0626\u06D0';
  23491. t['\uFBF8'] = '\u0626\u06D0';
  23492. t['\uFBF9'] = '\u0626\u0649';
  23493. t['\uFBFA'] = '\u0626\u0649';
  23494. t['\uFBFB'] = '\u0626\u0649';
  23495. t['\uFBFC'] = '\u06CC';
  23496. t['\uFBFD'] = '\u06CC';
  23497. t['\uFBFE'] = '\u06CC';
  23498. t['\uFBFF'] = '\u06CC';
  23499. t['\uFC00'] = '\u0626\u062C';
  23500. t['\uFC01'] = '\u0626\u062D';
  23501. t['\uFC02'] = '\u0626\u0645';
  23502. t['\uFC03'] = '\u0626\u0649';
  23503. t['\uFC04'] = '\u0626\u064A';
  23504. t['\uFC05'] = '\u0628\u062C';
  23505. t['\uFC06'] = '\u0628\u062D';
  23506. t['\uFC07'] = '\u0628\u062E';
  23507. t['\uFC08'] = '\u0628\u0645';
  23508. t['\uFC09'] = '\u0628\u0649';
  23509. t['\uFC0A'] = '\u0628\u064A';
  23510. t['\uFC0B'] = '\u062A\u062C';
  23511. t['\uFC0C'] = '\u062A\u062D';
  23512. t['\uFC0D'] = '\u062A\u062E';
  23513. t['\uFC0E'] = '\u062A\u0645';
  23514. t['\uFC0F'] = '\u062A\u0649';
  23515. t['\uFC10'] = '\u062A\u064A';
  23516. t['\uFC11'] = '\u062B\u062C';
  23517. t['\uFC12'] = '\u062B\u0645';
  23518. t['\uFC13'] = '\u062B\u0649';
  23519. t['\uFC14'] = '\u062B\u064A';
  23520. t['\uFC15'] = '\u062C\u062D';
  23521. t['\uFC16'] = '\u062C\u0645';
  23522. t['\uFC17'] = '\u062D\u062C';
  23523. t['\uFC18'] = '\u062D\u0645';
  23524. t['\uFC19'] = '\u062E\u062C';
  23525. t['\uFC1A'] = '\u062E\u062D';
  23526. t['\uFC1B'] = '\u062E\u0645';
  23527. t['\uFC1C'] = '\u0633\u062C';
  23528. t['\uFC1D'] = '\u0633\u062D';
  23529. t['\uFC1E'] = '\u0633\u062E';
  23530. t['\uFC1F'] = '\u0633\u0645';
  23531. t['\uFC20'] = '\u0635\u062D';
  23532. t['\uFC21'] = '\u0635\u0645';
  23533. t['\uFC22'] = '\u0636\u062C';
  23534. t['\uFC23'] = '\u0636\u062D';
  23535. t['\uFC24'] = '\u0636\u062E';
  23536. t['\uFC25'] = '\u0636\u0645';
  23537. t['\uFC26'] = '\u0637\u062D';
  23538. t['\uFC27'] = '\u0637\u0645';
  23539. t['\uFC28'] = '\u0638\u0645';
  23540. t['\uFC29'] = '\u0639\u062C';
  23541. t['\uFC2A'] = '\u0639\u0645';
  23542. t['\uFC2B'] = '\u063A\u062C';
  23543. t['\uFC2C'] = '\u063A\u0645';
  23544. t['\uFC2D'] = '\u0641\u062C';
  23545. t['\uFC2E'] = '\u0641\u062D';
  23546. t['\uFC2F'] = '\u0641\u062E';
  23547. t['\uFC30'] = '\u0641\u0645';
  23548. t['\uFC31'] = '\u0641\u0649';
  23549. t['\uFC32'] = '\u0641\u064A';
  23550. t['\uFC33'] = '\u0642\u062D';
  23551. t['\uFC34'] = '\u0642\u0645';
  23552. t['\uFC35'] = '\u0642\u0649';
  23553. t['\uFC36'] = '\u0642\u064A';
  23554. t['\uFC37'] = '\u0643\u0627';
  23555. t['\uFC38'] = '\u0643\u062C';
  23556. t['\uFC39'] = '\u0643\u062D';
  23557. t['\uFC3A'] = '\u0643\u062E';
  23558. t['\uFC3B'] = '\u0643\u0644';
  23559. t['\uFC3C'] = '\u0643\u0645';
  23560. t['\uFC3D'] = '\u0643\u0649';
  23561. t['\uFC3E'] = '\u0643\u064A';
  23562. t['\uFC3F'] = '\u0644\u062C';
  23563. t['\uFC40'] = '\u0644\u062D';
  23564. t['\uFC41'] = '\u0644\u062E';
  23565. t['\uFC42'] = '\u0644\u0645';
  23566. t['\uFC43'] = '\u0644\u0649';
  23567. t['\uFC44'] = '\u0644\u064A';
  23568. t['\uFC45'] = '\u0645\u062C';
  23569. t['\uFC46'] = '\u0645\u062D';
  23570. t['\uFC47'] = '\u0645\u062E';
  23571. t['\uFC48'] = '\u0645\u0645';
  23572. t['\uFC49'] = '\u0645\u0649';
  23573. t['\uFC4A'] = '\u0645\u064A';
  23574. t['\uFC4B'] = '\u0646\u062C';
  23575. t['\uFC4C'] = '\u0646\u062D';
  23576. t['\uFC4D'] = '\u0646\u062E';
  23577. t['\uFC4E'] = '\u0646\u0645';
  23578. t['\uFC4F'] = '\u0646\u0649';
  23579. t['\uFC50'] = '\u0646\u064A';
  23580. t['\uFC51'] = '\u0647\u062C';
  23581. t['\uFC52'] = '\u0647\u0645';
  23582. t['\uFC53'] = '\u0647\u0649';
  23583. t['\uFC54'] = '\u0647\u064A';
  23584. t['\uFC55'] = '\u064A\u062C';
  23585. t['\uFC56'] = '\u064A\u062D';
  23586. t['\uFC57'] = '\u064A\u062E';
  23587. t['\uFC58'] = '\u064A\u0645';
  23588. t['\uFC59'] = '\u064A\u0649';
  23589. t['\uFC5A'] = '\u064A\u064A';
  23590. t['\uFC5B'] = '\u0630\u0670';
  23591. t['\uFC5C'] = '\u0631\u0670';
  23592. t['\uFC5D'] = '\u0649\u0670';
  23593. t['\uFC5E'] = '\u0020\u064C\u0651';
  23594. t['\uFC5F'] = '\u0020\u064D\u0651';
  23595. t['\uFC60'] = '\u0020\u064E\u0651';
  23596. t['\uFC61'] = '\u0020\u064F\u0651';
  23597. t['\uFC62'] = '\u0020\u0650\u0651';
  23598. t['\uFC63'] = '\u0020\u0651\u0670';
  23599. t['\uFC64'] = '\u0626\u0631';
  23600. t['\uFC65'] = '\u0626\u0632';
  23601. t['\uFC66'] = '\u0626\u0645';
  23602. t['\uFC67'] = '\u0626\u0646';
  23603. t['\uFC68'] = '\u0626\u0649';
  23604. t['\uFC69'] = '\u0626\u064A';
  23605. t['\uFC6A'] = '\u0628\u0631';
  23606. t['\uFC6B'] = '\u0628\u0632';
  23607. t['\uFC6C'] = '\u0628\u0645';
  23608. t['\uFC6D'] = '\u0628\u0646';
  23609. t['\uFC6E'] = '\u0628\u0649';
  23610. t['\uFC6F'] = '\u0628\u064A';
  23611. t['\uFC70'] = '\u062A\u0631';
  23612. t['\uFC71'] = '\u062A\u0632';
  23613. t['\uFC72'] = '\u062A\u0645';
  23614. t['\uFC73'] = '\u062A\u0646';
  23615. t['\uFC74'] = '\u062A\u0649';
  23616. t['\uFC75'] = '\u062A\u064A';
  23617. t['\uFC76'] = '\u062B\u0631';
  23618. t['\uFC77'] = '\u062B\u0632';
  23619. t['\uFC78'] = '\u062B\u0645';
  23620. t['\uFC79'] = '\u062B\u0646';
  23621. t['\uFC7A'] = '\u062B\u0649';
  23622. t['\uFC7B'] = '\u062B\u064A';
  23623. t['\uFC7C'] = '\u0641\u0649';
  23624. t['\uFC7D'] = '\u0641\u064A';
  23625. t['\uFC7E'] = '\u0642\u0649';
  23626. t['\uFC7F'] = '\u0642\u064A';
  23627. t['\uFC80'] = '\u0643\u0627';
  23628. t['\uFC81'] = '\u0643\u0644';
  23629. t['\uFC82'] = '\u0643\u0645';
  23630. t['\uFC83'] = '\u0643\u0649';
  23631. t['\uFC84'] = '\u0643\u064A';
  23632. t['\uFC85'] = '\u0644\u0645';
  23633. t['\uFC86'] = '\u0644\u0649';
  23634. t['\uFC87'] = '\u0644\u064A';
  23635. t['\uFC88'] = '\u0645\u0627';
  23636. t['\uFC89'] = '\u0645\u0645';
  23637. t['\uFC8A'] = '\u0646\u0631';
  23638. t['\uFC8B'] = '\u0646\u0632';
  23639. t['\uFC8C'] = '\u0646\u0645';
  23640. t['\uFC8D'] = '\u0646\u0646';
  23641. t['\uFC8E'] = '\u0646\u0649';
  23642. t['\uFC8F'] = '\u0646\u064A';
  23643. t['\uFC90'] = '\u0649\u0670';
  23644. t['\uFC91'] = '\u064A\u0631';
  23645. t['\uFC92'] = '\u064A\u0632';
  23646. t['\uFC93'] = '\u064A\u0645';
  23647. t['\uFC94'] = '\u064A\u0646';
  23648. t['\uFC95'] = '\u064A\u0649';
  23649. t['\uFC96'] = '\u064A\u064A';
  23650. t['\uFC97'] = '\u0626\u062C';
  23651. t['\uFC98'] = '\u0626\u062D';
  23652. t['\uFC99'] = '\u0626\u062E';
  23653. t['\uFC9A'] = '\u0626\u0645';
  23654. t['\uFC9B'] = '\u0626\u0647';
  23655. t['\uFC9C'] = '\u0628\u062C';
  23656. t['\uFC9D'] = '\u0628\u062D';
  23657. t['\uFC9E'] = '\u0628\u062E';
  23658. t['\uFC9F'] = '\u0628\u0645';
  23659. t['\uFCA0'] = '\u0628\u0647';
  23660. t['\uFCA1'] = '\u062A\u062C';
  23661. t['\uFCA2'] = '\u062A\u062D';
  23662. t['\uFCA3'] = '\u062A\u062E';
  23663. t['\uFCA4'] = '\u062A\u0645';
  23664. t['\uFCA5'] = '\u062A\u0647';
  23665. t['\uFCA6'] = '\u062B\u0645';
  23666. t['\uFCA7'] = '\u062C\u062D';
  23667. t['\uFCA8'] = '\u062C\u0645';
  23668. t['\uFCA9'] = '\u062D\u062C';
  23669. t['\uFCAA'] = '\u062D\u0645';
  23670. t['\uFCAB'] = '\u062E\u062C';
  23671. t['\uFCAC'] = '\u062E\u0645';
  23672. t['\uFCAD'] = '\u0633\u062C';
  23673. t['\uFCAE'] = '\u0633\u062D';
  23674. t['\uFCAF'] = '\u0633\u062E';
  23675. t['\uFCB0'] = '\u0633\u0645';
  23676. t['\uFCB1'] = '\u0635\u062D';
  23677. t['\uFCB2'] = '\u0635\u062E';
  23678. t['\uFCB3'] = '\u0635\u0645';
  23679. t['\uFCB4'] = '\u0636\u062C';
  23680. t['\uFCB5'] = '\u0636\u062D';
  23681. t['\uFCB6'] = '\u0636\u062E';
  23682. t['\uFCB7'] = '\u0636\u0645';
  23683. t['\uFCB8'] = '\u0637\u062D';
  23684. t['\uFCB9'] = '\u0638\u0645';
  23685. t['\uFCBA'] = '\u0639\u062C';
  23686. t['\uFCBB'] = '\u0639\u0645';
  23687. t['\uFCBC'] = '\u063A\u062C';
  23688. t['\uFCBD'] = '\u063A\u0645';
  23689. t['\uFCBE'] = '\u0641\u062C';
  23690. t['\uFCBF'] = '\u0641\u062D';
  23691. t['\uFCC0'] = '\u0641\u062E';
  23692. t['\uFCC1'] = '\u0641\u0645';
  23693. t['\uFCC2'] = '\u0642\u062D';
  23694. t['\uFCC3'] = '\u0642\u0645';
  23695. t['\uFCC4'] = '\u0643\u062C';
  23696. t['\uFCC5'] = '\u0643\u062D';
  23697. t['\uFCC6'] = '\u0643\u062E';
  23698. t['\uFCC7'] = '\u0643\u0644';
  23699. t['\uFCC8'] = '\u0643\u0645';
  23700. t['\uFCC9'] = '\u0644\u062C';
  23701. t['\uFCCA'] = '\u0644\u062D';
  23702. t['\uFCCB'] = '\u0644\u062E';
  23703. t['\uFCCC'] = '\u0644\u0645';
  23704. t['\uFCCD'] = '\u0644\u0647';
  23705. t['\uFCCE'] = '\u0645\u062C';
  23706. t['\uFCCF'] = '\u0645\u062D';
  23707. t['\uFCD0'] = '\u0645\u062E';
  23708. t['\uFCD1'] = '\u0645\u0645';
  23709. t['\uFCD2'] = '\u0646\u062C';
  23710. t['\uFCD3'] = '\u0646\u062D';
  23711. t['\uFCD4'] = '\u0646\u062E';
  23712. t['\uFCD5'] = '\u0646\u0645';
  23713. t['\uFCD6'] = '\u0646\u0647';
  23714. t['\uFCD7'] = '\u0647\u062C';
  23715. t['\uFCD8'] = '\u0647\u0645';
  23716. t['\uFCD9'] = '\u0647\u0670';
  23717. t['\uFCDA'] = '\u064A\u062C';
  23718. t['\uFCDB'] = '\u064A\u062D';
  23719. t['\uFCDC'] = '\u064A\u062E';
  23720. t['\uFCDD'] = '\u064A\u0645';
  23721. t['\uFCDE'] = '\u064A\u0647';
  23722. t['\uFCDF'] = '\u0626\u0645';
  23723. t['\uFCE0'] = '\u0626\u0647';
  23724. t['\uFCE1'] = '\u0628\u0645';
  23725. t['\uFCE2'] = '\u0628\u0647';
  23726. t['\uFCE3'] = '\u062A\u0645';
  23727. t['\uFCE4'] = '\u062A\u0647';
  23728. t['\uFCE5'] = '\u062B\u0645';
  23729. t['\uFCE6'] = '\u062B\u0647';
  23730. t['\uFCE7'] = '\u0633\u0645';
  23731. t['\uFCE8'] = '\u0633\u0647';
  23732. t['\uFCE9'] = '\u0634\u0645';
  23733. t['\uFCEA'] = '\u0634\u0647';
  23734. t['\uFCEB'] = '\u0643\u0644';
  23735. t['\uFCEC'] = '\u0643\u0645';
  23736. t['\uFCED'] = '\u0644\u0645';
  23737. t['\uFCEE'] = '\u0646\u0645';
  23738. t['\uFCEF'] = '\u0646\u0647';
  23739. t['\uFCF0'] = '\u064A\u0645';
  23740. t['\uFCF1'] = '\u064A\u0647';
  23741. t['\uFCF2'] = '\u0640\u064E\u0651';
  23742. t['\uFCF3'] = '\u0640\u064F\u0651';
  23743. t['\uFCF4'] = '\u0640\u0650\u0651';
  23744. t['\uFCF5'] = '\u0637\u0649';
  23745. t['\uFCF6'] = '\u0637\u064A';
  23746. t['\uFCF7'] = '\u0639\u0649';
  23747. t['\uFCF8'] = '\u0639\u064A';
  23748. t['\uFCF9'] = '\u063A\u0649';
  23749. t['\uFCFA'] = '\u063A\u064A';
  23750. t['\uFCFB'] = '\u0633\u0649';
  23751. t['\uFCFC'] = '\u0633\u064A';
  23752. t['\uFCFD'] = '\u0634\u0649';
  23753. t['\uFCFE'] = '\u0634\u064A';
  23754. t['\uFCFF'] = '\u062D\u0649';
  23755. t['\uFD00'] = '\u062D\u064A';
  23756. t['\uFD01'] = '\u062C\u0649';
  23757. t['\uFD02'] = '\u062C\u064A';
  23758. t['\uFD03'] = '\u062E\u0649';
  23759. t['\uFD04'] = '\u062E\u064A';
  23760. t['\uFD05'] = '\u0635\u0649';
  23761. t['\uFD06'] = '\u0635\u064A';
  23762. t['\uFD07'] = '\u0636\u0649';
  23763. t['\uFD08'] = '\u0636\u064A';
  23764. t['\uFD09'] = '\u0634\u062C';
  23765. t['\uFD0A'] = '\u0634\u062D';
  23766. t['\uFD0B'] = '\u0634\u062E';
  23767. t['\uFD0C'] = '\u0634\u0645';
  23768. t['\uFD0D'] = '\u0634\u0631';
  23769. t['\uFD0E'] = '\u0633\u0631';
  23770. t['\uFD0F'] = '\u0635\u0631';
  23771. t['\uFD10'] = '\u0636\u0631';
  23772. t['\uFD11'] = '\u0637\u0649';
  23773. t['\uFD12'] = '\u0637\u064A';
  23774. t['\uFD13'] = '\u0639\u0649';
  23775. t['\uFD14'] = '\u0639\u064A';
  23776. t['\uFD15'] = '\u063A\u0649';
  23777. t['\uFD16'] = '\u063A\u064A';
  23778. t['\uFD17'] = '\u0633\u0649';
  23779. t['\uFD18'] = '\u0633\u064A';
  23780. t['\uFD19'] = '\u0634\u0649';
  23781. t['\uFD1A'] = '\u0634\u064A';
  23782. t['\uFD1B'] = '\u062D\u0649';
  23783. t['\uFD1C'] = '\u062D\u064A';
  23784. t['\uFD1D'] = '\u062C\u0649';
  23785. t['\uFD1E'] = '\u062C\u064A';
  23786. t['\uFD1F'] = '\u062E\u0649';
  23787. t['\uFD20'] = '\u062E\u064A';
  23788. t['\uFD21'] = '\u0635\u0649';
  23789. t['\uFD22'] = '\u0635\u064A';
  23790. t['\uFD23'] = '\u0636\u0649';
  23791. t['\uFD24'] = '\u0636\u064A';
  23792. t['\uFD25'] = '\u0634\u062C';
  23793. t['\uFD26'] = '\u0634\u062D';
  23794. t['\uFD27'] = '\u0634\u062E';
  23795. t['\uFD28'] = '\u0634\u0645';
  23796. t['\uFD29'] = '\u0634\u0631';
  23797. t['\uFD2A'] = '\u0633\u0631';
  23798. t['\uFD2B'] = '\u0635\u0631';
  23799. t['\uFD2C'] = '\u0636\u0631';
  23800. t['\uFD2D'] = '\u0634\u062C';
  23801. t['\uFD2E'] = '\u0634\u062D';
  23802. t['\uFD2F'] = '\u0634\u062E';
  23803. t['\uFD30'] = '\u0634\u0645';
  23804. t['\uFD31'] = '\u0633\u0647';
  23805. t['\uFD32'] = '\u0634\u0647';
  23806. t['\uFD33'] = '\u0637\u0645';
  23807. t['\uFD34'] = '\u0633\u062C';
  23808. t['\uFD35'] = '\u0633\u062D';
  23809. t['\uFD36'] = '\u0633\u062E';
  23810. t['\uFD37'] = '\u0634\u062C';
  23811. t['\uFD38'] = '\u0634\u062D';
  23812. t['\uFD39'] = '\u0634\u062E';
  23813. t['\uFD3A'] = '\u0637\u0645';
  23814. t['\uFD3B'] = '\u0638\u0645';
  23815. t['\uFD3C'] = '\u0627\u064B';
  23816. t['\uFD3D'] = '\u0627\u064B';
  23817. t['\uFD50'] = '\u062A\u062C\u0645';
  23818. t['\uFD51'] = '\u062A\u062D\u062C';
  23819. t['\uFD52'] = '\u062A\u062D\u062C';
  23820. t['\uFD53'] = '\u062A\u062D\u0645';
  23821. t['\uFD54'] = '\u062A\u062E\u0645';
  23822. t['\uFD55'] = '\u062A\u0645\u062C';
  23823. t['\uFD56'] = '\u062A\u0645\u062D';
  23824. t['\uFD57'] = '\u062A\u0645\u062E';
  23825. t['\uFD58'] = '\u062C\u0645\u062D';
  23826. t['\uFD59'] = '\u062C\u0645\u062D';
  23827. t['\uFD5A'] = '\u062D\u0645\u064A';
  23828. t['\uFD5B'] = '\u062D\u0645\u0649';
  23829. t['\uFD5C'] = '\u0633\u062D\u062C';
  23830. t['\uFD5D'] = '\u0633\u062C\u062D';
  23831. t['\uFD5E'] = '\u0633\u062C\u0649';
  23832. t['\uFD5F'] = '\u0633\u0645\u062D';
  23833. t['\uFD60'] = '\u0633\u0645\u062D';
  23834. t['\uFD61'] = '\u0633\u0645\u062C';
  23835. t['\uFD62'] = '\u0633\u0645\u0645';
  23836. t['\uFD63'] = '\u0633\u0645\u0645';
  23837. t['\uFD64'] = '\u0635\u062D\u062D';
  23838. t['\uFD65'] = '\u0635\u062D\u062D';
  23839. t['\uFD66'] = '\u0635\u0645\u0645';
  23840. t['\uFD67'] = '\u0634\u062D\u0645';
  23841. t['\uFD68'] = '\u0634\u062D\u0645';
  23842. t['\uFD69'] = '\u0634\u062C\u064A';
  23843. t['\uFD6A'] = '\u0634\u0645\u062E';
  23844. t['\uFD6B'] = '\u0634\u0645\u062E';
  23845. t['\uFD6C'] = '\u0634\u0645\u0645';
  23846. t['\uFD6D'] = '\u0634\u0645\u0645';
  23847. t['\uFD6E'] = '\u0636\u062D\u0649';
  23848. t['\uFD6F'] = '\u0636\u062E\u0645';
  23849. t['\uFD70'] = '\u0636\u062E\u0645';
  23850. t['\uFD71'] = '\u0637\u0645\u062D';
  23851. t['\uFD72'] = '\u0637\u0645\u062D';
  23852. t['\uFD73'] = '\u0637\u0645\u0645';
  23853. t['\uFD74'] = '\u0637\u0645\u064A';
  23854. t['\uFD75'] = '\u0639\u062C\u0645';
  23855. t['\uFD76'] = '\u0639\u0645\u0645';
  23856. t['\uFD77'] = '\u0639\u0645\u0645';
  23857. t['\uFD78'] = '\u0639\u0645\u0649';
  23858. t['\uFD79'] = '\u063A\u0645\u0645';
  23859. t['\uFD7A'] = '\u063A\u0645\u064A';
  23860. t['\uFD7B'] = '\u063A\u0645\u0649';
  23861. t['\uFD7C'] = '\u0641\u062E\u0645';
  23862. t['\uFD7D'] = '\u0641\u062E\u0645';
  23863. t['\uFD7E'] = '\u0642\u0645\u062D';
  23864. t['\uFD7F'] = '\u0642\u0645\u0645';
  23865. t['\uFD80'] = '\u0644\u062D\u0645';
  23866. t['\uFD81'] = '\u0644\u062D\u064A';
  23867. t['\uFD82'] = '\u0644\u062D\u0649';
  23868. t['\uFD83'] = '\u0644\u062C\u062C';
  23869. t['\uFD84'] = '\u0644\u062C\u062C';
  23870. t['\uFD85'] = '\u0644\u062E\u0645';
  23871. t['\uFD86'] = '\u0644\u062E\u0645';
  23872. t['\uFD87'] = '\u0644\u0645\u062D';
  23873. t['\uFD88'] = '\u0644\u0645\u062D';
  23874. t['\uFD89'] = '\u0645\u062D\u062C';
  23875. t['\uFD8A'] = '\u0645\u062D\u0645';
  23876. t['\uFD8B'] = '\u0645\u062D\u064A';
  23877. t['\uFD8C'] = '\u0645\u062C\u062D';
  23878. t['\uFD8D'] = '\u0645\u062C\u0645';
  23879. t['\uFD8E'] = '\u0645\u062E\u062C';
  23880. t['\uFD8F'] = '\u0645\u062E\u0645';
  23881. t['\uFD92'] = '\u0645\u062C\u062E';
  23882. t['\uFD93'] = '\u0647\u0645\u062C';
  23883. t['\uFD94'] = '\u0647\u0645\u0645';
  23884. t['\uFD95'] = '\u0646\u062D\u0645';
  23885. t['\uFD96'] = '\u0646\u062D\u0649';
  23886. t['\uFD97'] = '\u0646\u062C\u0645';
  23887. t['\uFD98'] = '\u0646\u062C\u0645';
  23888. t['\uFD99'] = '\u0646\u062C\u0649';
  23889. t['\uFD9A'] = '\u0646\u0645\u064A';
  23890. t['\uFD9B'] = '\u0646\u0645\u0649';
  23891. t['\uFD9C'] = '\u064A\u0645\u0645';
  23892. t['\uFD9D'] = '\u064A\u0645\u0645';
  23893. t['\uFD9E'] = '\u0628\u062E\u064A';
  23894. t['\uFD9F'] = '\u062A\u062C\u064A';
  23895. t['\uFDA0'] = '\u062A\u062C\u0649';
  23896. t['\uFDA1'] = '\u062A\u062E\u064A';
  23897. t['\uFDA2'] = '\u062A\u062E\u0649';
  23898. t['\uFDA3'] = '\u062A\u0645\u064A';
  23899. t['\uFDA4'] = '\u062A\u0645\u0649';
  23900. t['\uFDA5'] = '\u062C\u0645\u064A';
  23901. t['\uFDA6'] = '\u062C\u062D\u0649';
  23902. t['\uFDA7'] = '\u062C\u0645\u0649';
  23903. t['\uFDA8'] = '\u0633\u062E\u0649';
  23904. t['\uFDA9'] = '\u0635\u062D\u064A';
  23905. t['\uFDAA'] = '\u0634\u062D\u064A';
  23906. t['\uFDAB'] = '\u0636\u062D\u064A';
  23907. t['\uFDAC'] = '\u0644\u062C\u064A';
  23908. t['\uFDAD'] = '\u0644\u0645\u064A';
  23909. t['\uFDAE'] = '\u064A\u062D\u064A';
  23910. t['\uFDAF'] = '\u064A\u062C\u064A';
  23911. t['\uFDB0'] = '\u064A\u0645\u064A';
  23912. t['\uFDB1'] = '\u0645\u0645\u064A';
  23913. t['\uFDB2'] = '\u0642\u0645\u064A';
  23914. t['\uFDB3'] = '\u0646\u062D\u064A';
  23915. t['\uFDB4'] = '\u0642\u0645\u062D';
  23916. t['\uFDB5'] = '\u0644\u062D\u0645';
  23917. t['\uFDB6'] = '\u0639\u0645\u064A';
  23918. t['\uFDB7'] = '\u0643\u0645\u064A';
  23919. t['\uFDB8'] = '\u0646\u062C\u062D';
  23920. t['\uFDB9'] = '\u0645\u062E\u064A';
  23921. t['\uFDBA'] = '\u0644\u062C\u0645';
  23922. t['\uFDBB'] = '\u0643\u0645\u0645';
  23923. t['\uFDBC'] = '\u0644\u062C\u0645';
  23924. t['\uFDBD'] = '\u0646\u062C\u062D';
  23925. t['\uFDBE'] = '\u062C\u062D\u064A';
  23926. t['\uFDBF'] = '\u062D\u062C\u064A';
  23927. t['\uFDC0'] = '\u0645\u062C\u064A';
  23928. t['\uFDC1'] = '\u0641\u0645\u064A';
  23929. t['\uFDC2'] = '\u0628\u062D\u064A';
  23930. t['\uFDC3'] = '\u0643\u0645\u0645';
  23931. t['\uFDC4'] = '\u0639\u062C\u0645';
  23932. t['\uFDC5'] = '\u0635\u0645\u0645';
  23933. t['\uFDC6'] = '\u0633\u062E\u064A';
  23934. t['\uFDC7'] = '\u0646\u062C\u064A';
  23935. t['\uFE49'] = '\u203E';
  23936. t['\uFE4A'] = '\u203E';
  23937. t['\uFE4B'] = '\u203E';
  23938. t['\uFE4C'] = '\u203E';
  23939. t['\uFE4D'] = '\u005F';
  23940. t['\uFE4E'] = '\u005F';
  23941. t['\uFE4F'] = '\u005F';
  23942. t['\uFE80'] = '\u0621';
  23943. t['\uFE81'] = '\u0622';
  23944. t['\uFE82'] = '\u0622';
  23945. t['\uFE83'] = '\u0623';
  23946. t['\uFE84'] = '\u0623';
  23947. t['\uFE85'] = '\u0624';
  23948. t['\uFE86'] = '\u0624';
  23949. t['\uFE87'] = '\u0625';
  23950. t['\uFE88'] = '\u0625';
  23951. t['\uFE89'] = '\u0626';
  23952. t['\uFE8A'] = '\u0626';
  23953. t['\uFE8B'] = '\u0626';
  23954. t['\uFE8C'] = '\u0626';
  23955. t['\uFE8D'] = '\u0627';
  23956. t['\uFE8E'] = '\u0627';
  23957. t['\uFE8F'] = '\u0628';
  23958. t['\uFE90'] = '\u0628';
  23959. t['\uFE91'] = '\u0628';
  23960. t['\uFE92'] = '\u0628';
  23961. t['\uFE93'] = '\u0629';
  23962. t['\uFE94'] = '\u0629';
  23963. t['\uFE95'] = '\u062A';
  23964. t['\uFE96'] = '\u062A';
  23965. t['\uFE97'] = '\u062A';
  23966. t['\uFE98'] = '\u062A';
  23967. t['\uFE99'] = '\u062B';
  23968. t['\uFE9A'] = '\u062B';
  23969. t['\uFE9B'] = '\u062B';
  23970. t['\uFE9C'] = '\u062B';
  23971. t['\uFE9D'] = '\u062C';
  23972. t['\uFE9E'] = '\u062C';
  23973. t['\uFE9F'] = '\u062C';
  23974. t['\uFEA0'] = '\u062C';
  23975. t['\uFEA1'] = '\u062D';
  23976. t['\uFEA2'] = '\u062D';
  23977. t['\uFEA3'] = '\u062D';
  23978. t['\uFEA4'] = '\u062D';
  23979. t['\uFEA5'] = '\u062E';
  23980. t['\uFEA6'] = '\u062E';
  23981. t['\uFEA7'] = '\u062E';
  23982. t['\uFEA8'] = '\u062E';
  23983. t['\uFEA9'] = '\u062F';
  23984. t['\uFEAA'] = '\u062F';
  23985. t['\uFEAB'] = '\u0630';
  23986. t['\uFEAC'] = '\u0630';
  23987. t['\uFEAD'] = '\u0631';
  23988. t['\uFEAE'] = '\u0631';
  23989. t['\uFEAF'] = '\u0632';
  23990. t['\uFEB0'] = '\u0632';
  23991. t['\uFEB1'] = '\u0633';
  23992. t['\uFEB2'] = '\u0633';
  23993. t['\uFEB3'] = '\u0633';
  23994. t['\uFEB4'] = '\u0633';
  23995. t['\uFEB5'] = '\u0634';
  23996. t['\uFEB6'] = '\u0634';
  23997. t['\uFEB7'] = '\u0634';
  23998. t['\uFEB8'] = '\u0634';
  23999. t['\uFEB9'] = '\u0635';
  24000. t['\uFEBA'] = '\u0635';
  24001. t['\uFEBB'] = '\u0635';
  24002. t['\uFEBC'] = '\u0635';
  24003. t['\uFEBD'] = '\u0636';
  24004. t['\uFEBE'] = '\u0636';
  24005. t['\uFEBF'] = '\u0636';
  24006. t['\uFEC0'] = '\u0636';
  24007. t['\uFEC1'] = '\u0637';
  24008. t['\uFEC2'] = '\u0637';
  24009. t['\uFEC3'] = '\u0637';
  24010. t['\uFEC4'] = '\u0637';
  24011. t['\uFEC5'] = '\u0638';
  24012. t['\uFEC6'] = '\u0638';
  24013. t['\uFEC7'] = '\u0638';
  24014. t['\uFEC8'] = '\u0638';
  24015. t['\uFEC9'] = '\u0639';
  24016. t['\uFECA'] = '\u0639';
  24017. t['\uFECB'] = '\u0639';
  24018. t['\uFECC'] = '\u0639';
  24019. t['\uFECD'] = '\u063A';
  24020. t['\uFECE'] = '\u063A';
  24021. t['\uFECF'] = '\u063A';
  24022. t['\uFED0'] = '\u063A';
  24023. t['\uFED1'] = '\u0641';
  24024. t['\uFED2'] = '\u0641';
  24025. t['\uFED3'] = '\u0641';
  24026. t['\uFED4'] = '\u0641';
  24027. t['\uFED5'] = '\u0642';
  24028. t['\uFED6'] = '\u0642';
  24029. t['\uFED7'] = '\u0642';
  24030. t['\uFED8'] = '\u0642';
  24031. t['\uFED9'] = '\u0643';
  24032. t['\uFEDA'] = '\u0643';
  24033. t['\uFEDB'] = '\u0643';
  24034. t['\uFEDC'] = '\u0643';
  24035. t['\uFEDD'] = '\u0644';
  24036. t['\uFEDE'] = '\u0644';
  24037. t['\uFEDF'] = '\u0644';
  24038. t['\uFEE0'] = '\u0644';
  24039. t['\uFEE1'] = '\u0645';
  24040. t['\uFEE2'] = '\u0645';
  24041. t['\uFEE3'] = '\u0645';
  24042. t['\uFEE4'] = '\u0645';
  24043. t['\uFEE5'] = '\u0646';
  24044. t['\uFEE6'] = '\u0646';
  24045. t['\uFEE7'] = '\u0646';
  24046. t['\uFEE8'] = '\u0646';
  24047. t['\uFEE9'] = '\u0647';
  24048. t['\uFEEA'] = '\u0647';
  24049. t['\uFEEB'] = '\u0647';
  24050. t['\uFEEC'] = '\u0647';
  24051. t['\uFEED'] = '\u0648';
  24052. t['\uFEEE'] = '\u0648';
  24053. t['\uFEEF'] = '\u0649';
  24054. t['\uFEF0'] = '\u0649';
  24055. t['\uFEF1'] = '\u064A';
  24056. t['\uFEF2'] = '\u064A';
  24057. t['\uFEF3'] = '\u064A';
  24058. t['\uFEF4'] = '\u064A';
  24059. t['\uFEF5'] = '\u0644\u0622';
  24060. t['\uFEF6'] = '\u0644\u0622';
  24061. t['\uFEF7'] = '\u0644\u0623';
  24062. t['\uFEF8'] = '\u0644\u0623';
  24063. t['\uFEF9'] = '\u0644\u0625';
  24064. t['\uFEFA'] = '\u0644\u0625';
  24065. t['\uFEFB'] = '\u0644\u0627';
  24066. t['\uFEFC'] = '\u0644\u0627';
  24067. });
  24068. function reverseIfRtl(chars) {
  24069. var charsLength = chars.length;
  24070. //reverse an arabic ligature
  24071. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24072. return chars;
  24073. }
  24074. var s = '';
  24075. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24076. s += chars[ii];
  24077. }
  24078. return s;
  24079. }
  24080. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24081. exports.reverseIfRtl = reverseIfRtl;
  24082. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24083. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24084. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24085. }));
  24086. (function (root, factory) {
  24087. factory(root.pdfjsDisplayDOMUtils = {}, root.pdfjsSharedUtil);
  24088. }(this, function (exports, sharedUtil) {
  24089. var removeNullCharacters = sharedUtil.removeNullCharacters;
  24090. var warn = sharedUtil.warn;
  24091. var deprecated = sharedUtil.deprecated;
  24092. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  24093. /**
  24094. * Optimised CSS custom property getter/setter.
  24095. * @class
  24096. */
  24097. var CustomStyle = function CustomStyleClosure() {
  24098. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  24099. // animate-css-transforms-firefox-webkit.html
  24100. // in some versions of IE9 it is critical that ms appear in this list
  24101. // before Moz
  24102. var prefixes = [
  24103. 'ms',
  24104. 'Moz',
  24105. 'Webkit',
  24106. 'O'
  24107. ];
  24108. var _cache = Object.create(null);
  24109. function CustomStyle() {
  24110. }
  24111. CustomStyle.getProp = function get(propName, element) {
  24112. // check cache only when no element is given
  24113. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  24114. return _cache[propName];
  24115. }
  24116. element = element || document.documentElement;
  24117. var style = element.style, prefixed, uPropName;
  24118. // test standard property first
  24119. if (typeof style[propName] === 'string') {
  24120. return _cache[propName] = propName;
  24121. }
  24122. // capitalize
  24123. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  24124. // test vendor specific properties
  24125. for (var i = 0, l = prefixes.length; i < l; i++) {
  24126. prefixed = prefixes[i] + uPropName;
  24127. if (typeof style[prefixed] === 'string') {
  24128. return _cache[propName] = prefixed;
  24129. }
  24130. }
  24131. //if all fails then set to undefined
  24132. return _cache[propName] = 'undefined';
  24133. };
  24134. CustomStyle.setProp = function set(propName, element, str) {
  24135. var prop = this.getProp(propName);
  24136. if (prop !== 'undefined') {
  24137. element.style[prop] = str;
  24138. }
  24139. };
  24140. return CustomStyle;
  24141. }();
  24142. var hasCanvasTypedArrays;
  24143. hasCanvasTypedArrays = function hasCanvasTypedArrays() {
  24144. var canvas = document.createElement('canvas');
  24145. canvas.width = canvas.height = 1;
  24146. var ctx = canvas.getContext('2d');
  24147. var imageData = ctx.createImageData(1, 1);
  24148. return typeof imageData.data.buffer !== 'undefined';
  24149. };
  24150. var LinkTarget = {
  24151. NONE: 0,
  24152. // Default value.
  24153. SELF: 1,
  24154. BLANK: 2,
  24155. PARENT: 3,
  24156. TOP: 4
  24157. };
  24158. var LinkTargetStringMap = [
  24159. '',
  24160. '_self',
  24161. '_blank',
  24162. '_parent',
  24163. '_top'
  24164. ];
  24165. /**
  24166. * @typedef ExternalLinkParameters
  24167. * @typedef {Object} ExternalLinkParameters
  24168. * @property {string} url - An absolute URL.
  24169. * @property {LinkTarget} target - The link target.
  24170. * @property {string} rel - The link relationship.
  24171. */
  24172. /**
  24173. * Adds various attributes (href, title, target, rel) to hyperlinks.
  24174. * @param {HTMLLinkElement} link - The link element.
  24175. * @param {ExternalLinkParameters} params
  24176. */
  24177. function addLinkAttributes(link, params) {
  24178. var url = params && params.url;
  24179. link.href = link.title = url ? removeNullCharacters(url) : '';
  24180. if (url) {
  24181. var target = params.target;
  24182. if (typeof target === 'undefined') {
  24183. target = getDefaultSetting('externalLinkTarget');
  24184. }
  24185. link.target = LinkTargetStringMap[target];
  24186. var rel = params.rel;
  24187. if (typeof rel === 'undefined') {
  24188. rel = getDefaultSetting('externalLinkRel');
  24189. }
  24190. link.rel = rel;
  24191. }
  24192. }
  24193. // Gets the file name from a given URL.
  24194. function getFilenameFromUrl(url) {
  24195. var anchor = url.indexOf('#');
  24196. var query = url.indexOf('?');
  24197. var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  24198. return url.substring(url.lastIndexOf('/', end) + 1, end);
  24199. }
  24200. function getDefaultSetting(id) {
  24201. // The list of the settings and their default is maintained for backward
  24202. // compatibility and shall not be extended or modified. See also global.js.
  24203. var globalSettings = sharedUtil.globalScope.PDFJS;
  24204. switch (id) {
  24205. case 'pdfBug':
  24206. return globalSettings ? globalSettings.pdfBug : false;
  24207. case 'disableAutoFetch':
  24208. return globalSettings ? globalSettings.disableAutoFetch : false;
  24209. case 'disableStream':
  24210. return globalSettings ? globalSettings.disableStream : false;
  24211. case 'disableRange':
  24212. return globalSettings ? globalSettings.disableRange : false;
  24213. case 'disableFontFace':
  24214. return globalSettings ? globalSettings.disableFontFace : false;
  24215. case 'disableCreateObjectURL':
  24216. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  24217. case 'disableWebGL':
  24218. return globalSettings ? globalSettings.disableWebGL : true;
  24219. case 'cMapUrl':
  24220. return globalSettings ? globalSettings.cMapUrl : null;
  24221. case 'cMapPacked':
  24222. return globalSettings ? globalSettings.cMapPacked : false;
  24223. case 'postMessageTransfers':
  24224. return globalSettings ? globalSettings.postMessageTransfers : true;
  24225. case 'workerSrc':
  24226. return globalSettings ? globalSettings.workerSrc : null;
  24227. case 'disableWorker':
  24228. return globalSettings ? globalSettings.disableWorker : false;
  24229. case 'maxImageSize':
  24230. return globalSettings ? globalSettings.maxImageSize : -1;
  24231. case 'imageResourcesPath':
  24232. return globalSettings ? globalSettings.imageResourcesPath : '';
  24233. case 'isEvalSupported':
  24234. return globalSettings ? globalSettings.isEvalSupported : true;
  24235. case 'externalLinkTarget':
  24236. if (!globalSettings) {
  24237. return LinkTarget.NONE;
  24238. }
  24239. switch (globalSettings.externalLinkTarget) {
  24240. case LinkTarget.NONE:
  24241. case LinkTarget.SELF:
  24242. case LinkTarget.BLANK:
  24243. case LinkTarget.PARENT:
  24244. case LinkTarget.TOP:
  24245. return globalSettings.externalLinkTarget;
  24246. }
  24247. warn('PDFJS.externalLinkTarget is invalid: ' + globalSettings.externalLinkTarget);
  24248. // Reset the external link target, to suppress further warnings.
  24249. globalSettings.externalLinkTarget = LinkTarget.NONE;
  24250. return LinkTarget.NONE;
  24251. case 'externalLinkRel':
  24252. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  24253. case 'enableStats':
  24254. return !!(globalSettings && globalSettings.enableStats);
  24255. default:
  24256. throw new Error('Unknown default setting: ' + id);
  24257. }
  24258. }
  24259. function isExternalLinkTargetSet() {
  24260. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  24261. switch (externalLinkTarget) {
  24262. case LinkTarget.NONE:
  24263. return false;
  24264. case LinkTarget.SELF:
  24265. case LinkTarget.BLANK:
  24266. case LinkTarget.PARENT:
  24267. case LinkTarget.TOP:
  24268. return true;
  24269. }
  24270. }
  24271. function isValidUrl(url, allowRelative) {
  24272. deprecated('isValidUrl(), please use createValidAbsoluteUrl() instead.');
  24273. var baseUrl = allowRelative ? 'http://example.com' : null;
  24274. return createValidAbsoluteUrl(url, baseUrl) !== null;
  24275. }
  24276. exports.CustomStyle = CustomStyle;
  24277. exports.addLinkAttributes = addLinkAttributes;
  24278. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  24279. exports.isValidUrl = isValidUrl;
  24280. exports.getFilenameFromUrl = getFilenameFromUrl;
  24281. exports.LinkTarget = LinkTarget;
  24282. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  24283. exports.getDefaultSetting = getDefaultSetting;
  24284. }));
  24285. (function (root, factory) {
  24286. factory(root.pdfjsDisplayFontLoader = {}, root.pdfjsSharedUtil);
  24287. }(this, function (exports, sharedUtil) {
  24288. var assert = sharedUtil.assert;
  24289. var bytesToString = sharedUtil.bytesToString;
  24290. var string32 = sharedUtil.string32;
  24291. var shadow = sharedUtil.shadow;
  24292. var warn = sharedUtil.warn;
  24293. function FontLoader(docId) {
  24294. this.docId = docId;
  24295. this.styleElement = null;
  24296. this.nativeFontFaces = [];
  24297. this.loadTestFontId = 0;
  24298. this.loadingContext = {
  24299. requests: [],
  24300. nextRequestId: 0
  24301. };
  24302. }
  24303. FontLoader.prototype = {
  24304. insertRule: function fontLoaderInsertRule(rule) {
  24305. var styleElement = this.styleElement;
  24306. if (!styleElement) {
  24307. styleElement = this.styleElement = document.createElement('style');
  24308. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  24309. document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement);
  24310. }
  24311. var styleSheet = styleElement.sheet;
  24312. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  24313. },
  24314. clear: function fontLoaderClear() {
  24315. var styleElement = this.styleElement;
  24316. if (styleElement) {
  24317. styleElement.parentNode.removeChild(styleElement);
  24318. styleElement = this.styleElement = null;
  24319. }
  24320. this.nativeFontFaces.forEach(function (nativeFontFace) {
  24321. document.fonts.delete(nativeFontFace);
  24322. });
  24323. this.nativeFontFaces.length = 0;
  24324. }
  24325. };
  24326. var getLoadTestFont = function () {
  24327. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  24328. // height.
  24329. return atob('T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' + 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' + 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' + 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' + 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' + 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' + 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' + 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' + 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' + 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' + 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' + 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' + 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' + 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' + 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' + 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' + 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' + 'ABAAAAAAAAAAAD6AAAAAAAAA==');
  24330. };
  24331. Object.defineProperty(FontLoader.prototype, 'loadTestFont', {
  24332. get: function () {
  24333. return shadow(this, 'loadTestFont', getLoadTestFont());
  24334. },
  24335. configurable: true
  24336. });
  24337. FontLoader.prototype.addNativeFontFace = function fontLoader_addNativeFontFace(nativeFontFace) {
  24338. this.nativeFontFaces.push(nativeFontFace);
  24339. document.fonts.add(nativeFontFace);
  24340. };
  24341. FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
  24342. var rules = [];
  24343. var fontsToLoad = [];
  24344. var fontLoadPromises = [];
  24345. var getNativeFontPromise = function (nativeFontFace) {
  24346. // Return a promise that is always fulfilled, even when the font fails to
  24347. // load.
  24348. return nativeFontFace.loaded.catch(function (e) {
  24349. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  24350. });
  24351. };
  24352. // Firefox Font Loading API does not work with mozPrintCallback --
  24353. // disabling it in this case.
  24354. var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported && !FontLoader.isSyncFontLoadingSupported;
  24355. for (var i = 0, ii = fonts.length; i < ii; i++) {
  24356. var font = fonts[i];
  24357. // Add the font to the DOM only once or skip if the font
  24358. // is already loaded.
  24359. if (font.attached || font.loading === false) {
  24360. continue;
  24361. }
  24362. font.attached = true;
  24363. if (isFontLoadingAPISupported) {
  24364. var nativeFontFace = font.createNativeFontFace();
  24365. if (nativeFontFace) {
  24366. this.addNativeFontFace(nativeFontFace);
  24367. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  24368. }
  24369. } else {
  24370. var rule = font.createFontFaceRule();
  24371. if (rule) {
  24372. this.insertRule(rule);
  24373. rules.push(rule);
  24374. fontsToLoad.push(font);
  24375. }
  24376. }
  24377. }
  24378. var request = this.queueLoadingCallback(callback);
  24379. if (isFontLoadingAPISupported) {
  24380. Promise.all(fontLoadPromises).then(function () {
  24381. request.complete();
  24382. });
  24383. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  24384. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  24385. } else {
  24386. request.complete();
  24387. }
  24388. };
  24389. FontLoader.prototype.queueLoadingCallback = function FontLoader_queueLoadingCallback(callback) {
  24390. function LoadLoader_completeRequest() {
  24391. assert(!request.end, 'completeRequest() cannot be called twice');
  24392. request.end = Date.now();
  24393. // sending all completed requests in order how they were queued
  24394. while (context.requests.length > 0 && context.requests[0].end) {
  24395. var otherRequest = context.requests.shift();
  24396. setTimeout(otherRequest.callback, 0);
  24397. }
  24398. }
  24399. var context = this.loadingContext;
  24400. var requestId = 'pdfjs-font-loading-' + context.nextRequestId++;
  24401. var request = {
  24402. id: requestId,
  24403. complete: LoadLoader_completeRequest,
  24404. callback: callback,
  24405. started: Date.now()
  24406. };
  24407. context.requests.push(request);
  24408. return request;
  24409. };
  24410. FontLoader.prototype.prepareFontLoadEvent = function fontLoaderPrepareFontLoadEvent(rules, fonts, request) {
  24411. /** Hack begin */
  24412. // There's currently no event when a font has finished downloading so the
  24413. // following code is a dirty hack to 'guess' when a font is
  24414. // ready. It's assumed fonts are loaded in order, so add a known test
  24415. // font after the desired fonts and then test for the loading of that
  24416. // test font.
  24417. function int32(data, offset) {
  24418. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  24419. }
  24420. function spliceString(s, offset, remove, insert) {
  24421. var chunk1 = s.substr(0, offset);
  24422. var chunk2 = s.substr(offset + remove);
  24423. return chunk1 + insert + chunk2;
  24424. }
  24425. var i, ii;
  24426. var canvas = document.createElement('canvas');
  24427. canvas.width = 1;
  24428. canvas.height = 1;
  24429. var ctx = canvas.getContext('2d');
  24430. var called = 0;
  24431. function isFontReady(name, callback) {
  24432. called++;
  24433. // With setTimeout clamping this gives the font ~100ms to load.
  24434. if (called > 30) {
  24435. warn('Load test font never loaded.');
  24436. callback();
  24437. return;
  24438. }
  24439. ctx.font = '30px ' + name;
  24440. ctx.fillText('.', 0, 20);
  24441. var imageData = ctx.getImageData(0, 0, 1, 1);
  24442. if (imageData.data[3] > 0) {
  24443. callback();
  24444. return;
  24445. }
  24446. setTimeout(isFontReady.bind(null, name, callback));
  24447. }
  24448. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  24449. // Chromium seems to cache fonts based on a hash of the actual font data,
  24450. // so the font must be modified for each load test else it will appear to
  24451. // be loaded already.
  24452. // TODO: This could maybe be made faster by avoiding the btoa of the full
  24453. // font by splitting it in chunks before hand and padding the font id.
  24454. var data = this.loadTestFont;
  24455. var COMMENT_OFFSET = 976;
  24456. // has to be on 4 byte boundary (for checksum)
  24457. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  24458. // CFF checksum is important for IE, adjusting it
  24459. var CFF_CHECKSUM_OFFSET = 16;
  24460. var XXXX_VALUE = 0x58585858;
  24461. // the "comment" filled with 'X'
  24462. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  24463. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  24464. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  24465. }
  24466. if (i < loadTestFontId.length) {
  24467. // align to 4 bytes boundary
  24468. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0;
  24469. }
  24470. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  24471. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  24472. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' + url + '}';
  24473. this.insertRule(rule);
  24474. var names = [];
  24475. for (i = 0, ii = fonts.length; i < ii; i++) {
  24476. names.push(fonts[i].loadedName);
  24477. }
  24478. names.push(loadTestFontId);
  24479. var div = document.createElement('div');
  24480. div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;');
  24481. for (i = 0, ii = names.length; i < ii; ++i) {
  24482. var span = document.createElement('span');
  24483. span.textContent = 'Hi';
  24484. span.style.fontFamily = names[i];
  24485. div.appendChild(span);
  24486. }
  24487. document.body.appendChild(div);
  24488. isFontReady(loadTestFontId, function () {
  24489. document.body.removeChild(div);
  24490. request.complete();
  24491. });
  24492. };
  24493. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' && !!document.fonts;
  24494. var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() {
  24495. if (typeof navigator === 'undefined') {
  24496. // node.js - we can pretend sync font loading is supported.
  24497. return true;
  24498. }
  24499. var supported = false;
  24500. // User agent string sniffing is bad, but there is no reliable way to tell
  24501. // if font is fully loaded and ready to be used with canvas.
  24502. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  24503. if (m && m[1] >= 14) {
  24504. supported = true;
  24505. }
  24506. // TODO other browsers
  24507. return supported;
  24508. };
  24509. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  24510. get: function () {
  24511. return shadow(FontLoader, 'isSyncFontLoadingSupported', isSyncFontLoadingSupported());
  24512. },
  24513. enumerable: true,
  24514. configurable: true
  24515. });
  24516. var IsEvalSupportedCached = {
  24517. get value() {
  24518. return shadow(this, 'value', sharedUtil.isEvalSupported());
  24519. }
  24520. };
  24521. var FontFaceObject = function FontFaceObjectClosure() {
  24522. function FontFaceObject(translatedData, options) {
  24523. this.compiledGlyphs = Object.create(null);
  24524. // importing translated data
  24525. for (var i in translatedData) {
  24526. this[i] = translatedData[i];
  24527. }
  24528. this.options = options;
  24529. }
  24530. FontFaceObject.prototype = {
  24531. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  24532. if (!this.data) {
  24533. return null;
  24534. }
  24535. if (this.options.disableFontFace) {
  24536. this.disableFontFace = true;
  24537. return null;
  24538. }
  24539. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  24540. if (this.options.fontRegistry) {
  24541. this.options.fontRegistry.registerFont(this);
  24542. }
  24543. return nativeFontFace;
  24544. },
  24545. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  24546. if (!this.data) {
  24547. return null;
  24548. }
  24549. if (this.options.disableFontFace) {
  24550. this.disableFontFace = true;
  24551. return null;
  24552. }
  24553. var data = bytesToString(new Uint8Array(this.data));
  24554. var fontName = this.loadedName;
  24555. // Add the font-face rule to the document
  24556. var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');';
  24557. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  24558. if (this.options.fontRegistry) {
  24559. this.options.fontRegistry.registerFont(this, url);
  24560. }
  24561. return rule;
  24562. },
  24563. getPathGenerator: function FontFaceObject_getPathGenerator(objs, character) {
  24564. if (!(character in this.compiledGlyphs)) {
  24565. var cmds = objs.get(this.loadedName + '_path_' + character);
  24566. var current, i, len;
  24567. // If we can, compile cmds into JS for MAXIMUM SPEED
  24568. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  24569. var args, js = '';
  24570. for (i = 0, len = cmds.length; i < len; i++) {
  24571. current = cmds[i];
  24572. if (current.args !== undefined) {
  24573. args = current.args.join(',');
  24574. } else {
  24575. args = '';
  24576. }
  24577. js += 'c.' + current.cmd + '(' + args + ');\n';
  24578. }
  24579. this.compiledGlyphs[character] = new Function('c', 'size', js);
  24580. } else {
  24581. // But fall back on using Function.prototype.apply() if we're
  24582. // blocked from using eval() for whatever reason (like CSP policies)
  24583. this.compiledGlyphs[character] = function (c, size) {
  24584. for (i = 0, len = cmds.length; i < len; i++) {
  24585. current = cmds[i];
  24586. if (current.cmd === 'scale') {
  24587. current.args = [
  24588. size,
  24589. -size
  24590. ];
  24591. }
  24592. c[current.cmd].apply(c, current.args);
  24593. }
  24594. };
  24595. }
  24596. }
  24597. return this.compiledGlyphs[character];
  24598. }
  24599. };
  24600. return FontFaceObject;
  24601. }();
  24602. exports.FontFaceObject = FontFaceObject;
  24603. exports.FontLoader = FontLoader;
  24604. }));
  24605. (function (root, factory) {
  24606. factory(root.pdfjsDisplayMetadata = {}, root.pdfjsSharedUtil);
  24607. }(this, function (exports, sharedUtil) {
  24608. var error = sharedUtil.error;
  24609. function fixMetadata(meta) {
  24610. return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  24611. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  24612. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  24613. });
  24614. var chars = '';
  24615. for (var i = 0; i < bytes.length; i += 2) {
  24616. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  24617. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38 && false ? String.fromCharCode(code) : '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  24618. }
  24619. return '>' + chars;
  24620. });
  24621. }
  24622. function Metadata(meta) {
  24623. if (typeof meta === 'string') {
  24624. // Ghostscript produces invalid metadata
  24625. meta = fixMetadata(meta);
  24626. var parser = new DOMParser();
  24627. meta = parser.parseFromString(meta, 'application/xml');
  24628. } else if (!(meta instanceof Document)) {
  24629. error('Metadata: Invalid metadata object');
  24630. }
  24631. this.metaDocument = meta;
  24632. this.metadata = Object.create(null);
  24633. this.parse();
  24634. }
  24635. Metadata.prototype = {
  24636. parse: function Metadata_parse() {
  24637. var doc = this.metaDocument;
  24638. var rdf = doc.documentElement;
  24639. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  24640. // Wrapped in <xmpmeta>
  24641. rdf = rdf.firstChild;
  24642. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  24643. rdf = rdf.nextSibling;
  24644. }
  24645. }
  24646. var nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  24647. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  24648. return;
  24649. }
  24650. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  24651. for (i = 0, length = children.length; i < length; i++) {
  24652. desc = children[i];
  24653. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  24654. continue;
  24655. }
  24656. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  24657. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  24658. entry = desc.childNodes[ii];
  24659. name = entry.nodeName.toLowerCase();
  24660. this.metadata[name] = entry.textContent.trim();
  24661. }
  24662. }
  24663. }
  24664. },
  24665. get: function Metadata_get(name) {
  24666. return this.metadata[name] || null;
  24667. },
  24668. has: function Metadata_has(name) {
  24669. return typeof this.metadata[name] !== 'undefined';
  24670. }
  24671. };
  24672. exports.Metadata = Metadata;
  24673. }));
  24674. (function (root, factory) {
  24675. factory(root.pdfjsDisplaySVG = {}, root.pdfjsSharedUtil);
  24676. }(this, function (exports, sharedUtil) {
  24677. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  24678. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  24679. var ImageKind = sharedUtil.ImageKind;
  24680. var OPS = sharedUtil.OPS;
  24681. var Util = sharedUtil.Util;
  24682. var isNum = sharedUtil.isNum;
  24683. var isArray = sharedUtil.isArray;
  24684. var warn = sharedUtil.warn;
  24685. var createObjectURL = sharedUtil.createObjectURL;
  24686. var SVG_DEFAULTS = {
  24687. fontStyle: 'normal',
  24688. fontWeight: 'normal',
  24689. fillColor: '#000000'
  24690. };
  24691. var convertImgDataToPng = function convertImgDataToPngClosure() {
  24692. var PNG_HEADER = new Uint8Array([
  24693. 0x89,
  24694. 0x50,
  24695. 0x4e,
  24696. 0x47,
  24697. 0x0d,
  24698. 0x0a,
  24699. 0x1a,
  24700. 0x0a
  24701. ]);
  24702. var CHUNK_WRAPPER_SIZE = 12;
  24703. var crcTable = new Int32Array(256);
  24704. for (var i = 0; i < 256; i++) {
  24705. var c = i;
  24706. for (var h = 0; h < 8; h++) {
  24707. if (c & 1) {
  24708. c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
  24709. } else {
  24710. c = c >> 1 & 0x7fffffff;
  24711. }
  24712. }
  24713. crcTable[i] = c;
  24714. }
  24715. function crc32(data, start, end) {
  24716. var crc = -1;
  24717. for (var i = start; i < end; i++) {
  24718. var a = (crc ^ data[i]) & 0xff;
  24719. var b = crcTable[a];
  24720. crc = crc >>> 8 ^ b;
  24721. }
  24722. return crc ^ -1;
  24723. }
  24724. function writePngChunk(type, body, data, offset) {
  24725. var p = offset;
  24726. var len = body.length;
  24727. data[p] = len >> 24 & 0xff;
  24728. data[p + 1] = len >> 16 & 0xff;
  24729. data[p + 2] = len >> 8 & 0xff;
  24730. data[p + 3] = len & 0xff;
  24731. p += 4;
  24732. data[p] = type.charCodeAt(0) & 0xff;
  24733. data[p + 1] = type.charCodeAt(1) & 0xff;
  24734. data[p + 2] = type.charCodeAt(2) & 0xff;
  24735. data[p + 3] = type.charCodeAt(3) & 0xff;
  24736. p += 4;
  24737. data.set(body, p);
  24738. p += body.length;
  24739. var crc = crc32(data, offset + 4, p);
  24740. data[p] = crc >> 24 & 0xff;
  24741. data[p + 1] = crc >> 16 & 0xff;
  24742. data[p + 2] = crc >> 8 & 0xff;
  24743. data[p + 3] = crc & 0xff;
  24744. }
  24745. function adler32(data, start, end) {
  24746. var a = 1;
  24747. var b = 0;
  24748. for (var i = start; i < end; ++i) {
  24749. a = (a + (data[i] & 0xff)) % 65521;
  24750. b = (b + a) % 65521;
  24751. }
  24752. return b << 16 | a;
  24753. }
  24754. function encode(imgData, kind, forceDataSchema) {
  24755. var width = imgData.width;
  24756. var height = imgData.height;
  24757. var bitDepth, colorType, lineSize;
  24758. var bytes = imgData.data;
  24759. switch (kind) {
  24760. case ImageKind.GRAYSCALE_1BPP:
  24761. colorType = 0;
  24762. bitDepth = 1;
  24763. lineSize = width + 7 >> 3;
  24764. break;
  24765. case ImageKind.RGB_24BPP:
  24766. colorType = 2;
  24767. bitDepth = 8;
  24768. lineSize = width * 3;
  24769. break;
  24770. case ImageKind.RGBA_32BPP:
  24771. colorType = 6;
  24772. bitDepth = 8;
  24773. lineSize = width * 4;
  24774. break;
  24775. default:
  24776. throw new Error('invalid format');
  24777. }
  24778. // prefix every row with predictor 0
  24779. var literals = new Uint8Array((1 + lineSize) * height);
  24780. var offsetLiterals = 0, offsetBytes = 0;
  24781. var y, i;
  24782. for (y = 0; y < height; ++y) {
  24783. literals[offsetLiterals++] = 0;
  24784. // no prediction
  24785. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  24786. offsetBytes += lineSize;
  24787. offsetLiterals += lineSize;
  24788. }
  24789. if (kind === ImageKind.GRAYSCALE_1BPP) {
  24790. // inverting for B/W
  24791. offsetLiterals = 0;
  24792. for (y = 0; y < height; y++) {
  24793. offsetLiterals++;
  24794. // skipping predictor
  24795. for (i = 0; i < lineSize; i++) {
  24796. literals[offsetLiterals++] ^= 0xFF;
  24797. }
  24798. }
  24799. }
  24800. var ihdr = new Uint8Array([
  24801. width >> 24 & 0xff,
  24802. width >> 16 & 0xff,
  24803. width >> 8 & 0xff,
  24804. width & 0xff,
  24805. height >> 24 & 0xff,
  24806. height >> 16 & 0xff,
  24807. height >> 8 & 0xff,
  24808. height & 0xff,
  24809. bitDepth,
  24810. // bit depth
  24811. colorType,
  24812. // color type
  24813. 0x00,
  24814. // compression method
  24815. 0x00,
  24816. // filter method
  24817. 0x00
  24818. ]);
  24819. // interlace method
  24820. var len = literals.length;
  24821. var maxBlockLength = 0xFFFF;
  24822. var deflateBlocks = Math.ceil(len / maxBlockLength);
  24823. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  24824. var pi = 0;
  24825. idat[pi++] = 0x78;
  24826. // compression method and flags
  24827. idat[pi++] = 0x9c;
  24828. // flags
  24829. var pos = 0;
  24830. while (len > maxBlockLength) {
  24831. // writing non-final DEFLATE blocks type 0 and length of 65535
  24832. idat[pi++] = 0x00;
  24833. idat[pi++] = 0xff;
  24834. idat[pi++] = 0xff;
  24835. idat[pi++] = 0x00;
  24836. idat[pi++] = 0x00;
  24837. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  24838. pi += maxBlockLength;
  24839. pos += maxBlockLength;
  24840. len -= maxBlockLength;
  24841. }
  24842. // writing non-final DEFLATE blocks type 0
  24843. idat[pi++] = 0x01;
  24844. idat[pi++] = len & 0xff;
  24845. idat[pi++] = len >> 8 & 0xff;
  24846. idat[pi++] = ~len & 0xffff & 0xff;
  24847. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  24848. idat.set(literals.subarray(pos), pi);
  24849. pi += literals.length - pos;
  24850. var adler = adler32(literals, 0, literals.length);
  24851. // checksum
  24852. idat[pi++] = adler >> 24 & 0xff;
  24853. idat[pi++] = adler >> 16 & 0xff;
  24854. idat[pi++] = adler >> 8 & 0xff;
  24855. idat[pi++] = adler & 0xff;
  24856. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  24857. var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  24858. var data = new Uint8Array(pngLength);
  24859. var offset = 0;
  24860. data.set(PNG_HEADER, offset);
  24861. offset += PNG_HEADER.length;
  24862. writePngChunk('IHDR', ihdr, data, offset);
  24863. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  24864. writePngChunk('IDATA', idat, data, offset);
  24865. offset += CHUNK_WRAPPER_SIZE + idat.length;
  24866. writePngChunk('IEND', new Uint8Array(0), data, offset);
  24867. return createObjectURL(data, 'image/png', forceDataSchema);
  24868. }
  24869. return function convertImgDataToPng(imgData, forceDataSchema) {
  24870. var kind = imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind;
  24871. return encode(imgData, kind, forceDataSchema);
  24872. };
  24873. }();
  24874. var SVGExtraState = function SVGExtraStateClosure() {
  24875. function SVGExtraState() {
  24876. this.fontSizeScale = 1;
  24877. this.fontWeight = SVG_DEFAULTS.fontWeight;
  24878. this.fontSize = 0;
  24879. this.textMatrix = IDENTITY_MATRIX;
  24880. this.fontMatrix = FONT_IDENTITY_MATRIX;
  24881. this.leading = 0;
  24882. // Current point (in user coordinates)
  24883. this.x = 0;
  24884. this.y = 0;
  24885. // Start of text line (in text coordinates)
  24886. this.lineX = 0;
  24887. this.lineY = 0;
  24888. // Character and word spacing
  24889. this.charSpacing = 0;
  24890. this.wordSpacing = 0;
  24891. this.textHScale = 1;
  24892. this.textRise = 0;
  24893. // Default foreground and background colors
  24894. this.fillColor = SVG_DEFAULTS.fillColor;
  24895. this.strokeColor = '#000000';
  24896. this.fillAlpha = 1;
  24897. this.strokeAlpha = 1;
  24898. this.lineWidth = 1;
  24899. this.lineJoin = '';
  24900. this.lineCap = '';
  24901. this.miterLimit = 0;
  24902. this.dashArray = [];
  24903. this.dashPhase = 0;
  24904. this.dependencies = [];
  24905. // Clipping
  24906. this.activeClipUrl = null;
  24907. this.clipGroup = null;
  24908. this.maskId = '';
  24909. }
  24910. SVGExtraState.prototype = {
  24911. clone: function SVGExtraState_clone() {
  24912. return Object.create(this);
  24913. },
  24914. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  24915. this.x = x;
  24916. this.y = y;
  24917. }
  24918. };
  24919. return SVGExtraState;
  24920. }();
  24921. var SVGGraphics = function SVGGraphicsClosure() {
  24922. function opListToTree(opList) {
  24923. var opTree = [];
  24924. var tmp = [];
  24925. var opListLen = opList.length;
  24926. for (var x = 0; x < opListLen; x++) {
  24927. if (opList[x].fn === 'save') {
  24928. opTree.push({
  24929. 'fnId': 92,
  24930. 'fn': 'group',
  24931. 'items': []
  24932. });
  24933. tmp.push(opTree);
  24934. opTree = opTree[opTree.length - 1].items;
  24935. continue;
  24936. }
  24937. if (opList[x].fn === 'restore') {
  24938. opTree = tmp.pop();
  24939. } else {
  24940. opTree.push(opList[x]);
  24941. }
  24942. }
  24943. return opTree;
  24944. }
  24945. /**
  24946. * Formats float number.
  24947. * @param value {number} number to format.
  24948. * @returns {string}
  24949. */
  24950. function pf(value) {
  24951. if (value === (value | 0)) {
  24952. // integer number
  24953. return value.toString();
  24954. }
  24955. var s = value.toFixed(10);
  24956. var i = s.length - 1;
  24957. if (s[i] !== '0') {
  24958. return s;
  24959. }
  24960. // removing trailing zeros
  24961. do {
  24962. i--;
  24963. } while (s[i] === '0');
  24964. return s.substr(0, s[i] === '.' ? i : i + 1);
  24965. }
  24966. /**
  24967. * Formats transform matrix. The standard rotation, scale and translate
  24968. * matrices are replaced by their shorter forms, and for identity matrix
  24969. * returns empty string to save the memory.
  24970. * @param m {Array} matrix to format.
  24971. * @returns {string}
  24972. */
  24973. function pm(m) {
  24974. if (m[4] === 0 && m[5] === 0) {
  24975. if (m[1] === 0 && m[2] === 0) {
  24976. if (m[0] === 1 && m[3] === 1) {
  24977. return '';
  24978. }
  24979. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  24980. }
  24981. if (m[0] === m[3] && m[1] === -m[2]) {
  24982. var a = Math.acos(m[0]) * 180 / Math.PI;
  24983. return 'rotate(' + pf(a) + ')';
  24984. }
  24985. } else {
  24986. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  24987. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  24988. }
  24989. }
  24990. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  24991. }
  24992. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  24993. this.current = new SVGExtraState();
  24994. this.transformMatrix = IDENTITY_MATRIX;
  24995. // Graphics state matrix
  24996. this.transformStack = [];
  24997. this.extraStack = [];
  24998. this.commonObjs = commonObjs;
  24999. this.objs = objs;
  25000. this.pendingEOFill = false;
  25001. this.embedFonts = false;
  25002. this.embeddedFonts = Object.create(null);
  25003. this.cssStyle = null;
  25004. this.forceDataSchema = !!forceDataSchema;
  25005. }
  25006. var NS = 'http://www.w3.org/2000/svg';
  25007. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  25008. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  25009. var LINE_CAP_STYLES = [
  25010. 'butt',
  25011. 'round',
  25012. 'square'
  25013. ];
  25014. var LINE_JOIN_STYLES = [
  25015. 'miter',
  25016. 'round',
  25017. 'bevel'
  25018. ];
  25019. var clipCount = 0;
  25020. var maskCount = 0;
  25021. SVGGraphics.prototype = {
  25022. save: function SVGGraphics_save() {
  25023. this.transformStack.push(this.transformMatrix);
  25024. var old = this.current;
  25025. this.extraStack.push(old);
  25026. this.current = old.clone();
  25027. },
  25028. restore: function SVGGraphics_restore() {
  25029. this.transformMatrix = this.transformStack.pop();
  25030. this.current = this.extraStack.pop();
  25031. this.tgrp = null;
  25032. },
  25033. group: function SVGGraphics_group(items) {
  25034. this.save();
  25035. this.executeOpTree(items);
  25036. this.restore();
  25037. },
  25038. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  25039. var fnArray = operatorList.fnArray;
  25040. var fnArrayLen = fnArray.length;
  25041. var argsArray = operatorList.argsArray;
  25042. var self = this;
  25043. for (var i = 0; i < fnArrayLen; i++) {
  25044. if (OPS.dependency === fnArray[i]) {
  25045. var deps = argsArray[i];
  25046. for (var n = 0, nn = deps.length; n < nn; n++) {
  25047. var obj = deps[n];
  25048. var common = obj.substring(0, 2) === 'g_';
  25049. var promise;
  25050. if (common) {
  25051. promise = new Promise(function (resolve) {
  25052. self.commonObjs.get(obj, resolve);
  25053. });
  25054. } else {
  25055. promise = new Promise(function (resolve) {
  25056. self.objs.get(obj, resolve);
  25057. });
  25058. }
  25059. this.current.dependencies.push(promise);
  25060. }
  25061. }
  25062. }
  25063. return Promise.all(this.current.dependencies);
  25064. },
  25065. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  25066. var transformMatrix = [
  25067. a,
  25068. b,
  25069. c,
  25070. d,
  25071. e,
  25072. f
  25073. ];
  25074. this.transformMatrix = Util.transform(this.transformMatrix, transformMatrix);
  25075. this.tgrp = null;
  25076. },
  25077. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  25078. this.viewport = viewport;
  25079. var svgElement = this._initialize(viewport);
  25080. return this.loadDependencies(operatorList).then(function () {
  25081. this.transformMatrix = IDENTITY_MATRIX;
  25082. var opTree = this.convertOpList(operatorList);
  25083. this.executeOpTree(opTree);
  25084. return svgElement;
  25085. }.bind(this));
  25086. },
  25087. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  25088. var argsArray = operatorList.argsArray;
  25089. var fnArray = operatorList.fnArray;
  25090. var fnArrayLen = fnArray.length;
  25091. var REVOPS = [];
  25092. var opList = [];
  25093. for (var op in OPS) {
  25094. REVOPS[OPS[op]] = op;
  25095. }
  25096. for (var x = 0; x < fnArrayLen; x++) {
  25097. var fnId = fnArray[x];
  25098. opList.push({
  25099. 'fnId': fnId,
  25100. 'fn': REVOPS[fnId],
  25101. 'args': argsArray[x]
  25102. });
  25103. }
  25104. return opListToTree(opList);
  25105. },
  25106. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  25107. var opTreeLen = opTree.length;
  25108. for (var x = 0; x < opTreeLen; x++) {
  25109. var fn = opTree[x].fn;
  25110. var fnId = opTree[x].fnId;
  25111. var args = opTree[x].args;
  25112. switch (fnId | 0) {
  25113. case OPS.beginText:
  25114. this.beginText();
  25115. break;
  25116. case OPS.setLeading:
  25117. this.setLeading(args);
  25118. break;
  25119. case OPS.setLeadingMoveText:
  25120. this.setLeadingMoveText(args[0], args[1]);
  25121. break;
  25122. case OPS.setFont:
  25123. this.setFont(args);
  25124. break;
  25125. case OPS.showText:
  25126. this.showText(args[0]);
  25127. break;
  25128. case OPS.showSpacedText:
  25129. this.showText(args[0]);
  25130. break;
  25131. case OPS.endText:
  25132. this.endText();
  25133. break;
  25134. case OPS.moveText:
  25135. this.moveText(args[0], args[1]);
  25136. break;
  25137. case OPS.setCharSpacing:
  25138. this.setCharSpacing(args[0]);
  25139. break;
  25140. case OPS.setWordSpacing:
  25141. this.setWordSpacing(args[0]);
  25142. break;
  25143. case OPS.setHScale:
  25144. this.setHScale(args[0]);
  25145. break;
  25146. case OPS.setTextMatrix:
  25147. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  25148. break;
  25149. case OPS.setLineWidth:
  25150. this.setLineWidth(args[0]);
  25151. break;
  25152. case OPS.setLineJoin:
  25153. this.setLineJoin(args[0]);
  25154. break;
  25155. case OPS.setLineCap:
  25156. this.setLineCap(args[0]);
  25157. break;
  25158. case OPS.setMiterLimit:
  25159. this.setMiterLimit(args[0]);
  25160. break;
  25161. case OPS.setFillRGBColor:
  25162. this.setFillRGBColor(args[0], args[1], args[2]);
  25163. break;
  25164. case OPS.setStrokeRGBColor:
  25165. this.setStrokeRGBColor(args[0], args[1], args[2]);
  25166. break;
  25167. case OPS.setDash:
  25168. this.setDash(args[0], args[1]);
  25169. break;
  25170. case OPS.setGState:
  25171. this.setGState(args[0]);
  25172. break;
  25173. case OPS.fill:
  25174. this.fill();
  25175. break;
  25176. case OPS.eoFill:
  25177. this.eoFill();
  25178. break;
  25179. case OPS.stroke:
  25180. this.stroke();
  25181. break;
  25182. case OPS.fillStroke:
  25183. this.fillStroke();
  25184. break;
  25185. case OPS.eoFillStroke:
  25186. this.eoFillStroke();
  25187. break;
  25188. case OPS.clip:
  25189. this.clip('nonzero');
  25190. break;
  25191. case OPS.eoClip:
  25192. this.clip('evenodd');
  25193. break;
  25194. case OPS.paintSolidColorImageMask:
  25195. this.paintSolidColorImageMask();
  25196. break;
  25197. case OPS.paintJpegXObject:
  25198. this.paintJpegXObject(args[0], args[1], args[2]);
  25199. break;
  25200. case OPS.paintImageXObject:
  25201. this.paintImageXObject(args[0]);
  25202. break;
  25203. case OPS.paintInlineImageXObject:
  25204. this.paintInlineImageXObject(args[0]);
  25205. break;
  25206. case OPS.paintImageMaskXObject:
  25207. this.paintImageMaskXObject(args[0]);
  25208. break;
  25209. case OPS.paintFormXObjectBegin:
  25210. this.paintFormXObjectBegin(args[0], args[1]);
  25211. break;
  25212. case OPS.paintFormXObjectEnd:
  25213. this.paintFormXObjectEnd();
  25214. break;
  25215. case OPS.closePath:
  25216. this.closePath();
  25217. break;
  25218. case OPS.closeStroke:
  25219. this.closeStroke();
  25220. break;
  25221. case OPS.closeFillStroke:
  25222. this.closeFillStroke();
  25223. break;
  25224. case OPS.nextLine:
  25225. this.nextLine();
  25226. break;
  25227. case OPS.transform:
  25228. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  25229. break;
  25230. case OPS.constructPath:
  25231. this.constructPath(args[0], args[1]);
  25232. break;
  25233. case OPS.endPath:
  25234. this.endPath();
  25235. break;
  25236. case 92:
  25237. this.group(opTree[x].items);
  25238. break;
  25239. default:
  25240. warn('Unimplemented operator ' + fn);
  25241. break;
  25242. }
  25243. }
  25244. },
  25245. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  25246. this.current.wordSpacing = wordSpacing;
  25247. },
  25248. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  25249. this.current.charSpacing = charSpacing;
  25250. },
  25251. nextLine: function SVGGraphics_nextLine() {
  25252. this.moveText(0, this.current.leading);
  25253. },
  25254. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  25255. var current = this.current;
  25256. this.current.textMatrix = this.current.lineMatrix = [
  25257. a,
  25258. b,
  25259. c,
  25260. d,
  25261. e,
  25262. f
  25263. ];
  25264. this.current.x = this.current.lineX = 0;
  25265. this.current.y = this.current.lineY = 0;
  25266. current.xcoords = [];
  25267. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25268. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25269. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25270. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25271. current.txtElement = document.createElementNS(NS, 'svg:text');
  25272. current.txtElement.appendChild(current.tspan);
  25273. },
  25274. beginText: function SVGGraphics_beginText() {
  25275. this.current.x = this.current.lineX = 0;
  25276. this.current.y = this.current.lineY = 0;
  25277. this.current.textMatrix = IDENTITY_MATRIX;
  25278. this.current.lineMatrix = IDENTITY_MATRIX;
  25279. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  25280. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  25281. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  25282. this.current.xcoords = [];
  25283. },
  25284. moveText: function SVGGraphics_moveText(x, y) {
  25285. var current = this.current;
  25286. this.current.x = this.current.lineX += x;
  25287. this.current.y = this.current.lineY += y;
  25288. current.xcoords = [];
  25289. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25290. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25291. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25292. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25293. },
  25294. showText: function SVGGraphics_showText(glyphs) {
  25295. var current = this.current;
  25296. var font = current.font;
  25297. var fontSize = current.fontSize;
  25298. if (fontSize === 0) {
  25299. return;
  25300. }
  25301. var charSpacing = current.charSpacing;
  25302. var wordSpacing = current.wordSpacing;
  25303. var fontDirection = current.fontDirection;
  25304. var textHScale = current.textHScale * fontDirection;
  25305. var glyphsLength = glyphs.length;
  25306. var vertical = font.vertical;
  25307. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  25308. var x = 0, i;
  25309. for (i = 0; i < glyphsLength; ++i) {
  25310. var glyph = glyphs[i];
  25311. if (glyph === null) {
  25312. // word break
  25313. x += fontDirection * wordSpacing;
  25314. continue;
  25315. } else if (isNum(glyph)) {
  25316. x += -glyph * fontSize * 0.001;
  25317. continue;
  25318. }
  25319. current.xcoords.push(current.x + x * textHScale);
  25320. var width = glyph.width;
  25321. var character = glyph.fontChar;
  25322. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  25323. x += charWidth;
  25324. current.tspan.textContent += character;
  25325. }
  25326. if (vertical) {
  25327. current.y -= x * textHScale;
  25328. } else {
  25329. current.x += x * textHScale;
  25330. }
  25331. current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
  25332. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25333. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25334. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25335. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  25336. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  25337. }
  25338. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  25339. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  25340. }
  25341. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  25342. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  25343. }
  25344. current.txtElement.setAttributeNS(null, 'transform', pm(current.textMatrix) + ' scale(1, -1)');
  25345. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  25346. current.txtElement.appendChild(current.tspan);
  25347. current.txtgrp.appendChild(current.txtElement);
  25348. this._ensureTransformGroup().appendChild(current.txtElement);
  25349. },
  25350. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  25351. this.setLeading(-y);
  25352. this.moveText(x, y);
  25353. },
  25354. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  25355. if (!this.cssStyle) {
  25356. this.cssStyle = document.createElementNS(NS, 'svg:style');
  25357. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  25358. this.defs.appendChild(this.cssStyle);
  25359. }
  25360. var url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  25361. this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
  25362. },
  25363. setFont: function SVGGraphics_setFont(details) {
  25364. var current = this.current;
  25365. var fontObj = this.commonObjs.get(details[0]);
  25366. var size = details[1];
  25367. this.current.font = fontObj;
  25368. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  25369. this.addFontStyle(fontObj);
  25370. this.embeddedFonts[fontObj.loadedName] = fontObj;
  25371. }
  25372. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX;
  25373. var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  25374. var italic = fontObj.italic ? 'italic' : 'normal';
  25375. if (size < 0) {
  25376. size = -size;
  25377. current.fontDirection = -1;
  25378. } else {
  25379. current.fontDirection = 1;
  25380. }
  25381. current.fontSize = size;
  25382. current.fontFamily = fontObj.loadedName;
  25383. current.fontWeight = bold;
  25384. current.fontStyle = italic;
  25385. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25386. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25387. current.xcoords = [];
  25388. },
  25389. endText: function SVGGraphics_endText() {
  25390. },
  25391. // Path properties
  25392. setLineWidth: function SVGGraphics_setLineWidth(width) {
  25393. this.current.lineWidth = width;
  25394. },
  25395. setLineCap: function SVGGraphics_setLineCap(style) {
  25396. this.current.lineCap = LINE_CAP_STYLES[style];
  25397. },
  25398. setLineJoin: function SVGGraphics_setLineJoin(style) {
  25399. this.current.lineJoin = LINE_JOIN_STYLES[style];
  25400. },
  25401. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  25402. this.current.miterLimit = limit;
  25403. },
  25404. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  25405. var color = Util.makeCssRgb(r, g, b);
  25406. this.current.strokeColor = color;
  25407. },
  25408. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  25409. var color = Util.makeCssRgb(r, g, b);
  25410. this.current.fillColor = color;
  25411. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  25412. this.current.xcoords = [];
  25413. },
  25414. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  25415. this.current.dashArray = dashArray;
  25416. this.current.dashPhase = dashPhase;
  25417. },
  25418. constructPath: function SVGGraphics_constructPath(ops, args) {
  25419. var current = this.current;
  25420. var x = current.x, y = current.y;
  25421. current.path = document.createElementNS(NS, 'svg:path');
  25422. var d = [];
  25423. var opLength = ops.length;
  25424. for (var i = 0, j = 0; i < opLength; i++) {
  25425. switch (ops[i] | 0) {
  25426. case OPS.rectangle:
  25427. x = args[j++];
  25428. y = args[j++];
  25429. var width = args[j++];
  25430. var height = args[j++];
  25431. var xw = x + width;
  25432. var yh = y + height;
  25433. d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
  25434. break;
  25435. case OPS.moveTo:
  25436. x = args[j++];
  25437. y = args[j++];
  25438. d.push('M', pf(x), pf(y));
  25439. break;
  25440. case OPS.lineTo:
  25441. x = args[j++];
  25442. y = args[j++];
  25443. d.push('L', pf(x), pf(y));
  25444. break;
  25445. case OPS.curveTo:
  25446. x = args[j + 4];
  25447. y = args[j + 5];
  25448. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  25449. j += 6;
  25450. break;
  25451. case OPS.curveTo2:
  25452. x = args[j + 2];
  25453. y = args[j + 3];
  25454. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  25455. j += 4;
  25456. break;
  25457. case OPS.curveTo3:
  25458. x = args[j + 2];
  25459. y = args[j + 3];
  25460. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  25461. j += 4;
  25462. break;
  25463. case OPS.closePath:
  25464. d.push('Z');
  25465. break;
  25466. }
  25467. }
  25468. current.path.setAttributeNS(null, 'd', d.join(' '));
  25469. current.path.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
  25470. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  25471. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  25472. current.path.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
  25473. current.path.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
  25474. current.path.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
  25475. current.path.setAttributeNS(null, 'fill', 'none');
  25476. this._ensureTransformGroup().appendChild(current.path);
  25477. // Saving a reference in current.element so that it can be addressed
  25478. // in 'fill' and 'stroke'
  25479. current.element = current.path;
  25480. current.setCurrentPoint(x, y);
  25481. },
  25482. endPath: function SVGGraphics_endPath() {
  25483. },
  25484. clip: function SVGGraphics_clip(type) {
  25485. var current = this.current;
  25486. // Add current path to clipping path
  25487. var clipId = 'clippath' + clipCount;
  25488. clipCount++;
  25489. var clipPath = document.createElementNS(NS, 'svg:clipPath');
  25490. clipPath.setAttributeNS(null, 'id', clipId);
  25491. clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25492. var clipElement = current.element.cloneNode();
  25493. if (type === 'evenodd') {
  25494. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  25495. } else {
  25496. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  25497. }
  25498. clipPath.appendChild(clipElement);
  25499. this.defs.appendChild(clipPath);
  25500. if (current.activeClipUrl) {
  25501. // The previous clipping group content can go out of order -- resetting
  25502. // cached clipGroup's.
  25503. current.clipGroup = null;
  25504. this.extraStack.forEach(function (prev) {
  25505. prev.clipGroup = null;
  25506. });
  25507. }
  25508. current.activeClipUrl = 'url(#' + clipId + ')';
  25509. this.tgrp = null;
  25510. },
  25511. closePath: function SVGGraphics_closePath() {
  25512. var current = this.current;
  25513. var d = current.path.getAttributeNS(null, 'd');
  25514. d += 'Z';
  25515. current.path.setAttributeNS(null, 'd', d);
  25516. },
  25517. setLeading: function SVGGraphics_setLeading(leading) {
  25518. this.current.leading = -leading;
  25519. },
  25520. setTextRise: function SVGGraphics_setTextRise(textRise) {
  25521. this.current.textRise = textRise;
  25522. },
  25523. setHScale: function SVGGraphics_setHScale(scale) {
  25524. this.current.textHScale = scale / 100;
  25525. },
  25526. setGState: function SVGGraphics_setGState(states) {
  25527. for (var i = 0, ii = states.length; i < ii; i++) {
  25528. var state = states[i];
  25529. var key = state[0];
  25530. var value = state[1];
  25531. switch (key) {
  25532. case 'LW':
  25533. this.setLineWidth(value);
  25534. break;
  25535. case 'LC':
  25536. this.setLineCap(value);
  25537. break;
  25538. case 'LJ':
  25539. this.setLineJoin(value);
  25540. break;
  25541. case 'ML':
  25542. this.setMiterLimit(value);
  25543. break;
  25544. case 'D':
  25545. this.setDash(value[0], value[1]);
  25546. break;
  25547. case 'Font':
  25548. this.setFont(value);
  25549. break;
  25550. default:
  25551. warn('Unimplemented graphic state ' + key);
  25552. break;
  25553. }
  25554. }
  25555. },
  25556. fill: function SVGGraphics_fill() {
  25557. var current = this.current;
  25558. current.element.setAttributeNS(null, 'fill', current.fillColor);
  25559. },
  25560. stroke: function SVGGraphics_stroke() {
  25561. var current = this.current;
  25562. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  25563. current.element.setAttributeNS(null, 'fill', 'none');
  25564. },
  25565. eoFill: function SVGGraphics_eoFill() {
  25566. var current = this.current;
  25567. current.element.setAttributeNS(null, 'fill', current.fillColor);
  25568. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  25569. },
  25570. fillStroke: function SVGGraphics_fillStroke() {
  25571. // Order is important since stroke wants fill to be none.
  25572. // First stroke, then if fill needed, it will be overwritten.
  25573. this.stroke();
  25574. this.fill();
  25575. },
  25576. eoFillStroke: function SVGGraphics_eoFillStroke() {
  25577. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  25578. this.fillStroke();
  25579. },
  25580. closeStroke: function SVGGraphics_closeStroke() {
  25581. this.closePath();
  25582. this.stroke();
  25583. },
  25584. closeFillStroke: function SVGGraphics_closeFillStroke() {
  25585. this.closePath();
  25586. this.fillStroke();
  25587. },
  25588. paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
  25589. var current = this.current;
  25590. var rect = document.createElementNS(NS, 'svg:rect');
  25591. rect.setAttributeNS(null, 'x', '0');
  25592. rect.setAttributeNS(null, 'y', '0');
  25593. rect.setAttributeNS(null, 'width', '1px');
  25594. rect.setAttributeNS(null, 'height', '1px');
  25595. rect.setAttributeNS(null, 'fill', current.fillColor);
  25596. this._ensureTransformGroup().appendChild(rect);
  25597. },
  25598. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  25599. var imgObj = this.objs.get(objId);
  25600. var imgEl = document.createElementNS(NS, 'svg:image');
  25601. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  25602. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  25603. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  25604. imgEl.setAttributeNS(null, 'x', '0');
  25605. imgEl.setAttributeNS(null, 'y', pf(-h));
  25606. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  25607. this._ensureTransformGroup().appendChild(imgEl);
  25608. },
  25609. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  25610. var imgData = this.objs.get(objId);
  25611. if (!imgData) {
  25612. warn('Dependent image isn\'t ready yet');
  25613. return;
  25614. }
  25615. this.paintInlineImageXObject(imgData);
  25616. },
  25617. paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  25618. var width = imgData.width;
  25619. var height = imgData.height;
  25620. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  25621. var cliprect = document.createElementNS(NS, 'svg:rect');
  25622. cliprect.setAttributeNS(null, 'x', '0');
  25623. cliprect.setAttributeNS(null, 'y', '0');
  25624. cliprect.setAttributeNS(null, 'width', pf(width));
  25625. cliprect.setAttributeNS(null, 'height', pf(height));
  25626. this.current.element = cliprect;
  25627. this.clip('nonzero');
  25628. var imgEl = document.createElementNS(NS, 'svg:image');
  25629. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  25630. imgEl.setAttributeNS(null, 'x', '0');
  25631. imgEl.setAttributeNS(null, 'y', pf(-height));
  25632. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  25633. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  25634. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
  25635. if (mask) {
  25636. mask.appendChild(imgEl);
  25637. } else {
  25638. this._ensureTransformGroup().appendChild(imgEl);
  25639. }
  25640. },
  25641. paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
  25642. var current = this.current;
  25643. var width = imgData.width;
  25644. var height = imgData.height;
  25645. var fillColor = current.fillColor;
  25646. current.maskId = 'mask' + maskCount++;
  25647. var mask = document.createElementNS(NS, 'svg:mask');
  25648. mask.setAttributeNS(null, 'id', current.maskId);
  25649. var rect = document.createElementNS(NS, 'svg:rect');
  25650. rect.setAttributeNS(null, 'x', '0');
  25651. rect.setAttributeNS(null, 'y', '0');
  25652. rect.setAttributeNS(null, 'width', pf(width));
  25653. rect.setAttributeNS(null, 'height', pf(height));
  25654. rect.setAttributeNS(null, 'fill', fillColor);
  25655. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
  25656. this.defs.appendChild(mask);
  25657. this._ensureTransformGroup().appendChild(rect);
  25658. this.paintInlineImageXObject(imgData, mask);
  25659. },
  25660. paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  25661. if (isArray(matrix) && matrix.length === 6) {
  25662. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  25663. }
  25664. if (isArray(bbox) && bbox.length === 4) {
  25665. var width = bbox[2] - bbox[0];
  25666. var height = bbox[3] - bbox[1];
  25667. var cliprect = document.createElementNS(NS, 'svg:rect');
  25668. cliprect.setAttributeNS(null, 'x', bbox[0]);
  25669. cliprect.setAttributeNS(null, 'y', bbox[1]);
  25670. cliprect.setAttributeNS(null, 'width', pf(width));
  25671. cliprect.setAttributeNS(null, 'height', pf(height));
  25672. this.current.element = cliprect;
  25673. this.clip('nonzero');
  25674. this.endPath();
  25675. }
  25676. },
  25677. paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {
  25678. },
  25679. /**
  25680. * @private
  25681. */
  25682. _initialize: function SVGGraphics_initialize(viewport) {
  25683. // Create the SVG element.
  25684. var svg = document.createElementNS(NS, 'svg:svg');
  25685. svg.setAttributeNS(null, 'version', '1.1');
  25686. svg.setAttributeNS(null, 'width', viewport.width + 'px');
  25687. svg.setAttributeNS(null, 'height', viewport.height + 'px');
  25688. svg.setAttributeNS(null, 'viewBox', '0 0 ' + viewport.width + ' ' + viewport.height);
  25689. // Create the definitions element.
  25690. var definitions = document.createElementNS(NS, 'svg:defs');
  25691. svg.appendChild(definitions);
  25692. this.defs = definitions;
  25693. // Create the root group element, which acts a container for all other
  25694. // groups and applies the viewport transform.
  25695. var rootGroup = document.createElementNS(NS, 'svg:g');
  25696. rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
  25697. svg.appendChild(rootGroup);
  25698. // For the construction of the SVG image we are only interested in the
  25699. // root group, so we expose it as the entry point of the SVG image for
  25700. // the other code in this class.
  25701. this.svg = rootGroup;
  25702. return svg;
  25703. },
  25704. /**
  25705. * @private
  25706. */
  25707. _ensureClipGroup: function SVGGraphics_ensureClipGroup() {
  25708. if (!this.current.clipGroup) {
  25709. var clipGroup = document.createElementNS(NS, 'svg:g');
  25710. clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
  25711. this.svg.appendChild(clipGroup);
  25712. this.current.clipGroup = clipGroup;
  25713. }
  25714. return this.current.clipGroup;
  25715. },
  25716. /**
  25717. * @private
  25718. */
  25719. _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() {
  25720. if (!this.tgrp) {
  25721. this.tgrp = document.createElementNS(NS, 'svg:g');
  25722. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25723. if (this.current.activeClipUrl) {
  25724. this._ensureClipGroup().appendChild(this.tgrp);
  25725. } else {
  25726. this.svg.appendChild(this.tgrp);
  25727. }
  25728. }
  25729. return this.tgrp;
  25730. }
  25731. };
  25732. return SVGGraphics;
  25733. }();
  25734. exports.SVGGraphics = SVGGraphics;
  25735. }));
  25736. (function (root, factory) {
  25737. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  25738. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  25739. var Util = sharedUtil.Util;
  25740. var error = sharedUtil.error;
  25741. var info = sharedUtil.info;
  25742. var isInt = sharedUtil.isInt;
  25743. var isArray = sharedUtil.isArray;
  25744. var createObjectURL = sharedUtil.createObjectURL;
  25745. var shadow = sharedUtil.shadow;
  25746. var warn = sharedUtil.warn;
  25747. var isSpace = sharedUtil.isSpace;
  25748. var Dict = corePrimitives.Dict;
  25749. var isDict = corePrimitives.isDict;
  25750. var isStream = corePrimitives.isStream;
  25751. var Jbig2Image = coreJbig2.Jbig2Image;
  25752. var JpegImage = coreJpg.JpegImage;
  25753. var JpxImage = coreJpx.JpxImage;
  25754. var Stream = function StreamClosure() {
  25755. function Stream(arrayBuffer, start, length, dict) {
  25756. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  25757. this.start = start || 0;
  25758. this.pos = this.start;
  25759. this.end = start + length || this.bytes.length;
  25760. this.dict = dict;
  25761. }
  25762. // required methods for a stream. if a particular stream does not
  25763. // implement these, an error should be thrown
  25764. Stream.prototype = {
  25765. get length() {
  25766. return this.end - this.start;
  25767. },
  25768. get isEmpty() {
  25769. return this.length === 0;
  25770. },
  25771. getByte: function Stream_getByte() {
  25772. if (this.pos >= this.end) {
  25773. return -1;
  25774. }
  25775. return this.bytes[this.pos++];
  25776. },
  25777. getUint16: function Stream_getUint16() {
  25778. var b0 = this.getByte();
  25779. var b1 = this.getByte();
  25780. if (b0 === -1 || b1 === -1) {
  25781. return -1;
  25782. }
  25783. return (b0 << 8) + b1;
  25784. },
  25785. getInt32: function Stream_getInt32() {
  25786. var b0 = this.getByte();
  25787. var b1 = this.getByte();
  25788. var b2 = this.getByte();
  25789. var b3 = this.getByte();
  25790. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25791. },
  25792. // returns subarray of original buffer
  25793. // should only be read
  25794. getBytes: function Stream_getBytes(length) {
  25795. var bytes = this.bytes;
  25796. var pos = this.pos;
  25797. var strEnd = this.end;
  25798. if (!length) {
  25799. return bytes.subarray(pos, strEnd);
  25800. }
  25801. var end = pos + length;
  25802. if (end > strEnd) {
  25803. end = strEnd;
  25804. }
  25805. this.pos = end;
  25806. return bytes.subarray(pos, end);
  25807. },
  25808. peekByte: function Stream_peekByte() {
  25809. var peekedByte = this.getByte();
  25810. this.pos--;
  25811. return peekedByte;
  25812. },
  25813. peekBytes: function Stream_peekBytes(length) {
  25814. var bytes = this.getBytes(length);
  25815. this.pos -= bytes.length;
  25816. return bytes;
  25817. },
  25818. skip: function Stream_skip(n) {
  25819. if (!n) {
  25820. n = 1;
  25821. }
  25822. this.pos += n;
  25823. },
  25824. reset: function Stream_reset() {
  25825. this.pos = this.start;
  25826. },
  25827. moveStart: function Stream_moveStart() {
  25828. this.start = this.pos;
  25829. },
  25830. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  25831. return new Stream(this.bytes.buffer, start, length, dict);
  25832. },
  25833. isStream: true
  25834. };
  25835. return Stream;
  25836. }();
  25837. var StringStream = function StringStreamClosure() {
  25838. function StringStream(str) {
  25839. var length = str.length;
  25840. var bytes = new Uint8Array(length);
  25841. for (var n = 0; n < length; ++n) {
  25842. bytes[n] = str.charCodeAt(n);
  25843. }
  25844. Stream.call(this, bytes);
  25845. }
  25846. StringStream.prototype = Stream.prototype;
  25847. return StringStream;
  25848. }();
  25849. // super class for the decoding streams
  25850. var DecodeStream = function DecodeStreamClosure() {
  25851. // Lots of DecodeStreams are created whose buffers are never used. For these
  25852. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  25853. // having special cases that would be required if we used |null| for an empty
  25854. // buffer.
  25855. var emptyBuffer = new Uint8Array(0);
  25856. function DecodeStream(maybeMinBufferLength) {
  25857. this.pos = 0;
  25858. this.bufferLength = 0;
  25859. this.eof = false;
  25860. this.buffer = emptyBuffer;
  25861. this.minBufferLength = 512;
  25862. if (maybeMinBufferLength) {
  25863. // Compute the first power of two that is as big as maybeMinBufferLength.
  25864. while (this.minBufferLength < maybeMinBufferLength) {
  25865. this.minBufferLength *= 2;
  25866. }
  25867. }
  25868. }
  25869. DecodeStream.prototype = {
  25870. get isEmpty() {
  25871. while (!this.eof && this.bufferLength === 0) {
  25872. this.readBlock();
  25873. }
  25874. return this.bufferLength === 0;
  25875. },
  25876. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  25877. var buffer = this.buffer;
  25878. if (requested <= buffer.byteLength) {
  25879. return buffer;
  25880. }
  25881. var size = this.minBufferLength;
  25882. while (size < requested) {
  25883. size *= 2;
  25884. }
  25885. var buffer2 = new Uint8Array(size);
  25886. buffer2.set(buffer);
  25887. return this.buffer = buffer2;
  25888. },
  25889. getByte: function DecodeStream_getByte() {
  25890. var pos = this.pos;
  25891. while (this.bufferLength <= pos) {
  25892. if (this.eof) {
  25893. return -1;
  25894. }
  25895. this.readBlock();
  25896. }
  25897. return this.buffer[this.pos++];
  25898. },
  25899. getUint16: function DecodeStream_getUint16() {
  25900. var b0 = this.getByte();
  25901. var b1 = this.getByte();
  25902. if (b0 === -1 || b1 === -1) {
  25903. return -1;
  25904. }
  25905. return (b0 << 8) + b1;
  25906. },
  25907. getInt32: function DecodeStream_getInt32() {
  25908. var b0 = this.getByte();
  25909. var b1 = this.getByte();
  25910. var b2 = this.getByte();
  25911. var b3 = this.getByte();
  25912. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25913. },
  25914. getBytes: function DecodeStream_getBytes(length) {
  25915. var end, pos = this.pos;
  25916. if (length) {
  25917. this.ensureBuffer(pos + length);
  25918. end = pos + length;
  25919. while (!this.eof && this.bufferLength < end) {
  25920. this.readBlock();
  25921. }
  25922. var bufEnd = this.bufferLength;
  25923. if (end > bufEnd) {
  25924. end = bufEnd;
  25925. }
  25926. } else {
  25927. while (!this.eof) {
  25928. this.readBlock();
  25929. }
  25930. end = this.bufferLength;
  25931. }
  25932. this.pos = end;
  25933. return this.buffer.subarray(pos, end);
  25934. },
  25935. peekByte: function DecodeStream_peekByte() {
  25936. var peekedByte = this.getByte();
  25937. this.pos--;
  25938. return peekedByte;
  25939. },
  25940. peekBytes: function DecodeStream_peekBytes(length) {
  25941. var bytes = this.getBytes(length);
  25942. this.pos -= bytes.length;
  25943. return bytes;
  25944. },
  25945. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  25946. var end = start + length;
  25947. while (this.bufferLength <= end && !this.eof) {
  25948. this.readBlock();
  25949. }
  25950. return new Stream(this.buffer, start, length, dict);
  25951. },
  25952. skip: function DecodeStream_skip(n) {
  25953. if (!n) {
  25954. n = 1;
  25955. }
  25956. this.pos += n;
  25957. },
  25958. reset: function DecodeStream_reset() {
  25959. this.pos = 0;
  25960. },
  25961. getBaseStreams: function DecodeStream_getBaseStreams() {
  25962. if (this.str && this.str.getBaseStreams) {
  25963. return this.str.getBaseStreams();
  25964. }
  25965. return [];
  25966. }
  25967. };
  25968. return DecodeStream;
  25969. }();
  25970. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  25971. function StreamsSequenceStream(streams) {
  25972. this.streams = streams;
  25973. DecodeStream.call(this, /* maybeLength = */
  25974. null);
  25975. }
  25976. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  25977. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  25978. var streams = this.streams;
  25979. if (streams.length === 0) {
  25980. this.eof = true;
  25981. return;
  25982. }
  25983. var stream = streams.shift();
  25984. var chunk = stream.getBytes();
  25985. var bufferLength = this.bufferLength;
  25986. var newLength = bufferLength + chunk.length;
  25987. var buffer = this.ensureBuffer(newLength);
  25988. buffer.set(chunk, bufferLength);
  25989. this.bufferLength = newLength;
  25990. };
  25991. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  25992. var baseStreams = [];
  25993. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  25994. var stream = this.streams[i];
  25995. if (stream.getBaseStreams) {
  25996. Util.appendToArray(baseStreams, stream.getBaseStreams());
  25997. }
  25998. }
  25999. return baseStreams;
  26000. };
  26001. return StreamsSequenceStream;
  26002. }();
  26003. var FlateStream = function FlateStreamClosure() {
  26004. var codeLenCodeMap = new Int32Array([
  26005. 16,
  26006. 17,
  26007. 18,
  26008. 0,
  26009. 8,
  26010. 7,
  26011. 9,
  26012. 6,
  26013. 10,
  26014. 5,
  26015. 11,
  26016. 4,
  26017. 12,
  26018. 3,
  26019. 13,
  26020. 2,
  26021. 14,
  26022. 1,
  26023. 15
  26024. ]);
  26025. var lengthDecode = new Int32Array([
  26026. 0x00003,
  26027. 0x00004,
  26028. 0x00005,
  26029. 0x00006,
  26030. 0x00007,
  26031. 0x00008,
  26032. 0x00009,
  26033. 0x0000a,
  26034. 0x1000b,
  26035. 0x1000d,
  26036. 0x1000f,
  26037. 0x10011,
  26038. 0x20013,
  26039. 0x20017,
  26040. 0x2001b,
  26041. 0x2001f,
  26042. 0x30023,
  26043. 0x3002b,
  26044. 0x30033,
  26045. 0x3003b,
  26046. 0x40043,
  26047. 0x40053,
  26048. 0x40063,
  26049. 0x40073,
  26050. 0x50083,
  26051. 0x500a3,
  26052. 0x500c3,
  26053. 0x500e3,
  26054. 0x00102,
  26055. 0x00102,
  26056. 0x00102
  26057. ]);
  26058. var distDecode = new Int32Array([
  26059. 0x00001,
  26060. 0x00002,
  26061. 0x00003,
  26062. 0x00004,
  26063. 0x10005,
  26064. 0x10007,
  26065. 0x20009,
  26066. 0x2000d,
  26067. 0x30011,
  26068. 0x30019,
  26069. 0x40021,
  26070. 0x40031,
  26071. 0x50041,
  26072. 0x50061,
  26073. 0x60081,
  26074. 0x600c1,
  26075. 0x70101,
  26076. 0x70181,
  26077. 0x80201,
  26078. 0x80301,
  26079. 0x90401,
  26080. 0x90601,
  26081. 0xa0801,
  26082. 0xa0c01,
  26083. 0xb1001,
  26084. 0xb1801,
  26085. 0xc2001,
  26086. 0xc3001,
  26087. 0xd4001,
  26088. 0xd6001
  26089. ]);
  26090. var fixedLitCodeTab = [
  26091. new Int32Array([
  26092. 0x70100,
  26093. 0x80050,
  26094. 0x80010,
  26095. 0x80118,
  26096. 0x70110,
  26097. 0x80070,
  26098. 0x80030,
  26099. 0x900c0,
  26100. 0x70108,
  26101. 0x80060,
  26102. 0x80020,
  26103. 0x900a0,
  26104. 0x80000,
  26105. 0x80080,
  26106. 0x80040,
  26107. 0x900e0,
  26108. 0x70104,
  26109. 0x80058,
  26110. 0x80018,
  26111. 0x90090,
  26112. 0x70114,
  26113. 0x80078,
  26114. 0x80038,
  26115. 0x900d0,
  26116. 0x7010c,
  26117. 0x80068,
  26118. 0x80028,
  26119. 0x900b0,
  26120. 0x80008,
  26121. 0x80088,
  26122. 0x80048,
  26123. 0x900f0,
  26124. 0x70102,
  26125. 0x80054,
  26126. 0x80014,
  26127. 0x8011c,
  26128. 0x70112,
  26129. 0x80074,
  26130. 0x80034,
  26131. 0x900c8,
  26132. 0x7010a,
  26133. 0x80064,
  26134. 0x80024,
  26135. 0x900a8,
  26136. 0x80004,
  26137. 0x80084,
  26138. 0x80044,
  26139. 0x900e8,
  26140. 0x70106,
  26141. 0x8005c,
  26142. 0x8001c,
  26143. 0x90098,
  26144. 0x70116,
  26145. 0x8007c,
  26146. 0x8003c,
  26147. 0x900d8,
  26148. 0x7010e,
  26149. 0x8006c,
  26150. 0x8002c,
  26151. 0x900b8,
  26152. 0x8000c,
  26153. 0x8008c,
  26154. 0x8004c,
  26155. 0x900f8,
  26156. 0x70101,
  26157. 0x80052,
  26158. 0x80012,
  26159. 0x8011a,
  26160. 0x70111,
  26161. 0x80072,
  26162. 0x80032,
  26163. 0x900c4,
  26164. 0x70109,
  26165. 0x80062,
  26166. 0x80022,
  26167. 0x900a4,
  26168. 0x80002,
  26169. 0x80082,
  26170. 0x80042,
  26171. 0x900e4,
  26172. 0x70105,
  26173. 0x8005a,
  26174. 0x8001a,
  26175. 0x90094,
  26176. 0x70115,
  26177. 0x8007a,
  26178. 0x8003a,
  26179. 0x900d4,
  26180. 0x7010d,
  26181. 0x8006a,
  26182. 0x8002a,
  26183. 0x900b4,
  26184. 0x8000a,
  26185. 0x8008a,
  26186. 0x8004a,
  26187. 0x900f4,
  26188. 0x70103,
  26189. 0x80056,
  26190. 0x80016,
  26191. 0x8011e,
  26192. 0x70113,
  26193. 0x80076,
  26194. 0x80036,
  26195. 0x900cc,
  26196. 0x7010b,
  26197. 0x80066,
  26198. 0x80026,
  26199. 0x900ac,
  26200. 0x80006,
  26201. 0x80086,
  26202. 0x80046,
  26203. 0x900ec,
  26204. 0x70107,
  26205. 0x8005e,
  26206. 0x8001e,
  26207. 0x9009c,
  26208. 0x70117,
  26209. 0x8007e,
  26210. 0x8003e,
  26211. 0x900dc,
  26212. 0x7010f,
  26213. 0x8006e,
  26214. 0x8002e,
  26215. 0x900bc,
  26216. 0x8000e,
  26217. 0x8008e,
  26218. 0x8004e,
  26219. 0x900fc,
  26220. 0x70100,
  26221. 0x80051,
  26222. 0x80011,
  26223. 0x80119,
  26224. 0x70110,
  26225. 0x80071,
  26226. 0x80031,
  26227. 0x900c2,
  26228. 0x70108,
  26229. 0x80061,
  26230. 0x80021,
  26231. 0x900a2,
  26232. 0x80001,
  26233. 0x80081,
  26234. 0x80041,
  26235. 0x900e2,
  26236. 0x70104,
  26237. 0x80059,
  26238. 0x80019,
  26239. 0x90092,
  26240. 0x70114,
  26241. 0x80079,
  26242. 0x80039,
  26243. 0x900d2,
  26244. 0x7010c,
  26245. 0x80069,
  26246. 0x80029,
  26247. 0x900b2,
  26248. 0x80009,
  26249. 0x80089,
  26250. 0x80049,
  26251. 0x900f2,
  26252. 0x70102,
  26253. 0x80055,
  26254. 0x80015,
  26255. 0x8011d,
  26256. 0x70112,
  26257. 0x80075,
  26258. 0x80035,
  26259. 0x900ca,
  26260. 0x7010a,
  26261. 0x80065,
  26262. 0x80025,
  26263. 0x900aa,
  26264. 0x80005,
  26265. 0x80085,
  26266. 0x80045,
  26267. 0x900ea,
  26268. 0x70106,
  26269. 0x8005d,
  26270. 0x8001d,
  26271. 0x9009a,
  26272. 0x70116,
  26273. 0x8007d,
  26274. 0x8003d,
  26275. 0x900da,
  26276. 0x7010e,
  26277. 0x8006d,
  26278. 0x8002d,
  26279. 0x900ba,
  26280. 0x8000d,
  26281. 0x8008d,
  26282. 0x8004d,
  26283. 0x900fa,
  26284. 0x70101,
  26285. 0x80053,
  26286. 0x80013,
  26287. 0x8011b,
  26288. 0x70111,
  26289. 0x80073,
  26290. 0x80033,
  26291. 0x900c6,
  26292. 0x70109,
  26293. 0x80063,
  26294. 0x80023,
  26295. 0x900a6,
  26296. 0x80003,
  26297. 0x80083,
  26298. 0x80043,
  26299. 0x900e6,
  26300. 0x70105,
  26301. 0x8005b,
  26302. 0x8001b,
  26303. 0x90096,
  26304. 0x70115,
  26305. 0x8007b,
  26306. 0x8003b,
  26307. 0x900d6,
  26308. 0x7010d,
  26309. 0x8006b,
  26310. 0x8002b,
  26311. 0x900b6,
  26312. 0x8000b,
  26313. 0x8008b,
  26314. 0x8004b,
  26315. 0x900f6,
  26316. 0x70103,
  26317. 0x80057,
  26318. 0x80017,
  26319. 0x8011f,
  26320. 0x70113,
  26321. 0x80077,
  26322. 0x80037,
  26323. 0x900ce,
  26324. 0x7010b,
  26325. 0x80067,
  26326. 0x80027,
  26327. 0x900ae,
  26328. 0x80007,
  26329. 0x80087,
  26330. 0x80047,
  26331. 0x900ee,
  26332. 0x70107,
  26333. 0x8005f,
  26334. 0x8001f,
  26335. 0x9009e,
  26336. 0x70117,
  26337. 0x8007f,
  26338. 0x8003f,
  26339. 0x900de,
  26340. 0x7010f,
  26341. 0x8006f,
  26342. 0x8002f,
  26343. 0x900be,
  26344. 0x8000f,
  26345. 0x8008f,
  26346. 0x8004f,
  26347. 0x900fe,
  26348. 0x70100,
  26349. 0x80050,
  26350. 0x80010,
  26351. 0x80118,
  26352. 0x70110,
  26353. 0x80070,
  26354. 0x80030,
  26355. 0x900c1,
  26356. 0x70108,
  26357. 0x80060,
  26358. 0x80020,
  26359. 0x900a1,
  26360. 0x80000,
  26361. 0x80080,
  26362. 0x80040,
  26363. 0x900e1,
  26364. 0x70104,
  26365. 0x80058,
  26366. 0x80018,
  26367. 0x90091,
  26368. 0x70114,
  26369. 0x80078,
  26370. 0x80038,
  26371. 0x900d1,
  26372. 0x7010c,
  26373. 0x80068,
  26374. 0x80028,
  26375. 0x900b1,
  26376. 0x80008,
  26377. 0x80088,
  26378. 0x80048,
  26379. 0x900f1,
  26380. 0x70102,
  26381. 0x80054,
  26382. 0x80014,
  26383. 0x8011c,
  26384. 0x70112,
  26385. 0x80074,
  26386. 0x80034,
  26387. 0x900c9,
  26388. 0x7010a,
  26389. 0x80064,
  26390. 0x80024,
  26391. 0x900a9,
  26392. 0x80004,
  26393. 0x80084,
  26394. 0x80044,
  26395. 0x900e9,
  26396. 0x70106,
  26397. 0x8005c,
  26398. 0x8001c,
  26399. 0x90099,
  26400. 0x70116,
  26401. 0x8007c,
  26402. 0x8003c,
  26403. 0x900d9,
  26404. 0x7010e,
  26405. 0x8006c,
  26406. 0x8002c,
  26407. 0x900b9,
  26408. 0x8000c,
  26409. 0x8008c,
  26410. 0x8004c,
  26411. 0x900f9,
  26412. 0x70101,
  26413. 0x80052,
  26414. 0x80012,
  26415. 0x8011a,
  26416. 0x70111,
  26417. 0x80072,
  26418. 0x80032,
  26419. 0x900c5,
  26420. 0x70109,
  26421. 0x80062,
  26422. 0x80022,
  26423. 0x900a5,
  26424. 0x80002,
  26425. 0x80082,
  26426. 0x80042,
  26427. 0x900e5,
  26428. 0x70105,
  26429. 0x8005a,
  26430. 0x8001a,
  26431. 0x90095,
  26432. 0x70115,
  26433. 0x8007a,
  26434. 0x8003a,
  26435. 0x900d5,
  26436. 0x7010d,
  26437. 0x8006a,
  26438. 0x8002a,
  26439. 0x900b5,
  26440. 0x8000a,
  26441. 0x8008a,
  26442. 0x8004a,
  26443. 0x900f5,
  26444. 0x70103,
  26445. 0x80056,
  26446. 0x80016,
  26447. 0x8011e,
  26448. 0x70113,
  26449. 0x80076,
  26450. 0x80036,
  26451. 0x900cd,
  26452. 0x7010b,
  26453. 0x80066,
  26454. 0x80026,
  26455. 0x900ad,
  26456. 0x80006,
  26457. 0x80086,
  26458. 0x80046,
  26459. 0x900ed,
  26460. 0x70107,
  26461. 0x8005e,
  26462. 0x8001e,
  26463. 0x9009d,
  26464. 0x70117,
  26465. 0x8007e,
  26466. 0x8003e,
  26467. 0x900dd,
  26468. 0x7010f,
  26469. 0x8006e,
  26470. 0x8002e,
  26471. 0x900bd,
  26472. 0x8000e,
  26473. 0x8008e,
  26474. 0x8004e,
  26475. 0x900fd,
  26476. 0x70100,
  26477. 0x80051,
  26478. 0x80011,
  26479. 0x80119,
  26480. 0x70110,
  26481. 0x80071,
  26482. 0x80031,
  26483. 0x900c3,
  26484. 0x70108,
  26485. 0x80061,
  26486. 0x80021,
  26487. 0x900a3,
  26488. 0x80001,
  26489. 0x80081,
  26490. 0x80041,
  26491. 0x900e3,
  26492. 0x70104,
  26493. 0x80059,
  26494. 0x80019,
  26495. 0x90093,
  26496. 0x70114,
  26497. 0x80079,
  26498. 0x80039,
  26499. 0x900d3,
  26500. 0x7010c,
  26501. 0x80069,
  26502. 0x80029,
  26503. 0x900b3,
  26504. 0x80009,
  26505. 0x80089,
  26506. 0x80049,
  26507. 0x900f3,
  26508. 0x70102,
  26509. 0x80055,
  26510. 0x80015,
  26511. 0x8011d,
  26512. 0x70112,
  26513. 0x80075,
  26514. 0x80035,
  26515. 0x900cb,
  26516. 0x7010a,
  26517. 0x80065,
  26518. 0x80025,
  26519. 0x900ab,
  26520. 0x80005,
  26521. 0x80085,
  26522. 0x80045,
  26523. 0x900eb,
  26524. 0x70106,
  26525. 0x8005d,
  26526. 0x8001d,
  26527. 0x9009b,
  26528. 0x70116,
  26529. 0x8007d,
  26530. 0x8003d,
  26531. 0x900db,
  26532. 0x7010e,
  26533. 0x8006d,
  26534. 0x8002d,
  26535. 0x900bb,
  26536. 0x8000d,
  26537. 0x8008d,
  26538. 0x8004d,
  26539. 0x900fb,
  26540. 0x70101,
  26541. 0x80053,
  26542. 0x80013,
  26543. 0x8011b,
  26544. 0x70111,
  26545. 0x80073,
  26546. 0x80033,
  26547. 0x900c7,
  26548. 0x70109,
  26549. 0x80063,
  26550. 0x80023,
  26551. 0x900a7,
  26552. 0x80003,
  26553. 0x80083,
  26554. 0x80043,
  26555. 0x900e7,
  26556. 0x70105,
  26557. 0x8005b,
  26558. 0x8001b,
  26559. 0x90097,
  26560. 0x70115,
  26561. 0x8007b,
  26562. 0x8003b,
  26563. 0x900d7,
  26564. 0x7010d,
  26565. 0x8006b,
  26566. 0x8002b,
  26567. 0x900b7,
  26568. 0x8000b,
  26569. 0x8008b,
  26570. 0x8004b,
  26571. 0x900f7,
  26572. 0x70103,
  26573. 0x80057,
  26574. 0x80017,
  26575. 0x8011f,
  26576. 0x70113,
  26577. 0x80077,
  26578. 0x80037,
  26579. 0x900cf,
  26580. 0x7010b,
  26581. 0x80067,
  26582. 0x80027,
  26583. 0x900af,
  26584. 0x80007,
  26585. 0x80087,
  26586. 0x80047,
  26587. 0x900ef,
  26588. 0x70107,
  26589. 0x8005f,
  26590. 0x8001f,
  26591. 0x9009f,
  26592. 0x70117,
  26593. 0x8007f,
  26594. 0x8003f,
  26595. 0x900df,
  26596. 0x7010f,
  26597. 0x8006f,
  26598. 0x8002f,
  26599. 0x900bf,
  26600. 0x8000f,
  26601. 0x8008f,
  26602. 0x8004f,
  26603. 0x900ff
  26604. ]),
  26605. 9
  26606. ];
  26607. var fixedDistCodeTab = [
  26608. new Int32Array([
  26609. 0x50000,
  26610. 0x50010,
  26611. 0x50008,
  26612. 0x50018,
  26613. 0x50004,
  26614. 0x50014,
  26615. 0x5000c,
  26616. 0x5001c,
  26617. 0x50002,
  26618. 0x50012,
  26619. 0x5000a,
  26620. 0x5001a,
  26621. 0x50006,
  26622. 0x50016,
  26623. 0x5000e,
  26624. 0x00000,
  26625. 0x50001,
  26626. 0x50011,
  26627. 0x50009,
  26628. 0x50019,
  26629. 0x50005,
  26630. 0x50015,
  26631. 0x5000d,
  26632. 0x5001d,
  26633. 0x50003,
  26634. 0x50013,
  26635. 0x5000b,
  26636. 0x5001b,
  26637. 0x50007,
  26638. 0x50017,
  26639. 0x5000f,
  26640. 0x00000
  26641. ]),
  26642. 5
  26643. ];
  26644. function FlateStream(str, maybeLength) {
  26645. this.str = str;
  26646. this.dict = str.dict;
  26647. var cmf = str.getByte();
  26648. var flg = str.getByte();
  26649. if (cmf === -1 || flg === -1) {
  26650. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  26651. }
  26652. if ((cmf & 0x0f) !== 0x08) {
  26653. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  26654. }
  26655. if (((cmf << 8) + flg) % 31 !== 0) {
  26656. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  26657. }
  26658. if (flg & 0x20) {
  26659. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  26660. }
  26661. this.codeSize = 0;
  26662. this.codeBuf = 0;
  26663. DecodeStream.call(this, maybeLength);
  26664. }
  26665. FlateStream.prototype = Object.create(DecodeStream.prototype);
  26666. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  26667. var str = this.str;
  26668. var codeSize = this.codeSize;
  26669. var codeBuf = this.codeBuf;
  26670. var b;
  26671. while (codeSize < bits) {
  26672. if ((b = str.getByte()) === -1) {
  26673. error('Bad encoding in flate stream');
  26674. }
  26675. codeBuf |= b << codeSize;
  26676. codeSize += 8;
  26677. }
  26678. b = codeBuf & (1 << bits) - 1;
  26679. this.codeBuf = codeBuf >> bits;
  26680. this.codeSize = codeSize -= bits;
  26681. return b;
  26682. };
  26683. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  26684. var str = this.str;
  26685. var codes = table[0];
  26686. var maxLen = table[1];
  26687. var codeSize = this.codeSize;
  26688. var codeBuf = this.codeBuf;
  26689. var b;
  26690. while (codeSize < maxLen) {
  26691. if ((b = str.getByte()) === -1) {
  26692. // premature end of stream. code might however still be valid.
  26693. // codeSize < codeLen check below guards against incomplete codeVal.
  26694. break;
  26695. }
  26696. codeBuf |= b << codeSize;
  26697. codeSize += 8;
  26698. }
  26699. var code = codes[codeBuf & (1 << maxLen) - 1];
  26700. var codeLen = code >> 16;
  26701. var codeVal = code & 0xffff;
  26702. if (codeLen < 1 || codeSize < codeLen) {
  26703. error('Bad encoding in flate stream');
  26704. }
  26705. this.codeBuf = codeBuf >> codeLen;
  26706. this.codeSize = codeSize - codeLen;
  26707. return codeVal;
  26708. };
  26709. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  26710. var n = lengths.length;
  26711. // find max code length
  26712. var maxLen = 0;
  26713. var i;
  26714. for (i = 0; i < n; ++i) {
  26715. if (lengths[i] > maxLen) {
  26716. maxLen = lengths[i];
  26717. }
  26718. }
  26719. // build the table
  26720. var size = 1 << maxLen;
  26721. var codes = new Int32Array(size);
  26722. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  26723. for (var val = 0; val < n; ++val) {
  26724. if (lengths[val] === len) {
  26725. // bit-reverse the code
  26726. var code2 = 0;
  26727. var t = code;
  26728. for (i = 0; i < len; ++i) {
  26729. code2 = code2 << 1 | t & 1;
  26730. t >>= 1;
  26731. }
  26732. // fill the table entries
  26733. for (i = code2; i < size; i += skip) {
  26734. codes[i] = len << 16 | val;
  26735. }
  26736. ++code;
  26737. }
  26738. }
  26739. }
  26740. return [
  26741. codes,
  26742. maxLen
  26743. ];
  26744. };
  26745. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  26746. var buffer, len;
  26747. var str = this.str;
  26748. // read block header
  26749. var hdr = this.getBits(3);
  26750. if (hdr & 1) {
  26751. this.eof = true;
  26752. }
  26753. hdr >>= 1;
  26754. if (hdr === 0) {
  26755. // uncompressed block
  26756. var b;
  26757. if ((b = str.getByte()) === -1) {
  26758. error('Bad block header in flate stream');
  26759. }
  26760. var blockLen = b;
  26761. if ((b = str.getByte()) === -1) {
  26762. error('Bad block header in flate stream');
  26763. }
  26764. blockLen |= b << 8;
  26765. if ((b = str.getByte()) === -1) {
  26766. error('Bad block header in flate stream');
  26767. }
  26768. var check = b;
  26769. if ((b = str.getByte()) === -1) {
  26770. error('Bad block header in flate stream');
  26771. }
  26772. check |= b << 8;
  26773. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  26774. // Ignoring error for bad "empty" block (see issue 1277)
  26775. error('Bad uncompressed block length in flate stream');
  26776. }
  26777. this.codeBuf = 0;
  26778. this.codeSize = 0;
  26779. var bufferLength = this.bufferLength;
  26780. buffer = this.ensureBuffer(bufferLength + blockLen);
  26781. var end = bufferLength + blockLen;
  26782. this.bufferLength = end;
  26783. if (blockLen === 0) {
  26784. if (str.peekByte() === -1) {
  26785. this.eof = true;
  26786. }
  26787. } else {
  26788. for (var n = bufferLength; n < end; ++n) {
  26789. if ((b = str.getByte()) === -1) {
  26790. this.eof = true;
  26791. break;
  26792. }
  26793. buffer[n] = b;
  26794. }
  26795. }
  26796. return;
  26797. }
  26798. var litCodeTable;
  26799. var distCodeTable;
  26800. if (hdr === 1) {
  26801. // compressed block, fixed codes
  26802. litCodeTable = fixedLitCodeTab;
  26803. distCodeTable = fixedDistCodeTab;
  26804. } else if (hdr === 2) {
  26805. // compressed block, dynamic codes
  26806. var numLitCodes = this.getBits(5) + 257;
  26807. var numDistCodes = this.getBits(5) + 1;
  26808. var numCodeLenCodes = this.getBits(4) + 4;
  26809. // build the code lengths code table
  26810. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  26811. var i;
  26812. for (i = 0; i < numCodeLenCodes; ++i) {
  26813. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  26814. }
  26815. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  26816. // build the literal and distance code tables
  26817. len = 0;
  26818. i = 0;
  26819. var codes = numLitCodes + numDistCodes;
  26820. var codeLengths = new Uint8Array(codes);
  26821. var bitsLength, bitsOffset, what;
  26822. while (i < codes) {
  26823. var code = this.getCode(codeLenCodeTab);
  26824. if (code === 16) {
  26825. bitsLength = 2;
  26826. bitsOffset = 3;
  26827. what = len;
  26828. } else if (code === 17) {
  26829. bitsLength = 3;
  26830. bitsOffset = 3;
  26831. what = len = 0;
  26832. } else if (code === 18) {
  26833. bitsLength = 7;
  26834. bitsOffset = 11;
  26835. what = len = 0;
  26836. } else {
  26837. codeLengths[i++] = len = code;
  26838. continue;
  26839. }
  26840. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  26841. while (repeatLength-- > 0) {
  26842. codeLengths[i++] = what;
  26843. }
  26844. }
  26845. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  26846. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  26847. } else {
  26848. error('Unknown block type in flate stream');
  26849. }
  26850. buffer = this.buffer;
  26851. var limit = buffer ? buffer.length : 0;
  26852. var pos = this.bufferLength;
  26853. while (true) {
  26854. var code1 = this.getCode(litCodeTable);
  26855. if (code1 < 256) {
  26856. if (pos + 1 >= limit) {
  26857. buffer = this.ensureBuffer(pos + 1);
  26858. limit = buffer.length;
  26859. }
  26860. buffer[pos++] = code1;
  26861. continue;
  26862. }
  26863. if (code1 === 256) {
  26864. this.bufferLength = pos;
  26865. return;
  26866. }
  26867. code1 -= 257;
  26868. code1 = lengthDecode[code1];
  26869. var code2 = code1 >> 16;
  26870. if (code2 > 0) {
  26871. code2 = this.getBits(code2);
  26872. }
  26873. len = (code1 & 0xffff) + code2;
  26874. code1 = this.getCode(distCodeTable);
  26875. code1 = distDecode[code1];
  26876. code2 = code1 >> 16;
  26877. if (code2 > 0) {
  26878. code2 = this.getBits(code2);
  26879. }
  26880. var dist = (code1 & 0xffff) + code2;
  26881. if (pos + len >= limit) {
  26882. buffer = this.ensureBuffer(pos + len);
  26883. limit = buffer.length;
  26884. }
  26885. for (var k = 0; k < len; ++k, ++pos) {
  26886. buffer[pos] = buffer[pos - dist];
  26887. }
  26888. }
  26889. };
  26890. return FlateStream;
  26891. }();
  26892. var PredictorStream = function PredictorStreamClosure() {
  26893. function PredictorStream(str, maybeLength, params) {
  26894. if (!isDict(params)) {
  26895. return str;
  26896. }
  26897. // no prediction
  26898. var predictor = this.predictor = params.get('Predictor') || 1;
  26899. if (predictor <= 1) {
  26900. return str;
  26901. }
  26902. // no prediction
  26903. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  26904. error('Unsupported predictor: ' + predictor);
  26905. }
  26906. if (predictor === 2) {
  26907. this.readBlock = this.readBlockTiff;
  26908. } else {
  26909. this.readBlock = this.readBlockPng;
  26910. }
  26911. this.str = str;
  26912. this.dict = str.dict;
  26913. var colors = this.colors = params.get('Colors') || 1;
  26914. var bits = this.bits = params.get('BitsPerComponent') || 8;
  26915. var columns = this.columns = params.get('Columns') || 1;
  26916. this.pixBytes = colors * bits + 7 >> 3;
  26917. this.rowBytes = columns * colors * bits + 7 >> 3;
  26918. DecodeStream.call(this, maybeLength);
  26919. return this;
  26920. }
  26921. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  26922. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  26923. var rowBytes = this.rowBytes;
  26924. var bufferLength = this.bufferLength;
  26925. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  26926. var bits = this.bits;
  26927. var colors = this.colors;
  26928. var rawBytes = this.str.getBytes(rowBytes);
  26929. this.eof = !rawBytes.length;
  26930. if (this.eof) {
  26931. return;
  26932. }
  26933. var inbuf = 0, outbuf = 0;
  26934. var inbits = 0, outbits = 0;
  26935. var pos = bufferLength;
  26936. var i;
  26937. if (bits === 1) {
  26938. for (i = 0; i < rowBytes; ++i) {
  26939. var c = rawBytes[i];
  26940. inbuf = inbuf << 8 | c;
  26941. // bitwise addition is exclusive or
  26942. // first shift inbuf and then add
  26943. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  26944. // truncate inbuf (assumes colors < 16)
  26945. inbuf &= 0xFFFF;
  26946. }
  26947. } else if (bits === 8) {
  26948. for (i = 0; i < colors; ++i) {
  26949. buffer[pos++] = rawBytes[i];
  26950. }
  26951. for (; i < rowBytes; ++i) {
  26952. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  26953. pos++;
  26954. }
  26955. } else {
  26956. var compArray = new Uint8Array(colors + 1);
  26957. var bitMask = (1 << bits) - 1;
  26958. var j = 0, k = bufferLength;
  26959. var columns = this.columns;
  26960. for (i = 0; i < columns; ++i) {
  26961. for (var kk = 0; kk < colors; ++kk) {
  26962. if (inbits < bits) {
  26963. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  26964. inbits += 8;
  26965. }
  26966. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  26967. inbits -= bits;
  26968. outbuf = outbuf << bits | compArray[kk];
  26969. outbits += bits;
  26970. if (outbits >= 8) {
  26971. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  26972. outbits -= 8;
  26973. }
  26974. }
  26975. }
  26976. if (outbits > 0) {
  26977. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  26978. }
  26979. }
  26980. this.bufferLength += rowBytes;
  26981. };
  26982. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  26983. var rowBytes = this.rowBytes;
  26984. var pixBytes = this.pixBytes;
  26985. var predictor = this.str.getByte();
  26986. var rawBytes = this.str.getBytes(rowBytes);
  26987. this.eof = !rawBytes.length;
  26988. if (this.eof) {
  26989. return;
  26990. }
  26991. var bufferLength = this.bufferLength;
  26992. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  26993. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  26994. if (prevRow.length === 0) {
  26995. prevRow = new Uint8Array(rowBytes);
  26996. }
  26997. var i, j = bufferLength, up, c;
  26998. switch (predictor) {
  26999. case 0:
  27000. for (i = 0; i < rowBytes; ++i) {
  27001. buffer[j++] = rawBytes[i];
  27002. }
  27003. break;
  27004. case 1:
  27005. for (i = 0; i < pixBytes; ++i) {
  27006. buffer[j++] = rawBytes[i];
  27007. }
  27008. for (; i < rowBytes; ++i) {
  27009. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  27010. j++;
  27011. }
  27012. break;
  27013. case 2:
  27014. for (i = 0; i < rowBytes; ++i) {
  27015. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  27016. }
  27017. break;
  27018. case 3:
  27019. for (i = 0; i < pixBytes; ++i) {
  27020. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  27021. }
  27022. for (; i < rowBytes; ++i) {
  27023. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  27024. j++;
  27025. }
  27026. break;
  27027. case 4:
  27028. // we need to save the up left pixels values. the simplest way
  27029. // is to create a new buffer
  27030. for (i = 0; i < pixBytes; ++i) {
  27031. up = prevRow[i];
  27032. c = rawBytes[i];
  27033. buffer[j++] = up + c;
  27034. }
  27035. for (; i < rowBytes; ++i) {
  27036. up = prevRow[i];
  27037. var upLeft = prevRow[i - pixBytes];
  27038. var left = buffer[j - pixBytes];
  27039. var p = left + up - upLeft;
  27040. var pa = p - left;
  27041. if (pa < 0) {
  27042. pa = -pa;
  27043. }
  27044. var pb = p - up;
  27045. if (pb < 0) {
  27046. pb = -pb;
  27047. }
  27048. var pc = p - upLeft;
  27049. if (pc < 0) {
  27050. pc = -pc;
  27051. }
  27052. c = rawBytes[i];
  27053. if (pa <= pb && pa <= pc) {
  27054. buffer[j++] = left + c;
  27055. } else if (pb <= pc) {
  27056. buffer[j++] = up + c;
  27057. } else {
  27058. buffer[j++] = upLeft + c;
  27059. }
  27060. }
  27061. break;
  27062. default:
  27063. error('Unsupported predictor: ' + predictor);
  27064. }
  27065. this.bufferLength += rowBytes;
  27066. };
  27067. return PredictorStream;
  27068. }();
  27069. /**
  27070. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  27071. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  27072. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  27073. * a library to decode these images and the stream behaves like all the other
  27074. * DecodeStreams.
  27075. */
  27076. var JpegStream = function JpegStreamClosure() {
  27077. function JpegStream(stream, maybeLength, dict, params) {
  27078. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  27079. // Note: this seems to mainly affect inline images.
  27080. var ch;
  27081. while ((ch = stream.getByte()) !== -1) {
  27082. if (ch === 0xFF) {
  27083. // Find the first byte of the SOI marker (0xFFD8).
  27084. stream.skip(-1);
  27085. // Reset the stream position to the SOI.
  27086. break;
  27087. }
  27088. }
  27089. this.stream = stream;
  27090. this.maybeLength = maybeLength;
  27091. this.dict = dict;
  27092. this.params = params;
  27093. DecodeStream.call(this, maybeLength);
  27094. }
  27095. JpegStream.prototype = Object.create(DecodeStream.prototype);
  27096. Object.defineProperty(JpegStream.prototype, 'bytes', {
  27097. get: function JpegStream_bytes() {
  27098. // If this.maybeLength is null, we'll get the entire stream.
  27099. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27100. },
  27101. configurable: true
  27102. });
  27103. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  27104. if (this.bufferLength) {
  27105. return;
  27106. }
  27107. var jpegImage = new JpegImage();
  27108. // Checking if values need to be transformed before conversion.
  27109. var decodeArr = this.dict.getArray('Decode', 'D');
  27110. if (this.forceRGB && isArray(decodeArr)) {
  27111. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  27112. var decodeArrLength = decodeArr.length;
  27113. var transform = new Int32Array(decodeArrLength);
  27114. var transformNeeded = false;
  27115. var maxValue = (1 << bitsPerComponent) - 1;
  27116. for (var i = 0; i < decodeArrLength; i += 2) {
  27117. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  27118. transform[i + 1] = decodeArr[i] * maxValue | 0;
  27119. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  27120. transformNeeded = true;
  27121. }
  27122. }
  27123. if (transformNeeded) {
  27124. jpegImage.decodeTransform = transform;
  27125. }
  27126. }
  27127. // Fetching the 'ColorTransform' entry, if it exists.
  27128. if (isDict(this.params)) {
  27129. var colorTransform = this.params.get('ColorTransform');
  27130. if (isInt(colorTransform)) {
  27131. jpegImage.colorTransform = colorTransform;
  27132. }
  27133. }
  27134. jpegImage.parse(this.bytes);
  27135. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  27136. this.buffer = data;
  27137. this.bufferLength = data.length;
  27138. this.eof = true;
  27139. };
  27140. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  27141. this.ensureBuffer();
  27142. return this.buffer;
  27143. };
  27144. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  27145. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  27146. };
  27147. return JpegStream;
  27148. }();
  27149. /**
  27150. * For JPEG 2000's we use a library to decode these images and
  27151. * the stream behaves like all the other DecodeStreams.
  27152. */
  27153. var JpxStream = function JpxStreamClosure() {
  27154. function JpxStream(stream, maybeLength, dict, params) {
  27155. this.stream = stream;
  27156. this.maybeLength = maybeLength;
  27157. this.dict = dict;
  27158. this.params = params;
  27159. DecodeStream.call(this, maybeLength);
  27160. }
  27161. JpxStream.prototype = Object.create(DecodeStream.prototype);
  27162. Object.defineProperty(JpxStream.prototype, 'bytes', {
  27163. get: function JpxStream_bytes() {
  27164. // If this.maybeLength is null, we'll get the entire stream.
  27165. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27166. },
  27167. configurable: true
  27168. });
  27169. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  27170. if (this.bufferLength) {
  27171. return;
  27172. }
  27173. var jpxImage = new JpxImage();
  27174. jpxImage.parse(this.bytes);
  27175. var width = jpxImage.width;
  27176. var height = jpxImage.height;
  27177. var componentsCount = jpxImage.componentsCount;
  27178. var tileCount = jpxImage.tiles.length;
  27179. if (tileCount === 1) {
  27180. this.buffer = jpxImage.tiles[0].items;
  27181. } else {
  27182. var data = new Uint8Array(width * height * componentsCount);
  27183. for (var k = 0; k < tileCount; k++) {
  27184. var tileComponents = jpxImage.tiles[k];
  27185. var tileWidth = tileComponents.width;
  27186. var tileHeight = tileComponents.height;
  27187. var tileLeft = tileComponents.left;
  27188. var tileTop = tileComponents.top;
  27189. var src = tileComponents.items;
  27190. var srcPosition = 0;
  27191. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  27192. var imgRowSize = width * componentsCount;
  27193. var tileRowSize = tileWidth * componentsCount;
  27194. for (var j = 0; j < tileHeight; j++) {
  27195. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  27196. data.set(rowBytes, dataPosition);
  27197. srcPosition += tileRowSize;
  27198. dataPosition += imgRowSize;
  27199. }
  27200. }
  27201. this.buffer = data;
  27202. }
  27203. this.bufferLength = this.buffer.length;
  27204. this.eof = true;
  27205. };
  27206. return JpxStream;
  27207. }();
  27208. /**
  27209. * For JBIG2's we use a library to decode these images and
  27210. * the stream behaves like all the other DecodeStreams.
  27211. */
  27212. var Jbig2Stream = function Jbig2StreamClosure() {
  27213. function Jbig2Stream(stream, maybeLength, dict, params) {
  27214. this.stream = stream;
  27215. this.maybeLength = maybeLength;
  27216. this.dict = dict;
  27217. this.params = params;
  27218. DecodeStream.call(this, maybeLength);
  27219. }
  27220. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  27221. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  27222. get: function Jbig2Stream_bytes() {
  27223. // If this.maybeLength is null, we'll get the entire stream.
  27224. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27225. },
  27226. configurable: true
  27227. });
  27228. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  27229. if (this.bufferLength) {
  27230. return;
  27231. }
  27232. var jbig2Image = new Jbig2Image();
  27233. var chunks = [];
  27234. if (isDict(this.params)) {
  27235. var globalsStream = this.params.get('JBIG2Globals');
  27236. if (isStream(globalsStream)) {
  27237. var globals = globalsStream.getBytes();
  27238. chunks.push({
  27239. data: globals,
  27240. start: 0,
  27241. end: globals.length
  27242. });
  27243. }
  27244. }
  27245. chunks.push({
  27246. data: this.bytes,
  27247. start: 0,
  27248. end: this.bytes.length
  27249. });
  27250. var data = jbig2Image.parseChunks(chunks);
  27251. var dataLength = data.length;
  27252. // JBIG2 had black as 1 and white as 0, inverting the colors
  27253. for (var i = 0; i < dataLength; i++) {
  27254. data[i] ^= 0xFF;
  27255. }
  27256. this.buffer = data;
  27257. this.bufferLength = dataLength;
  27258. this.eof = true;
  27259. };
  27260. return Jbig2Stream;
  27261. }();
  27262. var DecryptStream = function DecryptStreamClosure() {
  27263. function DecryptStream(str, maybeLength, decrypt) {
  27264. this.str = str;
  27265. this.dict = str.dict;
  27266. this.decrypt = decrypt;
  27267. this.nextChunk = null;
  27268. this.initialized = false;
  27269. DecodeStream.call(this, maybeLength);
  27270. }
  27271. var chunkSize = 512;
  27272. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  27273. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  27274. var chunk;
  27275. if (this.initialized) {
  27276. chunk = this.nextChunk;
  27277. } else {
  27278. chunk = this.str.getBytes(chunkSize);
  27279. this.initialized = true;
  27280. }
  27281. if (!chunk || chunk.length === 0) {
  27282. this.eof = true;
  27283. return;
  27284. }
  27285. this.nextChunk = this.str.getBytes(chunkSize);
  27286. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  27287. var decrypt = this.decrypt;
  27288. chunk = decrypt(chunk, !hasMoreData);
  27289. var bufferLength = this.bufferLength;
  27290. var i, n = chunk.length;
  27291. var buffer = this.ensureBuffer(bufferLength + n);
  27292. for (i = 0; i < n; i++) {
  27293. buffer[bufferLength++] = chunk[i];
  27294. }
  27295. this.bufferLength = bufferLength;
  27296. };
  27297. return DecryptStream;
  27298. }();
  27299. var Ascii85Stream = function Ascii85StreamClosure() {
  27300. function Ascii85Stream(str, maybeLength) {
  27301. this.str = str;
  27302. this.dict = str.dict;
  27303. this.input = new Uint8Array(5);
  27304. // Most streams increase in size when decoded, but Ascii85 streams
  27305. // typically shrink by ~20%.
  27306. if (maybeLength) {
  27307. maybeLength = 0.8 * maybeLength;
  27308. }
  27309. DecodeStream.call(this, maybeLength);
  27310. }
  27311. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  27312. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  27313. var TILDA_CHAR = 0x7E;
  27314. // '~'
  27315. var Z_LOWER_CHAR = 0x7A;
  27316. // 'z'
  27317. var EOF = -1;
  27318. var str = this.str;
  27319. var c = str.getByte();
  27320. while (isSpace(c)) {
  27321. c = str.getByte();
  27322. }
  27323. if (c === EOF || c === TILDA_CHAR) {
  27324. this.eof = true;
  27325. return;
  27326. }
  27327. var bufferLength = this.bufferLength, buffer;
  27328. var i;
  27329. // special code for z
  27330. if (c === Z_LOWER_CHAR) {
  27331. buffer = this.ensureBuffer(bufferLength + 4);
  27332. for (i = 0; i < 4; ++i) {
  27333. buffer[bufferLength + i] = 0;
  27334. }
  27335. this.bufferLength += 4;
  27336. } else {
  27337. var input = this.input;
  27338. input[0] = c;
  27339. for (i = 1; i < 5; ++i) {
  27340. c = str.getByte();
  27341. while (isSpace(c)) {
  27342. c = str.getByte();
  27343. }
  27344. input[i] = c;
  27345. if (c === EOF || c === TILDA_CHAR) {
  27346. break;
  27347. }
  27348. }
  27349. buffer = this.ensureBuffer(bufferLength + i - 1);
  27350. this.bufferLength += i - 1;
  27351. // partial ending;
  27352. if (i < 5) {
  27353. for (; i < 5; ++i) {
  27354. input[i] = 0x21 + 84;
  27355. }
  27356. this.eof = true;
  27357. }
  27358. var t = 0;
  27359. for (i = 0; i < 5; ++i) {
  27360. t = t * 85 + (input[i] - 0x21);
  27361. }
  27362. for (i = 3; i >= 0; --i) {
  27363. buffer[bufferLength + i] = t & 0xFF;
  27364. t >>= 8;
  27365. }
  27366. }
  27367. };
  27368. return Ascii85Stream;
  27369. }();
  27370. var AsciiHexStream = function AsciiHexStreamClosure() {
  27371. function AsciiHexStream(str, maybeLength) {
  27372. this.str = str;
  27373. this.dict = str.dict;
  27374. this.firstDigit = -1;
  27375. // Most streams increase in size when decoded, but AsciiHex streams shrink
  27376. // by 50%.
  27377. if (maybeLength) {
  27378. maybeLength = 0.5 * maybeLength;
  27379. }
  27380. DecodeStream.call(this, maybeLength);
  27381. }
  27382. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  27383. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  27384. var UPSTREAM_BLOCK_SIZE = 8000;
  27385. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  27386. if (!bytes.length) {
  27387. this.eof = true;
  27388. return;
  27389. }
  27390. var maxDecodeLength = bytes.length + 1 >> 1;
  27391. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  27392. var bufferLength = this.bufferLength;
  27393. var firstDigit = this.firstDigit;
  27394. for (var i = 0, ii = bytes.length; i < ii; i++) {
  27395. var ch = bytes[i], digit;
  27396. if (ch >= 0x30 && ch <= 0x39) {
  27397. // '0'-'9'
  27398. digit = ch & 0x0F;
  27399. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  27400. // 'A'-'Z', 'a'-'z'
  27401. digit = (ch & 0x0F) + 9;
  27402. } else if (ch === 0x3E) {
  27403. // '>'
  27404. this.eof = true;
  27405. break;
  27406. } else {
  27407. // probably whitespace
  27408. continue;
  27409. }
  27410. // ignoring
  27411. if (firstDigit < 0) {
  27412. firstDigit = digit;
  27413. } else {
  27414. buffer[bufferLength++] = firstDigit << 4 | digit;
  27415. firstDigit = -1;
  27416. }
  27417. }
  27418. if (firstDigit >= 0 && this.eof) {
  27419. // incomplete byte
  27420. buffer[bufferLength++] = firstDigit << 4;
  27421. firstDigit = -1;
  27422. }
  27423. this.firstDigit = firstDigit;
  27424. this.bufferLength = bufferLength;
  27425. };
  27426. return AsciiHexStream;
  27427. }();
  27428. var RunLengthStream = function RunLengthStreamClosure() {
  27429. function RunLengthStream(str, maybeLength) {
  27430. this.str = str;
  27431. this.dict = str.dict;
  27432. DecodeStream.call(this, maybeLength);
  27433. }
  27434. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  27435. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  27436. // The repeatHeader has following format. The first byte defines type of run
  27437. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  27438. // (in addition to the second byte from the header), n = 129 through 255 -
  27439. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  27440. var repeatHeader = this.str.getBytes(2);
  27441. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  27442. this.eof = true;
  27443. return;
  27444. }
  27445. var buffer;
  27446. var bufferLength = this.bufferLength;
  27447. var n = repeatHeader[0];
  27448. if (n < 128) {
  27449. // copy n bytes
  27450. buffer = this.ensureBuffer(bufferLength + n + 1);
  27451. buffer[bufferLength++] = repeatHeader[1];
  27452. if (n > 0) {
  27453. var source = this.str.getBytes(n);
  27454. buffer.set(source, bufferLength);
  27455. bufferLength += n;
  27456. }
  27457. } else {
  27458. n = 257 - n;
  27459. var b = repeatHeader[1];
  27460. buffer = this.ensureBuffer(bufferLength + n + 1);
  27461. for (var i = 0; i < n; i++) {
  27462. buffer[bufferLength++] = b;
  27463. }
  27464. }
  27465. this.bufferLength = bufferLength;
  27466. };
  27467. return RunLengthStream;
  27468. }();
  27469. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  27470. var ccittEOL = -2;
  27471. var ccittEOF = -1;
  27472. var twoDimPass = 0;
  27473. var twoDimHoriz = 1;
  27474. var twoDimVert0 = 2;
  27475. var twoDimVertR1 = 3;
  27476. var twoDimVertL1 = 4;
  27477. var twoDimVertR2 = 5;
  27478. var twoDimVertL2 = 6;
  27479. var twoDimVertR3 = 7;
  27480. var twoDimVertL3 = 8;
  27481. var twoDimTable = [
  27482. [
  27483. -1,
  27484. -1
  27485. ],
  27486. [
  27487. -1,
  27488. -1
  27489. ],
  27490. // 000000x
  27491. [
  27492. 7,
  27493. twoDimVertL3
  27494. ],
  27495. // 0000010
  27496. [
  27497. 7,
  27498. twoDimVertR3
  27499. ],
  27500. // 0000011
  27501. [
  27502. 6,
  27503. twoDimVertL2
  27504. ],
  27505. [
  27506. 6,
  27507. twoDimVertL2
  27508. ],
  27509. // 000010x
  27510. [
  27511. 6,
  27512. twoDimVertR2
  27513. ],
  27514. [
  27515. 6,
  27516. twoDimVertR2
  27517. ],
  27518. // 000011x
  27519. [
  27520. 4,
  27521. twoDimPass
  27522. ],
  27523. [
  27524. 4,
  27525. twoDimPass
  27526. ],
  27527. // 0001xxx
  27528. [
  27529. 4,
  27530. twoDimPass
  27531. ],
  27532. [
  27533. 4,
  27534. twoDimPass
  27535. ],
  27536. [
  27537. 4,
  27538. twoDimPass
  27539. ],
  27540. [
  27541. 4,
  27542. twoDimPass
  27543. ],
  27544. [
  27545. 4,
  27546. twoDimPass
  27547. ],
  27548. [
  27549. 4,
  27550. twoDimPass
  27551. ],
  27552. [
  27553. 3,
  27554. twoDimHoriz
  27555. ],
  27556. [
  27557. 3,
  27558. twoDimHoriz
  27559. ],
  27560. // 001xxxx
  27561. [
  27562. 3,
  27563. twoDimHoriz
  27564. ],
  27565. [
  27566. 3,
  27567. twoDimHoriz
  27568. ],
  27569. [
  27570. 3,
  27571. twoDimHoriz
  27572. ],
  27573. [
  27574. 3,
  27575. twoDimHoriz
  27576. ],
  27577. [
  27578. 3,
  27579. twoDimHoriz
  27580. ],
  27581. [
  27582. 3,
  27583. twoDimHoriz
  27584. ],
  27585. [
  27586. 3,
  27587. twoDimHoriz
  27588. ],
  27589. [
  27590. 3,
  27591. twoDimHoriz
  27592. ],
  27593. [
  27594. 3,
  27595. twoDimHoriz
  27596. ],
  27597. [
  27598. 3,
  27599. twoDimHoriz
  27600. ],
  27601. [
  27602. 3,
  27603. twoDimHoriz
  27604. ],
  27605. [
  27606. 3,
  27607. twoDimHoriz
  27608. ],
  27609. [
  27610. 3,
  27611. twoDimHoriz
  27612. ],
  27613. [
  27614. 3,
  27615. twoDimHoriz
  27616. ],
  27617. [
  27618. 3,
  27619. twoDimVertL1
  27620. ],
  27621. [
  27622. 3,
  27623. twoDimVertL1
  27624. ],
  27625. // 010xxxx
  27626. [
  27627. 3,
  27628. twoDimVertL1
  27629. ],
  27630. [
  27631. 3,
  27632. twoDimVertL1
  27633. ],
  27634. [
  27635. 3,
  27636. twoDimVertL1
  27637. ],
  27638. [
  27639. 3,
  27640. twoDimVertL1
  27641. ],
  27642. [
  27643. 3,
  27644. twoDimVertL1
  27645. ],
  27646. [
  27647. 3,
  27648. twoDimVertL1
  27649. ],
  27650. [
  27651. 3,
  27652. twoDimVertL1
  27653. ],
  27654. [
  27655. 3,
  27656. twoDimVertL1
  27657. ],
  27658. [
  27659. 3,
  27660. twoDimVertL1
  27661. ],
  27662. [
  27663. 3,
  27664. twoDimVertL1
  27665. ],
  27666. [
  27667. 3,
  27668. twoDimVertL1
  27669. ],
  27670. [
  27671. 3,
  27672. twoDimVertL1
  27673. ],
  27674. [
  27675. 3,
  27676. twoDimVertL1
  27677. ],
  27678. [
  27679. 3,
  27680. twoDimVertL1
  27681. ],
  27682. [
  27683. 3,
  27684. twoDimVertR1
  27685. ],
  27686. [
  27687. 3,
  27688. twoDimVertR1
  27689. ],
  27690. // 011xxxx
  27691. [
  27692. 3,
  27693. twoDimVertR1
  27694. ],
  27695. [
  27696. 3,
  27697. twoDimVertR1
  27698. ],
  27699. [
  27700. 3,
  27701. twoDimVertR1
  27702. ],
  27703. [
  27704. 3,
  27705. twoDimVertR1
  27706. ],
  27707. [
  27708. 3,
  27709. twoDimVertR1
  27710. ],
  27711. [
  27712. 3,
  27713. twoDimVertR1
  27714. ],
  27715. [
  27716. 3,
  27717. twoDimVertR1
  27718. ],
  27719. [
  27720. 3,
  27721. twoDimVertR1
  27722. ],
  27723. [
  27724. 3,
  27725. twoDimVertR1
  27726. ],
  27727. [
  27728. 3,
  27729. twoDimVertR1
  27730. ],
  27731. [
  27732. 3,
  27733. twoDimVertR1
  27734. ],
  27735. [
  27736. 3,
  27737. twoDimVertR1
  27738. ],
  27739. [
  27740. 3,
  27741. twoDimVertR1
  27742. ],
  27743. [
  27744. 3,
  27745. twoDimVertR1
  27746. ],
  27747. [
  27748. 1,
  27749. twoDimVert0
  27750. ],
  27751. [
  27752. 1,
  27753. twoDimVert0
  27754. ],
  27755. // 1xxxxxx
  27756. [
  27757. 1,
  27758. twoDimVert0
  27759. ],
  27760. [
  27761. 1,
  27762. twoDimVert0
  27763. ],
  27764. [
  27765. 1,
  27766. twoDimVert0
  27767. ],
  27768. [
  27769. 1,
  27770. twoDimVert0
  27771. ],
  27772. [
  27773. 1,
  27774. twoDimVert0
  27775. ],
  27776. [
  27777. 1,
  27778. twoDimVert0
  27779. ],
  27780. [
  27781. 1,
  27782. twoDimVert0
  27783. ],
  27784. [
  27785. 1,
  27786. twoDimVert0
  27787. ],
  27788. [
  27789. 1,
  27790. twoDimVert0
  27791. ],
  27792. [
  27793. 1,
  27794. twoDimVert0
  27795. ],
  27796. [
  27797. 1,
  27798. twoDimVert0
  27799. ],
  27800. [
  27801. 1,
  27802. twoDimVert0
  27803. ],
  27804. [
  27805. 1,
  27806. twoDimVert0
  27807. ],
  27808. [
  27809. 1,
  27810. twoDimVert0
  27811. ],
  27812. [
  27813. 1,
  27814. twoDimVert0
  27815. ],
  27816. [
  27817. 1,
  27818. twoDimVert0
  27819. ],
  27820. [
  27821. 1,
  27822. twoDimVert0
  27823. ],
  27824. [
  27825. 1,
  27826. twoDimVert0
  27827. ],
  27828. [
  27829. 1,
  27830. twoDimVert0
  27831. ],
  27832. [
  27833. 1,
  27834. twoDimVert0
  27835. ],
  27836. [
  27837. 1,
  27838. twoDimVert0
  27839. ],
  27840. [
  27841. 1,
  27842. twoDimVert0
  27843. ],
  27844. [
  27845. 1,
  27846. twoDimVert0
  27847. ],
  27848. [
  27849. 1,
  27850. twoDimVert0
  27851. ],
  27852. [
  27853. 1,
  27854. twoDimVert0
  27855. ],
  27856. [
  27857. 1,
  27858. twoDimVert0
  27859. ],
  27860. [
  27861. 1,
  27862. twoDimVert0
  27863. ],
  27864. [
  27865. 1,
  27866. twoDimVert0
  27867. ],
  27868. [
  27869. 1,
  27870. twoDimVert0
  27871. ],
  27872. [
  27873. 1,
  27874. twoDimVert0
  27875. ],
  27876. [
  27877. 1,
  27878. twoDimVert0
  27879. ],
  27880. [
  27881. 1,
  27882. twoDimVert0
  27883. ],
  27884. [
  27885. 1,
  27886. twoDimVert0
  27887. ],
  27888. [
  27889. 1,
  27890. twoDimVert0
  27891. ],
  27892. [
  27893. 1,
  27894. twoDimVert0
  27895. ],
  27896. [
  27897. 1,
  27898. twoDimVert0
  27899. ],
  27900. [
  27901. 1,
  27902. twoDimVert0
  27903. ],
  27904. [
  27905. 1,
  27906. twoDimVert0
  27907. ],
  27908. [
  27909. 1,
  27910. twoDimVert0
  27911. ],
  27912. [
  27913. 1,
  27914. twoDimVert0
  27915. ],
  27916. [
  27917. 1,
  27918. twoDimVert0
  27919. ],
  27920. [
  27921. 1,
  27922. twoDimVert0
  27923. ],
  27924. [
  27925. 1,
  27926. twoDimVert0
  27927. ],
  27928. [
  27929. 1,
  27930. twoDimVert0
  27931. ],
  27932. [
  27933. 1,
  27934. twoDimVert0
  27935. ],
  27936. [
  27937. 1,
  27938. twoDimVert0
  27939. ],
  27940. [
  27941. 1,
  27942. twoDimVert0
  27943. ],
  27944. [
  27945. 1,
  27946. twoDimVert0
  27947. ],
  27948. [
  27949. 1,
  27950. twoDimVert0
  27951. ],
  27952. [
  27953. 1,
  27954. twoDimVert0
  27955. ],
  27956. [
  27957. 1,
  27958. twoDimVert0
  27959. ],
  27960. [
  27961. 1,
  27962. twoDimVert0
  27963. ],
  27964. [
  27965. 1,
  27966. twoDimVert0
  27967. ],
  27968. [
  27969. 1,
  27970. twoDimVert0
  27971. ],
  27972. [
  27973. 1,
  27974. twoDimVert0
  27975. ],
  27976. [
  27977. 1,
  27978. twoDimVert0
  27979. ],
  27980. [
  27981. 1,
  27982. twoDimVert0
  27983. ],
  27984. [
  27985. 1,
  27986. twoDimVert0
  27987. ],
  27988. [
  27989. 1,
  27990. twoDimVert0
  27991. ],
  27992. [
  27993. 1,
  27994. twoDimVert0
  27995. ],
  27996. [
  27997. 1,
  27998. twoDimVert0
  27999. ],
  28000. [
  28001. 1,
  28002. twoDimVert0
  28003. ]
  28004. ];
  28005. var whiteTable1 = [
  28006. [
  28007. -1,
  28008. -1
  28009. ],
  28010. // 00000
  28011. [
  28012. 12,
  28013. ccittEOL
  28014. ],
  28015. // 00001
  28016. [
  28017. -1,
  28018. -1
  28019. ],
  28020. [
  28021. -1,
  28022. -1
  28023. ],
  28024. // 0001x
  28025. [
  28026. -1,
  28027. -1
  28028. ],
  28029. [
  28030. -1,
  28031. -1
  28032. ],
  28033. [
  28034. -1,
  28035. -1
  28036. ],
  28037. [
  28038. -1,
  28039. -1
  28040. ],
  28041. // 001xx
  28042. [
  28043. -1,
  28044. -1
  28045. ],
  28046. [
  28047. -1,
  28048. -1
  28049. ],
  28050. [
  28051. -1,
  28052. -1
  28053. ],
  28054. [
  28055. -1,
  28056. -1
  28057. ],
  28058. // 010xx
  28059. [
  28060. -1,
  28061. -1
  28062. ],
  28063. [
  28064. -1,
  28065. -1
  28066. ],
  28067. [
  28068. -1,
  28069. -1
  28070. ],
  28071. [
  28072. -1,
  28073. -1
  28074. ],
  28075. // 011xx
  28076. [
  28077. 11,
  28078. 1792
  28079. ],
  28080. [
  28081. 11,
  28082. 1792
  28083. ],
  28084. // 1000x
  28085. [
  28086. 12,
  28087. 1984
  28088. ],
  28089. // 10010
  28090. [
  28091. 12,
  28092. 2048
  28093. ],
  28094. // 10011
  28095. [
  28096. 12,
  28097. 2112
  28098. ],
  28099. // 10100
  28100. [
  28101. 12,
  28102. 2176
  28103. ],
  28104. // 10101
  28105. [
  28106. 12,
  28107. 2240
  28108. ],
  28109. // 10110
  28110. [
  28111. 12,
  28112. 2304
  28113. ],
  28114. // 10111
  28115. [
  28116. 11,
  28117. 1856
  28118. ],
  28119. [
  28120. 11,
  28121. 1856
  28122. ],
  28123. // 1100x
  28124. [
  28125. 11,
  28126. 1920
  28127. ],
  28128. [
  28129. 11,
  28130. 1920
  28131. ],
  28132. // 1101x
  28133. [
  28134. 12,
  28135. 2368
  28136. ],
  28137. // 11100
  28138. [
  28139. 12,
  28140. 2432
  28141. ],
  28142. // 11101
  28143. [
  28144. 12,
  28145. 2496
  28146. ],
  28147. // 11110
  28148. [
  28149. 12,
  28150. 2560
  28151. ]
  28152. ];
  28153. // 11111
  28154. var whiteTable2 = [
  28155. [
  28156. -1,
  28157. -1
  28158. ],
  28159. [
  28160. -1,
  28161. -1
  28162. ],
  28163. [
  28164. -1,
  28165. -1
  28166. ],
  28167. [
  28168. -1,
  28169. -1
  28170. ],
  28171. // 0000000xx
  28172. [
  28173. 8,
  28174. 29
  28175. ],
  28176. [
  28177. 8,
  28178. 29
  28179. ],
  28180. // 00000010x
  28181. [
  28182. 8,
  28183. 30
  28184. ],
  28185. [
  28186. 8,
  28187. 30
  28188. ],
  28189. // 00000011x
  28190. [
  28191. 8,
  28192. 45
  28193. ],
  28194. [
  28195. 8,
  28196. 45
  28197. ],
  28198. // 00000100x
  28199. [
  28200. 8,
  28201. 46
  28202. ],
  28203. [
  28204. 8,
  28205. 46
  28206. ],
  28207. // 00000101x
  28208. [
  28209. 7,
  28210. 22
  28211. ],
  28212. [
  28213. 7,
  28214. 22
  28215. ],
  28216. [
  28217. 7,
  28218. 22
  28219. ],
  28220. [
  28221. 7,
  28222. 22
  28223. ],
  28224. // 0000011xx
  28225. [
  28226. 7,
  28227. 23
  28228. ],
  28229. [
  28230. 7,
  28231. 23
  28232. ],
  28233. [
  28234. 7,
  28235. 23
  28236. ],
  28237. [
  28238. 7,
  28239. 23
  28240. ],
  28241. // 0000100xx
  28242. [
  28243. 8,
  28244. 47
  28245. ],
  28246. [
  28247. 8,
  28248. 47
  28249. ],
  28250. // 00001010x
  28251. [
  28252. 8,
  28253. 48
  28254. ],
  28255. [
  28256. 8,
  28257. 48
  28258. ],
  28259. // 00001011x
  28260. [
  28261. 6,
  28262. 13
  28263. ],
  28264. [
  28265. 6,
  28266. 13
  28267. ],
  28268. [
  28269. 6,
  28270. 13
  28271. ],
  28272. [
  28273. 6,
  28274. 13
  28275. ],
  28276. // 000011xxx
  28277. [
  28278. 6,
  28279. 13
  28280. ],
  28281. [
  28282. 6,
  28283. 13
  28284. ],
  28285. [
  28286. 6,
  28287. 13
  28288. ],
  28289. [
  28290. 6,
  28291. 13
  28292. ],
  28293. [
  28294. 7,
  28295. 20
  28296. ],
  28297. [
  28298. 7,
  28299. 20
  28300. ],
  28301. [
  28302. 7,
  28303. 20
  28304. ],
  28305. [
  28306. 7,
  28307. 20
  28308. ],
  28309. // 0001000xx
  28310. [
  28311. 8,
  28312. 33
  28313. ],
  28314. [
  28315. 8,
  28316. 33
  28317. ],
  28318. // 00010010x
  28319. [
  28320. 8,
  28321. 34
  28322. ],
  28323. [
  28324. 8,
  28325. 34
  28326. ],
  28327. // 00010011x
  28328. [
  28329. 8,
  28330. 35
  28331. ],
  28332. [
  28333. 8,
  28334. 35
  28335. ],
  28336. // 00010100x
  28337. [
  28338. 8,
  28339. 36
  28340. ],
  28341. [
  28342. 8,
  28343. 36
  28344. ],
  28345. // 00010101x
  28346. [
  28347. 8,
  28348. 37
  28349. ],
  28350. [
  28351. 8,
  28352. 37
  28353. ],
  28354. // 00010110x
  28355. [
  28356. 8,
  28357. 38
  28358. ],
  28359. [
  28360. 8,
  28361. 38
  28362. ],
  28363. // 00010111x
  28364. [
  28365. 7,
  28366. 19
  28367. ],
  28368. [
  28369. 7,
  28370. 19
  28371. ],
  28372. [
  28373. 7,
  28374. 19
  28375. ],
  28376. [
  28377. 7,
  28378. 19
  28379. ],
  28380. // 0001100xx
  28381. [
  28382. 8,
  28383. 31
  28384. ],
  28385. [
  28386. 8,
  28387. 31
  28388. ],
  28389. // 00011010x
  28390. [
  28391. 8,
  28392. 32
  28393. ],
  28394. [
  28395. 8,
  28396. 32
  28397. ],
  28398. // 00011011x
  28399. [
  28400. 6,
  28401. 1
  28402. ],
  28403. [
  28404. 6,
  28405. 1
  28406. ],
  28407. [
  28408. 6,
  28409. 1
  28410. ],
  28411. [
  28412. 6,
  28413. 1
  28414. ],
  28415. // 000111xxx
  28416. [
  28417. 6,
  28418. 1
  28419. ],
  28420. [
  28421. 6,
  28422. 1
  28423. ],
  28424. [
  28425. 6,
  28426. 1
  28427. ],
  28428. [
  28429. 6,
  28430. 1
  28431. ],
  28432. [
  28433. 6,
  28434. 12
  28435. ],
  28436. [
  28437. 6,
  28438. 12
  28439. ],
  28440. [
  28441. 6,
  28442. 12
  28443. ],
  28444. [
  28445. 6,
  28446. 12
  28447. ],
  28448. // 001000xxx
  28449. [
  28450. 6,
  28451. 12
  28452. ],
  28453. [
  28454. 6,
  28455. 12
  28456. ],
  28457. [
  28458. 6,
  28459. 12
  28460. ],
  28461. [
  28462. 6,
  28463. 12
  28464. ],
  28465. [
  28466. 8,
  28467. 53
  28468. ],
  28469. [
  28470. 8,
  28471. 53
  28472. ],
  28473. // 00100100x
  28474. [
  28475. 8,
  28476. 54
  28477. ],
  28478. [
  28479. 8,
  28480. 54
  28481. ],
  28482. // 00100101x
  28483. [
  28484. 7,
  28485. 26
  28486. ],
  28487. [
  28488. 7,
  28489. 26
  28490. ],
  28491. [
  28492. 7,
  28493. 26
  28494. ],
  28495. [
  28496. 7,
  28497. 26
  28498. ],
  28499. // 0010011xx
  28500. [
  28501. 8,
  28502. 39
  28503. ],
  28504. [
  28505. 8,
  28506. 39
  28507. ],
  28508. // 00101000x
  28509. [
  28510. 8,
  28511. 40
  28512. ],
  28513. [
  28514. 8,
  28515. 40
  28516. ],
  28517. // 00101001x
  28518. [
  28519. 8,
  28520. 41
  28521. ],
  28522. [
  28523. 8,
  28524. 41
  28525. ],
  28526. // 00101010x
  28527. [
  28528. 8,
  28529. 42
  28530. ],
  28531. [
  28532. 8,
  28533. 42
  28534. ],
  28535. // 00101011x
  28536. [
  28537. 8,
  28538. 43
  28539. ],
  28540. [
  28541. 8,
  28542. 43
  28543. ],
  28544. // 00101100x
  28545. [
  28546. 8,
  28547. 44
  28548. ],
  28549. [
  28550. 8,
  28551. 44
  28552. ],
  28553. // 00101101x
  28554. [
  28555. 7,
  28556. 21
  28557. ],
  28558. [
  28559. 7,
  28560. 21
  28561. ],
  28562. [
  28563. 7,
  28564. 21
  28565. ],
  28566. [
  28567. 7,
  28568. 21
  28569. ],
  28570. // 0010111xx
  28571. [
  28572. 7,
  28573. 28
  28574. ],
  28575. [
  28576. 7,
  28577. 28
  28578. ],
  28579. [
  28580. 7,
  28581. 28
  28582. ],
  28583. [
  28584. 7,
  28585. 28
  28586. ],
  28587. // 0011000xx
  28588. [
  28589. 8,
  28590. 61
  28591. ],
  28592. [
  28593. 8,
  28594. 61
  28595. ],
  28596. // 00110010x
  28597. [
  28598. 8,
  28599. 62
  28600. ],
  28601. [
  28602. 8,
  28603. 62
  28604. ],
  28605. // 00110011x
  28606. [
  28607. 8,
  28608. 63
  28609. ],
  28610. [
  28611. 8,
  28612. 63
  28613. ],
  28614. // 00110100x
  28615. [
  28616. 8,
  28617. 0
  28618. ],
  28619. [
  28620. 8,
  28621. 0
  28622. ],
  28623. // 00110101x
  28624. [
  28625. 8,
  28626. 320
  28627. ],
  28628. [
  28629. 8,
  28630. 320
  28631. ],
  28632. // 00110110x
  28633. [
  28634. 8,
  28635. 384
  28636. ],
  28637. [
  28638. 8,
  28639. 384
  28640. ],
  28641. // 00110111x
  28642. [
  28643. 5,
  28644. 10
  28645. ],
  28646. [
  28647. 5,
  28648. 10
  28649. ],
  28650. [
  28651. 5,
  28652. 10
  28653. ],
  28654. [
  28655. 5,
  28656. 10
  28657. ],
  28658. // 00111xxxx
  28659. [
  28660. 5,
  28661. 10
  28662. ],
  28663. [
  28664. 5,
  28665. 10
  28666. ],
  28667. [
  28668. 5,
  28669. 10
  28670. ],
  28671. [
  28672. 5,
  28673. 10
  28674. ],
  28675. [
  28676. 5,
  28677. 10
  28678. ],
  28679. [
  28680. 5,
  28681. 10
  28682. ],
  28683. [
  28684. 5,
  28685. 10
  28686. ],
  28687. [
  28688. 5,
  28689. 10
  28690. ],
  28691. [
  28692. 5,
  28693. 10
  28694. ],
  28695. [
  28696. 5,
  28697. 10
  28698. ],
  28699. [
  28700. 5,
  28701. 10
  28702. ],
  28703. [
  28704. 5,
  28705. 10
  28706. ],
  28707. [
  28708. 5,
  28709. 11
  28710. ],
  28711. [
  28712. 5,
  28713. 11
  28714. ],
  28715. [
  28716. 5,
  28717. 11
  28718. ],
  28719. [
  28720. 5,
  28721. 11
  28722. ],
  28723. // 01000xxxx
  28724. [
  28725. 5,
  28726. 11
  28727. ],
  28728. [
  28729. 5,
  28730. 11
  28731. ],
  28732. [
  28733. 5,
  28734. 11
  28735. ],
  28736. [
  28737. 5,
  28738. 11
  28739. ],
  28740. [
  28741. 5,
  28742. 11
  28743. ],
  28744. [
  28745. 5,
  28746. 11
  28747. ],
  28748. [
  28749. 5,
  28750. 11
  28751. ],
  28752. [
  28753. 5,
  28754. 11
  28755. ],
  28756. [
  28757. 5,
  28758. 11
  28759. ],
  28760. [
  28761. 5,
  28762. 11
  28763. ],
  28764. [
  28765. 5,
  28766. 11
  28767. ],
  28768. [
  28769. 5,
  28770. 11
  28771. ],
  28772. [
  28773. 7,
  28774. 27
  28775. ],
  28776. [
  28777. 7,
  28778. 27
  28779. ],
  28780. [
  28781. 7,
  28782. 27
  28783. ],
  28784. [
  28785. 7,
  28786. 27
  28787. ],
  28788. // 0100100xx
  28789. [
  28790. 8,
  28791. 59
  28792. ],
  28793. [
  28794. 8,
  28795. 59
  28796. ],
  28797. // 01001010x
  28798. [
  28799. 8,
  28800. 60
  28801. ],
  28802. [
  28803. 8,
  28804. 60
  28805. ],
  28806. // 01001011x
  28807. [
  28808. 9,
  28809. 1472
  28810. ],
  28811. // 010011000
  28812. [
  28813. 9,
  28814. 1536
  28815. ],
  28816. // 010011001
  28817. [
  28818. 9,
  28819. 1600
  28820. ],
  28821. // 010011010
  28822. [
  28823. 9,
  28824. 1728
  28825. ],
  28826. // 010011011
  28827. [
  28828. 7,
  28829. 18
  28830. ],
  28831. [
  28832. 7,
  28833. 18
  28834. ],
  28835. [
  28836. 7,
  28837. 18
  28838. ],
  28839. [
  28840. 7,
  28841. 18
  28842. ],
  28843. // 0100111xx
  28844. [
  28845. 7,
  28846. 24
  28847. ],
  28848. [
  28849. 7,
  28850. 24
  28851. ],
  28852. [
  28853. 7,
  28854. 24
  28855. ],
  28856. [
  28857. 7,
  28858. 24
  28859. ],
  28860. // 0101000xx
  28861. [
  28862. 8,
  28863. 49
  28864. ],
  28865. [
  28866. 8,
  28867. 49
  28868. ],
  28869. // 01010010x
  28870. [
  28871. 8,
  28872. 50
  28873. ],
  28874. [
  28875. 8,
  28876. 50
  28877. ],
  28878. // 01010011x
  28879. [
  28880. 8,
  28881. 51
  28882. ],
  28883. [
  28884. 8,
  28885. 51
  28886. ],
  28887. // 01010100x
  28888. [
  28889. 8,
  28890. 52
  28891. ],
  28892. [
  28893. 8,
  28894. 52
  28895. ],
  28896. // 01010101x
  28897. [
  28898. 7,
  28899. 25
  28900. ],
  28901. [
  28902. 7,
  28903. 25
  28904. ],
  28905. [
  28906. 7,
  28907. 25
  28908. ],
  28909. [
  28910. 7,
  28911. 25
  28912. ],
  28913. // 0101011xx
  28914. [
  28915. 8,
  28916. 55
  28917. ],
  28918. [
  28919. 8,
  28920. 55
  28921. ],
  28922. // 01011000x
  28923. [
  28924. 8,
  28925. 56
  28926. ],
  28927. [
  28928. 8,
  28929. 56
  28930. ],
  28931. // 01011001x
  28932. [
  28933. 8,
  28934. 57
  28935. ],
  28936. [
  28937. 8,
  28938. 57
  28939. ],
  28940. // 01011010x
  28941. [
  28942. 8,
  28943. 58
  28944. ],
  28945. [
  28946. 8,
  28947. 58
  28948. ],
  28949. // 01011011x
  28950. [
  28951. 6,
  28952. 192
  28953. ],
  28954. [
  28955. 6,
  28956. 192
  28957. ],
  28958. [
  28959. 6,
  28960. 192
  28961. ],
  28962. [
  28963. 6,
  28964. 192
  28965. ],
  28966. // 010111xxx
  28967. [
  28968. 6,
  28969. 192
  28970. ],
  28971. [
  28972. 6,
  28973. 192
  28974. ],
  28975. [
  28976. 6,
  28977. 192
  28978. ],
  28979. [
  28980. 6,
  28981. 192
  28982. ],
  28983. [
  28984. 6,
  28985. 1664
  28986. ],
  28987. [
  28988. 6,
  28989. 1664
  28990. ],
  28991. [
  28992. 6,
  28993. 1664
  28994. ],
  28995. [
  28996. 6,
  28997. 1664
  28998. ],
  28999. // 011000xxx
  29000. [
  29001. 6,
  29002. 1664
  29003. ],
  29004. [
  29005. 6,
  29006. 1664
  29007. ],
  29008. [
  29009. 6,
  29010. 1664
  29011. ],
  29012. [
  29013. 6,
  29014. 1664
  29015. ],
  29016. [
  29017. 8,
  29018. 448
  29019. ],
  29020. [
  29021. 8,
  29022. 448
  29023. ],
  29024. // 01100100x
  29025. [
  29026. 8,
  29027. 512
  29028. ],
  29029. [
  29030. 8,
  29031. 512
  29032. ],
  29033. // 01100101x
  29034. [
  29035. 9,
  29036. 704
  29037. ],
  29038. // 011001100
  29039. [
  29040. 9,
  29041. 768
  29042. ],
  29043. // 011001101
  29044. [
  29045. 8,
  29046. 640
  29047. ],
  29048. [
  29049. 8,
  29050. 640
  29051. ],
  29052. // 01100111x
  29053. [
  29054. 8,
  29055. 576
  29056. ],
  29057. [
  29058. 8,
  29059. 576
  29060. ],
  29061. // 01101000x
  29062. [
  29063. 9,
  29064. 832
  29065. ],
  29066. // 011010010
  29067. [
  29068. 9,
  29069. 896
  29070. ],
  29071. // 011010011
  29072. [
  29073. 9,
  29074. 960
  29075. ],
  29076. // 011010100
  29077. [
  29078. 9,
  29079. 1024
  29080. ],
  29081. // 011010101
  29082. [
  29083. 9,
  29084. 1088
  29085. ],
  29086. // 011010110
  29087. [
  29088. 9,
  29089. 1152
  29090. ],
  29091. // 011010111
  29092. [
  29093. 9,
  29094. 1216
  29095. ],
  29096. // 011011000
  29097. [
  29098. 9,
  29099. 1280
  29100. ],
  29101. // 011011001
  29102. [
  29103. 9,
  29104. 1344
  29105. ],
  29106. // 011011010
  29107. [
  29108. 9,
  29109. 1408
  29110. ],
  29111. // 011011011
  29112. [
  29113. 7,
  29114. 256
  29115. ],
  29116. [
  29117. 7,
  29118. 256
  29119. ],
  29120. [
  29121. 7,
  29122. 256
  29123. ],
  29124. [
  29125. 7,
  29126. 256
  29127. ],
  29128. // 0110111xx
  29129. [
  29130. 4,
  29131. 2
  29132. ],
  29133. [
  29134. 4,
  29135. 2
  29136. ],
  29137. [
  29138. 4,
  29139. 2
  29140. ],
  29141. [
  29142. 4,
  29143. 2
  29144. ],
  29145. // 0111xxxxx
  29146. [
  29147. 4,
  29148. 2
  29149. ],
  29150. [
  29151. 4,
  29152. 2
  29153. ],
  29154. [
  29155. 4,
  29156. 2
  29157. ],
  29158. [
  29159. 4,
  29160. 2
  29161. ],
  29162. [
  29163. 4,
  29164. 2
  29165. ],
  29166. [
  29167. 4,
  29168. 2
  29169. ],
  29170. [
  29171. 4,
  29172. 2
  29173. ],
  29174. [
  29175. 4,
  29176. 2
  29177. ],
  29178. [
  29179. 4,
  29180. 2
  29181. ],
  29182. [
  29183. 4,
  29184. 2
  29185. ],
  29186. [
  29187. 4,
  29188. 2
  29189. ],
  29190. [
  29191. 4,
  29192. 2
  29193. ],
  29194. [
  29195. 4,
  29196. 2
  29197. ],
  29198. [
  29199. 4,
  29200. 2
  29201. ],
  29202. [
  29203. 4,
  29204. 2
  29205. ],
  29206. [
  29207. 4,
  29208. 2
  29209. ],
  29210. [
  29211. 4,
  29212. 2
  29213. ],
  29214. [
  29215. 4,
  29216. 2
  29217. ],
  29218. [
  29219. 4,
  29220. 2
  29221. ],
  29222. [
  29223. 4,
  29224. 2
  29225. ],
  29226. [
  29227. 4,
  29228. 2
  29229. ],
  29230. [
  29231. 4,
  29232. 2
  29233. ],
  29234. [
  29235. 4,
  29236. 2
  29237. ],
  29238. [
  29239. 4,
  29240. 2
  29241. ],
  29242. [
  29243. 4,
  29244. 2
  29245. ],
  29246. [
  29247. 4,
  29248. 2
  29249. ],
  29250. [
  29251. 4,
  29252. 2
  29253. ],
  29254. [
  29255. 4,
  29256. 2
  29257. ],
  29258. [
  29259. 4,
  29260. 3
  29261. ],
  29262. [
  29263. 4,
  29264. 3
  29265. ],
  29266. [
  29267. 4,
  29268. 3
  29269. ],
  29270. [
  29271. 4,
  29272. 3
  29273. ],
  29274. // 1000xxxxx
  29275. [
  29276. 4,
  29277. 3
  29278. ],
  29279. [
  29280. 4,
  29281. 3
  29282. ],
  29283. [
  29284. 4,
  29285. 3
  29286. ],
  29287. [
  29288. 4,
  29289. 3
  29290. ],
  29291. [
  29292. 4,
  29293. 3
  29294. ],
  29295. [
  29296. 4,
  29297. 3
  29298. ],
  29299. [
  29300. 4,
  29301. 3
  29302. ],
  29303. [
  29304. 4,
  29305. 3
  29306. ],
  29307. [
  29308. 4,
  29309. 3
  29310. ],
  29311. [
  29312. 4,
  29313. 3
  29314. ],
  29315. [
  29316. 4,
  29317. 3
  29318. ],
  29319. [
  29320. 4,
  29321. 3
  29322. ],
  29323. [
  29324. 4,
  29325. 3
  29326. ],
  29327. [
  29328. 4,
  29329. 3
  29330. ],
  29331. [
  29332. 4,
  29333. 3
  29334. ],
  29335. [
  29336. 4,
  29337. 3
  29338. ],
  29339. [
  29340. 4,
  29341. 3
  29342. ],
  29343. [
  29344. 4,
  29345. 3
  29346. ],
  29347. [
  29348. 4,
  29349. 3
  29350. ],
  29351. [
  29352. 4,
  29353. 3
  29354. ],
  29355. [
  29356. 4,
  29357. 3
  29358. ],
  29359. [
  29360. 4,
  29361. 3
  29362. ],
  29363. [
  29364. 4,
  29365. 3
  29366. ],
  29367. [
  29368. 4,
  29369. 3
  29370. ],
  29371. [
  29372. 4,
  29373. 3
  29374. ],
  29375. [
  29376. 4,
  29377. 3
  29378. ],
  29379. [
  29380. 4,
  29381. 3
  29382. ],
  29383. [
  29384. 4,
  29385. 3
  29386. ],
  29387. [
  29388. 5,
  29389. 128
  29390. ],
  29391. [
  29392. 5,
  29393. 128
  29394. ],
  29395. [
  29396. 5,
  29397. 128
  29398. ],
  29399. [
  29400. 5,
  29401. 128
  29402. ],
  29403. // 10010xxxx
  29404. [
  29405. 5,
  29406. 128
  29407. ],
  29408. [
  29409. 5,
  29410. 128
  29411. ],
  29412. [
  29413. 5,
  29414. 128
  29415. ],
  29416. [
  29417. 5,
  29418. 128
  29419. ],
  29420. [
  29421. 5,
  29422. 128
  29423. ],
  29424. [
  29425. 5,
  29426. 128
  29427. ],
  29428. [
  29429. 5,
  29430. 128
  29431. ],
  29432. [
  29433. 5,
  29434. 128
  29435. ],
  29436. [
  29437. 5,
  29438. 128
  29439. ],
  29440. [
  29441. 5,
  29442. 128
  29443. ],
  29444. [
  29445. 5,
  29446. 128
  29447. ],
  29448. [
  29449. 5,
  29450. 128
  29451. ],
  29452. [
  29453. 5,
  29454. 8
  29455. ],
  29456. [
  29457. 5,
  29458. 8
  29459. ],
  29460. [
  29461. 5,
  29462. 8
  29463. ],
  29464. [
  29465. 5,
  29466. 8
  29467. ],
  29468. // 10011xxxx
  29469. [
  29470. 5,
  29471. 8
  29472. ],
  29473. [
  29474. 5,
  29475. 8
  29476. ],
  29477. [
  29478. 5,
  29479. 8
  29480. ],
  29481. [
  29482. 5,
  29483. 8
  29484. ],
  29485. [
  29486. 5,
  29487. 8
  29488. ],
  29489. [
  29490. 5,
  29491. 8
  29492. ],
  29493. [
  29494. 5,
  29495. 8
  29496. ],
  29497. [
  29498. 5,
  29499. 8
  29500. ],
  29501. [
  29502. 5,
  29503. 8
  29504. ],
  29505. [
  29506. 5,
  29507. 8
  29508. ],
  29509. [
  29510. 5,
  29511. 8
  29512. ],
  29513. [
  29514. 5,
  29515. 8
  29516. ],
  29517. [
  29518. 5,
  29519. 9
  29520. ],
  29521. [
  29522. 5,
  29523. 9
  29524. ],
  29525. [
  29526. 5,
  29527. 9
  29528. ],
  29529. [
  29530. 5,
  29531. 9
  29532. ],
  29533. // 10100xxxx
  29534. [
  29535. 5,
  29536. 9
  29537. ],
  29538. [
  29539. 5,
  29540. 9
  29541. ],
  29542. [
  29543. 5,
  29544. 9
  29545. ],
  29546. [
  29547. 5,
  29548. 9
  29549. ],
  29550. [
  29551. 5,
  29552. 9
  29553. ],
  29554. [
  29555. 5,
  29556. 9
  29557. ],
  29558. [
  29559. 5,
  29560. 9
  29561. ],
  29562. [
  29563. 5,
  29564. 9
  29565. ],
  29566. [
  29567. 5,
  29568. 9
  29569. ],
  29570. [
  29571. 5,
  29572. 9
  29573. ],
  29574. [
  29575. 5,
  29576. 9
  29577. ],
  29578. [
  29579. 5,
  29580. 9
  29581. ],
  29582. [
  29583. 6,
  29584. 16
  29585. ],
  29586. [
  29587. 6,
  29588. 16
  29589. ],
  29590. [
  29591. 6,
  29592. 16
  29593. ],
  29594. [
  29595. 6,
  29596. 16
  29597. ],
  29598. // 101010xxx
  29599. [
  29600. 6,
  29601. 16
  29602. ],
  29603. [
  29604. 6,
  29605. 16
  29606. ],
  29607. [
  29608. 6,
  29609. 16
  29610. ],
  29611. [
  29612. 6,
  29613. 16
  29614. ],
  29615. [
  29616. 6,
  29617. 17
  29618. ],
  29619. [
  29620. 6,
  29621. 17
  29622. ],
  29623. [
  29624. 6,
  29625. 17
  29626. ],
  29627. [
  29628. 6,
  29629. 17
  29630. ],
  29631. // 101011xxx
  29632. [
  29633. 6,
  29634. 17
  29635. ],
  29636. [
  29637. 6,
  29638. 17
  29639. ],
  29640. [
  29641. 6,
  29642. 17
  29643. ],
  29644. [
  29645. 6,
  29646. 17
  29647. ],
  29648. [
  29649. 4,
  29650. 4
  29651. ],
  29652. [
  29653. 4,
  29654. 4
  29655. ],
  29656. [
  29657. 4,
  29658. 4
  29659. ],
  29660. [
  29661. 4,
  29662. 4
  29663. ],
  29664. // 1011xxxxx
  29665. [
  29666. 4,
  29667. 4
  29668. ],
  29669. [
  29670. 4,
  29671. 4
  29672. ],
  29673. [
  29674. 4,
  29675. 4
  29676. ],
  29677. [
  29678. 4,
  29679. 4
  29680. ],
  29681. [
  29682. 4,
  29683. 4
  29684. ],
  29685. [
  29686. 4,
  29687. 4
  29688. ],
  29689. [
  29690. 4,
  29691. 4
  29692. ],
  29693. [
  29694. 4,
  29695. 4
  29696. ],
  29697. [
  29698. 4,
  29699. 4
  29700. ],
  29701. [
  29702. 4,
  29703. 4
  29704. ],
  29705. [
  29706. 4,
  29707. 4
  29708. ],
  29709. [
  29710. 4,
  29711. 4
  29712. ],
  29713. [
  29714. 4,
  29715. 4
  29716. ],
  29717. [
  29718. 4,
  29719. 4
  29720. ],
  29721. [
  29722. 4,
  29723. 4
  29724. ],
  29725. [
  29726. 4,
  29727. 4
  29728. ],
  29729. [
  29730. 4,
  29731. 4
  29732. ],
  29733. [
  29734. 4,
  29735. 4
  29736. ],
  29737. [
  29738. 4,
  29739. 4
  29740. ],
  29741. [
  29742. 4,
  29743. 4
  29744. ],
  29745. [
  29746. 4,
  29747. 4
  29748. ],
  29749. [
  29750. 4,
  29751. 4
  29752. ],
  29753. [
  29754. 4,
  29755. 4
  29756. ],
  29757. [
  29758. 4,
  29759. 4
  29760. ],
  29761. [
  29762. 4,
  29763. 4
  29764. ],
  29765. [
  29766. 4,
  29767. 4
  29768. ],
  29769. [
  29770. 4,
  29771. 4
  29772. ],
  29773. [
  29774. 4,
  29775. 4
  29776. ],
  29777. [
  29778. 4,
  29779. 5
  29780. ],
  29781. [
  29782. 4,
  29783. 5
  29784. ],
  29785. [
  29786. 4,
  29787. 5
  29788. ],
  29789. [
  29790. 4,
  29791. 5
  29792. ],
  29793. // 1100xxxxx
  29794. [
  29795. 4,
  29796. 5
  29797. ],
  29798. [
  29799. 4,
  29800. 5
  29801. ],
  29802. [
  29803. 4,
  29804. 5
  29805. ],
  29806. [
  29807. 4,
  29808. 5
  29809. ],
  29810. [
  29811. 4,
  29812. 5
  29813. ],
  29814. [
  29815. 4,
  29816. 5
  29817. ],
  29818. [
  29819. 4,
  29820. 5
  29821. ],
  29822. [
  29823. 4,
  29824. 5
  29825. ],
  29826. [
  29827. 4,
  29828. 5
  29829. ],
  29830. [
  29831. 4,
  29832. 5
  29833. ],
  29834. [
  29835. 4,
  29836. 5
  29837. ],
  29838. [
  29839. 4,
  29840. 5
  29841. ],
  29842. [
  29843. 4,
  29844. 5
  29845. ],
  29846. [
  29847. 4,
  29848. 5
  29849. ],
  29850. [
  29851. 4,
  29852. 5
  29853. ],
  29854. [
  29855. 4,
  29856. 5
  29857. ],
  29858. [
  29859. 4,
  29860. 5
  29861. ],
  29862. [
  29863. 4,
  29864. 5
  29865. ],
  29866. [
  29867. 4,
  29868. 5
  29869. ],
  29870. [
  29871. 4,
  29872. 5
  29873. ],
  29874. [
  29875. 4,
  29876. 5
  29877. ],
  29878. [
  29879. 4,
  29880. 5
  29881. ],
  29882. [
  29883. 4,
  29884. 5
  29885. ],
  29886. [
  29887. 4,
  29888. 5
  29889. ],
  29890. [
  29891. 4,
  29892. 5
  29893. ],
  29894. [
  29895. 4,
  29896. 5
  29897. ],
  29898. [
  29899. 4,
  29900. 5
  29901. ],
  29902. [
  29903. 4,
  29904. 5
  29905. ],
  29906. [
  29907. 6,
  29908. 14
  29909. ],
  29910. [
  29911. 6,
  29912. 14
  29913. ],
  29914. [
  29915. 6,
  29916. 14
  29917. ],
  29918. [
  29919. 6,
  29920. 14
  29921. ],
  29922. // 110100xxx
  29923. [
  29924. 6,
  29925. 14
  29926. ],
  29927. [
  29928. 6,
  29929. 14
  29930. ],
  29931. [
  29932. 6,
  29933. 14
  29934. ],
  29935. [
  29936. 6,
  29937. 14
  29938. ],
  29939. [
  29940. 6,
  29941. 15
  29942. ],
  29943. [
  29944. 6,
  29945. 15
  29946. ],
  29947. [
  29948. 6,
  29949. 15
  29950. ],
  29951. [
  29952. 6,
  29953. 15
  29954. ],
  29955. // 110101xxx
  29956. [
  29957. 6,
  29958. 15
  29959. ],
  29960. [
  29961. 6,
  29962. 15
  29963. ],
  29964. [
  29965. 6,
  29966. 15
  29967. ],
  29968. [
  29969. 6,
  29970. 15
  29971. ],
  29972. [
  29973. 5,
  29974. 64
  29975. ],
  29976. [
  29977. 5,
  29978. 64
  29979. ],
  29980. [
  29981. 5,
  29982. 64
  29983. ],
  29984. [
  29985. 5,
  29986. 64
  29987. ],
  29988. // 11011xxxx
  29989. [
  29990. 5,
  29991. 64
  29992. ],
  29993. [
  29994. 5,
  29995. 64
  29996. ],
  29997. [
  29998. 5,
  29999. 64
  30000. ],
  30001. [
  30002. 5,
  30003. 64
  30004. ],
  30005. [
  30006. 5,
  30007. 64
  30008. ],
  30009. [
  30010. 5,
  30011. 64
  30012. ],
  30013. [
  30014. 5,
  30015. 64
  30016. ],
  30017. [
  30018. 5,
  30019. 64
  30020. ],
  30021. [
  30022. 5,
  30023. 64
  30024. ],
  30025. [
  30026. 5,
  30027. 64
  30028. ],
  30029. [
  30030. 5,
  30031. 64
  30032. ],
  30033. [
  30034. 5,
  30035. 64
  30036. ],
  30037. [
  30038. 4,
  30039. 6
  30040. ],
  30041. [
  30042. 4,
  30043. 6
  30044. ],
  30045. [
  30046. 4,
  30047. 6
  30048. ],
  30049. [
  30050. 4,
  30051. 6
  30052. ],
  30053. // 1110xxxxx
  30054. [
  30055. 4,
  30056. 6
  30057. ],
  30058. [
  30059. 4,
  30060. 6
  30061. ],
  30062. [
  30063. 4,
  30064. 6
  30065. ],
  30066. [
  30067. 4,
  30068. 6
  30069. ],
  30070. [
  30071. 4,
  30072. 6
  30073. ],
  30074. [
  30075. 4,
  30076. 6
  30077. ],
  30078. [
  30079. 4,
  30080. 6
  30081. ],
  30082. [
  30083. 4,
  30084. 6
  30085. ],
  30086. [
  30087. 4,
  30088. 6
  30089. ],
  30090. [
  30091. 4,
  30092. 6
  30093. ],
  30094. [
  30095. 4,
  30096. 6
  30097. ],
  30098. [
  30099. 4,
  30100. 6
  30101. ],
  30102. [
  30103. 4,
  30104. 6
  30105. ],
  30106. [
  30107. 4,
  30108. 6
  30109. ],
  30110. [
  30111. 4,
  30112. 6
  30113. ],
  30114. [
  30115. 4,
  30116. 6
  30117. ],
  30118. [
  30119. 4,
  30120. 6
  30121. ],
  30122. [
  30123. 4,
  30124. 6
  30125. ],
  30126. [
  30127. 4,
  30128. 6
  30129. ],
  30130. [
  30131. 4,
  30132. 6
  30133. ],
  30134. [
  30135. 4,
  30136. 6
  30137. ],
  30138. [
  30139. 4,
  30140. 6
  30141. ],
  30142. [
  30143. 4,
  30144. 6
  30145. ],
  30146. [
  30147. 4,
  30148. 6
  30149. ],
  30150. [
  30151. 4,
  30152. 6
  30153. ],
  30154. [
  30155. 4,
  30156. 6
  30157. ],
  30158. [
  30159. 4,
  30160. 6
  30161. ],
  30162. [
  30163. 4,
  30164. 6
  30165. ],
  30166. [
  30167. 4,
  30168. 7
  30169. ],
  30170. [
  30171. 4,
  30172. 7
  30173. ],
  30174. [
  30175. 4,
  30176. 7
  30177. ],
  30178. [
  30179. 4,
  30180. 7
  30181. ],
  30182. // 1111xxxxx
  30183. [
  30184. 4,
  30185. 7
  30186. ],
  30187. [
  30188. 4,
  30189. 7
  30190. ],
  30191. [
  30192. 4,
  30193. 7
  30194. ],
  30195. [
  30196. 4,
  30197. 7
  30198. ],
  30199. [
  30200. 4,
  30201. 7
  30202. ],
  30203. [
  30204. 4,
  30205. 7
  30206. ],
  30207. [
  30208. 4,
  30209. 7
  30210. ],
  30211. [
  30212. 4,
  30213. 7
  30214. ],
  30215. [
  30216. 4,
  30217. 7
  30218. ],
  30219. [
  30220. 4,
  30221. 7
  30222. ],
  30223. [
  30224. 4,
  30225. 7
  30226. ],
  30227. [
  30228. 4,
  30229. 7
  30230. ],
  30231. [
  30232. 4,
  30233. 7
  30234. ],
  30235. [
  30236. 4,
  30237. 7
  30238. ],
  30239. [
  30240. 4,
  30241. 7
  30242. ],
  30243. [
  30244. 4,
  30245. 7
  30246. ],
  30247. [
  30248. 4,
  30249. 7
  30250. ],
  30251. [
  30252. 4,
  30253. 7
  30254. ],
  30255. [
  30256. 4,
  30257. 7
  30258. ],
  30259. [
  30260. 4,
  30261. 7
  30262. ],
  30263. [
  30264. 4,
  30265. 7
  30266. ],
  30267. [
  30268. 4,
  30269. 7
  30270. ],
  30271. [
  30272. 4,
  30273. 7
  30274. ],
  30275. [
  30276. 4,
  30277. 7
  30278. ],
  30279. [
  30280. 4,
  30281. 7
  30282. ],
  30283. [
  30284. 4,
  30285. 7
  30286. ],
  30287. [
  30288. 4,
  30289. 7
  30290. ],
  30291. [
  30292. 4,
  30293. 7
  30294. ]
  30295. ];
  30296. var blackTable1 = [
  30297. [
  30298. -1,
  30299. -1
  30300. ],
  30301. [
  30302. -1,
  30303. -1
  30304. ],
  30305. // 000000000000x
  30306. [
  30307. 12,
  30308. ccittEOL
  30309. ],
  30310. [
  30311. 12,
  30312. ccittEOL
  30313. ],
  30314. // 000000000001x
  30315. [
  30316. -1,
  30317. -1
  30318. ],
  30319. [
  30320. -1,
  30321. -1
  30322. ],
  30323. [
  30324. -1,
  30325. -1
  30326. ],
  30327. [
  30328. -1,
  30329. -1
  30330. ],
  30331. // 00000000001xx
  30332. [
  30333. -1,
  30334. -1
  30335. ],
  30336. [
  30337. -1,
  30338. -1
  30339. ],
  30340. [
  30341. -1,
  30342. -1
  30343. ],
  30344. [
  30345. -1,
  30346. -1
  30347. ],
  30348. // 00000000010xx
  30349. [
  30350. -1,
  30351. -1
  30352. ],
  30353. [
  30354. -1,
  30355. -1
  30356. ],
  30357. [
  30358. -1,
  30359. -1
  30360. ],
  30361. [
  30362. -1,
  30363. -1
  30364. ],
  30365. // 00000000011xx
  30366. [
  30367. -1,
  30368. -1
  30369. ],
  30370. [
  30371. -1,
  30372. -1
  30373. ],
  30374. [
  30375. -1,
  30376. -1
  30377. ],
  30378. [
  30379. -1,
  30380. -1
  30381. ],
  30382. // 00000000100xx
  30383. [
  30384. -1,
  30385. -1
  30386. ],
  30387. [
  30388. -1,
  30389. -1
  30390. ],
  30391. [
  30392. -1,
  30393. -1
  30394. ],
  30395. [
  30396. -1,
  30397. -1
  30398. ],
  30399. // 00000000101xx
  30400. [
  30401. -1,
  30402. -1
  30403. ],
  30404. [
  30405. -1,
  30406. -1
  30407. ],
  30408. [
  30409. -1,
  30410. -1
  30411. ],
  30412. [
  30413. -1,
  30414. -1
  30415. ],
  30416. // 00000000110xx
  30417. [
  30418. -1,
  30419. -1
  30420. ],
  30421. [
  30422. -1,
  30423. -1
  30424. ],
  30425. [
  30426. -1,
  30427. -1
  30428. ],
  30429. [
  30430. -1,
  30431. -1
  30432. ],
  30433. // 00000000111xx
  30434. [
  30435. 11,
  30436. 1792
  30437. ],
  30438. [
  30439. 11,
  30440. 1792
  30441. ],
  30442. [
  30443. 11,
  30444. 1792
  30445. ],
  30446. [
  30447. 11,
  30448. 1792
  30449. ],
  30450. // 00000001000xx
  30451. [
  30452. 12,
  30453. 1984
  30454. ],
  30455. [
  30456. 12,
  30457. 1984
  30458. ],
  30459. // 000000010010x
  30460. [
  30461. 12,
  30462. 2048
  30463. ],
  30464. [
  30465. 12,
  30466. 2048
  30467. ],
  30468. // 000000010011x
  30469. [
  30470. 12,
  30471. 2112
  30472. ],
  30473. [
  30474. 12,
  30475. 2112
  30476. ],
  30477. // 000000010100x
  30478. [
  30479. 12,
  30480. 2176
  30481. ],
  30482. [
  30483. 12,
  30484. 2176
  30485. ],
  30486. // 000000010101x
  30487. [
  30488. 12,
  30489. 2240
  30490. ],
  30491. [
  30492. 12,
  30493. 2240
  30494. ],
  30495. // 000000010110x
  30496. [
  30497. 12,
  30498. 2304
  30499. ],
  30500. [
  30501. 12,
  30502. 2304
  30503. ],
  30504. // 000000010111x
  30505. [
  30506. 11,
  30507. 1856
  30508. ],
  30509. [
  30510. 11,
  30511. 1856
  30512. ],
  30513. [
  30514. 11,
  30515. 1856
  30516. ],
  30517. [
  30518. 11,
  30519. 1856
  30520. ],
  30521. // 00000001100xx
  30522. [
  30523. 11,
  30524. 1920
  30525. ],
  30526. [
  30527. 11,
  30528. 1920
  30529. ],
  30530. [
  30531. 11,
  30532. 1920
  30533. ],
  30534. [
  30535. 11,
  30536. 1920
  30537. ],
  30538. // 00000001101xx
  30539. [
  30540. 12,
  30541. 2368
  30542. ],
  30543. [
  30544. 12,
  30545. 2368
  30546. ],
  30547. // 000000011100x
  30548. [
  30549. 12,
  30550. 2432
  30551. ],
  30552. [
  30553. 12,
  30554. 2432
  30555. ],
  30556. // 000000011101x
  30557. [
  30558. 12,
  30559. 2496
  30560. ],
  30561. [
  30562. 12,
  30563. 2496
  30564. ],
  30565. // 000000011110x
  30566. [
  30567. 12,
  30568. 2560
  30569. ],
  30570. [
  30571. 12,
  30572. 2560
  30573. ],
  30574. // 000000011111x
  30575. [
  30576. 10,
  30577. 18
  30578. ],
  30579. [
  30580. 10,
  30581. 18
  30582. ],
  30583. [
  30584. 10,
  30585. 18
  30586. ],
  30587. [
  30588. 10,
  30589. 18
  30590. ],
  30591. // 0000001000xxx
  30592. [
  30593. 10,
  30594. 18
  30595. ],
  30596. [
  30597. 10,
  30598. 18
  30599. ],
  30600. [
  30601. 10,
  30602. 18
  30603. ],
  30604. [
  30605. 10,
  30606. 18
  30607. ],
  30608. [
  30609. 12,
  30610. 52
  30611. ],
  30612. [
  30613. 12,
  30614. 52
  30615. ],
  30616. // 000000100100x
  30617. [
  30618. 13,
  30619. 640
  30620. ],
  30621. // 0000001001010
  30622. [
  30623. 13,
  30624. 704
  30625. ],
  30626. // 0000001001011
  30627. [
  30628. 13,
  30629. 768
  30630. ],
  30631. // 0000001001100
  30632. [
  30633. 13,
  30634. 832
  30635. ],
  30636. // 0000001001101
  30637. [
  30638. 12,
  30639. 55
  30640. ],
  30641. [
  30642. 12,
  30643. 55
  30644. ],
  30645. // 000000100111x
  30646. [
  30647. 12,
  30648. 56
  30649. ],
  30650. [
  30651. 12,
  30652. 56
  30653. ],
  30654. // 000000101000x
  30655. [
  30656. 13,
  30657. 1280
  30658. ],
  30659. // 0000001010010
  30660. [
  30661. 13,
  30662. 1344
  30663. ],
  30664. // 0000001010011
  30665. [
  30666. 13,
  30667. 1408
  30668. ],
  30669. // 0000001010100
  30670. [
  30671. 13,
  30672. 1472
  30673. ],
  30674. // 0000001010101
  30675. [
  30676. 12,
  30677. 59
  30678. ],
  30679. [
  30680. 12,
  30681. 59
  30682. ],
  30683. // 000000101011x
  30684. [
  30685. 12,
  30686. 60
  30687. ],
  30688. [
  30689. 12,
  30690. 60
  30691. ],
  30692. // 000000101100x
  30693. [
  30694. 13,
  30695. 1536
  30696. ],
  30697. // 0000001011010
  30698. [
  30699. 13,
  30700. 1600
  30701. ],
  30702. // 0000001011011
  30703. [
  30704. 11,
  30705. 24
  30706. ],
  30707. [
  30708. 11,
  30709. 24
  30710. ],
  30711. [
  30712. 11,
  30713. 24
  30714. ],
  30715. [
  30716. 11,
  30717. 24
  30718. ],
  30719. // 00000010111xx
  30720. [
  30721. 11,
  30722. 25
  30723. ],
  30724. [
  30725. 11,
  30726. 25
  30727. ],
  30728. [
  30729. 11,
  30730. 25
  30731. ],
  30732. [
  30733. 11,
  30734. 25
  30735. ],
  30736. // 00000011000xx
  30737. [
  30738. 13,
  30739. 1664
  30740. ],
  30741. // 0000001100100
  30742. [
  30743. 13,
  30744. 1728
  30745. ],
  30746. // 0000001100101
  30747. [
  30748. 12,
  30749. 320
  30750. ],
  30751. [
  30752. 12,
  30753. 320
  30754. ],
  30755. // 000000110011x
  30756. [
  30757. 12,
  30758. 384
  30759. ],
  30760. [
  30761. 12,
  30762. 384
  30763. ],
  30764. // 000000110100x
  30765. [
  30766. 12,
  30767. 448
  30768. ],
  30769. [
  30770. 12,
  30771. 448
  30772. ],
  30773. // 000000110101x
  30774. [
  30775. 13,
  30776. 512
  30777. ],
  30778. // 0000001101100
  30779. [
  30780. 13,
  30781. 576
  30782. ],
  30783. // 0000001101101
  30784. [
  30785. 12,
  30786. 53
  30787. ],
  30788. [
  30789. 12,
  30790. 53
  30791. ],
  30792. // 000000110111x
  30793. [
  30794. 12,
  30795. 54
  30796. ],
  30797. [
  30798. 12,
  30799. 54
  30800. ],
  30801. // 000000111000x
  30802. [
  30803. 13,
  30804. 896
  30805. ],
  30806. // 0000001110010
  30807. [
  30808. 13,
  30809. 960
  30810. ],
  30811. // 0000001110011
  30812. [
  30813. 13,
  30814. 1024
  30815. ],
  30816. // 0000001110100
  30817. [
  30818. 13,
  30819. 1088
  30820. ],
  30821. // 0000001110101
  30822. [
  30823. 13,
  30824. 1152
  30825. ],
  30826. // 0000001110110
  30827. [
  30828. 13,
  30829. 1216
  30830. ],
  30831. // 0000001110111
  30832. [
  30833. 10,
  30834. 64
  30835. ],
  30836. [
  30837. 10,
  30838. 64
  30839. ],
  30840. [
  30841. 10,
  30842. 64
  30843. ],
  30844. [
  30845. 10,
  30846. 64
  30847. ],
  30848. // 0000001111xxx
  30849. [
  30850. 10,
  30851. 64
  30852. ],
  30853. [
  30854. 10,
  30855. 64
  30856. ],
  30857. [
  30858. 10,
  30859. 64
  30860. ],
  30861. [
  30862. 10,
  30863. 64
  30864. ]
  30865. ];
  30866. var blackTable2 = [
  30867. [
  30868. 8,
  30869. 13
  30870. ],
  30871. [
  30872. 8,
  30873. 13
  30874. ],
  30875. [
  30876. 8,
  30877. 13
  30878. ],
  30879. [
  30880. 8,
  30881. 13
  30882. ],
  30883. // 00000100xxxx
  30884. [
  30885. 8,
  30886. 13
  30887. ],
  30888. [
  30889. 8,
  30890. 13
  30891. ],
  30892. [
  30893. 8,
  30894. 13
  30895. ],
  30896. [
  30897. 8,
  30898. 13
  30899. ],
  30900. [
  30901. 8,
  30902. 13
  30903. ],
  30904. [
  30905. 8,
  30906. 13
  30907. ],
  30908. [
  30909. 8,
  30910. 13
  30911. ],
  30912. [
  30913. 8,
  30914. 13
  30915. ],
  30916. [
  30917. 8,
  30918. 13
  30919. ],
  30920. [
  30921. 8,
  30922. 13
  30923. ],
  30924. [
  30925. 8,
  30926. 13
  30927. ],
  30928. [
  30929. 8,
  30930. 13
  30931. ],
  30932. [
  30933. 11,
  30934. 23
  30935. ],
  30936. [
  30937. 11,
  30938. 23
  30939. ],
  30940. // 00000101000x
  30941. [
  30942. 12,
  30943. 50
  30944. ],
  30945. // 000001010010
  30946. [
  30947. 12,
  30948. 51
  30949. ],
  30950. // 000001010011
  30951. [
  30952. 12,
  30953. 44
  30954. ],
  30955. // 000001010100
  30956. [
  30957. 12,
  30958. 45
  30959. ],
  30960. // 000001010101
  30961. [
  30962. 12,
  30963. 46
  30964. ],
  30965. // 000001010110
  30966. [
  30967. 12,
  30968. 47
  30969. ],
  30970. // 000001010111
  30971. [
  30972. 12,
  30973. 57
  30974. ],
  30975. // 000001011000
  30976. [
  30977. 12,
  30978. 58
  30979. ],
  30980. // 000001011001
  30981. [
  30982. 12,
  30983. 61
  30984. ],
  30985. // 000001011010
  30986. [
  30987. 12,
  30988. 256
  30989. ],
  30990. // 000001011011
  30991. [
  30992. 10,
  30993. 16
  30994. ],
  30995. [
  30996. 10,
  30997. 16
  30998. ],
  30999. [
  31000. 10,
  31001. 16
  31002. ],
  31003. [
  31004. 10,
  31005. 16
  31006. ],
  31007. // 0000010111xx
  31008. [
  31009. 10,
  31010. 17
  31011. ],
  31012. [
  31013. 10,
  31014. 17
  31015. ],
  31016. [
  31017. 10,
  31018. 17
  31019. ],
  31020. [
  31021. 10,
  31022. 17
  31023. ],
  31024. // 0000011000xx
  31025. [
  31026. 12,
  31027. 48
  31028. ],
  31029. // 000001100100
  31030. [
  31031. 12,
  31032. 49
  31033. ],
  31034. // 000001100101
  31035. [
  31036. 12,
  31037. 62
  31038. ],
  31039. // 000001100110
  31040. [
  31041. 12,
  31042. 63
  31043. ],
  31044. // 000001100111
  31045. [
  31046. 12,
  31047. 30
  31048. ],
  31049. // 000001101000
  31050. [
  31051. 12,
  31052. 31
  31053. ],
  31054. // 000001101001
  31055. [
  31056. 12,
  31057. 32
  31058. ],
  31059. // 000001101010
  31060. [
  31061. 12,
  31062. 33
  31063. ],
  31064. // 000001101011
  31065. [
  31066. 12,
  31067. 40
  31068. ],
  31069. // 000001101100
  31070. [
  31071. 12,
  31072. 41
  31073. ],
  31074. // 000001101101
  31075. [
  31076. 11,
  31077. 22
  31078. ],
  31079. [
  31080. 11,
  31081. 22
  31082. ],
  31083. // 00000110111x
  31084. [
  31085. 8,
  31086. 14
  31087. ],
  31088. [
  31089. 8,
  31090. 14
  31091. ],
  31092. [
  31093. 8,
  31094. 14
  31095. ],
  31096. [
  31097. 8,
  31098. 14
  31099. ],
  31100. // 00000111xxxx
  31101. [
  31102. 8,
  31103. 14
  31104. ],
  31105. [
  31106. 8,
  31107. 14
  31108. ],
  31109. [
  31110. 8,
  31111. 14
  31112. ],
  31113. [
  31114. 8,
  31115. 14
  31116. ],
  31117. [
  31118. 8,
  31119. 14
  31120. ],
  31121. [
  31122. 8,
  31123. 14
  31124. ],
  31125. [
  31126. 8,
  31127. 14
  31128. ],
  31129. [
  31130. 8,
  31131. 14
  31132. ],
  31133. [
  31134. 8,
  31135. 14
  31136. ],
  31137. [
  31138. 8,
  31139. 14
  31140. ],
  31141. [
  31142. 8,
  31143. 14
  31144. ],
  31145. [
  31146. 8,
  31147. 14
  31148. ],
  31149. [
  31150. 7,
  31151. 10
  31152. ],
  31153. [
  31154. 7,
  31155. 10
  31156. ],
  31157. [
  31158. 7,
  31159. 10
  31160. ],
  31161. [
  31162. 7,
  31163. 10
  31164. ],
  31165. // 0000100xxxxx
  31166. [
  31167. 7,
  31168. 10
  31169. ],
  31170. [
  31171. 7,
  31172. 10
  31173. ],
  31174. [
  31175. 7,
  31176. 10
  31177. ],
  31178. [
  31179. 7,
  31180. 10
  31181. ],
  31182. [
  31183. 7,
  31184. 10
  31185. ],
  31186. [
  31187. 7,
  31188. 10
  31189. ],
  31190. [
  31191. 7,
  31192. 10
  31193. ],
  31194. [
  31195. 7,
  31196. 10
  31197. ],
  31198. [
  31199. 7,
  31200. 10
  31201. ],
  31202. [
  31203. 7,
  31204. 10
  31205. ],
  31206. [
  31207. 7,
  31208. 10
  31209. ],
  31210. [
  31211. 7,
  31212. 10
  31213. ],
  31214. [
  31215. 7,
  31216. 10
  31217. ],
  31218. [
  31219. 7,
  31220. 10
  31221. ],
  31222. [
  31223. 7,
  31224. 10
  31225. ],
  31226. [
  31227. 7,
  31228. 10
  31229. ],
  31230. [
  31231. 7,
  31232. 10
  31233. ],
  31234. [
  31235. 7,
  31236. 10
  31237. ],
  31238. [
  31239. 7,
  31240. 10
  31241. ],
  31242. [
  31243. 7,
  31244. 10
  31245. ],
  31246. [
  31247. 7,
  31248. 10
  31249. ],
  31250. [
  31251. 7,
  31252. 10
  31253. ],
  31254. [
  31255. 7,
  31256. 10
  31257. ],
  31258. [
  31259. 7,
  31260. 10
  31261. ],
  31262. [
  31263. 7,
  31264. 10
  31265. ],
  31266. [
  31267. 7,
  31268. 10
  31269. ],
  31270. [
  31271. 7,
  31272. 10
  31273. ],
  31274. [
  31275. 7,
  31276. 10
  31277. ],
  31278. [
  31279. 7,
  31280. 11
  31281. ],
  31282. [
  31283. 7,
  31284. 11
  31285. ],
  31286. [
  31287. 7,
  31288. 11
  31289. ],
  31290. [
  31291. 7,
  31292. 11
  31293. ],
  31294. // 0000101xxxxx
  31295. [
  31296. 7,
  31297. 11
  31298. ],
  31299. [
  31300. 7,
  31301. 11
  31302. ],
  31303. [
  31304. 7,
  31305. 11
  31306. ],
  31307. [
  31308. 7,
  31309. 11
  31310. ],
  31311. [
  31312. 7,
  31313. 11
  31314. ],
  31315. [
  31316. 7,
  31317. 11
  31318. ],
  31319. [
  31320. 7,
  31321. 11
  31322. ],
  31323. [
  31324. 7,
  31325. 11
  31326. ],
  31327. [
  31328. 7,
  31329. 11
  31330. ],
  31331. [
  31332. 7,
  31333. 11
  31334. ],
  31335. [
  31336. 7,
  31337. 11
  31338. ],
  31339. [
  31340. 7,
  31341. 11
  31342. ],
  31343. [
  31344. 7,
  31345. 11
  31346. ],
  31347. [
  31348. 7,
  31349. 11
  31350. ],
  31351. [
  31352. 7,
  31353. 11
  31354. ],
  31355. [
  31356. 7,
  31357. 11
  31358. ],
  31359. [
  31360. 7,
  31361. 11
  31362. ],
  31363. [
  31364. 7,
  31365. 11
  31366. ],
  31367. [
  31368. 7,
  31369. 11
  31370. ],
  31371. [
  31372. 7,
  31373. 11
  31374. ],
  31375. [
  31376. 7,
  31377. 11
  31378. ],
  31379. [
  31380. 7,
  31381. 11
  31382. ],
  31383. [
  31384. 7,
  31385. 11
  31386. ],
  31387. [
  31388. 7,
  31389. 11
  31390. ],
  31391. [
  31392. 7,
  31393. 11
  31394. ],
  31395. [
  31396. 7,
  31397. 11
  31398. ],
  31399. [
  31400. 7,
  31401. 11
  31402. ],
  31403. [
  31404. 7,
  31405. 11
  31406. ],
  31407. [
  31408. 9,
  31409. 15
  31410. ],
  31411. [
  31412. 9,
  31413. 15
  31414. ],
  31415. [
  31416. 9,
  31417. 15
  31418. ],
  31419. [
  31420. 9,
  31421. 15
  31422. ],
  31423. // 000011000xxx
  31424. [
  31425. 9,
  31426. 15
  31427. ],
  31428. [
  31429. 9,
  31430. 15
  31431. ],
  31432. [
  31433. 9,
  31434. 15
  31435. ],
  31436. [
  31437. 9,
  31438. 15
  31439. ],
  31440. [
  31441. 12,
  31442. 128
  31443. ],
  31444. // 000011001000
  31445. [
  31446. 12,
  31447. 192
  31448. ],
  31449. // 000011001001
  31450. [
  31451. 12,
  31452. 26
  31453. ],
  31454. // 000011001010
  31455. [
  31456. 12,
  31457. 27
  31458. ],
  31459. // 000011001011
  31460. [
  31461. 12,
  31462. 28
  31463. ],
  31464. // 000011001100
  31465. [
  31466. 12,
  31467. 29
  31468. ],
  31469. // 000011001101
  31470. [
  31471. 11,
  31472. 19
  31473. ],
  31474. [
  31475. 11,
  31476. 19
  31477. ],
  31478. // 00001100111x
  31479. [
  31480. 11,
  31481. 20
  31482. ],
  31483. [
  31484. 11,
  31485. 20
  31486. ],
  31487. // 00001101000x
  31488. [
  31489. 12,
  31490. 34
  31491. ],
  31492. // 000011010010
  31493. [
  31494. 12,
  31495. 35
  31496. ],
  31497. // 000011010011
  31498. [
  31499. 12,
  31500. 36
  31501. ],
  31502. // 000011010100
  31503. [
  31504. 12,
  31505. 37
  31506. ],
  31507. // 000011010101
  31508. [
  31509. 12,
  31510. 38
  31511. ],
  31512. // 000011010110
  31513. [
  31514. 12,
  31515. 39
  31516. ],
  31517. // 000011010111
  31518. [
  31519. 11,
  31520. 21
  31521. ],
  31522. [
  31523. 11,
  31524. 21
  31525. ],
  31526. // 00001101100x
  31527. [
  31528. 12,
  31529. 42
  31530. ],
  31531. // 000011011010
  31532. [
  31533. 12,
  31534. 43
  31535. ],
  31536. // 000011011011
  31537. [
  31538. 10,
  31539. 0
  31540. ],
  31541. [
  31542. 10,
  31543. 0
  31544. ],
  31545. [
  31546. 10,
  31547. 0
  31548. ],
  31549. [
  31550. 10,
  31551. 0
  31552. ],
  31553. // 0000110111xx
  31554. [
  31555. 7,
  31556. 12
  31557. ],
  31558. [
  31559. 7,
  31560. 12
  31561. ],
  31562. [
  31563. 7,
  31564. 12
  31565. ],
  31566. [
  31567. 7,
  31568. 12
  31569. ],
  31570. // 0000111xxxxx
  31571. [
  31572. 7,
  31573. 12
  31574. ],
  31575. [
  31576. 7,
  31577. 12
  31578. ],
  31579. [
  31580. 7,
  31581. 12
  31582. ],
  31583. [
  31584. 7,
  31585. 12
  31586. ],
  31587. [
  31588. 7,
  31589. 12
  31590. ],
  31591. [
  31592. 7,
  31593. 12
  31594. ],
  31595. [
  31596. 7,
  31597. 12
  31598. ],
  31599. [
  31600. 7,
  31601. 12
  31602. ],
  31603. [
  31604. 7,
  31605. 12
  31606. ],
  31607. [
  31608. 7,
  31609. 12
  31610. ],
  31611. [
  31612. 7,
  31613. 12
  31614. ],
  31615. [
  31616. 7,
  31617. 12
  31618. ],
  31619. [
  31620. 7,
  31621. 12
  31622. ],
  31623. [
  31624. 7,
  31625. 12
  31626. ],
  31627. [
  31628. 7,
  31629. 12
  31630. ],
  31631. [
  31632. 7,
  31633. 12
  31634. ],
  31635. [
  31636. 7,
  31637. 12
  31638. ],
  31639. [
  31640. 7,
  31641. 12
  31642. ],
  31643. [
  31644. 7,
  31645. 12
  31646. ],
  31647. [
  31648. 7,
  31649. 12
  31650. ],
  31651. [
  31652. 7,
  31653. 12
  31654. ],
  31655. [
  31656. 7,
  31657. 12
  31658. ],
  31659. [
  31660. 7,
  31661. 12
  31662. ],
  31663. [
  31664. 7,
  31665. 12
  31666. ],
  31667. [
  31668. 7,
  31669. 12
  31670. ],
  31671. [
  31672. 7,
  31673. 12
  31674. ],
  31675. [
  31676. 7,
  31677. 12
  31678. ],
  31679. [
  31680. 7,
  31681. 12
  31682. ]
  31683. ];
  31684. var blackTable3 = [
  31685. [
  31686. -1,
  31687. -1
  31688. ],
  31689. [
  31690. -1,
  31691. -1
  31692. ],
  31693. [
  31694. -1,
  31695. -1
  31696. ],
  31697. [
  31698. -1,
  31699. -1
  31700. ],
  31701. // 0000xx
  31702. [
  31703. 6,
  31704. 9
  31705. ],
  31706. // 000100
  31707. [
  31708. 6,
  31709. 8
  31710. ],
  31711. // 000101
  31712. [
  31713. 5,
  31714. 7
  31715. ],
  31716. [
  31717. 5,
  31718. 7
  31719. ],
  31720. // 00011x
  31721. [
  31722. 4,
  31723. 6
  31724. ],
  31725. [
  31726. 4,
  31727. 6
  31728. ],
  31729. [
  31730. 4,
  31731. 6
  31732. ],
  31733. [
  31734. 4,
  31735. 6
  31736. ],
  31737. // 0010xx
  31738. [
  31739. 4,
  31740. 5
  31741. ],
  31742. [
  31743. 4,
  31744. 5
  31745. ],
  31746. [
  31747. 4,
  31748. 5
  31749. ],
  31750. [
  31751. 4,
  31752. 5
  31753. ],
  31754. // 0011xx
  31755. [
  31756. 3,
  31757. 1
  31758. ],
  31759. [
  31760. 3,
  31761. 1
  31762. ],
  31763. [
  31764. 3,
  31765. 1
  31766. ],
  31767. [
  31768. 3,
  31769. 1
  31770. ],
  31771. // 010xxx
  31772. [
  31773. 3,
  31774. 1
  31775. ],
  31776. [
  31777. 3,
  31778. 1
  31779. ],
  31780. [
  31781. 3,
  31782. 1
  31783. ],
  31784. [
  31785. 3,
  31786. 1
  31787. ],
  31788. [
  31789. 3,
  31790. 4
  31791. ],
  31792. [
  31793. 3,
  31794. 4
  31795. ],
  31796. [
  31797. 3,
  31798. 4
  31799. ],
  31800. [
  31801. 3,
  31802. 4
  31803. ],
  31804. // 011xxx
  31805. [
  31806. 3,
  31807. 4
  31808. ],
  31809. [
  31810. 3,
  31811. 4
  31812. ],
  31813. [
  31814. 3,
  31815. 4
  31816. ],
  31817. [
  31818. 3,
  31819. 4
  31820. ],
  31821. [
  31822. 2,
  31823. 3
  31824. ],
  31825. [
  31826. 2,
  31827. 3
  31828. ],
  31829. [
  31830. 2,
  31831. 3
  31832. ],
  31833. [
  31834. 2,
  31835. 3
  31836. ],
  31837. // 10xxxx
  31838. [
  31839. 2,
  31840. 3
  31841. ],
  31842. [
  31843. 2,
  31844. 3
  31845. ],
  31846. [
  31847. 2,
  31848. 3
  31849. ],
  31850. [
  31851. 2,
  31852. 3
  31853. ],
  31854. [
  31855. 2,
  31856. 3
  31857. ],
  31858. [
  31859. 2,
  31860. 3
  31861. ],
  31862. [
  31863. 2,
  31864. 3
  31865. ],
  31866. [
  31867. 2,
  31868. 3
  31869. ],
  31870. [
  31871. 2,
  31872. 3
  31873. ],
  31874. [
  31875. 2,
  31876. 3
  31877. ],
  31878. [
  31879. 2,
  31880. 3
  31881. ],
  31882. [
  31883. 2,
  31884. 3
  31885. ],
  31886. [
  31887. 2,
  31888. 2
  31889. ],
  31890. [
  31891. 2,
  31892. 2
  31893. ],
  31894. [
  31895. 2,
  31896. 2
  31897. ],
  31898. [
  31899. 2,
  31900. 2
  31901. ],
  31902. // 11xxxx
  31903. [
  31904. 2,
  31905. 2
  31906. ],
  31907. [
  31908. 2,
  31909. 2
  31910. ],
  31911. [
  31912. 2,
  31913. 2
  31914. ],
  31915. [
  31916. 2,
  31917. 2
  31918. ],
  31919. [
  31920. 2,
  31921. 2
  31922. ],
  31923. [
  31924. 2,
  31925. 2
  31926. ],
  31927. [
  31928. 2,
  31929. 2
  31930. ],
  31931. [
  31932. 2,
  31933. 2
  31934. ],
  31935. [
  31936. 2,
  31937. 2
  31938. ],
  31939. [
  31940. 2,
  31941. 2
  31942. ],
  31943. [
  31944. 2,
  31945. 2
  31946. ],
  31947. [
  31948. 2,
  31949. 2
  31950. ]
  31951. ];
  31952. function CCITTFaxStream(str, maybeLength, params) {
  31953. this.str = str;
  31954. this.dict = str.dict;
  31955. params = params || Dict.empty;
  31956. this.encoding = params.get('K') || 0;
  31957. this.eoline = params.get('EndOfLine') || false;
  31958. this.byteAlign = params.get('EncodedByteAlign') || false;
  31959. this.columns = params.get('Columns') || 1728;
  31960. this.rows = params.get('Rows') || 0;
  31961. var eoblock = params.get('EndOfBlock');
  31962. if (eoblock === null || eoblock === undefined) {
  31963. eoblock = true;
  31964. }
  31965. this.eoblock = eoblock;
  31966. this.black = params.get('BlackIs1') || false;
  31967. this.codingLine = new Uint32Array(this.columns + 1);
  31968. this.refLine = new Uint32Array(this.columns + 2);
  31969. this.codingLine[0] = this.columns;
  31970. this.codingPos = 0;
  31971. this.row = 0;
  31972. this.nextLine2D = this.encoding < 0;
  31973. this.inputBits = 0;
  31974. this.inputBuf = 0;
  31975. this.outputBits = 0;
  31976. var code1;
  31977. while ((code1 = this.lookBits(12)) === 0) {
  31978. this.eatBits(1);
  31979. }
  31980. if (code1 === 1) {
  31981. this.eatBits(12);
  31982. }
  31983. if (this.encoding > 0) {
  31984. this.nextLine2D = !this.lookBits(1);
  31985. this.eatBits(1);
  31986. }
  31987. DecodeStream.call(this, maybeLength);
  31988. }
  31989. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31990. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31991. while (!this.eof) {
  31992. var c = this.lookChar();
  31993. this.ensureBuffer(this.bufferLength + 1);
  31994. this.buffer[this.bufferLength++] = c;
  31995. }
  31996. };
  31997. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  31998. var codingLine = this.codingLine;
  31999. var codingPos = this.codingPos;
  32000. if (a1 > codingLine[codingPos]) {
  32001. if (a1 > this.columns) {
  32002. info('row is wrong length');
  32003. this.err = true;
  32004. a1 = this.columns;
  32005. }
  32006. if (codingPos & 1 ^ blackPixels) {
  32007. ++codingPos;
  32008. }
  32009. codingLine[codingPos] = a1;
  32010. }
  32011. this.codingPos = codingPos;
  32012. };
  32013. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  32014. var codingLine = this.codingLine;
  32015. var codingPos = this.codingPos;
  32016. if (a1 > codingLine[codingPos]) {
  32017. if (a1 > this.columns) {
  32018. info('row is wrong length');
  32019. this.err = true;
  32020. a1 = this.columns;
  32021. }
  32022. if (codingPos & 1 ^ blackPixels) {
  32023. ++codingPos;
  32024. }
  32025. codingLine[codingPos] = a1;
  32026. } else if (a1 < codingLine[codingPos]) {
  32027. if (a1 < 0) {
  32028. info('invalid code');
  32029. this.err = true;
  32030. a1 = 0;
  32031. }
  32032. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  32033. --codingPos;
  32034. }
  32035. codingLine[codingPos] = a1;
  32036. }
  32037. this.codingPos = codingPos;
  32038. };
  32039. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  32040. var refLine = this.refLine;
  32041. var codingLine = this.codingLine;
  32042. var columns = this.columns;
  32043. var refPos, blackPixels, bits, i;
  32044. if (this.outputBits === 0) {
  32045. if (this.eof) {
  32046. return null;
  32047. }
  32048. this.err = false;
  32049. var code1, code2, code3;
  32050. if (this.nextLine2D) {
  32051. for (i = 0; codingLine[i] < columns; ++i) {
  32052. refLine[i] = codingLine[i];
  32053. }
  32054. refLine[i++] = columns;
  32055. refLine[i] = columns;
  32056. codingLine[0] = 0;
  32057. this.codingPos = 0;
  32058. refPos = 0;
  32059. blackPixels = 0;
  32060. while (codingLine[this.codingPos] < columns) {
  32061. code1 = this.getTwoDimCode();
  32062. switch (code1) {
  32063. case twoDimPass:
  32064. this.addPixels(refLine[refPos + 1], blackPixels);
  32065. if (refLine[refPos + 1] < columns) {
  32066. refPos += 2;
  32067. }
  32068. break;
  32069. case twoDimHoriz:
  32070. code1 = code2 = 0;
  32071. if (blackPixels) {
  32072. do {
  32073. code1 += code3 = this.getBlackCode();
  32074. } while (code3 >= 64);
  32075. do {
  32076. code2 += code3 = this.getWhiteCode();
  32077. } while (code3 >= 64);
  32078. } else {
  32079. do {
  32080. code1 += code3 = this.getWhiteCode();
  32081. } while (code3 >= 64);
  32082. do {
  32083. code2 += code3 = this.getBlackCode();
  32084. } while (code3 >= 64);
  32085. }
  32086. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32087. if (codingLine[this.codingPos] < columns) {
  32088. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  32089. }
  32090. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32091. refPos += 2;
  32092. }
  32093. break;
  32094. case twoDimVertR3:
  32095. this.addPixels(refLine[refPos] + 3, blackPixels);
  32096. blackPixels ^= 1;
  32097. if (codingLine[this.codingPos] < columns) {
  32098. ++refPos;
  32099. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32100. refPos += 2;
  32101. }
  32102. }
  32103. break;
  32104. case twoDimVertR2:
  32105. this.addPixels(refLine[refPos] + 2, blackPixels);
  32106. blackPixels ^= 1;
  32107. if (codingLine[this.codingPos] < columns) {
  32108. ++refPos;
  32109. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32110. refPos += 2;
  32111. }
  32112. }
  32113. break;
  32114. case twoDimVertR1:
  32115. this.addPixels(refLine[refPos] + 1, blackPixels);
  32116. blackPixels ^= 1;
  32117. if (codingLine[this.codingPos] < columns) {
  32118. ++refPos;
  32119. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32120. refPos += 2;
  32121. }
  32122. }
  32123. break;
  32124. case twoDimVert0:
  32125. this.addPixels(refLine[refPos], blackPixels);
  32126. blackPixels ^= 1;
  32127. if (codingLine[this.codingPos] < columns) {
  32128. ++refPos;
  32129. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32130. refPos += 2;
  32131. }
  32132. }
  32133. break;
  32134. case twoDimVertL3:
  32135. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  32136. blackPixels ^= 1;
  32137. if (codingLine[this.codingPos] < columns) {
  32138. if (refPos > 0) {
  32139. --refPos;
  32140. } else {
  32141. ++refPos;
  32142. }
  32143. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32144. refPos += 2;
  32145. }
  32146. }
  32147. break;
  32148. case twoDimVertL2:
  32149. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  32150. blackPixels ^= 1;
  32151. if (codingLine[this.codingPos] < columns) {
  32152. if (refPos > 0) {
  32153. --refPos;
  32154. } else {
  32155. ++refPos;
  32156. }
  32157. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32158. refPos += 2;
  32159. }
  32160. }
  32161. break;
  32162. case twoDimVertL1:
  32163. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  32164. blackPixels ^= 1;
  32165. if (codingLine[this.codingPos] < columns) {
  32166. if (refPos > 0) {
  32167. --refPos;
  32168. } else {
  32169. ++refPos;
  32170. }
  32171. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32172. refPos += 2;
  32173. }
  32174. }
  32175. break;
  32176. case ccittEOF:
  32177. this.addPixels(columns, 0);
  32178. this.eof = true;
  32179. break;
  32180. default:
  32181. info('bad 2d code');
  32182. this.addPixels(columns, 0);
  32183. this.err = true;
  32184. }
  32185. }
  32186. } else {
  32187. codingLine[0] = 0;
  32188. this.codingPos = 0;
  32189. blackPixels = 0;
  32190. while (codingLine[this.codingPos] < columns) {
  32191. code1 = 0;
  32192. if (blackPixels) {
  32193. do {
  32194. code1 += code3 = this.getBlackCode();
  32195. } while (code3 >= 64);
  32196. } else {
  32197. do {
  32198. code1 += code3 = this.getWhiteCode();
  32199. } while (code3 >= 64);
  32200. }
  32201. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32202. blackPixels ^= 1;
  32203. }
  32204. }
  32205. var gotEOL = false;
  32206. if (this.byteAlign) {
  32207. this.inputBits &= ~7;
  32208. }
  32209. if (!this.eoblock && this.row === this.rows - 1) {
  32210. this.eof = true;
  32211. } else {
  32212. code1 = this.lookBits(12);
  32213. if (this.eoline) {
  32214. while (code1 !== ccittEOF && code1 !== 1) {
  32215. this.eatBits(1);
  32216. code1 = this.lookBits(12);
  32217. }
  32218. } else {
  32219. while (code1 === 0) {
  32220. this.eatBits(1);
  32221. code1 = this.lookBits(12);
  32222. }
  32223. }
  32224. if (code1 === 1) {
  32225. this.eatBits(12);
  32226. gotEOL = true;
  32227. } else if (code1 === ccittEOF) {
  32228. this.eof = true;
  32229. }
  32230. }
  32231. if (!this.eof && this.encoding > 0) {
  32232. this.nextLine2D = !this.lookBits(1);
  32233. this.eatBits(1);
  32234. }
  32235. if (this.eoblock && gotEOL && this.byteAlign) {
  32236. code1 = this.lookBits(12);
  32237. if (code1 === 1) {
  32238. this.eatBits(12);
  32239. if (this.encoding > 0) {
  32240. this.lookBits(1);
  32241. this.eatBits(1);
  32242. }
  32243. if (this.encoding >= 0) {
  32244. for (i = 0; i < 4; ++i) {
  32245. code1 = this.lookBits(12);
  32246. if (code1 !== 1) {
  32247. info('bad rtc code: ' + code1);
  32248. }
  32249. this.eatBits(12);
  32250. if (this.encoding > 0) {
  32251. this.lookBits(1);
  32252. this.eatBits(1);
  32253. }
  32254. }
  32255. }
  32256. this.eof = true;
  32257. }
  32258. } else if (this.err && this.eoline) {
  32259. while (true) {
  32260. code1 = this.lookBits(13);
  32261. if (code1 === ccittEOF) {
  32262. this.eof = true;
  32263. return null;
  32264. }
  32265. if (code1 >> 1 === 1) {
  32266. break;
  32267. }
  32268. this.eatBits(1);
  32269. }
  32270. this.eatBits(12);
  32271. if (this.encoding > 0) {
  32272. this.eatBits(1);
  32273. this.nextLine2D = !(code1 & 1);
  32274. }
  32275. }
  32276. if (codingLine[0] > 0) {
  32277. this.outputBits = codingLine[this.codingPos = 0];
  32278. } else {
  32279. this.outputBits = codingLine[this.codingPos = 1];
  32280. }
  32281. this.row++;
  32282. }
  32283. var c;
  32284. if (this.outputBits >= 8) {
  32285. c = this.codingPos & 1 ? 0 : 0xFF;
  32286. this.outputBits -= 8;
  32287. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  32288. this.codingPos++;
  32289. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  32290. }
  32291. } else {
  32292. bits = 8;
  32293. c = 0;
  32294. do {
  32295. if (this.outputBits > bits) {
  32296. c <<= bits;
  32297. if (!(this.codingPos & 1)) {
  32298. c |= 0xFF >> 8 - bits;
  32299. }
  32300. this.outputBits -= bits;
  32301. bits = 0;
  32302. } else {
  32303. c <<= this.outputBits;
  32304. if (!(this.codingPos & 1)) {
  32305. c |= 0xFF >> 8 - this.outputBits;
  32306. }
  32307. bits -= this.outputBits;
  32308. this.outputBits = 0;
  32309. if (codingLine[this.codingPos] < columns) {
  32310. this.codingPos++;
  32311. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  32312. } else if (bits > 0) {
  32313. c <<= bits;
  32314. bits = 0;
  32315. }
  32316. }
  32317. } while (bits);
  32318. }
  32319. if (this.black) {
  32320. c ^= 0xFF;
  32321. }
  32322. return c;
  32323. };
  32324. // This functions returns the code found from the table.
  32325. // The start and end parameters set the boundaries for searching the table.
  32326. // The limit parameter is optional. Function returns an array with three
  32327. // values. The first array element indicates whether a valid code is being
  32328. // returned. The second array element is the actual code. The third array
  32329. // element indicates whether EOF was reached.
  32330. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  32331. var limitValue = limit || 0;
  32332. for (var i = start; i <= end; ++i) {
  32333. var code = this.lookBits(i);
  32334. if (code === ccittEOF) {
  32335. return [
  32336. true,
  32337. 1,
  32338. false
  32339. ];
  32340. }
  32341. if (i < end) {
  32342. code <<= end - i;
  32343. }
  32344. if (!limitValue || code >= limitValue) {
  32345. var p = table[code - limitValue];
  32346. if (p[0] === i) {
  32347. this.eatBits(i);
  32348. return [
  32349. true,
  32350. p[1],
  32351. true
  32352. ];
  32353. }
  32354. }
  32355. }
  32356. return [
  32357. false,
  32358. 0,
  32359. false
  32360. ];
  32361. };
  32362. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  32363. var code = 0;
  32364. var p;
  32365. if (this.eoblock) {
  32366. code = this.lookBits(7);
  32367. p = twoDimTable[code];
  32368. if (p && p[0] > 0) {
  32369. this.eatBits(p[0]);
  32370. return p[1];
  32371. }
  32372. } else {
  32373. var result = this.findTableCode(1, 7, twoDimTable);
  32374. if (result[0] && result[2]) {
  32375. return result[1];
  32376. }
  32377. }
  32378. info('Bad two dim code');
  32379. return ccittEOF;
  32380. };
  32381. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  32382. var code = 0;
  32383. var p;
  32384. if (this.eoblock) {
  32385. code = this.lookBits(12);
  32386. if (code === ccittEOF) {
  32387. return 1;
  32388. }
  32389. if (code >> 5 === 0) {
  32390. p = whiteTable1[code];
  32391. } else {
  32392. p = whiteTable2[code >> 3];
  32393. }
  32394. if (p[0] > 0) {
  32395. this.eatBits(p[0]);
  32396. return p[1];
  32397. }
  32398. } else {
  32399. var result = this.findTableCode(1, 9, whiteTable2);
  32400. if (result[0]) {
  32401. return result[1];
  32402. }
  32403. result = this.findTableCode(11, 12, whiteTable1);
  32404. if (result[0]) {
  32405. return result[1];
  32406. }
  32407. }
  32408. info('bad white code');
  32409. this.eatBits(1);
  32410. return 1;
  32411. };
  32412. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  32413. var code, p;
  32414. if (this.eoblock) {
  32415. code = this.lookBits(13);
  32416. if (code === ccittEOF) {
  32417. return 1;
  32418. }
  32419. if (code >> 7 === 0) {
  32420. p = blackTable1[code];
  32421. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  32422. p = blackTable2[(code >> 1) - 64];
  32423. } else {
  32424. p = blackTable3[code >> 7];
  32425. }
  32426. if (p[0] > 0) {
  32427. this.eatBits(p[0]);
  32428. return p[1];
  32429. }
  32430. } else {
  32431. var result = this.findTableCode(2, 6, blackTable3);
  32432. if (result[0]) {
  32433. return result[1];
  32434. }
  32435. result = this.findTableCode(7, 12, blackTable2, 64);
  32436. if (result[0]) {
  32437. return result[1];
  32438. }
  32439. result = this.findTableCode(10, 13, blackTable1);
  32440. if (result[0]) {
  32441. return result[1];
  32442. }
  32443. }
  32444. info('bad black code');
  32445. this.eatBits(1);
  32446. return 1;
  32447. };
  32448. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  32449. var c;
  32450. while (this.inputBits < n) {
  32451. if ((c = this.str.getByte()) === -1) {
  32452. if (this.inputBits === 0) {
  32453. return ccittEOF;
  32454. }
  32455. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  32456. }
  32457. this.inputBuf = this.inputBuf << 8 | c;
  32458. this.inputBits += 8;
  32459. }
  32460. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  32461. };
  32462. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  32463. if ((this.inputBits -= n) < 0) {
  32464. this.inputBits = 0;
  32465. }
  32466. };
  32467. return CCITTFaxStream;
  32468. }();
  32469. var LZWStream = function LZWStreamClosure() {
  32470. function LZWStream(str, maybeLength, earlyChange) {
  32471. this.str = str;
  32472. this.dict = str.dict;
  32473. this.cachedData = 0;
  32474. this.bitsCached = 0;
  32475. var maxLzwDictionarySize = 4096;
  32476. var lzwState = {
  32477. earlyChange: earlyChange,
  32478. codeLength: 9,
  32479. nextCode: 258,
  32480. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  32481. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  32482. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  32483. currentSequence: new Uint8Array(maxLzwDictionarySize),
  32484. currentSequenceLength: 0
  32485. };
  32486. for (var i = 0; i < 256; ++i) {
  32487. lzwState.dictionaryValues[i] = i;
  32488. lzwState.dictionaryLengths[i] = 1;
  32489. }
  32490. this.lzwState = lzwState;
  32491. DecodeStream.call(this, maybeLength);
  32492. }
  32493. LZWStream.prototype = Object.create(DecodeStream.prototype);
  32494. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  32495. var bitsCached = this.bitsCached;
  32496. var cachedData = this.cachedData;
  32497. while (bitsCached < n) {
  32498. var c = this.str.getByte();
  32499. if (c === -1) {
  32500. this.eof = true;
  32501. return null;
  32502. }
  32503. cachedData = cachedData << 8 | c;
  32504. bitsCached += 8;
  32505. }
  32506. this.bitsCached = bitsCached -= n;
  32507. this.cachedData = cachedData;
  32508. this.lastCode = null;
  32509. return cachedData >>> bitsCached & (1 << n) - 1;
  32510. };
  32511. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  32512. var blockSize = 512;
  32513. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  32514. var i, j, q;
  32515. var lzwState = this.lzwState;
  32516. if (!lzwState) {
  32517. return;
  32518. }
  32519. // eof was found
  32520. var earlyChange = lzwState.earlyChange;
  32521. var nextCode = lzwState.nextCode;
  32522. var dictionaryValues = lzwState.dictionaryValues;
  32523. var dictionaryLengths = lzwState.dictionaryLengths;
  32524. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  32525. var codeLength = lzwState.codeLength;
  32526. var prevCode = lzwState.prevCode;
  32527. var currentSequence = lzwState.currentSequence;
  32528. var currentSequenceLength = lzwState.currentSequenceLength;
  32529. var decodedLength = 0;
  32530. var currentBufferLength = this.bufferLength;
  32531. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32532. for (i = 0; i < blockSize; i++) {
  32533. var code = this.readBits(codeLength);
  32534. var hasPrev = currentSequenceLength > 0;
  32535. if (code < 256) {
  32536. currentSequence[0] = code;
  32537. currentSequenceLength = 1;
  32538. } else if (code >= 258) {
  32539. if (code < nextCode) {
  32540. currentSequenceLength = dictionaryLengths[code];
  32541. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  32542. currentSequence[j] = dictionaryValues[q];
  32543. q = dictionaryPrevCodes[q];
  32544. }
  32545. } else {
  32546. currentSequence[currentSequenceLength++] = currentSequence[0];
  32547. }
  32548. } else if (code === 256) {
  32549. codeLength = 9;
  32550. nextCode = 258;
  32551. currentSequenceLength = 0;
  32552. continue;
  32553. } else {
  32554. this.eof = true;
  32555. delete this.lzwState;
  32556. break;
  32557. }
  32558. if (hasPrev) {
  32559. dictionaryPrevCodes[nextCode] = prevCode;
  32560. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  32561. dictionaryValues[nextCode] = currentSequence[0];
  32562. nextCode++;
  32563. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  32564. }
  32565. prevCode = code;
  32566. decodedLength += currentSequenceLength;
  32567. if (estimatedDecodedSize < decodedLength) {
  32568. do {
  32569. estimatedDecodedSize += decodedSizeDelta;
  32570. } while (estimatedDecodedSize < decodedLength);
  32571. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32572. }
  32573. for (j = 0; j < currentSequenceLength; j++) {
  32574. buffer[currentBufferLength++] = currentSequence[j];
  32575. }
  32576. }
  32577. lzwState.nextCode = nextCode;
  32578. lzwState.codeLength = codeLength;
  32579. lzwState.prevCode = prevCode;
  32580. lzwState.currentSequenceLength = currentSequenceLength;
  32581. this.bufferLength = currentBufferLength;
  32582. };
  32583. return LZWStream;
  32584. }();
  32585. var NullStream = function NullStreamClosure() {
  32586. function NullStream() {
  32587. Stream.call(this, new Uint8Array(0));
  32588. }
  32589. NullStream.prototype = Stream.prototype;
  32590. return NullStream;
  32591. }();
  32592. exports.Ascii85Stream = Ascii85Stream;
  32593. exports.AsciiHexStream = AsciiHexStream;
  32594. exports.CCITTFaxStream = CCITTFaxStream;
  32595. exports.DecryptStream = DecryptStream;
  32596. exports.DecodeStream = DecodeStream;
  32597. exports.FlateStream = FlateStream;
  32598. exports.Jbig2Stream = Jbig2Stream;
  32599. exports.JpegStream = JpegStream;
  32600. exports.JpxStream = JpxStream;
  32601. exports.NullStream = NullStream;
  32602. exports.PredictorStream = PredictorStream;
  32603. exports.RunLengthStream = RunLengthStream;
  32604. exports.Stream = Stream;
  32605. exports.StreamsSequenceStream = StreamsSequenceStream;
  32606. exports.StringStream = StringStream;
  32607. exports.LZWStream = LZWStream;
  32608. }));
  32609. (function (root, factory) {
  32610. factory(root.pdfjsDisplayAnnotationLayer = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  32611. }(this, function (exports, sharedUtil, displayDOMUtils) {
  32612. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  32613. var AnnotationType = sharedUtil.AnnotationType;
  32614. var Util = sharedUtil.Util;
  32615. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  32616. var LinkTarget = displayDOMUtils.LinkTarget;
  32617. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  32618. var warn = sharedUtil.warn;
  32619. var CustomStyle = displayDOMUtils.CustomStyle;
  32620. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  32621. /**
  32622. * @typedef {Object} AnnotationElementParameters
  32623. * @property {Object} data
  32624. * @property {HTMLDivElement} layer
  32625. * @property {PDFPage} page
  32626. * @property {PageViewport} viewport
  32627. * @property {IPDFLinkService} linkService
  32628. * @property {DownloadManager} downloadManager
  32629. * @property {string} imageResourcesPath
  32630. * @property {boolean} renderInteractiveForms
  32631. */
  32632. /**
  32633. * @class
  32634. * @alias AnnotationElementFactory
  32635. */
  32636. function AnnotationElementFactory() {
  32637. }
  32638. AnnotationElementFactory.prototype = /** @lends AnnotationElementFactory.prototype */
  32639. {
  32640. /**
  32641. * @param {AnnotationElementParameters} parameters
  32642. * @returns {AnnotationElement}
  32643. */
  32644. create: function AnnotationElementFactory_create(parameters) {
  32645. var subtype = parameters.data.annotationType;
  32646. switch (subtype) {
  32647. case AnnotationType.LINK:
  32648. return new LinkAnnotationElement(parameters);
  32649. case AnnotationType.TEXT:
  32650. return new TextAnnotationElement(parameters);
  32651. case AnnotationType.WIDGET:
  32652. var fieldType = parameters.data.fieldType;
  32653. switch (fieldType) {
  32654. case 'Tx':
  32655. return new TextWidgetAnnotationElement(parameters);
  32656. case 'Ch':
  32657. return new ChoiceWidgetAnnotationElement(parameters);
  32658. }
  32659. return new WidgetAnnotationElement(parameters);
  32660. case AnnotationType.POPUP:
  32661. return new PopupAnnotationElement(parameters);
  32662. case AnnotationType.HIGHLIGHT:
  32663. return new HighlightAnnotationElement(parameters);
  32664. case AnnotationType.UNDERLINE:
  32665. return new UnderlineAnnotationElement(parameters);
  32666. case AnnotationType.SQUIGGLY:
  32667. return new SquigglyAnnotationElement(parameters);
  32668. case AnnotationType.STRIKEOUT:
  32669. return new StrikeOutAnnotationElement(parameters);
  32670. case AnnotationType.FILEATTACHMENT:
  32671. return new FileAttachmentAnnotationElement(parameters);
  32672. default:
  32673. return new AnnotationElement(parameters);
  32674. }
  32675. }
  32676. };
  32677. /**
  32678. * @class
  32679. * @alias AnnotationElement
  32680. */
  32681. var AnnotationElement = function AnnotationElementClosure() {
  32682. function AnnotationElement(parameters, isRenderable) {
  32683. this.isRenderable = isRenderable || false;
  32684. this.data = parameters.data;
  32685. this.layer = parameters.layer;
  32686. this.page = parameters.page;
  32687. this.viewport = parameters.viewport;
  32688. this.linkService = parameters.linkService;
  32689. this.downloadManager = parameters.downloadManager;
  32690. this.imageResourcesPath = parameters.imageResourcesPath;
  32691. this.renderInteractiveForms = parameters.renderInteractiveForms;
  32692. if (isRenderable) {
  32693. this.container = this._createContainer();
  32694. }
  32695. }
  32696. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */
  32697. {
  32698. /**
  32699. * Create an empty container for the annotation's HTML element.
  32700. *
  32701. * @private
  32702. * @memberof AnnotationElement
  32703. * @returns {HTMLSectionElement}
  32704. */
  32705. _createContainer: function AnnotationElement_createContainer() {
  32706. var data = this.data, page = this.page, viewport = this.viewport;
  32707. var container = document.createElement('section');
  32708. var width = data.rect[2] - data.rect[0];
  32709. var height = data.rect[3] - data.rect[1];
  32710. container.setAttribute('data-annotation-id', data.id);
  32711. // Do *not* modify `data.rect`, since that will corrupt the annotation
  32712. // position on subsequent calls to `_createContainer` (see issue 6804).
  32713. var rect = Util.normalizeRect([
  32714. data.rect[0],
  32715. page.view[3] - data.rect[1] + page.view[1],
  32716. data.rect[2],
  32717. page.view[3] - data.rect[3] + page.view[1]
  32718. ]);
  32719. CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  32720. CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  32721. if (data.borderStyle.width > 0) {
  32722. container.style.borderWidth = data.borderStyle.width + 'px';
  32723. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  32724. // Underline styles only have a bottom border, so we do not need
  32725. // to adjust for all borders. This yields a similar result as
  32726. // Adobe Acrobat/Reader.
  32727. width = width - 2 * data.borderStyle.width;
  32728. height = height - 2 * data.borderStyle.width;
  32729. }
  32730. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  32731. var verticalRadius = data.borderStyle.verticalCornerRadius;
  32732. if (horizontalRadius > 0 || verticalRadius > 0) {
  32733. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  32734. CustomStyle.setProp('borderRadius', container, radius);
  32735. }
  32736. switch (data.borderStyle.style) {
  32737. case AnnotationBorderStyleType.SOLID:
  32738. container.style.borderStyle = 'solid';
  32739. break;
  32740. case AnnotationBorderStyleType.DASHED:
  32741. container.style.borderStyle = 'dashed';
  32742. break;
  32743. case AnnotationBorderStyleType.BEVELED:
  32744. warn('Unimplemented border style: beveled');
  32745. break;
  32746. case AnnotationBorderStyleType.INSET:
  32747. warn('Unimplemented border style: inset');
  32748. break;
  32749. case AnnotationBorderStyleType.UNDERLINE:
  32750. container.style.borderBottomStyle = 'solid';
  32751. break;
  32752. default:
  32753. break;
  32754. }
  32755. if (data.color) {
  32756. container.style.borderColor = Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  32757. } else {
  32758. // Transparent (invisible) border, so do not draw it at all.
  32759. container.style.borderWidth = 0;
  32760. }
  32761. }
  32762. container.style.left = rect[0] + 'px';
  32763. container.style.top = rect[1] + 'px';
  32764. container.style.width = width + 'px';
  32765. container.style.height = height + 'px';
  32766. return container;
  32767. },
  32768. /**
  32769. * Create a popup for the annotation's HTML element. This is used for
  32770. * annotations that do not have a Popup entry in the dictionary, but
  32771. * are of a type that works with popups (such as Highlight annotations).
  32772. *
  32773. * @private
  32774. * @param {HTMLSectionElement} container
  32775. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  32776. * @param {Object} data
  32777. * @memberof AnnotationElement
  32778. */
  32779. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  32780. // If no trigger element is specified, create it.
  32781. if (!trigger) {
  32782. trigger = document.createElement('div');
  32783. trigger.style.height = container.style.height;
  32784. trigger.style.width = container.style.width;
  32785. container.appendChild(trigger);
  32786. }
  32787. var popupElement = new PopupElement({
  32788. container: container,
  32789. trigger: trigger,
  32790. color: data.color,
  32791. title: data.title,
  32792. contents: data.contents,
  32793. hideWrapper: true
  32794. });
  32795. var popup = popupElement.render();
  32796. // Position the popup next to the annotation's container.
  32797. popup.style.left = container.style.width;
  32798. container.appendChild(popup);
  32799. },
  32800. /**
  32801. * Render the annotation's HTML element in the empty container.
  32802. *
  32803. * @public
  32804. * @memberof AnnotationElement
  32805. */
  32806. render: function AnnotationElement_render() {
  32807. throw new Error('Abstract method AnnotationElement.render called');
  32808. }
  32809. };
  32810. return AnnotationElement;
  32811. }();
  32812. /**
  32813. * @class
  32814. * @alias LinkAnnotationElement
  32815. */
  32816. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  32817. function LinkAnnotationElement(parameters) {
  32818. AnnotationElement.call(this, parameters, true);
  32819. }
  32820. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  32821. /**
  32822. * Render the link annotation's HTML element in the empty container.
  32823. *
  32824. * @public
  32825. * @memberof LinkAnnotationElement
  32826. * @returns {HTMLSectionElement}
  32827. */
  32828. render: function LinkAnnotationElement_render() {
  32829. this.container.className = 'linkAnnotation';
  32830. var link = document.createElement('a');
  32831. addLinkAttributes(link, {
  32832. url: this.data.url,
  32833. target: this.data.newWindow ? LinkTarget.BLANK : undefined
  32834. });
  32835. if (!this.data.url) {
  32836. if (this.data.action) {
  32837. this._bindNamedAction(link, this.data.action);
  32838. } else {
  32839. this._bindLink(link, this.data.dest);
  32840. }
  32841. }
  32842. this.container.appendChild(link);
  32843. return this.container;
  32844. },
  32845. /**
  32846. * Bind internal links to the link element.
  32847. *
  32848. * @private
  32849. * @param {Object} link
  32850. * @param {Object} destination
  32851. * @memberof LinkAnnotationElement
  32852. */
  32853. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  32854. var self = this;
  32855. link.href = this.linkService.getDestinationHash(destination);
  32856. link.onclick = function () {
  32857. if (destination) {
  32858. self.linkService.navigateTo(destination);
  32859. }
  32860. return false;
  32861. };
  32862. if (destination) {
  32863. link.className = 'internalLink';
  32864. }
  32865. },
  32866. /**
  32867. * Bind named actions to the link element.
  32868. *
  32869. * @private
  32870. * @param {Object} link
  32871. * @param {Object} action
  32872. * @memberof LinkAnnotationElement
  32873. */
  32874. _bindNamedAction: function LinkAnnotationElement_bindNamedAction(link, action) {
  32875. var self = this;
  32876. link.href = this.linkService.getAnchorUrl('');
  32877. link.onclick = function () {
  32878. self.linkService.executeNamedAction(action);
  32879. return false;
  32880. };
  32881. link.className = 'internalLink';
  32882. }
  32883. });
  32884. return LinkAnnotationElement;
  32885. }();
  32886. /**
  32887. * @class
  32888. * @alias TextAnnotationElement
  32889. */
  32890. var TextAnnotationElement = function TextAnnotationElementClosure() {
  32891. function TextAnnotationElement(parameters) {
  32892. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  32893. AnnotationElement.call(this, parameters, isRenderable);
  32894. }
  32895. Util.inherit(TextAnnotationElement, AnnotationElement, {
  32896. /**
  32897. * Render the text annotation's HTML element in the empty container.
  32898. *
  32899. * @public
  32900. * @memberof TextAnnotationElement
  32901. * @returns {HTMLSectionElement}
  32902. */
  32903. render: function TextAnnotationElement_render() {
  32904. this.container.className = 'textAnnotation';
  32905. var image = document.createElement('img');
  32906. image.style.height = this.container.style.height;
  32907. image.style.width = this.container.style.width;
  32908. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  32909. image.alt = '[{{type}} Annotation]';
  32910. image.dataset.l10nId = 'text_annotation_type';
  32911. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  32912. if (!this.data.hasPopup) {
  32913. this._createPopup(this.container, image, this.data);
  32914. }
  32915. this.container.appendChild(image);
  32916. return this.container;
  32917. }
  32918. });
  32919. return TextAnnotationElement;
  32920. }();
  32921. /**
  32922. * @class
  32923. * @alias WidgetAnnotationElement
  32924. */
  32925. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  32926. function WidgetAnnotationElement(parameters, isRenderable) {
  32927. AnnotationElement.call(this, parameters, isRenderable);
  32928. }
  32929. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  32930. /**
  32931. * Render the widget annotation's HTML element in the empty container.
  32932. *
  32933. * @public
  32934. * @memberof WidgetAnnotationElement
  32935. * @returns {HTMLSectionElement}
  32936. */
  32937. render: function WidgetAnnotationElement_render() {
  32938. // Show only the container for unsupported field types.
  32939. return this.container;
  32940. }
  32941. });
  32942. return WidgetAnnotationElement;
  32943. }();
  32944. /**
  32945. * @class
  32946. * @alias TextWidgetAnnotationElement
  32947. */
  32948. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  32949. var TEXT_ALIGNMENT = [
  32950. 'left',
  32951. 'center',
  32952. 'right'
  32953. ];
  32954. function TextWidgetAnnotationElement(parameters) {
  32955. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  32956. WidgetAnnotationElement.call(this, parameters, isRenderable);
  32957. }
  32958. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  32959. /**
  32960. * Render the text widget annotation's HTML element in the empty container.
  32961. *
  32962. * @public
  32963. * @memberof TextWidgetAnnotationElement
  32964. * @returns {HTMLSectionElement}
  32965. */
  32966. render: function TextWidgetAnnotationElement_render() {
  32967. this.container.className = 'textWidgetAnnotation';
  32968. var element = null;
  32969. if (this.renderInteractiveForms) {
  32970. // NOTE: We cannot set the values using `element.value` below, since it
  32971. // prevents the AnnotationLayer rasterizer in `test/driver.js`
  32972. // from parsing the elements correctly for the reference tests.
  32973. if (this.data.multiLine) {
  32974. element = document.createElement('textarea');
  32975. element.textContent = this.data.fieldValue;
  32976. } else {
  32977. element = document.createElement('input');
  32978. element.type = 'text';
  32979. element.setAttribute('value', this.data.fieldValue);
  32980. }
  32981. element.disabled = this.data.readOnly;
  32982. if (this.data.maxLen !== null) {
  32983. element.maxLength = this.data.maxLen;
  32984. }
  32985. if (this.data.comb) {
  32986. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  32987. var combWidth = fieldWidth / this.data.maxLen;
  32988. element.classList.add('comb');
  32989. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  32990. }
  32991. } else {
  32992. element = document.createElement('div');
  32993. element.textContent = this.data.fieldValue;
  32994. element.style.verticalAlign = 'middle';
  32995. element.style.display = 'table-cell';
  32996. var font = null;
  32997. if (this.data.fontRefName) {
  32998. font = this.page.commonObjs.getData(this.data.fontRefName);
  32999. }
  33000. this._setTextStyle(element, font);
  33001. }
  33002. if (this.data.textAlignment !== null) {
  33003. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  33004. }
  33005. this.container.appendChild(element);
  33006. return this.container;
  33007. },
  33008. /**
  33009. * Apply text styles to the text in the element.
  33010. *
  33011. * @private
  33012. * @param {HTMLDivElement} element
  33013. * @param {Object} font
  33014. * @memberof TextWidgetAnnotationElement
  33015. */
  33016. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  33017. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  33018. var style = element.style;
  33019. style.fontSize = this.data.fontSize + 'px';
  33020. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  33021. if (!font) {
  33022. return;
  33023. }
  33024. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  33025. style.fontStyle = font.italic ? 'italic' : 'normal';
  33026. // Use a reasonable default font if the font doesn't specify a fallback.
  33027. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  33028. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  33029. style.fontFamily = fontFamily + fallbackName;
  33030. }
  33031. });
  33032. return TextWidgetAnnotationElement;
  33033. }();
  33034. /**
  33035. * @class
  33036. * @alias ChoiceWidgetAnnotationElement
  33037. */
  33038. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  33039. function ChoiceWidgetAnnotationElement(parameters) {
  33040. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  33041. }
  33042. Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  33043. /**
  33044. * Render the choice widget annotation's HTML element in the empty
  33045. * container.
  33046. *
  33047. * @public
  33048. * @memberof ChoiceWidgetAnnotationElement
  33049. * @returns {HTMLSectionElement}
  33050. */
  33051. render: function ChoiceWidgetAnnotationElement_render() {
  33052. this.container.className = 'choiceWidgetAnnotation';
  33053. var selectElement = document.createElement('select');
  33054. selectElement.disabled = this.data.readOnly;
  33055. if (!this.data.combo) {
  33056. // List boxes have a size and (optionally) multiple selection.
  33057. selectElement.size = this.data.options.length;
  33058. if (this.data.multiSelect) {
  33059. selectElement.multiple = true;
  33060. }
  33061. }
  33062. // Insert the options into the choice field.
  33063. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  33064. var option = this.data.options[i];
  33065. var optionElement = document.createElement('option');
  33066. optionElement.textContent = option.displayValue;
  33067. optionElement.value = option.exportValue;
  33068. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  33069. optionElement.setAttribute('selected', true);
  33070. }
  33071. selectElement.appendChild(optionElement);
  33072. }
  33073. this.container.appendChild(selectElement);
  33074. return this.container;
  33075. }
  33076. });
  33077. return ChoiceWidgetAnnotationElement;
  33078. }();
  33079. /**
  33080. * @class
  33081. * @alias PopupAnnotationElement
  33082. */
  33083. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  33084. function PopupAnnotationElement(parameters) {
  33085. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  33086. AnnotationElement.call(this, parameters, isRenderable);
  33087. }
  33088. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  33089. /**
  33090. * Render the popup annotation's HTML element in the empty container.
  33091. *
  33092. * @public
  33093. * @memberof PopupAnnotationElement
  33094. * @returns {HTMLSectionElement}
  33095. */
  33096. render: function PopupAnnotationElement_render() {
  33097. this.container.className = 'popupAnnotation';
  33098. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  33099. var parentElement = this.layer.querySelector(selector);
  33100. if (!parentElement) {
  33101. return this.container;
  33102. }
  33103. var popup = new PopupElement({
  33104. container: this.container,
  33105. trigger: parentElement,
  33106. color: this.data.color,
  33107. title: this.data.title,
  33108. contents: this.data.contents
  33109. });
  33110. // Position the popup next to the parent annotation's container.
  33111. // PDF viewers ignore a popup annotation's rectangle.
  33112. var parentLeft = parseFloat(parentElement.style.left);
  33113. var parentWidth = parseFloat(parentElement.style.width);
  33114. CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  33115. this.container.style.left = parentLeft + parentWidth + 'px';
  33116. this.container.appendChild(popup.render());
  33117. return this.container;
  33118. }
  33119. });
  33120. return PopupAnnotationElement;
  33121. }();
  33122. /**
  33123. * @class
  33124. * @alias PopupElement
  33125. */
  33126. var PopupElement = function PopupElementClosure() {
  33127. var BACKGROUND_ENLIGHT = 0.7;
  33128. function PopupElement(parameters) {
  33129. this.container = parameters.container;
  33130. this.trigger = parameters.trigger;
  33131. this.color = parameters.color;
  33132. this.title = parameters.title;
  33133. this.contents = parameters.contents;
  33134. this.hideWrapper = parameters.hideWrapper || false;
  33135. this.pinned = false;
  33136. }
  33137. PopupElement.prototype = /** @lends PopupElement.prototype */
  33138. {
  33139. /**
  33140. * Render the popup's HTML element.
  33141. *
  33142. * @public
  33143. * @memberof PopupElement
  33144. * @returns {HTMLSectionElement}
  33145. */
  33146. render: function PopupElement_render() {
  33147. var wrapper = document.createElement('div');
  33148. wrapper.className = 'popupWrapper';
  33149. // For Popup annotations we hide the entire section because it contains
  33150. // only the popup. However, for Text annotations without a separate Popup
  33151. // annotation, we cannot hide the entire container as the image would
  33152. // disappear too. In that special case, hiding the wrapper suffices.
  33153. this.hideElement = this.hideWrapper ? wrapper : this.container;
  33154. this.hideElement.setAttribute('hidden', true);
  33155. var popup = document.createElement('div');
  33156. popup.className = 'popup';
  33157. var color = this.color;
  33158. if (color) {
  33159. // Enlighten the color.
  33160. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  33161. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  33162. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  33163. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  33164. }
  33165. var contents = this._formatContents(this.contents);
  33166. var title = document.createElement('h1');
  33167. title.textContent = this.title;
  33168. // Attach the event listeners to the trigger element.
  33169. this.trigger.addEventListener('click', this._toggle.bind(this));
  33170. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  33171. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  33172. popup.addEventListener('click', this._hide.bind(this, true));
  33173. popup.appendChild(title);
  33174. popup.appendChild(contents);
  33175. wrapper.appendChild(popup);
  33176. return wrapper;
  33177. },
  33178. /**
  33179. * Format the contents of the popup by adding newlines where necessary.
  33180. *
  33181. * @private
  33182. * @param {string} contents
  33183. * @memberof PopupElement
  33184. * @returns {HTMLParagraphElement}
  33185. */
  33186. _formatContents: function PopupElement_formatContents(contents) {
  33187. var p = document.createElement('p');
  33188. var lines = contents.split(/(?:\r\n?|\n)/);
  33189. for (var i = 0, ii = lines.length; i < ii; ++i) {
  33190. var line = lines[i];
  33191. p.appendChild(document.createTextNode(line));
  33192. if (i < ii - 1) {
  33193. p.appendChild(document.createElement('br'));
  33194. }
  33195. }
  33196. return p;
  33197. },
  33198. /**
  33199. * Toggle the visibility of the popup.
  33200. *
  33201. * @private
  33202. * @memberof PopupElement
  33203. */
  33204. _toggle: function PopupElement_toggle() {
  33205. if (this.pinned) {
  33206. this._hide(true);
  33207. } else {
  33208. this._show(true);
  33209. }
  33210. },
  33211. /**
  33212. * Show the popup.
  33213. *
  33214. * @private
  33215. * @param {boolean} pin
  33216. * @memberof PopupElement
  33217. */
  33218. _show: function PopupElement_show(pin) {
  33219. if (pin) {
  33220. this.pinned = true;
  33221. }
  33222. if (this.hideElement.hasAttribute('hidden')) {
  33223. this.hideElement.removeAttribute('hidden');
  33224. this.container.style.zIndex += 1;
  33225. }
  33226. },
  33227. /**
  33228. * Hide the popup.
  33229. *
  33230. * @private
  33231. * @param {boolean} unpin
  33232. * @memberof PopupElement
  33233. */
  33234. _hide: function PopupElement_hide(unpin) {
  33235. if (unpin) {
  33236. this.pinned = false;
  33237. }
  33238. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  33239. this.hideElement.setAttribute('hidden', true);
  33240. this.container.style.zIndex -= 1;
  33241. }
  33242. }
  33243. };
  33244. return PopupElement;
  33245. }();
  33246. /**
  33247. * @class
  33248. * @alias HighlightAnnotationElement
  33249. */
  33250. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  33251. function HighlightAnnotationElement(parameters) {
  33252. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33253. AnnotationElement.call(this, parameters, isRenderable);
  33254. }
  33255. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  33256. /**
  33257. * Render the highlight annotation's HTML element in the empty container.
  33258. *
  33259. * @public
  33260. * @memberof HighlightAnnotationElement
  33261. * @returns {HTMLSectionElement}
  33262. */
  33263. render: function HighlightAnnotationElement_render() {
  33264. this.container.className = 'highlightAnnotation';
  33265. if (!this.data.hasPopup) {
  33266. this._createPopup(this.container, null, this.data);
  33267. }
  33268. return this.container;
  33269. }
  33270. });
  33271. return HighlightAnnotationElement;
  33272. }();
  33273. /**
  33274. * @class
  33275. * @alias UnderlineAnnotationElement
  33276. */
  33277. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  33278. function UnderlineAnnotationElement(parameters) {
  33279. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33280. AnnotationElement.call(this, parameters, isRenderable);
  33281. }
  33282. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  33283. /**
  33284. * Render the underline annotation's HTML element in the empty container.
  33285. *
  33286. * @public
  33287. * @memberof UnderlineAnnotationElement
  33288. * @returns {HTMLSectionElement}
  33289. */
  33290. render: function UnderlineAnnotationElement_render() {
  33291. this.container.className = 'underlineAnnotation';
  33292. if (!this.data.hasPopup) {
  33293. this._createPopup(this.container, null, this.data);
  33294. }
  33295. return this.container;
  33296. }
  33297. });
  33298. return UnderlineAnnotationElement;
  33299. }();
  33300. /**
  33301. * @class
  33302. * @alias SquigglyAnnotationElement
  33303. */
  33304. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  33305. function SquigglyAnnotationElement(parameters) {
  33306. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33307. AnnotationElement.call(this, parameters, isRenderable);
  33308. }
  33309. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  33310. /**
  33311. * Render the squiggly annotation's HTML element in the empty container.
  33312. *
  33313. * @public
  33314. * @memberof SquigglyAnnotationElement
  33315. * @returns {HTMLSectionElement}
  33316. */
  33317. render: function SquigglyAnnotationElement_render() {
  33318. this.container.className = 'squigglyAnnotation';
  33319. if (!this.data.hasPopup) {
  33320. this._createPopup(this.container, null, this.data);
  33321. }
  33322. return this.container;
  33323. }
  33324. });
  33325. return SquigglyAnnotationElement;
  33326. }();
  33327. /**
  33328. * @class
  33329. * @alias StrikeOutAnnotationElement
  33330. */
  33331. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  33332. function StrikeOutAnnotationElement(parameters) {
  33333. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33334. AnnotationElement.call(this, parameters, isRenderable);
  33335. }
  33336. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  33337. /**
  33338. * Render the strikeout annotation's HTML element in the empty container.
  33339. *
  33340. * @public
  33341. * @memberof StrikeOutAnnotationElement
  33342. * @returns {HTMLSectionElement}
  33343. */
  33344. render: function StrikeOutAnnotationElement_render() {
  33345. this.container.className = 'strikeoutAnnotation';
  33346. if (!this.data.hasPopup) {
  33347. this._createPopup(this.container, null, this.data);
  33348. }
  33349. return this.container;
  33350. }
  33351. });
  33352. return StrikeOutAnnotationElement;
  33353. }();
  33354. /**
  33355. * @class
  33356. * @alias FileAttachmentAnnotationElement
  33357. */
  33358. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  33359. function FileAttachmentAnnotationElement(parameters) {
  33360. AnnotationElement.call(this, parameters, true);
  33361. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  33362. this.content = parameters.data.file.content;
  33363. }
  33364. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  33365. /**
  33366. * Render the file attachment annotation's HTML element in the empty
  33367. * container.
  33368. *
  33369. * @public
  33370. * @memberof FileAttachmentAnnotationElement
  33371. * @returns {HTMLSectionElement}
  33372. */
  33373. render: function FileAttachmentAnnotationElement_render() {
  33374. this.container.className = 'fileAttachmentAnnotation';
  33375. var trigger = document.createElement('div');
  33376. trigger.style.height = this.container.style.height;
  33377. trigger.style.width = this.container.style.width;
  33378. trigger.addEventListener('dblclick', this._download.bind(this));
  33379. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  33380. this._createPopup(this.container, trigger, this.data);
  33381. }
  33382. this.container.appendChild(trigger);
  33383. return this.container;
  33384. },
  33385. /**
  33386. * Download the file attachment associated with this annotation.
  33387. *
  33388. * @private
  33389. * @memberof FileAttachmentAnnotationElement
  33390. */
  33391. _download: function FileAttachmentAnnotationElement_download() {
  33392. if (!this.downloadManager) {
  33393. warn('Download cannot be started due to unavailable download manager');
  33394. return;
  33395. }
  33396. this.downloadManager.downloadData(this.content, this.filename, '');
  33397. }
  33398. });
  33399. return FileAttachmentAnnotationElement;
  33400. }();
  33401. /**
  33402. * @typedef {Object} AnnotationLayerParameters
  33403. * @property {PageViewport} viewport
  33404. * @property {HTMLDivElement} div
  33405. * @property {Array} annotations
  33406. * @property {PDFPage} page
  33407. * @property {IPDFLinkService} linkService
  33408. * @property {string} imageResourcesPath
  33409. * @property {boolean} renderInteractiveForms
  33410. */
  33411. /**
  33412. * @class
  33413. * @alias AnnotationLayer
  33414. */
  33415. var AnnotationLayer = function AnnotationLayerClosure() {
  33416. return {
  33417. /**
  33418. * Render a new annotation layer with all annotation elements.
  33419. *
  33420. * @public
  33421. * @param {AnnotationLayerParameters} parameters
  33422. * @memberof AnnotationLayer
  33423. */
  33424. render: function AnnotationLayer_render(parameters) {
  33425. var annotationElementFactory = new AnnotationElementFactory();
  33426. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  33427. var data = parameters.annotations[i];
  33428. if (!data) {
  33429. continue;
  33430. }
  33431. var properties = {
  33432. data: data,
  33433. layer: parameters.div,
  33434. page: parameters.page,
  33435. viewport: parameters.viewport,
  33436. linkService: parameters.linkService,
  33437. downloadManager: parameters.downloadManager,
  33438. imageResourcesPath: parameters.imageResourcesPath || getDefaultSetting('imageResourcesPath'),
  33439. renderInteractiveForms: parameters.renderInteractiveForms || false
  33440. };
  33441. var element = annotationElementFactory.create(properties);
  33442. if (element.isRenderable) {
  33443. parameters.div.appendChild(element.render());
  33444. }
  33445. }
  33446. },
  33447. /**
  33448. * Update the annotation elements on existing annotation layer.
  33449. *
  33450. * @public
  33451. * @param {AnnotationLayerParameters} parameters
  33452. * @memberof AnnotationLayer
  33453. */
  33454. update: function AnnotationLayer_update(parameters) {
  33455. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  33456. var data = parameters.annotations[i];
  33457. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  33458. if (element) {
  33459. CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  33460. }
  33461. }
  33462. parameters.div.removeAttribute('hidden');
  33463. }
  33464. };
  33465. }();
  33466. exports.AnnotationLayer = AnnotationLayer;
  33467. }));
  33468. (function (root, factory) {
  33469. factory(root.pdfjsDisplayTextLayer = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  33470. }(this, function (exports, sharedUtil, displayDOMUtils) {
  33471. var Util = sharedUtil.Util;
  33472. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33473. var CustomStyle = displayDOMUtils.CustomStyle;
  33474. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  33475. /**
  33476. * Text layer render parameters.
  33477. *
  33478. * @typedef {Object} TextLayerRenderParameters
  33479. * @property {TextContent} textContent - Text content to render (the object is
  33480. * returned by the page's getTextContent() method).
  33481. * @property {HTMLElement} container - HTML element that will contain text runs.
  33482. * @property {PageViewport} viewport - The target viewport to properly
  33483. * layout the text runs.
  33484. * @property {Array} textDivs - (optional) HTML elements that are correspond
  33485. * the text items of the textContent input. This is output and shall be
  33486. * initially be set to empty array.
  33487. * @property {number} timeout - (optional) Delay in milliseconds before
  33488. * rendering of the text runs occurs.
  33489. * @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
  33490. * text selection enhancement.
  33491. */
  33492. var renderTextLayer = function renderTextLayerClosure() {
  33493. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  33494. var NonWhitespaceRegexp = /\S/;
  33495. function isAllWhitespace(str) {
  33496. return !NonWhitespaceRegexp.test(str);
  33497. }
  33498. // Text layers may contain many thousand div's, and using `styleBuf` avoids
  33499. // creating many intermediate strings when building their 'style' properties.
  33500. var styleBuf = [
  33501. 'left: ',
  33502. 0,
  33503. 'px; top: ',
  33504. 0,
  33505. 'px; font-size: ',
  33506. 0,
  33507. 'px; font-family: ',
  33508. '',
  33509. ';'
  33510. ];
  33511. function appendText(task, geom, styles) {
  33512. // Initialize all used properties to keep the caches monomorphic.
  33513. var textDiv = document.createElement('div');
  33514. var textDivProperties = {
  33515. style: null,
  33516. angle: 0,
  33517. canvasWidth: 0,
  33518. isWhitespace: false,
  33519. originalTransform: null,
  33520. paddingBottom: 0,
  33521. paddingLeft: 0,
  33522. paddingRight: 0,
  33523. paddingTop: 0,
  33524. scale: 1
  33525. };
  33526. task._textDivs.push(textDiv);
  33527. if (isAllWhitespace(geom.str)) {
  33528. textDivProperties.isWhitespace = true;
  33529. task._textDivProperties.set(textDiv, textDivProperties);
  33530. return;
  33531. }
  33532. var tx = Util.transform(task._viewport.transform, geom.transform);
  33533. var angle = Math.atan2(tx[1], tx[0]);
  33534. var style = styles[geom.fontName];
  33535. if (style.vertical) {
  33536. angle += Math.PI / 2;
  33537. }
  33538. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  33539. var fontAscent = fontHeight;
  33540. if (style.ascent) {
  33541. fontAscent = style.ascent * fontAscent;
  33542. } else if (style.descent) {
  33543. fontAscent = (1 + style.descent) * fontAscent;
  33544. }
  33545. var left;
  33546. var top;
  33547. if (angle === 0) {
  33548. left = tx[4];
  33549. top = tx[5] - fontAscent;
  33550. } else {
  33551. left = tx[4] + fontAscent * Math.sin(angle);
  33552. top = tx[5] - fontAscent * Math.cos(angle);
  33553. }
  33554. styleBuf[1] = left;
  33555. styleBuf[3] = top;
  33556. styleBuf[5] = fontHeight;
  33557. styleBuf[7] = style.fontFamily;
  33558. textDivProperties.style = styleBuf.join('');
  33559. textDiv.setAttribute('style', textDivProperties.style);
  33560. textDiv.textContent = geom.str;
  33561. // |fontName| is only used by the Font Inspector. This test will succeed
  33562. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  33563. // not worth the effort to do a more accurate test. We only use `dataset`
  33564. // here to make the font name available for the debugger.
  33565. if (getDefaultSetting('pdfBug')) {
  33566. textDiv.dataset.fontName = geom.fontName;
  33567. }
  33568. if (angle !== 0) {
  33569. textDivProperties.angle = angle * (180 / Math.PI);
  33570. }
  33571. // We don't bother scaling single-char text divs, because it has very
  33572. // little effect on text highlighting. This makes scrolling on docs with
  33573. // lots of such divs a lot faster.
  33574. if (geom.str.length > 1) {
  33575. if (style.vertical) {
  33576. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  33577. } else {
  33578. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  33579. }
  33580. }
  33581. task._textDivProperties.set(textDiv, textDivProperties);
  33582. if (task._enhanceTextSelection) {
  33583. var angleCos = 1, angleSin = 0;
  33584. if (angle !== 0) {
  33585. angleCos = Math.cos(angle);
  33586. angleSin = Math.sin(angle);
  33587. }
  33588. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  33589. var divHeight = fontHeight;
  33590. var m, b;
  33591. if (angle !== 0) {
  33592. m = [
  33593. angleCos,
  33594. angleSin,
  33595. -angleSin,
  33596. angleCos,
  33597. left,
  33598. top
  33599. ];
  33600. b = Util.getAxialAlignedBoundingBox([
  33601. 0,
  33602. 0,
  33603. divWidth,
  33604. divHeight
  33605. ], m);
  33606. } else {
  33607. b = [
  33608. left,
  33609. top,
  33610. left + divWidth,
  33611. top + divHeight
  33612. ];
  33613. }
  33614. task._bounds.push({
  33615. left: b[0],
  33616. top: b[1],
  33617. right: b[2],
  33618. bottom: b[3],
  33619. div: textDiv,
  33620. size: [
  33621. divWidth,
  33622. divHeight
  33623. ],
  33624. m: m
  33625. });
  33626. }
  33627. }
  33628. function render(task) {
  33629. if (task._canceled) {
  33630. return;
  33631. }
  33632. var textLayerFrag = task._container;
  33633. var textDivs = task._textDivs;
  33634. var capability = task._capability;
  33635. var textDivsLength = textDivs.length;
  33636. // No point in rendering many divs as it would make the browser
  33637. // unusable even after the divs are rendered.
  33638. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  33639. task._renderingDone = true;
  33640. capability.resolve();
  33641. return;
  33642. }
  33643. var canvas = document.createElement('canvas');
  33644. var ctx = canvas.getContext('2d', { alpha: false });
  33645. var lastFontSize;
  33646. var lastFontFamily;
  33647. for (var i = 0; i < textDivsLength; i++) {
  33648. var textDiv = textDivs[i];
  33649. var textDivProperties = task._textDivProperties.get(textDiv);
  33650. if (textDivProperties.isWhitespace) {
  33651. continue;
  33652. }
  33653. var fontSize = textDiv.style.fontSize;
  33654. var fontFamily = textDiv.style.fontFamily;
  33655. // Only build font string and set to context if different from last.
  33656. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  33657. ctx.font = fontSize + ' ' + fontFamily;
  33658. lastFontSize = fontSize;
  33659. lastFontFamily = fontFamily;
  33660. }
  33661. var width = ctx.measureText(textDiv.textContent).width;
  33662. textLayerFrag.appendChild(textDiv);
  33663. var transform = '';
  33664. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  33665. textDivProperties.scale = textDivProperties.canvasWidth / width;
  33666. transform = 'scaleX(' + textDivProperties.scale + ')';
  33667. }
  33668. if (textDivProperties.angle !== 0) {
  33669. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  33670. }
  33671. if (transform !== '') {
  33672. textDivProperties.originalTransform = transform;
  33673. CustomStyle.setProp('transform', textDiv, transform);
  33674. }
  33675. task._textDivProperties.set(textDiv, textDivProperties);
  33676. }
  33677. task._renderingDone = true;
  33678. capability.resolve();
  33679. }
  33680. function expand(task) {
  33681. var bounds = task._bounds;
  33682. var viewport = task._viewport;
  33683. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  33684. for (var i = 0; i < expanded.length; i++) {
  33685. var div = bounds[i].div;
  33686. var divProperties = task._textDivProperties.get(div);
  33687. if (divProperties.angle === 0) {
  33688. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  33689. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  33690. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  33691. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  33692. task._textDivProperties.set(div, divProperties);
  33693. continue;
  33694. }
  33695. // Box is rotated -- trying to find padding so rotated div will not
  33696. // exceed its expanded bounds.
  33697. var e = expanded[i], b = bounds[i];
  33698. var m = b.m, c = m[0], s = m[1];
  33699. // Finding intersections with expanded box.
  33700. var points = [
  33701. [
  33702. 0,
  33703. 0
  33704. ],
  33705. [
  33706. 0,
  33707. b.size[1]
  33708. ],
  33709. [
  33710. b.size[0],
  33711. 0
  33712. ],
  33713. b.size
  33714. ];
  33715. var ts = new Float64Array(64);
  33716. points.forEach(function (p, i) {
  33717. var t = Util.applyTransform(p, m);
  33718. ts[i + 0] = c && (e.left - t[0]) / c;
  33719. ts[i + 4] = s && (e.top - t[1]) / s;
  33720. ts[i + 8] = c && (e.right - t[0]) / c;
  33721. ts[i + 12] = s && (e.bottom - t[1]) / s;
  33722. ts[i + 16] = s && (e.left - t[0]) / -s;
  33723. ts[i + 20] = c && (e.top - t[1]) / c;
  33724. ts[i + 24] = s && (e.right - t[0]) / -s;
  33725. ts[i + 28] = c && (e.bottom - t[1]) / c;
  33726. ts[i + 32] = c && (e.left - t[0]) / -c;
  33727. ts[i + 36] = s && (e.top - t[1]) / -s;
  33728. ts[i + 40] = c && (e.right - t[0]) / -c;
  33729. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  33730. ts[i + 48] = s && (e.left - t[0]) / s;
  33731. ts[i + 52] = c && (e.top - t[1]) / -c;
  33732. ts[i + 56] = s && (e.right - t[0]) / s;
  33733. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  33734. });
  33735. var findPositiveMin = function (ts, offset, count) {
  33736. var result = 0;
  33737. for (var i = 0; i < count; i++) {
  33738. var t = ts[offset++];
  33739. if (t > 0) {
  33740. result = result ? Math.min(t, result) : t;
  33741. }
  33742. }
  33743. return result;
  33744. };
  33745. // Not based on math, but to simplify calculations, using cos and sin
  33746. // absolute values to not exceed the box (it can but insignificantly).
  33747. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  33748. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  33749. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  33750. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  33751. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  33752. task._textDivProperties.set(div, divProperties);
  33753. }
  33754. }
  33755. function expandBounds(width, height, boxes) {
  33756. var bounds = boxes.map(function (box, i) {
  33757. return {
  33758. x1: box.left,
  33759. y1: box.top,
  33760. x2: box.right,
  33761. y2: box.bottom,
  33762. index: i,
  33763. x1New: undefined,
  33764. x2New: undefined
  33765. };
  33766. });
  33767. expandBoundsLTR(width, bounds);
  33768. var expanded = new Array(boxes.length);
  33769. bounds.forEach(function (b) {
  33770. var i = b.index;
  33771. expanded[i] = {
  33772. left: b.x1New,
  33773. top: 0,
  33774. right: b.x2New,
  33775. bottom: 0
  33776. };
  33777. });
  33778. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  33779. // array and objects.
  33780. boxes.map(function (box, i) {
  33781. var e = expanded[i], b = bounds[i];
  33782. b.x1 = box.top;
  33783. b.y1 = width - e.right;
  33784. b.x2 = box.bottom;
  33785. b.y2 = width - e.left;
  33786. b.index = i;
  33787. b.x1New = undefined;
  33788. b.x2New = undefined;
  33789. });
  33790. expandBoundsLTR(height, bounds);
  33791. bounds.forEach(function (b) {
  33792. var i = b.index;
  33793. expanded[i].top = b.x1New;
  33794. expanded[i].bottom = b.x2New;
  33795. });
  33796. return expanded;
  33797. }
  33798. function expandBoundsLTR(width, bounds) {
  33799. // Sorting by x1 coordinate and walk by the bounds in the same order.
  33800. bounds.sort(function (a, b) {
  33801. return a.x1 - b.x1 || a.index - b.index;
  33802. });
  33803. // First we see on the horizon is a fake boundary.
  33804. var fakeBoundary = {
  33805. x1: -Infinity,
  33806. y1: -Infinity,
  33807. x2: 0,
  33808. y2: Infinity,
  33809. index: -1,
  33810. x1New: 0,
  33811. x2New: 0
  33812. };
  33813. var horizon = [{
  33814. start: -Infinity,
  33815. end: Infinity,
  33816. boundary: fakeBoundary
  33817. }];
  33818. bounds.forEach(function (boundary) {
  33819. // Searching for the affected part of horizon.
  33820. // TODO red-black tree or simple binary search
  33821. var i = 0;
  33822. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  33823. i++;
  33824. }
  33825. var j = horizon.length - 1;
  33826. while (j >= 0 && horizon[j].start >= boundary.y2) {
  33827. j--;
  33828. }
  33829. var horizonPart, affectedBoundary;
  33830. var q, k, maxXNew = -Infinity;
  33831. for (q = i; q <= j; q++) {
  33832. horizonPart = horizon[q];
  33833. affectedBoundary = horizonPart.boundary;
  33834. var xNew;
  33835. if (affectedBoundary.x2 > boundary.x1) {
  33836. // In the middle of the previous element, new x shall be at the
  33837. // boundary start. Extending if further if the affected bondary
  33838. // placed on top of the current one.
  33839. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  33840. } else if (affectedBoundary.x2New === undefined) {
  33841. // We have some space in between, new x in middle will be a fair
  33842. // choice.
  33843. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  33844. } else {
  33845. // Affected boundary has x2new set, using it as new x.
  33846. xNew = affectedBoundary.x2New;
  33847. }
  33848. if (xNew > maxXNew) {
  33849. maxXNew = xNew;
  33850. }
  33851. }
  33852. // Set new x1 for current boundary.
  33853. boundary.x1New = maxXNew;
  33854. // Adjusts new x2 for the affected boundaries.
  33855. for (q = i; q <= j; q++) {
  33856. horizonPart = horizon[q];
  33857. affectedBoundary = horizonPart.boundary;
  33858. if (affectedBoundary.x2New === undefined) {
  33859. // Was not set yet, choosing new x if possible.
  33860. if (affectedBoundary.x2 > boundary.x1) {
  33861. // Current and affected boundaries intersect. If affected boundary
  33862. // is placed on top of the current, shrinking the affected.
  33863. if (affectedBoundary.index > boundary.index) {
  33864. affectedBoundary.x2New = affectedBoundary.x2;
  33865. }
  33866. } else {
  33867. affectedBoundary.x2New = maxXNew;
  33868. }
  33869. } else if (affectedBoundary.x2New > maxXNew) {
  33870. // Affected boundary is touching new x, pushing it back.
  33871. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  33872. }
  33873. }
  33874. // Fixing the horizon.
  33875. var changedHorizon = [], lastBoundary = null;
  33876. for (q = i; q <= j; q++) {
  33877. horizonPart = horizon[q];
  33878. affectedBoundary = horizonPart.boundary;
  33879. // Checking which boundary will be visible.
  33880. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  33881. if (lastBoundary === useBoundary) {
  33882. // Merging with previous.
  33883. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  33884. } else {
  33885. changedHorizon.push({
  33886. start: horizonPart.start,
  33887. end: horizonPart.end,
  33888. boundary: useBoundary
  33889. });
  33890. lastBoundary = useBoundary;
  33891. }
  33892. }
  33893. if (horizon[i].start < boundary.y1) {
  33894. changedHorizon[0].start = boundary.y1;
  33895. changedHorizon.unshift({
  33896. start: horizon[i].start,
  33897. end: boundary.y1,
  33898. boundary: horizon[i].boundary
  33899. });
  33900. }
  33901. if (boundary.y2 < horizon[j].end) {
  33902. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  33903. changedHorizon.push({
  33904. start: boundary.y2,
  33905. end: horizon[j].end,
  33906. boundary: horizon[j].boundary
  33907. });
  33908. }
  33909. // Set x2 new of boundary that is no longer visible (see overlapping case
  33910. // above).
  33911. // TODO more efficient, e.g. via reference counting.
  33912. for (q = i; q <= j; q++) {
  33913. horizonPart = horizon[q];
  33914. affectedBoundary = horizonPart.boundary;
  33915. if (affectedBoundary.x2New !== undefined) {
  33916. continue;
  33917. }
  33918. var used = false;
  33919. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  33920. used = horizon[k].boundary === affectedBoundary;
  33921. }
  33922. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  33923. used = horizon[k].boundary === affectedBoundary;
  33924. }
  33925. for (k = 0; !used && k < changedHorizon.length; k++) {
  33926. used = changedHorizon[k].boundary === affectedBoundary;
  33927. }
  33928. if (!used) {
  33929. affectedBoundary.x2New = maxXNew;
  33930. }
  33931. }
  33932. Array.prototype.splice.apply(horizon, [
  33933. i,
  33934. j - i + 1
  33935. ].concat(changedHorizon));
  33936. });
  33937. // Set new x2 for all unset boundaries.
  33938. horizon.forEach(function (horizonPart) {
  33939. var affectedBoundary = horizonPart.boundary;
  33940. if (affectedBoundary.x2New === undefined) {
  33941. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  33942. }
  33943. });
  33944. }
  33945. /**
  33946. * Text layer rendering task.
  33947. *
  33948. * @param {TextContent} textContent
  33949. * @param {HTMLElement} container
  33950. * @param {PageViewport} viewport
  33951. * @param {Array} textDivs
  33952. * @param {boolean} enhanceTextSelection
  33953. * @private
  33954. */
  33955. function TextLayerRenderTask(textContent, container, viewport, textDivs, enhanceTextSelection) {
  33956. this._textContent = textContent;
  33957. this._container = container;
  33958. this._viewport = viewport;
  33959. this._textDivs = textDivs || [];
  33960. this._textDivProperties = new WeakMap();
  33961. this._renderingDone = false;
  33962. this._canceled = false;
  33963. this._capability = createPromiseCapability();
  33964. this._renderTimer = null;
  33965. this._bounds = [];
  33966. this._enhanceTextSelection = !!enhanceTextSelection;
  33967. }
  33968. TextLayerRenderTask.prototype = {
  33969. get promise() {
  33970. return this._capability.promise;
  33971. },
  33972. cancel: function TextLayer_cancel() {
  33973. this._canceled = true;
  33974. if (this._renderTimer !== null) {
  33975. clearTimeout(this._renderTimer);
  33976. this._renderTimer = null;
  33977. }
  33978. this._capability.reject('canceled');
  33979. },
  33980. _render: function TextLayer_render(timeout) {
  33981. var textItems = this._textContent.items;
  33982. var textStyles = this._textContent.styles;
  33983. for (var i = 0, len = textItems.length; i < len; i++) {
  33984. appendText(this, textItems[i], textStyles);
  33985. }
  33986. if (!timeout) {
  33987. // Render right away
  33988. render(this);
  33989. } else {
  33990. // Schedule
  33991. var self = this;
  33992. this._renderTimer = setTimeout(function () {
  33993. render(self);
  33994. self._renderTimer = null;
  33995. }, timeout);
  33996. }
  33997. },
  33998. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  33999. if (!this._enhanceTextSelection || !this._renderingDone) {
  34000. return;
  34001. }
  34002. if (this._bounds !== null) {
  34003. expand(this);
  34004. this._bounds = null;
  34005. }
  34006. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  34007. var div = this._textDivs[i];
  34008. var divProperties = this._textDivProperties.get(div);
  34009. if (divProperties.isWhitespace) {
  34010. continue;
  34011. }
  34012. if (expandDivs) {
  34013. var transform = '', padding = '';
  34014. if (divProperties.scale !== 1) {
  34015. transform = 'scaleX(' + divProperties.scale + ')';
  34016. }
  34017. if (divProperties.angle !== 0) {
  34018. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  34019. }
  34020. if (divProperties.paddingLeft !== 0) {
  34021. padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
  34022. transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
  34023. }
  34024. if (divProperties.paddingTop !== 0) {
  34025. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  34026. transform += ' translateY(' + -divProperties.paddingTop + 'px)';
  34027. }
  34028. if (divProperties.paddingRight !== 0) {
  34029. padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
  34030. }
  34031. if (divProperties.paddingBottom !== 0) {
  34032. padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
  34033. }
  34034. if (padding !== '') {
  34035. div.setAttribute('style', divProperties.style + padding);
  34036. }
  34037. if (transform !== '') {
  34038. CustomStyle.setProp('transform', div, transform);
  34039. }
  34040. } else {
  34041. div.style.padding = 0;
  34042. CustomStyle.setProp('transform', div, divProperties.originalTransform || '');
  34043. }
  34044. }
  34045. }
  34046. };
  34047. /**
  34048. * Starts rendering of the text layer.
  34049. *
  34050. * @param {TextLayerRenderParameters} renderParameters
  34051. * @returns {TextLayerRenderTask}
  34052. */
  34053. function renderTextLayer(renderParameters) {
  34054. var task = new TextLayerRenderTask(renderParameters.textContent, renderParameters.container, renderParameters.viewport, renderParameters.textDivs, renderParameters.enhanceTextSelection);
  34055. task._render(renderParameters.timeout);
  34056. return task;
  34057. }
  34058. return renderTextLayer;
  34059. }();
  34060. exports.renderTextLayer = renderTextLayer;
  34061. }));
  34062. (function (root, factory) {
  34063. factory(root.pdfjsDisplayWebGL = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  34064. }(this, function (exports, sharedUtil, displayDOMUtils) {
  34065. var shadow = sharedUtil.shadow;
  34066. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  34067. var WebGLUtils = function WebGLUtilsClosure() {
  34068. function loadShader(gl, code, shaderType) {
  34069. var shader = gl.createShader(shaderType);
  34070. gl.shaderSource(shader, code);
  34071. gl.compileShader(shader);
  34072. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  34073. if (!compiled) {
  34074. var errorMsg = gl.getShaderInfoLog(shader);
  34075. throw new Error('Error during shader compilation: ' + errorMsg);
  34076. }
  34077. return shader;
  34078. }
  34079. function createVertexShader(gl, code) {
  34080. return loadShader(gl, code, gl.VERTEX_SHADER);
  34081. }
  34082. function createFragmentShader(gl, code) {
  34083. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  34084. }
  34085. function createProgram(gl, shaders) {
  34086. var program = gl.createProgram();
  34087. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  34088. gl.attachShader(program, shaders[i]);
  34089. }
  34090. gl.linkProgram(program);
  34091. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  34092. if (!linked) {
  34093. var errorMsg = gl.getProgramInfoLog(program);
  34094. throw new Error('Error during program linking: ' + errorMsg);
  34095. }
  34096. return program;
  34097. }
  34098. function createTexture(gl, image, textureId) {
  34099. gl.activeTexture(textureId);
  34100. var texture = gl.createTexture();
  34101. gl.bindTexture(gl.TEXTURE_2D, texture);
  34102. // Set the parameters so we can render any size image.
  34103. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  34104. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  34105. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  34106. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  34107. // Upload the image into the texture.
  34108. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  34109. return texture;
  34110. }
  34111. var currentGL, currentCanvas;
  34112. function generateGL() {
  34113. if (currentGL) {
  34114. return;
  34115. }
  34116. currentCanvas = document.createElement('canvas');
  34117. currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });
  34118. }
  34119. var smaskVertexShaderCode = '\
  34120. attribute vec2 a_position; \
  34121. attribute vec2 a_texCoord; \
  34122. \
  34123. uniform vec2 u_resolution; \
  34124. \
  34125. varying vec2 v_texCoord; \
  34126. \
  34127. void main() { \
  34128. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  34129. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  34130. \
  34131. v_texCoord = a_texCoord; \
  34132. } ';
  34133. var smaskFragmentShaderCode = '\
  34134. precision mediump float; \
  34135. \
  34136. uniform vec4 u_backdrop; \
  34137. uniform int u_subtype; \
  34138. uniform sampler2D u_image; \
  34139. uniform sampler2D u_mask; \
  34140. \
  34141. varying vec2 v_texCoord; \
  34142. \
  34143. void main() { \
  34144. vec4 imageColor = texture2D(u_image, v_texCoord); \
  34145. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  34146. if (u_backdrop.a > 0.0) { \
  34147. maskColor.rgb = maskColor.rgb * maskColor.a + \
  34148. u_backdrop.rgb * (1.0 - maskColor.a); \
  34149. } \
  34150. float lum; \
  34151. if (u_subtype == 0) { \
  34152. lum = maskColor.a; \
  34153. } else { \
  34154. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  34155. maskColor.b * 0.11; \
  34156. } \
  34157. imageColor.a *= lum; \
  34158. imageColor.rgb *= imageColor.a; \
  34159. gl_FragColor = imageColor; \
  34160. } ';
  34161. var smaskCache = null;
  34162. function initSmaskGL() {
  34163. var canvas, gl;
  34164. generateGL();
  34165. canvas = currentCanvas;
  34166. currentCanvas = null;
  34167. gl = currentGL;
  34168. currentGL = null;
  34169. // setup a GLSL program
  34170. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  34171. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  34172. var program = createProgram(gl, [
  34173. vertexShader,
  34174. fragmentShader
  34175. ]);
  34176. gl.useProgram(program);
  34177. var cache = {};
  34178. cache.gl = gl;
  34179. cache.canvas = canvas;
  34180. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  34181. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  34182. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  34183. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  34184. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  34185. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  34186. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  34187. // provide texture coordinates for the rectangle.
  34188. var texCoordBuffer = gl.createBuffer();
  34189. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  34190. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  34191. 0.0,
  34192. 0.0,
  34193. 1.0,
  34194. 0.0,
  34195. 0.0,
  34196. 1.0,
  34197. 0.0,
  34198. 1.0,
  34199. 1.0,
  34200. 0.0,
  34201. 1.0,
  34202. 1.0
  34203. ]), gl.STATIC_DRAW);
  34204. gl.enableVertexAttribArray(texCoordLocation);
  34205. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  34206. gl.uniform1i(texLayerLocation, 0);
  34207. gl.uniform1i(texMaskLocation, 1);
  34208. smaskCache = cache;
  34209. }
  34210. function composeSMask(layer, mask, properties) {
  34211. var width = layer.width, height = layer.height;
  34212. if (!smaskCache) {
  34213. initSmaskGL();
  34214. }
  34215. var cache = smaskCache, canvas = cache.canvas, gl = cache.gl;
  34216. canvas.width = width;
  34217. canvas.height = height;
  34218. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  34219. gl.uniform2f(cache.resolutionLocation, width, height);
  34220. if (properties.backdrop) {
  34221. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  34222. } else {
  34223. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  34224. }
  34225. gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0);
  34226. // Create a textures
  34227. var texture = createTexture(gl, layer, gl.TEXTURE0);
  34228. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  34229. // Create a buffer and put a single clipspace rectangle in
  34230. // it (2 triangles)
  34231. var buffer = gl.createBuffer();
  34232. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  34233. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  34234. 0,
  34235. 0,
  34236. width,
  34237. 0,
  34238. 0,
  34239. height,
  34240. 0,
  34241. height,
  34242. width,
  34243. 0,
  34244. width,
  34245. height
  34246. ]), gl.STATIC_DRAW);
  34247. gl.enableVertexAttribArray(cache.positionLocation);
  34248. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  34249. // draw
  34250. gl.clearColor(0, 0, 0, 0);
  34251. gl.enable(gl.BLEND);
  34252. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  34253. gl.clear(gl.COLOR_BUFFER_BIT);
  34254. gl.drawArrays(gl.TRIANGLES, 0, 6);
  34255. gl.flush();
  34256. gl.deleteTexture(texture);
  34257. gl.deleteTexture(maskTexture);
  34258. gl.deleteBuffer(buffer);
  34259. return canvas;
  34260. }
  34261. var figuresVertexShaderCode = '\
  34262. attribute vec2 a_position; \
  34263. attribute vec3 a_color; \
  34264. \
  34265. uniform vec2 u_resolution; \
  34266. uniform vec2 u_scale; \
  34267. uniform vec2 u_offset; \
  34268. \
  34269. varying vec4 v_color; \
  34270. \
  34271. void main() { \
  34272. vec2 position = (a_position + u_offset) * u_scale; \
  34273. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  34274. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  34275. \
  34276. v_color = vec4(a_color / 255.0, 1.0); \
  34277. } ';
  34278. var figuresFragmentShaderCode = '\
  34279. precision mediump float; \
  34280. \
  34281. varying vec4 v_color; \
  34282. \
  34283. void main() { \
  34284. gl_FragColor = v_color; \
  34285. } ';
  34286. var figuresCache = null;
  34287. function initFiguresGL() {
  34288. var canvas, gl;
  34289. generateGL();
  34290. canvas = currentCanvas;
  34291. currentCanvas = null;
  34292. gl = currentGL;
  34293. currentGL = null;
  34294. // setup a GLSL program
  34295. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  34296. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  34297. var program = createProgram(gl, [
  34298. vertexShader,
  34299. fragmentShader
  34300. ]);
  34301. gl.useProgram(program);
  34302. var cache = {};
  34303. cache.gl = gl;
  34304. cache.canvas = canvas;
  34305. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  34306. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  34307. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  34308. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  34309. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  34310. figuresCache = cache;
  34311. }
  34312. function drawFigures(width, height, backgroundColor, figures, context) {
  34313. if (!figuresCache) {
  34314. initFiguresGL();
  34315. }
  34316. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  34317. canvas.width = width;
  34318. canvas.height = height;
  34319. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  34320. gl.uniform2f(cache.resolutionLocation, width, height);
  34321. // count triangle points
  34322. var count = 0;
  34323. var i, ii, rows;
  34324. for (i = 0, ii = figures.length; i < ii; i++) {
  34325. switch (figures[i].type) {
  34326. case 'lattice':
  34327. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  34328. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  34329. break;
  34330. case 'triangles':
  34331. count += figures[i].coords.length;
  34332. break;
  34333. }
  34334. }
  34335. // transfer data
  34336. var coords = new Float32Array(count * 2);
  34337. var colors = new Uint8Array(count * 3);
  34338. var coordsMap = context.coords, colorsMap = context.colors;
  34339. var pIndex = 0, cIndex = 0;
  34340. for (i = 0, ii = figures.length; i < ii; i++) {
  34341. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34342. switch (figure.type) {
  34343. case 'lattice':
  34344. var cols = figure.verticesPerRow;
  34345. rows = ps.length / cols | 0;
  34346. for (var row = 1; row < rows; row++) {
  34347. var offset = row * cols + 1;
  34348. for (var col = 1; col < cols; col++, offset++) {
  34349. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  34350. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  34351. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  34352. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  34353. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  34354. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  34355. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  34356. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  34357. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  34358. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  34359. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  34360. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  34361. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  34362. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  34363. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  34364. coords[pIndex + 6] = coords[pIndex + 2];
  34365. coords[pIndex + 7] = coords[pIndex + 3];
  34366. coords[pIndex + 8] = coords[pIndex + 4];
  34367. coords[pIndex + 9] = coords[pIndex + 5];
  34368. coords[pIndex + 10] = coordsMap[ps[offset]];
  34369. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  34370. colors[cIndex + 9] = colors[cIndex + 3];
  34371. colors[cIndex + 10] = colors[cIndex + 4];
  34372. colors[cIndex + 11] = colors[cIndex + 5];
  34373. colors[cIndex + 12] = colors[cIndex + 6];
  34374. colors[cIndex + 13] = colors[cIndex + 7];
  34375. colors[cIndex + 14] = colors[cIndex + 8];
  34376. colors[cIndex + 15] = colorsMap[cs[offset]];
  34377. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  34378. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  34379. pIndex += 12;
  34380. cIndex += 18;
  34381. }
  34382. }
  34383. break;
  34384. case 'triangles':
  34385. for (var j = 0, jj = ps.length; j < jj; j++) {
  34386. coords[pIndex] = coordsMap[ps[j]];
  34387. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  34388. colors[cIndex] = colorsMap[cs[j]];
  34389. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  34390. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  34391. pIndex += 2;
  34392. cIndex += 3;
  34393. }
  34394. break;
  34395. }
  34396. }
  34397. // draw
  34398. if (backgroundColor) {
  34399. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  34400. } else {
  34401. gl.clearColor(0, 0, 0, 0);
  34402. }
  34403. gl.clear(gl.COLOR_BUFFER_BIT);
  34404. var coordsBuffer = gl.createBuffer();
  34405. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  34406. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  34407. gl.enableVertexAttribArray(cache.positionLocation);
  34408. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  34409. var colorsBuffer = gl.createBuffer();
  34410. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  34411. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  34412. gl.enableVertexAttribArray(cache.colorLocation);
  34413. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  34414. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  34415. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  34416. gl.drawArrays(gl.TRIANGLES, 0, count);
  34417. gl.flush();
  34418. gl.deleteBuffer(coordsBuffer);
  34419. gl.deleteBuffer(colorsBuffer);
  34420. return canvas;
  34421. }
  34422. function cleanup() {
  34423. if (smaskCache && smaskCache.canvas) {
  34424. smaskCache.canvas.width = 0;
  34425. smaskCache.canvas.height = 0;
  34426. }
  34427. if (figuresCache && figuresCache.canvas) {
  34428. figuresCache.canvas.width = 0;
  34429. figuresCache.canvas.height = 0;
  34430. }
  34431. smaskCache = null;
  34432. figuresCache = null;
  34433. }
  34434. return {
  34435. get isEnabled() {
  34436. if (getDefaultSetting('disableWebGL')) {
  34437. return false;
  34438. }
  34439. var enabled = false;
  34440. try {
  34441. generateGL();
  34442. enabled = !!currentGL;
  34443. } catch (e) {
  34444. }
  34445. return shadow(this, 'isEnabled', enabled);
  34446. },
  34447. composeSMask: composeSMask,
  34448. drawFigures: drawFigures,
  34449. clear: cleanup
  34450. };
  34451. }();
  34452. exports.WebGLUtils = WebGLUtils;
  34453. }));
  34454. (function (root, factory) {
  34455. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  34456. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  34457. var PasswordException = sharedUtil.PasswordException;
  34458. var PasswordResponses = sharedUtil.PasswordResponses;
  34459. var bytesToString = sharedUtil.bytesToString;
  34460. var warn = sharedUtil.warn;
  34461. var error = sharedUtil.error;
  34462. var assert = sharedUtil.assert;
  34463. var isInt = sharedUtil.isInt;
  34464. var stringToBytes = sharedUtil.stringToBytes;
  34465. var utf8StringToString = sharedUtil.utf8StringToString;
  34466. var Name = corePrimitives.Name;
  34467. var isName = corePrimitives.isName;
  34468. var isDict = corePrimitives.isDict;
  34469. var DecryptStream = coreStream.DecryptStream;
  34470. var ARCFourCipher = function ARCFourCipherClosure() {
  34471. function ARCFourCipher(key) {
  34472. this.a = 0;
  34473. this.b = 0;
  34474. var s = new Uint8Array(256);
  34475. var i, j = 0, tmp, keyLength = key.length;
  34476. for (i = 0; i < 256; ++i) {
  34477. s[i] = i;
  34478. }
  34479. for (i = 0; i < 256; ++i) {
  34480. tmp = s[i];
  34481. j = j + tmp + key[i % keyLength] & 0xFF;
  34482. s[i] = s[j];
  34483. s[j] = tmp;
  34484. }
  34485. this.s = s;
  34486. }
  34487. ARCFourCipher.prototype = {
  34488. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  34489. var i, n = data.length, tmp, tmp2;
  34490. var a = this.a, b = this.b, s = this.s;
  34491. var output = new Uint8Array(n);
  34492. for (i = 0; i < n; ++i) {
  34493. a = a + 1 & 0xFF;
  34494. tmp = s[a];
  34495. b = b + tmp & 0xFF;
  34496. tmp2 = s[b];
  34497. s[a] = tmp2;
  34498. s[b] = tmp;
  34499. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  34500. }
  34501. this.a = a;
  34502. this.b = b;
  34503. return output;
  34504. }
  34505. };
  34506. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  34507. return ARCFourCipher;
  34508. }();
  34509. var calculateMD5 = function calculateMD5Closure() {
  34510. var r = new Uint8Array([
  34511. 7,
  34512. 12,
  34513. 17,
  34514. 22,
  34515. 7,
  34516. 12,
  34517. 17,
  34518. 22,
  34519. 7,
  34520. 12,
  34521. 17,
  34522. 22,
  34523. 7,
  34524. 12,
  34525. 17,
  34526. 22,
  34527. 5,
  34528. 9,
  34529. 14,
  34530. 20,
  34531. 5,
  34532. 9,
  34533. 14,
  34534. 20,
  34535. 5,
  34536. 9,
  34537. 14,
  34538. 20,
  34539. 5,
  34540. 9,
  34541. 14,
  34542. 20,
  34543. 4,
  34544. 11,
  34545. 16,
  34546. 23,
  34547. 4,
  34548. 11,
  34549. 16,
  34550. 23,
  34551. 4,
  34552. 11,
  34553. 16,
  34554. 23,
  34555. 4,
  34556. 11,
  34557. 16,
  34558. 23,
  34559. 6,
  34560. 10,
  34561. 15,
  34562. 21,
  34563. 6,
  34564. 10,
  34565. 15,
  34566. 21,
  34567. 6,
  34568. 10,
  34569. 15,
  34570. 21,
  34571. 6,
  34572. 10,
  34573. 15,
  34574. 21
  34575. ]);
  34576. var k = new Int32Array([
  34577. -680876936,
  34578. -389564586,
  34579. 606105819,
  34580. -1044525330,
  34581. -176418897,
  34582. 1200080426,
  34583. -1473231341,
  34584. -45705983,
  34585. 1770035416,
  34586. -1958414417,
  34587. -42063,
  34588. -1990404162,
  34589. 1804603682,
  34590. -40341101,
  34591. -1502002290,
  34592. 1236535329,
  34593. -165796510,
  34594. -1069501632,
  34595. 643717713,
  34596. -373897302,
  34597. -701558691,
  34598. 38016083,
  34599. -660478335,
  34600. -405537848,
  34601. 568446438,
  34602. -1019803690,
  34603. -187363961,
  34604. 1163531501,
  34605. -1444681467,
  34606. -51403784,
  34607. 1735328473,
  34608. -1926607734,
  34609. -378558,
  34610. -2022574463,
  34611. 1839030562,
  34612. -35309556,
  34613. -1530992060,
  34614. 1272893353,
  34615. -155497632,
  34616. -1094730640,
  34617. 681279174,
  34618. -358537222,
  34619. -722521979,
  34620. 76029189,
  34621. -640364487,
  34622. -421815835,
  34623. 530742520,
  34624. -995338651,
  34625. -198630844,
  34626. 1126891415,
  34627. -1416354905,
  34628. -57434055,
  34629. 1700485571,
  34630. -1894986606,
  34631. -1051523,
  34632. -2054922799,
  34633. 1873313359,
  34634. -30611744,
  34635. -1560198380,
  34636. 1309151649,
  34637. -145523070,
  34638. -1120210379,
  34639. 718787259,
  34640. -343485551
  34641. ]);
  34642. function hash(data, offset, length) {
  34643. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  34644. // pre-processing
  34645. var paddedLength = length + 72 & ~63;
  34646. // data + 9 extra bytes
  34647. var padded = new Uint8Array(paddedLength);
  34648. var i, j, n;
  34649. for (i = 0; i < length; ++i) {
  34650. padded[i] = data[offset++];
  34651. }
  34652. padded[i++] = 0x80;
  34653. n = paddedLength - 8;
  34654. while (i < n) {
  34655. padded[i++] = 0;
  34656. }
  34657. padded[i++] = length << 3 & 0xFF;
  34658. padded[i++] = length >> 5 & 0xFF;
  34659. padded[i++] = length >> 13 & 0xFF;
  34660. padded[i++] = length >> 21 & 0xFF;
  34661. padded[i++] = length >>> 29 & 0xFF;
  34662. padded[i++] = 0;
  34663. padded[i++] = 0;
  34664. padded[i++] = 0;
  34665. var w = new Int32Array(16);
  34666. for (i = 0; i < paddedLength;) {
  34667. for (j = 0; j < 16; ++j, i += 4) {
  34668. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  34669. }
  34670. var a = h0, b = h1, c = h2, d = h3, f, g;
  34671. for (j = 0; j < 64; ++j) {
  34672. if (j < 16) {
  34673. f = b & c | ~b & d;
  34674. g = j;
  34675. } else if (j < 32) {
  34676. f = d & b | ~d & c;
  34677. g = 5 * j + 1 & 15;
  34678. } else if (j < 48) {
  34679. f = b ^ c ^ d;
  34680. g = 3 * j + 5 & 15;
  34681. } else {
  34682. f = c ^ (b | ~d);
  34683. g = 7 * j & 15;
  34684. }
  34685. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  34686. d = c;
  34687. c = b;
  34688. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  34689. a = tmp;
  34690. }
  34691. h0 = h0 + a | 0;
  34692. h1 = h1 + b | 0;
  34693. h2 = h2 + c | 0;
  34694. h3 = h3 + d | 0;
  34695. }
  34696. return new Uint8Array([
  34697. h0 & 0xFF,
  34698. h0 >> 8 & 0xFF,
  34699. h0 >> 16 & 0xFF,
  34700. h0 >>> 24 & 0xFF,
  34701. h1 & 0xFF,
  34702. h1 >> 8 & 0xFF,
  34703. h1 >> 16 & 0xFF,
  34704. h1 >>> 24 & 0xFF,
  34705. h2 & 0xFF,
  34706. h2 >> 8 & 0xFF,
  34707. h2 >> 16 & 0xFF,
  34708. h2 >>> 24 & 0xFF,
  34709. h3 & 0xFF,
  34710. h3 >> 8 & 0xFF,
  34711. h3 >> 16 & 0xFF,
  34712. h3 >>> 24 & 0xFF
  34713. ]);
  34714. }
  34715. return hash;
  34716. }();
  34717. var Word64 = function Word64Closure() {
  34718. function Word64(highInteger, lowInteger) {
  34719. this.high = highInteger | 0;
  34720. this.low = lowInteger | 0;
  34721. }
  34722. Word64.prototype = {
  34723. and: function Word64_and(word) {
  34724. this.high &= word.high;
  34725. this.low &= word.low;
  34726. },
  34727. xor: function Word64_xor(word) {
  34728. this.high ^= word.high;
  34729. this.low ^= word.low;
  34730. },
  34731. or: function Word64_or(word) {
  34732. this.high |= word.high;
  34733. this.low |= word.low;
  34734. },
  34735. shiftRight: function Word64_shiftRight(places) {
  34736. if (places >= 32) {
  34737. this.low = this.high >>> places - 32 | 0;
  34738. this.high = 0;
  34739. } else {
  34740. this.low = this.low >>> places | this.high << 32 - places;
  34741. this.high = this.high >>> places | 0;
  34742. }
  34743. },
  34744. shiftLeft: function Word64_shiftLeft(places) {
  34745. if (places >= 32) {
  34746. this.high = this.low << places - 32;
  34747. this.low = 0;
  34748. } else {
  34749. this.high = this.high << places | this.low >>> 32 - places;
  34750. this.low = this.low << places;
  34751. }
  34752. },
  34753. rotateRight: function Word64_rotateRight(places) {
  34754. var low, high;
  34755. if (places & 32) {
  34756. high = this.low;
  34757. low = this.high;
  34758. } else {
  34759. low = this.low;
  34760. high = this.high;
  34761. }
  34762. places &= 31;
  34763. this.low = low >>> places | high << 32 - places;
  34764. this.high = high >>> places | low << 32 - places;
  34765. },
  34766. not: function Word64_not() {
  34767. this.high = ~this.high;
  34768. this.low = ~this.low;
  34769. },
  34770. add: function Word64_add(word) {
  34771. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  34772. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  34773. if (lowAdd > 0xFFFFFFFF) {
  34774. highAdd += 1;
  34775. }
  34776. this.low = lowAdd | 0;
  34777. this.high = highAdd | 0;
  34778. },
  34779. copyTo: function Word64_copyTo(bytes, offset) {
  34780. bytes[offset] = this.high >>> 24 & 0xFF;
  34781. bytes[offset + 1] = this.high >> 16 & 0xFF;
  34782. bytes[offset + 2] = this.high >> 8 & 0xFF;
  34783. bytes[offset + 3] = this.high & 0xFF;
  34784. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  34785. bytes[offset + 5] = this.low >> 16 & 0xFF;
  34786. bytes[offset + 6] = this.low >> 8 & 0xFF;
  34787. bytes[offset + 7] = this.low & 0xFF;
  34788. },
  34789. assign: function Word64_assign(word) {
  34790. this.high = word.high;
  34791. this.low = word.low;
  34792. }
  34793. };
  34794. return Word64;
  34795. }();
  34796. var calculateSHA256 = function calculateSHA256Closure() {
  34797. function rotr(x, n) {
  34798. return x >>> n | x << 32 - n;
  34799. }
  34800. function ch(x, y, z) {
  34801. return x & y ^ ~x & z;
  34802. }
  34803. function maj(x, y, z) {
  34804. return x & y ^ x & z ^ y & z;
  34805. }
  34806. function sigma(x) {
  34807. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  34808. }
  34809. function sigmaPrime(x) {
  34810. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  34811. }
  34812. function littleSigma(x) {
  34813. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  34814. }
  34815. function littleSigmaPrime(x) {
  34816. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  34817. }
  34818. var k = [
  34819. 0x428a2f98,
  34820. 0x71374491,
  34821. 0xb5c0fbcf,
  34822. 0xe9b5dba5,
  34823. 0x3956c25b,
  34824. 0x59f111f1,
  34825. 0x923f82a4,
  34826. 0xab1c5ed5,
  34827. 0xd807aa98,
  34828. 0x12835b01,
  34829. 0x243185be,
  34830. 0x550c7dc3,
  34831. 0x72be5d74,
  34832. 0x80deb1fe,
  34833. 0x9bdc06a7,
  34834. 0xc19bf174,
  34835. 0xe49b69c1,
  34836. 0xefbe4786,
  34837. 0x0fc19dc6,
  34838. 0x240ca1cc,
  34839. 0x2de92c6f,
  34840. 0x4a7484aa,
  34841. 0x5cb0a9dc,
  34842. 0x76f988da,
  34843. 0x983e5152,
  34844. 0xa831c66d,
  34845. 0xb00327c8,
  34846. 0xbf597fc7,
  34847. 0xc6e00bf3,
  34848. 0xd5a79147,
  34849. 0x06ca6351,
  34850. 0x14292967,
  34851. 0x27b70a85,
  34852. 0x2e1b2138,
  34853. 0x4d2c6dfc,
  34854. 0x53380d13,
  34855. 0x650a7354,
  34856. 0x766a0abb,
  34857. 0x81c2c92e,
  34858. 0x92722c85,
  34859. 0xa2bfe8a1,
  34860. 0xa81a664b,
  34861. 0xc24b8b70,
  34862. 0xc76c51a3,
  34863. 0xd192e819,
  34864. 0xd6990624,
  34865. 0xf40e3585,
  34866. 0x106aa070,
  34867. 0x19a4c116,
  34868. 0x1e376c08,
  34869. 0x2748774c,
  34870. 0x34b0bcb5,
  34871. 0x391c0cb3,
  34872. 0x4ed8aa4a,
  34873. 0x5b9cca4f,
  34874. 0x682e6ff3,
  34875. 0x748f82ee,
  34876. 0x78a5636f,
  34877. 0x84c87814,
  34878. 0x8cc70208,
  34879. 0x90befffa,
  34880. 0xa4506ceb,
  34881. 0xbef9a3f7,
  34882. 0xc67178f2
  34883. ];
  34884. function hash(data, offset, length) {
  34885. // initial hash values
  34886. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  34887. // pre-processing
  34888. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  34889. var padded = new Uint8Array(paddedLength);
  34890. var i, j, n;
  34891. for (i = 0; i < length; ++i) {
  34892. padded[i] = data[offset++];
  34893. }
  34894. padded[i++] = 0x80;
  34895. n = paddedLength - 8;
  34896. while (i < n) {
  34897. padded[i++] = 0;
  34898. }
  34899. padded[i++] = 0;
  34900. padded[i++] = 0;
  34901. padded[i++] = 0;
  34902. padded[i++] = length >>> 29 & 0xFF;
  34903. padded[i++] = length >> 21 & 0xFF;
  34904. padded[i++] = length >> 13 & 0xFF;
  34905. padded[i++] = length >> 5 & 0xFF;
  34906. padded[i++] = length << 3 & 0xFF;
  34907. var w = new Uint32Array(64);
  34908. // for each 512 bit block
  34909. for (i = 0; i < paddedLength;) {
  34910. for (j = 0; j < 16; ++j) {
  34911. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  34912. i += 4;
  34913. }
  34914. for (j = 16; j < 64; ++j) {
  34915. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  34916. }
  34917. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  34918. for (j = 0; j < 64; ++j) {
  34919. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  34920. t2 = sigma(a) + maj(a, b, c);
  34921. h = g;
  34922. g = f;
  34923. f = e;
  34924. e = d + t1 | 0;
  34925. d = c;
  34926. c = b;
  34927. b = a;
  34928. a = t1 + t2 | 0;
  34929. }
  34930. h0 = h0 + a | 0;
  34931. h1 = h1 + b | 0;
  34932. h2 = h2 + c | 0;
  34933. h3 = h3 + d | 0;
  34934. h4 = h4 + e | 0;
  34935. h5 = h5 + f | 0;
  34936. h6 = h6 + g | 0;
  34937. h7 = h7 + h | 0;
  34938. }
  34939. return new Uint8Array([
  34940. h0 >> 24 & 0xFF,
  34941. h0 >> 16 & 0xFF,
  34942. h0 >> 8 & 0xFF,
  34943. h0 & 0xFF,
  34944. h1 >> 24 & 0xFF,
  34945. h1 >> 16 & 0xFF,
  34946. h1 >> 8 & 0xFF,
  34947. h1 & 0xFF,
  34948. h2 >> 24 & 0xFF,
  34949. h2 >> 16 & 0xFF,
  34950. h2 >> 8 & 0xFF,
  34951. h2 & 0xFF,
  34952. h3 >> 24 & 0xFF,
  34953. h3 >> 16 & 0xFF,
  34954. h3 >> 8 & 0xFF,
  34955. h3 & 0xFF,
  34956. h4 >> 24 & 0xFF,
  34957. h4 >> 16 & 0xFF,
  34958. h4 >> 8 & 0xFF,
  34959. h4 & 0xFF,
  34960. h5 >> 24 & 0xFF,
  34961. h5 >> 16 & 0xFF,
  34962. h5 >> 8 & 0xFF,
  34963. h5 & 0xFF,
  34964. h6 >> 24 & 0xFF,
  34965. h6 >> 16 & 0xFF,
  34966. h6 >> 8 & 0xFF,
  34967. h6 & 0xFF,
  34968. h7 >> 24 & 0xFF,
  34969. h7 >> 16 & 0xFF,
  34970. h7 >> 8 & 0xFF,
  34971. h7 & 0xFF
  34972. ]);
  34973. }
  34974. return hash;
  34975. }();
  34976. var calculateSHA512 = function calculateSHA512Closure() {
  34977. function ch(result, x, y, z, tmp) {
  34978. result.assign(x);
  34979. result.and(y);
  34980. tmp.assign(x);
  34981. tmp.not();
  34982. tmp.and(z);
  34983. result.xor(tmp);
  34984. }
  34985. function maj(result, x, y, z, tmp) {
  34986. result.assign(x);
  34987. result.and(y);
  34988. tmp.assign(x);
  34989. tmp.and(z);
  34990. result.xor(tmp);
  34991. tmp.assign(y);
  34992. tmp.and(z);
  34993. result.xor(tmp);
  34994. }
  34995. function sigma(result, x, tmp) {
  34996. result.assign(x);
  34997. result.rotateRight(28);
  34998. tmp.assign(x);
  34999. tmp.rotateRight(34);
  35000. result.xor(tmp);
  35001. tmp.assign(x);
  35002. tmp.rotateRight(39);
  35003. result.xor(tmp);
  35004. }
  35005. function sigmaPrime(result, x, tmp) {
  35006. result.assign(x);
  35007. result.rotateRight(14);
  35008. tmp.assign(x);
  35009. tmp.rotateRight(18);
  35010. result.xor(tmp);
  35011. tmp.assign(x);
  35012. tmp.rotateRight(41);
  35013. result.xor(tmp);
  35014. }
  35015. function littleSigma(result, x, tmp) {
  35016. result.assign(x);
  35017. result.rotateRight(1);
  35018. tmp.assign(x);
  35019. tmp.rotateRight(8);
  35020. result.xor(tmp);
  35021. tmp.assign(x);
  35022. tmp.shiftRight(7);
  35023. result.xor(tmp);
  35024. }
  35025. function littleSigmaPrime(result, x, tmp) {
  35026. result.assign(x);
  35027. result.rotateRight(19);
  35028. tmp.assign(x);
  35029. tmp.rotateRight(61);
  35030. result.xor(tmp);
  35031. tmp.assign(x);
  35032. tmp.shiftRight(6);
  35033. result.xor(tmp);
  35034. }
  35035. var k = [
  35036. new Word64(0x428a2f98, 0xd728ae22),
  35037. new Word64(0x71374491, 0x23ef65cd),
  35038. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  35039. new Word64(0xe9b5dba5, 0x8189dbbc),
  35040. new Word64(0x3956c25b, 0xf348b538),
  35041. new Word64(0x59f111f1, 0xb605d019),
  35042. new Word64(0x923f82a4, 0xaf194f9b),
  35043. new Word64(0xab1c5ed5, 0xda6d8118),
  35044. new Word64(0xd807aa98, 0xa3030242),
  35045. new Word64(0x12835b01, 0x45706fbe),
  35046. new Word64(0x243185be, 0x4ee4b28c),
  35047. new Word64(0x550c7dc3, 0xd5ffb4e2),
  35048. new Word64(0x72be5d74, 0xf27b896f),
  35049. new Word64(0x80deb1fe, 0x3b1696b1),
  35050. new Word64(0x9bdc06a7, 0x25c71235),
  35051. new Word64(0xc19bf174, 0xcf692694),
  35052. new Word64(0xe49b69c1, 0x9ef14ad2),
  35053. new Word64(0xefbe4786, 0x384f25e3),
  35054. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  35055. new Word64(0x240ca1cc, 0x77ac9c65),
  35056. new Word64(0x2de92c6f, 0x592b0275),
  35057. new Word64(0x4a7484aa, 0x6ea6e483),
  35058. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  35059. new Word64(0x76f988da, 0x831153b5),
  35060. new Word64(0x983e5152, 0xee66dfab),
  35061. new Word64(0xa831c66d, 0x2db43210),
  35062. new Word64(0xb00327c8, 0x98fb213f),
  35063. new Word64(0xbf597fc7, 0xbeef0ee4),
  35064. new Word64(0xc6e00bf3, 0x3da88fc2),
  35065. new Word64(0xd5a79147, 0x930aa725),
  35066. new Word64(0x06ca6351, 0xe003826f),
  35067. new Word64(0x14292967, 0x0a0e6e70),
  35068. new Word64(0x27b70a85, 0x46d22ffc),
  35069. new Word64(0x2e1b2138, 0x5c26c926),
  35070. new Word64(0x4d2c6dfc, 0x5ac42aed),
  35071. new Word64(0x53380d13, 0x9d95b3df),
  35072. new Word64(0x650a7354, 0x8baf63de),
  35073. new Word64(0x766a0abb, 0x3c77b2a8),
  35074. new Word64(0x81c2c92e, 0x47edaee6),
  35075. new Word64(0x92722c85, 0x1482353b),
  35076. new Word64(0xa2bfe8a1, 0x4cf10364),
  35077. new Word64(0xa81a664b, 0xbc423001),
  35078. new Word64(0xc24b8b70, 0xd0f89791),
  35079. new Word64(0xc76c51a3, 0x0654be30),
  35080. new Word64(0xd192e819, 0xd6ef5218),
  35081. new Word64(0xd6990624, 0x5565a910),
  35082. new Word64(0xf40e3585, 0x5771202a),
  35083. new Word64(0x106aa070, 0x32bbd1b8),
  35084. new Word64(0x19a4c116, 0xb8d2d0c8),
  35085. new Word64(0x1e376c08, 0x5141ab53),
  35086. new Word64(0x2748774c, 0xdf8eeb99),
  35087. new Word64(0x34b0bcb5, 0xe19b48a8),
  35088. new Word64(0x391c0cb3, 0xc5c95a63),
  35089. new Word64(0x4ed8aa4a, 0xe3418acb),
  35090. new Word64(0x5b9cca4f, 0x7763e373),
  35091. new Word64(0x682e6ff3, 0xd6b2b8a3),
  35092. new Word64(0x748f82ee, 0x5defb2fc),
  35093. new Word64(0x78a5636f, 0x43172f60),
  35094. new Word64(0x84c87814, 0xa1f0ab72),
  35095. new Word64(0x8cc70208, 0x1a6439ec),
  35096. new Word64(0x90befffa, 0x23631e28),
  35097. new Word64(0xa4506ceb, 0xde82bde9),
  35098. new Word64(0xbef9a3f7, 0xb2c67915),
  35099. new Word64(0xc67178f2, 0xe372532b),
  35100. new Word64(0xca273ece, 0xea26619c),
  35101. new Word64(0xd186b8c7, 0x21c0c207),
  35102. new Word64(0xeada7dd6, 0xcde0eb1e),
  35103. new Word64(0xf57d4f7f, 0xee6ed178),
  35104. new Word64(0x06f067aa, 0x72176fba),
  35105. new Word64(0x0a637dc5, 0xa2c898a6),
  35106. new Word64(0x113f9804, 0xbef90dae),
  35107. new Word64(0x1b710b35, 0x131c471b),
  35108. new Word64(0x28db77f5, 0x23047d84),
  35109. new Word64(0x32caab7b, 0x40c72493),
  35110. new Word64(0x3c9ebe0a, 0x15c9bebc),
  35111. new Word64(0x431d67c4, 0x9c100d4c),
  35112. new Word64(0x4cc5d4be, 0xcb3e42b6),
  35113. new Word64(0x597f299c, 0xfc657e2a),
  35114. new Word64(0x5fcb6fab, 0x3ad6faec),
  35115. new Word64(0x6c44198c, 0x4a475817)
  35116. ];
  35117. function hash(data, offset, length, mode384) {
  35118. mode384 = !!mode384;
  35119. // initial hash values
  35120. var h0, h1, h2, h3, h4, h5, h6, h7;
  35121. if (!mode384) {
  35122. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  35123. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  35124. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  35125. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  35126. h4 = new Word64(0x510e527f, 0xade682d1);
  35127. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  35128. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  35129. h7 = new Word64(0x5be0cd19, 0x137e2179);
  35130. } else {
  35131. // SHA384 is exactly the same
  35132. // except with different starting values and a trimmed result
  35133. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  35134. h1 = new Word64(0x629a292a, 0x367cd507);
  35135. h2 = new Word64(0x9159015a, 0x3070dd17);
  35136. h3 = new Word64(0x152fecd8, 0xf70e5939);
  35137. h4 = new Word64(0x67332667, 0xffc00b31);
  35138. h5 = new Word64(0x8eb44a87, 0x68581511);
  35139. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  35140. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  35141. }
  35142. // pre-processing
  35143. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  35144. var padded = new Uint8Array(paddedLength);
  35145. var i, j, n;
  35146. for (i = 0; i < length; ++i) {
  35147. padded[i] = data[offset++];
  35148. }
  35149. padded[i++] = 0x80;
  35150. n = paddedLength - 16;
  35151. while (i < n) {
  35152. padded[i++] = 0;
  35153. }
  35154. padded[i++] = 0;
  35155. padded[i++] = 0;
  35156. padded[i++] = 0;
  35157. padded[i++] = 0;
  35158. padded[i++] = 0;
  35159. padded[i++] = 0;
  35160. padded[i++] = 0;
  35161. padded[i++] = 0;
  35162. padded[i++] = 0;
  35163. padded[i++] = 0;
  35164. padded[i++] = 0;
  35165. padded[i++] = length >>> 29 & 0xFF;
  35166. padded[i++] = length >> 21 & 0xFF;
  35167. padded[i++] = length >> 13 & 0xFF;
  35168. padded[i++] = length >> 5 & 0xFF;
  35169. padded[i++] = length << 3 & 0xFF;
  35170. var w = new Array(80);
  35171. for (i = 0; i < 80; i++) {
  35172. w[i] = new Word64(0, 0);
  35173. }
  35174. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  35175. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  35176. var g = new Word64(0, 0), h = new Word64(0, 0);
  35177. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  35178. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  35179. // for each 1024 bit block
  35180. for (i = 0; i < paddedLength;) {
  35181. for (j = 0; j < 16; ++j) {
  35182. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  35183. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  35184. i += 8;
  35185. }
  35186. for (j = 16; j < 80; ++j) {
  35187. tmp3 = w[j];
  35188. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  35189. tmp3.add(w[j - 7]);
  35190. littleSigma(tmp1, w[j - 15], tmp2);
  35191. tmp3.add(tmp1);
  35192. tmp3.add(w[j - 16]);
  35193. }
  35194. a.assign(h0);
  35195. b.assign(h1);
  35196. c.assign(h2);
  35197. d.assign(h3);
  35198. e.assign(h4);
  35199. f.assign(h5);
  35200. g.assign(h6);
  35201. h.assign(h7);
  35202. for (j = 0; j < 80; ++j) {
  35203. t1.assign(h);
  35204. sigmaPrime(tmp1, e, tmp2);
  35205. t1.add(tmp1);
  35206. ch(tmp1, e, f, g, tmp2);
  35207. t1.add(tmp1);
  35208. t1.add(k[j]);
  35209. t1.add(w[j]);
  35210. sigma(t2, a, tmp2);
  35211. maj(tmp1, a, b, c, tmp2);
  35212. t2.add(tmp1);
  35213. tmp3 = h;
  35214. h = g;
  35215. g = f;
  35216. f = e;
  35217. d.add(t1);
  35218. e = d;
  35219. d = c;
  35220. c = b;
  35221. b = a;
  35222. tmp3.assign(t1);
  35223. tmp3.add(t2);
  35224. a = tmp3;
  35225. }
  35226. h0.add(a);
  35227. h1.add(b);
  35228. h2.add(c);
  35229. h3.add(d);
  35230. h4.add(e);
  35231. h5.add(f);
  35232. h6.add(g);
  35233. h7.add(h);
  35234. }
  35235. var result;
  35236. if (!mode384) {
  35237. result = new Uint8Array(64);
  35238. h0.copyTo(result, 0);
  35239. h1.copyTo(result, 8);
  35240. h2.copyTo(result, 16);
  35241. h3.copyTo(result, 24);
  35242. h4.copyTo(result, 32);
  35243. h5.copyTo(result, 40);
  35244. h6.copyTo(result, 48);
  35245. h7.copyTo(result, 56);
  35246. } else {
  35247. result = new Uint8Array(48);
  35248. h0.copyTo(result, 0);
  35249. h1.copyTo(result, 8);
  35250. h2.copyTo(result, 16);
  35251. h3.copyTo(result, 24);
  35252. h4.copyTo(result, 32);
  35253. h5.copyTo(result, 40);
  35254. }
  35255. return result;
  35256. }
  35257. return hash;
  35258. }();
  35259. var calculateSHA384 = function calculateSHA384Closure() {
  35260. function hash(data, offset, length) {
  35261. return calculateSHA512(data, offset, length, true);
  35262. }
  35263. return hash;
  35264. }();
  35265. var NullCipher = function NullCipherClosure() {
  35266. function NullCipher() {
  35267. }
  35268. NullCipher.prototype = {
  35269. decryptBlock: function NullCipher_decryptBlock(data) {
  35270. return data;
  35271. }
  35272. };
  35273. return NullCipher;
  35274. }();
  35275. var AES128Cipher = function AES128CipherClosure() {
  35276. var rcon = new Uint8Array([
  35277. 0x8d,
  35278. 0x01,
  35279. 0x02,
  35280. 0x04,
  35281. 0x08,
  35282. 0x10,
  35283. 0x20,
  35284. 0x40,
  35285. 0x80,
  35286. 0x1b,
  35287. 0x36,
  35288. 0x6c,
  35289. 0xd8,
  35290. 0xab,
  35291. 0x4d,
  35292. 0x9a,
  35293. 0x2f,
  35294. 0x5e,
  35295. 0xbc,
  35296. 0x63,
  35297. 0xc6,
  35298. 0x97,
  35299. 0x35,
  35300. 0x6a,
  35301. 0xd4,
  35302. 0xb3,
  35303. 0x7d,
  35304. 0xfa,
  35305. 0xef,
  35306. 0xc5,
  35307. 0x91,
  35308. 0x39,
  35309. 0x72,
  35310. 0xe4,
  35311. 0xd3,
  35312. 0xbd,
  35313. 0x61,
  35314. 0xc2,
  35315. 0x9f,
  35316. 0x25,
  35317. 0x4a,
  35318. 0x94,
  35319. 0x33,
  35320. 0x66,
  35321. 0xcc,
  35322. 0x83,
  35323. 0x1d,
  35324. 0x3a,
  35325. 0x74,
  35326. 0xe8,
  35327. 0xcb,
  35328. 0x8d,
  35329. 0x01,
  35330. 0x02,
  35331. 0x04,
  35332. 0x08,
  35333. 0x10,
  35334. 0x20,
  35335. 0x40,
  35336. 0x80,
  35337. 0x1b,
  35338. 0x36,
  35339. 0x6c,
  35340. 0xd8,
  35341. 0xab,
  35342. 0x4d,
  35343. 0x9a,
  35344. 0x2f,
  35345. 0x5e,
  35346. 0xbc,
  35347. 0x63,
  35348. 0xc6,
  35349. 0x97,
  35350. 0x35,
  35351. 0x6a,
  35352. 0xd4,
  35353. 0xb3,
  35354. 0x7d,
  35355. 0xfa,
  35356. 0xef,
  35357. 0xc5,
  35358. 0x91,
  35359. 0x39,
  35360. 0x72,
  35361. 0xe4,
  35362. 0xd3,
  35363. 0xbd,
  35364. 0x61,
  35365. 0xc2,
  35366. 0x9f,
  35367. 0x25,
  35368. 0x4a,
  35369. 0x94,
  35370. 0x33,
  35371. 0x66,
  35372. 0xcc,
  35373. 0x83,
  35374. 0x1d,
  35375. 0x3a,
  35376. 0x74,
  35377. 0xe8,
  35378. 0xcb,
  35379. 0x8d,
  35380. 0x01,
  35381. 0x02,
  35382. 0x04,
  35383. 0x08,
  35384. 0x10,
  35385. 0x20,
  35386. 0x40,
  35387. 0x80,
  35388. 0x1b,
  35389. 0x36,
  35390. 0x6c,
  35391. 0xd8,
  35392. 0xab,
  35393. 0x4d,
  35394. 0x9a,
  35395. 0x2f,
  35396. 0x5e,
  35397. 0xbc,
  35398. 0x63,
  35399. 0xc6,
  35400. 0x97,
  35401. 0x35,
  35402. 0x6a,
  35403. 0xd4,
  35404. 0xb3,
  35405. 0x7d,
  35406. 0xfa,
  35407. 0xef,
  35408. 0xc5,
  35409. 0x91,
  35410. 0x39,
  35411. 0x72,
  35412. 0xe4,
  35413. 0xd3,
  35414. 0xbd,
  35415. 0x61,
  35416. 0xc2,
  35417. 0x9f,
  35418. 0x25,
  35419. 0x4a,
  35420. 0x94,
  35421. 0x33,
  35422. 0x66,
  35423. 0xcc,
  35424. 0x83,
  35425. 0x1d,
  35426. 0x3a,
  35427. 0x74,
  35428. 0xe8,
  35429. 0xcb,
  35430. 0x8d,
  35431. 0x01,
  35432. 0x02,
  35433. 0x04,
  35434. 0x08,
  35435. 0x10,
  35436. 0x20,
  35437. 0x40,
  35438. 0x80,
  35439. 0x1b,
  35440. 0x36,
  35441. 0x6c,
  35442. 0xd8,
  35443. 0xab,
  35444. 0x4d,
  35445. 0x9a,
  35446. 0x2f,
  35447. 0x5e,
  35448. 0xbc,
  35449. 0x63,
  35450. 0xc6,
  35451. 0x97,
  35452. 0x35,
  35453. 0x6a,
  35454. 0xd4,
  35455. 0xb3,
  35456. 0x7d,
  35457. 0xfa,
  35458. 0xef,
  35459. 0xc5,
  35460. 0x91,
  35461. 0x39,
  35462. 0x72,
  35463. 0xe4,
  35464. 0xd3,
  35465. 0xbd,
  35466. 0x61,
  35467. 0xc2,
  35468. 0x9f,
  35469. 0x25,
  35470. 0x4a,
  35471. 0x94,
  35472. 0x33,
  35473. 0x66,
  35474. 0xcc,
  35475. 0x83,
  35476. 0x1d,
  35477. 0x3a,
  35478. 0x74,
  35479. 0xe8,
  35480. 0xcb,
  35481. 0x8d,
  35482. 0x01,
  35483. 0x02,
  35484. 0x04,
  35485. 0x08,
  35486. 0x10,
  35487. 0x20,
  35488. 0x40,
  35489. 0x80,
  35490. 0x1b,
  35491. 0x36,
  35492. 0x6c,
  35493. 0xd8,
  35494. 0xab,
  35495. 0x4d,
  35496. 0x9a,
  35497. 0x2f,
  35498. 0x5e,
  35499. 0xbc,
  35500. 0x63,
  35501. 0xc6,
  35502. 0x97,
  35503. 0x35,
  35504. 0x6a,
  35505. 0xd4,
  35506. 0xb3,
  35507. 0x7d,
  35508. 0xfa,
  35509. 0xef,
  35510. 0xc5,
  35511. 0x91,
  35512. 0x39,
  35513. 0x72,
  35514. 0xe4,
  35515. 0xd3,
  35516. 0xbd,
  35517. 0x61,
  35518. 0xc2,
  35519. 0x9f,
  35520. 0x25,
  35521. 0x4a,
  35522. 0x94,
  35523. 0x33,
  35524. 0x66,
  35525. 0xcc,
  35526. 0x83,
  35527. 0x1d,
  35528. 0x3a,
  35529. 0x74,
  35530. 0xe8,
  35531. 0xcb,
  35532. 0x8d
  35533. ]);
  35534. var s = new Uint8Array([
  35535. 0x63,
  35536. 0x7c,
  35537. 0x77,
  35538. 0x7b,
  35539. 0xf2,
  35540. 0x6b,
  35541. 0x6f,
  35542. 0xc5,
  35543. 0x30,
  35544. 0x01,
  35545. 0x67,
  35546. 0x2b,
  35547. 0xfe,
  35548. 0xd7,
  35549. 0xab,
  35550. 0x76,
  35551. 0xca,
  35552. 0x82,
  35553. 0xc9,
  35554. 0x7d,
  35555. 0xfa,
  35556. 0x59,
  35557. 0x47,
  35558. 0xf0,
  35559. 0xad,
  35560. 0xd4,
  35561. 0xa2,
  35562. 0xaf,
  35563. 0x9c,
  35564. 0xa4,
  35565. 0x72,
  35566. 0xc0,
  35567. 0xb7,
  35568. 0xfd,
  35569. 0x93,
  35570. 0x26,
  35571. 0x36,
  35572. 0x3f,
  35573. 0xf7,
  35574. 0xcc,
  35575. 0x34,
  35576. 0xa5,
  35577. 0xe5,
  35578. 0xf1,
  35579. 0x71,
  35580. 0xd8,
  35581. 0x31,
  35582. 0x15,
  35583. 0x04,
  35584. 0xc7,
  35585. 0x23,
  35586. 0xc3,
  35587. 0x18,
  35588. 0x96,
  35589. 0x05,
  35590. 0x9a,
  35591. 0x07,
  35592. 0x12,
  35593. 0x80,
  35594. 0xe2,
  35595. 0xeb,
  35596. 0x27,
  35597. 0xb2,
  35598. 0x75,
  35599. 0x09,
  35600. 0x83,
  35601. 0x2c,
  35602. 0x1a,
  35603. 0x1b,
  35604. 0x6e,
  35605. 0x5a,
  35606. 0xa0,
  35607. 0x52,
  35608. 0x3b,
  35609. 0xd6,
  35610. 0xb3,
  35611. 0x29,
  35612. 0xe3,
  35613. 0x2f,
  35614. 0x84,
  35615. 0x53,
  35616. 0xd1,
  35617. 0x00,
  35618. 0xed,
  35619. 0x20,
  35620. 0xfc,
  35621. 0xb1,
  35622. 0x5b,
  35623. 0x6a,
  35624. 0xcb,
  35625. 0xbe,
  35626. 0x39,
  35627. 0x4a,
  35628. 0x4c,
  35629. 0x58,
  35630. 0xcf,
  35631. 0xd0,
  35632. 0xef,
  35633. 0xaa,
  35634. 0xfb,
  35635. 0x43,
  35636. 0x4d,
  35637. 0x33,
  35638. 0x85,
  35639. 0x45,
  35640. 0xf9,
  35641. 0x02,
  35642. 0x7f,
  35643. 0x50,
  35644. 0x3c,
  35645. 0x9f,
  35646. 0xa8,
  35647. 0x51,
  35648. 0xa3,
  35649. 0x40,
  35650. 0x8f,
  35651. 0x92,
  35652. 0x9d,
  35653. 0x38,
  35654. 0xf5,
  35655. 0xbc,
  35656. 0xb6,
  35657. 0xda,
  35658. 0x21,
  35659. 0x10,
  35660. 0xff,
  35661. 0xf3,
  35662. 0xd2,
  35663. 0xcd,
  35664. 0x0c,
  35665. 0x13,
  35666. 0xec,
  35667. 0x5f,
  35668. 0x97,
  35669. 0x44,
  35670. 0x17,
  35671. 0xc4,
  35672. 0xa7,
  35673. 0x7e,
  35674. 0x3d,
  35675. 0x64,
  35676. 0x5d,
  35677. 0x19,
  35678. 0x73,
  35679. 0x60,
  35680. 0x81,
  35681. 0x4f,
  35682. 0xdc,
  35683. 0x22,
  35684. 0x2a,
  35685. 0x90,
  35686. 0x88,
  35687. 0x46,
  35688. 0xee,
  35689. 0xb8,
  35690. 0x14,
  35691. 0xde,
  35692. 0x5e,
  35693. 0x0b,
  35694. 0xdb,
  35695. 0xe0,
  35696. 0x32,
  35697. 0x3a,
  35698. 0x0a,
  35699. 0x49,
  35700. 0x06,
  35701. 0x24,
  35702. 0x5c,
  35703. 0xc2,
  35704. 0xd3,
  35705. 0xac,
  35706. 0x62,
  35707. 0x91,
  35708. 0x95,
  35709. 0xe4,
  35710. 0x79,
  35711. 0xe7,
  35712. 0xc8,
  35713. 0x37,
  35714. 0x6d,
  35715. 0x8d,
  35716. 0xd5,
  35717. 0x4e,
  35718. 0xa9,
  35719. 0x6c,
  35720. 0x56,
  35721. 0xf4,
  35722. 0xea,
  35723. 0x65,
  35724. 0x7a,
  35725. 0xae,
  35726. 0x08,
  35727. 0xba,
  35728. 0x78,
  35729. 0x25,
  35730. 0x2e,
  35731. 0x1c,
  35732. 0xa6,
  35733. 0xb4,
  35734. 0xc6,
  35735. 0xe8,
  35736. 0xdd,
  35737. 0x74,
  35738. 0x1f,
  35739. 0x4b,
  35740. 0xbd,
  35741. 0x8b,
  35742. 0x8a,
  35743. 0x70,
  35744. 0x3e,
  35745. 0xb5,
  35746. 0x66,
  35747. 0x48,
  35748. 0x03,
  35749. 0xf6,
  35750. 0x0e,
  35751. 0x61,
  35752. 0x35,
  35753. 0x57,
  35754. 0xb9,
  35755. 0x86,
  35756. 0xc1,
  35757. 0x1d,
  35758. 0x9e,
  35759. 0xe1,
  35760. 0xf8,
  35761. 0x98,
  35762. 0x11,
  35763. 0x69,
  35764. 0xd9,
  35765. 0x8e,
  35766. 0x94,
  35767. 0x9b,
  35768. 0x1e,
  35769. 0x87,
  35770. 0xe9,
  35771. 0xce,
  35772. 0x55,
  35773. 0x28,
  35774. 0xdf,
  35775. 0x8c,
  35776. 0xa1,
  35777. 0x89,
  35778. 0x0d,
  35779. 0xbf,
  35780. 0xe6,
  35781. 0x42,
  35782. 0x68,
  35783. 0x41,
  35784. 0x99,
  35785. 0x2d,
  35786. 0x0f,
  35787. 0xb0,
  35788. 0x54,
  35789. 0xbb,
  35790. 0x16
  35791. ]);
  35792. var inv_s = new Uint8Array([
  35793. 0x52,
  35794. 0x09,
  35795. 0x6a,
  35796. 0xd5,
  35797. 0x30,
  35798. 0x36,
  35799. 0xa5,
  35800. 0x38,
  35801. 0xbf,
  35802. 0x40,
  35803. 0xa3,
  35804. 0x9e,
  35805. 0x81,
  35806. 0xf3,
  35807. 0xd7,
  35808. 0xfb,
  35809. 0x7c,
  35810. 0xe3,
  35811. 0x39,
  35812. 0x82,
  35813. 0x9b,
  35814. 0x2f,
  35815. 0xff,
  35816. 0x87,
  35817. 0x34,
  35818. 0x8e,
  35819. 0x43,
  35820. 0x44,
  35821. 0xc4,
  35822. 0xde,
  35823. 0xe9,
  35824. 0xcb,
  35825. 0x54,
  35826. 0x7b,
  35827. 0x94,
  35828. 0x32,
  35829. 0xa6,
  35830. 0xc2,
  35831. 0x23,
  35832. 0x3d,
  35833. 0xee,
  35834. 0x4c,
  35835. 0x95,
  35836. 0x0b,
  35837. 0x42,
  35838. 0xfa,
  35839. 0xc3,
  35840. 0x4e,
  35841. 0x08,
  35842. 0x2e,
  35843. 0xa1,
  35844. 0x66,
  35845. 0x28,
  35846. 0xd9,
  35847. 0x24,
  35848. 0xb2,
  35849. 0x76,
  35850. 0x5b,
  35851. 0xa2,
  35852. 0x49,
  35853. 0x6d,
  35854. 0x8b,
  35855. 0xd1,
  35856. 0x25,
  35857. 0x72,
  35858. 0xf8,
  35859. 0xf6,
  35860. 0x64,
  35861. 0x86,
  35862. 0x68,
  35863. 0x98,
  35864. 0x16,
  35865. 0xd4,
  35866. 0xa4,
  35867. 0x5c,
  35868. 0xcc,
  35869. 0x5d,
  35870. 0x65,
  35871. 0xb6,
  35872. 0x92,
  35873. 0x6c,
  35874. 0x70,
  35875. 0x48,
  35876. 0x50,
  35877. 0xfd,
  35878. 0xed,
  35879. 0xb9,
  35880. 0xda,
  35881. 0x5e,
  35882. 0x15,
  35883. 0x46,
  35884. 0x57,
  35885. 0xa7,
  35886. 0x8d,
  35887. 0x9d,
  35888. 0x84,
  35889. 0x90,
  35890. 0xd8,
  35891. 0xab,
  35892. 0x00,
  35893. 0x8c,
  35894. 0xbc,
  35895. 0xd3,
  35896. 0x0a,
  35897. 0xf7,
  35898. 0xe4,
  35899. 0x58,
  35900. 0x05,
  35901. 0xb8,
  35902. 0xb3,
  35903. 0x45,
  35904. 0x06,
  35905. 0xd0,
  35906. 0x2c,
  35907. 0x1e,
  35908. 0x8f,
  35909. 0xca,
  35910. 0x3f,
  35911. 0x0f,
  35912. 0x02,
  35913. 0xc1,
  35914. 0xaf,
  35915. 0xbd,
  35916. 0x03,
  35917. 0x01,
  35918. 0x13,
  35919. 0x8a,
  35920. 0x6b,
  35921. 0x3a,
  35922. 0x91,
  35923. 0x11,
  35924. 0x41,
  35925. 0x4f,
  35926. 0x67,
  35927. 0xdc,
  35928. 0xea,
  35929. 0x97,
  35930. 0xf2,
  35931. 0xcf,
  35932. 0xce,
  35933. 0xf0,
  35934. 0xb4,
  35935. 0xe6,
  35936. 0x73,
  35937. 0x96,
  35938. 0xac,
  35939. 0x74,
  35940. 0x22,
  35941. 0xe7,
  35942. 0xad,
  35943. 0x35,
  35944. 0x85,
  35945. 0xe2,
  35946. 0xf9,
  35947. 0x37,
  35948. 0xe8,
  35949. 0x1c,
  35950. 0x75,
  35951. 0xdf,
  35952. 0x6e,
  35953. 0x47,
  35954. 0xf1,
  35955. 0x1a,
  35956. 0x71,
  35957. 0x1d,
  35958. 0x29,
  35959. 0xc5,
  35960. 0x89,
  35961. 0x6f,
  35962. 0xb7,
  35963. 0x62,
  35964. 0x0e,
  35965. 0xaa,
  35966. 0x18,
  35967. 0xbe,
  35968. 0x1b,
  35969. 0xfc,
  35970. 0x56,
  35971. 0x3e,
  35972. 0x4b,
  35973. 0xc6,
  35974. 0xd2,
  35975. 0x79,
  35976. 0x20,
  35977. 0x9a,
  35978. 0xdb,
  35979. 0xc0,
  35980. 0xfe,
  35981. 0x78,
  35982. 0xcd,
  35983. 0x5a,
  35984. 0xf4,
  35985. 0x1f,
  35986. 0xdd,
  35987. 0xa8,
  35988. 0x33,
  35989. 0x88,
  35990. 0x07,
  35991. 0xc7,
  35992. 0x31,
  35993. 0xb1,
  35994. 0x12,
  35995. 0x10,
  35996. 0x59,
  35997. 0x27,
  35998. 0x80,
  35999. 0xec,
  36000. 0x5f,
  36001. 0x60,
  36002. 0x51,
  36003. 0x7f,
  36004. 0xa9,
  36005. 0x19,
  36006. 0xb5,
  36007. 0x4a,
  36008. 0x0d,
  36009. 0x2d,
  36010. 0xe5,
  36011. 0x7a,
  36012. 0x9f,
  36013. 0x93,
  36014. 0xc9,
  36015. 0x9c,
  36016. 0xef,
  36017. 0xa0,
  36018. 0xe0,
  36019. 0x3b,
  36020. 0x4d,
  36021. 0xae,
  36022. 0x2a,
  36023. 0xf5,
  36024. 0xb0,
  36025. 0xc8,
  36026. 0xeb,
  36027. 0xbb,
  36028. 0x3c,
  36029. 0x83,
  36030. 0x53,
  36031. 0x99,
  36032. 0x61,
  36033. 0x17,
  36034. 0x2b,
  36035. 0x04,
  36036. 0x7e,
  36037. 0xba,
  36038. 0x77,
  36039. 0xd6,
  36040. 0x26,
  36041. 0xe1,
  36042. 0x69,
  36043. 0x14,
  36044. 0x63,
  36045. 0x55,
  36046. 0x21,
  36047. 0x0c,
  36048. 0x7d
  36049. ]);
  36050. var mixCol = new Uint8Array(256);
  36051. for (var i = 0; i < 256; i++) {
  36052. if (i < 128) {
  36053. mixCol[i] = i << 1;
  36054. } else {
  36055. mixCol[i] = i << 1 ^ 0x1b;
  36056. }
  36057. }
  36058. var mix = new Uint32Array([
  36059. 0x00000000,
  36060. 0x0e090d0b,
  36061. 0x1c121a16,
  36062. 0x121b171d,
  36063. 0x3824342c,
  36064. 0x362d3927,
  36065. 0x24362e3a,
  36066. 0x2a3f2331,
  36067. 0x70486858,
  36068. 0x7e416553,
  36069. 0x6c5a724e,
  36070. 0x62537f45,
  36071. 0x486c5c74,
  36072. 0x4665517f,
  36073. 0x547e4662,
  36074. 0x5a774b69,
  36075. 0xe090d0b0,
  36076. 0xee99ddbb,
  36077. 0xfc82caa6,
  36078. 0xf28bc7ad,
  36079. 0xd8b4e49c,
  36080. 0xd6bde997,
  36081. 0xc4a6fe8a,
  36082. 0xcaaff381,
  36083. 0x90d8b8e8,
  36084. 0x9ed1b5e3,
  36085. 0x8ccaa2fe,
  36086. 0x82c3aff5,
  36087. 0xa8fc8cc4,
  36088. 0xa6f581cf,
  36089. 0xb4ee96d2,
  36090. 0xbae79bd9,
  36091. 0xdb3bbb7b,
  36092. 0xd532b670,
  36093. 0xc729a16d,
  36094. 0xc920ac66,
  36095. 0xe31f8f57,
  36096. 0xed16825c,
  36097. 0xff0d9541,
  36098. 0xf104984a,
  36099. 0xab73d323,
  36100. 0xa57ade28,
  36101. 0xb761c935,
  36102. 0xb968c43e,
  36103. 0x9357e70f,
  36104. 0x9d5eea04,
  36105. 0x8f45fd19,
  36106. 0x814cf012,
  36107. 0x3bab6bcb,
  36108. 0x35a266c0,
  36109. 0x27b971dd,
  36110. 0x29b07cd6,
  36111. 0x038f5fe7,
  36112. 0x0d8652ec,
  36113. 0x1f9d45f1,
  36114. 0x119448fa,
  36115. 0x4be30393,
  36116. 0x45ea0e98,
  36117. 0x57f11985,
  36118. 0x59f8148e,
  36119. 0x73c737bf,
  36120. 0x7dce3ab4,
  36121. 0x6fd52da9,
  36122. 0x61dc20a2,
  36123. 0xad766df6,
  36124. 0xa37f60fd,
  36125. 0xb16477e0,
  36126. 0xbf6d7aeb,
  36127. 0x955259da,
  36128. 0x9b5b54d1,
  36129. 0x894043cc,
  36130. 0x87494ec7,
  36131. 0xdd3e05ae,
  36132. 0xd33708a5,
  36133. 0xc12c1fb8,
  36134. 0xcf2512b3,
  36135. 0xe51a3182,
  36136. 0xeb133c89,
  36137. 0xf9082b94,
  36138. 0xf701269f,
  36139. 0x4de6bd46,
  36140. 0x43efb04d,
  36141. 0x51f4a750,
  36142. 0x5ffdaa5b,
  36143. 0x75c2896a,
  36144. 0x7bcb8461,
  36145. 0x69d0937c,
  36146. 0x67d99e77,
  36147. 0x3daed51e,
  36148. 0x33a7d815,
  36149. 0x21bccf08,
  36150. 0x2fb5c203,
  36151. 0x058ae132,
  36152. 0x0b83ec39,
  36153. 0x1998fb24,
  36154. 0x1791f62f,
  36155. 0x764dd68d,
  36156. 0x7844db86,
  36157. 0x6a5fcc9b,
  36158. 0x6456c190,
  36159. 0x4e69e2a1,
  36160. 0x4060efaa,
  36161. 0x527bf8b7,
  36162. 0x5c72f5bc,
  36163. 0x0605bed5,
  36164. 0x080cb3de,
  36165. 0x1a17a4c3,
  36166. 0x141ea9c8,
  36167. 0x3e218af9,
  36168. 0x302887f2,
  36169. 0x223390ef,
  36170. 0x2c3a9de4,
  36171. 0x96dd063d,
  36172. 0x98d40b36,
  36173. 0x8acf1c2b,
  36174. 0x84c61120,
  36175. 0xaef93211,
  36176. 0xa0f03f1a,
  36177. 0xb2eb2807,
  36178. 0xbce2250c,
  36179. 0xe6956e65,
  36180. 0xe89c636e,
  36181. 0xfa877473,
  36182. 0xf48e7978,
  36183. 0xdeb15a49,
  36184. 0xd0b85742,
  36185. 0xc2a3405f,
  36186. 0xccaa4d54,
  36187. 0x41ecdaf7,
  36188. 0x4fe5d7fc,
  36189. 0x5dfec0e1,
  36190. 0x53f7cdea,
  36191. 0x79c8eedb,
  36192. 0x77c1e3d0,
  36193. 0x65daf4cd,
  36194. 0x6bd3f9c6,
  36195. 0x31a4b2af,
  36196. 0x3fadbfa4,
  36197. 0x2db6a8b9,
  36198. 0x23bfa5b2,
  36199. 0x09808683,
  36200. 0x07898b88,
  36201. 0x15929c95,
  36202. 0x1b9b919e,
  36203. 0xa17c0a47,
  36204. 0xaf75074c,
  36205. 0xbd6e1051,
  36206. 0xb3671d5a,
  36207. 0x99583e6b,
  36208. 0x97513360,
  36209. 0x854a247d,
  36210. 0x8b432976,
  36211. 0xd134621f,
  36212. 0xdf3d6f14,
  36213. 0xcd267809,
  36214. 0xc32f7502,
  36215. 0xe9105633,
  36216. 0xe7195b38,
  36217. 0xf5024c25,
  36218. 0xfb0b412e,
  36219. 0x9ad7618c,
  36220. 0x94de6c87,
  36221. 0x86c57b9a,
  36222. 0x88cc7691,
  36223. 0xa2f355a0,
  36224. 0xacfa58ab,
  36225. 0xbee14fb6,
  36226. 0xb0e842bd,
  36227. 0xea9f09d4,
  36228. 0xe49604df,
  36229. 0xf68d13c2,
  36230. 0xf8841ec9,
  36231. 0xd2bb3df8,
  36232. 0xdcb230f3,
  36233. 0xcea927ee,
  36234. 0xc0a02ae5,
  36235. 0x7a47b13c,
  36236. 0x744ebc37,
  36237. 0x6655ab2a,
  36238. 0x685ca621,
  36239. 0x42638510,
  36240. 0x4c6a881b,
  36241. 0x5e719f06,
  36242. 0x5078920d,
  36243. 0x0a0fd964,
  36244. 0x0406d46f,
  36245. 0x161dc372,
  36246. 0x1814ce79,
  36247. 0x322bed48,
  36248. 0x3c22e043,
  36249. 0x2e39f75e,
  36250. 0x2030fa55,
  36251. 0xec9ab701,
  36252. 0xe293ba0a,
  36253. 0xf088ad17,
  36254. 0xfe81a01c,
  36255. 0xd4be832d,
  36256. 0xdab78e26,
  36257. 0xc8ac993b,
  36258. 0xc6a59430,
  36259. 0x9cd2df59,
  36260. 0x92dbd252,
  36261. 0x80c0c54f,
  36262. 0x8ec9c844,
  36263. 0xa4f6eb75,
  36264. 0xaaffe67e,
  36265. 0xb8e4f163,
  36266. 0xb6edfc68,
  36267. 0x0c0a67b1,
  36268. 0x02036aba,
  36269. 0x10187da7,
  36270. 0x1e1170ac,
  36271. 0x342e539d,
  36272. 0x3a275e96,
  36273. 0x283c498b,
  36274. 0x26354480,
  36275. 0x7c420fe9,
  36276. 0x724b02e2,
  36277. 0x605015ff,
  36278. 0x6e5918f4,
  36279. 0x44663bc5,
  36280. 0x4a6f36ce,
  36281. 0x587421d3,
  36282. 0x567d2cd8,
  36283. 0x37a10c7a,
  36284. 0x39a80171,
  36285. 0x2bb3166c,
  36286. 0x25ba1b67,
  36287. 0x0f853856,
  36288. 0x018c355d,
  36289. 0x13972240,
  36290. 0x1d9e2f4b,
  36291. 0x47e96422,
  36292. 0x49e06929,
  36293. 0x5bfb7e34,
  36294. 0x55f2733f,
  36295. 0x7fcd500e,
  36296. 0x71c45d05,
  36297. 0x63df4a18,
  36298. 0x6dd64713,
  36299. 0xd731dcca,
  36300. 0xd938d1c1,
  36301. 0xcb23c6dc,
  36302. 0xc52acbd7,
  36303. 0xef15e8e6,
  36304. 0xe11ce5ed,
  36305. 0xf307f2f0,
  36306. 0xfd0efffb,
  36307. 0xa779b492,
  36308. 0xa970b999,
  36309. 0xbb6bae84,
  36310. 0xb562a38f,
  36311. 0x9f5d80be,
  36312. 0x91548db5,
  36313. 0x834f9aa8,
  36314. 0x8d4697a3
  36315. ]);
  36316. function expandKey128(cipherKey) {
  36317. var b = 176, result = new Uint8Array(b);
  36318. result.set(cipherKey);
  36319. for (var j = 16, i = 1; j < b; ++i) {
  36320. // RotWord
  36321. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  36322. // SubWord
  36323. t1 = s[t1];
  36324. t2 = s[t2];
  36325. t3 = s[t3];
  36326. t4 = s[t4];
  36327. // Rcon
  36328. t1 = t1 ^ rcon[i];
  36329. for (var n = 0; n < 4; ++n) {
  36330. result[j] = t1 ^= result[j - 16];
  36331. j++;
  36332. result[j] = t2 ^= result[j - 16];
  36333. j++;
  36334. result[j] = t3 ^= result[j - 16];
  36335. j++;
  36336. result[j] = t4 ^= result[j - 16];
  36337. j++;
  36338. }
  36339. }
  36340. return result;
  36341. }
  36342. function decrypt128(input, key) {
  36343. var state = new Uint8Array(16);
  36344. state.set(input);
  36345. var i, j, k;
  36346. var t, u, v;
  36347. // AddRoundKey
  36348. for (j = 0, k = 160; j < 16; ++j, ++k) {
  36349. state[j] ^= key[k];
  36350. }
  36351. for (i = 9; i >= 1; --i) {
  36352. // InvShiftRows
  36353. t = state[13];
  36354. state[13] = state[9];
  36355. state[9] = state[5];
  36356. state[5] = state[1];
  36357. state[1] = t;
  36358. t = state[14];
  36359. u = state[10];
  36360. state[14] = state[6];
  36361. state[10] = state[2];
  36362. state[6] = t;
  36363. state[2] = u;
  36364. t = state[15];
  36365. u = state[11];
  36366. v = state[7];
  36367. state[15] = state[3];
  36368. state[11] = t;
  36369. state[7] = u;
  36370. state[3] = v;
  36371. // InvSubBytes
  36372. for (j = 0; j < 16; ++j) {
  36373. state[j] = inv_s[state[j]];
  36374. }
  36375. // AddRoundKey
  36376. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  36377. state[j] ^= key[k];
  36378. }
  36379. // InvMixColumns
  36380. for (j = 0; j < 16; j += 4) {
  36381. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  36382. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  36383. state[j] = t >>> 24 & 0xFF;
  36384. state[j + 1] = t >> 16 & 0xFF;
  36385. state[j + 2] = t >> 8 & 0xFF;
  36386. state[j + 3] = t & 0xFF;
  36387. }
  36388. }
  36389. // InvShiftRows
  36390. t = state[13];
  36391. state[13] = state[9];
  36392. state[9] = state[5];
  36393. state[5] = state[1];
  36394. state[1] = t;
  36395. t = state[14];
  36396. u = state[10];
  36397. state[14] = state[6];
  36398. state[10] = state[2];
  36399. state[6] = t;
  36400. state[2] = u;
  36401. t = state[15];
  36402. u = state[11];
  36403. v = state[7];
  36404. state[15] = state[3];
  36405. state[11] = t;
  36406. state[7] = u;
  36407. state[3] = v;
  36408. for (j = 0; j < 16; ++j) {
  36409. // InvSubBytes
  36410. state[j] = inv_s[state[j]];
  36411. // AddRoundKey
  36412. state[j] ^= key[j];
  36413. }
  36414. return state;
  36415. }
  36416. function encrypt128(input, key) {
  36417. var t, u, v, k;
  36418. var state = new Uint8Array(16);
  36419. state.set(input);
  36420. for (j = 0; j < 16; ++j) {
  36421. // AddRoundKey
  36422. state[j] ^= key[j];
  36423. }
  36424. for (i = 1; i < 10; i++) {
  36425. //SubBytes
  36426. for (j = 0; j < 16; ++j) {
  36427. state[j] = s[state[j]];
  36428. }
  36429. //ShiftRows
  36430. v = state[1];
  36431. state[1] = state[5];
  36432. state[5] = state[9];
  36433. state[9] = state[13];
  36434. state[13] = v;
  36435. v = state[2];
  36436. u = state[6];
  36437. state[2] = state[10];
  36438. state[6] = state[14];
  36439. state[10] = v;
  36440. state[14] = u;
  36441. v = state[3];
  36442. u = state[7];
  36443. t = state[11];
  36444. state[3] = state[15];
  36445. state[7] = v;
  36446. state[11] = u;
  36447. state[15] = t;
  36448. //MixColumns
  36449. for (var j = 0; j < 16; j += 4) {
  36450. var s0 = state[j + 0], s1 = state[j + 1];
  36451. var s2 = state[j + 2], s3 = state[j + 3];
  36452. t = s0 ^ s1 ^ s2 ^ s3;
  36453. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  36454. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  36455. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  36456. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  36457. }
  36458. //AddRoundKey
  36459. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  36460. state[j] ^= key[k];
  36461. }
  36462. }
  36463. //SubBytes
  36464. for (j = 0; j < 16; ++j) {
  36465. state[j] = s[state[j]];
  36466. }
  36467. //ShiftRows
  36468. v = state[1];
  36469. state[1] = state[5];
  36470. state[5] = state[9];
  36471. state[9] = state[13];
  36472. state[13] = v;
  36473. v = state[2];
  36474. u = state[6];
  36475. state[2] = state[10];
  36476. state[6] = state[14];
  36477. state[10] = v;
  36478. state[14] = u;
  36479. v = state[3];
  36480. u = state[7];
  36481. t = state[11];
  36482. state[3] = state[15];
  36483. state[7] = v;
  36484. state[11] = u;
  36485. state[15] = t;
  36486. //AddRoundKey
  36487. for (j = 0, k = 160; j < 16; ++j, ++k) {
  36488. state[j] ^= key[k];
  36489. }
  36490. return state;
  36491. }
  36492. function AES128Cipher(key) {
  36493. this.key = expandKey128(key);
  36494. this.buffer = new Uint8Array(16);
  36495. this.bufferPosition = 0;
  36496. }
  36497. function decryptBlock2(data, finalize) {
  36498. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  36499. for (i = 0; i < sourceLength; ++i) {
  36500. buffer[bufferLength] = data[i];
  36501. ++bufferLength;
  36502. if (bufferLength < 16) {
  36503. continue;
  36504. }
  36505. // buffer is full, decrypting
  36506. var plain = decrypt128(buffer, this.key);
  36507. // xor-ing the IV vector to get plain text
  36508. for (j = 0; j < 16; ++j) {
  36509. plain[j] ^= iv[j];
  36510. }
  36511. iv = buffer;
  36512. result.push(plain);
  36513. buffer = new Uint8Array(16);
  36514. bufferLength = 0;
  36515. }
  36516. // saving incomplete buffer
  36517. this.buffer = buffer;
  36518. this.bufferLength = bufferLength;
  36519. this.iv = iv;
  36520. if (result.length === 0) {
  36521. return new Uint8Array([]);
  36522. }
  36523. // combining plain text blocks into one
  36524. var outputLength = 16 * result.length;
  36525. if (finalize) {
  36526. // undo a padding that is described in RFC 2898
  36527. var lastBlock = result[result.length - 1];
  36528. var psLen = lastBlock[15];
  36529. if (psLen <= 16) {
  36530. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  36531. if (lastBlock[i] !== psLen) {
  36532. // Invalid padding, assume that the block has no padding.
  36533. psLen = 0;
  36534. break;
  36535. }
  36536. }
  36537. outputLength -= psLen;
  36538. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  36539. }
  36540. }
  36541. var output = new Uint8Array(outputLength);
  36542. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36543. output.set(result[i], j);
  36544. }
  36545. return output;
  36546. }
  36547. AES128Cipher.prototype = {
  36548. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  36549. var i, sourceLength = data.length;
  36550. var buffer = this.buffer, bufferLength = this.bufferPosition;
  36551. // waiting for IV values -- they are at the start of the stream
  36552. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  36553. buffer[bufferLength] = data[i];
  36554. }
  36555. if (bufferLength < 16) {
  36556. // need more data
  36557. this.bufferLength = bufferLength;
  36558. return new Uint8Array([]);
  36559. }
  36560. this.iv = buffer;
  36561. this.buffer = new Uint8Array(16);
  36562. this.bufferLength = 0;
  36563. // starting decryption
  36564. this.decryptBlock = decryptBlock2;
  36565. return this.decryptBlock(data.subarray(16), finalize);
  36566. },
  36567. encrypt: function AES128Cipher_encrypt(data, iv) {
  36568. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  36569. if (!iv) {
  36570. iv = new Uint8Array(16);
  36571. }
  36572. for (i = 0; i < sourceLength; ++i) {
  36573. buffer[bufferLength] = data[i];
  36574. ++bufferLength;
  36575. if (bufferLength < 16) {
  36576. continue;
  36577. }
  36578. for (j = 0; j < 16; ++j) {
  36579. buffer[j] ^= iv[j];
  36580. }
  36581. // buffer is full, encrypting
  36582. var cipher = encrypt128(buffer, this.key);
  36583. iv = cipher;
  36584. result.push(cipher);
  36585. buffer = new Uint8Array(16);
  36586. bufferLength = 0;
  36587. }
  36588. // saving incomplete buffer
  36589. this.buffer = buffer;
  36590. this.bufferLength = bufferLength;
  36591. this.iv = iv;
  36592. if (result.length === 0) {
  36593. return new Uint8Array([]);
  36594. }
  36595. // combining plain text blocks into one
  36596. var outputLength = 16 * result.length;
  36597. var output = new Uint8Array(outputLength);
  36598. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36599. output.set(result[i], j);
  36600. }
  36601. return output;
  36602. }
  36603. };
  36604. return AES128Cipher;
  36605. }();
  36606. var AES256Cipher = function AES256CipherClosure() {
  36607. var rcon = new Uint8Array([
  36608. 0x8d,
  36609. 0x01,
  36610. 0x02,
  36611. 0x04,
  36612. 0x08,
  36613. 0x10,
  36614. 0x20,
  36615. 0x40,
  36616. 0x80,
  36617. 0x1b,
  36618. 0x36,
  36619. 0x6c,
  36620. 0xd8,
  36621. 0xab,
  36622. 0x4d,
  36623. 0x9a,
  36624. 0x2f,
  36625. 0x5e,
  36626. 0xbc,
  36627. 0x63,
  36628. 0xc6,
  36629. 0x97,
  36630. 0x35,
  36631. 0x6a,
  36632. 0xd4,
  36633. 0xb3,
  36634. 0x7d,
  36635. 0xfa,
  36636. 0xef,
  36637. 0xc5,
  36638. 0x91,
  36639. 0x39,
  36640. 0x72,
  36641. 0xe4,
  36642. 0xd3,
  36643. 0xbd,
  36644. 0x61,
  36645. 0xc2,
  36646. 0x9f,
  36647. 0x25,
  36648. 0x4a,
  36649. 0x94,
  36650. 0x33,
  36651. 0x66,
  36652. 0xcc,
  36653. 0x83,
  36654. 0x1d,
  36655. 0x3a,
  36656. 0x74,
  36657. 0xe8,
  36658. 0xcb,
  36659. 0x8d,
  36660. 0x01,
  36661. 0x02,
  36662. 0x04,
  36663. 0x08,
  36664. 0x10,
  36665. 0x20,
  36666. 0x40,
  36667. 0x80,
  36668. 0x1b,
  36669. 0x36,
  36670. 0x6c,
  36671. 0xd8,
  36672. 0xab,
  36673. 0x4d,
  36674. 0x9a,
  36675. 0x2f,
  36676. 0x5e,
  36677. 0xbc,
  36678. 0x63,
  36679. 0xc6,
  36680. 0x97,
  36681. 0x35,
  36682. 0x6a,
  36683. 0xd4,
  36684. 0xb3,
  36685. 0x7d,
  36686. 0xfa,
  36687. 0xef,
  36688. 0xc5,
  36689. 0x91,
  36690. 0x39,
  36691. 0x72,
  36692. 0xe4,
  36693. 0xd3,
  36694. 0xbd,
  36695. 0x61,
  36696. 0xc2,
  36697. 0x9f,
  36698. 0x25,
  36699. 0x4a,
  36700. 0x94,
  36701. 0x33,
  36702. 0x66,
  36703. 0xcc,
  36704. 0x83,
  36705. 0x1d,
  36706. 0x3a,
  36707. 0x74,
  36708. 0xe8,
  36709. 0xcb,
  36710. 0x8d,
  36711. 0x01,
  36712. 0x02,
  36713. 0x04,
  36714. 0x08,
  36715. 0x10,
  36716. 0x20,
  36717. 0x40,
  36718. 0x80,
  36719. 0x1b,
  36720. 0x36,
  36721. 0x6c,
  36722. 0xd8,
  36723. 0xab,
  36724. 0x4d,
  36725. 0x9a,
  36726. 0x2f,
  36727. 0x5e,
  36728. 0xbc,
  36729. 0x63,
  36730. 0xc6,
  36731. 0x97,
  36732. 0x35,
  36733. 0x6a,
  36734. 0xd4,
  36735. 0xb3,
  36736. 0x7d,
  36737. 0xfa,
  36738. 0xef,
  36739. 0xc5,
  36740. 0x91,
  36741. 0x39,
  36742. 0x72,
  36743. 0xe4,
  36744. 0xd3,
  36745. 0xbd,
  36746. 0x61,
  36747. 0xc2,
  36748. 0x9f,
  36749. 0x25,
  36750. 0x4a,
  36751. 0x94,
  36752. 0x33,
  36753. 0x66,
  36754. 0xcc,
  36755. 0x83,
  36756. 0x1d,
  36757. 0x3a,
  36758. 0x74,
  36759. 0xe8,
  36760. 0xcb,
  36761. 0x8d,
  36762. 0x01,
  36763. 0x02,
  36764. 0x04,
  36765. 0x08,
  36766. 0x10,
  36767. 0x20,
  36768. 0x40,
  36769. 0x80,
  36770. 0x1b,
  36771. 0x36,
  36772. 0x6c,
  36773. 0xd8,
  36774. 0xab,
  36775. 0x4d,
  36776. 0x9a,
  36777. 0x2f,
  36778. 0x5e,
  36779. 0xbc,
  36780. 0x63,
  36781. 0xc6,
  36782. 0x97,
  36783. 0x35,
  36784. 0x6a,
  36785. 0xd4,
  36786. 0xb3,
  36787. 0x7d,
  36788. 0xfa,
  36789. 0xef,
  36790. 0xc5,
  36791. 0x91,
  36792. 0x39,
  36793. 0x72,
  36794. 0xe4,
  36795. 0xd3,
  36796. 0xbd,
  36797. 0x61,
  36798. 0xc2,
  36799. 0x9f,
  36800. 0x25,
  36801. 0x4a,
  36802. 0x94,
  36803. 0x33,
  36804. 0x66,
  36805. 0xcc,
  36806. 0x83,
  36807. 0x1d,
  36808. 0x3a,
  36809. 0x74,
  36810. 0xe8,
  36811. 0xcb,
  36812. 0x8d,
  36813. 0x01,
  36814. 0x02,
  36815. 0x04,
  36816. 0x08,
  36817. 0x10,
  36818. 0x20,
  36819. 0x40,
  36820. 0x80,
  36821. 0x1b,
  36822. 0x36,
  36823. 0x6c,
  36824. 0xd8,
  36825. 0xab,
  36826. 0x4d,
  36827. 0x9a,
  36828. 0x2f,
  36829. 0x5e,
  36830. 0xbc,
  36831. 0x63,
  36832. 0xc6,
  36833. 0x97,
  36834. 0x35,
  36835. 0x6a,
  36836. 0xd4,
  36837. 0xb3,
  36838. 0x7d,
  36839. 0xfa,
  36840. 0xef,
  36841. 0xc5,
  36842. 0x91,
  36843. 0x39,
  36844. 0x72,
  36845. 0xe4,
  36846. 0xd3,
  36847. 0xbd,
  36848. 0x61,
  36849. 0xc2,
  36850. 0x9f,
  36851. 0x25,
  36852. 0x4a,
  36853. 0x94,
  36854. 0x33,
  36855. 0x66,
  36856. 0xcc,
  36857. 0x83,
  36858. 0x1d,
  36859. 0x3a,
  36860. 0x74,
  36861. 0xe8,
  36862. 0xcb,
  36863. 0x8d
  36864. ]);
  36865. var s = new Uint8Array([
  36866. 0x63,
  36867. 0x7c,
  36868. 0x77,
  36869. 0x7b,
  36870. 0xf2,
  36871. 0x6b,
  36872. 0x6f,
  36873. 0xc5,
  36874. 0x30,
  36875. 0x01,
  36876. 0x67,
  36877. 0x2b,
  36878. 0xfe,
  36879. 0xd7,
  36880. 0xab,
  36881. 0x76,
  36882. 0xca,
  36883. 0x82,
  36884. 0xc9,
  36885. 0x7d,
  36886. 0xfa,
  36887. 0x59,
  36888. 0x47,
  36889. 0xf0,
  36890. 0xad,
  36891. 0xd4,
  36892. 0xa2,
  36893. 0xaf,
  36894. 0x9c,
  36895. 0xa4,
  36896. 0x72,
  36897. 0xc0,
  36898. 0xb7,
  36899. 0xfd,
  36900. 0x93,
  36901. 0x26,
  36902. 0x36,
  36903. 0x3f,
  36904. 0xf7,
  36905. 0xcc,
  36906. 0x34,
  36907. 0xa5,
  36908. 0xe5,
  36909. 0xf1,
  36910. 0x71,
  36911. 0xd8,
  36912. 0x31,
  36913. 0x15,
  36914. 0x04,
  36915. 0xc7,
  36916. 0x23,
  36917. 0xc3,
  36918. 0x18,
  36919. 0x96,
  36920. 0x05,
  36921. 0x9a,
  36922. 0x07,
  36923. 0x12,
  36924. 0x80,
  36925. 0xe2,
  36926. 0xeb,
  36927. 0x27,
  36928. 0xb2,
  36929. 0x75,
  36930. 0x09,
  36931. 0x83,
  36932. 0x2c,
  36933. 0x1a,
  36934. 0x1b,
  36935. 0x6e,
  36936. 0x5a,
  36937. 0xa0,
  36938. 0x52,
  36939. 0x3b,
  36940. 0xd6,
  36941. 0xb3,
  36942. 0x29,
  36943. 0xe3,
  36944. 0x2f,
  36945. 0x84,
  36946. 0x53,
  36947. 0xd1,
  36948. 0x00,
  36949. 0xed,
  36950. 0x20,
  36951. 0xfc,
  36952. 0xb1,
  36953. 0x5b,
  36954. 0x6a,
  36955. 0xcb,
  36956. 0xbe,
  36957. 0x39,
  36958. 0x4a,
  36959. 0x4c,
  36960. 0x58,
  36961. 0xcf,
  36962. 0xd0,
  36963. 0xef,
  36964. 0xaa,
  36965. 0xfb,
  36966. 0x43,
  36967. 0x4d,
  36968. 0x33,
  36969. 0x85,
  36970. 0x45,
  36971. 0xf9,
  36972. 0x02,
  36973. 0x7f,
  36974. 0x50,
  36975. 0x3c,
  36976. 0x9f,
  36977. 0xa8,
  36978. 0x51,
  36979. 0xa3,
  36980. 0x40,
  36981. 0x8f,
  36982. 0x92,
  36983. 0x9d,
  36984. 0x38,
  36985. 0xf5,
  36986. 0xbc,
  36987. 0xb6,
  36988. 0xda,
  36989. 0x21,
  36990. 0x10,
  36991. 0xff,
  36992. 0xf3,
  36993. 0xd2,
  36994. 0xcd,
  36995. 0x0c,
  36996. 0x13,
  36997. 0xec,
  36998. 0x5f,
  36999. 0x97,
  37000. 0x44,
  37001. 0x17,
  37002. 0xc4,
  37003. 0xa7,
  37004. 0x7e,
  37005. 0x3d,
  37006. 0x64,
  37007. 0x5d,
  37008. 0x19,
  37009. 0x73,
  37010. 0x60,
  37011. 0x81,
  37012. 0x4f,
  37013. 0xdc,
  37014. 0x22,
  37015. 0x2a,
  37016. 0x90,
  37017. 0x88,
  37018. 0x46,
  37019. 0xee,
  37020. 0xb8,
  37021. 0x14,
  37022. 0xde,
  37023. 0x5e,
  37024. 0x0b,
  37025. 0xdb,
  37026. 0xe0,
  37027. 0x32,
  37028. 0x3a,
  37029. 0x0a,
  37030. 0x49,
  37031. 0x06,
  37032. 0x24,
  37033. 0x5c,
  37034. 0xc2,
  37035. 0xd3,
  37036. 0xac,
  37037. 0x62,
  37038. 0x91,
  37039. 0x95,
  37040. 0xe4,
  37041. 0x79,
  37042. 0xe7,
  37043. 0xc8,
  37044. 0x37,
  37045. 0x6d,
  37046. 0x8d,
  37047. 0xd5,
  37048. 0x4e,
  37049. 0xa9,
  37050. 0x6c,
  37051. 0x56,
  37052. 0xf4,
  37053. 0xea,
  37054. 0x65,
  37055. 0x7a,
  37056. 0xae,
  37057. 0x08,
  37058. 0xba,
  37059. 0x78,
  37060. 0x25,
  37061. 0x2e,
  37062. 0x1c,
  37063. 0xa6,
  37064. 0xb4,
  37065. 0xc6,
  37066. 0xe8,
  37067. 0xdd,
  37068. 0x74,
  37069. 0x1f,
  37070. 0x4b,
  37071. 0xbd,
  37072. 0x8b,
  37073. 0x8a,
  37074. 0x70,
  37075. 0x3e,
  37076. 0xb5,
  37077. 0x66,
  37078. 0x48,
  37079. 0x03,
  37080. 0xf6,
  37081. 0x0e,
  37082. 0x61,
  37083. 0x35,
  37084. 0x57,
  37085. 0xb9,
  37086. 0x86,
  37087. 0xc1,
  37088. 0x1d,
  37089. 0x9e,
  37090. 0xe1,
  37091. 0xf8,
  37092. 0x98,
  37093. 0x11,
  37094. 0x69,
  37095. 0xd9,
  37096. 0x8e,
  37097. 0x94,
  37098. 0x9b,
  37099. 0x1e,
  37100. 0x87,
  37101. 0xe9,
  37102. 0xce,
  37103. 0x55,
  37104. 0x28,
  37105. 0xdf,
  37106. 0x8c,
  37107. 0xa1,
  37108. 0x89,
  37109. 0x0d,
  37110. 0xbf,
  37111. 0xe6,
  37112. 0x42,
  37113. 0x68,
  37114. 0x41,
  37115. 0x99,
  37116. 0x2d,
  37117. 0x0f,
  37118. 0xb0,
  37119. 0x54,
  37120. 0xbb,
  37121. 0x16
  37122. ]);
  37123. var inv_s = new Uint8Array([
  37124. 0x52,
  37125. 0x09,
  37126. 0x6a,
  37127. 0xd5,
  37128. 0x30,
  37129. 0x36,
  37130. 0xa5,
  37131. 0x38,
  37132. 0xbf,
  37133. 0x40,
  37134. 0xa3,
  37135. 0x9e,
  37136. 0x81,
  37137. 0xf3,
  37138. 0xd7,
  37139. 0xfb,
  37140. 0x7c,
  37141. 0xe3,
  37142. 0x39,
  37143. 0x82,
  37144. 0x9b,
  37145. 0x2f,
  37146. 0xff,
  37147. 0x87,
  37148. 0x34,
  37149. 0x8e,
  37150. 0x43,
  37151. 0x44,
  37152. 0xc4,
  37153. 0xde,
  37154. 0xe9,
  37155. 0xcb,
  37156. 0x54,
  37157. 0x7b,
  37158. 0x94,
  37159. 0x32,
  37160. 0xa6,
  37161. 0xc2,
  37162. 0x23,
  37163. 0x3d,
  37164. 0xee,
  37165. 0x4c,
  37166. 0x95,
  37167. 0x0b,
  37168. 0x42,
  37169. 0xfa,
  37170. 0xc3,
  37171. 0x4e,
  37172. 0x08,
  37173. 0x2e,
  37174. 0xa1,
  37175. 0x66,
  37176. 0x28,
  37177. 0xd9,
  37178. 0x24,
  37179. 0xb2,
  37180. 0x76,
  37181. 0x5b,
  37182. 0xa2,
  37183. 0x49,
  37184. 0x6d,
  37185. 0x8b,
  37186. 0xd1,
  37187. 0x25,
  37188. 0x72,
  37189. 0xf8,
  37190. 0xf6,
  37191. 0x64,
  37192. 0x86,
  37193. 0x68,
  37194. 0x98,
  37195. 0x16,
  37196. 0xd4,
  37197. 0xa4,
  37198. 0x5c,
  37199. 0xcc,
  37200. 0x5d,
  37201. 0x65,
  37202. 0xb6,
  37203. 0x92,
  37204. 0x6c,
  37205. 0x70,
  37206. 0x48,
  37207. 0x50,
  37208. 0xfd,
  37209. 0xed,
  37210. 0xb9,
  37211. 0xda,
  37212. 0x5e,
  37213. 0x15,
  37214. 0x46,
  37215. 0x57,
  37216. 0xa7,
  37217. 0x8d,
  37218. 0x9d,
  37219. 0x84,
  37220. 0x90,
  37221. 0xd8,
  37222. 0xab,
  37223. 0x00,
  37224. 0x8c,
  37225. 0xbc,
  37226. 0xd3,
  37227. 0x0a,
  37228. 0xf7,
  37229. 0xe4,
  37230. 0x58,
  37231. 0x05,
  37232. 0xb8,
  37233. 0xb3,
  37234. 0x45,
  37235. 0x06,
  37236. 0xd0,
  37237. 0x2c,
  37238. 0x1e,
  37239. 0x8f,
  37240. 0xca,
  37241. 0x3f,
  37242. 0x0f,
  37243. 0x02,
  37244. 0xc1,
  37245. 0xaf,
  37246. 0xbd,
  37247. 0x03,
  37248. 0x01,
  37249. 0x13,
  37250. 0x8a,
  37251. 0x6b,
  37252. 0x3a,
  37253. 0x91,
  37254. 0x11,
  37255. 0x41,
  37256. 0x4f,
  37257. 0x67,
  37258. 0xdc,
  37259. 0xea,
  37260. 0x97,
  37261. 0xf2,
  37262. 0xcf,
  37263. 0xce,
  37264. 0xf0,
  37265. 0xb4,
  37266. 0xe6,
  37267. 0x73,
  37268. 0x96,
  37269. 0xac,
  37270. 0x74,
  37271. 0x22,
  37272. 0xe7,
  37273. 0xad,
  37274. 0x35,
  37275. 0x85,
  37276. 0xe2,
  37277. 0xf9,
  37278. 0x37,
  37279. 0xe8,
  37280. 0x1c,
  37281. 0x75,
  37282. 0xdf,
  37283. 0x6e,
  37284. 0x47,
  37285. 0xf1,
  37286. 0x1a,
  37287. 0x71,
  37288. 0x1d,
  37289. 0x29,
  37290. 0xc5,
  37291. 0x89,
  37292. 0x6f,
  37293. 0xb7,
  37294. 0x62,
  37295. 0x0e,
  37296. 0xaa,
  37297. 0x18,
  37298. 0xbe,
  37299. 0x1b,
  37300. 0xfc,
  37301. 0x56,
  37302. 0x3e,
  37303. 0x4b,
  37304. 0xc6,
  37305. 0xd2,
  37306. 0x79,
  37307. 0x20,
  37308. 0x9a,
  37309. 0xdb,
  37310. 0xc0,
  37311. 0xfe,
  37312. 0x78,
  37313. 0xcd,
  37314. 0x5a,
  37315. 0xf4,
  37316. 0x1f,
  37317. 0xdd,
  37318. 0xa8,
  37319. 0x33,
  37320. 0x88,
  37321. 0x07,
  37322. 0xc7,
  37323. 0x31,
  37324. 0xb1,
  37325. 0x12,
  37326. 0x10,
  37327. 0x59,
  37328. 0x27,
  37329. 0x80,
  37330. 0xec,
  37331. 0x5f,
  37332. 0x60,
  37333. 0x51,
  37334. 0x7f,
  37335. 0xa9,
  37336. 0x19,
  37337. 0xb5,
  37338. 0x4a,
  37339. 0x0d,
  37340. 0x2d,
  37341. 0xe5,
  37342. 0x7a,
  37343. 0x9f,
  37344. 0x93,
  37345. 0xc9,
  37346. 0x9c,
  37347. 0xef,
  37348. 0xa0,
  37349. 0xe0,
  37350. 0x3b,
  37351. 0x4d,
  37352. 0xae,
  37353. 0x2a,
  37354. 0xf5,
  37355. 0xb0,
  37356. 0xc8,
  37357. 0xeb,
  37358. 0xbb,
  37359. 0x3c,
  37360. 0x83,
  37361. 0x53,
  37362. 0x99,
  37363. 0x61,
  37364. 0x17,
  37365. 0x2b,
  37366. 0x04,
  37367. 0x7e,
  37368. 0xba,
  37369. 0x77,
  37370. 0xd6,
  37371. 0x26,
  37372. 0xe1,
  37373. 0x69,
  37374. 0x14,
  37375. 0x63,
  37376. 0x55,
  37377. 0x21,
  37378. 0x0c,
  37379. 0x7d
  37380. ]);
  37381. var mixCol = new Uint8Array(256);
  37382. for (var i = 0; i < 256; i++) {
  37383. if (i < 128) {
  37384. mixCol[i] = i << 1;
  37385. } else {
  37386. mixCol[i] = i << 1 ^ 0x1b;
  37387. }
  37388. }
  37389. var mix = new Uint32Array([
  37390. 0x00000000,
  37391. 0x0e090d0b,
  37392. 0x1c121a16,
  37393. 0x121b171d,
  37394. 0x3824342c,
  37395. 0x362d3927,
  37396. 0x24362e3a,
  37397. 0x2a3f2331,
  37398. 0x70486858,
  37399. 0x7e416553,
  37400. 0x6c5a724e,
  37401. 0x62537f45,
  37402. 0x486c5c74,
  37403. 0x4665517f,
  37404. 0x547e4662,
  37405. 0x5a774b69,
  37406. 0xe090d0b0,
  37407. 0xee99ddbb,
  37408. 0xfc82caa6,
  37409. 0xf28bc7ad,
  37410. 0xd8b4e49c,
  37411. 0xd6bde997,
  37412. 0xc4a6fe8a,
  37413. 0xcaaff381,
  37414. 0x90d8b8e8,
  37415. 0x9ed1b5e3,
  37416. 0x8ccaa2fe,
  37417. 0x82c3aff5,
  37418. 0xa8fc8cc4,
  37419. 0xa6f581cf,
  37420. 0xb4ee96d2,
  37421. 0xbae79bd9,
  37422. 0xdb3bbb7b,
  37423. 0xd532b670,
  37424. 0xc729a16d,
  37425. 0xc920ac66,
  37426. 0xe31f8f57,
  37427. 0xed16825c,
  37428. 0xff0d9541,
  37429. 0xf104984a,
  37430. 0xab73d323,
  37431. 0xa57ade28,
  37432. 0xb761c935,
  37433. 0xb968c43e,
  37434. 0x9357e70f,
  37435. 0x9d5eea04,
  37436. 0x8f45fd19,
  37437. 0x814cf012,
  37438. 0x3bab6bcb,
  37439. 0x35a266c0,
  37440. 0x27b971dd,
  37441. 0x29b07cd6,
  37442. 0x038f5fe7,
  37443. 0x0d8652ec,
  37444. 0x1f9d45f1,
  37445. 0x119448fa,
  37446. 0x4be30393,
  37447. 0x45ea0e98,
  37448. 0x57f11985,
  37449. 0x59f8148e,
  37450. 0x73c737bf,
  37451. 0x7dce3ab4,
  37452. 0x6fd52da9,
  37453. 0x61dc20a2,
  37454. 0xad766df6,
  37455. 0xa37f60fd,
  37456. 0xb16477e0,
  37457. 0xbf6d7aeb,
  37458. 0x955259da,
  37459. 0x9b5b54d1,
  37460. 0x894043cc,
  37461. 0x87494ec7,
  37462. 0xdd3e05ae,
  37463. 0xd33708a5,
  37464. 0xc12c1fb8,
  37465. 0xcf2512b3,
  37466. 0xe51a3182,
  37467. 0xeb133c89,
  37468. 0xf9082b94,
  37469. 0xf701269f,
  37470. 0x4de6bd46,
  37471. 0x43efb04d,
  37472. 0x51f4a750,
  37473. 0x5ffdaa5b,
  37474. 0x75c2896a,
  37475. 0x7bcb8461,
  37476. 0x69d0937c,
  37477. 0x67d99e77,
  37478. 0x3daed51e,
  37479. 0x33a7d815,
  37480. 0x21bccf08,
  37481. 0x2fb5c203,
  37482. 0x058ae132,
  37483. 0x0b83ec39,
  37484. 0x1998fb24,
  37485. 0x1791f62f,
  37486. 0x764dd68d,
  37487. 0x7844db86,
  37488. 0x6a5fcc9b,
  37489. 0x6456c190,
  37490. 0x4e69e2a1,
  37491. 0x4060efaa,
  37492. 0x527bf8b7,
  37493. 0x5c72f5bc,
  37494. 0x0605bed5,
  37495. 0x080cb3de,
  37496. 0x1a17a4c3,
  37497. 0x141ea9c8,
  37498. 0x3e218af9,
  37499. 0x302887f2,
  37500. 0x223390ef,
  37501. 0x2c3a9de4,
  37502. 0x96dd063d,
  37503. 0x98d40b36,
  37504. 0x8acf1c2b,
  37505. 0x84c61120,
  37506. 0xaef93211,
  37507. 0xa0f03f1a,
  37508. 0xb2eb2807,
  37509. 0xbce2250c,
  37510. 0xe6956e65,
  37511. 0xe89c636e,
  37512. 0xfa877473,
  37513. 0xf48e7978,
  37514. 0xdeb15a49,
  37515. 0xd0b85742,
  37516. 0xc2a3405f,
  37517. 0xccaa4d54,
  37518. 0x41ecdaf7,
  37519. 0x4fe5d7fc,
  37520. 0x5dfec0e1,
  37521. 0x53f7cdea,
  37522. 0x79c8eedb,
  37523. 0x77c1e3d0,
  37524. 0x65daf4cd,
  37525. 0x6bd3f9c6,
  37526. 0x31a4b2af,
  37527. 0x3fadbfa4,
  37528. 0x2db6a8b9,
  37529. 0x23bfa5b2,
  37530. 0x09808683,
  37531. 0x07898b88,
  37532. 0x15929c95,
  37533. 0x1b9b919e,
  37534. 0xa17c0a47,
  37535. 0xaf75074c,
  37536. 0xbd6e1051,
  37537. 0xb3671d5a,
  37538. 0x99583e6b,
  37539. 0x97513360,
  37540. 0x854a247d,
  37541. 0x8b432976,
  37542. 0xd134621f,
  37543. 0xdf3d6f14,
  37544. 0xcd267809,
  37545. 0xc32f7502,
  37546. 0xe9105633,
  37547. 0xe7195b38,
  37548. 0xf5024c25,
  37549. 0xfb0b412e,
  37550. 0x9ad7618c,
  37551. 0x94de6c87,
  37552. 0x86c57b9a,
  37553. 0x88cc7691,
  37554. 0xa2f355a0,
  37555. 0xacfa58ab,
  37556. 0xbee14fb6,
  37557. 0xb0e842bd,
  37558. 0xea9f09d4,
  37559. 0xe49604df,
  37560. 0xf68d13c2,
  37561. 0xf8841ec9,
  37562. 0xd2bb3df8,
  37563. 0xdcb230f3,
  37564. 0xcea927ee,
  37565. 0xc0a02ae5,
  37566. 0x7a47b13c,
  37567. 0x744ebc37,
  37568. 0x6655ab2a,
  37569. 0x685ca621,
  37570. 0x42638510,
  37571. 0x4c6a881b,
  37572. 0x5e719f06,
  37573. 0x5078920d,
  37574. 0x0a0fd964,
  37575. 0x0406d46f,
  37576. 0x161dc372,
  37577. 0x1814ce79,
  37578. 0x322bed48,
  37579. 0x3c22e043,
  37580. 0x2e39f75e,
  37581. 0x2030fa55,
  37582. 0xec9ab701,
  37583. 0xe293ba0a,
  37584. 0xf088ad17,
  37585. 0xfe81a01c,
  37586. 0xd4be832d,
  37587. 0xdab78e26,
  37588. 0xc8ac993b,
  37589. 0xc6a59430,
  37590. 0x9cd2df59,
  37591. 0x92dbd252,
  37592. 0x80c0c54f,
  37593. 0x8ec9c844,
  37594. 0xa4f6eb75,
  37595. 0xaaffe67e,
  37596. 0xb8e4f163,
  37597. 0xb6edfc68,
  37598. 0x0c0a67b1,
  37599. 0x02036aba,
  37600. 0x10187da7,
  37601. 0x1e1170ac,
  37602. 0x342e539d,
  37603. 0x3a275e96,
  37604. 0x283c498b,
  37605. 0x26354480,
  37606. 0x7c420fe9,
  37607. 0x724b02e2,
  37608. 0x605015ff,
  37609. 0x6e5918f4,
  37610. 0x44663bc5,
  37611. 0x4a6f36ce,
  37612. 0x587421d3,
  37613. 0x567d2cd8,
  37614. 0x37a10c7a,
  37615. 0x39a80171,
  37616. 0x2bb3166c,
  37617. 0x25ba1b67,
  37618. 0x0f853856,
  37619. 0x018c355d,
  37620. 0x13972240,
  37621. 0x1d9e2f4b,
  37622. 0x47e96422,
  37623. 0x49e06929,
  37624. 0x5bfb7e34,
  37625. 0x55f2733f,
  37626. 0x7fcd500e,
  37627. 0x71c45d05,
  37628. 0x63df4a18,
  37629. 0x6dd64713,
  37630. 0xd731dcca,
  37631. 0xd938d1c1,
  37632. 0xcb23c6dc,
  37633. 0xc52acbd7,
  37634. 0xef15e8e6,
  37635. 0xe11ce5ed,
  37636. 0xf307f2f0,
  37637. 0xfd0efffb,
  37638. 0xa779b492,
  37639. 0xa970b999,
  37640. 0xbb6bae84,
  37641. 0xb562a38f,
  37642. 0x9f5d80be,
  37643. 0x91548db5,
  37644. 0x834f9aa8,
  37645. 0x8d4697a3
  37646. ]);
  37647. function expandKey256(cipherKey) {
  37648. var b = 240, result = new Uint8Array(b);
  37649. var r = 1;
  37650. result.set(cipherKey);
  37651. for (var j = 32, i = 1; j < b; ++i) {
  37652. if (j % 32 === 16) {
  37653. t1 = s[t1];
  37654. t2 = s[t2];
  37655. t3 = s[t3];
  37656. t4 = s[t4];
  37657. } else if (j % 32 === 0) {
  37658. // RotWord
  37659. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  37660. // SubWord
  37661. t1 = s[t1];
  37662. t2 = s[t2];
  37663. t3 = s[t3];
  37664. t4 = s[t4];
  37665. // Rcon
  37666. t1 = t1 ^ r;
  37667. if ((r <<= 1) >= 256) {
  37668. r = (r ^ 0x1b) & 0xFF;
  37669. }
  37670. }
  37671. for (var n = 0; n < 4; ++n) {
  37672. result[j] = t1 ^= result[j - 32];
  37673. j++;
  37674. result[j] = t2 ^= result[j - 32];
  37675. j++;
  37676. result[j] = t3 ^= result[j - 32];
  37677. j++;
  37678. result[j] = t4 ^= result[j - 32];
  37679. j++;
  37680. }
  37681. }
  37682. return result;
  37683. }
  37684. function decrypt256(input, key) {
  37685. var state = new Uint8Array(16);
  37686. state.set(input);
  37687. var i, j, k;
  37688. var t, u, v;
  37689. // AddRoundKey
  37690. for (j = 0, k = 224; j < 16; ++j, ++k) {
  37691. state[j] ^= key[k];
  37692. }
  37693. for (i = 13; i >= 1; --i) {
  37694. // InvShiftRows
  37695. t = state[13];
  37696. state[13] = state[9];
  37697. state[9] = state[5];
  37698. state[5] = state[1];
  37699. state[1] = t;
  37700. t = state[14];
  37701. u = state[10];
  37702. state[14] = state[6];
  37703. state[10] = state[2];
  37704. state[6] = t;
  37705. state[2] = u;
  37706. t = state[15];
  37707. u = state[11];
  37708. v = state[7];
  37709. state[15] = state[3];
  37710. state[11] = t;
  37711. state[7] = u;
  37712. state[3] = v;
  37713. // InvSubBytes
  37714. for (j = 0; j < 16; ++j) {
  37715. state[j] = inv_s[state[j]];
  37716. }
  37717. // AddRoundKey
  37718. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  37719. state[j] ^= key[k];
  37720. }
  37721. // InvMixColumns
  37722. for (j = 0; j < 16; j += 4) {
  37723. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  37724. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  37725. state[j] = t >>> 24 & 0xFF;
  37726. state[j + 1] = t >> 16 & 0xFF;
  37727. state[j + 2] = t >> 8 & 0xFF;
  37728. state[j + 3] = t & 0xFF;
  37729. }
  37730. }
  37731. // InvShiftRows
  37732. t = state[13];
  37733. state[13] = state[9];
  37734. state[9] = state[5];
  37735. state[5] = state[1];
  37736. state[1] = t;
  37737. t = state[14];
  37738. u = state[10];
  37739. state[14] = state[6];
  37740. state[10] = state[2];
  37741. state[6] = t;
  37742. state[2] = u;
  37743. t = state[15];
  37744. u = state[11];
  37745. v = state[7];
  37746. state[15] = state[3];
  37747. state[11] = t;
  37748. state[7] = u;
  37749. state[3] = v;
  37750. for (j = 0; j < 16; ++j) {
  37751. // InvSubBytes
  37752. state[j] = inv_s[state[j]];
  37753. // AddRoundKey
  37754. state[j] ^= key[j];
  37755. }
  37756. return state;
  37757. }
  37758. function encrypt256(input, key) {
  37759. var t, u, v, k;
  37760. var state = new Uint8Array(16);
  37761. state.set(input);
  37762. for (j = 0; j < 16; ++j) {
  37763. // AddRoundKey
  37764. state[j] ^= key[j];
  37765. }
  37766. for (i = 1; i < 14; i++) {
  37767. //SubBytes
  37768. for (j = 0; j < 16; ++j) {
  37769. state[j] = s[state[j]];
  37770. }
  37771. //ShiftRows
  37772. v = state[1];
  37773. state[1] = state[5];
  37774. state[5] = state[9];
  37775. state[9] = state[13];
  37776. state[13] = v;
  37777. v = state[2];
  37778. u = state[6];
  37779. state[2] = state[10];
  37780. state[6] = state[14];
  37781. state[10] = v;
  37782. state[14] = u;
  37783. v = state[3];
  37784. u = state[7];
  37785. t = state[11];
  37786. state[3] = state[15];
  37787. state[7] = v;
  37788. state[11] = u;
  37789. state[15] = t;
  37790. //MixColumns
  37791. for (var j = 0; j < 16; j += 4) {
  37792. var s0 = state[j + 0], s1 = state[j + 1];
  37793. var s2 = state[j + 2], s3 = state[j + 3];
  37794. t = s0 ^ s1 ^ s2 ^ s3;
  37795. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  37796. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  37797. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  37798. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  37799. }
  37800. //AddRoundKey
  37801. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  37802. state[j] ^= key[k];
  37803. }
  37804. }
  37805. //SubBytes
  37806. for (j = 0; j < 16; ++j) {
  37807. state[j] = s[state[j]];
  37808. }
  37809. //ShiftRows
  37810. v = state[1];
  37811. state[1] = state[5];
  37812. state[5] = state[9];
  37813. state[9] = state[13];
  37814. state[13] = v;
  37815. v = state[2];
  37816. u = state[6];
  37817. state[2] = state[10];
  37818. state[6] = state[14];
  37819. state[10] = v;
  37820. state[14] = u;
  37821. v = state[3];
  37822. u = state[7];
  37823. t = state[11];
  37824. state[3] = state[15];
  37825. state[7] = v;
  37826. state[11] = u;
  37827. state[15] = t;
  37828. //AddRoundKey
  37829. for (j = 0, k = 224; j < 16; ++j, ++k) {
  37830. state[j] ^= key[k];
  37831. }
  37832. return state;
  37833. }
  37834. function AES256Cipher(key) {
  37835. this.key = expandKey256(key);
  37836. this.buffer = new Uint8Array(16);
  37837. this.bufferPosition = 0;
  37838. }
  37839. function decryptBlock2(data, finalize) {
  37840. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  37841. for (i = 0; i < sourceLength; ++i) {
  37842. buffer[bufferLength] = data[i];
  37843. ++bufferLength;
  37844. if (bufferLength < 16) {
  37845. continue;
  37846. }
  37847. // buffer is full, decrypting
  37848. var plain = decrypt256(buffer, this.key);
  37849. // xor-ing the IV vector to get plain text
  37850. for (j = 0; j < 16; ++j) {
  37851. plain[j] ^= iv[j];
  37852. }
  37853. iv = buffer;
  37854. result.push(plain);
  37855. buffer = new Uint8Array(16);
  37856. bufferLength = 0;
  37857. }
  37858. // saving incomplete buffer
  37859. this.buffer = buffer;
  37860. this.bufferLength = bufferLength;
  37861. this.iv = iv;
  37862. if (result.length === 0) {
  37863. return new Uint8Array([]);
  37864. }
  37865. // combining plain text blocks into one
  37866. var outputLength = 16 * result.length;
  37867. if (finalize) {
  37868. // undo a padding that is described in RFC 2898
  37869. var lastBlock = result[result.length - 1];
  37870. var psLen = lastBlock[15];
  37871. if (psLen <= 16) {
  37872. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  37873. if (lastBlock[i] !== psLen) {
  37874. // Invalid padding, assume that the block has no padding.
  37875. psLen = 0;
  37876. break;
  37877. }
  37878. }
  37879. outputLength -= psLen;
  37880. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  37881. }
  37882. }
  37883. var output = new Uint8Array(outputLength);
  37884. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  37885. output.set(result[i], j);
  37886. }
  37887. return output;
  37888. }
  37889. AES256Cipher.prototype = {
  37890. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  37891. var i, sourceLength = data.length;
  37892. var buffer = this.buffer, bufferLength = this.bufferPosition;
  37893. // if not supplied an IV wait for IV values
  37894. // they are at the start of the stream
  37895. if (iv) {
  37896. this.iv = iv;
  37897. } else {
  37898. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  37899. buffer[bufferLength] = data[i];
  37900. }
  37901. if (bufferLength < 16) {
  37902. //need more data
  37903. this.bufferLength = bufferLength;
  37904. return new Uint8Array([]);
  37905. }
  37906. this.iv = buffer;
  37907. data = data.subarray(16);
  37908. }
  37909. this.buffer = new Uint8Array(16);
  37910. this.bufferLength = 0;
  37911. // starting decryption
  37912. this.decryptBlock = decryptBlock2;
  37913. return this.decryptBlock(data, finalize);
  37914. },
  37915. encrypt: function AES256Cipher_encrypt(data, iv) {
  37916. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  37917. if (!iv) {
  37918. iv = new Uint8Array(16);
  37919. }
  37920. for (i = 0; i < sourceLength; ++i) {
  37921. buffer[bufferLength] = data[i];
  37922. ++bufferLength;
  37923. if (bufferLength < 16) {
  37924. continue;
  37925. }
  37926. for (j = 0; j < 16; ++j) {
  37927. buffer[j] ^= iv[j];
  37928. }
  37929. // buffer is full, encrypting
  37930. var cipher = encrypt256(buffer, this.key);
  37931. this.iv = cipher;
  37932. result.push(cipher);
  37933. buffer = new Uint8Array(16);
  37934. bufferLength = 0;
  37935. }
  37936. // saving incomplete buffer
  37937. this.buffer = buffer;
  37938. this.bufferLength = bufferLength;
  37939. this.iv = iv;
  37940. if (result.length === 0) {
  37941. return new Uint8Array([]);
  37942. }
  37943. // combining plain text blocks into one
  37944. var outputLength = 16 * result.length;
  37945. var output = new Uint8Array(outputLength);
  37946. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  37947. output.set(result[i], j);
  37948. }
  37949. return output;
  37950. }
  37951. };
  37952. return AES256Cipher;
  37953. }();
  37954. var PDF17 = function PDF17Closure() {
  37955. function compareByteArrays(array1, array2) {
  37956. if (array1.length !== array2.length) {
  37957. return false;
  37958. }
  37959. for (var i = 0; i < array1.length; i++) {
  37960. if (array1[i] !== array2[i]) {
  37961. return false;
  37962. }
  37963. }
  37964. return true;
  37965. }
  37966. function PDF17() {
  37967. }
  37968. PDF17.prototype = {
  37969. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  37970. var hashData = new Uint8Array(password.length + 56);
  37971. hashData.set(password, 0);
  37972. hashData.set(ownerValidationSalt, password.length);
  37973. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  37974. var result = calculateSHA256(hashData, 0, hashData.length);
  37975. return compareByteArrays(result, ownerPassword);
  37976. },
  37977. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  37978. var hashData = new Uint8Array(password.length + 8);
  37979. hashData.set(password, 0);
  37980. hashData.set(userValidationSalt, password.length);
  37981. var result = calculateSHA256(hashData, 0, hashData.length);
  37982. return compareByteArrays(result, userPassword);
  37983. },
  37984. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  37985. var hashData = new Uint8Array(password.length + 56);
  37986. hashData.set(password, 0);
  37987. hashData.set(ownerKeySalt, password.length);
  37988. hashData.set(userBytes, password.length + ownerKeySalt.length);
  37989. var key = calculateSHA256(hashData, 0, hashData.length);
  37990. var cipher = new AES256Cipher(key);
  37991. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  37992. },
  37993. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  37994. var hashData = new Uint8Array(password.length + 8);
  37995. hashData.set(password, 0);
  37996. hashData.set(userKeySalt, password.length);
  37997. //key is the decryption key for the UE string
  37998. var key = calculateSHA256(hashData, 0, hashData.length);
  37999. var cipher = new AES256Cipher(key);
  38000. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  38001. }
  38002. };
  38003. return PDF17;
  38004. }();
  38005. var PDF20 = function PDF20Closure() {
  38006. function concatArrays(array1, array2) {
  38007. var t = new Uint8Array(array1.length + array2.length);
  38008. t.set(array1, 0);
  38009. t.set(array2, array1.length);
  38010. return t;
  38011. }
  38012. function calculatePDF20Hash(password, input, userBytes) {
  38013. //This refers to Algorithm 2.B as defined in ISO 32000-2
  38014. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  38015. var e = [0];
  38016. var i = 0;
  38017. while (i < 64 || e[e.length - 1] > i - 32) {
  38018. var arrayLength = password.length + k.length + userBytes.length;
  38019. var k1 = new Uint8Array(arrayLength * 64);
  38020. var array = concatArrays(password, k);
  38021. array = concatArrays(array, userBytes);
  38022. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  38023. k1.set(array, pos);
  38024. }
  38025. //AES128 CBC NO PADDING with
  38026. //first 16 bytes of k as the key and the second 16 as the iv.
  38027. var cipher = new AES128Cipher(k.subarray(0, 16));
  38028. e = cipher.encrypt(k1, k.subarray(16, 32));
  38029. //Now we have to take the first 16 bytes of an unsigned
  38030. //big endian integer... and compute the remainder
  38031. //modulo 3.... That is a fairly large number and
  38032. //JavaScript isn't going to handle that well...
  38033. //So we're using a trick that allows us to perform
  38034. //modulo math byte by byte
  38035. var remainder = 0;
  38036. for (var z = 0; z < 16; z++) {
  38037. remainder *= 256 % 3;
  38038. remainder %= 3;
  38039. remainder += (e[z] >>> 0) % 3;
  38040. remainder %= 3;
  38041. }
  38042. if (remainder === 0) {
  38043. k = calculateSHA256(e, 0, e.length);
  38044. } else if (remainder === 1) {
  38045. k = calculateSHA384(e, 0, e.length);
  38046. } else if (remainder === 2) {
  38047. k = calculateSHA512(e, 0, e.length);
  38048. }
  38049. i++;
  38050. }
  38051. return k.subarray(0, 32);
  38052. }
  38053. function PDF20() {
  38054. }
  38055. function compareByteArrays(array1, array2) {
  38056. if (array1.length !== array2.length) {
  38057. return false;
  38058. }
  38059. for (var i = 0; i < array1.length; i++) {
  38060. if (array1[i] !== array2[i]) {
  38061. return false;
  38062. }
  38063. }
  38064. return true;
  38065. }
  38066. PDF20.prototype = {
  38067. hash: function PDF20_hash(password, concatBytes, userBytes) {
  38068. return calculatePDF20Hash(password, concatBytes, userBytes);
  38069. },
  38070. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  38071. var hashData = new Uint8Array(password.length + 56);
  38072. hashData.set(password, 0);
  38073. hashData.set(ownerValidationSalt, password.length);
  38074. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  38075. var result = calculatePDF20Hash(password, hashData, userBytes);
  38076. return compareByteArrays(result, ownerPassword);
  38077. },
  38078. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  38079. var hashData = new Uint8Array(password.length + 8);
  38080. hashData.set(password, 0);
  38081. hashData.set(userValidationSalt, password.length);
  38082. var result = calculatePDF20Hash(password, hashData, []);
  38083. return compareByteArrays(result, userPassword);
  38084. },
  38085. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  38086. var hashData = new Uint8Array(password.length + 56);
  38087. hashData.set(password, 0);
  38088. hashData.set(ownerKeySalt, password.length);
  38089. hashData.set(userBytes, password.length + ownerKeySalt.length);
  38090. var key = calculatePDF20Hash(password, hashData, userBytes);
  38091. var cipher = new AES256Cipher(key);
  38092. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  38093. },
  38094. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  38095. var hashData = new Uint8Array(password.length + 8);
  38096. hashData.set(password, 0);
  38097. hashData.set(userKeySalt, password.length);
  38098. //key is the decryption key for the UE string
  38099. var key = calculatePDF20Hash(password, hashData, []);
  38100. var cipher = new AES256Cipher(key);
  38101. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  38102. }
  38103. };
  38104. return PDF20;
  38105. }();
  38106. var CipherTransform = function CipherTransformClosure() {
  38107. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  38108. this.stringCipherConstructor = stringCipherConstructor;
  38109. this.streamCipherConstructor = streamCipherConstructor;
  38110. }
  38111. CipherTransform.prototype = {
  38112. createStream: function CipherTransform_createStream(stream, length) {
  38113. var cipher = new this.streamCipherConstructor();
  38114. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  38115. return cipher.decryptBlock(data, finalize);
  38116. });
  38117. },
  38118. decryptString: function CipherTransform_decryptString(s) {
  38119. var cipher = new this.stringCipherConstructor();
  38120. var data = stringToBytes(s);
  38121. data = cipher.decryptBlock(data, true);
  38122. return bytesToString(data);
  38123. }
  38124. };
  38125. return CipherTransform;
  38126. }();
  38127. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  38128. var defaultPasswordBytes = new Uint8Array([
  38129. 0x28,
  38130. 0xBF,
  38131. 0x4E,
  38132. 0x5E,
  38133. 0x4E,
  38134. 0x75,
  38135. 0x8A,
  38136. 0x41,
  38137. 0x64,
  38138. 0x00,
  38139. 0x4E,
  38140. 0x56,
  38141. 0xFF,
  38142. 0xFA,
  38143. 0x01,
  38144. 0x08,
  38145. 0x2E,
  38146. 0x2E,
  38147. 0x00,
  38148. 0xB6,
  38149. 0xD0,
  38150. 0x68,
  38151. 0x3E,
  38152. 0x80,
  38153. 0x2F,
  38154. 0x0C,
  38155. 0xA9,
  38156. 0xFE,
  38157. 0x64,
  38158. 0x53,
  38159. 0x69,
  38160. 0x7A
  38161. ]);
  38162. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  38163. if (password) {
  38164. var passwordLength = Math.min(127, password.length);
  38165. password = password.subarray(0, passwordLength);
  38166. } else {
  38167. password = [];
  38168. }
  38169. var pdfAlgorithm;
  38170. if (revision === 6) {
  38171. pdfAlgorithm = new PDF20();
  38172. } else {
  38173. pdfAlgorithm = new PDF17();
  38174. }
  38175. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  38176. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  38177. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  38178. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  38179. }
  38180. return null;
  38181. }
  38182. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  38183. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  38184. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  38185. if (password) {
  38186. n = Math.min(32, password.length);
  38187. for (; i < n; ++i) {
  38188. hashData[i] = password[i];
  38189. }
  38190. }
  38191. j = 0;
  38192. while (i < 32) {
  38193. hashData[i++] = defaultPasswordBytes[j++];
  38194. }
  38195. // as now the padded password in the hashData[0..i]
  38196. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  38197. hashData[i++] = ownerPassword[j];
  38198. }
  38199. hashData[i++] = flags & 0xFF;
  38200. hashData[i++] = flags >> 8 & 0xFF;
  38201. hashData[i++] = flags >> 16 & 0xFF;
  38202. hashData[i++] = flags >>> 24 & 0xFF;
  38203. for (j = 0, n = fileId.length; j < n; ++j) {
  38204. hashData[i++] = fileId[j];
  38205. }
  38206. if (revision >= 4 && !encryptMetadata) {
  38207. hashData[i++] = 0xFF;
  38208. hashData[i++] = 0xFF;
  38209. hashData[i++] = 0xFF;
  38210. hashData[i++] = 0xFF;
  38211. }
  38212. var hash = calculateMD5(hashData, 0, i);
  38213. var keyLengthInBytes = keyLength >> 3;
  38214. if (revision >= 3) {
  38215. for (j = 0; j < 50; ++j) {
  38216. hash = calculateMD5(hash, 0, keyLengthInBytes);
  38217. }
  38218. }
  38219. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  38220. var cipher, checkData;
  38221. if (revision >= 3) {
  38222. for (i = 0; i < 32; ++i) {
  38223. hashData[i] = defaultPasswordBytes[i];
  38224. }
  38225. for (j = 0, n = fileId.length; j < n; ++j) {
  38226. hashData[i++] = fileId[j];
  38227. }
  38228. cipher = new ARCFourCipher(encryptionKey);
  38229. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  38230. n = encryptionKey.length;
  38231. var derivedKey = new Uint8Array(n), k;
  38232. for (j = 1; j <= 19; ++j) {
  38233. for (k = 0; k < n; ++k) {
  38234. derivedKey[k] = encryptionKey[k] ^ j;
  38235. }
  38236. cipher = new ARCFourCipher(derivedKey);
  38237. checkData = cipher.encryptBlock(checkData);
  38238. }
  38239. for (j = 0, n = checkData.length; j < n; ++j) {
  38240. if (userPassword[j] !== checkData[j]) {
  38241. return null;
  38242. }
  38243. }
  38244. } else {
  38245. cipher = new ARCFourCipher(encryptionKey);
  38246. checkData = cipher.encryptBlock(defaultPasswordBytes);
  38247. for (j = 0, n = checkData.length; j < n; ++j) {
  38248. if (userPassword[j] !== checkData[j]) {
  38249. return null;
  38250. }
  38251. }
  38252. }
  38253. return encryptionKey;
  38254. }
  38255. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  38256. var hashData = new Uint8Array(32), i = 0, j, n;
  38257. n = Math.min(32, password.length);
  38258. for (; i < n; ++i) {
  38259. hashData[i] = password[i];
  38260. }
  38261. j = 0;
  38262. while (i < 32) {
  38263. hashData[i++] = defaultPasswordBytes[j++];
  38264. }
  38265. var hash = calculateMD5(hashData, 0, i);
  38266. var keyLengthInBytes = keyLength >> 3;
  38267. if (revision >= 3) {
  38268. for (j = 0; j < 50; ++j) {
  38269. hash = calculateMD5(hash, 0, hash.length);
  38270. }
  38271. }
  38272. var cipher, userPassword;
  38273. if (revision >= 3) {
  38274. userPassword = ownerPassword;
  38275. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  38276. for (j = 19; j >= 0; j--) {
  38277. for (k = 0; k < keyLengthInBytes; ++k) {
  38278. derivedKey[k] = hash[k] ^ j;
  38279. }
  38280. cipher = new ARCFourCipher(derivedKey);
  38281. userPassword = cipher.encryptBlock(userPassword);
  38282. }
  38283. } else {
  38284. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  38285. userPassword = cipher.encryptBlock(ownerPassword);
  38286. }
  38287. return userPassword;
  38288. }
  38289. var identityName = Name.get('Identity');
  38290. function CipherTransformFactory(dict, fileId, password) {
  38291. var filter = dict.get('Filter');
  38292. if (!isName(filter, 'Standard')) {
  38293. error('unknown encryption method');
  38294. }
  38295. this.dict = dict;
  38296. var algorithm = dict.get('V');
  38297. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  38298. error('unsupported encryption algorithm');
  38299. }
  38300. this.algorithm = algorithm;
  38301. var keyLength = dict.get('Length');
  38302. if (!keyLength) {
  38303. // Spec asks to rely on encryption dictionary's Length entry, however
  38304. // some PDFs don't have it. Trying to recover.
  38305. if (algorithm <= 3) {
  38306. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  38307. keyLength = 40;
  38308. } else {
  38309. // Trying to find default handler -- it usually has Length.
  38310. var cfDict = dict.get('CF');
  38311. var streamCryptoName = dict.get('StmF');
  38312. if (isDict(cfDict) && isName(streamCryptoName)) {
  38313. cfDict.suppressEncryption = true;
  38314. // See comment below.
  38315. var handlerDict = cfDict.get(streamCryptoName.name);
  38316. keyLength = handlerDict && handlerDict.get('Length') || 128;
  38317. if (keyLength < 40) {
  38318. // Sometimes it's incorrect value of bits, generators specify bytes.
  38319. keyLength <<= 3;
  38320. }
  38321. }
  38322. }
  38323. }
  38324. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  38325. error('invalid key length');
  38326. }
  38327. // prepare keys
  38328. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  38329. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  38330. var flags = dict.get('P');
  38331. var revision = dict.get('R');
  38332. // meaningful when V is 4 or 5
  38333. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  38334. this.encryptMetadata = encryptMetadata;
  38335. var fileIdBytes = stringToBytes(fileId);
  38336. var passwordBytes;
  38337. if (password) {
  38338. if (revision === 6) {
  38339. try {
  38340. password = utf8StringToString(password);
  38341. } catch (ex) {
  38342. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  38343. }
  38344. }
  38345. passwordBytes = stringToBytes(password);
  38346. }
  38347. var encryptionKey;
  38348. if (algorithm !== 5) {
  38349. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  38350. } else {
  38351. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  38352. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  38353. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  38354. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  38355. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  38356. var ownerEncryption = stringToBytes(dict.get('OE'));
  38357. var userEncryption = stringToBytes(dict.get('UE'));
  38358. var perms = stringToBytes(dict.get('Perms'));
  38359. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  38360. }
  38361. if (!encryptionKey && !password) {
  38362. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  38363. } else if (!encryptionKey && password) {
  38364. // Attempting use the password as an owner password
  38365. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  38366. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  38367. }
  38368. if (!encryptionKey) {
  38369. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  38370. }
  38371. this.encryptionKey = encryptionKey;
  38372. if (algorithm >= 4) {
  38373. var cf = dict.get('CF');
  38374. if (isDict(cf)) {
  38375. // The 'CF' dictionary itself should not be encrypted, and by setting
  38376. // `suppressEncryption` we can prevent an infinite loop inside of
  38377. // `XRef_fetchUncompressed` if the dictionary contains indirect objects
  38378. // (fixes issue7665.pdf).
  38379. cf.suppressEncryption = true;
  38380. }
  38381. this.cf = cf;
  38382. this.stmf = dict.get('StmF') || identityName;
  38383. this.strf = dict.get('StrF') || identityName;
  38384. this.eff = dict.get('EFF') || this.stmf;
  38385. }
  38386. }
  38387. function buildObjectKey(num, gen, encryptionKey, isAes) {
  38388. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  38389. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  38390. key[i] = encryptionKey[i];
  38391. }
  38392. key[i++] = num & 0xFF;
  38393. key[i++] = num >> 8 & 0xFF;
  38394. key[i++] = num >> 16 & 0xFF;
  38395. key[i++] = gen & 0xFF;
  38396. key[i++] = gen >> 8 & 0xFF;
  38397. if (isAes) {
  38398. key[i++] = 0x73;
  38399. key[i++] = 0x41;
  38400. key[i++] = 0x6C;
  38401. key[i++] = 0x54;
  38402. }
  38403. var hash = calculateMD5(key, 0, i);
  38404. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  38405. }
  38406. function buildCipherConstructor(cf, name, num, gen, key) {
  38407. assert(isName(name), 'Invalid crypt filter name.');
  38408. var cryptFilter = cf.get(name.name);
  38409. var cfm;
  38410. if (cryptFilter !== null && cryptFilter !== undefined) {
  38411. cfm = cryptFilter.get('CFM');
  38412. }
  38413. if (!cfm || cfm.name === 'None') {
  38414. return function cipherTransformFactoryBuildCipherConstructorNone() {
  38415. return new NullCipher();
  38416. };
  38417. }
  38418. if ('V2' === cfm.name) {
  38419. return function cipherTransformFactoryBuildCipherConstructorV2() {
  38420. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  38421. };
  38422. }
  38423. if ('AESV2' === cfm.name) {
  38424. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  38425. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  38426. };
  38427. }
  38428. if ('AESV3' === cfm.name) {
  38429. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  38430. return new AES256Cipher(key);
  38431. };
  38432. }
  38433. error('Unknown crypto method');
  38434. }
  38435. CipherTransformFactory.prototype = {
  38436. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  38437. if (this.algorithm === 4 || this.algorithm === 5) {
  38438. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  38439. }
  38440. // algorithms 1 and 2
  38441. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  38442. var cipherConstructor = function buildCipherCipherConstructor() {
  38443. return new ARCFourCipher(key);
  38444. };
  38445. return new CipherTransform(cipherConstructor, cipherConstructor);
  38446. }
  38447. };
  38448. return CipherTransformFactory;
  38449. }();
  38450. exports.AES128Cipher = AES128Cipher;
  38451. exports.AES256Cipher = AES256Cipher;
  38452. exports.ARCFourCipher = ARCFourCipher;
  38453. exports.CipherTransformFactory = CipherTransformFactory;
  38454. exports.PDF17 = PDF17;
  38455. exports.PDF20 = PDF20;
  38456. exports.calculateMD5 = calculateMD5;
  38457. exports.calculateSHA256 = calculateSHA256;
  38458. exports.calculateSHA384 = calculateSHA384;
  38459. exports.calculateSHA512 = calculateSHA512;
  38460. }));
  38461. (function (root, factory) {
  38462. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  38463. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  38464. var Util = sharedUtil.Util;
  38465. var bytesToString = sharedUtil.bytesToString;
  38466. var error = sharedUtil.error;
  38467. var Stream = coreStream.Stream;
  38468. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38469. var StandardEncoding = coreEncodings.StandardEncoding;
  38470. var CFFParser = coreCFFParser.CFFParser;
  38471. var FontRendererFactory = function FontRendererFactoryClosure() {
  38472. function getLong(data, offset) {
  38473. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  38474. }
  38475. function getUshort(data, offset) {
  38476. return data[offset] << 8 | data[offset + 1];
  38477. }
  38478. function parseCmap(data, start, end) {
  38479. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  38480. var format = getUshort(data, start + offset);
  38481. var length, ranges, p, i;
  38482. if (format === 4) {
  38483. length = getUshort(data, start + offset + 2);
  38484. var segCount = getUshort(data, start + offset + 6) >> 1;
  38485. p = start + offset + 14;
  38486. ranges = [];
  38487. for (i = 0; i < segCount; i++, p += 2) {
  38488. ranges[i] = { end: getUshort(data, p) };
  38489. }
  38490. p += 2;
  38491. for (i = 0; i < segCount; i++, p += 2) {
  38492. ranges[i].start = getUshort(data, p);
  38493. }
  38494. for (i = 0; i < segCount; i++, p += 2) {
  38495. ranges[i].idDelta = getUshort(data, p);
  38496. }
  38497. for (i = 0; i < segCount; i++, p += 2) {
  38498. var idOffset = getUshort(data, p);
  38499. if (idOffset === 0) {
  38500. continue;
  38501. }
  38502. ranges[i].ids = [];
  38503. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  38504. ranges[i].ids[j] = getUshort(data, p + idOffset);
  38505. idOffset += 2;
  38506. }
  38507. }
  38508. return ranges;
  38509. } else if (format === 12) {
  38510. length = getLong(data, start + offset + 4);
  38511. var groups = getLong(data, start + offset + 12);
  38512. p = start + offset + 16;
  38513. ranges = [];
  38514. for (i = 0; i < groups; i++) {
  38515. ranges.push({
  38516. start: getLong(data, p),
  38517. end: getLong(data, p + 4),
  38518. idDelta: getLong(data, p + 8) - getLong(data, p)
  38519. });
  38520. p += 12;
  38521. }
  38522. return ranges;
  38523. }
  38524. error('not supported cmap: ' + format);
  38525. }
  38526. function parseCff(data, start, end, seacAnalysisEnabled) {
  38527. var properties = {};
  38528. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  38529. var cff = parser.parse();
  38530. return {
  38531. glyphs: cff.charStrings.objects,
  38532. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  38533. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  38534. };
  38535. }
  38536. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  38537. var itemSize, itemDecode;
  38538. if (isGlyphLocationsLong) {
  38539. itemSize = 4;
  38540. itemDecode = function fontItemDecodeLong(data, offset) {
  38541. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  38542. };
  38543. } else {
  38544. itemSize = 2;
  38545. itemDecode = function fontItemDecode(data, offset) {
  38546. return data[offset] << 9 | data[offset + 1] << 1;
  38547. };
  38548. }
  38549. var glyphs = [];
  38550. var startOffset = itemDecode(loca, 0);
  38551. for (var j = itemSize; j < loca.length; j += itemSize) {
  38552. var endOffset = itemDecode(loca, j);
  38553. glyphs.push(glyf.subarray(startOffset, endOffset));
  38554. startOffset = endOffset;
  38555. }
  38556. return glyphs;
  38557. }
  38558. function lookupCmap(ranges, unicode) {
  38559. var code = unicode.charCodeAt(0), gid = 0;
  38560. var l = 0, r = ranges.length - 1;
  38561. while (l < r) {
  38562. var c = l + r + 1 >> 1;
  38563. if (code < ranges[c].start) {
  38564. r = c - 1;
  38565. } else {
  38566. l = c;
  38567. }
  38568. }
  38569. if (ranges[l].start <= code && code <= ranges[l].end) {
  38570. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  38571. }
  38572. return {
  38573. charCode: code,
  38574. glyphId: gid
  38575. };
  38576. }
  38577. function compileGlyf(code, cmds, font) {
  38578. function moveTo(x, y) {
  38579. cmds.push({
  38580. cmd: 'moveTo',
  38581. args: [
  38582. x,
  38583. y
  38584. ]
  38585. });
  38586. }
  38587. function lineTo(x, y) {
  38588. cmds.push({
  38589. cmd: 'lineTo',
  38590. args: [
  38591. x,
  38592. y
  38593. ]
  38594. });
  38595. }
  38596. function quadraticCurveTo(xa, ya, x, y) {
  38597. cmds.push({
  38598. cmd: 'quadraticCurveTo',
  38599. args: [
  38600. xa,
  38601. ya,
  38602. x,
  38603. y
  38604. ]
  38605. });
  38606. }
  38607. var i = 0;
  38608. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  38609. var flags;
  38610. var x = 0, y = 0;
  38611. i += 10;
  38612. if (numberOfContours < 0) {
  38613. // composite glyph
  38614. do {
  38615. flags = code[i] << 8 | code[i + 1];
  38616. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  38617. i += 4;
  38618. var arg1, arg2;
  38619. if (flags & 0x01) {
  38620. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  38621. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  38622. i += 4;
  38623. } else {
  38624. arg1 = code[i++];
  38625. arg2 = code[i++];
  38626. }
  38627. if (flags & 0x02) {
  38628. x = arg1;
  38629. y = arg2;
  38630. } else {
  38631. x = 0;
  38632. y = 0;
  38633. }
  38634. // TODO "they are points" ?
  38635. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  38636. if (flags & 0x08) {
  38637. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38638. i += 2;
  38639. } else if (flags & 0x40) {
  38640. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38641. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  38642. i += 4;
  38643. } else if (flags & 0x80) {
  38644. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38645. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  38646. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  38647. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  38648. i += 8;
  38649. }
  38650. var subglyph = font.glyphs[glyphIndex];
  38651. if (subglyph) {
  38652. cmds.push({ cmd: 'save' });
  38653. cmds.push({
  38654. cmd: 'transform',
  38655. args: [
  38656. scaleX,
  38657. scale01,
  38658. scale10,
  38659. scaleY,
  38660. x,
  38661. y
  38662. ]
  38663. });
  38664. compileGlyf(subglyph, cmds, font);
  38665. cmds.push({ cmd: 'restore' });
  38666. }
  38667. } while (flags & 0x20);
  38668. } else {
  38669. // simple glyph
  38670. var endPtsOfContours = [];
  38671. var j, jj;
  38672. for (j = 0; j < numberOfContours; j++) {
  38673. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  38674. i += 2;
  38675. }
  38676. var instructionLength = code[i] << 8 | code[i + 1];
  38677. i += 2 + instructionLength;
  38678. // skipping the instructions
  38679. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  38680. var points = [];
  38681. while (points.length < numberOfPoints) {
  38682. flags = code[i++];
  38683. var repeat = 1;
  38684. if (flags & 0x08) {
  38685. repeat += code[i++];
  38686. }
  38687. while (repeat-- > 0) {
  38688. points.push({ flags: flags });
  38689. }
  38690. }
  38691. for (j = 0; j < numberOfPoints; j++) {
  38692. switch (points[j].flags & 0x12) {
  38693. case 0x00:
  38694. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  38695. i += 2;
  38696. break;
  38697. case 0x02:
  38698. x -= code[i++];
  38699. break;
  38700. case 0x12:
  38701. x += code[i++];
  38702. break;
  38703. }
  38704. points[j].x = x;
  38705. }
  38706. for (j = 0; j < numberOfPoints; j++) {
  38707. switch (points[j].flags & 0x24) {
  38708. case 0x00:
  38709. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  38710. i += 2;
  38711. break;
  38712. case 0x04:
  38713. y -= code[i++];
  38714. break;
  38715. case 0x24:
  38716. y += code[i++];
  38717. break;
  38718. }
  38719. points[j].y = y;
  38720. }
  38721. var startPoint = 0;
  38722. for (i = 0; i < numberOfContours; i++) {
  38723. var endPoint = endPtsOfContours[i];
  38724. // contours might have implicit points, which is located in the middle
  38725. // between two neighboring off-curve points
  38726. var contour = points.slice(startPoint, endPoint + 1);
  38727. if (contour[0].flags & 1) {
  38728. contour.push(contour[0]);
  38729. } else // using start point at the contour end
  38730. if (contour[contour.length - 1].flags & 1) {
  38731. // first is off-curve point, trying to use one from the end
  38732. contour.unshift(contour[contour.length - 1]);
  38733. } else {
  38734. // start and end are off-curve points, creating implicit one
  38735. var p = {
  38736. flags: 1,
  38737. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  38738. y: (contour[0].y + contour[contour.length - 1].y) / 2
  38739. };
  38740. contour.unshift(p);
  38741. contour.push(p);
  38742. }
  38743. moveTo(contour[0].x, contour[0].y);
  38744. for (j = 1, jj = contour.length; j < jj; j++) {
  38745. if (contour[j].flags & 1) {
  38746. lineTo(contour[j].x, contour[j].y);
  38747. } else if (contour[j + 1].flags & 1) {
  38748. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  38749. j++;
  38750. } else {
  38751. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  38752. }
  38753. }
  38754. startPoint = endPoint + 1;
  38755. }
  38756. }
  38757. }
  38758. function compileCharString(code, cmds, font) {
  38759. var stack = [];
  38760. var x = 0, y = 0;
  38761. var stems = 0;
  38762. function moveTo(x, y) {
  38763. cmds.push({
  38764. cmd: 'moveTo',
  38765. args: [
  38766. x,
  38767. y
  38768. ]
  38769. });
  38770. }
  38771. function lineTo(x, y) {
  38772. cmds.push({
  38773. cmd: 'lineTo',
  38774. args: [
  38775. x,
  38776. y
  38777. ]
  38778. });
  38779. }
  38780. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  38781. cmds.push({
  38782. cmd: 'bezierCurveTo',
  38783. args: [
  38784. x1,
  38785. y1,
  38786. x2,
  38787. y2,
  38788. x,
  38789. y
  38790. ]
  38791. });
  38792. }
  38793. function parse(code) {
  38794. var i = 0;
  38795. while (i < code.length) {
  38796. var stackClean = false;
  38797. var v = code[i++];
  38798. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  38799. switch (v) {
  38800. case 1:
  38801. // hstem
  38802. stems += stack.length >> 1;
  38803. stackClean = true;
  38804. break;
  38805. case 3:
  38806. // vstem
  38807. stems += stack.length >> 1;
  38808. stackClean = true;
  38809. break;
  38810. case 4:
  38811. // vmoveto
  38812. y += stack.pop();
  38813. moveTo(x, y);
  38814. stackClean = true;
  38815. break;
  38816. case 5:
  38817. // rlineto
  38818. while (stack.length > 0) {
  38819. x += stack.shift();
  38820. y += stack.shift();
  38821. lineTo(x, y);
  38822. }
  38823. break;
  38824. case 6:
  38825. // hlineto
  38826. while (stack.length > 0) {
  38827. x += stack.shift();
  38828. lineTo(x, y);
  38829. if (stack.length === 0) {
  38830. break;
  38831. }
  38832. y += stack.shift();
  38833. lineTo(x, y);
  38834. }
  38835. break;
  38836. case 7:
  38837. // vlineto
  38838. while (stack.length > 0) {
  38839. y += stack.shift();
  38840. lineTo(x, y);
  38841. if (stack.length === 0) {
  38842. break;
  38843. }
  38844. x += stack.shift();
  38845. lineTo(x, y);
  38846. }
  38847. break;
  38848. case 8:
  38849. // rrcurveto
  38850. while (stack.length > 0) {
  38851. xa = x + stack.shift();
  38852. ya = y + stack.shift();
  38853. xb = xa + stack.shift();
  38854. yb = ya + stack.shift();
  38855. x = xb + stack.shift();
  38856. y = yb + stack.shift();
  38857. bezierCurveTo(xa, ya, xb, yb, x, y);
  38858. }
  38859. break;
  38860. case 10:
  38861. // callsubr
  38862. n = stack.pop() + font.subrsBias;
  38863. subrCode = font.subrs[n];
  38864. if (subrCode) {
  38865. parse(subrCode);
  38866. }
  38867. break;
  38868. case 11:
  38869. // return
  38870. return;
  38871. case 12:
  38872. v = code[i++];
  38873. switch (v) {
  38874. case 34:
  38875. // flex
  38876. xa = x + stack.shift();
  38877. xb = xa + stack.shift();
  38878. y1 = y + stack.shift();
  38879. x = xb + stack.shift();
  38880. bezierCurveTo(xa, y, xb, y1, x, y1);
  38881. xa = x + stack.shift();
  38882. xb = xa + stack.shift();
  38883. x = xb + stack.shift();
  38884. bezierCurveTo(xa, y1, xb, y, x, y);
  38885. break;
  38886. case 35:
  38887. // flex
  38888. xa = x + stack.shift();
  38889. ya = y + stack.shift();
  38890. xb = xa + stack.shift();
  38891. yb = ya + stack.shift();
  38892. x = xb + stack.shift();
  38893. y = yb + stack.shift();
  38894. bezierCurveTo(xa, ya, xb, yb, x, y);
  38895. xa = x + stack.shift();
  38896. ya = y + stack.shift();
  38897. xb = xa + stack.shift();
  38898. yb = ya + stack.shift();
  38899. x = xb + stack.shift();
  38900. y = yb + stack.shift();
  38901. bezierCurveTo(xa, ya, xb, yb, x, y);
  38902. stack.pop();
  38903. // fd
  38904. break;
  38905. case 36:
  38906. // hflex1
  38907. xa = x + stack.shift();
  38908. y1 = y + stack.shift();
  38909. xb = xa + stack.shift();
  38910. y2 = y1 + stack.shift();
  38911. x = xb + stack.shift();
  38912. bezierCurveTo(xa, y1, xb, y2, x, y2);
  38913. xa = x + stack.shift();
  38914. xb = xa + stack.shift();
  38915. y3 = y2 + stack.shift();
  38916. x = xb + stack.shift();
  38917. bezierCurveTo(xa, y2, xb, y3, x, y);
  38918. break;
  38919. case 37:
  38920. // flex1
  38921. var x0 = x, y0 = y;
  38922. xa = x + stack.shift();
  38923. ya = y + stack.shift();
  38924. xb = xa + stack.shift();
  38925. yb = ya + stack.shift();
  38926. x = xb + stack.shift();
  38927. y = yb + stack.shift();
  38928. bezierCurveTo(xa, ya, xb, yb, x, y);
  38929. xa = x + stack.shift();
  38930. ya = y + stack.shift();
  38931. xb = xa + stack.shift();
  38932. yb = ya + stack.shift();
  38933. x = xb;
  38934. y = yb;
  38935. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  38936. x += stack.shift();
  38937. } else {
  38938. y += stack.shift();
  38939. }
  38940. bezierCurveTo(xa, ya, xb, yb, x, y);
  38941. break;
  38942. default:
  38943. error('unknown operator: 12 ' + v);
  38944. }
  38945. break;
  38946. case 14:
  38947. // endchar
  38948. if (stack.length >= 4) {
  38949. var achar = stack.pop();
  38950. var bchar = stack.pop();
  38951. y = stack.pop();
  38952. x = stack.pop();
  38953. cmds.push({ cmd: 'save' });
  38954. cmds.push({
  38955. cmd: 'translate',
  38956. args: [
  38957. x,
  38958. y
  38959. ]
  38960. });
  38961. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  38962. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  38963. cmds.push({ cmd: 'restore' });
  38964. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  38965. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  38966. }
  38967. return;
  38968. case 18:
  38969. // hstemhm
  38970. stems += stack.length >> 1;
  38971. stackClean = true;
  38972. break;
  38973. case 19:
  38974. // hintmask
  38975. stems += stack.length >> 1;
  38976. i += stems + 7 >> 3;
  38977. stackClean = true;
  38978. break;
  38979. case 20:
  38980. // cntrmask
  38981. stems += stack.length >> 1;
  38982. i += stems + 7 >> 3;
  38983. stackClean = true;
  38984. break;
  38985. case 21:
  38986. // rmoveto
  38987. y += stack.pop();
  38988. x += stack.pop();
  38989. moveTo(x, y);
  38990. stackClean = true;
  38991. break;
  38992. case 22:
  38993. // hmoveto
  38994. x += stack.pop();
  38995. moveTo(x, y);
  38996. stackClean = true;
  38997. break;
  38998. case 23:
  38999. // vstemhm
  39000. stems += stack.length >> 1;
  39001. stackClean = true;
  39002. break;
  39003. case 24:
  39004. // rcurveline
  39005. while (stack.length > 2) {
  39006. xa = x + stack.shift();
  39007. ya = y + stack.shift();
  39008. xb = xa + stack.shift();
  39009. yb = ya + stack.shift();
  39010. x = xb + stack.shift();
  39011. y = yb + stack.shift();
  39012. bezierCurveTo(xa, ya, xb, yb, x, y);
  39013. }
  39014. x += stack.shift();
  39015. y += stack.shift();
  39016. lineTo(x, y);
  39017. break;
  39018. case 25:
  39019. // rlinecurve
  39020. while (stack.length > 6) {
  39021. x += stack.shift();
  39022. y += stack.shift();
  39023. lineTo(x, y);
  39024. }
  39025. xa = x + stack.shift();
  39026. ya = y + stack.shift();
  39027. xb = xa + stack.shift();
  39028. yb = ya + stack.shift();
  39029. x = xb + stack.shift();
  39030. y = yb + stack.shift();
  39031. bezierCurveTo(xa, ya, xb, yb, x, y);
  39032. break;
  39033. case 26:
  39034. // vvcurveto
  39035. if (stack.length % 2) {
  39036. x += stack.shift();
  39037. }
  39038. while (stack.length > 0) {
  39039. xa = x;
  39040. ya = y + stack.shift();
  39041. xb = xa + stack.shift();
  39042. yb = ya + stack.shift();
  39043. x = xb;
  39044. y = yb + stack.shift();
  39045. bezierCurveTo(xa, ya, xb, yb, x, y);
  39046. }
  39047. break;
  39048. case 27:
  39049. // hhcurveto
  39050. if (stack.length % 2) {
  39051. y += stack.shift();
  39052. }
  39053. while (stack.length > 0) {
  39054. xa = x + stack.shift();
  39055. ya = y;
  39056. xb = xa + stack.shift();
  39057. yb = ya + stack.shift();
  39058. x = xb + stack.shift();
  39059. y = yb;
  39060. bezierCurveTo(xa, ya, xb, yb, x, y);
  39061. }
  39062. break;
  39063. case 28:
  39064. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  39065. i += 2;
  39066. break;
  39067. case 29:
  39068. // callgsubr
  39069. n = stack.pop() + font.gsubrsBias;
  39070. subrCode = font.gsubrs[n];
  39071. if (subrCode) {
  39072. parse(subrCode);
  39073. }
  39074. break;
  39075. case 30:
  39076. // vhcurveto
  39077. while (stack.length > 0) {
  39078. xa = x;
  39079. ya = y + stack.shift();
  39080. xb = xa + stack.shift();
  39081. yb = ya + stack.shift();
  39082. x = xb + stack.shift();
  39083. y = yb + (stack.length === 1 ? stack.shift() : 0);
  39084. bezierCurveTo(xa, ya, xb, yb, x, y);
  39085. if (stack.length === 0) {
  39086. break;
  39087. }
  39088. xa = x + stack.shift();
  39089. ya = y;
  39090. xb = xa + stack.shift();
  39091. yb = ya + stack.shift();
  39092. y = yb + stack.shift();
  39093. x = xb + (stack.length === 1 ? stack.shift() : 0);
  39094. bezierCurveTo(xa, ya, xb, yb, x, y);
  39095. }
  39096. break;
  39097. case 31:
  39098. // hvcurveto
  39099. while (stack.length > 0) {
  39100. xa = x + stack.shift();
  39101. ya = y;
  39102. xb = xa + stack.shift();
  39103. yb = ya + stack.shift();
  39104. y = yb + stack.shift();
  39105. x = xb + (stack.length === 1 ? stack.shift() : 0);
  39106. bezierCurveTo(xa, ya, xb, yb, x, y);
  39107. if (stack.length === 0) {
  39108. break;
  39109. }
  39110. xa = x;
  39111. ya = y + stack.shift();
  39112. xb = xa + stack.shift();
  39113. yb = ya + stack.shift();
  39114. x = xb + stack.shift();
  39115. y = yb + (stack.length === 1 ? stack.shift() : 0);
  39116. bezierCurveTo(xa, ya, xb, yb, x, y);
  39117. }
  39118. break;
  39119. default:
  39120. if (v < 32) {
  39121. error('unknown operator: ' + v);
  39122. }
  39123. if (v < 247) {
  39124. stack.push(v - 139);
  39125. } else if (v < 251) {
  39126. stack.push((v - 247) * 256 + code[i++] + 108);
  39127. } else if (v < 255) {
  39128. stack.push(-(v - 251) * 256 - code[i++] - 108);
  39129. } else {
  39130. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  39131. i += 4;
  39132. }
  39133. break;
  39134. }
  39135. if (stackClean) {
  39136. stack.length = 0;
  39137. }
  39138. }
  39139. }
  39140. parse(code);
  39141. }
  39142. var noop = '';
  39143. function CompiledFont(fontMatrix) {
  39144. this.compiledGlyphs = Object.create(null);
  39145. this.compiledCharCodeToGlyphId = Object.create(null);
  39146. this.fontMatrix = fontMatrix;
  39147. }
  39148. CompiledFont.prototype = {
  39149. getPathJs: function (unicode) {
  39150. var cmap = lookupCmap(this.cmap, unicode);
  39151. var fn = this.compiledGlyphs[cmap.glyphId];
  39152. if (!fn) {
  39153. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  39154. this.compiledGlyphs[cmap.glyphId] = fn;
  39155. }
  39156. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  39157. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  39158. }
  39159. return fn;
  39160. },
  39161. compileGlyph: function (code) {
  39162. if (!code || code.length === 0 || code[0] === 14) {
  39163. return noop;
  39164. }
  39165. var cmds = [];
  39166. cmds.push({ cmd: 'save' });
  39167. cmds.push({
  39168. cmd: 'transform',
  39169. args: this.fontMatrix.slice()
  39170. });
  39171. cmds.push({
  39172. cmd: 'scale',
  39173. args: [
  39174. 'size',
  39175. '-size'
  39176. ]
  39177. });
  39178. this.compileGlyphImpl(code, cmds);
  39179. cmds.push({ cmd: 'restore' });
  39180. return cmds;
  39181. },
  39182. compileGlyphImpl: function () {
  39183. error('Children classes should implement this.');
  39184. },
  39185. hasBuiltPath: function (unicode) {
  39186. var cmap = lookupCmap(this.cmap, unicode);
  39187. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  39188. }
  39189. };
  39190. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  39191. fontMatrix = fontMatrix || [
  39192. 0.000488,
  39193. 0,
  39194. 0,
  39195. 0.000488,
  39196. 0,
  39197. 0
  39198. ];
  39199. CompiledFont.call(this, fontMatrix);
  39200. this.glyphs = glyphs;
  39201. this.cmap = cmap;
  39202. }
  39203. Util.inherit(TrueTypeCompiled, CompiledFont, {
  39204. compileGlyphImpl: function (code, cmds) {
  39205. compileGlyf(code, cmds, this);
  39206. }
  39207. });
  39208. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  39209. fontMatrix = fontMatrix || [
  39210. 0.001,
  39211. 0,
  39212. 0,
  39213. 0.001,
  39214. 0,
  39215. 0
  39216. ];
  39217. CompiledFont.call(this, fontMatrix);
  39218. this.glyphs = cffInfo.glyphs;
  39219. this.gsubrs = cffInfo.gsubrs || [];
  39220. this.subrs = cffInfo.subrs || [];
  39221. this.cmap = cmap;
  39222. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  39223. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  39224. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  39225. }
  39226. Util.inherit(Type2Compiled, CompiledFont, {
  39227. compileGlyphImpl: function (code, cmds) {
  39228. compileCharString(code, cmds, this);
  39229. }
  39230. });
  39231. return {
  39232. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  39233. var data = new Uint8Array(font.data);
  39234. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  39235. var numTables = getUshort(data, 4);
  39236. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  39237. var tag = bytesToString(data.subarray(p, p + 4));
  39238. var offset = getLong(data, p + 8);
  39239. var length = getLong(data, p + 12);
  39240. switch (tag) {
  39241. case 'cmap':
  39242. cmap = parseCmap(data, offset, offset + length);
  39243. break;
  39244. case 'glyf':
  39245. glyf = data.subarray(offset, offset + length);
  39246. break;
  39247. case 'loca':
  39248. loca = data.subarray(offset, offset + length);
  39249. break;
  39250. case 'head':
  39251. unitsPerEm = getUshort(data, offset + 18);
  39252. indexToLocFormat = getUshort(data, offset + 50);
  39253. break;
  39254. case 'CFF ':
  39255. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  39256. break;
  39257. }
  39258. }
  39259. if (glyf) {
  39260. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  39261. 1 / unitsPerEm,
  39262. 0,
  39263. 0,
  39264. 1 / unitsPerEm,
  39265. 0,
  39266. 0
  39267. ];
  39268. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  39269. } else {
  39270. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  39271. }
  39272. }
  39273. };
  39274. }();
  39275. exports.FontRendererFactory = FontRendererFactory;
  39276. }));
  39277. (function (root, factory) {
  39278. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  39279. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  39280. var MissingDataException = sharedUtil.MissingDataException;
  39281. var StreamType = sharedUtil.StreamType;
  39282. var assert = sharedUtil.assert;
  39283. var error = sharedUtil.error;
  39284. var info = sharedUtil.info;
  39285. var isArray = sharedUtil.isArray;
  39286. var isInt = sharedUtil.isInt;
  39287. var isNum = sharedUtil.isNum;
  39288. var isString = sharedUtil.isString;
  39289. var warn = sharedUtil.warn;
  39290. var Cmd = corePrimitives.Cmd;
  39291. var Dict = corePrimitives.Dict;
  39292. var Name = corePrimitives.Name;
  39293. var Ref = corePrimitives.Ref;
  39294. var isCmd = corePrimitives.isCmd;
  39295. var isDict = corePrimitives.isDict;
  39296. var isName = corePrimitives.isName;
  39297. var Ascii85Stream = coreStream.Ascii85Stream;
  39298. var AsciiHexStream = coreStream.AsciiHexStream;
  39299. var CCITTFaxStream = coreStream.CCITTFaxStream;
  39300. var FlateStream = coreStream.FlateStream;
  39301. var Jbig2Stream = coreStream.Jbig2Stream;
  39302. var JpegStream = coreStream.JpegStream;
  39303. var JpxStream = coreStream.JpxStream;
  39304. var LZWStream = coreStream.LZWStream;
  39305. var NullStream = coreStream.NullStream;
  39306. var PredictorStream = coreStream.PredictorStream;
  39307. var RunLengthStream = coreStream.RunLengthStream;
  39308. var EOF = {};
  39309. function isEOF(v) {
  39310. return v === EOF;
  39311. }
  39312. var MAX_LENGTH_TO_CACHE = 1000;
  39313. var Parser = function ParserClosure() {
  39314. function Parser(lexer, allowStreams, xref, recoveryMode) {
  39315. this.lexer = lexer;
  39316. this.allowStreams = allowStreams;
  39317. this.xref = xref;
  39318. this.recoveryMode = recoveryMode || false;
  39319. this.imageCache = Object.create(null);
  39320. this.refill();
  39321. }
  39322. Parser.prototype = {
  39323. refill: function Parser_refill() {
  39324. this.buf1 = this.lexer.getObj();
  39325. this.buf2 = this.lexer.getObj();
  39326. },
  39327. shift: function Parser_shift() {
  39328. if (isCmd(this.buf2, 'ID')) {
  39329. this.buf1 = this.buf2;
  39330. this.buf2 = null;
  39331. } else {
  39332. this.buf1 = this.buf2;
  39333. this.buf2 = this.lexer.getObj();
  39334. }
  39335. },
  39336. tryShift: function Parser_tryShift() {
  39337. try {
  39338. this.shift();
  39339. return true;
  39340. } catch (e) {
  39341. if (e instanceof MissingDataException) {
  39342. throw e;
  39343. }
  39344. // Upon failure, the caller should reset this.lexer.pos to a known good
  39345. // state and call this.shift() twice to reset the buffers.
  39346. return false;
  39347. }
  39348. },
  39349. getObj: function Parser_getObj(cipherTransform) {
  39350. var buf1 = this.buf1;
  39351. this.shift();
  39352. if (buf1 instanceof Cmd) {
  39353. switch (buf1.cmd) {
  39354. case 'BI':
  39355. // inline image
  39356. return this.makeInlineImage(cipherTransform);
  39357. case '[':
  39358. // array
  39359. var array = [];
  39360. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  39361. array.push(this.getObj(cipherTransform));
  39362. }
  39363. if (isEOF(this.buf1)) {
  39364. if (!this.recoveryMode) {
  39365. error('End of file inside array');
  39366. }
  39367. return array;
  39368. }
  39369. this.shift();
  39370. return array;
  39371. case '<<':
  39372. // dictionary or stream
  39373. var dict = new Dict(this.xref);
  39374. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  39375. if (!isName(this.buf1)) {
  39376. info('Malformed dictionary: key must be a name object');
  39377. this.shift();
  39378. continue;
  39379. }
  39380. var key = this.buf1.name;
  39381. this.shift();
  39382. if (isEOF(this.buf1)) {
  39383. break;
  39384. }
  39385. dict.set(key, this.getObj(cipherTransform));
  39386. }
  39387. if (isEOF(this.buf1)) {
  39388. if (!this.recoveryMode) {
  39389. error('End of file inside dictionary');
  39390. }
  39391. return dict;
  39392. }
  39393. // Stream objects are not allowed inside content streams or
  39394. // object streams.
  39395. if (isCmd(this.buf2, 'stream')) {
  39396. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  39397. }
  39398. this.shift();
  39399. return dict;
  39400. default:
  39401. // simple object
  39402. return buf1;
  39403. }
  39404. }
  39405. if (isInt(buf1)) {
  39406. // indirect reference or integer
  39407. var num = buf1;
  39408. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  39409. var ref = new Ref(num, this.buf1);
  39410. this.shift();
  39411. this.shift();
  39412. return ref;
  39413. }
  39414. return num;
  39415. }
  39416. if (isString(buf1)) {
  39417. // string
  39418. var str = buf1;
  39419. if (cipherTransform) {
  39420. str = cipherTransform.decryptString(str);
  39421. }
  39422. return str;
  39423. }
  39424. // simple object
  39425. return buf1;
  39426. },
  39427. /**
  39428. * Find the end of the stream by searching for the /EI\s/.
  39429. * @returns {number} The inline stream length.
  39430. */
  39431. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  39432. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  39433. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  39434. while ((ch = stream.getByte()) !== -1) {
  39435. if (state === 0) {
  39436. state = ch === E ? 1 : 0;
  39437. } else if (state === 1) {
  39438. state = ch === I ? 2 : 0;
  39439. } else {
  39440. assert(state === 2);
  39441. if (ch === SPACE || ch === LF || ch === CR) {
  39442. // Let's check the next five bytes are ASCII... just be sure.
  39443. n = 5;
  39444. followingBytes = stream.peekBytes(n);
  39445. for (i = 0; i < n; i++) {
  39446. ch = followingBytes[i];
  39447. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  39448. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  39449. // it's binary stuff. Resetting the state.
  39450. state = 0;
  39451. break;
  39452. }
  39453. }
  39454. if (state === 2) {
  39455. break;
  39456. }
  39457. } else
  39458. // Finished!
  39459. {
  39460. state = 0;
  39461. }
  39462. }
  39463. }
  39464. return stream.pos - 4 - startPos;
  39465. },
  39466. /**
  39467. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  39468. * @returns {number} The inline stream length.
  39469. */
  39470. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  39471. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  39472. while ((b = stream.getByte()) !== -1) {
  39473. if (b !== 0xFF) {
  39474. // Not a valid marker.
  39475. continue;
  39476. }
  39477. switch (stream.getByte()) {
  39478. case 0x00:
  39479. // Byte stuffing.
  39480. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  39481. break;
  39482. case 0xFF:
  39483. // Fill byte.
  39484. // Avoid skipping a valid marker, resetting the stream position.
  39485. stream.skip(-1);
  39486. break;
  39487. case 0xD9:
  39488. // EOI
  39489. foundEOI = true;
  39490. break;
  39491. case 0xC0:
  39492. // SOF0
  39493. case 0xC1:
  39494. // SOF1
  39495. case 0xC2:
  39496. // SOF2
  39497. case 0xC3:
  39498. // SOF3
  39499. case 0xC5:
  39500. // SOF5
  39501. case 0xC6:
  39502. // SOF6
  39503. case 0xC7:
  39504. // SOF7
  39505. case 0xC9:
  39506. // SOF9
  39507. case 0xCA:
  39508. // SOF10
  39509. case 0xCB:
  39510. // SOF11
  39511. case 0xCD:
  39512. // SOF13
  39513. case 0xCE:
  39514. // SOF14
  39515. case 0xCF:
  39516. // SOF15
  39517. case 0xC4:
  39518. // DHT
  39519. case 0xCC:
  39520. // DAC
  39521. case 0xDA:
  39522. // SOS
  39523. case 0xDB:
  39524. // DQT
  39525. case 0xDC:
  39526. // DNL
  39527. case 0xDD:
  39528. // DRI
  39529. case 0xDE:
  39530. // DHP
  39531. case 0xDF:
  39532. // EXP
  39533. case 0xE0:
  39534. // APP0
  39535. case 0xE1:
  39536. // APP1
  39537. case 0xE2:
  39538. // APP2
  39539. case 0xE3:
  39540. // APP3
  39541. case 0xE4:
  39542. // APP4
  39543. case 0xE5:
  39544. // APP5
  39545. case 0xE6:
  39546. // APP6
  39547. case 0xE7:
  39548. // APP7
  39549. case 0xE8:
  39550. // APP8
  39551. case 0xE9:
  39552. // APP9
  39553. case 0xEA:
  39554. // APP10
  39555. case 0xEB:
  39556. // APP11
  39557. case 0xEC:
  39558. // APP12
  39559. case 0xED:
  39560. // APP13
  39561. case 0xEE:
  39562. // APP14
  39563. case 0xEF:
  39564. // APP15
  39565. case 0xFE:
  39566. // COM
  39567. // The marker should be followed by the length of the segment.
  39568. markerLength = stream.getUint16();
  39569. if (markerLength > 2) {
  39570. // |markerLength| contains the byte length of the marker segment,
  39571. // including its own length (2 bytes) and excluding the marker.
  39572. stream.skip(markerLength - 2);
  39573. } else
  39574. // Jump to the next marker.
  39575. {
  39576. // The marker length is invalid, resetting the stream position.
  39577. stream.skip(-2);
  39578. }
  39579. break;
  39580. }
  39581. if (foundEOI) {
  39582. break;
  39583. }
  39584. }
  39585. length = stream.pos - startPos;
  39586. if (b === -1) {
  39587. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  39588. stream.skip(-length);
  39589. // Reset the stream position.
  39590. return this.findDefaultInlineStreamEnd(stream);
  39591. }
  39592. this.inlineStreamSkipEI(stream);
  39593. return length;
  39594. },
  39595. /**
  39596. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  39597. * @returns {number} The inline stream length.
  39598. */
  39599. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  39600. var TILDE = 0x7E, GT = 0x3E;
  39601. var startPos = stream.pos, ch, length;
  39602. while ((ch = stream.getByte()) !== -1) {
  39603. if (ch === TILDE && stream.peekByte() === GT) {
  39604. stream.skip();
  39605. break;
  39606. }
  39607. }
  39608. length = stream.pos - startPos;
  39609. if (ch === -1) {
  39610. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  39611. stream.skip(-length);
  39612. // Reset the stream position.
  39613. return this.findDefaultInlineStreamEnd(stream);
  39614. }
  39615. this.inlineStreamSkipEI(stream);
  39616. return length;
  39617. },
  39618. /**
  39619. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  39620. * @returns {number} The inline stream length.
  39621. */
  39622. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  39623. var GT = 0x3E;
  39624. var startPos = stream.pos, ch, length;
  39625. while ((ch = stream.getByte()) !== -1) {
  39626. if (ch === GT) {
  39627. break;
  39628. }
  39629. }
  39630. length = stream.pos - startPos;
  39631. if (ch === -1) {
  39632. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  39633. stream.skip(-length);
  39634. // Reset the stream position.
  39635. return this.findDefaultInlineStreamEnd(stream);
  39636. }
  39637. this.inlineStreamSkipEI(stream);
  39638. return length;
  39639. },
  39640. /**
  39641. * Skip over the /EI/ for streams where we search for an EOD marker.
  39642. */
  39643. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  39644. var E = 0x45, I = 0x49;
  39645. var state = 0, ch;
  39646. while ((ch = stream.getByte()) !== -1) {
  39647. if (state === 0) {
  39648. state = ch === E ? 1 : 0;
  39649. } else if (state === 1) {
  39650. state = ch === I ? 2 : 0;
  39651. } else if (state === 2) {
  39652. break;
  39653. }
  39654. }
  39655. },
  39656. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  39657. var lexer = this.lexer;
  39658. var stream = lexer.stream;
  39659. // Parse dictionary.
  39660. var dict = new Dict(this.xref);
  39661. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  39662. if (!isName(this.buf1)) {
  39663. error('Dictionary key must be a name object');
  39664. }
  39665. var key = this.buf1.name;
  39666. this.shift();
  39667. if (isEOF(this.buf1)) {
  39668. break;
  39669. }
  39670. dict.set(key, this.getObj(cipherTransform));
  39671. }
  39672. // Extract the name of the first (i.e. the current) image filter.
  39673. var filter = dict.get('Filter', 'F'), filterName;
  39674. if (isName(filter)) {
  39675. filterName = filter.name;
  39676. } else if (isArray(filter) && isName(filter[0])) {
  39677. filterName = filter[0].name;
  39678. }
  39679. // Parse image stream.
  39680. var startPos = stream.pos, length, i, ii;
  39681. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  39682. length = this.findDCTDecodeInlineStreamEnd(stream);
  39683. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  39684. length = this.findASCII85DecodeInlineStreamEnd(stream);
  39685. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  39686. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  39687. } else {
  39688. length = this.findDefaultInlineStreamEnd(stream);
  39689. }
  39690. var imageStream = stream.makeSubStream(startPos, length, dict);
  39691. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  39692. // adler32 checksum.
  39693. var adler32;
  39694. if (length < MAX_LENGTH_TO_CACHE) {
  39695. var imageBytes = imageStream.getBytes();
  39696. imageStream.reset();
  39697. var a = 1;
  39698. var b = 0;
  39699. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  39700. // No modulo required in the loop if imageBytes.length < 5552.
  39701. a += imageBytes[i] & 0xff;
  39702. b += a;
  39703. }
  39704. adler32 = b % 65521 << 16 | a % 65521;
  39705. if (this.imageCache.adler32 === adler32) {
  39706. this.buf2 = Cmd.get('EI');
  39707. this.shift();
  39708. this.imageCache[adler32].reset();
  39709. return this.imageCache[adler32];
  39710. }
  39711. }
  39712. if (cipherTransform) {
  39713. imageStream = cipherTransform.createStream(imageStream, length);
  39714. }
  39715. imageStream = this.filter(imageStream, dict, length);
  39716. imageStream.dict = dict;
  39717. if (adler32 !== undefined) {
  39718. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  39719. this.imageCache[adler32] = imageStream;
  39720. }
  39721. this.buf2 = Cmd.get('EI');
  39722. this.shift();
  39723. return imageStream;
  39724. },
  39725. makeStream: function Parser_makeStream(dict, cipherTransform) {
  39726. var lexer = this.lexer;
  39727. var stream = lexer.stream;
  39728. // get stream start position
  39729. lexer.skipToNextLine();
  39730. var pos = stream.pos - 1;
  39731. // get length
  39732. var length = dict.get('Length');
  39733. if (!isInt(length)) {
  39734. info('Bad ' + length + ' attribute in stream');
  39735. length = 0;
  39736. }
  39737. // skip over the stream data
  39738. stream.pos = pos + length;
  39739. lexer.nextChar();
  39740. // Shift '>>' and check whether the new object marks the end of the stream
  39741. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  39742. this.shift();
  39743. } else
  39744. // 'stream'
  39745. {
  39746. // bad stream length, scanning for endstream
  39747. stream.pos = pos;
  39748. var SCAN_BLOCK_SIZE = 2048;
  39749. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  39750. var ENDSTREAM_SIGNATURE = [
  39751. 0x65,
  39752. 0x6E,
  39753. 0x64,
  39754. 0x73,
  39755. 0x74,
  39756. 0x72,
  39757. 0x65,
  39758. 0x61,
  39759. 0x6D
  39760. ];
  39761. var skipped = 0, found = false, i, j;
  39762. while (stream.pos < stream.end) {
  39763. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  39764. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  39765. if (scanLength <= 0) {
  39766. break;
  39767. }
  39768. found = false;
  39769. i = 0;
  39770. while (i < scanLength) {
  39771. j = 0;
  39772. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  39773. j++;
  39774. }
  39775. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  39776. found = true;
  39777. break;
  39778. }
  39779. i++;
  39780. }
  39781. if (found) {
  39782. skipped += i;
  39783. stream.pos += i;
  39784. break;
  39785. }
  39786. skipped += scanLength;
  39787. stream.pos += scanLength;
  39788. }
  39789. if (!found) {
  39790. error('Missing endstream');
  39791. }
  39792. length = skipped;
  39793. lexer.nextChar();
  39794. this.shift();
  39795. this.shift();
  39796. }
  39797. this.shift();
  39798. // 'endstream'
  39799. stream = stream.makeSubStream(pos, length, dict);
  39800. if (cipherTransform) {
  39801. stream = cipherTransform.createStream(stream, length);
  39802. }
  39803. stream = this.filter(stream, dict, length);
  39804. stream.dict = dict;
  39805. return stream;
  39806. },
  39807. filter: function Parser_filter(stream, dict, length) {
  39808. var filter = dict.get('Filter', 'F');
  39809. var params = dict.get('DecodeParms', 'DP');
  39810. if (isName(filter)) {
  39811. if (isArray(params)) {
  39812. params = params[0];
  39813. }
  39814. return this.makeFilter(stream, filter.name, length, params);
  39815. }
  39816. var maybeLength = length;
  39817. if (isArray(filter)) {
  39818. var filterArray = filter;
  39819. var paramsArray = params;
  39820. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  39821. filter = filterArray[i];
  39822. if (!isName(filter)) {
  39823. error('Bad filter name: ' + filter);
  39824. }
  39825. params = null;
  39826. if (isArray(paramsArray) && i in paramsArray) {
  39827. params = paramsArray[i];
  39828. }
  39829. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  39830. // after the first stream the length variable is invalid
  39831. maybeLength = null;
  39832. }
  39833. }
  39834. return stream;
  39835. },
  39836. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  39837. // Since the 'Length' entry in the stream dictionary can be completely
  39838. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  39839. // when we can be absolutely certain that it actually is empty.
  39840. if (maybeLength === 0) {
  39841. warn('Empty "' + name + '" stream.');
  39842. return new NullStream(stream);
  39843. }
  39844. try {
  39845. if (params && this.xref) {
  39846. params = this.xref.fetchIfRef(params);
  39847. }
  39848. var xrefStreamStats = this.xref.stats.streamTypes;
  39849. if (name === 'FlateDecode' || name === 'Fl') {
  39850. xrefStreamStats[StreamType.FLATE] = true;
  39851. if (params) {
  39852. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  39853. }
  39854. return new FlateStream(stream, maybeLength);
  39855. }
  39856. if (name === 'LZWDecode' || name === 'LZW') {
  39857. xrefStreamStats[StreamType.LZW] = true;
  39858. var earlyChange = 1;
  39859. if (params) {
  39860. if (params.has('EarlyChange')) {
  39861. earlyChange = params.get('EarlyChange');
  39862. }
  39863. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  39864. }
  39865. return new LZWStream(stream, maybeLength, earlyChange);
  39866. }
  39867. if (name === 'DCTDecode' || name === 'DCT') {
  39868. xrefStreamStats[StreamType.DCT] = true;
  39869. return new JpegStream(stream, maybeLength, stream.dict, params);
  39870. }
  39871. if (name === 'JPXDecode' || name === 'JPX') {
  39872. xrefStreamStats[StreamType.JPX] = true;
  39873. return new JpxStream(stream, maybeLength, stream.dict, params);
  39874. }
  39875. if (name === 'ASCII85Decode' || name === 'A85') {
  39876. xrefStreamStats[StreamType.A85] = true;
  39877. return new Ascii85Stream(stream, maybeLength);
  39878. }
  39879. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  39880. xrefStreamStats[StreamType.AHX] = true;
  39881. return new AsciiHexStream(stream, maybeLength);
  39882. }
  39883. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  39884. xrefStreamStats[StreamType.CCF] = true;
  39885. return new CCITTFaxStream(stream, maybeLength, params);
  39886. }
  39887. if (name === 'RunLengthDecode' || name === 'RL') {
  39888. xrefStreamStats[StreamType.RL] = true;
  39889. return new RunLengthStream(stream, maybeLength);
  39890. }
  39891. if (name === 'JBIG2Decode') {
  39892. xrefStreamStats[StreamType.JBIG] = true;
  39893. return new Jbig2Stream(stream, maybeLength, stream.dict, params);
  39894. }
  39895. warn('filter "' + name + '" not supported yet');
  39896. return stream;
  39897. } catch (ex) {
  39898. if (ex instanceof MissingDataException) {
  39899. throw ex;
  39900. }
  39901. warn('Invalid stream: \"' + ex + '\"');
  39902. return new NullStream(stream);
  39903. }
  39904. }
  39905. };
  39906. return Parser;
  39907. }();
  39908. var Lexer = function LexerClosure() {
  39909. function Lexer(stream, knownCommands) {
  39910. this.stream = stream;
  39911. this.nextChar();
  39912. // While lexing, we build up many strings one char at a time. Using += for
  39913. // this can result in lots of garbage strings. It's better to build an
  39914. // array of single-char strings and then join() them together at the end.
  39915. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  39916. // purpose uses less memory than using a new array for each string.
  39917. this.strBuf = [];
  39918. // The PDFs might have "glued" commands with other commands, operands or
  39919. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  39920. // commands and their prefixes. The prefixes are built the following way:
  39921. // if there a command that is a prefix of the other valid command or
  39922. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  39923. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  39924. // other commands or literals as a prefix. The knowCommands is optional.
  39925. this.knownCommands = knownCommands;
  39926. }
  39927. // A '1' in this array means the character is white space. A '1' or
  39928. // '2' means the character ends a name or command.
  39929. var specialChars = [
  39930. 1,
  39931. 0,
  39932. 0,
  39933. 0,
  39934. 0,
  39935. 0,
  39936. 0,
  39937. 0,
  39938. 0,
  39939. 1,
  39940. 1,
  39941. 0,
  39942. 1,
  39943. 1,
  39944. 0,
  39945. 0,
  39946. // 0x
  39947. 0,
  39948. 0,
  39949. 0,
  39950. 0,
  39951. 0,
  39952. 0,
  39953. 0,
  39954. 0,
  39955. 0,
  39956. 0,
  39957. 0,
  39958. 0,
  39959. 0,
  39960. 0,
  39961. 0,
  39962. 0,
  39963. // 1x
  39964. 1,
  39965. 0,
  39966. 0,
  39967. 0,
  39968. 0,
  39969. 2,
  39970. 0,
  39971. 0,
  39972. 2,
  39973. 2,
  39974. 0,
  39975. 0,
  39976. 0,
  39977. 0,
  39978. 0,
  39979. 2,
  39980. // 2x
  39981. 0,
  39982. 0,
  39983. 0,
  39984. 0,
  39985. 0,
  39986. 0,
  39987. 0,
  39988. 0,
  39989. 0,
  39990. 0,
  39991. 0,
  39992. 0,
  39993. 2,
  39994. 0,
  39995. 2,
  39996. 0,
  39997. // 3x
  39998. 0,
  39999. 0,
  40000. 0,
  40001. 0,
  40002. 0,
  40003. 0,
  40004. 0,
  40005. 0,
  40006. 0,
  40007. 0,
  40008. 0,
  40009. 0,
  40010. 0,
  40011. 0,
  40012. 0,
  40013. 0,
  40014. // 4x
  40015. 0,
  40016. 0,
  40017. 0,
  40018. 0,
  40019. 0,
  40020. 0,
  40021. 0,
  40022. 0,
  40023. 0,
  40024. 0,
  40025. 0,
  40026. 2,
  40027. 0,
  40028. 2,
  40029. 0,
  40030. 0,
  40031. // 5x
  40032. 0,
  40033. 0,
  40034. 0,
  40035. 0,
  40036. 0,
  40037. 0,
  40038. 0,
  40039. 0,
  40040. 0,
  40041. 0,
  40042. 0,
  40043. 0,
  40044. 0,
  40045. 0,
  40046. 0,
  40047. 0,
  40048. // 6x
  40049. 0,
  40050. 0,
  40051. 0,
  40052. 0,
  40053. 0,
  40054. 0,
  40055. 0,
  40056. 0,
  40057. 0,
  40058. 0,
  40059. 0,
  40060. 2,
  40061. 0,
  40062. 2,
  40063. 0,
  40064. 0,
  40065. // 7x
  40066. 0,
  40067. 0,
  40068. 0,
  40069. 0,
  40070. 0,
  40071. 0,
  40072. 0,
  40073. 0,
  40074. 0,
  40075. 0,
  40076. 0,
  40077. 0,
  40078. 0,
  40079. 0,
  40080. 0,
  40081. 0,
  40082. // 8x
  40083. 0,
  40084. 0,
  40085. 0,
  40086. 0,
  40087. 0,
  40088. 0,
  40089. 0,
  40090. 0,
  40091. 0,
  40092. 0,
  40093. 0,
  40094. 0,
  40095. 0,
  40096. 0,
  40097. 0,
  40098. 0,
  40099. // 9x
  40100. 0,
  40101. 0,
  40102. 0,
  40103. 0,
  40104. 0,
  40105. 0,
  40106. 0,
  40107. 0,
  40108. 0,
  40109. 0,
  40110. 0,
  40111. 0,
  40112. 0,
  40113. 0,
  40114. 0,
  40115. 0,
  40116. // ax
  40117. 0,
  40118. 0,
  40119. 0,
  40120. 0,
  40121. 0,
  40122. 0,
  40123. 0,
  40124. 0,
  40125. 0,
  40126. 0,
  40127. 0,
  40128. 0,
  40129. 0,
  40130. 0,
  40131. 0,
  40132. 0,
  40133. // bx
  40134. 0,
  40135. 0,
  40136. 0,
  40137. 0,
  40138. 0,
  40139. 0,
  40140. 0,
  40141. 0,
  40142. 0,
  40143. 0,
  40144. 0,
  40145. 0,
  40146. 0,
  40147. 0,
  40148. 0,
  40149. 0,
  40150. // cx
  40151. 0,
  40152. 0,
  40153. 0,
  40154. 0,
  40155. 0,
  40156. 0,
  40157. 0,
  40158. 0,
  40159. 0,
  40160. 0,
  40161. 0,
  40162. 0,
  40163. 0,
  40164. 0,
  40165. 0,
  40166. 0,
  40167. // dx
  40168. 0,
  40169. 0,
  40170. 0,
  40171. 0,
  40172. 0,
  40173. 0,
  40174. 0,
  40175. 0,
  40176. 0,
  40177. 0,
  40178. 0,
  40179. 0,
  40180. 0,
  40181. 0,
  40182. 0,
  40183. 0,
  40184. // ex
  40185. 0,
  40186. 0,
  40187. 0,
  40188. 0,
  40189. 0,
  40190. 0,
  40191. 0,
  40192. 0,
  40193. 0,
  40194. 0,
  40195. 0,
  40196. 0,
  40197. 0,
  40198. 0,
  40199. 0,
  40200. 0
  40201. ];
  40202. // fx
  40203. function toHexDigit(ch) {
  40204. if (ch >= 0x30 && ch <= 0x39) {
  40205. // '0'-'9'
  40206. return ch & 0x0F;
  40207. }
  40208. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  40209. // 'A'-'F', 'a'-'f'
  40210. return (ch & 0x0F) + 9;
  40211. }
  40212. return -1;
  40213. }
  40214. Lexer.prototype = {
  40215. nextChar: function Lexer_nextChar() {
  40216. return this.currentChar = this.stream.getByte();
  40217. },
  40218. peekChar: function Lexer_peekChar() {
  40219. return this.stream.peekByte();
  40220. },
  40221. getNumber: function Lexer_getNumber() {
  40222. var ch = this.currentChar;
  40223. var eNotation = false;
  40224. var divideBy = 0;
  40225. // different from 0 if it's a floating point value
  40226. var sign = 1;
  40227. if (ch === 0x2D) {
  40228. // '-'
  40229. sign = -1;
  40230. ch = this.nextChar();
  40231. if (ch === 0x2D) {
  40232. // '-'
  40233. // Ignore double negative (this is consistent with Adobe Reader).
  40234. ch = this.nextChar();
  40235. }
  40236. } else if (ch === 0x2B) {
  40237. // '+'
  40238. ch = this.nextChar();
  40239. }
  40240. if (ch === 0x2E) {
  40241. // '.'
  40242. divideBy = 10;
  40243. ch = this.nextChar();
  40244. }
  40245. if (ch < 0x30 || ch > 0x39) {
  40246. // '0' - '9'
  40247. error('Invalid number: ' + String.fromCharCode(ch));
  40248. return 0;
  40249. }
  40250. var baseValue = ch - 0x30;
  40251. // '0'
  40252. var powerValue = 0;
  40253. var powerValueSign = 1;
  40254. while ((ch = this.nextChar()) >= 0) {
  40255. if (0x30 <= ch && ch <= 0x39) {
  40256. // '0' - '9'
  40257. var currentDigit = ch - 0x30;
  40258. // '0'
  40259. if (eNotation) {
  40260. // We are after an 'e' or 'E'
  40261. powerValue = powerValue * 10 + currentDigit;
  40262. } else {
  40263. if (divideBy !== 0) {
  40264. // We are after a point
  40265. divideBy *= 10;
  40266. }
  40267. baseValue = baseValue * 10 + currentDigit;
  40268. }
  40269. } else if (ch === 0x2E) {
  40270. // '.'
  40271. if (divideBy === 0) {
  40272. divideBy = 1;
  40273. } else {
  40274. // A number can have only one '.'
  40275. break;
  40276. }
  40277. } else if (ch === 0x2D) {
  40278. // '-'
  40279. // ignore minus signs in the middle of numbers to match
  40280. // Adobe's behavior
  40281. warn('Badly formatted number');
  40282. } else if (ch === 0x45 || ch === 0x65) {
  40283. // 'E', 'e'
  40284. // 'E' can be either a scientific notation or the beginning of a new
  40285. // operator
  40286. ch = this.peekChar();
  40287. if (ch === 0x2B || ch === 0x2D) {
  40288. // '+', '-'
  40289. powerValueSign = ch === 0x2D ? -1 : 1;
  40290. this.nextChar();
  40291. } else // Consume the sign character
  40292. if (ch < 0x30 || ch > 0x39) {
  40293. // '0' - '9'
  40294. // The 'E' must be the beginning of a new operator
  40295. break;
  40296. }
  40297. eNotation = true;
  40298. } else {
  40299. // the last character doesn't belong to us
  40300. break;
  40301. }
  40302. }
  40303. if (divideBy !== 0) {
  40304. baseValue /= divideBy;
  40305. }
  40306. if (eNotation) {
  40307. baseValue *= Math.pow(10, powerValueSign * powerValue);
  40308. }
  40309. return sign * baseValue;
  40310. },
  40311. getString: function Lexer_getString() {
  40312. var numParen = 1;
  40313. var done = false;
  40314. var strBuf = this.strBuf;
  40315. strBuf.length = 0;
  40316. var ch = this.nextChar();
  40317. while (true) {
  40318. var charBuffered = false;
  40319. switch (ch | 0) {
  40320. case -1:
  40321. warn('Unterminated string');
  40322. done = true;
  40323. break;
  40324. case 0x28:
  40325. // '('
  40326. ++numParen;
  40327. strBuf.push('(');
  40328. break;
  40329. case 0x29:
  40330. // ')'
  40331. if (--numParen === 0) {
  40332. this.nextChar();
  40333. // consume strings ')'
  40334. done = true;
  40335. } else {
  40336. strBuf.push(')');
  40337. }
  40338. break;
  40339. case 0x5C:
  40340. // '\\'
  40341. ch = this.nextChar();
  40342. switch (ch) {
  40343. case -1:
  40344. warn('Unterminated string');
  40345. done = true;
  40346. break;
  40347. case 0x6E:
  40348. // 'n'
  40349. strBuf.push('\n');
  40350. break;
  40351. case 0x72:
  40352. // 'r'
  40353. strBuf.push('\r');
  40354. break;
  40355. case 0x74:
  40356. // 't'
  40357. strBuf.push('\t');
  40358. break;
  40359. case 0x62:
  40360. // 'b'
  40361. strBuf.push('\b');
  40362. break;
  40363. case 0x66:
  40364. // 'f'
  40365. strBuf.push('\f');
  40366. break;
  40367. case 0x5C:
  40368. // '\'
  40369. case 0x28:
  40370. // '('
  40371. case 0x29:
  40372. // ')'
  40373. strBuf.push(String.fromCharCode(ch));
  40374. break;
  40375. case 0x30:
  40376. case 0x31:
  40377. case 0x32:
  40378. case 0x33:
  40379. // '0'-'3'
  40380. case 0x34:
  40381. case 0x35:
  40382. case 0x36:
  40383. case 0x37:
  40384. // '4'-'7'
  40385. var x = ch & 0x0F;
  40386. ch = this.nextChar();
  40387. charBuffered = true;
  40388. if (ch >= 0x30 && ch <= 0x37) {
  40389. // '0'-'7'
  40390. x = (x << 3) + (ch & 0x0F);
  40391. ch = this.nextChar();
  40392. if (ch >= 0x30 && ch <= 0x37) {
  40393. // '0'-'7'
  40394. charBuffered = false;
  40395. x = (x << 3) + (ch & 0x0F);
  40396. }
  40397. }
  40398. strBuf.push(String.fromCharCode(x));
  40399. break;
  40400. case 0x0D:
  40401. // CR
  40402. if (this.peekChar() === 0x0A) {
  40403. // LF
  40404. this.nextChar();
  40405. }
  40406. break;
  40407. case 0x0A:
  40408. // LF
  40409. break;
  40410. default:
  40411. strBuf.push(String.fromCharCode(ch));
  40412. break;
  40413. }
  40414. break;
  40415. default:
  40416. strBuf.push(String.fromCharCode(ch));
  40417. break;
  40418. }
  40419. if (done) {
  40420. break;
  40421. }
  40422. if (!charBuffered) {
  40423. ch = this.nextChar();
  40424. }
  40425. }
  40426. return strBuf.join('');
  40427. },
  40428. getName: function Lexer_getName() {
  40429. var ch, previousCh;
  40430. var strBuf = this.strBuf;
  40431. strBuf.length = 0;
  40432. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  40433. if (ch === 0x23) {
  40434. // '#'
  40435. ch = this.nextChar();
  40436. if (specialChars[ch]) {
  40437. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  40438. strBuf.push('#');
  40439. break;
  40440. }
  40441. var x = toHexDigit(ch);
  40442. if (x !== -1) {
  40443. previousCh = ch;
  40444. ch = this.nextChar();
  40445. var x2 = toHexDigit(ch);
  40446. if (x2 === -1) {
  40447. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  40448. strBuf.push('#', String.fromCharCode(previousCh));
  40449. if (specialChars[ch]) {
  40450. break;
  40451. }
  40452. strBuf.push(String.fromCharCode(ch));
  40453. continue;
  40454. }
  40455. strBuf.push(String.fromCharCode(x << 4 | x2));
  40456. } else {
  40457. strBuf.push('#', String.fromCharCode(ch));
  40458. }
  40459. } else {
  40460. strBuf.push(String.fromCharCode(ch));
  40461. }
  40462. }
  40463. if (strBuf.length > 127) {
  40464. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  40465. }
  40466. return Name.get(strBuf.join(''));
  40467. },
  40468. getHexString: function Lexer_getHexString() {
  40469. var strBuf = this.strBuf;
  40470. strBuf.length = 0;
  40471. var ch = this.currentChar;
  40472. var isFirstHex = true;
  40473. var firstDigit;
  40474. var secondDigit;
  40475. while (true) {
  40476. if (ch < 0) {
  40477. warn('Unterminated hex string');
  40478. break;
  40479. } else if (ch === 0x3E) {
  40480. // '>'
  40481. this.nextChar();
  40482. break;
  40483. } else if (specialChars[ch] === 1) {
  40484. ch = this.nextChar();
  40485. continue;
  40486. } else {
  40487. if (isFirstHex) {
  40488. firstDigit = toHexDigit(ch);
  40489. if (firstDigit === -1) {
  40490. warn('Ignoring invalid character "' + ch + '" in hex string');
  40491. ch = this.nextChar();
  40492. continue;
  40493. }
  40494. } else {
  40495. secondDigit = toHexDigit(ch);
  40496. if (secondDigit === -1) {
  40497. warn('Ignoring invalid character "' + ch + '" in hex string');
  40498. ch = this.nextChar();
  40499. continue;
  40500. }
  40501. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  40502. }
  40503. isFirstHex = !isFirstHex;
  40504. ch = this.nextChar();
  40505. }
  40506. }
  40507. return strBuf.join('');
  40508. },
  40509. getObj: function Lexer_getObj() {
  40510. // skip whitespace and comments
  40511. var comment = false;
  40512. var ch = this.currentChar;
  40513. while (true) {
  40514. if (ch < 0) {
  40515. return EOF;
  40516. }
  40517. if (comment) {
  40518. if (ch === 0x0A || ch === 0x0D) {
  40519. // LF, CR
  40520. comment = false;
  40521. }
  40522. } else if (ch === 0x25) {
  40523. // '%'
  40524. comment = true;
  40525. } else if (specialChars[ch] !== 1) {
  40526. break;
  40527. }
  40528. ch = this.nextChar();
  40529. }
  40530. // start reading token
  40531. switch (ch | 0) {
  40532. case 0x30:
  40533. case 0x31:
  40534. case 0x32:
  40535. case 0x33:
  40536. case 0x34:
  40537. // '0'-'4'
  40538. case 0x35:
  40539. case 0x36:
  40540. case 0x37:
  40541. case 0x38:
  40542. case 0x39:
  40543. // '5'-'9'
  40544. case 0x2B:
  40545. case 0x2D:
  40546. case 0x2E:
  40547. // '+', '-', '.'
  40548. return this.getNumber();
  40549. case 0x28:
  40550. // '('
  40551. return this.getString();
  40552. case 0x2F:
  40553. // '/'
  40554. return this.getName();
  40555. // array punctuation
  40556. case 0x5B:
  40557. // '['
  40558. this.nextChar();
  40559. return Cmd.get('[');
  40560. case 0x5D:
  40561. // ']'
  40562. this.nextChar();
  40563. return Cmd.get(']');
  40564. // hex string or dict punctuation
  40565. case 0x3C:
  40566. // '<'
  40567. ch = this.nextChar();
  40568. if (ch === 0x3C) {
  40569. // dict punctuation
  40570. this.nextChar();
  40571. return Cmd.get('<<');
  40572. }
  40573. return this.getHexString();
  40574. // dict punctuation
  40575. case 0x3E:
  40576. // '>'
  40577. ch = this.nextChar();
  40578. if (ch === 0x3E) {
  40579. this.nextChar();
  40580. return Cmd.get('>>');
  40581. }
  40582. return Cmd.get('>');
  40583. case 0x7B:
  40584. // '{'
  40585. this.nextChar();
  40586. return Cmd.get('{');
  40587. case 0x7D:
  40588. // '}'
  40589. this.nextChar();
  40590. return Cmd.get('}');
  40591. case 0x29:
  40592. // ')'
  40593. error('Illegal character: ' + ch);
  40594. break;
  40595. }
  40596. // command
  40597. var str = String.fromCharCode(ch);
  40598. var knownCommands = this.knownCommands;
  40599. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  40600. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  40601. // stop if known command is found and next character does not make
  40602. // the str a command
  40603. var possibleCommand = str + String.fromCharCode(ch);
  40604. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  40605. break;
  40606. }
  40607. if (str.length === 128) {
  40608. error('Command token too long: ' + str.length);
  40609. }
  40610. str = possibleCommand;
  40611. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  40612. }
  40613. if (str === 'true') {
  40614. return true;
  40615. }
  40616. if (str === 'false') {
  40617. return false;
  40618. }
  40619. if (str === 'null') {
  40620. return null;
  40621. }
  40622. return Cmd.get(str);
  40623. },
  40624. skipToNextLine: function Lexer_skipToNextLine() {
  40625. var ch = this.currentChar;
  40626. while (ch >= 0) {
  40627. if (ch === 0x0D) {
  40628. // CR
  40629. ch = this.nextChar();
  40630. if (ch === 0x0A) {
  40631. // LF
  40632. this.nextChar();
  40633. }
  40634. break;
  40635. } else if (ch === 0x0A) {
  40636. // LF
  40637. this.nextChar();
  40638. break;
  40639. }
  40640. ch = this.nextChar();
  40641. }
  40642. }
  40643. };
  40644. return Lexer;
  40645. }();
  40646. var Linearization = {
  40647. create: function LinearizationCreate(stream) {
  40648. function getInt(name, allowZeroValue) {
  40649. var obj = linDict.get(name);
  40650. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  40651. return obj;
  40652. }
  40653. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  40654. }
  40655. function getHints() {
  40656. var hints = linDict.get('H'), hintsLength, item;
  40657. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  40658. for (var index = 0; index < hintsLength; index++) {
  40659. if (!(isInt(item = hints[index]) && item > 0)) {
  40660. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  40661. }
  40662. }
  40663. return hints;
  40664. }
  40665. throw new Error('Hint array in the linearization dictionary is invalid.');
  40666. }
  40667. var parser = new Parser(new Lexer(stream), false, null);
  40668. var obj1 = parser.getObj();
  40669. var obj2 = parser.getObj();
  40670. var obj3 = parser.getObj();
  40671. var linDict = parser.getObj();
  40672. var obj, length;
  40673. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  40674. return null;
  40675. } else // No valid linearization dictionary found.
  40676. if ((length = getInt('L')) !== stream.length) {
  40677. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  40678. }
  40679. return {
  40680. length: length,
  40681. hints: getHints(),
  40682. objectNumberFirst: getInt('O'),
  40683. endFirst: getInt('E'),
  40684. numPages: getInt('N'),
  40685. mainXRefEntriesOffset: getInt('T'),
  40686. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  40687. };
  40688. }
  40689. };
  40690. exports.EOF = EOF;
  40691. exports.Lexer = Lexer;
  40692. exports.Linearization = Linearization;
  40693. exports.Parser = Parser;
  40694. exports.isEOF = isEOF;
  40695. }));
  40696. (function (root, factory) {
  40697. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  40698. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  40699. var warn = sharedUtil.warn;
  40700. var isSpace = sharedUtil.isSpace;
  40701. var Stream = coreStream.Stream;
  40702. var getEncoding = coreEncodings.getEncoding;
  40703. // Hinting is currently disabled due to unknown problems on windows
  40704. // in tracemonkey and various other pdfs with type1 fonts.
  40705. var HINTING_ENABLED = false;
  40706. /*
  40707. * CharStrings are encoded following the the CharString Encoding sequence
  40708. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  40709. * The value in a byte indicates a command, a number, or subsequent bytes
  40710. * that are to be interpreted in a special way.
  40711. *
  40712. * CharString Number Encoding:
  40713. * A CharString byte containing the values from 32 through 255 inclusive
  40714. * indicate an integer. These values are decoded in four ranges.
  40715. *
  40716. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  40717. * indicate the integer v - 139. Thus, the integer values from -107 through
  40718. * 107 inclusive may be encoded in single byte.
  40719. *
  40720. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  40721. * indicates an integer involving the next byte, w, according to the formula:
  40722. * [(v - 247) x 256] + w + 108
  40723. *
  40724. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  40725. * indicates an integer involving the next byte, w, according to the formula:
  40726. * -[(v - 251) * 256] - w - 108
  40727. *
  40728. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  40729. * are a two complement signed integer. The first of these bytes contains the
  40730. * highest order bits, the second byte contains the next higher order bits
  40731. * and the fourth byte contain the lowest order bits.
  40732. *
  40733. *
  40734. * CharString Command Encoding:
  40735. * CharStrings commands are encoded in 1 or 2 bytes.
  40736. *
  40737. * Single byte commands are encoded in 1 byte that contains a value between
  40738. * 0 and 31 inclusive.
  40739. * If a command byte contains the value 12, then the value in the next byte
  40740. * indicates a command. This "escape" mechanism allows many extra commands
  40741. * to be encoded and this encoding technique helps to minimize the length of
  40742. * the charStrings.
  40743. */
  40744. var Type1CharString = function Type1CharStringClosure() {
  40745. var COMMAND_MAP = {
  40746. 'hstem': [1],
  40747. 'vstem': [3],
  40748. 'vmoveto': [4],
  40749. 'rlineto': [5],
  40750. 'hlineto': [6],
  40751. 'vlineto': [7],
  40752. 'rrcurveto': [8],
  40753. 'callsubr': [10],
  40754. 'flex': [
  40755. 12,
  40756. 35
  40757. ],
  40758. 'drop': [
  40759. 12,
  40760. 18
  40761. ],
  40762. 'endchar': [14],
  40763. 'rmoveto': [21],
  40764. 'hmoveto': [22],
  40765. 'vhcurveto': [30],
  40766. 'hvcurveto': [31]
  40767. };
  40768. function Type1CharString() {
  40769. this.width = 0;
  40770. this.lsb = 0;
  40771. this.flexing = false;
  40772. this.output = [];
  40773. this.stack = [];
  40774. }
  40775. Type1CharString.prototype = {
  40776. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  40777. var count = encoded.length;
  40778. var error = false;
  40779. var wx, sbx, subrNumber;
  40780. for (var i = 0; i < count; i++) {
  40781. var value = encoded[i];
  40782. if (value < 32) {
  40783. if (value === 12) {
  40784. value = (value << 8) + encoded[++i];
  40785. }
  40786. switch (value) {
  40787. case 1:
  40788. // hstem
  40789. if (!HINTING_ENABLED) {
  40790. this.stack = [];
  40791. break;
  40792. }
  40793. error = this.executeCommand(2, COMMAND_MAP.hstem);
  40794. break;
  40795. case 3:
  40796. // vstem
  40797. if (!HINTING_ENABLED) {
  40798. this.stack = [];
  40799. break;
  40800. }
  40801. error = this.executeCommand(2, COMMAND_MAP.vstem);
  40802. break;
  40803. case 4:
  40804. // vmoveto
  40805. if (this.flexing) {
  40806. if (this.stack.length < 1) {
  40807. error = true;
  40808. break;
  40809. }
  40810. // Add the dx for flex and but also swap the values so they are
  40811. // the right order.
  40812. var dy = this.stack.pop();
  40813. this.stack.push(0, dy);
  40814. break;
  40815. }
  40816. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  40817. break;
  40818. case 5:
  40819. // rlineto
  40820. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  40821. break;
  40822. case 6:
  40823. // hlineto
  40824. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  40825. break;
  40826. case 7:
  40827. // vlineto
  40828. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  40829. break;
  40830. case 8:
  40831. // rrcurveto
  40832. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  40833. break;
  40834. case 9:
  40835. // closepath
  40836. // closepath is a Type1 command that does not take argument and is
  40837. // useless in Type2 and it can simply be ignored.
  40838. this.stack = [];
  40839. break;
  40840. case 10:
  40841. // callsubr
  40842. if (this.stack.length < 1) {
  40843. error = true;
  40844. break;
  40845. }
  40846. subrNumber = this.stack.pop();
  40847. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  40848. break;
  40849. case 11:
  40850. // return
  40851. return error;
  40852. case 13:
  40853. // hsbw
  40854. if (this.stack.length < 2) {
  40855. error = true;
  40856. break;
  40857. }
  40858. // To convert to type2 we have to move the width value to the
  40859. // first part of the charstring and then use hmoveto with lsb.
  40860. wx = this.stack.pop();
  40861. sbx = this.stack.pop();
  40862. this.lsb = sbx;
  40863. this.width = wx;
  40864. this.stack.push(wx, sbx);
  40865. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  40866. break;
  40867. case 14:
  40868. // endchar
  40869. this.output.push(COMMAND_MAP.endchar[0]);
  40870. break;
  40871. case 21:
  40872. // rmoveto
  40873. if (this.flexing) {
  40874. break;
  40875. }
  40876. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  40877. break;
  40878. case 22:
  40879. // hmoveto
  40880. if (this.flexing) {
  40881. // Add the dy for flex.
  40882. this.stack.push(0);
  40883. break;
  40884. }
  40885. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  40886. break;
  40887. case 30:
  40888. // vhcurveto
  40889. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  40890. break;
  40891. case 31:
  40892. // hvcurveto
  40893. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  40894. break;
  40895. case (12 << 8) + 0:
  40896. // dotsection
  40897. // dotsection is a Type1 command to specify some hinting feature
  40898. // for dots that do not take a parameter and it can safely be
  40899. // ignored for Type2.
  40900. this.stack = [];
  40901. break;
  40902. case (12 << 8) + 1:
  40903. // vstem3
  40904. if (!HINTING_ENABLED) {
  40905. this.stack = [];
  40906. break;
  40907. }
  40908. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  40909. // multiple parameters, so instead of returning [vh]stem3 take a
  40910. // shortcut and return [vhstem] instead.
  40911. error = this.executeCommand(2, COMMAND_MAP.vstem);
  40912. break;
  40913. case (12 << 8) + 2:
  40914. // hstem3
  40915. if (!HINTING_ENABLED) {
  40916. this.stack = [];
  40917. break;
  40918. }
  40919. // See vstem3.
  40920. error = this.executeCommand(2, COMMAND_MAP.hstem);
  40921. break;
  40922. case (12 << 8) + 6:
  40923. // seac
  40924. // seac is like type 2's special endchar but it doesn't use the
  40925. // first argument asb, so remove it.
  40926. if (seacAnalysisEnabled) {
  40927. this.seac = this.stack.splice(-4, 4);
  40928. error = this.executeCommand(0, COMMAND_MAP.endchar);
  40929. } else {
  40930. error = this.executeCommand(4, COMMAND_MAP.endchar);
  40931. }
  40932. break;
  40933. case (12 << 8) + 7:
  40934. // sbw
  40935. if (this.stack.length < 4) {
  40936. error = true;
  40937. break;
  40938. }
  40939. // To convert to type2 we have to move the width value to the
  40940. // first part of the charstring and then use rmoveto with
  40941. // (dx, dy). The height argument will not be used for vmtx and
  40942. // vhea tables reconstruction -- ignoring it.
  40943. var wy = this.stack.pop();
  40944. wx = this.stack.pop();
  40945. var sby = this.stack.pop();
  40946. sbx = this.stack.pop();
  40947. this.lsb = sbx;
  40948. this.width = wx;
  40949. this.stack.push(wx, sbx, sby);
  40950. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  40951. break;
  40952. case (12 << 8) + 12:
  40953. // div
  40954. if (this.stack.length < 2) {
  40955. error = true;
  40956. break;
  40957. }
  40958. var num2 = this.stack.pop();
  40959. var num1 = this.stack.pop();
  40960. this.stack.push(num1 / num2);
  40961. break;
  40962. case (12 << 8) + 16:
  40963. // callothersubr
  40964. if (this.stack.length < 2) {
  40965. error = true;
  40966. break;
  40967. }
  40968. subrNumber = this.stack.pop();
  40969. var numArgs = this.stack.pop();
  40970. if (subrNumber === 0 && numArgs === 3) {
  40971. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  40972. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  40973. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  40974. flexArgs[4], // bcp2x
  40975. flexArgs[5], // bcp2y
  40976. flexArgs[6], // p2x
  40977. flexArgs[7], // p2y
  40978. flexArgs[8], // bcp3x
  40979. flexArgs[9], // bcp3y
  40980. flexArgs[10], // bcp4x
  40981. flexArgs[11], // bcp4y
  40982. flexArgs[12], // p3x
  40983. flexArgs[13], // p3y
  40984. flexArgs[14]);
  40985. // flexDepth
  40986. // 15 = finalx unused by flex
  40987. // 16 = finaly unused by flex
  40988. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  40989. this.flexing = false;
  40990. this.stack.push(flexArgs[15], flexArgs[16]);
  40991. } else if (subrNumber === 1 && numArgs === 0) {
  40992. this.flexing = true;
  40993. }
  40994. break;
  40995. case (12 << 8) + 17:
  40996. // pop
  40997. // Ignore this since it is only used with othersubr.
  40998. break;
  40999. case (12 << 8) + 33:
  41000. // setcurrentpoint
  41001. // Ignore for now.
  41002. this.stack = [];
  41003. break;
  41004. default:
  41005. warn('Unknown type 1 charstring command of "' + value + '"');
  41006. break;
  41007. }
  41008. if (error) {
  41009. break;
  41010. }
  41011. continue;
  41012. } else if (value <= 246) {
  41013. value = value - 139;
  41014. } else if (value <= 250) {
  41015. value = (value - 247) * 256 + encoded[++i] + 108;
  41016. } else if (value <= 254) {
  41017. value = -((value - 251) * 256) - encoded[++i] - 108;
  41018. } else {
  41019. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  41020. }
  41021. this.stack.push(value);
  41022. }
  41023. return error;
  41024. },
  41025. executeCommand: function (howManyArgs, command, keepStack) {
  41026. var stackLength = this.stack.length;
  41027. if (howManyArgs > stackLength) {
  41028. return true;
  41029. }
  41030. var start = stackLength - howManyArgs;
  41031. for (var i = start; i < stackLength; i++) {
  41032. var value = this.stack[i];
  41033. if (value === (value | 0)) {
  41034. // int
  41035. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  41036. } else {
  41037. // fixed point
  41038. value = 65536 * value | 0;
  41039. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  41040. }
  41041. }
  41042. this.output.push.apply(this.output, command);
  41043. if (keepStack) {
  41044. this.stack.splice(start, howManyArgs);
  41045. } else {
  41046. this.stack.length = 0;
  41047. }
  41048. return false;
  41049. }
  41050. };
  41051. return Type1CharString;
  41052. }();
  41053. /*
  41054. * Type1Parser encapsulate the needed code for parsing a Type1 font
  41055. * program. Some of its logic depends on the Type2 charstrings
  41056. * structure.
  41057. * Note: this doesn't really parse the font since that would require evaluation
  41058. * of PostScript, but it is possible in most cases to extract what we need
  41059. * without a full parse.
  41060. */
  41061. var Type1Parser = function Type1ParserClosure() {
  41062. /*
  41063. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  41064. * of Plaintext Bytes. The function took a key as a parameter which can be
  41065. * for decrypting the eexec block of for decoding charStrings.
  41066. */
  41067. var EEXEC_ENCRYPT_KEY = 55665;
  41068. var CHAR_STRS_ENCRYPT_KEY = 4330;
  41069. function isHexDigit(code) {
  41070. return code >= 48 && code <= 57 || // '0'-'9'
  41071. code >= 65 && code <= 70 || // 'A'-'F'
  41072. code >= 97 && code <= 102;
  41073. }
  41074. // 'a'-'f'
  41075. function decrypt(data, key, discardNumber) {
  41076. if (discardNumber >= data.length) {
  41077. return new Uint8Array(0);
  41078. }
  41079. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  41080. for (i = 0; i < discardNumber; i++) {
  41081. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  41082. }
  41083. var count = data.length - discardNumber;
  41084. var decrypted = new Uint8Array(count);
  41085. for (i = discardNumber, j = 0; j < count; i++, j++) {
  41086. var value = data[i];
  41087. decrypted[j] = value ^ r >> 8;
  41088. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  41089. }
  41090. return decrypted;
  41091. }
  41092. function decryptAscii(data, key, discardNumber) {
  41093. var r = key | 0, c1 = 52845, c2 = 22719;
  41094. var count = data.length, maybeLength = count >>> 1;
  41095. var decrypted = new Uint8Array(maybeLength);
  41096. var i, j;
  41097. for (i = 0, j = 0; i < count; i++) {
  41098. var digit1 = data[i];
  41099. if (!isHexDigit(digit1)) {
  41100. continue;
  41101. }
  41102. i++;
  41103. var digit2;
  41104. while (i < count && !isHexDigit(digit2 = data[i])) {
  41105. i++;
  41106. }
  41107. if (i < count) {
  41108. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  41109. decrypted[j++] = value ^ r >> 8;
  41110. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  41111. }
  41112. }
  41113. return Array.prototype.slice.call(decrypted, discardNumber, j);
  41114. }
  41115. function isSpecial(c) {
  41116. return c === 0x2F || // '/'
  41117. c === 0x5B || c === 0x5D || // '[', ']'
  41118. c === 0x7B || c === 0x7D || // '{', '}'
  41119. c === 0x28 || c === 0x29;
  41120. }
  41121. // '(', ')'
  41122. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  41123. if (encrypted) {
  41124. var data = stream.getBytes();
  41125. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  41126. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  41127. }
  41128. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  41129. this.stream = stream;
  41130. this.nextChar();
  41131. }
  41132. Type1Parser.prototype = {
  41133. readNumberArray: function Type1Parser_readNumberArray() {
  41134. this.getToken();
  41135. // read '[' or '{' (arrays can start with either)
  41136. var array = [];
  41137. while (true) {
  41138. var token = this.getToken();
  41139. if (token === null || token === ']' || token === '}') {
  41140. break;
  41141. }
  41142. array.push(parseFloat(token || 0));
  41143. }
  41144. return array;
  41145. },
  41146. readNumber: function Type1Parser_readNumber() {
  41147. var token = this.getToken();
  41148. return parseFloat(token || 0);
  41149. },
  41150. readInt: function Type1Parser_readInt() {
  41151. // Use '| 0' to prevent setting a double into length such as the double
  41152. // does not flow into the loop variable.
  41153. var token = this.getToken();
  41154. return parseInt(token || 0, 10) | 0;
  41155. },
  41156. readBoolean: function Type1Parser_readBoolean() {
  41157. var token = this.getToken();
  41158. // Use 1 and 0 since that's what type2 charstrings use.
  41159. return token === 'true' ? 1 : 0;
  41160. },
  41161. nextChar: function Type1_nextChar() {
  41162. return this.currentChar = this.stream.getByte();
  41163. },
  41164. getToken: function Type1Parser_getToken() {
  41165. // Eat whitespace and comments.
  41166. var comment = false;
  41167. var ch = this.currentChar;
  41168. while (true) {
  41169. if (ch === -1) {
  41170. return null;
  41171. }
  41172. if (comment) {
  41173. if (ch === 0x0A || ch === 0x0D) {
  41174. comment = false;
  41175. }
  41176. } else if (ch === 0x25) {
  41177. // '%'
  41178. comment = true;
  41179. } else if (!isSpace(ch)) {
  41180. break;
  41181. }
  41182. ch = this.nextChar();
  41183. }
  41184. if (isSpecial(ch)) {
  41185. this.nextChar();
  41186. return String.fromCharCode(ch);
  41187. }
  41188. var token = '';
  41189. do {
  41190. token += String.fromCharCode(ch);
  41191. ch = this.nextChar();
  41192. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  41193. return token;
  41194. },
  41195. /*
  41196. * Returns an object containing a Subrs array and a CharStrings
  41197. * array extracted from and eexec encrypted block of data
  41198. */
  41199. extractFontProgram: function Type1Parser_extractFontProgram() {
  41200. var stream = this.stream;
  41201. var subrs = [], charstrings = [];
  41202. var privateData = Object.create(null);
  41203. privateData['lenIV'] = 4;
  41204. var program = {
  41205. subrs: [],
  41206. charstrings: [],
  41207. properties: { 'privateData': privateData }
  41208. };
  41209. var token, length, data, lenIV, encoded;
  41210. while ((token = this.getToken()) !== null) {
  41211. if (token !== '/') {
  41212. continue;
  41213. }
  41214. token = this.getToken();
  41215. switch (token) {
  41216. case 'CharStrings':
  41217. // The number immediately following CharStrings must be greater or
  41218. // equal to the number of CharStrings.
  41219. this.getToken();
  41220. this.getToken();
  41221. // read in 'dict'
  41222. this.getToken();
  41223. // read in 'dup'
  41224. this.getToken();
  41225. // read in 'begin'
  41226. while (true) {
  41227. token = this.getToken();
  41228. if (token === null || token === 'end') {
  41229. break;
  41230. }
  41231. if (token !== '/') {
  41232. continue;
  41233. }
  41234. var glyph = this.getToken();
  41235. length = this.readInt();
  41236. this.getToken();
  41237. // read in 'RD' or '-|'
  41238. data = stream.makeSubStream(stream.pos, length);
  41239. lenIV = program.properties.privateData['lenIV'];
  41240. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  41241. // Skip past the required space and binary data.
  41242. stream.skip(length);
  41243. this.nextChar();
  41244. token = this.getToken();
  41245. // read in 'ND' or '|-'
  41246. if (token === 'noaccess') {
  41247. this.getToken();
  41248. }
  41249. // read in 'def'
  41250. charstrings.push({
  41251. glyph: glyph,
  41252. encoded: encoded
  41253. });
  41254. }
  41255. break;
  41256. case 'Subrs':
  41257. var num = this.readInt();
  41258. this.getToken();
  41259. // read in 'array'
  41260. while ((token = this.getToken()) === 'dup') {
  41261. var index = this.readInt();
  41262. length = this.readInt();
  41263. this.getToken();
  41264. // read in 'RD' or '-|'
  41265. data = stream.makeSubStream(stream.pos, length);
  41266. lenIV = program.properties.privateData['lenIV'];
  41267. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  41268. // Skip past the required space and binary data.
  41269. stream.skip(length);
  41270. this.nextChar();
  41271. token = this.getToken();
  41272. // read in 'NP' or '|'
  41273. if (token === 'noaccess') {
  41274. this.getToken();
  41275. }
  41276. // read in 'put'
  41277. subrs[index] = encoded;
  41278. }
  41279. break;
  41280. case 'BlueValues':
  41281. case 'OtherBlues':
  41282. case 'FamilyBlues':
  41283. case 'FamilyOtherBlues':
  41284. var blueArray = this.readNumberArray();
  41285. // *Blue* values may contain invalid data: disables reading of
  41286. // those values when hinting is disabled.
  41287. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  41288. program.properties.privateData[token] = blueArray;
  41289. }
  41290. break;
  41291. case 'StemSnapH':
  41292. case 'StemSnapV':
  41293. program.properties.privateData[token] = this.readNumberArray();
  41294. break;
  41295. case 'StdHW':
  41296. case 'StdVW':
  41297. program.properties.privateData[token] = this.readNumberArray()[0];
  41298. break;
  41299. case 'BlueShift':
  41300. case 'lenIV':
  41301. case 'BlueFuzz':
  41302. case 'BlueScale':
  41303. case 'LanguageGroup':
  41304. case 'ExpansionFactor':
  41305. program.properties.privateData[token] = this.readNumber();
  41306. break;
  41307. case 'ForceBold':
  41308. program.properties.privateData[token] = this.readBoolean();
  41309. break;
  41310. }
  41311. }
  41312. for (var i = 0; i < charstrings.length; i++) {
  41313. glyph = charstrings[i].glyph;
  41314. encoded = charstrings[i].encoded;
  41315. var charString = new Type1CharString();
  41316. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  41317. var output = charString.output;
  41318. if (error) {
  41319. // It seems when FreeType encounters an error while evaluating a glyph
  41320. // that it completely ignores the glyph so we'll mimic that behaviour
  41321. // here and put an endchar to make the validator happy.
  41322. output = [14];
  41323. }
  41324. program.charstrings.push({
  41325. glyphName: glyph,
  41326. charstring: output,
  41327. width: charString.width,
  41328. lsb: charString.lsb,
  41329. seac: charString.seac
  41330. });
  41331. }
  41332. return program;
  41333. },
  41334. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  41335. var token;
  41336. while ((token = this.getToken()) !== null) {
  41337. if (token !== '/') {
  41338. continue;
  41339. }
  41340. token = this.getToken();
  41341. switch (token) {
  41342. case 'FontMatrix':
  41343. var matrix = this.readNumberArray();
  41344. properties.fontMatrix = matrix;
  41345. break;
  41346. case 'Encoding':
  41347. var encodingArg = this.getToken();
  41348. var encoding;
  41349. if (!/^\d+$/.test(encodingArg)) {
  41350. // encoding name is specified
  41351. encoding = getEncoding(encodingArg);
  41352. } else {
  41353. encoding = [];
  41354. var size = parseInt(encodingArg, 10) | 0;
  41355. this.getToken();
  41356. // read in 'array'
  41357. for (var j = 0; j < size; j++) {
  41358. token = this.getToken();
  41359. // skipping till first dup or def (e.g. ignoring for statement)
  41360. while (token !== 'dup' && token !== 'def') {
  41361. token = this.getToken();
  41362. if (token === null) {
  41363. return;
  41364. }
  41365. }
  41366. // invalid header
  41367. if (token === 'def') {
  41368. break;
  41369. }
  41370. // read all array data
  41371. var index = this.readInt();
  41372. this.getToken();
  41373. // read in '/'
  41374. var glyph = this.getToken();
  41375. encoding[index] = glyph;
  41376. this.getToken();
  41377. }
  41378. }
  41379. // read the in 'put'
  41380. properties.builtInEncoding = encoding;
  41381. break;
  41382. case 'FontBBox':
  41383. var fontBBox = this.readNumberArray();
  41384. // adjusting ascent/descent
  41385. properties.ascent = fontBBox[3];
  41386. properties.descent = fontBBox[1];
  41387. properties.ascentScaled = true;
  41388. break;
  41389. }
  41390. }
  41391. }
  41392. };
  41393. return Type1Parser;
  41394. }();
  41395. exports.Type1Parser = Type1Parser;
  41396. }));
  41397. (function (root, factory) {
  41398. factory(root.pdfjsDisplayPatternHelper = {}, root.pdfjsSharedUtil, root.pdfjsDisplayWebGL);
  41399. }(this, function (exports, sharedUtil, displayWebGL) {
  41400. var Util = sharedUtil.Util;
  41401. var info = sharedUtil.info;
  41402. var isArray = sharedUtil.isArray;
  41403. var error = sharedUtil.error;
  41404. var WebGLUtils = displayWebGL.WebGLUtils;
  41405. var ShadingIRs = {};
  41406. ShadingIRs.RadialAxial = {
  41407. fromIR: function RadialAxial_fromIR(raw) {
  41408. var type = raw[1];
  41409. var colorStops = raw[2];
  41410. var p0 = raw[3];
  41411. var p1 = raw[4];
  41412. var r0 = raw[5];
  41413. var r1 = raw[6];
  41414. return {
  41415. type: 'Pattern',
  41416. getPattern: function RadialAxial_getPattern(ctx) {
  41417. var grad;
  41418. if (type === 'axial') {
  41419. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  41420. } else if (type === 'radial') {
  41421. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  41422. }
  41423. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  41424. var c = colorStops[i];
  41425. grad.addColorStop(c[0], c[1]);
  41426. }
  41427. return grad;
  41428. }
  41429. };
  41430. }
  41431. };
  41432. var createMeshCanvas = function createMeshCanvasClosure() {
  41433. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  41434. // Very basic Gouraud-shaded triangle rasterization algorithm.
  41435. var coords = context.coords, colors = context.colors;
  41436. var bytes = data.data, rowSize = data.width * 4;
  41437. var tmp;
  41438. if (coords[p1 + 1] > coords[p2 + 1]) {
  41439. tmp = p1;
  41440. p1 = p2;
  41441. p2 = tmp;
  41442. tmp = c1;
  41443. c1 = c2;
  41444. c2 = tmp;
  41445. }
  41446. if (coords[p2 + 1] > coords[p3 + 1]) {
  41447. tmp = p2;
  41448. p2 = p3;
  41449. p3 = tmp;
  41450. tmp = c2;
  41451. c2 = c3;
  41452. c3 = tmp;
  41453. }
  41454. if (coords[p1 + 1] > coords[p2 + 1]) {
  41455. tmp = p1;
  41456. p1 = p2;
  41457. p2 = tmp;
  41458. tmp = c1;
  41459. c1 = c2;
  41460. c2 = tmp;
  41461. }
  41462. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  41463. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  41464. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  41465. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  41466. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  41467. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  41468. if (y1 >= y3) {
  41469. return;
  41470. }
  41471. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  41472. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  41473. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  41474. var minY = Math.round(y1), maxY = Math.round(y3);
  41475. var xa, car, cag, cab;
  41476. var xb, cbr, cbg, cbb;
  41477. var k;
  41478. for (var y = minY; y <= maxY; y++) {
  41479. if (y < y2) {
  41480. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  41481. xa = x1 - (x1 - x2) * k;
  41482. car = c1r - (c1r - c2r) * k;
  41483. cag = c1g - (c1g - c2g) * k;
  41484. cab = c1b - (c1b - c2b) * k;
  41485. } else {
  41486. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  41487. xa = x2 - (x2 - x3) * k;
  41488. car = c2r - (c2r - c3r) * k;
  41489. cag = c2g - (c2g - c3g) * k;
  41490. cab = c2b - (c2b - c3b) * k;
  41491. }
  41492. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  41493. xb = x1 - (x1 - x3) * k;
  41494. cbr = c1r - (c1r - c3r) * k;
  41495. cbg = c1g - (c1g - c3g) * k;
  41496. cbb = c1b - (c1b - c3b) * k;
  41497. var x1_ = Math.round(Math.min(xa, xb));
  41498. var x2_ = Math.round(Math.max(xa, xb));
  41499. var j = rowSize * y + x1_ * 4;
  41500. for (var x = x1_; x <= x2_; x++) {
  41501. k = (xa - x) / (xa - xb);
  41502. k = k < 0 ? 0 : k > 1 ? 1 : k;
  41503. bytes[j++] = car - (car - cbr) * k | 0;
  41504. bytes[j++] = cag - (cag - cbg) * k | 0;
  41505. bytes[j++] = cab - (cab - cbb) * k | 0;
  41506. bytes[j++] = 255;
  41507. }
  41508. }
  41509. }
  41510. function drawFigure(data, figure, context) {
  41511. var ps = figure.coords;
  41512. var cs = figure.colors;
  41513. var i, ii;
  41514. switch (figure.type) {
  41515. case 'lattice':
  41516. var verticesPerRow = figure.verticesPerRow;
  41517. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  41518. var cols = verticesPerRow - 1;
  41519. for (i = 0; i < rows; i++) {
  41520. var q = i * verticesPerRow;
  41521. for (var j = 0; j < cols; j++, q++) {
  41522. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  41523. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  41524. }
  41525. }
  41526. break;
  41527. case 'triangles':
  41528. for (i = 0, ii = ps.length; i < ii; i += 3) {
  41529. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  41530. }
  41531. break;
  41532. default:
  41533. error('illigal figure');
  41534. break;
  41535. }
  41536. }
  41537. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases) {
  41538. // we will increase scale on some weird factor to let antialiasing take
  41539. // care of "rough" edges
  41540. var EXPECTED_SCALE = 1.1;
  41541. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  41542. var MAX_PATTERN_SIZE = 3000;
  41543. // 10in @ 300dpi shall be enough
  41544. // We need to keep transparent border around our pattern for fill():
  41545. // createPattern with 'no-repeat' will bleed edges across entire area.
  41546. var BORDER_SIZE = 2;
  41547. var offsetX = Math.floor(bounds[0]);
  41548. var offsetY = Math.floor(bounds[1]);
  41549. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  41550. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  41551. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  41552. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  41553. var scaleX = boundsWidth / width;
  41554. var scaleY = boundsHeight / height;
  41555. var context = {
  41556. coords: coords,
  41557. colors: colors,
  41558. offsetX: -offsetX,
  41559. offsetY: -offsetY,
  41560. scaleX: 1 / scaleX,
  41561. scaleY: 1 / scaleY
  41562. };
  41563. var paddedWidth = width + BORDER_SIZE * 2;
  41564. var paddedHeight = height + BORDER_SIZE * 2;
  41565. var canvas, tmpCanvas, i, ii;
  41566. if (WebGLUtils.isEnabled) {
  41567. canvas = WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  41568. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  41569. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  41570. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  41571. canvas = tmpCanvas.canvas;
  41572. } else {
  41573. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  41574. var tmpCtx = tmpCanvas.context;
  41575. var data = tmpCtx.createImageData(width, height);
  41576. if (backgroundColor) {
  41577. var bytes = data.data;
  41578. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  41579. bytes[i] = backgroundColor[0];
  41580. bytes[i + 1] = backgroundColor[1];
  41581. bytes[i + 2] = backgroundColor[2];
  41582. bytes[i + 3] = 255;
  41583. }
  41584. }
  41585. for (i = 0; i < figures.length; i++) {
  41586. drawFigure(data, figures[i], context);
  41587. }
  41588. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  41589. canvas = tmpCanvas.canvas;
  41590. }
  41591. return {
  41592. canvas: canvas,
  41593. offsetX: offsetX - BORDER_SIZE * scaleX,
  41594. offsetY: offsetY - BORDER_SIZE * scaleY,
  41595. scaleX: scaleX,
  41596. scaleY: scaleY
  41597. };
  41598. }
  41599. return createMeshCanvas;
  41600. }();
  41601. ShadingIRs.Mesh = {
  41602. fromIR: function Mesh_fromIR(raw) {
  41603. //var type = raw[1];
  41604. var coords = raw[2];
  41605. var colors = raw[3];
  41606. var figures = raw[4];
  41607. var bounds = raw[5];
  41608. var matrix = raw[6];
  41609. //var bbox = raw[7];
  41610. var background = raw[8];
  41611. return {
  41612. type: 'Pattern',
  41613. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  41614. var scale;
  41615. if (shadingFill) {
  41616. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  41617. } else {
  41618. // Obtain scale from matrix and current transformation matrix.
  41619. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  41620. if (matrix) {
  41621. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  41622. scale = [
  41623. scale[0] * matrixScale[0],
  41624. scale[1] * matrixScale[1]
  41625. ];
  41626. }
  41627. }
  41628. // Rasterizing on the main thread since sending/queue large canvases
  41629. // might cause OOM.
  41630. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases);
  41631. if (!shadingFill) {
  41632. ctx.setTransform.apply(ctx, owner.baseTransform);
  41633. if (matrix) {
  41634. ctx.transform.apply(ctx, matrix);
  41635. }
  41636. }
  41637. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  41638. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  41639. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  41640. }
  41641. };
  41642. }
  41643. };
  41644. ShadingIRs.Dummy = {
  41645. fromIR: function Dummy_fromIR() {
  41646. return {
  41647. type: 'Pattern',
  41648. getPattern: function Dummy_fromIR_getPattern() {
  41649. return 'hotpink';
  41650. }
  41651. };
  41652. }
  41653. };
  41654. function getShadingPatternFromIR(raw) {
  41655. var shadingIR = ShadingIRs[raw[0]];
  41656. if (!shadingIR) {
  41657. error('Unknown IR type: ' + raw[0]);
  41658. }
  41659. return shadingIR.fromIR(raw);
  41660. }
  41661. var TilingPattern = function TilingPatternClosure() {
  41662. var PaintType = {
  41663. COLORED: 1,
  41664. UNCOLORED: 2
  41665. };
  41666. var MAX_PATTERN_SIZE = 3000;
  41667. // 10in @ 300dpi shall be enough
  41668. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  41669. this.operatorList = IR[2];
  41670. this.matrix = IR[3] || [
  41671. 1,
  41672. 0,
  41673. 0,
  41674. 1,
  41675. 0,
  41676. 0
  41677. ];
  41678. this.bbox = IR[4];
  41679. this.xstep = IR[5];
  41680. this.ystep = IR[6];
  41681. this.paintType = IR[7];
  41682. this.tilingType = IR[8];
  41683. this.color = color;
  41684. this.canvasGraphicsFactory = canvasGraphicsFactory;
  41685. this.baseTransform = baseTransform;
  41686. this.type = 'Pattern';
  41687. this.ctx = ctx;
  41688. }
  41689. TilingPattern.prototype = {
  41690. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  41691. var operatorList = this.operatorList;
  41692. var bbox = this.bbox;
  41693. var xstep = this.xstep;
  41694. var ystep = this.ystep;
  41695. var paintType = this.paintType;
  41696. var tilingType = this.tilingType;
  41697. var color = this.color;
  41698. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  41699. info('TilingType: ' + tilingType);
  41700. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  41701. var topLeft = [
  41702. x0,
  41703. y0
  41704. ];
  41705. // we want the canvas to be as large as the step size
  41706. var botRight = [
  41707. x0 + xstep,
  41708. y0 + ystep
  41709. ];
  41710. var width = botRight[0] - topLeft[0];
  41711. var height = botRight[1] - topLeft[1];
  41712. // Obtain scale from matrix and current transformation matrix.
  41713. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  41714. var curMatrixScale = Util.singularValueDecompose2dScale(this.baseTransform);
  41715. var combinedScale = [
  41716. matrixScale[0] * curMatrixScale[0],
  41717. matrixScale[1] * curMatrixScale[1]
  41718. ];
  41719. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  41720. // Use width and height values that are as close as possible to the end
  41721. // result when the pattern is used. Too low value makes the pattern look
  41722. // blurry. Too large value makes it look too crispy.
  41723. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE);
  41724. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE);
  41725. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true);
  41726. var tmpCtx = tmpCanvas.context;
  41727. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  41728. graphics.groupLevel = owner.groupLevel;
  41729. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  41730. this.setScale(width, height, xstep, ystep);
  41731. this.transformToScale(graphics);
  41732. // transform coordinates to pattern space
  41733. var tmpTranslate = [
  41734. 1,
  41735. 0,
  41736. 0,
  41737. 1,
  41738. -topLeft[0],
  41739. -topLeft[1]
  41740. ];
  41741. graphics.transform.apply(graphics, tmpTranslate);
  41742. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  41743. graphics.executeOperatorList(operatorList);
  41744. return tmpCanvas.canvas;
  41745. },
  41746. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  41747. this.scale = [
  41748. width / xstep,
  41749. height / ystep
  41750. ];
  41751. },
  41752. transformToScale: function TilingPattern_transformToScale(graphics) {
  41753. var scale = this.scale;
  41754. var tmpScale = [
  41755. scale[0],
  41756. 0,
  41757. 0,
  41758. scale[1],
  41759. 0,
  41760. 0
  41761. ];
  41762. graphics.transform.apply(graphics, tmpScale);
  41763. },
  41764. scaleToContext: function TilingPattern_scaleToContext() {
  41765. var scale = this.scale;
  41766. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  41767. },
  41768. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  41769. if (bbox && isArray(bbox) && bbox.length === 4) {
  41770. var bboxWidth = x1 - x0;
  41771. var bboxHeight = y1 - y0;
  41772. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  41773. graphics.clip();
  41774. graphics.endPath();
  41775. }
  41776. },
  41777. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(context, paintType, color) {
  41778. switch (paintType) {
  41779. case PaintType.COLORED:
  41780. var ctx = this.ctx;
  41781. context.fillStyle = ctx.fillStyle;
  41782. context.strokeStyle = ctx.strokeStyle;
  41783. break;
  41784. case PaintType.UNCOLORED:
  41785. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  41786. context.fillStyle = cssColor;
  41787. context.strokeStyle = cssColor;
  41788. break;
  41789. default:
  41790. error('Unsupported paint type: ' + paintType);
  41791. }
  41792. },
  41793. getPattern: function TilingPattern_getPattern(ctx, owner) {
  41794. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  41795. ctx = this.ctx;
  41796. ctx.setTransform.apply(ctx, this.baseTransform);
  41797. ctx.transform.apply(ctx, this.matrix);
  41798. this.scaleToContext();
  41799. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  41800. }
  41801. };
  41802. return TilingPattern;
  41803. }();
  41804. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  41805. exports.TilingPattern = TilingPattern;
  41806. }));
  41807. (function (root, factory) {
  41808. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  41809. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  41810. var Util = sharedUtil.Util;
  41811. var assert = sharedUtil.assert;
  41812. var warn = sharedUtil.warn;
  41813. var error = sharedUtil.error;
  41814. var isInt = sharedUtil.isInt;
  41815. var isString = sharedUtil.isString;
  41816. var MissingDataException = sharedUtil.MissingDataException;
  41817. var isName = corePrimitives.isName;
  41818. var isCmd = corePrimitives.isCmd;
  41819. var isStream = corePrimitives.isStream;
  41820. var StringStream = coreStream.StringStream;
  41821. var Lexer = coreParser.Lexer;
  41822. var isEOF = coreParser.isEOF;
  41823. var BUILT_IN_CMAPS = [
  41824. // << Start unicode maps.
  41825. 'Adobe-GB1-UCS2',
  41826. 'Adobe-CNS1-UCS2',
  41827. 'Adobe-Japan1-UCS2',
  41828. 'Adobe-Korea1-UCS2',
  41829. // >> End unicode maps.
  41830. '78-EUC-H',
  41831. '78-EUC-V',
  41832. '78-H',
  41833. '78-RKSJ-H',
  41834. '78-RKSJ-V',
  41835. '78-V',
  41836. '78ms-RKSJ-H',
  41837. '78ms-RKSJ-V',
  41838. '83pv-RKSJ-H',
  41839. '90ms-RKSJ-H',
  41840. '90ms-RKSJ-V',
  41841. '90msp-RKSJ-H',
  41842. '90msp-RKSJ-V',
  41843. '90pv-RKSJ-H',
  41844. '90pv-RKSJ-V',
  41845. 'Add-H',
  41846. 'Add-RKSJ-H',
  41847. 'Add-RKSJ-V',
  41848. 'Add-V',
  41849. 'Adobe-CNS1-0',
  41850. 'Adobe-CNS1-1',
  41851. 'Adobe-CNS1-2',
  41852. 'Adobe-CNS1-3',
  41853. 'Adobe-CNS1-4',
  41854. 'Adobe-CNS1-5',
  41855. 'Adobe-CNS1-6',
  41856. 'Adobe-GB1-0',
  41857. 'Adobe-GB1-1',
  41858. 'Adobe-GB1-2',
  41859. 'Adobe-GB1-3',
  41860. 'Adobe-GB1-4',
  41861. 'Adobe-GB1-5',
  41862. 'Adobe-Japan1-0',
  41863. 'Adobe-Japan1-1',
  41864. 'Adobe-Japan1-2',
  41865. 'Adobe-Japan1-3',
  41866. 'Adobe-Japan1-4',
  41867. 'Adobe-Japan1-5',
  41868. 'Adobe-Japan1-6',
  41869. 'Adobe-Korea1-0',
  41870. 'Adobe-Korea1-1',
  41871. 'Adobe-Korea1-2',
  41872. 'B5-H',
  41873. 'B5-V',
  41874. 'B5pc-H',
  41875. 'B5pc-V',
  41876. 'CNS-EUC-H',
  41877. 'CNS-EUC-V',
  41878. 'CNS1-H',
  41879. 'CNS1-V',
  41880. 'CNS2-H',
  41881. 'CNS2-V',
  41882. 'ETHK-B5-H',
  41883. 'ETHK-B5-V',
  41884. 'ETen-B5-H',
  41885. 'ETen-B5-V',
  41886. 'ETenms-B5-H',
  41887. 'ETenms-B5-V',
  41888. 'EUC-H',
  41889. 'EUC-V',
  41890. 'Ext-H',
  41891. 'Ext-RKSJ-H',
  41892. 'Ext-RKSJ-V',
  41893. 'Ext-V',
  41894. 'GB-EUC-H',
  41895. 'GB-EUC-V',
  41896. 'GB-H',
  41897. 'GB-V',
  41898. 'GBK-EUC-H',
  41899. 'GBK-EUC-V',
  41900. 'GBK2K-H',
  41901. 'GBK2K-V',
  41902. 'GBKp-EUC-H',
  41903. 'GBKp-EUC-V',
  41904. 'GBT-EUC-H',
  41905. 'GBT-EUC-V',
  41906. 'GBT-H',
  41907. 'GBT-V',
  41908. 'GBTpc-EUC-H',
  41909. 'GBTpc-EUC-V',
  41910. 'GBpc-EUC-H',
  41911. 'GBpc-EUC-V',
  41912. 'H',
  41913. 'HKdla-B5-H',
  41914. 'HKdla-B5-V',
  41915. 'HKdlb-B5-H',
  41916. 'HKdlb-B5-V',
  41917. 'HKgccs-B5-H',
  41918. 'HKgccs-B5-V',
  41919. 'HKm314-B5-H',
  41920. 'HKm314-B5-V',
  41921. 'HKm471-B5-H',
  41922. 'HKm471-B5-V',
  41923. 'HKscs-B5-H',
  41924. 'HKscs-B5-V',
  41925. 'Hankaku',
  41926. 'Hiragana',
  41927. 'KSC-EUC-H',
  41928. 'KSC-EUC-V',
  41929. 'KSC-H',
  41930. 'KSC-Johab-H',
  41931. 'KSC-Johab-V',
  41932. 'KSC-V',
  41933. 'KSCms-UHC-H',
  41934. 'KSCms-UHC-HW-H',
  41935. 'KSCms-UHC-HW-V',
  41936. 'KSCms-UHC-V',
  41937. 'KSCpc-EUC-H',
  41938. 'KSCpc-EUC-V',
  41939. 'Katakana',
  41940. 'NWP-H',
  41941. 'NWP-V',
  41942. 'RKSJ-H',
  41943. 'RKSJ-V',
  41944. 'Roman',
  41945. 'UniCNS-UCS2-H',
  41946. 'UniCNS-UCS2-V',
  41947. 'UniCNS-UTF16-H',
  41948. 'UniCNS-UTF16-V',
  41949. 'UniCNS-UTF32-H',
  41950. 'UniCNS-UTF32-V',
  41951. 'UniCNS-UTF8-H',
  41952. 'UniCNS-UTF8-V',
  41953. 'UniGB-UCS2-H',
  41954. 'UniGB-UCS2-V',
  41955. 'UniGB-UTF16-H',
  41956. 'UniGB-UTF16-V',
  41957. 'UniGB-UTF32-H',
  41958. 'UniGB-UTF32-V',
  41959. 'UniGB-UTF8-H',
  41960. 'UniGB-UTF8-V',
  41961. 'UniJIS-UCS2-H',
  41962. 'UniJIS-UCS2-HW-H',
  41963. 'UniJIS-UCS2-HW-V',
  41964. 'UniJIS-UCS2-V',
  41965. 'UniJIS-UTF16-H',
  41966. 'UniJIS-UTF16-V',
  41967. 'UniJIS-UTF32-H',
  41968. 'UniJIS-UTF32-V',
  41969. 'UniJIS-UTF8-H',
  41970. 'UniJIS-UTF8-V',
  41971. 'UniJIS2004-UTF16-H',
  41972. 'UniJIS2004-UTF16-V',
  41973. 'UniJIS2004-UTF32-H',
  41974. 'UniJIS2004-UTF32-V',
  41975. 'UniJIS2004-UTF8-H',
  41976. 'UniJIS2004-UTF8-V',
  41977. 'UniJISPro-UCS2-HW-V',
  41978. 'UniJISPro-UCS2-V',
  41979. 'UniJISPro-UTF8-V',
  41980. 'UniJISX0213-UTF32-H',
  41981. 'UniJISX0213-UTF32-V',
  41982. 'UniJISX02132004-UTF32-H',
  41983. 'UniJISX02132004-UTF32-V',
  41984. 'UniKS-UCS2-H',
  41985. 'UniKS-UCS2-V',
  41986. 'UniKS-UTF16-H',
  41987. 'UniKS-UTF16-V',
  41988. 'UniKS-UTF32-H',
  41989. 'UniKS-UTF32-V',
  41990. 'UniKS-UTF8-H',
  41991. 'UniKS-UTF8-V',
  41992. 'V',
  41993. 'WP-Symbol'
  41994. ];
  41995. // CMap, not to be confused with TrueType's cmap.
  41996. var CMap = function CMapClosure() {
  41997. function CMap(builtInCMap) {
  41998. // Codespace ranges are stored as follows:
  41999. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  42000. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  42001. this.codespaceRanges = [
  42002. [],
  42003. [],
  42004. [],
  42005. []
  42006. ];
  42007. this.numCodespaceRanges = 0;
  42008. // Map entries have one of two forms.
  42009. // - cid chars are 16-bit unsigned integers, stored as integers.
  42010. // - bf chars are variable-length byte sequences, stored as strings, with
  42011. // one byte per character.
  42012. this._map = [];
  42013. this.name = '';
  42014. this.vertical = false;
  42015. this.useCMap = null;
  42016. this.builtInCMap = builtInCMap;
  42017. }
  42018. CMap.prototype = {
  42019. addCodespaceRange: function (n, low, high) {
  42020. this.codespaceRanges[n - 1].push(low, high);
  42021. this.numCodespaceRanges++;
  42022. },
  42023. mapCidRange: function (low, high, dstLow) {
  42024. while (low <= high) {
  42025. this._map[low++] = dstLow++;
  42026. }
  42027. },
  42028. mapBfRange: function (low, high, dstLow) {
  42029. var lastByte = dstLow.length - 1;
  42030. while (low <= high) {
  42031. this._map[low++] = dstLow;
  42032. // Only the last byte has to be incremented.
  42033. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  42034. }
  42035. },
  42036. mapBfRangeToArray: function (low, high, array) {
  42037. var i = 0, ii = array.length;
  42038. while (low <= high && i < ii) {
  42039. this._map[low] = array[i++];
  42040. ++low;
  42041. }
  42042. },
  42043. // This is used for both bf and cid chars.
  42044. mapOne: function (src, dst) {
  42045. this._map[src] = dst;
  42046. },
  42047. lookup: function (code) {
  42048. return this._map[code];
  42049. },
  42050. contains: function (code) {
  42051. return this._map[code] !== undefined;
  42052. },
  42053. forEach: function (callback) {
  42054. // Most maps have fewer than 65536 entries, and for those we use normal
  42055. // array iteration. But really sparse tables are possible -- e.g. with
  42056. // indices in the *billions*. For such tables we use for..in, which isn't
  42057. // ideal because it stringifies the indices for all present elements, but
  42058. // it does avoid iterating over every undefined entry.
  42059. var map = this._map;
  42060. var length = map.length;
  42061. var i;
  42062. if (length <= 0x10000) {
  42063. for (i = 0; i < length; i++) {
  42064. if (map[i] !== undefined) {
  42065. callback(i, map[i]);
  42066. }
  42067. }
  42068. } else {
  42069. for (i in this._map) {
  42070. callback(i, map[i]);
  42071. }
  42072. }
  42073. },
  42074. charCodeOf: function (value) {
  42075. return this._map.indexOf(value);
  42076. },
  42077. getMap: function () {
  42078. return this._map;
  42079. },
  42080. readCharCode: function (str, offset, out) {
  42081. var c = 0;
  42082. var codespaceRanges = this.codespaceRanges;
  42083. var codespaceRangesLen = this.codespaceRanges.length;
  42084. // 9.7.6.2 CMap Mapping
  42085. // The code length is at most 4.
  42086. for (var n = 0; n < codespaceRangesLen; n++) {
  42087. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  42088. // Check each codespace range to see if it falls within.
  42089. var codespaceRange = codespaceRanges[n];
  42090. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  42091. var low = codespaceRange[k++];
  42092. var high = codespaceRange[k++];
  42093. if (c >= low && c <= high) {
  42094. out.charcode = c;
  42095. out.length = n + 1;
  42096. return;
  42097. }
  42098. }
  42099. }
  42100. out.charcode = 0;
  42101. out.length = 1;
  42102. },
  42103. get length() {
  42104. return this._map.length;
  42105. },
  42106. get isIdentityCMap() {
  42107. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  42108. return false;
  42109. }
  42110. if (this._map.length !== 0x10000) {
  42111. return false;
  42112. }
  42113. for (var i = 0; i < 0x10000; i++) {
  42114. if (this._map[i] !== i) {
  42115. return false;
  42116. }
  42117. }
  42118. return true;
  42119. }
  42120. };
  42121. return CMap;
  42122. }();
  42123. // A special case of CMap, where the _map array implicitly has a length of
  42124. // 65536 and each element is equal to its index.
  42125. var IdentityCMap = function IdentityCMapClosure() {
  42126. function IdentityCMap(vertical, n) {
  42127. CMap.call(this);
  42128. this.vertical = vertical;
  42129. this.addCodespaceRange(n, 0, 0xffff);
  42130. }
  42131. Util.inherit(IdentityCMap, CMap, {});
  42132. IdentityCMap.prototype = {
  42133. addCodespaceRange: CMap.prototype.addCodespaceRange,
  42134. mapCidRange: function (low, high, dstLow) {
  42135. error('should not call mapCidRange');
  42136. },
  42137. mapBfRange: function (low, high, dstLow) {
  42138. error('should not call mapBfRange');
  42139. },
  42140. mapBfRangeToArray: function (low, high, array) {
  42141. error('should not call mapBfRangeToArray');
  42142. },
  42143. mapOne: function (src, dst) {
  42144. error('should not call mapCidOne');
  42145. },
  42146. lookup: function (code) {
  42147. return isInt(code) && code <= 0xffff ? code : undefined;
  42148. },
  42149. contains: function (code) {
  42150. return isInt(code) && code <= 0xffff;
  42151. },
  42152. forEach: function (callback) {
  42153. for (var i = 0; i <= 0xffff; i++) {
  42154. callback(i, i);
  42155. }
  42156. },
  42157. charCodeOf: function (value) {
  42158. return isInt(value) && value <= 0xffff ? value : -1;
  42159. },
  42160. getMap: function () {
  42161. // Sometimes identity maps must be instantiated, but it's rare.
  42162. var map = new Array(0x10000);
  42163. for (var i = 0; i <= 0xffff; i++) {
  42164. map[i] = i;
  42165. }
  42166. return map;
  42167. },
  42168. readCharCode: CMap.prototype.readCharCode,
  42169. get length() {
  42170. return 0x10000;
  42171. },
  42172. get isIdentityCMap() {
  42173. error('should not access .isIdentityCMap');
  42174. }
  42175. };
  42176. return IdentityCMap;
  42177. }();
  42178. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  42179. function fetchBinaryData(url) {
  42180. return new Promise(function (resolve, reject) {
  42181. var request = new XMLHttpRequest();
  42182. request.open('GET', url, true);
  42183. request.responseType = 'arraybuffer';
  42184. request.onreadystatechange = function () {
  42185. if (request.readyState === XMLHttpRequest.DONE) {
  42186. if (!request.response || request.status !== 200 && request.status !== 0) {
  42187. reject(new Error('Unable to get binary cMap at: ' + url));
  42188. } else {
  42189. resolve(new Uint8Array(request.response));
  42190. }
  42191. }
  42192. };
  42193. request.send(null);
  42194. });
  42195. }
  42196. function hexToInt(a, size) {
  42197. var n = 0;
  42198. for (var i = 0; i <= size; i++) {
  42199. n = n << 8 | a[i];
  42200. }
  42201. return n >>> 0;
  42202. }
  42203. function hexToStr(a, size) {
  42204. // This code is hot. Special-case some common values to avoid creating an
  42205. // object with subarray().
  42206. if (size === 1) {
  42207. return String.fromCharCode(a[0], a[1]);
  42208. }
  42209. if (size === 3) {
  42210. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  42211. }
  42212. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  42213. }
  42214. function addHex(a, b, size) {
  42215. var c = 0;
  42216. for (var i = size; i >= 0; i--) {
  42217. c += a[i] + b[i];
  42218. a[i] = c & 255;
  42219. c >>= 8;
  42220. }
  42221. }
  42222. function incHex(a, size) {
  42223. var c = 1;
  42224. for (var i = size; i >= 0 && c > 0; i--) {
  42225. c += a[i];
  42226. a[i] = c & 255;
  42227. c >>= 8;
  42228. }
  42229. }
  42230. var MAX_NUM_SIZE = 16;
  42231. var MAX_ENCODED_NUM_SIZE = 19;
  42232. // ceil(MAX_NUM_SIZE * 7 / 8)
  42233. function BinaryCMapStream(data) {
  42234. this.buffer = data;
  42235. this.pos = 0;
  42236. this.end = data.length;
  42237. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  42238. }
  42239. BinaryCMapStream.prototype = {
  42240. readByte: function () {
  42241. if (this.pos >= this.end) {
  42242. return -1;
  42243. }
  42244. return this.buffer[this.pos++];
  42245. },
  42246. readNumber: function () {
  42247. var n = 0;
  42248. var last;
  42249. do {
  42250. var b = this.readByte();
  42251. if (b < 0) {
  42252. error('unexpected EOF in bcmap');
  42253. }
  42254. last = !(b & 0x80);
  42255. n = n << 7 | b & 0x7F;
  42256. } while (!last);
  42257. return n;
  42258. },
  42259. readSigned: function () {
  42260. var n = this.readNumber();
  42261. return n & 1 ? ~(n >>> 1) : n >>> 1;
  42262. },
  42263. readHex: function (num, size) {
  42264. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  42265. this.pos += size + 1;
  42266. },
  42267. readHexNumber: function (num, size) {
  42268. var last;
  42269. var stack = this.tmpBuf, sp = 0;
  42270. do {
  42271. var b = this.readByte();
  42272. if (b < 0) {
  42273. error('unexpected EOF in bcmap');
  42274. }
  42275. last = !(b & 0x80);
  42276. stack[sp++] = b & 0x7F;
  42277. } while (!last);
  42278. var i = size, buffer = 0, bufferSize = 0;
  42279. while (i >= 0) {
  42280. while (bufferSize < 8 && stack.length > 0) {
  42281. buffer = stack[--sp] << bufferSize | buffer;
  42282. bufferSize += 7;
  42283. }
  42284. num[i] = buffer & 255;
  42285. i--;
  42286. buffer >>= 8;
  42287. bufferSize -= 8;
  42288. }
  42289. },
  42290. readHexSigned: function (num, size) {
  42291. this.readHexNumber(num, size);
  42292. var sign = num[size] & 1 ? 255 : 0;
  42293. var c = 0;
  42294. for (var i = 0; i <= size; i++) {
  42295. c = (c & 1) << 8 | num[i];
  42296. num[i] = c >> 1 ^ sign;
  42297. }
  42298. },
  42299. readString: function () {
  42300. var len = this.readNumber();
  42301. var s = '';
  42302. for (var i = 0; i < len; i++) {
  42303. s += String.fromCharCode(this.readNumber());
  42304. }
  42305. return s;
  42306. }
  42307. };
  42308. function processBinaryCMap(url, cMap, extend) {
  42309. return fetchBinaryData(url).then(function (data) {
  42310. var stream = new BinaryCMapStream(data);
  42311. var header = stream.readByte();
  42312. cMap.vertical = !!(header & 1);
  42313. var useCMap = null;
  42314. var start = new Uint8Array(MAX_NUM_SIZE);
  42315. var end = new Uint8Array(MAX_NUM_SIZE);
  42316. var char = new Uint8Array(MAX_NUM_SIZE);
  42317. var charCode = new Uint8Array(MAX_NUM_SIZE);
  42318. var tmp = new Uint8Array(MAX_NUM_SIZE);
  42319. var code;
  42320. var b;
  42321. while ((b = stream.readByte()) >= 0) {
  42322. var type = b >> 5;
  42323. if (type === 7) {
  42324. // metadata, e.g. comment or usecmap
  42325. switch (b & 0x1F) {
  42326. case 0:
  42327. stream.readString();
  42328. // skipping comment
  42329. break;
  42330. case 1:
  42331. useCMap = stream.readString();
  42332. break;
  42333. }
  42334. continue;
  42335. }
  42336. var sequence = !!(b & 0x10);
  42337. var dataSize = b & 15;
  42338. assert(dataSize + 1 <= MAX_NUM_SIZE);
  42339. var ucs2DataSize = 1;
  42340. var subitemsCount = stream.readNumber();
  42341. var i;
  42342. switch (type) {
  42343. case 0:
  42344. // codespacerange
  42345. stream.readHex(start, dataSize);
  42346. stream.readHexNumber(end, dataSize);
  42347. addHex(end, start, dataSize);
  42348. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  42349. for (i = 1; i < subitemsCount; i++) {
  42350. incHex(end, dataSize);
  42351. stream.readHexNumber(start, dataSize);
  42352. addHex(start, end, dataSize);
  42353. stream.readHexNumber(end, dataSize);
  42354. addHex(end, start, dataSize);
  42355. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  42356. }
  42357. break;
  42358. case 1:
  42359. // notdefrange
  42360. stream.readHex(start, dataSize);
  42361. stream.readHexNumber(end, dataSize);
  42362. addHex(end, start, dataSize);
  42363. code = stream.readNumber();
  42364. // undefined range, skipping
  42365. for (i = 1; i < subitemsCount; i++) {
  42366. incHex(end, dataSize);
  42367. stream.readHexNumber(start, dataSize);
  42368. addHex(start, end, dataSize);
  42369. stream.readHexNumber(end, dataSize);
  42370. addHex(end, start, dataSize);
  42371. code = stream.readNumber();
  42372. }
  42373. // nop
  42374. break;
  42375. case 2:
  42376. // cidchar
  42377. stream.readHex(char, dataSize);
  42378. code = stream.readNumber();
  42379. cMap.mapOne(hexToInt(char, dataSize), code);
  42380. for (i = 1; i < subitemsCount; i++) {
  42381. incHex(char, dataSize);
  42382. if (!sequence) {
  42383. stream.readHexNumber(tmp, dataSize);
  42384. addHex(char, tmp, dataSize);
  42385. }
  42386. code = stream.readSigned() + (code + 1);
  42387. cMap.mapOne(hexToInt(char, dataSize), code);
  42388. }
  42389. break;
  42390. case 3:
  42391. // cidrange
  42392. stream.readHex(start, dataSize);
  42393. stream.readHexNumber(end, dataSize);
  42394. addHex(end, start, dataSize);
  42395. code = stream.readNumber();
  42396. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  42397. for (i = 1; i < subitemsCount; i++) {
  42398. incHex(end, dataSize);
  42399. if (!sequence) {
  42400. stream.readHexNumber(start, dataSize);
  42401. addHex(start, end, dataSize);
  42402. } else {
  42403. start.set(end);
  42404. }
  42405. stream.readHexNumber(end, dataSize);
  42406. addHex(end, start, dataSize);
  42407. code = stream.readNumber();
  42408. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  42409. }
  42410. break;
  42411. case 4:
  42412. // bfchar
  42413. stream.readHex(char, ucs2DataSize);
  42414. stream.readHex(charCode, dataSize);
  42415. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  42416. for (i = 1; i < subitemsCount; i++) {
  42417. incHex(char, ucs2DataSize);
  42418. if (!sequence) {
  42419. stream.readHexNumber(tmp, ucs2DataSize);
  42420. addHex(char, tmp, ucs2DataSize);
  42421. }
  42422. incHex(charCode, dataSize);
  42423. stream.readHexSigned(tmp, dataSize);
  42424. addHex(charCode, tmp, dataSize);
  42425. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  42426. }
  42427. break;
  42428. case 5:
  42429. // bfrange
  42430. stream.readHex(start, ucs2DataSize);
  42431. stream.readHexNumber(end, ucs2DataSize);
  42432. addHex(end, start, ucs2DataSize);
  42433. stream.readHex(charCode, dataSize);
  42434. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  42435. for (i = 1; i < subitemsCount; i++) {
  42436. incHex(end, ucs2DataSize);
  42437. if (!sequence) {
  42438. stream.readHexNumber(start, ucs2DataSize);
  42439. addHex(start, end, ucs2DataSize);
  42440. } else {
  42441. start.set(end);
  42442. }
  42443. stream.readHexNumber(end, ucs2DataSize);
  42444. addHex(end, start, ucs2DataSize);
  42445. stream.readHex(charCode, dataSize);
  42446. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  42447. }
  42448. break;
  42449. default:
  42450. error('Unknown type: ' + type);
  42451. break;
  42452. }
  42453. }
  42454. if (useCMap) {
  42455. return extend(useCMap);
  42456. }
  42457. return cMap;
  42458. });
  42459. }
  42460. function BinaryCMapReader() {
  42461. }
  42462. BinaryCMapReader.prototype = { read: processBinaryCMap };
  42463. return BinaryCMapReader;
  42464. }();
  42465. var CMapFactory = function CMapFactoryClosure() {
  42466. function strToInt(str) {
  42467. var a = 0;
  42468. for (var i = 0; i < str.length; i++) {
  42469. a = a << 8 | str.charCodeAt(i);
  42470. }
  42471. return a >>> 0;
  42472. }
  42473. function expectString(obj) {
  42474. if (!isString(obj)) {
  42475. error('Malformed CMap: expected string.');
  42476. }
  42477. }
  42478. function expectInt(obj) {
  42479. if (!isInt(obj)) {
  42480. error('Malformed CMap: expected int.');
  42481. }
  42482. }
  42483. function parseBfChar(cMap, lexer) {
  42484. while (true) {
  42485. var obj = lexer.getObj();
  42486. if (isEOF(obj)) {
  42487. break;
  42488. }
  42489. if (isCmd(obj, 'endbfchar')) {
  42490. return;
  42491. }
  42492. expectString(obj);
  42493. var src = strToInt(obj);
  42494. obj = lexer.getObj();
  42495. // TODO are /dstName used?
  42496. expectString(obj);
  42497. var dst = obj;
  42498. cMap.mapOne(src, dst);
  42499. }
  42500. }
  42501. function parseBfRange(cMap, lexer) {
  42502. while (true) {
  42503. var obj = lexer.getObj();
  42504. if (isEOF(obj)) {
  42505. break;
  42506. }
  42507. if (isCmd(obj, 'endbfrange')) {
  42508. return;
  42509. }
  42510. expectString(obj);
  42511. var low = strToInt(obj);
  42512. obj = lexer.getObj();
  42513. expectString(obj);
  42514. var high = strToInt(obj);
  42515. obj = lexer.getObj();
  42516. if (isInt(obj) || isString(obj)) {
  42517. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  42518. cMap.mapBfRange(low, high, dstLow);
  42519. } else if (isCmd(obj, '[')) {
  42520. obj = lexer.getObj();
  42521. var array = [];
  42522. while (!isCmd(obj, ']') && !isEOF(obj)) {
  42523. array.push(obj);
  42524. obj = lexer.getObj();
  42525. }
  42526. cMap.mapBfRangeToArray(low, high, array);
  42527. } else {
  42528. break;
  42529. }
  42530. }
  42531. error('Invalid bf range.');
  42532. }
  42533. function parseCidChar(cMap, lexer) {
  42534. while (true) {
  42535. var obj = lexer.getObj();
  42536. if (isEOF(obj)) {
  42537. break;
  42538. }
  42539. if (isCmd(obj, 'endcidchar')) {
  42540. return;
  42541. }
  42542. expectString(obj);
  42543. var src = strToInt(obj);
  42544. obj = lexer.getObj();
  42545. expectInt(obj);
  42546. var dst = obj;
  42547. cMap.mapOne(src, dst);
  42548. }
  42549. }
  42550. function parseCidRange(cMap, lexer) {
  42551. while (true) {
  42552. var obj = lexer.getObj();
  42553. if (isEOF(obj)) {
  42554. break;
  42555. }
  42556. if (isCmd(obj, 'endcidrange')) {
  42557. return;
  42558. }
  42559. expectString(obj);
  42560. var low = strToInt(obj);
  42561. obj = lexer.getObj();
  42562. expectString(obj);
  42563. var high = strToInt(obj);
  42564. obj = lexer.getObj();
  42565. expectInt(obj);
  42566. var dstLow = obj;
  42567. cMap.mapCidRange(low, high, dstLow);
  42568. }
  42569. }
  42570. function parseCodespaceRange(cMap, lexer) {
  42571. while (true) {
  42572. var obj = lexer.getObj();
  42573. if (isEOF(obj)) {
  42574. break;
  42575. }
  42576. if (isCmd(obj, 'endcodespacerange')) {
  42577. return;
  42578. }
  42579. if (!isString(obj)) {
  42580. break;
  42581. }
  42582. var low = strToInt(obj);
  42583. obj = lexer.getObj();
  42584. if (!isString(obj)) {
  42585. break;
  42586. }
  42587. var high = strToInt(obj);
  42588. cMap.addCodespaceRange(obj.length, low, high);
  42589. }
  42590. error('Invalid codespace range.');
  42591. }
  42592. function parseWMode(cMap, lexer) {
  42593. var obj = lexer.getObj();
  42594. if (isInt(obj)) {
  42595. cMap.vertical = !!obj;
  42596. }
  42597. }
  42598. function parseCMapName(cMap, lexer) {
  42599. var obj = lexer.getObj();
  42600. if (isName(obj) && isString(obj.name)) {
  42601. cMap.name = obj.name;
  42602. }
  42603. }
  42604. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  42605. var previous;
  42606. var embededUseCMap;
  42607. objLoop:
  42608. while (true) {
  42609. try {
  42610. var obj = lexer.getObj();
  42611. if (isEOF(obj)) {
  42612. break;
  42613. } else if (isName(obj)) {
  42614. if (obj.name === 'WMode') {
  42615. parseWMode(cMap, lexer);
  42616. } else if (obj.name === 'CMapName') {
  42617. parseCMapName(cMap, lexer);
  42618. }
  42619. previous = obj;
  42620. } else if (isCmd(obj)) {
  42621. switch (obj.cmd) {
  42622. case 'endcmap':
  42623. break objLoop;
  42624. case 'usecmap':
  42625. if (isName(previous)) {
  42626. embededUseCMap = previous.name;
  42627. }
  42628. break;
  42629. case 'begincodespacerange':
  42630. parseCodespaceRange(cMap, lexer);
  42631. break;
  42632. case 'beginbfchar':
  42633. parseBfChar(cMap, lexer);
  42634. break;
  42635. case 'begincidchar':
  42636. parseCidChar(cMap, lexer);
  42637. break;
  42638. case 'beginbfrange':
  42639. parseBfRange(cMap, lexer);
  42640. break;
  42641. case 'begincidrange':
  42642. parseCidRange(cMap, lexer);
  42643. break;
  42644. }
  42645. }
  42646. } catch (ex) {
  42647. if (ex instanceof MissingDataException) {
  42648. throw ex;
  42649. }
  42650. warn('Invalid cMap data: ' + ex);
  42651. continue;
  42652. }
  42653. }
  42654. if (!useCMap && embededUseCMap) {
  42655. // Load the usecmap definition from the file only if there wasn't one
  42656. // specified.
  42657. useCMap = embededUseCMap;
  42658. }
  42659. if (useCMap) {
  42660. return extendCMap(cMap, builtInCMapParams, useCMap);
  42661. }
  42662. return Promise.resolve(cMap);
  42663. }
  42664. function extendCMap(cMap, builtInCMapParams, useCMap) {
  42665. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  42666. cMap.useCMap = newCMap;
  42667. // If there aren't any code space ranges defined clone all the parent ones
  42668. // into this cMap.
  42669. if (cMap.numCodespaceRanges === 0) {
  42670. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  42671. for (var i = 0; i < useCodespaceRanges.length; i++) {
  42672. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  42673. }
  42674. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  42675. }
  42676. // Merge the map into the current one, making sure not to override
  42677. // any previously defined entries.
  42678. cMap.useCMap.forEach(function (key, value) {
  42679. if (!cMap.contains(key)) {
  42680. cMap.mapOne(key, cMap.useCMap.lookup(key));
  42681. }
  42682. });
  42683. return cMap;
  42684. });
  42685. }
  42686. function parseBinaryCMap(name, builtInCMapParams) {
  42687. var url = builtInCMapParams.url + name + '.bcmap';
  42688. var cMap = new CMap(true);
  42689. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  42690. return extendCMap(cMap, builtInCMapParams, useCMap);
  42691. });
  42692. }
  42693. function createBuiltInCMap(name, builtInCMapParams) {
  42694. if (name === 'Identity-H') {
  42695. return Promise.resolve(new IdentityCMap(false, 2));
  42696. } else if (name === 'Identity-V') {
  42697. return Promise.resolve(new IdentityCMap(true, 2));
  42698. }
  42699. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  42700. return Promise.reject(new Error('Unknown cMap name: ' + name));
  42701. }
  42702. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  42703. if (builtInCMapParams.packed) {
  42704. return parseBinaryCMap(name, builtInCMapParams);
  42705. }
  42706. return new Promise(function (resolve, reject) {
  42707. var url = builtInCMapParams.url + name;
  42708. var request = new XMLHttpRequest();
  42709. request.onreadystatechange = function () {
  42710. if (request.readyState === XMLHttpRequest.DONE) {
  42711. if (request.status === 200 || request.status === 0) {
  42712. var cMap = new CMap(true);
  42713. var lexer = new Lexer(new StringStream(request.responseText));
  42714. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  42715. resolve(parsedCMap);
  42716. });
  42717. } else {
  42718. reject(new Error('Unable to get cMap at: ' + url));
  42719. }
  42720. }
  42721. };
  42722. request.open('GET', url, true);
  42723. request.send(null);
  42724. });
  42725. }
  42726. return {
  42727. create: function (encoding, builtInCMapParams, useCMap) {
  42728. if (isName(encoding)) {
  42729. return createBuiltInCMap(encoding.name, builtInCMapParams);
  42730. } else if (isStream(encoding)) {
  42731. var cMap = new CMap();
  42732. var lexer = new Lexer(encoding);
  42733. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  42734. if (parsedCMap.isIdentityCMap) {
  42735. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  42736. }
  42737. return parsedCMap;
  42738. });
  42739. }
  42740. return Promise.reject(new Error('Encoding required.'));
  42741. }
  42742. };
  42743. }();
  42744. exports.CMap = CMap;
  42745. exports.CMapFactory = CMapFactory;
  42746. exports.IdentityCMap = IdentityCMap;
  42747. }));
  42748. (function (root, factory) {
  42749. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  42750. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  42751. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42752. var FontType = sharedUtil.FontType;
  42753. var assert = sharedUtil.assert;
  42754. var bytesToString = sharedUtil.bytesToString;
  42755. var error = sharedUtil.error;
  42756. var info = sharedUtil.info;
  42757. var isArray = sharedUtil.isArray;
  42758. var isInt = sharedUtil.isInt;
  42759. var isNum = sharedUtil.isNum;
  42760. var readUint32 = sharedUtil.readUint32;
  42761. var shadow = sharedUtil.shadow;
  42762. var string32 = sharedUtil.string32;
  42763. var warn = sharedUtil.warn;
  42764. var MissingDataException = sharedUtil.MissingDataException;
  42765. var isSpace = sharedUtil.isSpace;
  42766. var Stream = coreStream.Stream;
  42767. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42768. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  42769. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  42770. var StandardEncoding = coreEncodings.StandardEncoding;
  42771. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42772. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42773. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42774. var getEncoding = coreEncodings.getEncoding;
  42775. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42776. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  42777. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  42778. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  42779. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  42780. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  42781. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42782. var Type1Parser = coreType1Parser.Type1Parser;
  42783. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  42784. var CFFParser = coreCFFParser.CFFParser;
  42785. var CFFCompiler = coreCFFParser.CFFCompiler;
  42786. var CFF = coreCFFParser.CFF;
  42787. var CFFHeader = coreCFFParser.CFFHeader;
  42788. var CFFTopDict = coreCFFParser.CFFTopDict;
  42789. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  42790. var CFFStrings = coreCFFParser.CFFStrings;
  42791. var CFFIndex = coreCFFParser.CFFIndex;
  42792. var CFFCharset = coreCFFParser.CFFCharset;
  42793. // Unicode Private Use Area
  42794. var PRIVATE_USE_OFFSET_START = 0xE000;
  42795. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  42796. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  42797. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  42798. // except for Type 3 fonts
  42799. var PDF_GLYPH_SPACE_UNITS = 1000;
  42800. // Accented charactars are not displayed properly on Windows, using this flag
  42801. // to control analysis of seac charstrings.
  42802. var SEAC_ANALYSIS_ENABLED = false;
  42803. var FontFlags = {
  42804. FixedPitch: 1,
  42805. Serif: 2,
  42806. Symbolic: 4,
  42807. Script: 8,
  42808. Nonsymbolic: 32,
  42809. Italic: 64,
  42810. AllCap: 65536,
  42811. SmallCap: 131072,
  42812. ForceBold: 262144
  42813. };
  42814. var MacStandardGlyphOrdering = [
  42815. '.notdef',
  42816. '.null',
  42817. 'nonmarkingreturn',
  42818. 'space',
  42819. 'exclam',
  42820. 'quotedbl',
  42821. 'numbersign',
  42822. 'dollar',
  42823. 'percent',
  42824. 'ampersand',
  42825. 'quotesingle',
  42826. 'parenleft',
  42827. 'parenright',
  42828. 'asterisk',
  42829. 'plus',
  42830. 'comma',
  42831. 'hyphen',
  42832. 'period',
  42833. 'slash',
  42834. 'zero',
  42835. 'one',
  42836. 'two',
  42837. 'three',
  42838. 'four',
  42839. 'five',
  42840. 'six',
  42841. 'seven',
  42842. 'eight',
  42843. 'nine',
  42844. 'colon',
  42845. 'semicolon',
  42846. 'less',
  42847. 'equal',
  42848. 'greater',
  42849. 'question',
  42850. 'at',
  42851. 'A',
  42852. 'B',
  42853. 'C',
  42854. 'D',
  42855. 'E',
  42856. 'F',
  42857. 'G',
  42858. 'H',
  42859. 'I',
  42860. 'J',
  42861. 'K',
  42862. 'L',
  42863. 'M',
  42864. 'N',
  42865. 'O',
  42866. 'P',
  42867. 'Q',
  42868. 'R',
  42869. 'S',
  42870. 'T',
  42871. 'U',
  42872. 'V',
  42873. 'W',
  42874. 'X',
  42875. 'Y',
  42876. 'Z',
  42877. 'bracketleft',
  42878. 'backslash',
  42879. 'bracketright',
  42880. 'asciicircum',
  42881. 'underscore',
  42882. 'grave',
  42883. 'a',
  42884. 'b',
  42885. 'c',
  42886. 'd',
  42887. 'e',
  42888. 'f',
  42889. 'g',
  42890. 'h',
  42891. 'i',
  42892. 'j',
  42893. 'k',
  42894. 'l',
  42895. 'm',
  42896. 'n',
  42897. 'o',
  42898. 'p',
  42899. 'q',
  42900. 'r',
  42901. 's',
  42902. 't',
  42903. 'u',
  42904. 'v',
  42905. 'w',
  42906. 'x',
  42907. 'y',
  42908. 'z',
  42909. 'braceleft',
  42910. 'bar',
  42911. 'braceright',
  42912. 'asciitilde',
  42913. 'Adieresis',
  42914. 'Aring',
  42915. 'Ccedilla',
  42916. 'Eacute',
  42917. 'Ntilde',
  42918. 'Odieresis',
  42919. 'Udieresis',
  42920. 'aacute',
  42921. 'agrave',
  42922. 'acircumflex',
  42923. 'adieresis',
  42924. 'atilde',
  42925. 'aring',
  42926. 'ccedilla',
  42927. 'eacute',
  42928. 'egrave',
  42929. 'ecircumflex',
  42930. 'edieresis',
  42931. 'iacute',
  42932. 'igrave',
  42933. 'icircumflex',
  42934. 'idieresis',
  42935. 'ntilde',
  42936. 'oacute',
  42937. 'ograve',
  42938. 'ocircumflex',
  42939. 'odieresis',
  42940. 'otilde',
  42941. 'uacute',
  42942. 'ugrave',
  42943. 'ucircumflex',
  42944. 'udieresis',
  42945. 'dagger',
  42946. 'degree',
  42947. 'cent',
  42948. 'sterling',
  42949. 'section',
  42950. 'bullet',
  42951. 'paragraph',
  42952. 'germandbls',
  42953. 'registered',
  42954. 'copyright',
  42955. 'trademark',
  42956. 'acute',
  42957. 'dieresis',
  42958. 'notequal',
  42959. 'AE',
  42960. 'Oslash',
  42961. 'infinity',
  42962. 'plusminus',
  42963. 'lessequal',
  42964. 'greaterequal',
  42965. 'yen',
  42966. 'mu',
  42967. 'partialdiff',
  42968. 'summation',
  42969. 'product',
  42970. 'pi',
  42971. 'integral',
  42972. 'ordfeminine',
  42973. 'ordmasculine',
  42974. 'Omega',
  42975. 'ae',
  42976. 'oslash',
  42977. 'questiondown',
  42978. 'exclamdown',
  42979. 'logicalnot',
  42980. 'radical',
  42981. 'florin',
  42982. 'approxequal',
  42983. 'Delta',
  42984. 'guillemotleft',
  42985. 'guillemotright',
  42986. 'ellipsis',
  42987. 'nonbreakingspace',
  42988. 'Agrave',
  42989. 'Atilde',
  42990. 'Otilde',
  42991. 'OE',
  42992. 'oe',
  42993. 'endash',
  42994. 'emdash',
  42995. 'quotedblleft',
  42996. 'quotedblright',
  42997. 'quoteleft',
  42998. 'quoteright',
  42999. 'divide',
  43000. 'lozenge',
  43001. 'ydieresis',
  43002. 'Ydieresis',
  43003. 'fraction',
  43004. 'currency',
  43005. 'guilsinglleft',
  43006. 'guilsinglright',
  43007. 'fi',
  43008. 'fl',
  43009. 'daggerdbl',
  43010. 'periodcentered',
  43011. 'quotesinglbase',
  43012. 'quotedblbase',
  43013. 'perthousand',
  43014. 'Acircumflex',
  43015. 'Ecircumflex',
  43016. 'Aacute',
  43017. 'Edieresis',
  43018. 'Egrave',
  43019. 'Iacute',
  43020. 'Icircumflex',
  43021. 'Idieresis',
  43022. 'Igrave',
  43023. 'Oacute',
  43024. 'Ocircumflex',
  43025. 'apple',
  43026. 'Ograve',
  43027. 'Uacute',
  43028. 'Ucircumflex',
  43029. 'Ugrave',
  43030. 'dotlessi',
  43031. 'circumflex',
  43032. 'tilde',
  43033. 'macron',
  43034. 'breve',
  43035. 'dotaccent',
  43036. 'ring',
  43037. 'cedilla',
  43038. 'hungarumlaut',
  43039. 'ogonek',
  43040. 'caron',
  43041. 'Lslash',
  43042. 'lslash',
  43043. 'Scaron',
  43044. 'scaron',
  43045. 'Zcaron',
  43046. 'zcaron',
  43047. 'brokenbar',
  43048. 'Eth',
  43049. 'eth',
  43050. 'Yacute',
  43051. 'yacute',
  43052. 'Thorn',
  43053. 'thorn',
  43054. 'minus',
  43055. 'multiply',
  43056. 'onesuperior',
  43057. 'twosuperior',
  43058. 'threesuperior',
  43059. 'onehalf',
  43060. 'onequarter',
  43061. 'threequarters',
  43062. 'franc',
  43063. 'Gbreve',
  43064. 'gbreve',
  43065. 'Idotaccent',
  43066. 'Scedilla',
  43067. 'scedilla',
  43068. 'Cacute',
  43069. 'cacute',
  43070. 'Ccaron',
  43071. 'ccaron',
  43072. 'dcroat'
  43073. ];
  43074. function adjustWidths(properties) {
  43075. if (!properties.fontMatrix) {
  43076. return;
  43077. }
  43078. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  43079. return;
  43080. }
  43081. // adjusting width to fontMatrix scale
  43082. var scale = 0.001 / properties.fontMatrix[0];
  43083. var glyphsWidths = properties.widths;
  43084. for (var glyph in glyphsWidths) {
  43085. glyphsWidths[glyph] *= scale;
  43086. }
  43087. properties.defaultWidth *= scale;
  43088. }
  43089. function adjustToUnicode(properties, builtInEncoding) {
  43090. if (properties.hasIncludedToUnicodeMap) {
  43091. return;
  43092. }
  43093. // The font dictionary has a `ToUnicode` entry.
  43094. if (properties.hasEncoding) {
  43095. return;
  43096. }
  43097. // The font dictionary has an `Encoding` entry.
  43098. if (builtInEncoding === properties.defaultEncoding) {
  43099. return;
  43100. }
  43101. // No point in trying to adjust `toUnicode` if the encodings match.
  43102. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  43103. return;
  43104. }
  43105. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  43106. for (var charCode in builtInEncoding) {
  43107. var glyphName = builtInEncoding[charCode];
  43108. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43109. if (unicode !== -1) {
  43110. toUnicode[charCode] = String.fromCharCode(unicode);
  43111. }
  43112. }
  43113. properties.toUnicode.amend(toUnicode);
  43114. }
  43115. function getFontType(type, subtype) {
  43116. switch (type) {
  43117. case 'Type1':
  43118. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  43119. case 'CIDFontType0':
  43120. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  43121. case 'OpenType':
  43122. return FontType.OPENTYPE;
  43123. case 'TrueType':
  43124. return FontType.TRUETYPE;
  43125. case 'CIDFontType2':
  43126. return FontType.CIDFONTTYPE2;
  43127. case 'MMType1':
  43128. return FontType.MMTYPE1;
  43129. case 'Type0':
  43130. return FontType.TYPE0;
  43131. default:
  43132. return FontType.UNKNOWN;
  43133. }
  43134. }
  43135. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  43136. // in a 'uniXXXX' format -- attempting to recover proper ones.
  43137. function recoverGlyphName(name, glyphsUnicodeMap) {
  43138. if (glyphsUnicodeMap[name] !== undefined) {
  43139. return name;
  43140. }
  43141. // The glyph name is non-standard, trying to recover.
  43142. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  43143. if (unicode !== -1) {
  43144. for (var key in glyphsUnicodeMap) {
  43145. if (glyphsUnicodeMap[key] === unicode) {
  43146. return key;
  43147. }
  43148. }
  43149. }
  43150. info('Unable to recover a standard glyph name for: ' + name);
  43151. return name;
  43152. }
  43153. var Glyph = function GlyphClosure() {
  43154. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  43155. this.fontChar = fontChar;
  43156. this.unicode = unicode;
  43157. this.accent = accent;
  43158. this.width = width;
  43159. this.vmetric = vmetric;
  43160. this.operatorListId = operatorListId;
  43161. this.isSpace = isSpace;
  43162. this.isInFont = isInFont;
  43163. }
  43164. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  43165. return this.fontChar === fontChar && this.unicode === unicode && this.accent === accent && this.width === width && this.vmetric === vmetric && this.operatorListId === operatorListId && this.isSpace === isSpace && this.isInFont === isInFont;
  43166. };
  43167. return Glyph;
  43168. }();
  43169. var ToUnicodeMap = function ToUnicodeMapClosure() {
  43170. function ToUnicodeMap(cmap) {
  43171. // The elements of this._map can be integers or strings, depending on how
  43172. // |cmap| was created.
  43173. this._map = cmap;
  43174. }
  43175. ToUnicodeMap.prototype = {
  43176. get length() {
  43177. return this._map.length;
  43178. },
  43179. forEach: function (callback) {
  43180. for (var charCode in this._map) {
  43181. callback(charCode, this._map[charCode].charCodeAt(0));
  43182. }
  43183. },
  43184. has: function (i) {
  43185. return this._map[i] !== undefined;
  43186. },
  43187. get: function (i) {
  43188. return this._map[i];
  43189. },
  43190. charCodeOf: function (v) {
  43191. return this._map.indexOf(v);
  43192. },
  43193. amend: function (map) {
  43194. for (var charCode in map) {
  43195. this._map[charCode] = map[charCode];
  43196. }
  43197. }
  43198. };
  43199. return ToUnicodeMap;
  43200. }();
  43201. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  43202. function IdentityToUnicodeMap(firstChar, lastChar) {
  43203. this.firstChar = firstChar;
  43204. this.lastChar = lastChar;
  43205. }
  43206. IdentityToUnicodeMap.prototype = {
  43207. get length() {
  43208. return this.lastChar + 1 - this.firstChar;
  43209. },
  43210. forEach: function (callback) {
  43211. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  43212. callback(i, i);
  43213. }
  43214. },
  43215. has: function (i) {
  43216. return this.firstChar <= i && i <= this.lastChar;
  43217. },
  43218. get: function (i) {
  43219. if (this.firstChar <= i && i <= this.lastChar) {
  43220. return String.fromCharCode(i);
  43221. }
  43222. return undefined;
  43223. },
  43224. charCodeOf: function (v) {
  43225. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  43226. },
  43227. amend: function (map) {
  43228. error('Should not call amend()');
  43229. }
  43230. };
  43231. return IdentityToUnicodeMap;
  43232. }();
  43233. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  43234. function writeInt16(dest, offset, num) {
  43235. dest[offset] = num >> 8 & 0xFF;
  43236. dest[offset + 1] = num & 0xFF;
  43237. }
  43238. function writeInt32(dest, offset, num) {
  43239. dest[offset] = num >> 24 & 0xFF;
  43240. dest[offset + 1] = num >> 16 & 0xFF;
  43241. dest[offset + 2] = num >> 8 & 0xFF;
  43242. dest[offset + 3] = num & 0xFF;
  43243. }
  43244. function writeData(dest, offset, data) {
  43245. var i, ii;
  43246. if (data instanceof Uint8Array) {
  43247. dest.set(data, offset);
  43248. } else if (typeof data === 'string') {
  43249. for (i = 0, ii = data.length; i < ii; i++) {
  43250. dest[offset++] = data.charCodeAt(i) & 0xFF;
  43251. }
  43252. } else {
  43253. // treating everything else as array
  43254. for (i = 0, ii = data.length; i < ii; i++) {
  43255. dest[offset++] = data[i] & 0xFF;
  43256. }
  43257. }
  43258. }
  43259. function OpenTypeFileBuilder(sfnt) {
  43260. this.sfnt = sfnt;
  43261. this.tables = Object.create(null);
  43262. }
  43263. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  43264. var maxPower2 = 1, log2 = 0;
  43265. while ((maxPower2 ^ entriesCount) > maxPower2) {
  43266. maxPower2 <<= 1;
  43267. log2++;
  43268. }
  43269. var searchRange = maxPower2 * entrySize;
  43270. return {
  43271. range: searchRange,
  43272. entry: log2,
  43273. rangeShift: entrySize * entriesCount - searchRange
  43274. };
  43275. };
  43276. var OTF_HEADER_SIZE = 12;
  43277. var OTF_TABLE_ENTRY_SIZE = 16;
  43278. OpenTypeFileBuilder.prototype = {
  43279. toArray: function OpenTypeFileBuilder_toArray() {
  43280. var sfnt = this.sfnt;
  43281. // Tables needs to be written by ascendant alphabetic order
  43282. var tables = this.tables;
  43283. var tablesNames = Object.keys(tables);
  43284. tablesNames.sort();
  43285. var numTables = tablesNames.length;
  43286. var i, j, jj, table, tableName;
  43287. // layout the tables data
  43288. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  43289. var tableOffsets = [offset];
  43290. for (i = 0; i < numTables; i++) {
  43291. table = tables[tablesNames[i]];
  43292. var paddedLength = (table.length + 3 & ~3) >>> 0;
  43293. offset += paddedLength;
  43294. tableOffsets.push(offset);
  43295. }
  43296. var file = new Uint8Array(offset);
  43297. // write the table data first (mostly for checksum)
  43298. for (i = 0; i < numTables; i++) {
  43299. table = tables[tablesNames[i]];
  43300. writeData(file, tableOffsets[i], table);
  43301. }
  43302. // sfnt version (4 bytes)
  43303. if (sfnt === 'true') {
  43304. // Windows hates the Mac TrueType sfnt version number
  43305. sfnt = string32(0x00010000);
  43306. }
  43307. file[0] = sfnt.charCodeAt(0) & 0xFF;
  43308. file[1] = sfnt.charCodeAt(1) & 0xFF;
  43309. file[2] = sfnt.charCodeAt(2) & 0xFF;
  43310. file[3] = sfnt.charCodeAt(3) & 0xFF;
  43311. // numTables (2 bytes)
  43312. writeInt16(file, 4, numTables);
  43313. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  43314. // searchRange (2 bytes)
  43315. writeInt16(file, 6, searchParams.range);
  43316. // entrySelector (2 bytes)
  43317. writeInt16(file, 8, searchParams.entry);
  43318. // rangeShift (2 bytes)
  43319. writeInt16(file, 10, searchParams.rangeShift);
  43320. offset = OTF_HEADER_SIZE;
  43321. // writing table entries
  43322. for (i = 0; i < numTables; i++) {
  43323. tableName = tablesNames[i];
  43324. file[offset] = tableName.charCodeAt(0) & 0xFF;
  43325. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  43326. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  43327. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  43328. // checksum
  43329. var checksum = 0;
  43330. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  43331. var quad = readUint32(file, j);
  43332. checksum = checksum + quad >>> 0;
  43333. }
  43334. writeInt32(file, offset + 4, checksum);
  43335. // offset
  43336. writeInt32(file, offset + 8, tableOffsets[i]);
  43337. // length
  43338. writeInt32(file, offset + 12, tables[tableName].length);
  43339. offset += OTF_TABLE_ENTRY_SIZE;
  43340. }
  43341. return file;
  43342. },
  43343. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  43344. if (tag in this.tables) {
  43345. throw new Error('Table ' + tag + ' already exists');
  43346. }
  43347. this.tables[tag] = data;
  43348. }
  43349. };
  43350. return OpenTypeFileBuilder;
  43351. }();
  43352. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  43353. // issues when they are painted on the canvas, e.g. complex-script shaping or
  43354. // control/whitespace characters. The ranges are listed in pairs: the first item
  43355. // is a code of the first problematic code, the second one is the next
  43356. // non-problematic code. The ranges must be in sorted order.
  43357. var ProblematicCharRanges = new Int32Array([
  43358. // Control characters.
  43359. 0x0000,
  43360. 0x0020,
  43361. 0x007F,
  43362. 0x00A1,
  43363. 0x00AD,
  43364. 0x00AE,
  43365. // Chars that is used in complex-script shaping.
  43366. 0x0600,
  43367. 0x0780,
  43368. 0x08A0,
  43369. 0x10A0,
  43370. 0x1780,
  43371. 0x1800,
  43372. 0x1C00,
  43373. 0x1C50,
  43374. // General punctuation chars.
  43375. 0x2000,
  43376. 0x2010,
  43377. 0x2011,
  43378. 0x2012,
  43379. 0x2028,
  43380. 0x2030,
  43381. 0x205F,
  43382. 0x2070,
  43383. 0x25CC,
  43384. 0x25CD,
  43385. 0x3000,
  43386. 0x3001,
  43387. // Chars that is used in complex-script shaping.
  43388. 0xAA60,
  43389. 0xAA80,
  43390. // Specials Unicode block.
  43391. 0xFFF0,
  43392. 0x10000
  43393. ]);
  43394. /**
  43395. * 'Font' is the class the outside world should use, it encapsulate all the font
  43396. * decoding logics whatever type it is (assuming the font type is supported).
  43397. *
  43398. * For example to read a Type1 font and to attach it to the document:
  43399. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  43400. * type1Font.bind();
  43401. */
  43402. var Font = function FontClosure() {
  43403. function Font(name, file, properties) {
  43404. var charCode, glyphName, unicode;
  43405. this.name = name;
  43406. this.loadedName = properties.loadedName;
  43407. this.isType3Font = properties.isType3Font;
  43408. this.sizes = [];
  43409. this.missingFile = false;
  43410. this.glyphCache = Object.create(null);
  43411. var names = name.split('+');
  43412. names = names.length > 1 ? names[1] : names[0];
  43413. names = names.split(/[-,_]/g)[0];
  43414. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  43415. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  43416. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  43417. var type = properties.type;
  43418. var subtype = properties.subtype;
  43419. this.type = type;
  43420. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  43421. this.differences = properties.differences;
  43422. this.widths = properties.widths;
  43423. this.defaultWidth = properties.defaultWidth;
  43424. this.composite = properties.composite;
  43425. this.wideChars = properties.wideChars;
  43426. this.cMap = properties.cMap;
  43427. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  43428. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  43429. this.fontMatrix = properties.fontMatrix;
  43430. this.bbox = properties.bbox;
  43431. this.toUnicode = properties.toUnicode;
  43432. this.toFontChar = [];
  43433. if (properties.type === 'Type3') {
  43434. for (charCode = 0; charCode < 256; charCode++) {
  43435. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  43436. }
  43437. this.fontType = FontType.TYPE3;
  43438. return;
  43439. }
  43440. this.cidEncoding = properties.cidEncoding;
  43441. this.vertical = properties.vertical;
  43442. if (this.vertical) {
  43443. this.vmetrics = properties.vmetrics;
  43444. this.defaultVMetrics = properties.defaultVMetrics;
  43445. }
  43446. var glyphsUnicodeMap;
  43447. if (!file || file.isEmpty) {
  43448. if (file) {
  43449. // Some bad PDF generators will include empty font files,
  43450. // attempting to recover by assuming that no file exists.
  43451. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  43452. }
  43453. this.missingFile = true;
  43454. // The file data is not specified. Trying to fix the font name
  43455. // to be used with the canvas.font.
  43456. var fontName = name.replace(/[,_]/g, '-');
  43457. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  43458. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  43459. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  43460. this.bold = fontName.search(/bold/gi) !== -1;
  43461. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  43462. // Use 'name' instead of 'fontName' here because the original
  43463. // name ArialBlack for example will be replaced by Helvetica.
  43464. this.black = name.search(/Black/g) !== -1;
  43465. // if at least one width is present, remeasure all chars when exists
  43466. this.remeasure = Object.keys(this.widths).length > 0;
  43467. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  43468. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  43469. // Standard fonts might be embedded as CID font without glyph mapping.
  43470. // Building one based on GlyphMapForStandardFonts.
  43471. var map = [];
  43472. for (charCode in GlyphMapForStandardFonts) {
  43473. map[+charCode] = GlyphMapForStandardFonts[charCode];
  43474. }
  43475. if (/ArialBlack/i.test(name)) {
  43476. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  43477. for (charCode in SupplementalGlyphMapForArialBlack) {
  43478. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  43479. }
  43480. }
  43481. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  43482. if (!isIdentityUnicode) {
  43483. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  43484. map[+charCode] = unicodeCharCode;
  43485. });
  43486. }
  43487. this.toFontChar = map;
  43488. this.toUnicode = new ToUnicodeMap(map);
  43489. } else if (/Symbol/i.test(fontName)) {
  43490. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  43491. } else if (/Dingbats/i.test(fontName)) {
  43492. if (/Wingdings/i.test(name)) {
  43493. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  43494. }
  43495. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  43496. } else if (isStandardFont) {
  43497. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  43498. } else {
  43499. glyphsUnicodeMap = getGlyphsUnicode();
  43500. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  43501. if (!this.composite) {
  43502. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  43503. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43504. if (unicode !== -1) {
  43505. unicodeCharCode = unicode;
  43506. }
  43507. }
  43508. this.toFontChar[charCode] = unicodeCharCode;
  43509. }.bind(this));
  43510. }
  43511. this.loadedName = fontName.split('-')[0];
  43512. this.loading = false;
  43513. this.fontType = getFontType(type, subtype);
  43514. return;
  43515. }
  43516. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  43517. if (subtype === 'Type1C') {
  43518. if (type !== 'Type1' && type !== 'MMType1') {
  43519. // Some TrueType fonts by mistake claim Type1C
  43520. if (isTrueTypeFile(file)) {
  43521. subtype = 'TrueType';
  43522. } else {
  43523. type = 'Type1';
  43524. }
  43525. } else if (isOpenTypeFile(file)) {
  43526. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  43527. type = subtype = 'OpenType';
  43528. }
  43529. }
  43530. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  43531. type = 'CIDFontType0';
  43532. }
  43533. if (subtype === 'OpenType') {
  43534. type = 'OpenType';
  43535. }
  43536. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  43537. if (type === 'CIDFontType0') {
  43538. if (isType1File(file)) {
  43539. subtype = 'CIDFontType0';
  43540. } else if (isOpenTypeFile(file)) {
  43541. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  43542. type = subtype = 'OpenType';
  43543. } else {
  43544. subtype = 'CIDFontType0C';
  43545. }
  43546. }
  43547. var data;
  43548. switch (type) {
  43549. case 'MMType1':
  43550. info('MMType1 font (' + name + '), falling back to Type1.');
  43551. case 'Type1':
  43552. case 'CIDFontType0':
  43553. this.mimetype = 'font/opentype';
  43554. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  43555. adjustWidths(properties);
  43556. // Wrap the CFF data inside an OTF font file
  43557. data = this.convert(name, cff, properties);
  43558. break;
  43559. case 'OpenType':
  43560. case 'TrueType':
  43561. case 'CIDFontType2':
  43562. this.mimetype = 'font/opentype';
  43563. // Repair the TrueType file. It is can be damaged in the point of
  43564. // view of the sanitizer
  43565. data = this.checkAndRepair(name, file, properties);
  43566. if (this.isOpenType) {
  43567. adjustWidths(properties);
  43568. type = 'OpenType';
  43569. }
  43570. break;
  43571. default:
  43572. error('Font ' + type + ' is not supported');
  43573. break;
  43574. }
  43575. this.data = data;
  43576. this.fontType = getFontType(type, subtype);
  43577. // Transfer some properties again that could change during font conversion
  43578. this.fontMatrix = properties.fontMatrix;
  43579. this.widths = properties.widths;
  43580. this.defaultWidth = properties.defaultWidth;
  43581. this.toUnicode = properties.toUnicode;
  43582. this.encoding = properties.baseEncoding;
  43583. this.seacMap = properties.seacMap;
  43584. this.loading = true;
  43585. }
  43586. Font.getFontID = function () {
  43587. var ID = 1;
  43588. return function Font_getFontID() {
  43589. return String(ID++);
  43590. };
  43591. }();
  43592. function int16(b0, b1) {
  43593. return (b0 << 8) + b1;
  43594. }
  43595. function signedInt16(b0, b1) {
  43596. var value = (b0 << 8) + b1;
  43597. return value & 1 << 15 ? value - 0x10000 : value;
  43598. }
  43599. function int32(b0, b1, b2, b3) {
  43600. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  43601. }
  43602. function string16(value) {
  43603. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  43604. }
  43605. function safeString16(value) {
  43606. // clamp value to the 16-bit int range
  43607. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  43608. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  43609. }
  43610. function isTrueTypeFile(file) {
  43611. var header = file.peekBytes(4);
  43612. return readUint32(header, 0) === 0x00010000;
  43613. }
  43614. function isOpenTypeFile(file) {
  43615. var header = file.peekBytes(4);
  43616. return bytesToString(header) === 'OTTO';
  43617. }
  43618. function isType1File(file) {
  43619. var header = file.peekBytes(2);
  43620. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  43621. if (header[0] === 0x25 && header[1] === 0x21) {
  43622. return true;
  43623. }
  43624. // ... obviously some fonts violate that part of the specification,
  43625. // please refer to the comment in |Type1Font| below.
  43626. if (header[0] === 0x80 && header[1] === 0x01) {
  43627. // pfb file header.
  43628. return true;
  43629. }
  43630. return false;
  43631. }
  43632. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  43633. var toFontChar = [], unicode;
  43634. for (var i = 0, ii = encoding.length; i < ii; i++) {
  43635. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  43636. if (unicode !== -1) {
  43637. toFontChar[i] = unicode;
  43638. }
  43639. }
  43640. for (var charCode in differences) {
  43641. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  43642. if (unicode !== -1) {
  43643. toFontChar[+charCode] = unicode;
  43644. }
  43645. }
  43646. return toFontChar;
  43647. }
  43648. /**
  43649. * Helper function for |adjustMapping|.
  43650. * @return {boolean}
  43651. */
  43652. function isProblematicUnicodeLocation(code) {
  43653. // Using binary search to find a range start.
  43654. var i = 0, j = ProblematicCharRanges.length - 1;
  43655. while (i < j) {
  43656. var c = i + j + 1 >> 1;
  43657. if (code < ProblematicCharRanges[c]) {
  43658. j = c - 1;
  43659. } else {
  43660. i = c;
  43661. }
  43662. }
  43663. // Even index means code in problematic range.
  43664. return !(i & 1);
  43665. }
  43666. /**
  43667. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  43668. * with their unicode value. It also moves char codes that are in known
  43669. * problematic locations.
  43670. * @return {Object} Two properties:
  43671. * 'toFontChar' - maps original char codes(the value that will be read
  43672. * from commands such as show text) to the char codes that will be used in the
  43673. * font that we build
  43674. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  43675. */
  43676. function adjustMapping(charCodeToGlyphId, properties) {
  43677. var toUnicode = properties.toUnicode;
  43678. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  43679. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  43680. var newMap = Object.create(null);
  43681. var toFontChar = [];
  43682. var usedFontCharCodes = [];
  43683. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  43684. for (var originalCharCode in charCodeToGlyphId) {
  43685. originalCharCode |= 0;
  43686. var glyphId = charCodeToGlyphId[originalCharCode];
  43687. var fontCharCode = originalCharCode;
  43688. // First try to map the value to a unicode position if a non identity map
  43689. // was created.
  43690. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  43691. var unicode = toUnicode.get(fontCharCode);
  43692. // TODO: Try to map ligatures to the correct spot.
  43693. if (unicode.length === 1) {
  43694. fontCharCode = unicode.charCodeAt(0);
  43695. }
  43696. }
  43697. // Try to move control characters, special characters and already mapped
  43698. // characters to the private use area since they will not be drawn by
  43699. // canvas if left in their current position. Also, move characters if the
  43700. // font was symbolic and there is only an identity unicode map since the
  43701. // characters probably aren't in the correct position (fixes an issue
  43702. // with firefox and thuluthfont).
  43703. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  43704. // Room left.
  43705. // Loop to try and find a free spot in the private use area.
  43706. do {
  43707. fontCharCode = nextAvailableFontCharCode++;
  43708. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  43709. fontCharCode = 0xF020;
  43710. nextAvailableFontCharCode = fontCharCode + 1;
  43711. }
  43712. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  43713. }
  43714. newMap[fontCharCode] = glyphId;
  43715. toFontChar[originalCharCode] = fontCharCode;
  43716. usedFontCharCodes[fontCharCode] = true;
  43717. }
  43718. return {
  43719. toFontChar: toFontChar,
  43720. charCodeToGlyphId: newMap,
  43721. nextAvailableFontCharCode: nextAvailableFontCharCode
  43722. };
  43723. }
  43724. function getRanges(glyphs, numGlyphs) {
  43725. // Array.sort() sorts by characters, not numerically, so convert to an
  43726. // array of characters.
  43727. var codes = [];
  43728. for (var charCode in glyphs) {
  43729. // Remove an invalid glyph ID mappings to make OTS happy.
  43730. if (glyphs[charCode] >= numGlyphs) {
  43731. continue;
  43732. }
  43733. codes.push({
  43734. fontCharCode: charCode | 0,
  43735. glyphId: glyphs[charCode]
  43736. });
  43737. }
  43738. codes.sort(function fontGetRangesSort(a, b) {
  43739. return a.fontCharCode - b.fontCharCode;
  43740. });
  43741. // Split the sorted codes into ranges.
  43742. var ranges = [];
  43743. var length = codes.length;
  43744. for (var n = 0; n < length;) {
  43745. var start = codes[n].fontCharCode;
  43746. var codeIndices = [codes[n].glyphId];
  43747. ++n;
  43748. var end = start;
  43749. while (n < length && end + 1 === codes[n].fontCharCode) {
  43750. codeIndices.push(codes[n].glyphId);
  43751. ++end;
  43752. ++n;
  43753. if (end === 0xFFFF) {
  43754. break;
  43755. }
  43756. }
  43757. ranges.push([
  43758. start,
  43759. end,
  43760. codeIndices
  43761. ]);
  43762. }
  43763. return ranges;
  43764. }
  43765. function createCmapTable(glyphs, numGlyphs) {
  43766. var ranges = getRanges(glyphs, numGlyphs);
  43767. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  43768. var cmap = '\x00\x00' + // version
  43769. string16(numTables) + // numTables
  43770. '\x00\x03' + // platformID
  43771. '\x00\x01' + // encodingID
  43772. string32(4 + numTables * 8);
  43773. // start of the table record
  43774. var i, ii, j, jj;
  43775. for (i = ranges.length - 1; i >= 0; --i) {
  43776. if (ranges[i][0] <= 0xFFFF) {
  43777. break;
  43778. }
  43779. }
  43780. var bmpLength = i + 1;
  43781. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  43782. ranges[i][1] = 0xFFFE;
  43783. }
  43784. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  43785. var segCount = bmpLength + trailingRangesCount;
  43786. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  43787. // Fill up the 4 parallel arrays describing the segments.
  43788. var startCount = '';
  43789. var endCount = '';
  43790. var idDeltas = '';
  43791. var idRangeOffsets = '';
  43792. var glyphsIds = '';
  43793. var bias = 0;
  43794. var range, start, end, codes;
  43795. for (i = 0, ii = bmpLength; i < ii; i++) {
  43796. range = ranges[i];
  43797. start = range[0];
  43798. end = range[1];
  43799. startCount += string16(start);
  43800. endCount += string16(end);
  43801. codes = range[2];
  43802. var contiguous = true;
  43803. for (j = 1, jj = codes.length; j < jj; ++j) {
  43804. if (codes[j] !== codes[j - 1] + 1) {
  43805. contiguous = false;
  43806. break;
  43807. }
  43808. }
  43809. if (!contiguous) {
  43810. var offset = (segCount - i) * 2 + bias * 2;
  43811. bias += end - start + 1;
  43812. idDeltas += string16(0);
  43813. idRangeOffsets += string16(offset);
  43814. for (j = 0, jj = codes.length; j < jj; ++j) {
  43815. glyphsIds += string16(codes[j]);
  43816. }
  43817. } else {
  43818. var startCode = codes[0];
  43819. idDeltas += string16(startCode - start & 0xFFFF);
  43820. idRangeOffsets += string16(0);
  43821. }
  43822. }
  43823. if (trailingRangesCount > 0) {
  43824. endCount += '\xFF\xFF';
  43825. startCount += '\xFF\xFF';
  43826. idDeltas += '\x00\x01';
  43827. idRangeOffsets += '\x00\x00';
  43828. }
  43829. var format314 = '\x00\x00' + // language
  43830. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  43831. var format31012 = '';
  43832. var header31012 = '';
  43833. if (numTables > 1) {
  43834. cmap += '\x00\x03' + // platformID
  43835. '\x00\x0A' + // encodingID
  43836. string32(4 + numTables * 8 + 4 + format314.length);
  43837. // start of the table record
  43838. format31012 = '';
  43839. for (i = 0, ii = ranges.length; i < ii; i++) {
  43840. range = ranges[i];
  43841. start = range[0];
  43842. codes = range[2];
  43843. var code = codes[0];
  43844. for (j = 1, jj = codes.length; j < jj; ++j) {
  43845. if (codes[j] !== codes[j - 1] + 1) {
  43846. end = range[0] + j - 1;
  43847. format31012 += string32(start) + // startCharCode
  43848. string32(end) + // endCharCode
  43849. string32(code);
  43850. // startGlyphID
  43851. start = end + 1;
  43852. code = codes[j];
  43853. }
  43854. }
  43855. format31012 += string32(start) + // startCharCode
  43856. string32(range[1]) + // endCharCode
  43857. string32(code);
  43858. }
  43859. // startGlyphID
  43860. header31012 = '\x00\x0C' + // format
  43861. '\x00\x00' + // reserved
  43862. string32(format31012.length + 16) + // length
  43863. '\x00\x00\x00\x00' + // language
  43864. string32(format31012.length / 12);
  43865. }
  43866. // nGroups
  43867. return cmap + '\x00\x04' + // format
  43868. string16(format314.length + 4) + // length
  43869. format314 + header31012 + format31012;
  43870. }
  43871. function validateOS2Table(os2) {
  43872. var stream = new Stream(os2.data);
  43873. var version = stream.getUint16();
  43874. // TODO verify all OS/2 tables fields, but currently we validate only those
  43875. // that give us issues
  43876. stream.getBytes(60);
  43877. // skipping type, misc sizes, panose, unicode ranges
  43878. var selection = stream.getUint16();
  43879. if (version < 4 && selection & 0x0300) {
  43880. return false;
  43881. }
  43882. var firstChar = stream.getUint16();
  43883. var lastChar = stream.getUint16();
  43884. if (firstChar > lastChar) {
  43885. return false;
  43886. }
  43887. stream.getBytes(6);
  43888. // skipping sTypoAscender/Descender/LineGap
  43889. var usWinAscent = stream.getUint16();
  43890. if (usWinAscent === 0) {
  43891. // makes font unreadable by windows
  43892. return false;
  43893. }
  43894. // OS/2 appears to be valid, resetting some fields
  43895. os2.data[8] = os2.data[9] = 0;
  43896. // IE rejects fonts if fsType != 0
  43897. return true;
  43898. }
  43899. function createOS2Table(properties, charstrings, override) {
  43900. override = override || {
  43901. unitsPerEm: 0,
  43902. yMax: 0,
  43903. yMin: 0,
  43904. ascent: 0,
  43905. descent: 0
  43906. };
  43907. var ulUnicodeRange1 = 0;
  43908. var ulUnicodeRange2 = 0;
  43909. var ulUnicodeRange3 = 0;
  43910. var ulUnicodeRange4 = 0;
  43911. var firstCharIndex = null;
  43912. var lastCharIndex = 0;
  43913. if (charstrings) {
  43914. for (var code in charstrings) {
  43915. code |= 0;
  43916. if (firstCharIndex > code || !firstCharIndex) {
  43917. firstCharIndex = code;
  43918. }
  43919. if (lastCharIndex < code) {
  43920. lastCharIndex = code;
  43921. }
  43922. var position = getUnicodeRangeFor(code);
  43923. if (position < 32) {
  43924. ulUnicodeRange1 |= 1 << position;
  43925. } else if (position < 64) {
  43926. ulUnicodeRange2 |= 1 << position - 32;
  43927. } else if (position < 96) {
  43928. ulUnicodeRange3 |= 1 << position - 64;
  43929. } else if (position < 123) {
  43930. ulUnicodeRange4 |= 1 << position - 96;
  43931. } else {
  43932. error('Unicode ranges Bits > 123 are reserved for internal usage');
  43933. }
  43934. }
  43935. } else {
  43936. // TODO
  43937. firstCharIndex = 0;
  43938. lastCharIndex = 255;
  43939. }
  43940. var bbox = properties.bbox || [
  43941. 0,
  43942. 0,
  43943. 0,
  43944. 0
  43945. ];
  43946. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  43947. // if the font units differ to the PDF glyph space units
  43948. // then scale up the values
  43949. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  43950. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  43951. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  43952. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  43953. typoDescent = -typoDescent;
  43954. }
  43955. // fixing incorrect descent
  43956. var winAscent = override.yMax || typoAscent;
  43957. var winDescent = -override.yMin || -typoDescent;
  43958. return '\x00\x03' + // version
  43959. '\x02\x24' + // xAvgCharWidth
  43960. '\x01\xF4' + // usWeightClass
  43961. '\x00\x05' + // usWidthClass
  43962. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  43963. '\x02\x8A' + // ySubscriptXSize
  43964. '\x02\xBB' + // ySubscriptYSize
  43965. '\x00\x00' + // ySubscriptXOffset
  43966. '\x00\x8C' + // ySubscriptYOffset
  43967. '\x02\x8A' + // ySuperScriptXSize
  43968. '\x02\xBB' + // ySuperScriptYSize
  43969. '\x00\x00' + // ySuperScriptXOffset
  43970. '\x01\xDF' + // ySuperScriptYOffset
  43971. '\x00\x31' + // yStrikeOutSize
  43972. '\x01\x02' + // yStrikeOutPosition
  43973. '\x00\x00' + // sFamilyClass
  43974. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  43975. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  43976. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  43977. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  43978. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  43979. '\x2A\x32\x31\x2A' + // achVendID
  43980. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  43981. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  43982. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  43983. string16(typoAscent) + // sTypoAscender
  43984. string16(typoDescent) + // sTypoDescender
  43985. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  43986. string16(winAscent) + // usWinAscent
  43987. string16(winDescent) + // usWinDescent
  43988. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  43989. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  43990. string16(properties.xHeight) + // sxHeight
  43991. string16(properties.capHeight) + // sCapHeight
  43992. string16(0) + // usDefaultChar
  43993. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  43994. '\x00\x03';
  43995. }
  43996. // usMaxContext
  43997. function createPostTable(properties) {
  43998. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  43999. return '\x00\x03\x00\x00' + // Version number
  44000. string32(angle) + // italicAngle
  44001. '\x00\x00' + // underlinePosition
  44002. '\x00\x00' + // underlineThickness
  44003. string32(properties.fixedPitch) + // isFixedPitch
  44004. '\x00\x00\x00\x00' + // minMemType42
  44005. '\x00\x00\x00\x00' + // maxMemType42
  44006. '\x00\x00\x00\x00' + // minMemType1
  44007. '\x00\x00\x00\x00';
  44008. }
  44009. // maxMemType1
  44010. function createNameTable(name, proto) {
  44011. if (!proto) {
  44012. proto = [
  44013. [],
  44014. []
  44015. ];
  44016. }
  44017. // no strings and unicode strings
  44018. var strings = [
  44019. proto[0][0] || 'Original licence',
  44020. // 0.Copyright
  44021. proto[0][1] || name,
  44022. // 1.Font family
  44023. proto[0][2] || 'Unknown',
  44024. // 2.Font subfamily (font weight)
  44025. proto[0][3] || 'uniqueID',
  44026. // 3.Unique ID
  44027. proto[0][4] || name,
  44028. // 4.Full font name
  44029. proto[0][5] || 'Version 0.11',
  44030. // 5.Version
  44031. proto[0][6] || '',
  44032. // 6.Postscript name
  44033. proto[0][7] || 'Unknown',
  44034. // 7.Trademark
  44035. proto[0][8] || 'Unknown',
  44036. // 8.Manufacturer
  44037. proto[0][9] || 'Unknown'
  44038. ];
  44039. // 9.Designer
  44040. // Mac want 1-byte per character strings while Windows want
  44041. // 2-bytes per character, so duplicate the names table
  44042. var stringsUnicode = [];
  44043. var i, ii, j, jj, str;
  44044. for (i = 0, ii = strings.length; i < ii; i++) {
  44045. str = proto[1][i] || strings[i];
  44046. var strBufUnicode = [];
  44047. for (j = 0, jj = str.length; j < jj; j++) {
  44048. strBufUnicode.push(string16(str.charCodeAt(j)));
  44049. }
  44050. stringsUnicode.push(strBufUnicode.join(''));
  44051. }
  44052. var names = [
  44053. strings,
  44054. stringsUnicode
  44055. ];
  44056. var platforms = [
  44057. '\x00\x01',
  44058. '\x00\x03'
  44059. ];
  44060. var encodings = [
  44061. '\x00\x00',
  44062. '\x00\x01'
  44063. ];
  44064. var languages = [
  44065. '\x00\x00',
  44066. '\x04\x09'
  44067. ];
  44068. var namesRecordCount = strings.length * platforms.length;
  44069. var nameTable = '\x00\x00' + // format
  44070. string16(namesRecordCount) + // Number of names Record
  44071. string16(namesRecordCount * 12 + 6);
  44072. // Storage
  44073. // Build the name records field
  44074. var strOffset = 0;
  44075. for (i = 0, ii = platforms.length; i < ii; i++) {
  44076. var strs = names[i];
  44077. for (j = 0, jj = strs.length; j < jj; j++) {
  44078. str = strs[j];
  44079. var nameRecord = platforms[i] + // platform ID
  44080. encodings[i] + // encoding ID
  44081. languages[i] + // language ID
  44082. string16(j) + // name ID
  44083. string16(str.length) + string16(strOffset);
  44084. nameTable += nameRecord;
  44085. strOffset += str.length;
  44086. }
  44087. }
  44088. nameTable += strings.join('') + stringsUnicode.join('');
  44089. return nameTable;
  44090. }
  44091. Font.prototype = {
  44092. name: null,
  44093. font: null,
  44094. mimetype: null,
  44095. encoding: null,
  44096. get renderer() {
  44097. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  44098. return shadow(this, 'renderer', renderer);
  44099. },
  44100. exportData: function Font_exportData() {
  44101. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  44102. var data = {};
  44103. for (var i in this) {
  44104. if (this.hasOwnProperty(i)) {
  44105. data[i] = this[i];
  44106. }
  44107. }
  44108. return data;
  44109. },
  44110. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  44111. function readTableEntry(file) {
  44112. var tag = bytesToString(file.getBytes(4));
  44113. var checksum = file.getInt32() >>> 0;
  44114. var offset = file.getInt32() >>> 0;
  44115. var length = file.getInt32() >>> 0;
  44116. // Read the table associated data
  44117. var previousPosition = file.pos;
  44118. file.pos = file.start ? file.start : 0;
  44119. file.skip(offset);
  44120. var data = file.getBytes(length);
  44121. file.pos = previousPosition;
  44122. if (tag === 'head') {
  44123. // clearing checksum adjustment
  44124. data[8] = data[9] = data[10] = data[11] = 0;
  44125. data[17] |= 0x20;
  44126. }
  44127. //Set font optimized for cleartype flag
  44128. return {
  44129. tag: tag,
  44130. checksum: checksum,
  44131. length: length,
  44132. offset: offset,
  44133. data: data
  44134. };
  44135. }
  44136. function readOpenTypeHeader(ttf) {
  44137. return {
  44138. version: bytesToString(ttf.getBytes(4)),
  44139. numTables: ttf.getUint16(),
  44140. searchRange: ttf.getUint16(),
  44141. entrySelector: ttf.getUint16(),
  44142. rangeShift: ttf.getUint16()
  44143. };
  44144. }
  44145. /**
  44146. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  44147. * PDF spec
  44148. */
  44149. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  44150. if (!cmap) {
  44151. warn('No cmap table available.');
  44152. return {
  44153. platformId: -1,
  44154. encodingId: -1,
  44155. mappings: [],
  44156. hasShortCmap: false
  44157. };
  44158. }
  44159. var segment;
  44160. var start = (font.start ? font.start : 0) + cmap.offset;
  44161. font.pos = start;
  44162. var version = font.getUint16();
  44163. var numTables = font.getUint16();
  44164. var potentialTable;
  44165. var canBreak = false;
  44166. // There's an order of preference in terms of which cmap subtable to
  44167. // use:
  44168. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  44169. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  44170. // The following takes advantage of the fact that the tables are sorted
  44171. // to work.
  44172. for (var i = 0; i < numTables; i++) {
  44173. var platformId = font.getUint16();
  44174. var encodingId = font.getUint16();
  44175. var offset = font.getInt32() >>> 0;
  44176. var useTable = false;
  44177. if (platformId === 0 && encodingId === 0) {
  44178. useTable = true;
  44179. } else // Continue the loop since there still may be a higher priority
  44180. // table.
  44181. if (platformId === 1 && encodingId === 0) {
  44182. useTable = true;
  44183. } else // Continue the loop since there still may be a higher priority
  44184. // table.
  44185. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  44186. useTable = true;
  44187. if (!isSymbolicFont) {
  44188. canBreak = true;
  44189. }
  44190. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  44191. useTable = true;
  44192. canBreak = true;
  44193. }
  44194. if (useTable) {
  44195. potentialTable = {
  44196. platformId: platformId,
  44197. encodingId: encodingId,
  44198. offset: offset
  44199. };
  44200. }
  44201. if (canBreak) {
  44202. break;
  44203. }
  44204. }
  44205. if (potentialTable) {
  44206. font.pos = start + potentialTable.offset;
  44207. }
  44208. if (!potentialTable || font.peekByte() === -1) {
  44209. warn('Could not find a preferred cmap table.');
  44210. return {
  44211. platformId: -1,
  44212. encodingId: -1,
  44213. mappings: [],
  44214. hasShortCmap: false
  44215. };
  44216. }
  44217. var format = font.getUint16();
  44218. var length = font.getUint16();
  44219. var language = font.getUint16();
  44220. var hasShortCmap = false;
  44221. var mappings = [];
  44222. var j, glyphId;
  44223. // TODO(mack): refactor this cmap subtable reading logic out
  44224. if (format === 0) {
  44225. for (j = 0; j < 256; j++) {
  44226. var index = font.getByte();
  44227. if (!index) {
  44228. continue;
  44229. }
  44230. mappings.push({
  44231. charCode: j,
  44232. glyphId: index
  44233. });
  44234. }
  44235. hasShortCmap = true;
  44236. } else if (format === 4) {
  44237. // re-creating the table in format 4 since the encoding
  44238. // might be changed
  44239. var segCount = font.getUint16() >> 1;
  44240. font.getBytes(6);
  44241. // skipping range fields
  44242. var segIndex, segments = [];
  44243. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44244. segments.push({ end: font.getUint16() });
  44245. }
  44246. font.getUint16();
  44247. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44248. segments[segIndex].start = font.getUint16();
  44249. }
  44250. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44251. segments[segIndex].delta = font.getUint16();
  44252. }
  44253. var offsetsCount = 0;
  44254. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44255. segment = segments[segIndex];
  44256. var rangeOffset = font.getUint16();
  44257. if (!rangeOffset) {
  44258. segment.offsetIndex = -1;
  44259. continue;
  44260. }
  44261. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  44262. segment.offsetIndex = offsetIndex;
  44263. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  44264. }
  44265. var offsets = [];
  44266. for (j = 0; j < offsetsCount; j++) {
  44267. offsets.push(font.getUint16());
  44268. }
  44269. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44270. segment = segments[segIndex];
  44271. start = segment.start;
  44272. var end = segment.end;
  44273. var delta = segment.delta;
  44274. offsetIndex = segment.offsetIndex;
  44275. for (j = start; j <= end; j++) {
  44276. if (j === 0xFFFF) {
  44277. continue;
  44278. }
  44279. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  44280. glyphId = glyphId + delta & 0xFFFF;
  44281. if (glyphId === 0) {
  44282. continue;
  44283. }
  44284. mappings.push({
  44285. charCode: j,
  44286. glyphId: glyphId
  44287. });
  44288. }
  44289. }
  44290. } else if (format === 6) {
  44291. // Format 6 is a 2-bytes dense mapping, which means the font data
  44292. // lives glue together even if they are pretty far in the unicode
  44293. // table. (This looks weird, so I can have missed something), this
  44294. // works on Linux but seems to fails on Mac so let's rewrite the
  44295. // cmap table to a 3-1-4 style
  44296. var firstCode = font.getUint16();
  44297. var entryCount = font.getUint16();
  44298. for (j = 0; j < entryCount; j++) {
  44299. glyphId = font.getUint16();
  44300. var charCode = firstCode + j;
  44301. mappings.push({
  44302. charCode: charCode,
  44303. glyphId: glyphId
  44304. });
  44305. }
  44306. } else {
  44307. warn('cmap table has unsupported format: ' + format);
  44308. return {
  44309. platformId: -1,
  44310. encodingId: -1,
  44311. mappings: [],
  44312. hasShortCmap: false
  44313. };
  44314. }
  44315. // removing duplicate entries
  44316. mappings.sort(function (a, b) {
  44317. return a.charCode - b.charCode;
  44318. });
  44319. for (i = 1; i < mappings.length; i++) {
  44320. if (mappings[i - 1].charCode === mappings[i].charCode) {
  44321. mappings.splice(i, 1);
  44322. i--;
  44323. }
  44324. }
  44325. return {
  44326. platformId: potentialTable.platformId,
  44327. encodingId: potentialTable.encodingId,
  44328. mappings: mappings,
  44329. hasShortCmap: hasShortCmap
  44330. };
  44331. }
  44332. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  44333. if (!header) {
  44334. if (metrics) {
  44335. metrics.data = null;
  44336. }
  44337. return;
  44338. }
  44339. font.pos = (font.start ? font.start : 0) + header.offset;
  44340. font.pos += header.length - 2;
  44341. var numOfMetrics = font.getUint16();
  44342. if (numOfMetrics > numGlyphs) {
  44343. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  44344. // Reduce numOfMetrics if it is greater than numGlyphs
  44345. numOfMetrics = numGlyphs;
  44346. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  44347. header.data[35] = numOfMetrics & 0x00ff;
  44348. }
  44349. var numOfSidebearings = numGlyphs - numOfMetrics;
  44350. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  44351. if (numMissing > 0) {
  44352. // For each missing glyph, we set both the width and lsb to 0 (zero).
  44353. // Since we need to add two properties for each glyph, this explains
  44354. // the use of |numMissing * 2| when initializing the typed array.
  44355. var entries = new Uint8Array(metrics.length + numMissing * 2);
  44356. entries.set(metrics.data);
  44357. metrics.data = entries;
  44358. }
  44359. }
  44360. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  44361. if (sourceEnd - sourceStart <= 12) {
  44362. // glyph with data less than 12 is invalid one
  44363. return 0;
  44364. }
  44365. var glyf = source.subarray(sourceStart, sourceEnd);
  44366. var contoursCount = glyf[0] << 8 | glyf[1];
  44367. if (contoursCount & 0x8000) {
  44368. // complex glyph, writing as is
  44369. dest.set(glyf, destStart);
  44370. return glyf.length;
  44371. }
  44372. var i, j = 10, flagsCount = 0;
  44373. for (i = 0; i < contoursCount; i++) {
  44374. var endPoint = glyf[j] << 8 | glyf[j + 1];
  44375. flagsCount = endPoint + 1;
  44376. j += 2;
  44377. }
  44378. // skipping instructions
  44379. var instructionsStart = j;
  44380. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  44381. j += 2 + instructionsLength;
  44382. var instructionsEnd = j;
  44383. // validating flags
  44384. var coordinatesLength = 0;
  44385. for (i = 0; i < flagsCount; i++) {
  44386. var flag = glyf[j++];
  44387. if (flag & 0xC0) {
  44388. // reserved flags must be zero, cleaning up
  44389. glyf[j - 1] = flag & 0x3F;
  44390. }
  44391. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  44392. coordinatesLength += xyLength;
  44393. if (flag & 8) {
  44394. var repeat = glyf[j++];
  44395. i += repeat;
  44396. coordinatesLength += repeat * xyLength;
  44397. }
  44398. }
  44399. // glyph without coordinates will be rejected
  44400. if (coordinatesLength === 0) {
  44401. return 0;
  44402. }
  44403. var glyphDataLength = j + coordinatesLength;
  44404. if (glyphDataLength > glyf.length) {
  44405. // not enough data for coordinates
  44406. return 0;
  44407. }
  44408. if (!hintsValid && instructionsLength > 0) {
  44409. dest.set(glyf.subarray(0, instructionsStart), destStart);
  44410. dest.set([
  44411. 0,
  44412. 0
  44413. ], destStart + instructionsStart);
  44414. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  44415. glyphDataLength -= instructionsLength;
  44416. if (glyf.length - glyphDataLength > 3) {
  44417. glyphDataLength = glyphDataLength + 3 & ~3;
  44418. }
  44419. return glyphDataLength;
  44420. }
  44421. if (glyf.length - glyphDataLength > 3) {
  44422. // truncating and aligning to 4 bytes the long glyph data
  44423. glyphDataLength = glyphDataLength + 3 & ~3;
  44424. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  44425. return glyphDataLength;
  44426. }
  44427. // glyph data is fine
  44428. dest.set(glyf, destStart);
  44429. return glyf.length;
  44430. }
  44431. function sanitizeHead(head, numGlyphs, locaLength) {
  44432. var data = head.data;
  44433. // Validate version:
  44434. // Should always be 0x00010000
  44435. var version = int32(data[0], data[1], data[2], data[3]);
  44436. if (version >> 16 !== 1) {
  44437. info('Attempting to fix invalid version in head table: ' + version);
  44438. data[0] = 0;
  44439. data[1] = 1;
  44440. data[2] = 0;
  44441. data[3] = 0;
  44442. }
  44443. var indexToLocFormat = int16(data[50], data[51]);
  44444. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  44445. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  44446. // The value of indexToLocFormat should be 0 if the loca table
  44447. // consists of short offsets, and should be 1 if the loca table
  44448. // consists of long offsets.
  44449. //
  44450. // The number of entries in the loca table should be numGlyphs + 1.
  44451. //
  44452. // Using this information, we can work backwards to deduce if the
  44453. // size of each offset in the loca table, and thus figure out the
  44454. // appropriate value for indexToLocFormat.
  44455. var numGlyphsPlusOne = numGlyphs + 1;
  44456. if (locaLength === numGlyphsPlusOne << 1) {
  44457. // 0x0000 indicates the loca table consists of short offsets
  44458. data[50] = 0;
  44459. data[51] = 0;
  44460. } else if (locaLength === numGlyphsPlusOne << 2) {
  44461. // 0x0001 indicates the loca table consists of long offsets
  44462. data[50] = 0;
  44463. data[51] = 1;
  44464. } else {
  44465. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  44466. }
  44467. }
  44468. }
  44469. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  44470. var itemSize, itemDecode, itemEncode;
  44471. if (isGlyphLocationsLong) {
  44472. itemSize = 4;
  44473. itemDecode = function fontItemDecodeLong(data, offset) {
  44474. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  44475. };
  44476. itemEncode = function fontItemEncodeLong(data, offset, value) {
  44477. data[offset] = value >>> 24 & 0xFF;
  44478. data[offset + 1] = value >> 16 & 0xFF;
  44479. data[offset + 2] = value >> 8 & 0xFF;
  44480. data[offset + 3] = value & 0xFF;
  44481. };
  44482. } else {
  44483. itemSize = 2;
  44484. itemDecode = function fontItemDecode(data, offset) {
  44485. return data[offset] << 9 | data[offset + 1] << 1;
  44486. };
  44487. itemEncode = function fontItemEncode(data, offset, value) {
  44488. data[offset] = value >> 9 & 0xFF;
  44489. data[offset + 1] = value >> 1 & 0xFF;
  44490. };
  44491. }
  44492. var locaData = loca.data;
  44493. var locaDataSize = itemSize * (1 + numGlyphs);
  44494. // is loca.data too short or long?
  44495. if (locaData.length !== locaDataSize) {
  44496. locaData = new Uint8Array(locaDataSize);
  44497. locaData.set(loca.data.subarray(0, locaDataSize));
  44498. loca.data = locaData;
  44499. }
  44500. // removing the invalid glyphs
  44501. var oldGlyfData = glyf.data;
  44502. var oldGlyfDataLength = oldGlyfData.length;
  44503. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  44504. var startOffset = itemDecode(locaData, 0);
  44505. var writeOffset = 0;
  44506. var missingGlyphData = Object.create(null);
  44507. itemEncode(locaData, 0, writeOffset);
  44508. var i, j;
  44509. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  44510. var endOffset = itemDecode(locaData, j);
  44511. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  44512. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  44513. // the glyf table size, which makes last glyph out of range.
  44514. endOffset = oldGlyfDataLength;
  44515. }
  44516. if (endOffset > oldGlyfDataLength) {
  44517. // glyph end offset points outside glyf data, rejecting the glyph
  44518. itemEncode(locaData, j, writeOffset);
  44519. startOffset = endOffset;
  44520. continue;
  44521. }
  44522. if (startOffset === endOffset) {
  44523. missingGlyphData[i] = true;
  44524. }
  44525. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  44526. writeOffset += newLength;
  44527. itemEncode(locaData, j, writeOffset);
  44528. startOffset = endOffset;
  44529. }
  44530. if (writeOffset === 0) {
  44531. // glyf table cannot be empty -- redoing the glyf and loca tables
  44532. // to have single glyph with one point
  44533. var simpleGlyph = new Uint8Array([
  44534. 0,
  44535. 1,
  44536. 0,
  44537. 0,
  44538. 0,
  44539. 0,
  44540. 0,
  44541. 0,
  44542. 0,
  44543. 0,
  44544. 0,
  44545. 0,
  44546. 0,
  44547. 0,
  44548. 49,
  44549. 0
  44550. ]);
  44551. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  44552. itemEncode(locaData, j, simpleGlyph.length);
  44553. }
  44554. glyf.data = simpleGlyph;
  44555. return missingGlyphData;
  44556. }
  44557. if (dupFirstEntry) {
  44558. var firstEntryLength = itemDecode(locaData, itemSize);
  44559. if (newGlyfData.length > firstEntryLength + writeOffset) {
  44560. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  44561. } else {
  44562. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  44563. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  44564. }
  44565. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  44566. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  44567. } else {
  44568. glyf.data = newGlyfData.subarray(0, writeOffset);
  44569. }
  44570. return missingGlyphData;
  44571. }
  44572. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  44573. var start = (font.start ? font.start : 0) + post.offset;
  44574. font.pos = start;
  44575. var length = post.length, end = start + length;
  44576. var version = font.getInt32();
  44577. // skip rest to the tables
  44578. font.getBytes(28);
  44579. var glyphNames;
  44580. var valid = true;
  44581. var i;
  44582. switch (version) {
  44583. case 0x00010000:
  44584. glyphNames = MacStandardGlyphOrdering;
  44585. break;
  44586. case 0x00020000:
  44587. var numGlyphs = font.getUint16();
  44588. if (numGlyphs !== maxpNumGlyphs) {
  44589. valid = false;
  44590. break;
  44591. }
  44592. var glyphNameIndexes = [];
  44593. for (i = 0; i < numGlyphs; ++i) {
  44594. var index = font.getUint16();
  44595. if (index >= 32768) {
  44596. valid = false;
  44597. break;
  44598. }
  44599. glyphNameIndexes.push(index);
  44600. }
  44601. if (!valid) {
  44602. break;
  44603. }
  44604. var customNames = [];
  44605. var strBuf = [];
  44606. while (font.pos < end) {
  44607. var stringLength = font.getByte();
  44608. strBuf.length = stringLength;
  44609. for (i = 0; i < stringLength; ++i) {
  44610. strBuf[i] = String.fromCharCode(font.getByte());
  44611. }
  44612. customNames.push(strBuf.join(''));
  44613. }
  44614. glyphNames = [];
  44615. for (i = 0; i < numGlyphs; ++i) {
  44616. var j = glyphNameIndexes[i];
  44617. if (j < 258) {
  44618. glyphNames.push(MacStandardGlyphOrdering[j]);
  44619. continue;
  44620. }
  44621. glyphNames.push(customNames[j - 258]);
  44622. }
  44623. break;
  44624. case 0x00030000:
  44625. break;
  44626. default:
  44627. warn('Unknown/unsupported post table version ' + version);
  44628. valid = false;
  44629. if (properties.defaultEncoding) {
  44630. glyphNames = properties.defaultEncoding;
  44631. }
  44632. break;
  44633. }
  44634. properties.glyphNames = glyphNames;
  44635. return valid;
  44636. }
  44637. function readNameTable(nameTable) {
  44638. var start = (font.start ? font.start : 0) + nameTable.offset;
  44639. font.pos = start;
  44640. var names = [
  44641. [],
  44642. []
  44643. ];
  44644. var length = nameTable.length, end = start + length;
  44645. var format = font.getUint16();
  44646. var FORMAT_0_HEADER_LENGTH = 6;
  44647. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  44648. // unsupported name table format or table "too" small
  44649. return names;
  44650. }
  44651. var numRecords = font.getUint16();
  44652. var stringsStart = font.getUint16();
  44653. var records = [];
  44654. var NAME_RECORD_LENGTH = 12;
  44655. var i, ii;
  44656. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  44657. var r = {
  44658. platform: font.getUint16(),
  44659. encoding: font.getUint16(),
  44660. language: font.getUint16(),
  44661. name: font.getUint16(),
  44662. length: font.getUint16(),
  44663. offset: font.getUint16()
  44664. };
  44665. // using only Macintosh and Windows platform/encoding names
  44666. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  44667. records.push(r);
  44668. }
  44669. }
  44670. for (i = 0, ii = records.length; i < ii; i++) {
  44671. var record = records[i];
  44672. if (record.length <= 0) {
  44673. continue;
  44674. }
  44675. // Nothing to process, ignoring.
  44676. var pos = start + stringsStart + record.offset;
  44677. if (pos + record.length > end) {
  44678. continue;
  44679. }
  44680. // outside of name table, ignoring
  44681. font.pos = pos;
  44682. var nameIndex = record.name;
  44683. if (record.encoding) {
  44684. // unicode
  44685. var str = '';
  44686. for (var j = 0, jj = record.length; j < jj; j += 2) {
  44687. str += String.fromCharCode(font.getUint16());
  44688. }
  44689. names[1][nameIndex] = str;
  44690. } else {
  44691. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  44692. }
  44693. }
  44694. return names;
  44695. }
  44696. var TTOpsStackDeltas = [
  44697. 0,
  44698. 0,
  44699. 0,
  44700. 0,
  44701. 0,
  44702. 0,
  44703. 0,
  44704. 0,
  44705. -2,
  44706. -2,
  44707. -2,
  44708. -2,
  44709. 0,
  44710. 0,
  44711. -2,
  44712. -5,
  44713. -1,
  44714. -1,
  44715. -1,
  44716. -1,
  44717. -1,
  44718. -1,
  44719. -1,
  44720. -1,
  44721. 0,
  44722. 0,
  44723. -1,
  44724. 0,
  44725. -1,
  44726. -1,
  44727. -1,
  44728. -1,
  44729. 1,
  44730. -1,
  44731. -999,
  44732. 0,
  44733. 1,
  44734. 0,
  44735. -1,
  44736. -2,
  44737. 0,
  44738. -1,
  44739. -2,
  44740. -1,
  44741. -1,
  44742. 0,
  44743. -1,
  44744. -1,
  44745. 0,
  44746. 0,
  44747. -999,
  44748. -999,
  44749. -1,
  44750. -1,
  44751. -1,
  44752. -1,
  44753. -2,
  44754. -999,
  44755. -2,
  44756. -2,
  44757. -999,
  44758. 0,
  44759. -2,
  44760. -2,
  44761. 0,
  44762. 0,
  44763. -2,
  44764. 0,
  44765. -2,
  44766. 0,
  44767. 0,
  44768. 0,
  44769. -2,
  44770. -1,
  44771. -1,
  44772. 1,
  44773. 1,
  44774. 0,
  44775. 0,
  44776. -1,
  44777. -1,
  44778. -1,
  44779. -1,
  44780. -1,
  44781. -1,
  44782. -1,
  44783. 0,
  44784. 0,
  44785. -1,
  44786. 0,
  44787. -1,
  44788. -1,
  44789. 0,
  44790. -999,
  44791. -1,
  44792. -1,
  44793. -1,
  44794. -1,
  44795. -1,
  44796. -1,
  44797. 0,
  44798. 0,
  44799. 0,
  44800. 0,
  44801. 0,
  44802. 0,
  44803. 0,
  44804. 0,
  44805. 0,
  44806. 0,
  44807. 0,
  44808. 0,
  44809. -2,
  44810. -999,
  44811. -999,
  44812. -999,
  44813. -999,
  44814. -999,
  44815. -1,
  44816. -1,
  44817. -2,
  44818. -2,
  44819. 0,
  44820. 0,
  44821. 0,
  44822. 0,
  44823. -1,
  44824. -1,
  44825. -999,
  44826. -2,
  44827. -2,
  44828. 0,
  44829. 0,
  44830. -1,
  44831. -2,
  44832. -2,
  44833. 0,
  44834. 0,
  44835. 0,
  44836. -1,
  44837. -1,
  44838. -1,
  44839. -2
  44840. ];
  44841. // 0xC0-DF == -1 and 0xE0-FF == -2
  44842. function sanitizeTTProgram(table, ttContext) {
  44843. var data = table.data;
  44844. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  44845. var stack = [];
  44846. var callstack = [];
  44847. var functionsCalled = [];
  44848. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  44849. var inFDEF = false, ifLevel = 0, inELSE = 0;
  44850. for (var ii = data.length; i < ii;) {
  44851. var op = data[i++];
  44852. // The TrueType instruction set docs can be found at
  44853. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  44854. if (op === 0x40) {
  44855. // NPUSHB - pushes n bytes
  44856. n = data[i++];
  44857. if (inFDEF || inELSE) {
  44858. i += n;
  44859. } else {
  44860. for (j = 0; j < n; j++) {
  44861. stack.push(data[i++]);
  44862. }
  44863. }
  44864. } else if (op === 0x41) {
  44865. // NPUSHW - pushes n words
  44866. n = data[i++];
  44867. if (inFDEF || inELSE) {
  44868. i += n * 2;
  44869. } else {
  44870. for (j = 0; j < n; j++) {
  44871. b = data[i++];
  44872. stack.push(b << 8 | data[i++]);
  44873. }
  44874. }
  44875. } else if ((op & 0xF8) === 0xB0) {
  44876. // PUSHB - pushes bytes
  44877. n = op - 0xB0 + 1;
  44878. if (inFDEF || inELSE) {
  44879. i += n;
  44880. } else {
  44881. for (j = 0; j < n; j++) {
  44882. stack.push(data[i++]);
  44883. }
  44884. }
  44885. } else if ((op & 0xF8) === 0xB8) {
  44886. // PUSHW - pushes words
  44887. n = op - 0xB8 + 1;
  44888. if (inFDEF || inELSE) {
  44889. i += n * 2;
  44890. } else {
  44891. for (j = 0; j < n; j++) {
  44892. b = data[i++];
  44893. stack.push(b << 8 | data[i++]);
  44894. }
  44895. }
  44896. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  44897. // CALL
  44898. if (!inFDEF && !inELSE) {
  44899. // collecting inforamtion about which functions are used
  44900. funcId = stack[stack.length - 1];
  44901. ttContext.functionsUsed[funcId] = true;
  44902. if (funcId in ttContext.functionsStackDeltas) {
  44903. stack.length += ttContext.functionsStackDeltas[funcId];
  44904. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  44905. callstack.push({
  44906. data: data,
  44907. i: i,
  44908. stackTop: stack.length - 1
  44909. });
  44910. functionsCalled.push(funcId);
  44911. pc = ttContext.functionsDefined[funcId];
  44912. if (!pc) {
  44913. warn('TT: CALL non-existent function');
  44914. ttContext.hintsValid = false;
  44915. return;
  44916. }
  44917. data = pc.data;
  44918. i = pc.i;
  44919. }
  44920. }
  44921. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  44922. // FDEF
  44923. if (inFDEF || inELSE) {
  44924. warn('TT: nested FDEFs not allowed');
  44925. tooComplexToFollowFunctions = true;
  44926. }
  44927. inFDEF = true;
  44928. // collecting inforamtion about which functions are defined
  44929. lastDeff = i;
  44930. funcId = stack.pop();
  44931. ttContext.functionsDefined[funcId] = {
  44932. data: data,
  44933. i: i
  44934. };
  44935. } else if (op === 0x2D) {
  44936. // ENDF - end of function
  44937. if (inFDEF) {
  44938. inFDEF = false;
  44939. lastEndf = i;
  44940. } else {
  44941. pc = callstack.pop();
  44942. if (!pc) {
  44943. warn('TT: ENDF bad stack');
  44944. ttContext.hintsValid = false;
  44945. return;
  44946. }
  44947. funcId = functionsCalled.pop();
  44948. data = pc.data;
  44949. i = pc.i;
  44950. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  44951. }
  44952. } else if (op === 0x89) {
  44953. // IDEF - instruction definition
  44954. if (inFDEF || inELSE) {
  44955. warn('TT: nested IDEFs not allowed');
  44956. tooComplexToFollowFunctions = true;
  44957. }
  44958. inFDEF = true;
  44959. // recording it as a function to track ENDF
  44960. lastDeff = i;
  44961. } else if (op === 0x58) {
  44962. // IF
  44963. ++ifLevel;
  44964. } else if (op === 0x1B) {
  44965. // ELSE
  44966. inELSE = ifLevel;
  44967. } else if (op === 0x59) {
  44968. // EIF
  44969. if (inELSE === ifLevel) {
  44970. inELSE = 0;
  44971. }
  44972. --ifLevel;
  44973. } else if (op === 0x1C) {
  44974. // JMPR
  44975. if (!inFDEF && !inELSE) {
  44976. var offset = stack[stack.length - 1];
  44977. // only jumping forward to prevent infinite loop
  44978. if (offset > 0) {
  44979. i += offset - 1;
  44980. }
  44981. }
  44982. }
  44983. // Adjusting stack not extactly, but just enough to get function id
  44984. if (!inFDEF && !inELSE) {
  44985. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  44986. if (op >= 0x71 && op <= 0x75) {
  44987. n = stack.pop();
  44988. if (n === n) {
  44989. stackDelta = -n * 2;
  44990. }
  44991. }
  44992. while (stackDelta < 0 && stack.length > 0) {
  44993. stack.pop();
  44994. stackDelta++;
  44995. }
  44996. while (stackDelta > 0) {
  44997. stack.push(NaN);
  44998. // pushing any number into stack
  44999. stackDelta--;
  45000. }
  45001. }
  45002. }
  45003. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  45004. var content = [data];
  45005. if (i > data.length) {
  45006. content.push(new Uint8Array(i - data.length));
  45007. }
  45008. if (lastDeff > lastEndf) {
  45009. warn('TT: complementing a missing function tail');
  45010. // new function definition started, but not finished
  45011. // complete function by [CLEAR, ENDF]
  45012. content.push(new Uint8Array([
  45013. 0x22,
  45014. 0x2D
  45015. ]));
  45016. }
  45017. foldTTTable(table, content);
  45018. }
  45019. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  45020. if (ttContext.tooComplexToFollowFunctions) {
  45021. return;
  45022. }
  45023. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  45024. warn('TT: more functions defined than expected');
  45025. ttContext.hintsValid = false;
  45026. return;
  45027. }
  45028. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  45029. if (j > maxFunctionDefs) {
  45030. warn('TT: invalid function id: ' + j);
  45031. ttContext.hintsValid = false;
  45032. return;
  45033. }
  45034. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  45035. warn('TT: undefined function: ' + j);
  45036. ttContext.hintsValid = false;
  45037. return;
  45038. }
  45039. }
  45040. }
  45041. function foldTTTable(table, content) {
  45042. if (content.length > 1) {
  45043. // concatenating the content items
  45044. var newLength = 0;
  45045. var j, jj;
  45046. for (j = 0, jj = content.length; j < jj; j++) {
  45047. newLength += content[j].length;
  45048. }
  45049. newLength = newLength + 3 & ~3;
  45050. var result = new Uint8Array(newLength);
  45051. var pos = 0;
  45052. for (j = 0, jj = content.length; j < jj; j++) {
  45053. result.set(content[j], pos);
  45054. pos += content[j].length;
  45055. }
  45056. table.data = result;
  45057. table.length = newLength;
  45058. }
  45059. }
  45060. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  45061. var ttContext = {
  45062. functionsDefined: [],
  45063. functionsUsed: [],
  45064. functionsStackDeltas: [],
  45065. tooComplexToFollowFunctions: false,
  45066. hintsValid: true
  45067. };
  45068. if (fpgm) {
  45069. sanitizeTTProgram(fpgm, ttContext);
  45070. }
  45071. if (prep) {
  45072. sanitizeTTProgram(prep, ttContext);
  45073. }
  45074. if (fpgm) {
  45075. checkInvalidFunctions(ttContext, maxFunctionDefs);
  45076. }
  45077. if (cvt && cvt.length & 1) {
  45078. var cvtData = new Uint8Array(cvt.length + 1);
  45079. cvtData.set(cvt.data);
  45080. cvt.data = cvtData;
  45081. }
  45082. return ttContext.hintsValid;
  45083. }
  45084. // The following steps modify the original font data, making copy
  45085. font = new Stream(new Uint8Array(font.getBytes()));
  45086. var VALID_TABLES = [
  45087. 'OS/2',
  45088. 'cmap',
  45089. 'head',
  45090. 'hhea',
  45091. 'hmtx',
  45092. 'maxp',
  45093. 'name',
  45094. 'post',
  45095. 'loca',
  45096. 'glyf',
  45097. 'fpgm',
  45098. 'prep',
  45099. 'cvt ',
  45100. 'CFF '
  45101. ];
  45102. var header = readOpenTypeHeader(font);
  45103. var numTables = header.numTables;
  45104. var cff, cffFile;
  45105. var tables = Object.create(null);
  45106. tables['OS/2'] = null;
  45107. tables['cmap'] = null;
  45108. tables['head'] = null;
  45109. tables['hhea'] = null;
  45110. tables['hmtx'] = null;
  45111. tables['maxp'] = null;
  45112. tables['name'] = null;
  45113. tables['post'] = null;
  45114. var table;
  45115. for (var i = 0; i < numTables; i++) {
  45116. table = readTableEntry(font);
  45117. if (VALID_TABLES.indexOf(table.tag) < 0) {
  45118. continue;
  45119. }
  45120. // skipping table if it's not a required or optional table
  45121. if (table.length === 0) {
  45122. continue;
  45123. }
  45124. // skipping empty tables
  45125. tables[table.tag] = table;
  45126. }
  45127. var isTrueType = !tables['CFF '];
  45128. if (!isTrueType) {
  45129. // OpenType font
  45130. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  45131. // no major tables: throwing everything at CFFFont
  45132. cffFile = new Stream(tables['CFF '].data);
  45133. cff = new CFFFont(cffFile, properties);
  45134. adjustWidths(properties);
  45135. return this.convert(name, cff, properties);
  45136. }
  45137. delete tables['glyf'];
  45138. delete tables['loca'];
  45139. delete tables['fpgm'];
  45140. delete tables['prep'];
  45141. delete tables['cvt '];
  45142. this.isOpenType = true;
  45143. } else {
  45144. if (!tables['loca']) {
  45145. error('Required "loca" table is not found');
  45146. }
  45147. if (!tables['glyf']) {
  45148. warn('Required "glyf" table is not found -- trying to recover.');
  45149. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  45150. tables['glyf'] = {
  45151. tag: 'glyf',
  45152. data: new Uint8Array(0)
  45153. };
  45154. }
  45155. this.isOpenType = false;
  45156. }
  45157. if (!tables['maxp']) {
  45158. error('Required "maxp" table is not found');
  45159. }
  45160. font.pos = (font.start || 0) + tables['maxp'].offset;
  45161. var version = font.getInt32();
  45162. var numGlyphs = font.getUint16();
  45163. var maxFunctionDefs = 0;
  45164. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  45165. // maxZones can be invalid
  45166. font.pos += 8;
  45167. var maxZones = font.getUint16();
  45168. if (maxZones > 2) {
  45169. // reset to 2 if font has invalid maxZones
  45170. tables['maxp'].data[14] = 0;
  45171. tables['maxp'].data[15] = 2;
  45172. }
  45173. font.pos += 4;
  45174. maxFunctionDefs = font.getUint16();
  45175. }
  45176. var dupFirstEntry = false;
  45177. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  45178. // oracle's defect (see 3427), duplicating first entry
  45179. dupFirstEntry = true;
  45180. numGlyphs++;
  45181. tables['maxp'].data[4] = numGlyphs >> 8;
  45182. tables['maxp'].data[5] = numGlyphs & 255;
  45183. }
  45184. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  45185. if (!hintsValid) {
  45186. delete tables['fpgm'];
  45187. delete tables['prep'];
  45188. delete tables['cvt '];
  45189. }
  45190. // Ensure the hmtx table contains the advance width and
  45191. // sidebearings information for numGlyphs in the maxp table
  45192. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  45193. if (!tables['head']) {
  45194. error('Required "head" table is not found');
  45195. }
  45196. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  45197. var missingGlyphs = Object.create(null);
  45198. if (isTrueType) {
  45199. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  45200. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  45201. }
  45202. if (!tables['hhea']) {
  45203. error('Required "hhea" table is not found');
  45204. }
  45205. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  45206. // Sometimes it's 0. That needs to be fixed
  45207. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  45208. tables['hhea'].data[10] = 0xFF;
  45209. tables['hhea'].data[11] = 0xFF;
  45210. }
  45211. // Extract some more font properties from the OpenType head and
  45212. // hhea tables; yMin and descent value are always negative.
  45213. var metricsOverride = {
  45214. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  45215. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  45216. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  45217. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  45218. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  45219. };
  45220. // PDF FontDescriptor metrics lie -- using data from actual font.
  45221. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  45222. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  45223. // The 'post' table has glyphs names.
  45224. if (tables['post']) {
  45225. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  45226. if (!valid) {
  45227. tables['post'] = null;
  45228. }
  45229. }
  45230. var charCodeToGlyphId = [], charCode;
  45231. var toUnicode = properties.toUnicode, widths = properties.widths;
  45232. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  45233. // Helper function to try to skip mapping of empty glyphs.
  45234. // Note: In some cases, just relying on the glyph data doesn't work,
  45235. // hence we also use a few heuristics to fix various PDF files.
  45236. function hasGlyph(glyphId, charCode, widthCode) {
  45237. if (!missingGlyphs[glyphId]) {
  45238. return true;
  45239. }
  45240. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  45241. return true;
  45242. }
  45243. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  45244. return true;
  45245. }
  45246. return false;
  45247. }
  45248. if (properties.type === 'CIDFontType2') {
  45249. var cidToGidMap = properties.cidToGidMap || [];
  45250. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  45251. properties.cMap.forEach(function (charCode, cid) {
  45252. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  45253. var glyphId = -1;
  45254. if (isCidToGidMapEmpty) {
  45255. glyphId = cid;
  45256. } else if (cidToGidMap[cid] !== undefined) {
  45257. glyphId = cidToGidMap[cid];
  45258. }
  45259. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  45260. charCodeToGlyphId[charCode] = glyphId;
  45261. }
  45262. });
  45263. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  45264. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  45265. // if the font has a `CIDToGIDMap` which has already mapped the first
  45266. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  45267. charCodeToGlyphId[0] = numGlyphs - 1;
  45268. }
  45269. } else {
  45270. // Most of the following logic in this code branch is based on the
  45271. // 9.6.6.4 of the PDF spec.
  45272. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  45273. var cmapPlatformId = cmapTable.platformId;
  45274. var cmapEncodingId = cmapTable.encodingId;
  45275. var cmapMappings = cmapTable.mappings;
  45276. var cmapMappingsLength = cmapMappings.length;
  45277. // The spec seems to imply that if the font is symbolic the encoding
  45278. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  45279. // where the the font is symbolic and it has an encoding.
  45280. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  45281. !!getEncoding(properties.baseEncodingName)) {
  45282. // Temporary hack
  45283. // When no preferred cmap table was found and |baseEncodingName| is
  45284. // one of the predefined encodings, we seem to obtain a better
  45285. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  45286. // TODO: Note that this is a hack which should be removed as soon as
  45287. // we have proper support for more exotic cmap tables.
  45288. var baseEncoding = [];
  45289. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  45290. baseEncoding = getEncoding(properties.baseEncodingName);
  45291. }
  45292. var glyphsUnicodeMap = getGlyphsUnicode();
  45293. for (charCode = 0; charCode < 256; charCode++) {
  45294. var glyphName, standardGlyphName;
  45295. if (this.differences && charCode in this.differences) {
  45296. glyphName = this.differences[charCode];
  45297. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  45298. glyphName = baseEncoding[charCode];
  45299. } else {
  45300. glyphName = StandardEncoding[charCode];
  45301. }
  45302. if (!glyphName) {
  45303. continue;
  45304. }
  45305. // Ensure that non-standard glyph names are resolved to valid ones.
  45306. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  45307. var unicodeOrCharCode, isUnicode = false;
  45308. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  45309. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  45310. isUnicode = true;
  45311. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  45312. // TODO: the encoding needs to be updated with mac os table.
  45313. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  45314. }
  45315. var found = false;
  45316. for (i = 0; i < cmapMappingsLength; ++i) {
  45317. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  45318. continue;
  45319. }
  45320. var code = isUnicode ? charCode : unicodeOrCharCode;
  45321. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  45322. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  45323. found = true;
  45324. break;
  45325. }
  45326. }
  45327. if (!found && properties.glyphNames) {
  45328. // Try to map using the post table.
  45329. var glyphId = properties.glyphNames.indexOf(glyphName);
  45330. // The post table ought to use the same kind of glyph names as the
  45331. // `differences` array, but check the standard ones as a fallback.
  45332. if (glyphId === -1 && standardGlyphName !== glyphName) {
  45333. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  45334. }
  45335. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  45336. charCodeToGlyphId[charCode] = glyphId;
  45337. found = true;
  45338. }
  45339. }
  45340. if (!found) {
  45341. charCodeToGlyphId[charCode] = 0;
  45342. }
  45343. }
  45344. } else // notdef
  45345. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  45346. // Default Unicode semantics, use the charcodes as is.
  45347. for (i = 0; i < cmapMappingsLength; ++i) {
  45348. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  45349. }
  45350. } else {
  45351. // For (3, 0) cmap tables:
  45352. // The charcode key being stored in charCodeToGlyphId is the lower
  45353. // byte of the two-byte charcodes of the cmap table since according to
  45354. // the spec: 'each byte from the string shall be prepended with the
  45355. // high byte of the range [of charcodes in the cmap table], to form
  45356. // a two-byte character, which shall be used to select the
  45357. // associated glyph description from the subtable'.
  45358. //
  45359. // For (1, 0) cmap tables:
  45360. // 'single bytes from the string shall be used to look up the
  45361. // associated glyph descriptions from the subtable'. This means
  45362. // charcodes in the cmap will be single bytes, so no-op since
  45363. // glyph.charCode & 0xFF === glyph.charCode
  45364. for (i = 0; i < cmapMappingsLength; ++i) {
  45365. charCode = cmapMappings[i].charCode & 0xFF;
  45366. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  45367. }
  45368. }
  45369. }
  45370. if (charCodeToGlyphId.length === 0) {
  45371. // defines at least one glyph
  45372. charCodeToGlyphId[0] = 0;
  45373. }
  45374. // Converting glyphs and ids into font's cmap table
  45375. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  45376. this.toFontChar = newMapping.toFontChar;
  45377. tables['cmap'] = {
  45378. tag: 'cmap',
  45379. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  45380. };
  45381. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  45382. tables['OS/2'] = {
  45383. tag: 'OS/2',
  45384. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  45385. };
  45386. }
  45387. // Rewrite the 'post' table if needed
  45388. if (!tables['post']) {
  45389. tables['post'] = {
  45390. tag: 'post',
  45391. data: createPostTable(properties)
  45392. };
  45393. }
  45394. if (!isTrueType) {
  45395. try {
  45396. // Trying to repair CFF file
  45397. cffFile = new Stream(tables['CFF '].data);
  45398. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  45399. cff = parser.parse();
  45400. var compiler = new CFFCompiler(cff);
  45401. tables['CFF '].data = compiler.compile();
  45402. } catch (e) {
  45403. warn('Failed to compile font ' + properties.loadedName);
  45404. }
  45405. }
  45406. // Re-creating 'name' table
  45407. if (!tables['name']) {
  45408. tables['name'] = {
  45409. tag: 'name',
  45410. data: createNameTable(this.name)
  45411. };
  45412. } else {
  45413. // ... using existing 'name' table as prototype
  45414. var namePrototype = readNameTable(tables['name']);
  45415. tables['name'].data = createNameTable(name, namePrototype);
  45416. }
  45417. var builder = new OpenTypeFileBuilder(header.version);
  45418. for (var tableTag in tables) {
  45419. builder.addTable(tableTag, tables[tableTag].data);
  45420. }
  45421. return builder.toArray();
  45422. },
  45423. convert: function Font_convert(fontName, font, properties) {
  45424. // TODO: Check the charstring widths to determine this.
  45425. properties.fixedPitch = false;
  45426. if (properties.builtInEncoding) {
  45427. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  45428. // data, attempt to use the `builtInEncoding` to improve text selection.
  45429. adjustToUnicode(properties, properties.builtInEncoding);
  45430. }
  45431. var mapping = font.getGlyphMapping(properties);
  45432. var newMapping = adjustMapping(mapping, properties);
  45433. this.toFontChar = newMapping.toFontChar;
  45434. var numGlyphs = font.numGlyphs;
  45435. function getCharCodes(charCodeToGlyphId, glyphId) {
  45436. var charCodes = null;
  45437. for (var charCode in charCodeToGlyphId) {
  45438. if (glyphId === charCodeToGlyphId[charCode]) {
  45439. if (!charCodes) {
  45440. charCodes = [];
  45441. }
  45442. charCodes.push(charCode | 0);
  45443. }
  45444. }
  45445. return charCodes;
  45446. }
  45447. function createCharCode(charCodeToGlyphId, glyphId) {
  45448. for (var charCode in charCodeToGlyphId) {
  45449. if (glyphId === charCodeToGlyphId[charCode]) {
  45450. return charCode | 0;
  45451. }
  45452. }
  45453. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  45454. return newMapping.nextAvailableFontCharCode++;
  45455. }
  45456. var seacs = font.seacs;
  45457. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  45458. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  45459. var charset = font.getCharset();
  45460. var seacMap = Object.create(null);
  45461. for (var glyphId in seacs) {
  45462. glyphId |= 0;
  45463. var seac = seacs[glyphId];
  45464. var baseGlyphName = StandardEncoding[seac[2]];
  45465. var accentGlyphName = StandardEncoding[seac[3]];
  45466. var baseGlyphId = charset.indexOf(baseGlyphName);
  45467. var accentGlyphId = charset.indexOf(accentGlyphName);
  45468. if (baseGlyphId < 0 || accentGlyphId < 0) {
  45469. continue;
  45470. }
  45471. var accentOffset = {
  45472. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  45473. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  45474. };
  45475. var charCodes = getCharCodes(mapping, glyphId);
  45476. if (!charCodes) {
  45477. // There's no point in mapping it if the char code was never mapped
  45478. // to begin with.
  45479. continue;
  45480. }
  45481. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  45482. var charCode = charCodes[i];
  45483. // Find a fontCharCode that maps to the base and accent glyphs.
  45484. // If one doesn't exists, create it.
  45485. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  45486. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  45487. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  45488. seacMap[charCode] = {
  45489. baseFontCharCode: baseFontCharCode,
  45490. accentFontCharCode: accentFontCharCode,
  45491. accentOffset: accentOffset
  45492. };
  45493. }
  45494. }
  45495. properties.seacMap = seacMap;
  45496. }
  45497. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  45498. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  45499. // PostScript Font Program
  45500. builder.addTable('CFF ', font.data);
  45501. // OS/2 and Windows Specific metrics
  45502. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  45503. // Character to glyphs mapping
  45504. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  45505. // Font header
  45506. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  45507. '\x00\x00\x10\x00' + // fontRevision
  45508. '\x00\x00\x00\x00' + // checksumAdjustement
  45509. '\x5F\x0F\x3C\xF5' + // magicNumber
  45510. '\x00\x00' + // Flags
  45511. safeString16(unitsPerEm) + // unitsPerEM
  45512. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  45513. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  45514. '\x00\x00' + // xMin
  45515. safeString16(properties.descent) + // yMin
  45516. '\x0F\xFF' + // xMax
  45517. safeString16(properties.ascent) + // yMax
  45518. string16(properties.italicAngle ? 2 : 0) + // macStyle
  45519. '\x00\x11' + // lowestRecPPEM
  45520. '\x00\x00' + // fontDirectionHint
  45521. '\x00\x00' + // indexToLocFormat
  45522. '\x00\x00');
  45523. // glyphDataFormat
  45524. // Horizontal header
  45525. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  45526. safeString16(properties.ascent) + // Typographic Ascent
  45527. safeString16(properties.descent) + // Typographic Descent
  45528. '\x00\x00' + // Line Gap
  45529. '\xFF\xFF' + // advanceWidthMax
  45530. '\x00\x00' + // minLeftSidebearing
  45531. '\x00\x00' + // minRightSidebearing
  45532. '\x00\x00' + // xMaxExtent
  45533. safeString16(properties.capHeight) + // caretSlopeRise
  45534. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  45535. '\x00\x00' + // caretOffset
  45536. '\x00\x00' + // -reserved-
  45537. '\x00\x00' + // -reserved-
  45538. '\x00\x00' + // -reserved-
  45539. '\x00\x00' + // -reserved-
  45540. '\x00\x00' + // metricDataFormat
  45541. string16(numGlyphs));
  45542. // Number of HMetrics
  45543. // Horizontal metrics
  45544. builder.addTable('hmtx', function fontFieldsHmtx() {
  45545. var charstrings = font.charstrings;
  45546. var cffWidths = font.cff ? font.cff.widths : null;
  45547. var hmtx = '\x00\x00\x00\x00';
  45548. // Fake .notdef
  45549. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  45550. var width = 0;
  45551. if (charstrings) {
  45552. var charstring = charstrings[i - 1];
  45553. width = 'width' in charstring ? charstring.width : 0;
  45554. } else if (cffWidths) {
  45555. width = Math.ceil(cffWidths[i] || 0);
  45556. }
  45557. hmtx += string16(width) + string16(0);
  45558. }
  45559. return hmtx;
  45560. }());
  45561. // Maximum profile
  45562. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  45563. string16(numGlyphs));
  45564. // Num of glyphs
  45565. // Naming tables
  45566. builder.addTable('name', createNameTable(fontName));
  45567. // PostScript information
  45568. builder.addTable('post', createPostTable(properties));
  45569. return builder.toArray();
  45570. },
  45571. get spaceWidth() {
  45572. if ('_shadowWidth' in this) {
  45573. return this._shadowWidth;
  45574. }
  45575. // trying to estimate space character width
  45576. var possibleSpaceReplacements = [
  45577. 'space',
  45578. 'minus',
  45579. 'one',
  45580. 'i',
  45581. 'I'
  45582. ];
  45583. var width;
  45584. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  45585. var glyphName = possibleSpaceReplacements[i];
  45586. // if possible, getting width by glyph name
  45587. if (glyphName in this.widths) {
  45588. width = this.widths[glyphName];
  45589. break;
  45590. }
  45591. var glyphsUnicodeMap = getGlyphsUnicode();
  45592. var glyphUnicode = glyphsUnicodeMap[glyphName];
  45593. // finding the charcode via unicodeToCID map
  45594. var charcode = 0;
  45595. if (this.composite) {
  45596. if (this.cMap.contains(glyphUnicode)) {
  45597. charcode = this.cMap.lookup(glyphUnicode);
  45598. }
  45599. }
  45600. // ... via toUnicode map
  45601. if (!charcode && this.toUnicode) {
  45602. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  45603. }
  45604. // setting it to unicode if negative or undefined
  45605. if (charcode <= 0) {
  45606. charcode = glyphUnicode;
  45607. }
  45608. // trying to get width via charcode
  45609. width = this.widths[charcode];
  45610. if (width) {
  45611. break;
  45612. }
  45613. }
  45614. // the non-zero width found
  45615. width = width || this.defaultWidth;
  45616. // Do not shadow the property here. See discussion:
  45617. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  45618. this._shadowWidth = width;
  45619. return width;
  45620. },
  45621. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  45622. var fontCharCode, width, operatorListId;
  45623. var widthCode = charcode;
  45624. if (this.cMap && this.cMap.contains(charcode)) {
  45625. widthCode = this.cMap.lookup(charcode);
  45626. }
  45627. width = this.widths[widthCode];
  45628. width = isNum(width) ? width : this.defaultWidth;
  45629. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  45630. var unicode = this.toUnicode.get(charcode) || charcode;
  45631. if (typeof unicode === 'number') {
  45632. unicode = String.fromCharCode(unicode);
  45633. }
  45634. var isInFont = charcode in this.toFontChar;
  45635. // First try the toFontChar map, if it's not there then try falling
  45636. // back to the char code.
  45637. fontCharCode = this.toFontChar[charcode] || charcode;
  45638. if (this.missingFile) {
  45639. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  45640. }
  45641. if (this.isType3Font) {
  45642. // Font char code in this case is actually a glyph name.
  45643. operatorListId = fontCharCode;
  45644. }
  45645. var accent = null;
  45646. if (this.seacMap && this.seacMap[charcode]) {
  45647. isInFont = true;
  45648. var seac = this.seacMap[charcode];
  45649. fontCharCode = seac.baseFontCharCode;
  45650. accent = {
  45651. fontChar: String.fromCharCode(seac.accentFontCharCode),
  45652. offset: seac.accentOffset
  45653. };
  45654. }
  45655. var fontChar = String.fromCharCode(fontCharCode);
  45656. var glyph = this.glyphCache[charcode];
  45657. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  45658. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  45659. this.glyphCache[charcode] = glyph;
  45660. }
  45661. return glyph;
  45662. },
  45663. charsToGlyphs: function Font_charsToGlyphs(chars) {
  45664. var charsCache = this.charsCache;
  45665. var glyphs, glyph, charcode;
  45666. // if we translated this string before, just grab it from the cache
  45667. if (charsCache) {
  45668. glyphs = charsCache[chars];
  45669. if (glyphs) {
  45670. return glyphs;
  45671. }
  45672. }
  45673. // lazily create the translation cache
  45674. if (!charsCache) {
  45675. charsCache = this.charsCache = Object.create(null);
  45676. }
  45677. glyphs = [];
  45678. var charsCacheKey = chars;
  45679. var i = 0, ii;
  45680. if (this.cMap) {
  45681. // composite fonts have multi-byte strings convert the string from
  45682. // single-byte to multi-byte
  45683. var c = Object.create(null);
  45684. while (i < chars.length) {
  45685. this.cMap.readCharCode(chars, i, c);
  45686. charcode = c.charcode;
  45687. var length = c.length;
  45688. i += length;
  45689. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  45690. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  45691. glyph = this.charToGlyph(charcode, isSpace);
  45692. glyphs.push(glyph);
  45693. }
  45694. } else {
  45695. for (i = 0, ii = chars.length; i < ii; ++i) {
  45696. charcode = chars.charCodeAt(i);
  45697. glyph = this.charToGlyph(charcode, charcode === 0x20);
  45698. glyphs.push(glyph);
  45699. }
  45700. }
  45701. // Enter the translated string into the cache
  45702. return charsCache[charsCacheKey] = glyphs;
  45703. }
  45704. };
  45705. return Font;
  45706. }();
  45707. var ErrorFont = function ErrorFontClosure() {
  45708. function ErrorFont(error) {
  45709. this.error = error;
  45710. this.loadedName = 'g_font_error';
  45711. this.loading = false;
  45712. }
  45713. ErrorFont.prototype = {
  45714. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  45715. return [];
  45716. },
  45717. exportData: function ErrorFont_exportData() {
  45718. return { error: this.error };
  45719. }
  45720. };
  45721. return ErrorFont;
  45722. }();
  45723. /**
  45724. * Shared logic for building a char code to glyph id mapping for Type1 and
  45725. * simple CFF fonts. See section 9.6.6.2 of the spec.
  45726. * @param {Object} properties Font properties object.
  45727. * @param {Object} builtInEncoding The encoding contained within the actual font
  45728. * data.
  45729. * @param {Array} glyphNames Array of glyph names where the index is the
  45730. * glyph ID.
  45731. * @returns {Object} A char code to glyph ID map.
  45732. */
  45733. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  45734. var charCodeToGlyphId = Object.create(null);
  45735. var glyphId, charCode, baseEncoding;
  45736. if (properties.baseEncodingName) {
  45737. // If a valid base encoding name was used, the mapping is initialized with
  45738. // that.
  45739. baseEncoding = getEncoding(properties.baseEncodingName);
  45740. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  45741. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  45742. if (glyphId >= 0) {
  45743. charCodeToGlyphId[charCode] = glyphId;
  45744. } else {
  45745. charCodeToGlyphId[charCode] = 0;
  45746. }
  45747. }
  45748. } else // notdef
  45749. if (!!(properties.flags & FontFlags.Symbolic)) {
  45750. // For a symbolic font the encoding should be the fonts built-in
  45751. // encoding.
  45752. for (charCode in builtInEncoding) {
  45753. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  45754. }
  45755. } else {
  45756. // For non-symbolic fonts that don't have a base encoding the standard
  45757. // encoding should be used.
  45758. baseEncoding = StandardEncoding;
  45759. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  45760. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  45761. if (glyphId >= 0) {
  45762. charCodeToGlyphId[charCode] = glyphId;
  45763. } else {
  45764. charCodeToGlyphId[charCode] = 0;
  45765. }
  45766. }
  45767. }
  45768. // notdef
  45769. // Lastly, merge in the differences.
  45770. var differences = properties.differences, glyphsUnicodeMap;
  45771. if (differences) {
  45772. for (charCode in differences) {
  45773. var glyphName = differences[charCode];
  45774. glyphId = glyphNames.indexOf(glyphName);
  45775. if (glyphId === -1) {
  45776. if (!glyphsUnicodeMap) {
  45777. glyphsUnicodeMap = getGlyphsUnicode();
  45778. }
  45779. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  45780. if (standardGlyphName !== glyphName) {
  45781. glyphId = glyphNames.indexOf(standardGlyphName);
  45782. }
  45783. }
  45784. if (glyphId >= 0) {
  45785. charCodeToGlyphId[charCode] = glyphId;
  45786. } else {
  45787. charCodeToGlyphId[charCode] = 0;
  45788. }
  45789. }
  45790. }
  45791. // notdef
  45792. return charCodeToGlyphId;
  45793. }
  45794. // Type1Font is also a CIDFontType0.
  45795. var Type1Font = function Type1FontClosure() {
  45796. function findBlock(streamBytes, signature, startIndex) {
  45797. var streamBytesLength = streamBytes.length;
  45798. var signatureLength = signature.length;
  45799. var scanLength = streamBytesLength - signatureLength;
  45800. var i = startIndex, j, found = false;
  45801. while (i < scanLength) {
  45802. j = 0;
  45803. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  45804. j++;
  45805. }
  45806. if (j >= signatureLength) {
  45807. // `signature` found, skip over whitespace.
  45808. i += j;
  45809. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  45810. i++;
  45811. }
  45812. found = true;
  45813. break;
  45814. }
  45815. i++;
  45816. }
  45817. return {
  45818. found: found,
  45819. length: i
  45820. };
  45821. }
  45822. function getHeaderBlock(stream, suggestedLength) {
  45823. var EEXEC_SIGNATURE = [
  45824. 0x65,
  45825. 0x65,
  45826. 0x78,
  45827. 0x65,
  45828. 0x63
  45829. ];
  45830. var streamStartPos = stream.pos;
  45831. // Save the initial stream position.
  45832. var headerBytes, headerBytesLength, block;
  45833. try {
  45834. headerBytes = stream.getBytes(suggestedLength);
  45835. headerBytesLength = headerBytes.length;
  45836. } catch (ex) {
  45837. if (ex instanceof MissingDataException) {
  45838. throw ex;
  45839. }
  45840. }
  45841. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  45842. // cannot hold the result of `getBytes`, and fallback to simply checking
  45843. // the entire stream (fixes issue3928.pdf).
  45844. if (headerBytesLength === suggestedLength) {
  45845. // Most of the time `suggestedLength` is correct, so to speed things up we
  45846. // initially only check the last few bytes to see if the header was found.
  45847. // Otherwise we (potentially) check the entire stream to prevent errors in
  45848. // `Type1Parser` (fixes issue5686.pdf).
  45849. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  45850. if (block.found && block.length === suggestedLength) {
  45851. return {
  45852. stream: new Stream(headerBytes),
  45853. length: suggestedLength
  45854. };
  45855. }
  45856. }
  45857. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  45858. stream.pos = streamStartPos;
  45859. // Reset the stream position.
  45860. var SCAN_BLOCK_LENGTH = 2048;
  45861. var actualLength;
  45862. while (true) {
  45863. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  45864. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  45865. if (block.length === 0) {
  45866. break;
  45867. }
  45868. stream.pos += block.length;
  45869. // Update the stream position.
  45870. if (block.found) {
  45871. actualLength = stream.pos - streamStartPos;
  45872. break;
  45873. }
  45874. }
  45875. stream.pos = streamStartPos;
  45876. // Reset the stream position.
  45877. if (actualLength) {
  45878. return {
  45879. stream: new Stream(stream.getBytes(actualLength)),
  45880. length: actualLength
  45881. };
  45882. }
  45883. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  45884. return {
  45885. stream: new Stream(stream.getBytes(suggestedLength)),
  45886. length: suggestedLength
  45887. };
  45888. }
  45889. function getEexecBlock(stream, suggestedLength) {
  45890. // We should ideally parse the eexec block to ensure that `suggestedLength`
  45891. // is correct, so we don't truncate the block data if it's too small.
  45892. // However, this would also require checking if the fixed-content portion
  45893. // exists (using the 'Length3' property), and ensuring that it's valid.
  45894. //
  45895. // Given that `suggestedLength` almost always is correct, all the validation
  45896. // would require a great deal of unnecessary parsing for most fonts.
  45897. // To save time, we always fetch the entire stream instead, which also avoid
  45898. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  45899. //
  45900. // NOTE: This means that the function can include the fixed-content portion
  45901. // in the returned eexec block. In practice this does *not* seem to matter,
  45902. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  45903. var eexecBytes = stream.getBytes();
  45904. return {
  45905. stream: new Stream(eexecBytes),
  45906. length: eexecBytes.length
  45907. };
  45908. }
  45909. function Type1Font(name, file, properties) {
  45910. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  45911. // Also, length1 and length2 might be off by 6 bytes as well.
  45912. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  45913. var PFB_HEADER_SIZE = 6;
  45914. var headerBlockLength = properties.length1;
  45915. var eexecBlockLength = properties.length2;
  45916. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  45917. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  45918. if (pfbHeaderPresent) {
  45919. file.skip(PFB_HEADER_SIZE);
  45920. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  45921. }
  45922. // Get the data block containing glyphs and subrs information
  45923. var headerBlock = getHeaderBlock(file, headerBlockLength);
  45924. headerBlockLength = headerBlock.length;
  45925. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  45926. headerBlockParser.extractFontHeader(properties);
  45927. if (pfbHeaderPresent) {
  45928. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  45929. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  45930. }
  45931. // Decrypt the data blocks and retrieve it's content
  45932. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  45933. eexecBlockLength = eexecBlock.length;
  45934. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  45935. var data = eexecBlockParser.extractFontProgram();
  45936. for (var info in data.properties) {
  45937. properties[info] = data.properties[info];
  45938. }
  45939. var charstrings = data.charstrings;
  45940. var type2Charstrings = this.getType2Charstrings(charstrings);
  45941. var subrs = this.getType2Subrs(data.subrs);
  45942. this.charstrings = charstrings;
  45943. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  45944. this.seacs = this.getSeacs(data.charstrings);
  45945. }
  45946. Type1Font.prototype = {
  45947. get numGlyphs() {
  45948. return this.charstrings.length + 1;
  45949. },
  45950. getCharset: function Type1Font_getCharset() {
  45951. var charset = ['.notdef'];
  45952. var charstrings = this.charstrings;
  45953. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  45954. charset.push(charstrings[glyphId].glyphName);
  45955. }
  45956. return charset;
  45957. },
  45958. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  45959. var charstrings = this.charstrings;
  45960. var glyphNames = ['.notdef'], glyphId;
  45961. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  45962. glyphNames.push(charstrings[glyphId].glyphName);
  45963. }
  45964. var encoding = properties.builtInEncoding;
  45965. if (encoding) {
  45966. var builtInEncoding = Object.create(null);
  45967. for (var charCode in encoding) {
  45968. glyphId = glyphNames.indexOf(encoding[charCode]);
  45969. if (glyphId >= 0) {
  45970. builtInEncoding[charCode] = glyphId;
  45971. }
  45972. }
  45973. }
  45974. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  45975. },
  45976. getSeacs: function Type1Font_getSeacs(charstrings) {
  45977. var i, ii;
  45978. var seacMap = [];
  45979. for (i = 0, ii = charstrings.length; i < ii; i++) {
  45980. var charstring = charstrings[i];
  45981. if (charstring.seac) {
  45982. // Offset by 1 for .notdef
  45983. seacMap[i + 1] = charstring.seac;
  45984. }
  45985. }
  45986. return seacMap;
  45987. },
  45988. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  45989. var type2Charstrings = [];
  45990. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  45991. type2Charstrings.push(type1Charstrings[i].charstring);
  45992. }
  45993. return type2Charstrings;
  45994. },
  45995. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  45996. var bias = 0;
  45997. var count = type1Subrs.length;
  45998. if (count < 1133) {
  45999. bias = 107;
  46000. } else if (count < 33769) {
  46001. bias = 1131;
  46002. } else {
  46003. bias = 32768;
  46004. }
  46005. // Add a bunch of empty subrs to deal with the Type2 bias
  46006. var type2Subrs = [];
  46007. var i;
  46008. for (i = 0; i < bias; i++) {
  46009. type2Subrs.push([0x0B]);
  46010. }
  46011. for (i = 0; i < count; i++) {
  46012. type2Subrs.push(type1Subrs[i]);
  46013. }
  46014. return type2Subrs;
  46015. },
  46016. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  46017. var cff = new CFF();
  46018. cff.header = new CFFHeader(1, 0, 4, 4);
  46019. cff.names = [name];
  46020. var topDict = new CFFTopDict();
  46021. // CFF strings IDs 0...390 are predefined names, so refering
  46022. // to entries in our own String INDEX starts at SID 391.
  46023. topDict.setByName('version', 391);
  46024. topDict.setByName('Notice', 392);
  46025. topDict.setByName('FullName', 393);
  46026. topDict.setByName('FamilyName', 394);
  46027. topDict.setByName('Weight', 395);
  46028. topDict.setByName('Encoding', null);
  46029. // placeholder
  46030. topDict.setByName('FontMatrix', properties.fontMatrix);
  46031. topDict.setByName('FontBBox', properties.bbox);
  46032. topDict.setByName('charset', null);
  46033. // placeholder
  46034. topDict.setByName('CharStrings', null);
  46035. // placeholder
  46036. topDict.setByName('Private', null);
  46037. // placeholder
  46038. cff.topDict = topDict;
  46039. var strings = new CFFStrings();
  46040. strings.add('Version 0.11');
  46041. // Version
  46042. strings.add('See original notice');
  46043. // Notice
  46044. strings.add(name);
  46045. // FullName
  46046. strings.add(name);
  46047. // FamilyName
  46048. strings.add('Medium');
  46049. // Weight
  46050. cff.strings = strings;
  46051. cff.globalSubrIndex = new CFFIndex();
  46052. var count = glyphs.length;
  46053. var charsetArray = [0];
  46054. var i, ii;
  46055. for (i = 0; i < count; i++) {
  46056. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  46057. // TODO: Insert the string and correctly map it. Previously it was
  46058. // thought mapping names that aren't in the standard strings to .notdef
  46059. // was fine, however in issue818 when mapping them all to .notdef the
  46060. // adieresis glyph no longer worked.
  46061. if (index === -1) {
  46062. index = 0;
  46063. }
  46064. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  46065. }
  46066. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  46067. var charStringsIndex = new CFFIndex();
  46068. charStringsIndex.add([
  46069. 0x8B,
  46070. 0x0E
  46071. ]);
  46072. // .notdef
  46073. for (i = 0; i < count; i++) {
  46074. var glyph = glyphs[i];
  46075. // If the CharString outline is empty, replace it with .notdef to
  46076. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  46077. if (glyph.length === 0) {
  46078. charStringsIndex.add([
  46079. 0x8B,
  46080. 0x0E
  46081. ]);
  46082. // .notdef
  46083. continue;
  46084. }
  46085. charStringsIndex.add(glyph);
  46086. }
  46087. cff.charStrings = charStringsIndex;
  46088. var privateDict = new CFFPrivateDict();
  46089. privateDict.setByName('Subrs', null);
  46090. // placeholder
  46091. var fields = [
  46092. 'BlueValues',
  46093. 'OtherBlues',
  46094. 'FamilyBlues',
  46095. 'FamilyOtherBlues',
  46096. 'StemSnapH',
  46097. 'StemSnapV',
  46098. 'BlueShift',
  46099. 'BlueFuzz',
  46100. 'BlueScale',
  46101. 'LanguageGroup',
  46102. 'ExpansionFactor',
  46103. 'ForceBold',
  46104. 'StdHW',
  46105. 'StdVW'
  46106. ];
  46107. for (i = 0, ii = fields.length; i < ii; i++) {
  46108. var field = fields[i];
  46109. if (!(field in properties.privateData)) {
  46110. continue;
  46111. }
  46112. var value = properties.privateData[field];
  46113. if (isArray(value)) {
  46114. // All of the private dictionary array data in CFF must be stored as
  46115. // "delta-encoded" numbers.
  46116. for (var j = value.length - 1; j > 0; j--) {
  46117. value[j] -= value[j - 1];
  46118. }
  46119. }
  46120. // ... difference from previous value
  46121. privateDict.setByName(field, value);
  46122. }
  46123. cff.topDict.privateDict = privateDict;
  46124. var subrIndex = new CFFIndex();
  46125. for (i = 0, ii = subrs.length; i < ii; i++) {
  46126. subrIndex.add(subrs[i]);
  46127. }
  46128. privateDict.subrsIndex = subrIndex;
  46129. var compiler = new CFFCompiler(cff);
  46130. return compiler.compile();
  46131. }
  46132. };
  46133. return Type1Font;
  46134. }();
  46135. var CFFFont = function CFFFontClosure() {
  46136. function CFFFont(file, properties) {
  46137. this.properties = properties;
  46138. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  46139. this.cff = parser.parse();
  46140. var compiler = new CFFCompiler(this.cff);
  46141. this.seacs = this.cff.seacs;
  46142. try {
  46143. this.data = compiler.compile();
  46144. } catch (e) {
  46145. warn('Failed to compile font ' + properties.loadedName);
  46146. // There may have just been an issue with the compiler, set the data
  46147. // anyway and hope the font loaded.
  46148. this.data = file;
  46149. }
  46150. }
  46151. CFFFont.prototype = {
  46152. get numGlyphs() {
  46153. return this.cff.charStrings.count;
  46154. },
  46155. getCharset: function CFFFont_getCharset() {
  46156. return this.cff.charset.charset;
  46157. },
  46158. getGlyphMapping: function CFFFont_getGlyphMapping() {
  46159. var cff = this.cff;
  46160. var properties = this.properties;
  46161. var charsets = cff.charset.charset;
  46162. var charCodeToGlyphId;
  46163. var glyphId;
  46164. if (properties.composite) {
  46165. charCodeToGlyphId = Object.create(null);
  46166. if (cff.isCIDFont) {
  46167. // If the font is actually a CID font then we should use the charset
  46168. // to map CIDs to GIDs.
  46169. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  46170. var cid = charsets[glyphId];
  46171. var charCode = properties.cMap.charCodeOf(cid);
  46172. charCodeToGlyphId[charCode] = glyphId;
  46173. }
  46174. } else {
  46175. // If it is NOT actually a CID font then CIDs should be mapped
  46176. // directly to GIDs.
  46177. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  46178. charCodeToGlyphId[glyphId] = glyphId;
  46179. }
  46180. }
  46181. return charCodeToGlyphId;
  46182. }
  46183. var encoding = cff.encoding ? cff.encoding.encoding : null;
  46184. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  46185. return charCodeToGlyphId;
  46186. }
  46187. };
  46188. return CFFFont;
  46189. }();
  46190. // Workaround for seac on Windows.
  46191. (function checkSeacSupport() {
  46192. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  46193. SEAC_ANALYSIS_ENABLED = true;
  46194. }
  46195. }());
  46196. // Workaround for Private Use Area characters in Chrome on Windows
  46197. // http://code.google.com/p/chromium/issues/detail?id=122465
  46198. // https://github.com/mozilla/pdf.js/issues/1689
  46199. (function checkChromeWindows() {
  46200. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  46201. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  46202. }
  46203. }());
  46204. exports.ErrorFont = ErrorFont;
  46205. exports.Font = Font;
  46206. exports.FontFlags = FontFlags;
  46207. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  46208. exports.ToUnicodeMap = ToUnicodeMap;
  46209. exports.getFontType = getFontType;
  46210. }));
  46211. (function (root, factory) {
  46212. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  46213. }(this, function (exports, sharedUtil, coreParser) {
  46214. var error = sharedUtil.error;
  46215. var isSpace = sharedUtil.isSpace;
  46216. var EOF = coreParser.EOF;
  46217. var PostScriptParser = function PostScriptParserClosure() {
  46218. function PostScriptParser(lexer) {
  46219. this.lexer = lexer;
  46220. this.operators = [];
  46221. this.token = null;
  46222. this.prev = null;
  46223. }
  46224. PostScriptParser.prototype = {
  46225. nextToken: function PostScriptParser_nextToken() {
  46226. this.prev = this.token;
  46227. this.token = this.lexer.getToken();
  46228. },
  46229. accept: function PostScriptParser_accept(type) {
  46230. if (this.token.type === type) {
  46231. this.nextToken();
  46232. return true;
  46233. }
  46234. return false;
  46235. },
  46236. expect: function PostScriptParser_expect(type) {
  46237. if (this.accept(type)) {
  46238. return true;
  46239. }
  46240. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  46241. },
  46242. parse: function PostScriptParser_parse() {
  46243. this.nextToken();
  46244. this.expect(PostScriptTokenTypes.LBRACE);
  46245. this.parseBlock();
  46246. this.expect(PostScriptTokenTypes.RBRACE);
  46247. return this.operators;
  46248. },
  46249. parseBlock: function PostScriptParser_parseBlock() {
  46250. while (true) {
  46251. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  46252. this.operators.push(this.prev.value);
  46253. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  46254. this.operators.push(this.prev.value);
  46255. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  46256. this.parseCondition();
  46257. } else {
  46258. return;
  46259. }
  46260. }
  46261. },
  46262. parseCondition: function PostScriptParser_parseCondition() {
  46263. // Add two place holders that will be updated later
  46264. var conditionLocation = this.operators.length;
  46265. this.operators.push(null, null);
  46266. this.parseBlock();
  46267. this.expect(PostScriptTokenTypes.RBRACE);
  46268. if (this.accept(PostScriptTokenTypes.IF)) {
  46269. // The true block is right after the 'if' so it just falls through on
  46270. // true else it jumps and skips the true block.
  46271. this.operators[conditionLocation] = this.operators.length;
  46272. this.operators[conditionLocation + 1] = 'jz';
  46273. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  46274. var jumpLocation = this.operators.length;
  46275. this.operators.push(null, null);
  46276. var endOfTrue = this.operators.length;
  46277. this.parseBlock();
  46278. this.expect(PostScriptTokenTypes.RBRACE);
  46279. this.expect(PostScriptTokenTypes.IFELSE);
  46280. // The jump is added at the end of the true block to skip the false
  46281. // block.
  46282. this.operators[jumpLocation] = this.operators.length;
  46283. this.operators[jumpLocation + 1] = 'j';
  46284. this.operators[conditionLocation] = endOfTrue;
  46285. this.operators[conditionLocation + 1] = 'jz';
  46286. } else {
  46287. error('PS Function: error parsing conditional.');
  46288. }
  46289. }
  46290. };
  46291. return PostScriptParser;
  46292. }();
  46293. var PostScriptTokenTypes = {
  46294. LBRACE: 0,
  46295. RBRACE: 1,
  46296. NUMBER: 2,
  46297. OPERATOR: 3,
  46298. IF: 4,
  46299. IFELSE: 5
  46300. };
  46301. var PostScriptToken = function PostScriptTokenClosure() {
  46302. function PostScriptToken(type, value) {
  46303. this.type = type;
  46304. this.value = value;
  46305. }
  46306. var opCache = Object.create(null);
  46307. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  46308. var opValue = opCache[op];
  46309. if (opValue) {
  46310. return opValue;
  46311. }
  46312. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  46313. };
  46314. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  46315. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  46316. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  46317. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  46318. return PostScriptToken;
  46319. }();
  46320. var PostScriptLexer = function PostScriptLexerClosure() {
  46321. function PostScriptLexer(stream) {
  46322. this.stream = stream;
  46323. this.nextChar();
  46324. this.strBuf = [];
  46325. }
  46326. PostScriptLexer.prototype = {
  46327. nextChar: function PostScriptLexer_nextChar() {
  46328. return this.currentChar = this.stream.getByte();
  46329. },
  46330. getToken: function PostScriptLexer_getToken() {
  46331. var comment = false;
  46332. var ch = this.currentChar;
  46333. // skip comments
  46334. while (true) {
  46335. if (ch < 0) {
  46336. return EOF;
  46337. }
  46338. if (comment) {
  46339. if (ch === 0x0A || ch === 0x0D) {
  46340. comment = false;
  46341. }
  46342. } else if (ch === 0x25) {
  46343. // '%'
  46344. comment = true;
  46345. } else if (!isSpace(ch)) {
  46346. break;
  46347. }
  46348. ch = this.nextChar();
  46349. }
  46350. switch (ch | 0) {
  46351. case 0x30:
  46352. case 0x31:
  46353. case 0x32:
  46354. case 0x33:
  46355. case 0x34:
  46356. // '0'-'4'
  46357. case 0x35:
  46358. case 0x36:
  46359. case 0x37:
  46360. case 0x38:
  46361. case 0x39:
  46362. // '5'-'9'
  46363. case 0x2B:
  46364. case 0x2D:
  46365. case 0x2E:
  46366. // '+', '-', '.'
  46367. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  46368. case 0x7B:
  46369. // '{'
  46370. this.nextChar();
  46371. return PostScriptToken.LBRACE;
  46372. case 0x7D:
  46373. // '}'
  46374. this.nextChar();
  46375. return PostScriptToken.RBRACE;
  46376. }
  46377. // operator
  46378. var strBuf = this.strBuf;
  46379. strBuf.length = 0;
  46380. strBuf[0] = String.fromCharCode(ch);
  46381. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  46382. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  46383. strBuf.push(String.fromCharCode(ch));
  46384. }
  46385. var str = strBuf.join('');
  46386. switch (str.toLowerCase()) {
  46387. case 'if':
  46388. return PostScriptToken.IF;
  46389. case 'ifelse':
  46390. return PostScriptToken.IFELSE;
  46391. default:
  46392. return PostScriptToken.getOperator(str);
  46393. }
  46394. },
  46395. getNumber: function PostScriptLexer_getNumber() {
  46396. var ch = this.currentChar;
  46397. var strBuf = this.strBuf;
  46398. strBuf.length = 0;
  46399. strBuf[0] = String.fromCharCode(ch);
  46400. while ((ch = this.nextChar()) >= 0) {
  46401. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  46402. ch === 0x2D || ch === 0x2E) {
  46403. // '-', '.'
  46404. strBuf.push(String.fromCharCode(ch));
  46405. } else {
  46406. break;
  46407. }
  46408. }
  46409. var value = parseFloat(strBuf.join(''));
  46410. if (isNaN(value)) {
  46411. error('Invalid floating point number: ' + value);
  46412. }
  46413. return value;
  46414. }
  46415. };
  46416. return PostScriptLexer;
  46417. }();
  46418. exports.PostScriptLexer = PostScriptLexer;
  46419. exports.PostScriptParser = PostScriptParser;
  46420. }));
  46421. (function (root, factory) {
  46422. factory(root.pdfjsDisplayCanvas = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  46423. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper, displayWebGL) {
  46424. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  46425. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  46426. var ImageKind = sharedUtil.ImageKind;
  46427. var OPS = sharedUtil.OPS;
  46428. var TextRenderingMode = sharedUtil.TextRenderingMode;
  46429. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  46430. var Util = sharedUtil.Util;
  46431. var assert = sharedUtil.assert;
  46432. var info = sharedUtil.info;
  46433. var isNum = sharedUtil.isNum;
  46434. var isArray = sharedUtil.isArray;
  46435. var isLittleEndian = sharedUtil.isLittleEndian;
  46436. var error = sharedUtil.error;
  46437. var shadow = sharedUtil.shadow;
  46438. var warn = sharedUtil.warn;
  46439. var TilingPattern = displayPatternHelper.TilingPattern;
  46440. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  46441. var WebGLUtils = displayWebGL.WebGLUtils;
  46442. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  46443. // <canvas> contexts store most of the state we need natively.
  46444. // However, PDF needs a bit more state, which we store here.
  46445. // Minimal font size that would be used during canvas fillText operations.
  46446. var MIN_FONT_SIZE = 16;
  46447. // Maximum font size that would be used during canvas fillText operations.
  46448. var MAX_FONT_SIZE = 100;
  46449. var MAX_GROUP_SIZE = 4096;
  46450. // Heuristic value used when enforcing minimum line widths.
  46451. var MIN_WIDTH_FACTOR = 0.65;
  46452. var COMPILE_TYPE3_GLYPHS = true;
  46453. var MAX_SIZE_TO_COMPILE = 1000;
  46454. var FULL_CHUNK_HEIGHT = 16;
  46455. var HasCanvasTypedArraysCached = {
  46456. get value() {
  46457. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  46458. }
  46459. };
  46460. var IsLittleEndianCached = {
  46461. get value() {
  46462. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  46463. }
  46464. };
  46465. function createScratchCanvas(width, height) {
  46466. var canvas = document.createElement('canvas');
  46467. canvas.width = width;
  46468. canvas.height = height;
  46469. return canvas;
  46470. }
  46471. function addContextCurrentTransform(ctx) {
  46472. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  46473. if (!ctx.mozCurrentTransform) {
  46474. ctx._originalSave = ctx.save;
  46475. ctx._originalRestore = ctx.restore;
  46476. ctx._originalRotate = ctx.rotate;
  46477. ctx._originalScale = ctx.scale;
  46478. ctx._originalTranslate = ctx.translate;
  46479. ctx._originalTransform = ctx.transform;
  46480. ctx._originalSetTransform = ctx.setTransform;
  46481. ctx._transformMatrix = ctx._transformMatrix || [
  46482. 1,
  46483. 0,
  46484. 0,
  46485. 1,
  46486. 0,
  46487. 0
  46488. ];
  46489. ctx._transformStack = [];
  46490. Object.defineProperty(ctx, 'mozCurrentTransform', {
  46491. get: function getCurrentTransform() {
  46492. return this._transformMatrix;
  46493. }
  46494. });
  46495. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  46496. get: function getCurrentTransformInverse() {
  46497. // Calculation done using WolframAlpha:
  46498. // http://www.wolframalpha.com/input/?
  46499. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  46500. var m = this._transformMatrix;
  46501. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  46502. var ad_bc = a * d - b * c;
  46503. var bc_ad = b * c - a * d;
  46504. return [
  46505. d / ad_bc,
  46506. b / bc_ad,
  46507. c / bc_ad,
  46508. a / ad_bc,
  46509. (d * e - c * f) / bc_ad,
  46510. (b * e - a * f) / ad_bc
  46511. ];
  46512. }
  46513. });
  46514. ctx.save = function ctxSave() {
  46515. var old = this._transformMatrix;
  46516. this._transformStack.push(old);
  46517. this._transformMatrix = old.slice(0, 6);
  46518. this._originalSave();
  46519. };
  46520. ctx.restore = function ctxRestore() {
  46521. var prev = this._transformStack.pop();
  46522. if (prev) {
  46523. this._transformMatrix = prev;
  46524. this._originalRestore();
  46525. }
  46526. };
  46527. ctx.translate = function ctxTranslate(x, y) {
  46528. var m = this._transformMatrix;
  46529. m[4] = m[0] * x + m[2] * y + m[4];
  46530. m[5] = m[1] * x + m[3] * y + m[5];
  46531. this._originalTranslate(x, y);
  46532. };
  46533. ctx.scale = function ctxScale(x, y) {
  46534. var m = this._transformMatrix;
  46535. m[0] = m[0] * x;
  46536. m[1] = m[1] * x;
  46537. m[2] = m[2] * y;
  46538. m[3] = m[3] * y;
  46539. this._originalScale(x, y);
  46540. };
  46541. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  46542. var m = this._transformMatrix;
  46543. this._transformMatrix = [
  46544. m[0] * a + m[2] * b,
  46545. m[1] * a + m[3] * b,
  46546. m[0] * c + m[2] * d,
  46547. m[1] * c + m[3] * d,
  46548. m[0] * e + m[2] * f + m[4],
  46549. m[1] * e + m[3] * f + m[5]
  46550. ];
  46551. ctx._originalTransform(a, b, c, d, e, f);
  46552. };
  46553. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  46554. this._transformMatrix = [
  46555. a,
  46556. b,
  46557. c,
  46558. d,
  46559. e,
  46560. f
  46561. ];
  46562. ctx._originalSetTransform(a, b, c, d, e, f);
  46563. };
  46564. ctx.rotate = function ctxRotate(angle) {
  46565. var cosValue = Math.cos(angle);
  46566. var sinValue = Math.sin(angle);
  46567. var m = this._transformMatrix;
  46568. this._transformMatrix = [
  46569. m[0] * cosValue + m[2] * sinValue,
  46570. m[1] * cosValue + m[3] * sinValue,
  46571. m[0] * -sinValue + m[2] * cosValue,
  46572. m[1] * -sinValue + m[3] * cosValue,
  46573. m[4],
  46574. m[5]
  46575. ];
  46576. this._originalRotate(angle);
  46577. };
  46578. }
  46579. }
  46580. var CachedCanvases = function CachedCanvasesClosure() {
  46581. function CachedCanvases() {
  46582. this.cache = Object.create(null);
  46583. }
  46584. CachedCanvases.prototype = {
  46585. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  46586. var canvasEntry;
  46587. if (this.cache[id] !== undefined) {
  46588. canvasEntry = this.cache[id];
  46589. canvasEntry.canvas.width = width;
  46590. canvasEntry.canvas.height = height;
  46591. // reset canvas transform for emulated mozCurrentTransform, if needed
  46592. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  46593. } else {
  46594. var canvas = createScratchCanvas(width, height);
  46595. var ctx = canvas.getContext('2d');
  46596. if (trackTransform) {
  46597. addContextCurrentTransform(ctx);
  46598. }
  46599. this.cache[id] = canvasEntry = {
  46600. canvas: canvas,
  46601. context: ctx
  46602. };
  46603. }
  46604. return canvasEntry;
  46605. },
  46606. clear: function () {
  46607. for (var id in this.cache) {
  46608. var canvasEntry = this.cache[id];
  46609. // Zeroing the width and height causes Firefox to release graphics
  46610. // resources immediately, which can greatly reduce memory consumption.
  46611. canvasEntry.canvas.width = 0;
  46612. canvasEntry.canvas.height = 0;
  46613. delete this.cache[id];
  46614. }
  46615. }
  46616. };
  46617. return CachedCanvases;
  46618. }();
  46619. function compileType3Glyph(imgData) {
  46620. var POINT_TO_PROCESS_LIMIT = 1000;
  46621. var width = imgData.width, height = imgData.height;
  46622. var i, j, j0, width1 = width + 1;
  46623. var points = new Uint8Array(width1 * (height + 1));
  46624. var POINT_TYPES = new Uint8Array([
  46625. 0,
  46626. 2,
  46627. 4,
  46628. 0,
  46629. 1,
  46630. 0,
  46631. 5,
  46632. 4,
  46633. 8,
  46634. 10,
  46635. 0,
  46636. 8,
  46637. 0,
  46638. 2,
  46639. 1,
  46640. 0
  46641. ]);
  46642. // decodes bit-packed mask data
  46643. var lineSize = width + 7 & ~7, data0 = imgData.data;
  46644. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  46645. for (i = 0, ii = data0.length; i < ii; i++) {
  46646. var mask = 128, elem = data0[i];
  46647. while (mask > 0) {
  46648. data[pos++] = elem & mask ? 0 : 255;
  46649. mask >>= 1;
  46650. }
  46651. }
  46652. // finding iteresting points: every point is located between mask pixels,
  46653. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  46654. // will have flags assigned based on neighboring mask pixels:
  46655. // 4 | 8
  46656. // --P--
  46657. // 2 | 1
  46658. // We are interested only in points with the flags:
  46659. // - outside corners: 1, 2, 4, 8;
  46660. // - inside corners: 7, 11, 13, 14;
  46661. // - and, intersections: 5, 10.
  46662. var count = 0;
  46663. pos = 0;
  46664. if (data[pos] !== 0) {
  46665. points[0] = 1;
  46666. ++count;
  46667. }
  46668. for (j = 1; j < width; j++) {
  46669. if (data[pos] !== data[pos + 1]) {
  46670. points[j] = data[pos] ? 2 : 1;
  46671. ++count;
  46672. }
  46673. pos++;
  46674. }
  46675. if (data[pos] !== 0) {
  46676. points[j] = 2;
  46677. ++count;
  46678. }
  46679. for (i = 1; i < height; i++) {
  46680. pos = i * lineSize;
  46681. j0 = i * width1;
  46682. if (data[pos - lineSize] !== data[pos]) {
  46683. points[j0] = data[pos] ? 1 : 8;
  46684. ++count;
  46685. }
  46686. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  46687. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  46688. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  46689. for (j = 1; j < width; j++) {
  46690. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  46691. if (POINT_TYPES[sum]) {
  46692. points[j0 + j] = POINT_TYPES[sum];
  46693. ++count;
  46694. }
  46695. pos++;
  46696. }
  46697. if (data[pos - lineSize] !== data[pos]) {
  46698. points[j0 + j] = data[pos] ? 2 : 4;
  46699. ++count;
  46700. }
  46701. if (count > POINT_TO_PROCESS_LIMIT) {
  46702. return null;
  46703. }
  46704. }
  46705. pos = lineSize * (height - 1);
  46706. j0 = i * width1;
  46707. if (data[pos] !== 0) {
  46708. points[j0] = 8;
  46709. ++count;
  46710. }
  46711. for (j = 1; j < width; j++) {
  46712. if (data[pos] !== data[pos + 1]) {
  46713. points[j0 + j] = data[pos] ? 4 : 8;
  46714. ++count;
  46715. }
  46716. pos++;
  46717. }
  46718. if (data[pos] !== 0) {
  46719. points[j0 + j] = 4;
  46720. ++count;
  46721. }
  46722. if (count > POINT_TO_PROCESS_LIMIT) {
  46723. return null;
  46724. }
  46725. // building outlines
  46726. var steps = new Int32Array([
  46727. 0,
  46728. width1,
  46729. -1,
  46730. 0,
  46731. -width1,
  46732. 0,
  46733. 0,
  46734. 0,
  46735. 1
  46736. ]);
  46737. var outlines = [];
  46738. for (i = 0; count && i <= height; i++) {
  46739. var p = i * width1;
  46740. var end = p + width;
  46741. while (p < end && !points[p]) {
  46742. p++;
  46743. }
  46744. if (p === end) {
  46745. continue;
  46746. }
  46747. var coords = [
  46748. p % width1,
  46749. i
  46750. ];
  46751. var type = points[p], p0 = p, pp;
  46752. do {
  46753. var step = steps[type];
  46754. do {
  46755. p += step;
  46756. } while (!points[p]);
  46757. pp = points[p];
  46758. if (pp !== 5 && pp !== 10) {
  46759. // set new direction
  46760. type = pp;
  46761. // delete mark
  46762. points[p] = 0;
  46763. } else {
  46764. // type is 5 or 10, ie, a crossing
  46765. // set new direction
  46766. type = pp & 0x33 * type >> 4;
  46767. // set new type for "future hit"
  46768. points[p] &= type >> 2 | type << 2;
  46769. }
  46770. coords.push(p % width1);
  46771. coords.push(p / width1 | 0);
  46772. --count;
  46773. } while (p0 !== p);
  46774. outlines.push(coords);
  46775. --i;
  46776. }
  46777. var drawOutline = function (c) {
  46778. c.save();
  46779. // the path shall be painted in [0..1]x[0..1] space
  46780. c.scale(1 / width, -1 / height);
  46781. c.translate(0, -height);
  46782. c.beginPath();
  46783. for (var i = 0, ii = outlines.length; i < ii; i++) {
  46784. var o = outlines[i];
  46785. c.moveTo(o[0], o[1]);
  46786. for (var j = 2, jj = o.length; j < jj; j += 2) {
  46787. c.lineTo(o[j], o[j + 1]);
  46788. }
  46789. }
  46790. c.fill();
  46791. c.beginPath();
  46792. c.restore();
  46793. };
  46794. return drawOutline;
  46795. }
  46796. var CanvasExtraState = function CanvasExtraStateClosure() {
  46797. function CanvasExtraState(old) {
  46798. // Are soft masks and alpha values shapes or opacities?
  46799. this.alphaIsShape = false;
  46800. this.fontSize = 0;
  46801. this.fontSizeScale = 1;
  46802. this.textMatrix = IDENTITY_MATRIX;
  46803. this.textMatrixScale = 1;
  46804. this.fontMatrix = FONT_IDENTITY_MATRIX;
  46805. this.leading = 0;
  46806. // Current point (in user coordinates)
  46807. this.x = 0;
  46808. this.y = 0;
  46809. // Start of text line (in text coordinates)
  46810. this.lineX = 0;
  46811. this.lineY = 0;
  46812. // Character and word spacing
  46813. this.charSpacing = 0;
  46814. this.wordSpacing = 0;
  46815. this.textHScale = 1;
  46816. this.textRenderingMode = TextRenderingMode.FILL;
  46817. this.textRise = 0;
  46818. // Default fore and background colors
  46819. this.fillColor = '#000000';
  46820. this.strokeColor = '#000000';
  46821. this.patternFill = false;
  46822. // Note: fill alpha applies to all non-stroking operations
  46823. this.fillAlpha = 1;
  46824. this.strokeAlpha = 1;
  46825. this.lineWidth = 1;
  46826. this.activeSMask = null;
  46827. this.resumeSMaskCtx = null;
  46828. // nonclonable field (see the save method below)
  46829. this.old = old;
  46830. }
  46831. CanvasExtraState.prototype = {
  46832. clone: function CanvasExtraState_clone() {
  46833. return Object.create(this);
  46834. },
  46835. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  46836. this.x = x;
  46837. this.y = y;
  46838. }
  46839. };
  46840. return CanvasExtraState;
  46841. }();
  46842. var CanvasGraphics = function CanvasGraphicsClosure() {
  46843. // Defines the time the executeOperatorList is going to be executing
  46844. // before it stops and shedules a continue of execution.
  46845. var EXECUTION_TIME = 15;
  46846. // Defines the number of steps before checking the execution time
  46847. var EXECUTION_STEPS = 10;
  46848. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  46849. this.ctx = canvasCtx;
  46850. this.current = new CanvasExtraState();
  46851. this.stateStack = [];
  46852. this.pendingClip = null;
  46853. this.pendingEOFill = false;
  46854. this.res = null;
  46855. this.xobjs = null;
  46856. this.commonObjs = commonObjs;
  46857. this.objs = objs;
  46858. this.imageLayer = imageLayer;
  46859. this.groupStack = [];
  46860. this.processingType3 = null;
  46861. // Patterns are painted relative to the initial page/form transform, see pdf
  46862. // spec 8.7.2 NOTE 1.
  46863. this.baseTransform = null;
  46864. this.baseTransformStack = [];
  46865. this.groupLevel = 0;
  46866. this.smaskStack = [];
  46867. this.smaskCounter = 0;
  46868. this.tempSMask = null;
  46869. this.cachedCanvases = new CachedCanvases();
  46870. if (canvasCtx) {
  46871. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  46872. // the transformation must already be set in canvasCtx._transformMatrix.
  46873. addContextCurrentTransform(canvasCtx);
  46874. }
  46875. this.cachedGetSinglePixelWidth = null;
  46876. }
  46877. function putBinaryImageData(ctx, imgData) {
  46878. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  46879. ctx.putImageData(imgData, 0, 0);
  46880. return;
  46881. }
  46882. // Put the image data to the canvas in chunks, rather than putting the
  46883. // whole image at once. This saves JS memory, because the ImageData object
  46884. // is smaller. It also possibly saves C++ memory within the implementation
  46885. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  46886. // the data passed to putImageData()). |n| shouldn't be too small, however,
  46887. // because too many putImageData() calls will slow things down.
  46888. //
  46889. // Note: as written, if the last chunk is partial, the putImageData() call
  46890. // will (conceptually) put pixels past the bounds of the canvas. But
  46891. // that's ok; any such pixels are ignored.
  46892. var height = imgData.height, width = imgData.width;
  46893. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  46894. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  46895. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  46896. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  46897. var srcPos = 0, destPos;
  46898. var src = imgData.data;
  46899. var dest = chunkImgData.data;
  46900. var i, j, thisChunkHeight, elemsInThisChunk;
  46901. // There are multiple forms in which the pixel data can be passed, and
  46902. // imgData.kind tells us which one this is.
  46903. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  46904. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  46905. var srcLength = src.byteLength;
  46906. var dest32 = HasCanvasTypedArraysCached.value ? new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  46907. var dest32DataLength = dest32.length;
  46908. var fullSrcDiff = width + 7 >> 3;
  46909. var white = 0xFFFFFFFF;
  46910. var black = IsLittleEndianCached.value || !HasCanvasTypedArraysCached.value ? 0xFF000000 : 0x000000FF;
  46911. for (i = 0; i < totalChunks; i++) {
  46912. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  46913. destPos = 0;
  46914. for (j = 0; j < thisChunkHeight; j++) {
  46915. var srcDiff = srcLength - srcPos;
  46916. var k = 0;
  46917. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  46918. var kEndUnrolled = kEnd & ~7;
  46919. var mask = 0;
  46920. var srcByte = 0;
  46921. for (; k < kEndUnrolled; k += 8) {
  46922. srcByte = src[srcPos++];
  46923. dest32[destPos++] = srcByte & 128 ? white : black;
  46924. dest32[destPos++] = srcByte & 64 ? white : black;
  46925. dest32[destPos++] = srcByte & 32 ? white : black;
  46926. dest32[destPos++] = srcByte & 16 ? white : black;
  46927. dest32[destPos++] = srcByte & 8 ? white : black;
  46928. dest32[destPos++] = srcByte & 4 ? white : black;
  46929. dest32[destPos++] = srcByte & 2 ? white : black;
  46930. dest32[destPos++] = srcByte & 1 ? white : black;
  46931. }
  46932. for (; k < kEnd; k++) {
  46933. if (mask === 0) {
  46934. srcByte = src[srcPos++];
  46935. mask = 128;
  46936. }
  46937. dest32[destPos++] = srcByte & mask ? white : black;
  46938. mask >>= 1;
  46939. }
  46940. }
  46941. // We ran out of input. Make all remaining pixels transparent.
  46942. while (destPos < dest32DataLength) {
  46943. dest32[destPos++] = 0;
  46944. }
  46945. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  46946. }
  46947. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  46948. // RGBA, 32-bits per pixel.
  46949. j = 0;
  46950. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  46951. for (i = 0; i < fullChunks; i++) {
  46952. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  46953. srcPos += elemsInThisChunk;
  46954. ctx.putImageData(chunkImgData, 0, j);
  46955. j += FULL_CHUNK_HEIGHT;
  46956. }
  46957. if (i < totalChunks) {
  46958. elemsInThisChunk = width * partialChunkHeight * 4;
  46959. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  46960. ctx.putImageData(chunkImgData, 0, j);
  46961. }
  46962. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  46963. // RGB, 24-bits per pixel.
  46964. thisChunkHeight = FULL_CHUNK_HEIGHT;
  46965. elemsInThisChunk = width * thisChunkHeight;
  46966. for (i = 0; i < totalChunks; i++) {
  46967. if (i >= fullChunks) {
  46968. thisChunkHeight = partialChunkHeight;
  46969. elemsInThisChunk = width * thisChunkHeight;
  46970. }
  46971. destPos = 0;
  46972. for (j = elemsInThisChunk; j--;) {
  46973. dest[destPos++] = src[srcPos++];
  46974. dest[destPos++] = src[srcPos++];
  46975. dest[destPos++] = src[srcPos++];
  46976. dest[destPos++] = 255;
  46977. }
  46978. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  46979. }
  46980. } else {
  46981. error('bad image kind: ' + imgData.kind);
  46982. }
  46983. }
  46984. function putBinaryImageMask(ctx, imgData) {
  46985. var height = imgData.height, width = imgData.width;
  46986. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  46987. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  46988. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  46989. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  46990. var srcPos = 0;
  46991. var src = imgData.data;
  46992. var dest = chunkImgData.data;
  46993. for (var i = 0; i < totalChunks; i++) {
  46994. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  46995. // Expand the mask so it can be used by the canvas. Any required
  46996. // inversion has already been handled.
  46997. var destPos = 3;
  46998. // alpha component offset
  46999. for (var j = 0; j < thisChunkHeight; j++) {
  47000. var mask = 0;
  47001. for (var k = 0; k < width; k++) {
  47002. if (!mask) {
  47003. var elem = src[srcPos++];
  47004. mask = 128;
  47005. }
  47006. dest[destPos] = elem & mask ? 0 : 255;
  47007. destPos += 4;
  47008. mask >>= 1;
  47009. }
  47010. }
  47011. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  47012. }
  47013. }
  47014. function copyCtxState(sourceCtx, destCtx) {
  47015. var properties = [
  47016. 'strokeStyle',
  47017. 'fillStyle',
  47018. 'fillRule',
  47019. 'globalAlpha',
  47020. 'lineWidth',
  47021. 'lineCap',
  47022. 'lineJoin',
  47023. 'miterLimit',
  47024. 'globalCompositeOperation',
  47025. 'font'
  47026. ];
  47027. for (var i = 0, ii = properties.length; i < ii; i++) {
  47028. var property = properties[i];
  47029. if (sourceCtx[property] !== undefined) {
  47030. destCtx[property] = sourceCtx[property];
  47031. }
  47032. }
  47033. if (sourceCtx.setLineDash !== undefined) {
  47034. destCtx.setLineDash(sourceCtx.getLineDash());
  47035. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  47036. }
  47037. }
  47038. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  47039. var length = bytes.length;
  47040. for (var i = 3; i < length; i += 4) {
  47041. var alpha = bytes[i];
  47042. if (alpha === 0) {
  47043. bytes[i - 3] = r0;
  47044. bytes[i - 2] = g0;
  47045. bytes[i - 1] = b0;
  47046. } else if (alpha < 255) {
  47047. var alpha_ = 255 - alpha;
  47048. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  47049. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  47050. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  47051. }
  47052. }
  47053. }
  47054. function composeSMaskAlpha(maskData, layerData, transferMap) {
  47055. var length = maskData.length;
  47056. var scale = 1 / 255;
  47057. for (var i = 3; i < length; i += 4) {
  47058. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  47059. layerData[i] = layerData[i] * alpha * scale | 0;
  47060. }
  47061. }
  47062. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  47063. var length = maskData.length;
  47064. for (var i = 3; i < length; i += 4) {
  47065. var y = maskData[i - 3] * 77 + // * 0.3 / 255 * 0x10000
  47066. maskData[i - 2] * 152 + // * 0.59 ....
  47067. maskData[i - 1] * 28;
  47068. // * 0.11 ....
  47069. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  47070. }
  47071. }
  47072. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  47073. var hasBackdrop = !!backdrop;
  47074. var r0 = hasBackdrop ? backdrop[0] : 0;
  47075. var g0 = hasBackdrop ? backdrop[1] : 0;
  47076. var b0 = hasBackdrop ? backdrop[2] : 0;
  47077. var composeFn;
  47078. if (subtype === 'Luminosity') {
  47079. composeFn = composeSMaskLuminosity;
  47080. } else {
  47081. composeFn = composeSMaskAlpha;
  47082. }
  47083. // processing image in chunks to save memory
  47084. var PIXELS_TO_PROCESS = 1048576;
  47085. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  47086. for (var row = 0; row < height; row += chunkSize) {
  47087. var chunkHeight = Math.min(chunkSize, height - row);
  47088. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  47089. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  47090. if (hasBackdrop) {
  47091. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  47092. }
  47093. composeFn(maskData.data, layerData.data, transferMap);
  47094. maskCtx.putImageData(layerData, 0, row);
  47095. }
  47096. }
  47097. function composeSMask(ctx, smask, layerCtx) {
  47098. var mask = smask.canvas;
  47099. var maskCtx = smask.context;
  47100. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  47101. var backdrop = smask.backdrop || null;
  47102. if (!smask.transferMap && WebGLUtils.isEnabled) {
  47103. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask, {
  47104. subtype: smask.subtype,
  47105. backdrop: backdrop
  47106. });
  47107. ctx.setTransform(1, 0, 0, 1, 0, 0);
  47108. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  47109. return;
  47110. }
  47111. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  47112. ctx.drawImage(mask, 0, 0);
  47113. }
  47114. var LINE_CAP_STYLES = [
  47115. 'butt',
  47116. 'round',
  47117. 'square'
  47118. ];
  47119. var LINE_JOIN_STYLES = [
  47120. 'miter',
  47121. 'round',
  47122. 'bevel'
  47123. ];
  47124. var NORMAL_CLIP = {};
  47125. var EO_CLIP = {};
  47126. CanvasGraphics.prototype = {
  47127. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) {
  47128. // For pdfs that use blend modes we have to clear the canvas else certain
  47129. // blend modes can look wrong since we'd be blending with a white
  47130. // backdrop. The problem with a transparent backdrop though is we then
  47131. // don't get sub pixel anti aliasing on text, creating temporary
  47132. // transparent canvas when we have blend modes.
  47133. var width = this.ctx.canvas.width;
  47134. var height = this.ctx.canvas.height;
  47135. this.ctx.save();
  47136. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  47137. this.ctx.fillRect(0, 0, width, height);
  47138. this.ctx.restore();
  47139. if (transparency) {
  47140. var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true);
  47141. this.compositeCtx = this.ctx;
  47142. this.transparentCanvas = transparentCanvas.canvas;
  47143. this.ctx = transparentCanvas.context;
  47144. this.ctx.save();
  47145. // The transform can be applied before rendering, transferring it to
  47146. // the new canvas.
  47147. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  47148. }
  47149. this.ctx.save();
  47150. if (transform) {
  47151. this.ctx.transform.apply(this.ctx, transform);
  47152. }
  47153. this.ctx.transform.apply(this.ctx, viewport.transform);
  47154. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  47155. if (this.imageLayer) {
  47156. this.imageLayer.beginLayout();
  47157. }
  47158. },
  47159. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  47160. var argsArray = operatorList.argsArray;
  47161. var fnArray = operatorList.fnArray;
  47162. var i = executionStartIdx || 0;
  47163. var argsArrayLen = argsArray.length;
  47164. // Sometimes the OperatorList to execute is empty.
  47165. if (argsArrayLen === i) {
  47166. return i;
  47167. }
  47168. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function';
  47169. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  47170. var steps = 0;
  47171. var commonObjs = this.commonObjs;
  47172. var objs = this.objs;
  47173. var fnId;
  47174. while (true) {
  47175. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  47176. stepper.breakIt(i, continueCallback);
  47177. return i;
  47178. }
  47179. fnId = fnArray[i];
  47180. if (fnId !== OPS.dependency) {
  47181. this[fnId].apply(this, argsArray[i]);
  47182. } else {
  47183. var deps = argsArray[i];
  47184. for (var n = 0, nn = deps.length; n < nn; n++) {
  47185. var depObjId = deps[n];
  47186. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  47187. var objsPool = common ? commonObjs : objs;
  47188. // If the promise isn't resolved yet, add the continueCallback
  47189. // to the promise and bail out.
  47190. if (!objsPool.isResolved(depObjId)) {
  47191. objsPool.get(depObjId, continueCallback);
  47192. return i;
  47193. }
  47194. }
  47195. }
  47196. i++;
  47197. // If the entire operatorList was executed, stop as were done.
  47198. if (i === argsArrayLen) {
  47199. return i;
  47200. }
  47201. // If the execution took longer then a certain amount of time and
  47202. // `continueCallback` is specified, interrupt the execution.
  47203. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  47204. if (Date.now() > endTime) {
  47205. continueCallback();
  47206. return i;
  47207. }
  47208. steps = 0;
  47209. }
  47210. }
  47211. },
  47212. // If the operatorList isn't executed completely yet OR the execution
  47213. // time was short enough, do another execution round.
  47214. endDrawing: function CanvasGraphics_endDrawing() {
  47215. // Finishing all opened operations such as SMask group painting.
  47216. if (this.current.activeSMask !== null) {
  47217. this.endSMaskGroup();
  47218. }
  47219. this.ctx.restore();
  47220. if (this.transparentCanvas) {
  47221. this.ctx = this.compositeCtx;
  47222. this.ctx.save();
  47223. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  47224. // Avoid apply transform twice
  47225. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  47226. this.ctx.restore();
  47227. this.transparentCanvas = null;
  47228. }
  47229. this.cachedCanvases.clear();
  47230. WebGLUtils.clear();
  47231. if (this.imageLayer) {
  47232. this.imageLayer.endLayout();
  47233. }
  47234. },
  47235. // Graphics state
  47236. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  47237. this.current.lineWidth = width;
  47238. this.ctx.lineWidth = width;
  47239. },
  47240. setLineCap: function CanvasGraphics_setLineCap(style) {
  47241. this.ctx.lineCap = LINE_CAP_STYLES[style];
  47242. },
  47243. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  47244. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  47245. },
  47246. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  47247. this.ctx.miterLimit = limit;
  47248. },
  47249. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  47250. var ctx = this.ctx;
  47251. if (ctx.setLineDash !== undefined) {
  47252. ctx.setLineDash(dashArray);
  47253. ctx.lineDashOffset = dashPhase;
  47254. }
  47255. },
  47256. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  47257. },
  47258. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  47259. },
  47260. setGState: function CanvasGraphics_setGState(states) {
  47261. for (var i = 0, ii = states.length; i < ii; i++) {
  47262. var state = states[i];
  47263. var key = state[0];
  47264. var value = state[1];
  47265. switch (key) {
  47266. case 'LW':
  47267. this.setLineWidth(value);
  47268. break;
  47269. case 'LC':
  47270. this.setLineCap(value);
  47271. break;
  47272. case 'LJ':
  47273. this.setLineJoin(value);
  47274. break;
  47275. case 'ML':
  47276. this.setMiterLimit(value);
  47277. break;
  47278. case 'D':
  47279. this.setDash(value[0], value[1]);
  47280. break;
  47281. case 'RI':
  47282. this.setRenderingIntent(value);
  47283. break;
  47284. case 'FL':
  47285. this.setFlatness(value);
  47286. break;
  47287. case 'Font':
  47288. this.setFont(value[0], value[1]);
  47289. break;
  47290. case 'CA':
  47291. this.current.strokeAlpha = state[1];
  47292. break;
  47293. case 'ca':
  47294. this.current.fillAlpha = state[1];
  47295. this.ctx.globalAlpha = state[1];
  47296. break;
  47297. case 'BM':
  47298. if (value && value.name && value.name !== 'Normal') {
  47299. var mode = value.name.replace(/([A-Z])/g, function (c) {
  47300. return '-' + c.toLowerCase();
  47301. }).substring(1);
  47302. this.ctx.globalCompositeOperation = mode;
  47303. if (this.ctx.globalCompositeOperation !== mode) {
  47304. warn('globalCompositeOperation "' + mode + '" is not supported');
  47305. }
  47306. } else {
  47307. this.ctx.globalCompositeOperation = 'source-over';
  47308. }
  47309. break;
  47310. case 'SMask':
  47311. if (this.current.activeSMask) {
  47312. // If SMask is currrenly used, it needs to be suspended or
  47313. // finished. Suspend only makes sense when at least one save()
  47314. // was performed and state needs to be reverted on restore().
  47315. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  47316. this.suspendSMaskGroup();
  47317. } else {
  47318. this.endSMaskGroup();
  47319. }
  47320. }
  47321. this.current.activeSMask = value ? this.tempSMask : null;
  47322. if (this.current.activeSMask) {
  47323. this.beginSMaskGroup();
  47324. }
  47325. this.tempSMask = null;
  47326. break;
  47327. }
  47328. }
  47329. },
  47330. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  47331. var activeSMask = this.current.activeSMask;
  47332. var drawnWidth = activeSMask.canvas.width;
  47333. var drawnHeight = activeSMask.canvas.height;
  47334. var cacheId = 'smaskGroupAt' + this.groupLevel;
  47335. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  47336. var currentCtx = this.ctx;
  47337. var currentTransform = currentCtx.mozCurrentTransform;
  47338. this.ctx.save();
  47339. var groupCtx = scratchCanvas.context;
  47340. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  47341. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  47342. groupCtx.transform.apply(groupCtx, currentTransform);
  47343. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  47344. copyCtxState(currentCtx, groupCtx);
  47345. this.ctx = groupCtx;
  47346. this.setGState([
  47347. [
  47348. 'BM',
  47349. 'Normal'
  47350. ],
  47351. [
  47352. 'ca',
  47353. 1
  47354. ],
  47355. [
  47356. 'CA',
  47357. 1
  47358. ]
  47359. ]);
  47360. this.groupStack.push(currentCtx);
  47361. this.groupLevel++;
  47362. },
  47363. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47364. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  47365. // and future ctx state restored.
  47366. var groupCtx = this.ctx;
  47367. this.groupLevel--;
  47368. this.ctx = this.groupStack.pop();
  47369. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  47370. this.ctx.restore();
  47371. this.ctx.save();
  47372. // save is needed since SMask will be resumed.
  47373. copyCtxState(groupCtx, this.ctx);
  47374. // Saving state for resuming.
  47375. this.current.resumeSMaskCtx = groupCtx;
  47376. // Transform was changed in the SMask canvas, reflecting this change on
  47377. // this.ctx.
  47378. var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  47379. this.ctx.transform.apply(this.ctx, deltaTransform);
  47380. // SMask was composed, the results at the groupCtx can be cleared.
  47381. groupCtx.save();
  47382. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  47383. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  47384. groupCtx.restore();
  47385. },
  47386. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47387. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  47388. // any groupCtx state since restore() command (the only caller) will do
  47389. // that for us. See also beginSMaskGroup.
  47390. var groupCtx = this.current.resumeSMaskCtx;
  47391. var currentCtx = this.ctx;
  47392. this.ctx = groupCtx;
  47393. this.groupStack.push(currentCtx);
  47394. this.groupLevel++;
  47395. },
  47396. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47397. var groupCtx = this.ctx;
  47398. this.groupLevel--;
  47399. this.ctx = this.groupStack.pop();
  47400. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  47401. this.ctx.restore();
  47402. copyCtxState(groupCtx, this.ctx);
  47403. // Transform was changed in the SMask canvas, reflecting this change on
  47404. // this.ctx.
  47405. var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  47406. this.ctx.transform.apply(this.ctx, deltaTransform);
  47407. },
  47408. save: function CanvasGraphics_save() {
  47409. this.ctx.save();
  47410. var old = this.current;
  47411. this.stateStack.push(old);
  47412. this.current = old.clone();
  47413. this.current.resumeSMaskCtx = null;
  47414. },
  47415. restore: function CanvasGraphics_restore() {
  47416. // SMask was suspended, we just need to resume it.
  47417. if (this.current.resumeSMaskCtx) {
  47418. this.resumeSMaskGroup();
  47419. }
  47420. // SMask has to be finished once there is no states that are using the
  47421. // same SMask.
  47422. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  47423. this.endSMaskGroup();
  47424. }
  47425. if (this.stateStack.length !== 0) {
  47426. this.current = this.stateStack.pop();
  47427. this.ctx.restore();
  47428. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  47429. this.pendingClip = null;
  47430. this.cachedGetSinglePixelWidth = null;
  47431. }
  47432. },
  47433. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  47434. this.ctx.transform(a, b, c, d, e, f);
  47435. this.cachedGetSinglePixelWidth = null;
  47436. },
  47437. // Path
  47438. constructPath: function CanvasGraphics_constructPath(ops, args) {
  47439. var ctx = this.ctx;
  47440. var current = this.current;
  47441. var x = current.x, y = current.y;
  47442. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  47443. switch (ops[i] | 0) {
  47444. case OPS.rectangle:
  47445. x = args[j++];
  47446. y = args[j++];
  47447. var width = args[j++];
  47448. var height = args[j++];
  47449. if (width === 0) {
  47450. width = this.getSinglePixelWidth();
  47451. }
  47452. if (height === 0) {
  47453. height = this.getSinglePixelWidth();
  47454. }
  47455. var xw = x + width;
  47456. var yh = y + height;
  47457. this.ctx.moveTo(x, y);
  47458. this.ctx.lineTo(xw, y);
  47459. this.ctx.lineTo(xw, yh);
  47460. this.ctx.lineTo(x, yh);
  47461. this.ctx.lineTo(x, y);
  47462. this.ctx.closePath();
  47463. break;
  47464. case OPS.moveTo:
  47465. x = args[j++];
  47466. y = args[j++];
  47467. ctx.moveTo(x, y);
  47468. break;
  47469. case OPS.lineTo:
  47470. x = args[j++];
  47471. y = args[j++];
  47472. ctx.lineTo(x, y);
  47473. break;
  47474. case OPS.curveTo:
  47475. x = args[j + 4];
  47476. y = args[j + 5];
  47477. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  47478. j += 6;
  47479. break;
  47480. case OPS.curveTo2:
  47481. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  47482. x = args[j + 2];
  47483. y = args[j + 3];
  47484. j += 4;
  47485. break;
  47486. case OPS.curveTo3:
  47487. x = args[j + 2];
  47488. y = args[j + 3];
  47489. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  47490. j += 4;
  47491. break;
  47492. case OPS.closePath:
  47493. ctx.closePath();
  47494. break;
  47495. }
  47496. }
  47497. current.setCurrentPoint(x, y);
  47498. },
  47499. closePath: function CanvasGraphics_closePath() {
  47500. this.ctx.closePath();
  47501. },
  47502. stroke: function CanvasGraphics_stroke(consumePath) {
  47503. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  47504. var ctx = this.ctx;
  47505. var strokeColor = this.current.strokeColor;
  47506. // Prevent drawing too thin lines by enforcing a minimum line width.
  47507. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  47508. // For stroke we want to temporarily change the global alpha to the
  47509. // stroking alpha.
  47510. ctx.globalAlpha = this.current.strokeAlpha;
  47511. if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
  47512. // for patterns, we transform to pattern space, calculate
  47513. // the pattern, call stroke, and restore to user space
  47514. ctx.save();
  47515. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  47516. ctx.stroke();
  47517. ctx.restore();
  47518. } else {
  47519. ctx.stroke();
  47520. }
  47521. if (consumePath) {
  47522. this.consumePath();
  47523. }
  47524. // Restore the global alpha to the fill alpha
  47525. ctx.globalAlpha = this.current.fillAlpha;
  47526. },
  47527. closeStroke: function CanvasGraphics_closeStroke() {
  47528. this.closePath();
  47529. this.stroke();
  47530. },
  47531. fill: function CanvasGraphics_fill(consumePath) {
  47532. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  47533. var ctx = this.ctx;
  47534. var fillColor = this.current.fillColor;
  47535. var isPatternFill = this.current.patternFill;
  47536. var needRestore = false;
  47537. if (isPatternFill) {
  47538. ctx.save();
  47539. if (this.baseTransform) {
  47540. ctx.setTransform.apply(ctx, this.baseTransform);
  47541. }
  47542. ctx.fillStyle = fillColor.getPattern(ctx, this);
  47543. needRestore = true;
  47544. }
  47545. if (this.pendingEOFill) {
  47546. if (ctx.mozFillRule !== undefined) {
  47547. ctx.mozFillRule = 'evenodd';
  47548. ctx.fill();
  47549. ctx.mozFillRule = 'nonzero';
  47550. } else {
  47551. ctx.fill('evenodd');
  47552. }
  47553. this.pendingEOFill = false;
  47554. } else {
  47555. ctx.fill();
  47556. }
  47557. if (needRestore) {
  47558. ctx.restore();
  47559. }
  47560. if (consumePath) {
  47561. this.consumePath();
  47562. }
  47563. },
  47564. eoFill: function CanvasGraphics_eoFill() {
  47565. this.pendingEOFill = true;
  47566. this.fill();
  47567. },
  47568. fillStroke: function CanvasGraphics_fillStroke() {
  47569. this.fill(false);
  47570. this.stroke(false);
  47571. this.consumePath();
  47572. },
  47573. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  47574. this.pendingEOFill = true;
  47575. this.fillStroke();
  47576. },
  47577. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  47578. this.closePath();
  47579. this.fillStroke();
  47580. },
  47581. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  47582. this.pendingEOFill = true;
  47583. this.closePath();
  47584. this.fillStroke();
  47585. },
  47586. endPath: function CanvasGraphics_endPath() {
  47587. this.consumePath();
  47588. },
  47589. // Clipping
  47590. clip: function CanvasGraphics_clip() {
  47591. this.pendingClip = NORMAL_CLIP;
  47592. },
  47593. eoClip: function CanvasGraphics_eoClip() {
  47594. this.pendingClip = EO_CLIP;
  47595. },
  47596. // Text
  47597. beginText: function CanvasGraphics_beginText() {
  47598. this.current.textMatrix = IDENTITY_MATRIX;
  47599. this.current.textMatrixScale = 1;
  47600. this.current.x = this.current.lineX = 0;
  47601. this.current.y = this.current.lineY = 0;
  47602. },
  47603. endText: function CanvasGraphics_endText() {
  47604. var paths = this.pendingTextPaths;
  47605. var ctx = this.ctx;
  47606. if (paths === undefined) {
  47607. ctx.beginPath();
  47608. return;
  47609. }
  47610. ctx.save();
  47611. ctx.beginPath();
  47612. for (var i = 0; i < paths.length; i++) {
  47613. var path = paths[i];
  47614. ctx.setTransform.apply(ctx, path.transform);
  47615. ctx.translate(path.x, path.y);
  47616. path.addToPath(ctx, path.fontSize);
  47617. }
  47618. ctx.restore();
  47619. ctx.clip();
  47620. ctx.beginPath();
  47621. delete this.pendingTextPaths;
  47622. },
  47623. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  47624. this.current.charSpacing = spacing;
  47625. },
  47626. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  47627. this.current.wordSpacing = spacing;
  47628. },
  47629. setHScale: function CanvasGraphics_setHScale(scale) {
  47630. this.current.textHScale = scale / 100;
  47631. },
  47632. setLeading: function CanvasGraphics_setLeading(leading) {
  47633. this.current.leading = -leading;
  47634. },
  47635. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  47636. var fontObj = this.commonObjs.get(fontRefName);
  47637. var current = this.current;
  47638. if (!fontObj) {
  47639. error('Can\'t find font for ' + fontRefName);
  47640. }
  47641. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX;
  47642. // A valid matrix needs all main diagonal elements to be non-zero
  47643. // This also ensures we bypass FF bugzilla bug #719844.
  47644. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  47645. warn('Invalid font matrix for font ' + fontRefName);
  47646. }
  47647. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  47648. // and in some docs this can be negative (inverted x-y axes).
  47649. if (size < 0) {
  47650. size = -size;
  47651. current.fontDirection = -1;
  47652. } else {
  47653. current.fontDirection = 1;
  47654. }
  47655. this.current.font = fontObj;
  47656. this.current.fontSize = size;
  47657. if (fontObj.isType3Font) {
  47658. return;
  47659. }
  47660. // we don't need ctx.font for Type3 fonts
  47661. var name = fontObj.loadedName || 'sans-serif';
  47662. var bold = fontObj.black ? fontObj.bold ? '900' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  47663. var italic = fontObj.italic ? 'italic' : 'normal';
  47664. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  47665. // Some font backends cannot handle fonts below certain size.
  47666. // Keeping the font at minimal size and using the fontSizeScale to change
  47667. // the current transformation matrix before the fillText/strokeText.
  47668. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  47669. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  47670. this.current.fontSizeScale = size / browserFontSize;
  47671. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  47672. this.ctx.font = rule;
  47673. },
  47674. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  47675. this.current.textRenderingMode = mode;
  47676. },
  47677. setTextRise: function CanvasGraphics_setTextRise(rise) {
  47678. this.current.textRise = rise;
  47679. },
  47680. moveText: function CanvasGraphics_moveText(x, y) {
  47681. this.current.x = this.current.lineX += x;
  47682. this.current.y = this.current.lineY += y;
  47683. },
  47684. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  47685. this.setLeading(-y);
  47686. this.moveText(x, y);
  47687. },
  47688. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  47689. this.current.textMatrix = [
  47690. a,
  47691. b,
  47692. c,
  47693. d,
  47694. e,
  47695. f
  47696. ];
  47697. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  47698. this.current.x = this.current.lineX = 0;
  47699. this.current.y = this.current.lineY = 0;
  47700. },
  47701. nextLine: function CanvasGraphics_nextLine() {
  47702. this.moveText(0, this.current.leading);
  47703. },
  47704. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  47705. var ctx = this.ctx;
  47706. var current = this.current;
  47707. var font = current.font;
  47708. var textRenderingMode = current.textRenderingMode;
  47709. var fontSize = current.fontSize / current.fontSizeScale;
  47710. var fillStrokeMode = textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  47711. var isAddToPathSet = !!(textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  47712. var addToPath;
  47713. if (font.disableFontFace || isAddToPathSet) {
  47714. addToPath = font.getPathGenerator(this.commonObjs, character);
  47715. }
  47716. if (font.disableFontFace) {
  47717. ctx.save();
  47718. ctx.translate(x, y);
  47719. ctx.beginPath();
  47720. addToPath(ctx, fontSize);
  47721. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47722. ctx.fill();
  47723. }
  47724. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47725. ctx.stroke();
  47726. }
  47727. ctx.restore();
  47728. } else {
  47729. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47730. ctx.fillText(character, x, y);
  47731. }
  47732. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47733. ctx.strokeText(character, x, y);
  47734. }
  47735. }
  47736. if (isAddToPathSet) {
  47737. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  47738. paths.push({
  47739. transform: ctx.mozCurrentTransform,
  47740. x: x,
  47741. y: y,
  47742. fontSize: fontSize,
  47743. addToPath: addToPath
  47744. });
  47745. }
  47746. },
  47747. get isFontSubpixelAAEnabled() {
  47748. // Checks if anti-aliasing is enabled when scaled text is painted.
  47749. // On Windows GDI scaled fonts looks bad.
  47750. var ctx = document.createElement('canvas').getContext('2d');
  47751. ctx.scale(1.5, 1);
  47752. ctx.fillText('I', 0, 10);
  47753. var data = ctx.getImageData(0, 0, 10, 10).data;
  47754. var enabled = false;
  47755. for (var i = 3; i < data.length; i += 4) {
  47756. if (data[i] > 0 && data[i] < 255) {
  47757. enabled = true;
  47758. break;
  47759. }
  47760. }
  47761. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  47762. },
  47763. showText: function CanvasGraphics_showText(glyphs) {
  47764. var current = this.current;
  47765. var font = current.font;
  47766. if (font.isType3Font) {
  47767. return this.showType3Text(glyphs);
  47768. }
  47769. var fontSize = current.fontSize;
  47770. if (fontSize === 0) {
  47771. return;
  47772. }
  47773. var ctx = this.ctx;
  47774. var fontSizeScale = current.fontSizeScale;
  47775. var charSpacing = current.charSpacing;
  47776. var wordSpacing = current.wordSpacing;
  47777. var fontDirection = current.fontDirection;
  47778. var textHScale = current.textHScale * fontDirection;
  47779. var glyphsLength = glyphs.length;
  47780. var vertical = font.vertical;
  47781. var spacingDir = vertical ? 1 : -1;
  47782. var defaultVMetrics = font.defaultVMetrics;
  47783. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  47784. var simpleFillText = current.textRenderingMode === TextRenderingMode.FILL && !font.disableFontFace;
  47785. ctx.save();
  47786. ctx.transform.apply(ctx, current.textMatrix);
  47787. ctx.translate(current.x, current.y + current.textRise);
  47788. if (current.patternFill) {
  47789. // TODO: Some shading patterns are not applied correctly to text,
  47790. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  47791. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  47792. }
  47793. if (fontDirection > 0) {
  47794. ctx.scale(textHScale, -1);
  47795. } else {
  47796. ctx.scale(textHScale, 1);
  47797. }
  47798. var lineWidth = current.lineWidth;
  47799. var scale = current.textMatrixScale;
  47800. if (scale === 0 || lineWidth === 0) {
  47801. var fillStrokeMode = current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  47802. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47803. this.cachedGetSinglePixelWidth = null;
  47804. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  47805. }
  47806. } else {
  47807. lineWidth /= scale;
  47808. }
  47809. if (fontSizeScale !== 1.0) {
  47810. ctx.scale(fontSizeScale, fontSizeScale);
  47811. lineWidth /= fontSizeScale;
  47812. }
  47813. ctx.lineWidth = lineWidth;
  47814. var x = 0, i;
  47815. for (i = 0; i < glyphsLength; ++i) {
  47816. var glyph = glyphs[i];
  47817. if (isNum(glyph)) {
  47818. x += spacingDir * glyph * fontSize / 1000;
  47819. continue;
  47820. }
  47821. var restoreNeeded = false;
  47822. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  47823. var character = glyph.fontChar;
  47824. var accent = glyph.accent;
  47825. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  47826. var width = glyph.width;
  47827. if (vertical) {
  47828. var vmetric, vx, vy;
  47829. vmetric = glyph.vmetric || defaultVMetrics;
  47830. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  47831. vx = -vx * widthAdvanceScale;
  47832. vy = vmetric[2] * widthAdvanceScale;
  47833. width = vmetric ? -vmetric[0] : width;
  47834. scaledX = vx / fontSizeScale;
  47835. scaledY = (x + vy) / fontSizeScale;
  47836. } else {
  47837. scaledX = x / fontSizeScale;
  47838. scaledY = 0;
  47839. }
  47840. if (font.remeasure && width > 0) {
  47841. // Some standard fonts may not have the exact width: rescale per
  47842. // character if measured width is greater than expected glyph width
  47843. // and subpixel-aa is enabled, otherwise just center the glyph.
  47844. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  47845. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  47846. var characterScaleX = width / measuredWidth;
  47847. restoreNeeded = true;
  47848. ctx.save();
  47849. ctx.scale(characterScaleX, 1);
  47850. scaledX /= characterScaleX;
  47851. } else if (width !== measuredWidth) {
  47852. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  47853. }
  47854. }
  47855. // Only attempt to draw the glyph if it is actually in the embedded font
  47856. // file or if there isn't a font file so the fallback font is shown.
  47857. if (glyph.isInFont || font.missingFile) {
  47858. if (simpleFillText && !accent) {
  47859. // common case
  47860. ctx.fillText(character, scaledX, scaledY);
  47861. } else {
  47862. this.paintChar(character, scaledX, scaledY);
  47863. if (accent) {
  47864. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  47865. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  47866. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  47867. }
  47868. }
  47869. }
  47870. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  47871. x += charWidth;
  47872. if (restoreNeeded) {
  47873. ctx.restore();
  47874. }
  47875. }
  47876. if (vertical) {
  47877. current.y -= x * textHScale;
  47878. } else {
  47879. current.x += x * textHScale;
  47880. }
  47881. ctx.restore();
  47882. },
  47883. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  47884. // Type3 fonts - each glyph is a "mini-PDF"
  47885. var ctx = this.ctx;
  47886. var current = this.current;
  47887. var font = current.font;
  47888. var fontSize = current.fontSize;
  47889. var fontDirection = current.fontDirection;
  47890. var spacingDir = font.vertical ? 1 : -1;
  47891. var charSpacing = current.charSpacing;
  47892. var wordSpacing = current.wordSpacing;
  47893. var textHScale = current.textHScale * fontDirection;
  47894. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  47895. var glyphsLength = glyphs.length;
  47896. var isTextInvisible = current.textRenderingMode === TextRenderingMode.INVISIBLE;
  47897. var i, glyph, width, spacingLength;
  47898. if (isTextInvisible || fontSize === 0) {
  47899. return;
  47900. }
  47901. this.cachedGetSinglePixelWidth = null;
  47902. ctx.save();
  47903. ctx.transform.apply(ctx, current.textMatrix);
  47904. ctx.translate(current.x, current.y);
  47905. ctx.scale(textHScale, fontDirection);
  47906. for (i = 0; i < glyphsLength; ++i) {
  47907. glyph = glyphs[i];
  47908. if (isNum(glyph)) {
  47909. spacingLength = spacingDir * glyph * fontSize / 1000;
  47910. this.ctx.translate(spacingLength, 0);
  47911. current.x += spacingLength * textHScale;
  47912. continue;
  47913. }
  47914. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  47915. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  47916. if (!operatorList) {
  47917. warn('Type3 character \"' + glyph.operatorListId + '\" is not available');
  47918. continue;
  47919. }
  47920. this.processingType3 = glyph;
  47921. this.save();
  47922. ctx.scale(fontSize, fontSize);
  47923. ctx.transform.apply(ctx, fontMatrix);
  47924. this.executeOperatorList(operatorList);
  47925. this.restore();
  47926. var transformed = Util.applyTransform([
  47927. glyph.width,
  47928. 0
  47929. ], fontMatrix);
  47930. width = transformed[0] * fontSize + spacing;
  47931. ctx.translate(width, 0);
  47932. current.x += width * textHScale;
  47933. }
  47934. ctx.restore();
  47935. this.processingType3 = null;
  47936. },
  47937. // Type3 fonts
  47938. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  47939. },
  47940. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  47941. // TODO According to the spec we're also suppose to ignore any operators
  47942. // that set color or include images while processing this type3 font.
  47943. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  47944. this.clip();
  47945. this.endPath();
  47946. },
  47947. // Color
  47948. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  47949. var pattern;
  47950. if (IR[0] === 'TilingPattern') {
  47951. var color = IR[1];
  47952. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  47953. var self = this;
  47954. var canvasGraphicsFactory = {
  47955. createCanvasGraphics: function (ctx) {
  47956. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  47957. }
  47958. };
  47959. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  47960. } else {
  47961. pattern = getShadingPatternFromIR(IR);
  47962. }
  47963. return pattern;
  47964. },
  47965. setStrokeColorN: function CanvasGraphics_setStrokeColorN()
  47966. /*...*/
  47967. {
  47968. this.current.strokeColor = this.getColorN_Pattern(arguments);
  47969. },
  47970. setFillColorN: function CanvasGraphics_setFillColorN()
  47971. /*...*/
  47972. {
  47973. this.current.fillColor = this.getColorN_Pattern(arguments);
  47974. this.current.patternFill = true;
  47975. },
  47976. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  47977. var color = Util.makeCssRgb(r, g, b);
  47978. this.ctx.strokeStyle = color;
  47979. this.current.strokeColor = color;
  47980. },
  47981. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  47982. var color = Util.makeCssRgb(r, g, b);
  47983. this.ctx.fillStyle = color;
  47984. this.current.fillColor = color;
  47985. this.current.patternFill = false;
  47986. },
  47987. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  47988. var ctx = this.ctx;
  47989. this.save();
  47990. var pattern = getShadingPatternFromIR(patternIR);
  47991. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  47992. var inv = ctx.mozCurrentTransformInverse;
  47993. if (inv) {
  47994. var canvas = ctx.canvas;
  47995. var width = canvas.width;
  47996. var height = canvas.height;
  47997. var bl = Util.applyTransform([
  47998. 0,
  47999. 0
  48000. ], inv);
  48001. var br = Util.applyTransform([
  48002. 0,
  48003. height
  48004. ], inv);
  48005. var ul = Util.applyTransform([
  48006. width,
  48007. 0
  48008. ], inv);
  48009. var ur = Util.applyTransform([
  48010. width,
  48011. height
  48012. ], inv);
  48013. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  48014. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  48015. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  48016. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  48017. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  48018. } else {
  48019. // HACK to draw the gradient onto an infinite rectangle.
  48020. // PDF gradients are drawn across the entire image while
  48021. // Canvas only allows gradients to be drawn in a rectangle
  48022. // The following bug should allow us to remove this.
  48023. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  48024. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  48025. }
  48026. this.restore();
  48027. },
  48028. // Images
  48029. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  48030. error('Should not call beginInlineImage');
  48031. },
  48032. beginImageData: function CanvasGraphics_beginImageData() {
  48033. error('Should not call beginImageData');
  48034. },
  48035. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  48036. this.save();
  48037. this.baseTransformStack.push(this.baseTransform);
  48038. if (isArray(matrix) && 6 === matrix.length) {
  48039. this.transform.apply(this, matrix);
  48040. }
  48041. this.baseTransform = this.ctx.mozCurrentTransform;
  48042. if (isArray(bbox) && 4 === bbox.length) {
  48043. var width = bbox[2] - bbox[0];
  48044. var height = bbox[3] - bbox[1];
  48045. this.ctx.rect(bbox[0], bbox[1], width, height);
  48046. this.clip();
  48047. this.endPath();
  48048. }
  48049. },
  48050. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  48051. this.restore();
  48052. this.baseTransform = this.baseTransformStack.pop();
  48053. },
  48054. beginGroup: function CanvasGraphics_beginGroup(group) {
  48055. this.save();
  48056. var currentCtx = this.ctx;
  48057. // TODO non-isolated groups - according to Rik at adobe non-isolated
  48058. // group results aren't usually that different and they even have tools
  48059. // that ignore this setting. Notes from Rik on implementing:
  48060. // - When you encounter an transparency group, create a new canvas with
  48061. // the dimensions of the bbox
  48062. // - copy the content from the previous canvas to the new canvas
  48063. // - draw as usual
  48064. // - remove the backdrop alpha:
  48065. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  48066. // value of your transparency group and 'alphaBackdrop' the alpha of the
  48067. // backdrop
  48068. // - remove background color:
  48069. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  48070. if (!group.isolated) {
  48071. info('TODO: Support non-isolated groups.');
  48072. }
  48073. // TODO knockout - supposedly possible with the clever use of compositing
  48074. // modes.
  48075. if (group.knockout) {
  48076. warn('Knockout groups not supported.');
  48077. }
  48078. var currentTransform = currentCtx.mozCurrentTransform;
  48079. if (group.matrix) {
  48080. currentCtx.transform.apply(currentCtx, group.matrix);
  48081. }
  48082. assert(group.bbox, 'Bounding box is required.');
  48083. // Based on the current transform figure out how big the bounding box
  48084. // will actually be.
  48085. var bounds = Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  48086. // Clip the bounding box to the current canvas.
  48087. var canvasBounds = [
  48088. 0,
  48089. 0,
  48090. currentCtx.canvas.width,
  48091. currentCtx.canvas.height
  48092. ];
  48093. bounds = Util.intersect(bounds, canvasBounds) || [
  48094. 0,
  48095. 0,
  48096. 0,
  48097. 0
  48098. ];
  48099. // Use ceil in case we're between sizes so we don't create canvas that is
  48100. // too small and make the canvas at least 1x1 pixels.
  48101. var offsetX = Math.floor(bounds[0]);
  48102. var offsetY = Math.floor(bounds[1]);
  48103. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  48104. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  48105. var scaleX = 1, scaleY = 1;
  48106. if (drawnWidth > MAX_GROUP_SIZE) {
  48107. scaleX = drawnWidth / MAX_GROUP_SIZE;
  48108. drawnWidth = MAX_GROUP_SIZE;
  48109. }
  48110. if (drawnHeight > MAX_GROUP_SIZE) {
  48111. scaleY = drawnHeight / MAX_GROUP_SIZE;
  48112. drawnHeight = MAX_GROUP_SIZE;
  48113. }
  48114. var cacheId = 'groupAt' + this.groupLevel;
  48115. if (group.smask) {
  48116. // Using two cache entries is case if masks are used one after another.
  48117. cacheId += '_smask_' + this.smaskCounter++ % 2;
  48118. }
  48119. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  48120. var groupCtx = scratchCanvas.context;
  48121. // Since we created a new canvas that is just the size of the bounding box
  48122. // we have to translate the group ctx.
  48123. groupCtx.scale(1 / scaleX, 1 / scaleY);
  48124. groupCtx.translate(-offsetX, -offsetY);
  48125. groupCtx.transform.apply(groupCtx, currentTransform);
  48126. if (group.smask) {
  48127. // Saving state and cached mask to be used in setGState.
  48128. this.smaskStack.push({
  48129. canvas: scratchCanvas.canvas,
  48130. context: groupCtx,
  48131. offsetX: offsetX,
  48132. offsetY: offsetY,
  48133. scaleX: scaleX,
  48134. scaleY: scaleY,
  48135. subtype: group.smask.subtype,
  48136. backdrop: group.smask.backdrop,
  48137. transferMap: group.smask.transferMap || null,
  48138. startTransformInverse: null
  48139. });
  48140. } else
  48141. // used during suspend operation
  48142. {
  48143. // Setup the current ctx so when the group is popped we draw it at the
  48144. // right location.
  48145. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  48146. currentCtx.translate(offsetX, offsetY);
  48147. currentCtx.scale(scaleX, scaleY);
  48148. }
  48149. // The transparency group inherits all off the current graphics state
  48150. // except the blend mode, soft mask, and alpha constants.
  48151. copyCtxState(currentCtx, groupCtx);
  48152. this.ctx = groupCtx;
  48153. this.setGState([
  48154. [
  48155. 'BM',
  48156. 'Normal'
  48157. ],
  48158. [
  48159. 'ca',
  48160. 1
  48161. ],
  48162. [
  48163. 'CA',
  48164. 1
  48165. ]
  48166. ]);
  48167. this.groupStack.push(currentCtx);
  48168. this.groupLevel++;
  48169. // Reseting mask state, masks will be applied on restore of the group.
  48170. this.current.activeSMask = null;
  48171. },
  48172. endGroup: function CanvasGraphics_endGroup(group) {
  48173. this.groupLevel--;
  48174. var groupCtx = this.ctx;
  48175. this.ctx = this.groupStack.pop();
  48176. // Turn off image smoothing to avoid sub pixel interpolation which can
  48177. // look kind of blurry for some pdfs.
  48178. if (this.ctx.imageSmoothingEnabled !== undefined) {
  48179. this.ctx.imageSmoothingEnabled = false;
  48180. } else {
  48181. this.ctx.mozImageSmoothingEnabled = false;
  48182. }
  48183. if (group.smask) {
  48184. this.tempSMask = this.smaskStack.pop();
  48185. } else {
  48186. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  48187. }
  48188. this.restore();
  48189. },
  48190. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  48191. this.save();
  48192. this.current = new CanvasExtraState();
  48193. if (this.baseTransform) {
  48194. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  48195. }
  48196. },
  48197. endAnnotations: function CanvasGraphics_endAnnotations() {
  48198. this.restore();
  48199. },
  48200. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  48201. this.save();
  48202. if (isArray(rect) && 4 === rect.length) {
  48203. var width = rect[2] - rect[0];
  48204. var height = rect[3] - rect[1];
  48205. this.ctx.rect(rect[0], rect[1], width, height);
  48206. this.clip();
  48207. this.endPath();
  48208. }
  48209. this.transform.apply(this, transform);
  48210. this.transform.apply(this, matrix);
  48211. },
  48212. endAnnotation: function CanvasGraphics_endAnnotation() {
  48213. this.restore();
  48214. },
  48215. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  48216. var domImage = this.objs.get(objId);
  48217. if (!domImage) {
  48218. warn('Dependent image isn\'t ready yet');
  48219. return;
  48220. }
  48221. this.save();
  48222. var ctx = this.ctx;
  48223. // scale the image to the unit square
  48224. ctx.scale(1 / w, -1 / h);
  48225. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
  48226. if (this.imageLayer) {
  48227. var currentTransform = ctx.mozCurrentTransformInverse;
  48228. var position = this.getCanvasPosition(0, 0);
  48229. this.imageLayer.appendImage({
  48230. objId: objId,
  48231. left: position[0],
  48232. top: position[1],
  48233. width: w / currentTransform[0],
  48234. height: h / currentTransform[3]
  48235. });
  48236. }
  48237. this.restore();
  48238. },
  48239. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  48240. var ctx = this.ctx;
  48241. var width = img.width, height = img.height;
  48242. var fillColor = this.current.fillColor;
  48243. var isPatternFill = this.current.patternFill;
  48244. var glyph = this.processingType3;
  48245. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  48246. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  48247. glyph.compiled = compileType3Glyph({
  48248. data: img.data,
  48249. width: width,
  48250. height: height
  48251. });
  48252. } else {
  48253. glyph.compiled = null;
  48254. }
  48255. }
  48256. if (glyph && glyph.compiled) {
  48257. glyph.compiled(ctx);
  48258. return;
  48259. }
  48260. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48261. var maskCtx = maskCanvas.context;
  48262. maskCtx.save();
  48263. putBinaryImageMask(maskCtx, img);
  48264. maskCtx.globalCompositeOperation = 'source-in';
  48265. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48266. maskCtx.fillRect(0, 0, width, height);
  48267. maskCtx.restore();
  48268. this.paintInlineImageXObject(maskCanvas.canvas);
  48269. },
  48270. paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
  48271. var width = imgData.width;
  48272. var height = imgData.height;
  48273. var fillColor = this.current.fillColor;
  48274. var isPatternFill = this.current.patternFill;
  48275. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48276. var maskCtx = maskCanvas.context;
  48277. maskCtx.save();
  48278. putBinaryImageMask(maskCtx, imgData);
  48279. maskCtx.globalCompositeOperation = 'source-in';
  48280. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48281. maskCtx.fillRect(0, 0, width, height);
  48282. maskCtx.restore();
  48283. var ctx = this.ctx;
  48284. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  48285. ctx.save();
  48286. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  48287. ctx.scale(1, -1);
  48288. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  48289. ctx.restore();
  48290. }
  48291. },
  48292. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  48293. var ctx = this.ctx;
  48294. var fillColor = this.current.fillColor;
  48295. var isPatternFill = this.current.patternFill;
  48296. for (var i = 0, ii = images.length; i < ii; i++) {
  48297. var image = images[i];
  48298. var width = image.width, height = image.height;
  48299. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48300. var maskCtx = maskCanvas.context;
  48301. maskCtx.save();
  48302. putBinaryImageMask(maskCtx, image);
  48303. maskCtx.globalCompositeOperation = 'source-in';
  48304. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48305. maskCtx.fillRect(0, 0, width, height);
  48306. maskCtx.restore();
  48307. ctx.save();
  48308. ctx.transform.apply(ctx, image.transform);
  48309. ctx.scale(1, -1);
  48310. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  48311. ctx.restore();
  48312. }
  48313. },
  48314. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  48315. var imgData = this.objs.get(objId);
  48316. if (!imgData) {
  48317. warn('Dependent image isn\'t ready yet');
  48318. return;
  48319. }
  48320. this.paintInlineImageXObject(imgData);
  48321. },
  48322. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  48323. var imgData = this.objs.get(objId);
  48324. if (!imgData) {
  48325. warn('Dependent image isn\'t ready yet');
  48326. return;
  48327. }
  48328. var width = imgData.width;
  48329. var height = imgData.height;
  48330. var map = [];
  48331. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  48332. map.push({
  48333. transform: [
  48334. scaleX,
  48335. 0,
  48336. 0,
  48337. scaleY,
  48338. positions[i],
  48339. positions[i + 1]
  48340. ],
  48341. x: 0,
  48342. y: 0,
  48343. w: width,
  48344. h: height
  48345. });
  48346. }
  48347. this.paintInlineImageXObjectGroup(imgData, map);
  48348. },
  48349. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  48350. var width = imgData.width;
  48351. var height = imgData.height;
  48352. var ctx = this.ctx;
  48353. this.save();
  48354. // scale the image to the unit square
  48355. ctx.scale(1 / width, -1 / height);
  48356. var currentTransform = ctx.mozCurrentTransformInverse;
  48357. var a = currentTransform[0], b = currentTransform[1];
  48358. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  48359. var c = currentTransform[2], d = currentTransform[3];
  48360. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  48361. var imgToPaint, tmpCanvas;
  48362. // instanceof HTMLElement does not work in jsdom node.js module
  48363. if (imgData instanceof HTMLElement || !imgData.data) {
  48364. imgToPaint = imgData;
  48365. } else {
  48366. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height);
  48367. var tmpCtx = tmpCanvas.context;
  48368. putBinaryImageData(tmpCtx, imgData);
  48369. imgToPaint = tmpCanvas.canvas;
  48370. }
  48371. var paintWidth = width, paintHeight = height;
  48372. var tmpCanvasId = 'prescale1';
  48373. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  48374. // pixels during drawImage operation, painting on the temporary canvas(es)
  48375. // that are twice smaller in size
  48376. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  48377. var newWidth = paintWidth, newHeight = paintHeight;
  48378. if (widthScale > 2 && paintWidth > 1) {
  48379. newWidth = Math.ceil(paintWidth / 2);
  48380. widthScale /= paintWidth / newWidth;
  48381. }
  48382. if (heightScale > 2 && paintHeight > 1) {
  48383. newHeight = Math.ceil(paintHeight / 2);
  48384. heightScale /= paintHeight / newHeight;
  48385. }
  48386. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  48387. tmpCtx = tmpCanvas.context;
  48388. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  48389. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  48390. imgToPaint = tmpCanvas.canvas;
  48391. paintWidth = newWidth;
  48392. paintHeight = newHeight;
  48393. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  48394. }
  48395. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  48396. if (this.imageLayer) {
  48397. var position = this.getCanvasPosition(0, -height);
  48398. this.imageLayer.appendImage({
  48399. imgData: imgData,
  48400. left: position[0],
  48401. top: position[1],
  48402. width: width / currentTransform[0],
  48403. height: height / currentTransform[3]
  48404. });
  48405. }
  48406. this.restore();
  48407. },
  48408. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  48409. var ctx = this.ctx;
  48410. var w = imgData.width;
  48411. var h = imgData.height;
  48412. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  48413. var tmpCtx = tmpCanvas.context;
  48414. putBinaryImageData(tmpCtx, imgData);
  48415. for (var i = 0, ii = map.length; i < ii; i++) {
  48416. var entry = map[i];
  48417. ctx.save();
  48418. ctx.transform.apply(ctx, entry.transform);
  48419. ctx.scale(1, -1);
  48420. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  48421. if (this.imageLayer) {
  48422. var position = this.getCanvasPosition(entry.x, entry.y);
  48423. this.imageLayer.appendImage({
  48424. imgData: imgData,
  48425. left: position[0],
  48426. top: position[1],
  48427. width: w,
  48428. height: h
  48429. });
  48430. }
  48431. ctx.restore();
  48432. }
  48433. },
  48434. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  48435. this.ctx.fillRect(0, 0, 1, 1);
  48436. },
  48437. paintXObject: function CanvasGraphics_paintXObject() {
  48438. warn('Unsupported \'paintXObject\' command.');
  48439. },
  48440. // Marked content
  48441. markPoint: function CanvasGraphics_markPoint(tag) {
  48442. },
  48443. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  48444. },
  48445. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  48446. },
  48447. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {
  48448. },
  48449. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  48450. },
  48451. // Compatibility
  48452. beginCompat: function CanvasGraphics_beginCompat() {
  48453. },
  48454. endCompat: function CanvasGraphics_endCompat() {
  48455. },
  48456. // Helper functions
  48457. consumePath: function CanvasGraphics_consumePath() {
  48458. var ctx = this.ctx;
  48459. if (this.pendingClip) {
  48460. if (this.pendingClip === EO_CLIP) {
  48461. if (ctx.mozFillRule !== undefined) {
  48462. ctx.mozFillRule = 'evenodd';
  48463. ctx.clip();
  48464. ctx.mozFillRule = 'nonzero';
  48465. } else {
  48466. ctx.clip('evenodd');
  48467. }
  48468. } else {
  48469. ctx.clip();
  48470. }
  48471. this.pendingClip = null;
  48472. }
  48473. ctx.beginPath();
  48474. },
  48475. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  48476. if (this.cachedGetSinglePixelWidth === null) {
  48477. // NOTE: The `save` and `restore` commands used below is a workaround
  48478. // that is necessary in order to prevent `mozCurrentTransformInverse`
  48479. // from intermittently returning incorrect values in Firefox, see:
  48480. // https://github.com/mozilla/pdf.js/issues/7188.
  48481. this.ctx.save();
  48482. var inverse = this.ctx.mozCurrentTransformInverse;
  48483. this.ctx.restore();
  48484. // max of the current horizontal and vertical scale
  48485. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  48486. }
  48487. return this.cachedGetSinglePixelWidth;
  48488. },
  48489. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  48490. var transform = this.ctx.mozCurrentTransform;
  48491. return [
  48492. transform[0] * x + transform[2] * y + transform[4],
  48493. transform[1] * x + transform[3] * y + transform[5]
  48494. ];
  48495. }
  48496. };
  48497. for (var op in OPS) {
  48498. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  48499. }
  48500. return CanvasGraphics;
  48501. }();
  48502. exports.CanvasGraphics = CanvasGraphics;
  48503. exports.createScratchCanvas = createScratchCanvas;
  48504. }));
  48505. (function (root, factory) {
  48506. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  48507. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  48508. var error = sharedUtil.error;
  48509. var info = sharedUtil.info;
  48510. var isArray = sharedUtil.isArray;
  48511. var isBool = sharedUtil.isBool;
  48512. var isDict = corePrimitives.isDict;
  48513. var isStream = corePrimitives.isStream;
  48514. var PostScriptLexer = corePsParser.PostScriptLexer;
  48515. var PostScriptParser = corePsParser.PostScriptParser;
  48516. var PDFFunction = function PDFFunctionClosure() {
  48517. var CONSTRUCT_SAMPLED = 0;
  48518. var CONSTRUCT_INTERPOLATED = 2;
  48519. var CONSTRUCT_STICHED = 3;
  48520. var CONSTRUCT_POSTSCRIPT = 4;
  48521. return {
  48522. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  48523. var i, ii;
  48524. var length = 1;
  48525. for (i = 0, ii = size.length; i < ii; i++) {
  48526. length *= size[i];
  48527. }
  48528. length *= outputSize;
  48529. var array = new Array(length);
  48530. var codeSize = 0;
  48531. var codeBuf = 0;
  48532. // 32 is a valid bps so shifting won't work
  48533. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  48534. var strBytes = str.getBytes((length * bps + 7) / 8);
  48535. var strIdx = 0;
  48536. for (i = 0; i < length; i++) {
  48537. while (codeSize < bps) {
  48538. codeBuf <<= 8;
  48539. codeBuf |= strBytes[strIdx++];
  48540. codeSize += 8;
  48541. }
  48542. codeSize -= bps;
  48543. array[i] = (codeBuf >> codeSize) * sampleMul;
  48544. codeBuf &= (1 << codeSize) - 1;
  48545. }
  48546. return array;
  48547. },
  48548. getIR: function PDFFunction_getIR(xref, fn) {
  48549. var dict = fn.dict;
  48550. if (!dict) {
  48551. dict = fn;
  48552. }
  48553. var types = [
  48554. this.constructSampled,
  48555. null,
  48556. this.constructInterpolated,
  48557. this.constructStiched,
  48558. this.constructPostScript
  48559. ];
  48560. var typeNum = dict.get('FunctionType');
  48561. var typeFn = types[typeNum];
  48562. if (!typeFn) {
  48563. error('Unknown type of function');
  48564. }
  48565. return typeFn.call(this, fn, dict, xref);
  48566. },
  48567. fromIR: function PDFFunction_fromIR(IR) {
  48568. var type = IR[0];
  48569. switch (type) {
  48570. case CONSTRUCT_SAMPLED:
  48571. return this.constructSampledFromIR(IR);
  48572. case CONSTRUCT_INTERPOLATED:
  48573. return this.constructInterpolatedFromIR(IR);
  48574. case CONSTRUCT_STICHED:
  48575. return this.constructStichedFromIR(IR);
  48576. //case CONSTRUCT_POSTSCRIPT:
  48577. default:
  48578. return this.constructPostScriptFromIR(IR);
  48579. }
  48580. },
  48581. parse: function PDFFunction_parse(xref, fn) {
  48582. var IR = this.getIR(xref, fn);
  48583. return this.fromIR(IR);
  48584. },
  48585. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  48586. if (!isArray(fnObj)) {
  48587. // not an array -- parsing as regular function
  48588. return this.parse(xref, fnObj);
  48589. }
  48590. var fnArray = [];
  48591. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  48592. var obj = xref.fetchIfRef(fnObj[j]);
  48593. fnArray.push(PDFFunction.parse(xref, obj));
  48594. }
  48595. return function (src, srcOffset, dest, destOffset) {
  48596. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  48597. fnArray[i](src, srcOffset, dest, destOffset + i);
  48598. }
  48599. };
  48600. },
  48601. constructSampled: function PDFFunction_constructSampled(str, dict) {
  48602. function toMultiArray(arr) {
  48603. var inputLength = arr.length;
  48604. var out = [];
  48605. var index = 0;
  48606. for (var i = 0; i < inputLength; i += 2) {
  48607. out[index] = [
  48608. arr[i],
  48609. arr[i + 1]
  48610. ];
  48611. ++index;
  48612. }
  48613. return out;
  48614. }
  48615. var domain = dict.getArray('Domain');
  48616. var range = dict.getArray('Range');
  48617. if (!domain || !range) {
  48618. error('No domain or range');
  48619. }
  48620. var inputSize = domain.length / 2;
  48621. var outputSize = range.length / 2;
  48622. domain = toMultiArray(domain);
  48623. range = toMultiArray(range);
  48624. var size = dict.get('Size');
  48625. var bps = dict.get('BitsPerSample');
  48626. var order = dict.get('Order') || 1;
  48627. if (order !== 1) {
  48628. // No description how cubic spline interpolation works in PDF32000:2008
  48629. // As in poppler, ignoring order, linear interpolation may work as good
  48630. info('No support for cubic spline interpolation: ' + order);
  48631. }
  48632. var encode = dict.getArray('Encode');
  48633. if (!encode) {
  48634. encode = [];
  48635. for (var i = 0; i < inputSize; ++i) {
  48636. encode.push(0);
  48637. encode.push(size[i] - 1);
  48638. }
  48639. }
  48640. encode = toMultiArray(encode);
  48641. var decode = dict.getArray('Decode');
  48642. if (!decode) {
  48643. decode = range;
  48644. } else {
  48645. decode = toMultiArray(decode);
  48646. }
  48647. var samples = this.getSampleArray(size, outputSize, bps, str);
  48648. return [
  48649. CONSTRUCT_SAMPLED,
  48650. inputSize,
  48651. domain,
  48652. encode,
  48653. decode,
  48654. samples,
  48655. size,
  48656. outputSize,
  48657. Math.pow(2, bps) - 1,
  48658. range
  48659. ];
  48660. },
  48661. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  48662. // See chapter 3, page 109 of the PDF reference
  48663. function interpolate(x, xmin, xmax, ymin, ymax) {
  48664. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  48665. }
  48666. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  48667. // See chapter 3, page 110 of the PDF reference.
  48668. var m = IR[1];
  48669. var domain = IR[2];
  48670. var encode = IR[3];
  48671. var decode = IR[4];
  48672. var samples = IR[5];
  48673. var size = IR[6];
  48674. var n = IR[7];
  48675. //var mask = IR[8];
  48676. var range = IR[9];
  48677. // Building the cube vertices: its part and sample index
  48678. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  48679. var cubeVertices = 1 << m;
  48680. var cubeN = new Float64Array(cubeVertices);
  48681. var cubeVertex = new Uint32Array(cubeVertices);
  48682. var i, j;
  48683. for (j = 0; j < cubeVertices; j++) {
  48684. cubeN[j] = 1;
  48685. }
  48686. var k = n, pos = 1;
  48687. // Map x_i to y_j for 0 <= i < m using the sampled function.
  48688. for (i = 0; i < m; ++i) {
  48689. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  48690. var domain_2i = domain[i][0];
  48691. var domain_2i_1 = domain[i][1];
  48692. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  48693. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  48694. // Encode_2i, Encode_2i+1)
  48695. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  48696. // e_i' = min(max(e_i, 0), Size_i - 1)
  48697. var size_i = size[i];
  48698. e = Math.min(Math.max(e, 0), size_i - 1);
  48699. // Adjusting the cube: N and vertex sample index
  48700. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  48701. // e1 = e0 + 1;
  48702. var n0 = e0 + 1 - e;
  48703. // (e1 - e) / (e1 - e0);
  48704. var n1 = e - e0;
  48705. // (e - e0) / (e1 - e0);
  48706. var offset0 = e0 * k;
  48707. var offset1 = offset0 + k;
  48708. // e1 * k
  48709. for (j = 0; j < cubeVertices; j++) {
  48710. if (j & pos) {
  48711. cubeN[j] *= n1;
  48712. cubeVertex[j] += offset1;
  48713. } else {
  48714. cubeN[j] *= n0;
  48715. cubeVertex[j] += offset0;
  48716. }
  48717. }
  48718. k *= size_i;
  48719. pos <<= 1;
  48720. }
  48721. for (j = 0; j < n; ++j) {
  48722. // Sum all cube vertices' samples portions
  48723. var rj = 0;
  48724. for (i = 0; i < cubeVertices; i++) {
  48725. rj += samples[cubeVertex[i] + j] * cubeN[i];
  48726. }
  48727. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  48728. // Decode_2j, Decode_2j+1)
  48729. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  48730. // y_j = min(max(r_j, range_2j), range_2j+1)
  48731. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  48732. }
  48733. };
  48734. },
  48735. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  48736. var c0 = dict.getArray('C0') || [0];
  48737. var c1 = dict.getArray('C1') || [1];
  48738. var n = dict.get('N');
  48739. if (!isArray(c0) || !isArray(c1)) {
  48740. error('Illegal dictionary for interpolated function');
  48741. }
  48742. var length = c0.length;
  48743. var diff = [];
  48744. for (var i = 0; i < length; ++i) {
  48745. diff.push(c1[i] - c0[i]);
  48746. }
  48747. return [
  48748. CONSTRUCT_INTERPOLATED,
  48749. c0,
  48750. diff,
  48751. n
  48752. ];
  48753. },
  48754. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  48755. var c0 = IR[1];
  48756. var diff = IR[2];
  48757. var n = IR[3];
  48758. var length = diff.length;
  48759. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  48760. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  48761. for (var j = 0; j < length; ++j) {
  48762. dest[destOffset + j] = c0[j] + x * diff[j];
  48763. }
  48764. };
  48765. },
  48766. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  48767. var domain = dict.getArray('Domain');
  48768. if (!domain) {
  48769. error('No domain');
  48770. }
  48771. var inputSize = domain.length / 2;
  48772. if (inputSize !== 1) {
  48773. error('Bad domain for stiched function');
  48774. }
  48775. var fnRefs = dict.get('Functions');
  48776. var fns = [];
  48777. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  48778. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  48779. }
  48780. var bounds = dict.getArray('Bounds');
  48781. var encode = dict.getArray('Encode');
  48782. return [
  48783. CONSTRUCT_STICHED,
  48784. domain,
  48785. bounds,
  48786. encode,
  48787. fns
  48788. ];
  48789. },
  48790. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  48791. var domain = IR[1];
  48792. var bounds = IR[2];
  48793. var encode = IR[3];
  48794. var fnsIR = IR[4];
  48795. var fns = [];
  48796. var tmpBuf = new Float32Array(1);
  48797. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  48798. fns.push(PDFFunction.fromIR(fnsIR[i]));
  48799. }
  48800. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  48801. var clip = function constructStichedFromIRClip(v, min, max) {
  48802. if (v > max) {
  48803. v = max;
  48804. } else if (v < min) {
  48805. v = min;
  48806. }
  48807. return v;
  48808. };
  48809. // clip to domain
  48810. var v = clip(src[srcOffset], domain[0], domain[1]);
  48811. // calculate which bound the value is in
  48812. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  48813. if (v < bounds[i]) {
  48814. break;
  48815. }
  48816. }
  48817. // encode value into domain of function
  48818. var dmin = domain[0];
  48819. if (i > 0) {
  48820. dmin = bounds[i - 1];
  48821. }
  48822. var dmax = domain[1];
  48823. if (i < bounds.length) {
  48824. dmax = bounds[i];
  48825. }
  48826. var rmin = encode[2 * i];
  48827. var rmax = encode[2 * i + 1];
  48828. // Prevent the value from becoming NaN as a result
  48829. // of division by zero (fixes issue6113.pdf).
  48830. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  48831. // call the appropriate function
  48832. fns[i](tmpBuf, 0, dest, destOffset);
  48833. };
  48834. },
  48835. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  48836. var domain = dict.getArray('Domain');
  48837. var range = dict.getArray('Range');
  48838. if (!domain) {
  48839. error('No domain.');
  48840. }
  48841. if (!range) {
  48842. error('No range.');
  48843. }
  48844. var lexer = new PostScriptLexer(fn);
  48845. var parser = new PostScriptParser(lexer);
  48846. var code = parser.parse();
  48847. return [
  48848. CONSTRUCT_POSTSCRIPT,
  48849. domain,
  48850. range,
  48851. code
  48852. ];
  48853. },
  48854. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  48855. var domain = IR[1];
  48856. var range = IR[2];
  48857. var code = IR[3];
  48858. var compiled = new PostScriptCompiler().compile(code, domain, range);
  48859. if (compiled) {
  48860. // Compiled function consists of simple expressions such as addition,
  48861. // subtraction, Math.max, and also contains 'var' and 'return'
  48862. // statements. See the generation in the PostScriptCompiler below.
  48863. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  48864. }
  48865. info('Unable to compile PS function');
  48866. var numOutputs = range.length >> 1;
  48867. var numInputs = domain.length >> 1;
  48868. var evaluator = new PostScriptEvaluator(code);
  48869. // Cache the values for a big speed up, the cache size is limited though
  48870. // since the number of possible values can be huge from a PS function.
  48871. var cache = Object.create(null);
  48872. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  48873. // seen in our tests.
  48874. var MAX_CACHE_SIZE = 2048 * 4;
  48875. var cache_available = MAX_CACHE_SIZE;
  48876. var tmpBuf = new Float32Array(numInputs);
  48877. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  48878. var i, value;
  48879. var key = '';
  48880. var input = tmpBuf;
  48881. for (i = 0; i < numInputs; i++) {
  48882. value = src[srcOffset + i];
  48883. input[i] = value;
  48884. key += value + '_';
  48885. }
  48886. var cachedValue = cache[key];
  48887. if (cachedValue !== undefined) {
  48888. dest.set(cachedValue, destOffset);
  48889. return;
  48890. }
  48891. var output = new Float32Array(numOutputs);
  48892. var stack = evaluator.execute(input);
  48893. var stackIndex = stack.length - numOutputs;
  48894. for (i = 0; i < numOutputs; i++) {
  48895. value = stack[stackIndex + i];
  48896. var bound = range[i * 2];
  48897. if (value < bound) {
  48898. value = bound;
  48899. } else {
  48900. bound = range[i * 2 + 1];
  48901. if (value > bound) {
  48902. value = bound;
  48903. }
  48904. }
  48905. output[i] = value;
  48906. }
  48907. if (cache_available > 0) {
  48908. cache_available--;
  48909. cache[key] = output;
  48910. }
  48911. dest.set(output, destOffset);
  48912. };
  48913. }
  48914. };
  48915. }();
  48916. function isPDFFunction(v) {
  48917. var fnDict;
  48918. if (typeof v !== 'object') {
  48919. return false;
  48920. } else if (isDict(v)) {
  48921. fnDict = v;
  48922. } else if (isStream(v)) {
  48923. fnDict = v.dict;
  48924. } else {
  48925. return false;
  48926. }
  48927. return fnDict.has('FunctionType');
  48928. }
  48929. var PostScriptStack = function PostScriptStackClosure() {
  48930. var MAX_STACK_SIZE = 100;
  48931. function PostScriptStack(initialStack) {
  48932. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  48933. }
  48934. PostScriptStack.prototype = {
  48935. push: function PostScriptStack_push(value) {
  48936. if (this.stack.length >= MAX_STACK_SIZE) {
  48937. error('PostScript function stack overflow.');
  48938. }
  48939. this.stack.push(value);
  48940. },
  48941. pop: function PostScriptStack_pop() {
  48942. if (this.stack.length <= 0) {
  48943. error('PostScript function stack underflow.');
  48944. }
  48945. return this.stack.pop();
  48946. },
  48947. copy: function PostScriptStack_copy(n) {
  48948. if (this.stack.length + n >= MAX_STACK_SIZE) {
  48949. error('PostScript function stack overflow.');
  48950. }
  48951. var stack = this.stack;
  48952. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  48953. stack.push(stack[i]);
  48954. }
  48955. },
  48956. index: function PostScriptStack_index(n) {
  48957. this.push(this.stack[this.stack.length - n - 1]);
  48958. },
  48959. // rotate the last n stack elements p times
  48960. roll: function PostScriptStack_roll(n, p) {
  48961. var stack = this.stack;
  48962. var l = stack.length - n;
  48963. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  48964. for (i = l, j = r; i < j; i++, j--) {
  48965. t = stack[i];
  48966. stack[i] = stack[j];
  48967. stack[j] = t;
  48968. }
  48969. for (i = l, j = c - 1; i < j; i++, j--) {
  48970. t = stack[i];
  48971. stack[i] = stack[j];
  48972. stack[j] = t;
  48973. }
  48974. for (i = c, j = r; i < j; i++, j--) {
  48975. t = stack[i];
  48976. stack[i] = stack[j];
  48977. stack[j] = t;
  48978. }
  48979. }
  48980. };
  48981. return PostScriptStack;
  48982. }();
  48983. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  48984. function PostScriptEvaluator(operators) {
  48985. this.operators = operators;
  48986. }
  48987. PostScriptEvaluator.prototype = {
  48988. execute: function PostScriptEvaluator_execute(initialStack) {
  48989. var stack = new PostScriptStack(initialStack);
  48990. var counter = 0;
  48991. var operators = this.operators;
  48992. var length = operators.length;
  48993. var operator, a, b;
  48994. while (counter < length) {
  48995. operator = operators[counter++];
  48996. if (typeof operator === 'number') {
  48997. // Operator is really an operand and should be pushed to the stack.
  48998. stack.push(operator);
  48999. continue;
  49000. }
  49001. switch (operator) {
  49002. // non standard ps operators
  49003. case 'jz':
  49004. // jump if false
  49005. b = stack.pop();
  49006. a = stack.pop();
  49007. if (!a) {
  49008. counter = b;
  49009. }
  49010. break;
  49011. case 'j':
  49012. // jump
  49013. a = stack.pop();
  49014. counter = a;
  49015. break;
  49016. // all ps operators in alphabetical order (excluding if/ifelse)
  49017. case 'abs':
  49018. a = stack.pop();
  49019. stack.push(Math.abs(a));
  49020. break;
  49021. case 'add':
  49022. b = stack.pop();
  49023. a = stack.pop();
  49024. stack.push(a + b);
  49025. break;
  49026. case 'and':
  49027. b = stack.pop();
  49028. a = stack.pop();
  49029. if (isBool(a) && isBool(b)) {
  49030. stack.push(a && b);
  49031. } else {
  49032. stack.push(a & b);
  49033. }
  49034. break;
  49035. case 'atan':
  49036. a = stack.pop();
  49037. stack.push(Math.atan(a));
  49038. break;
  49039. case 'bitshift':
  49040. b = stack.pop();
  49041. a = stack.pop();
  49042. if (a > 0) {
  49043. stack.push(a << b);
  49044. } else {
  49045. stack.push(a >> b);
  49046. }
  49047. break;
  49048. case 'ceiling':
  49049. a = stack.pop();
  49050. stack.push(Math.ceil(a));
  49051. break;
  49052. case 'copy':
  49053. a = stack.pop();
  49054. stack.copy(a);
  49055. break;
  49056. case 'cos':
  49057. a = stack.pop();
  49058. stack.push(Math.cos(a));
  49059. break;
  49060. case 'cvi':
  49061. a = stack.pop() | 0;
  49062. stack.push(a);
  49063. break;
  49064. case 'cvr':
  49065. // noop
  49066. break;
  49067. case 'div':
  49068. b = stack.pop();
  49069. a = stack.pop();
  49070. stack.push(a / b);
  49071. break;
  49072. case 'dup':
  49073. stack.copy(1);
  49074. break;
  49075. case 'eq':
  49076. b = stack.pop();
  49077. a = stack.pop();
  49078. stack.push(a === b);
  49079. break;
  49080. case 'exch':
  49081. stack.roll(2, 1);
  49082. break;
  49083. case 'exp':
  49084. b = stack.pop();
  49085. a = stack.pop();
  49086. stack.push(Math.pow(a, b));
  49087. break;
  49088. case 'false':
  49089. stack.push(false);
  49090. break;
  49091. case 'floor':
  49092. a = stack.pop();
  49093. stack.push(Math.floor(a));
  49094. break;
  49095. case 'ge':
  49096. b = stack.pop();
  49097. a = stack.pop();
  49098. stack.push(a >= b);
  49099. break;
  49100. case 'gt':
  49101. b = stack.pop();
  49102. a = stack.pop();
  49103. stack.push(a > b);
  49104. break;
  49105. case 'idiv':
  49106. b = stack.pop();
  49107. a = stack.pop();
  49108. stack.push(a / b | 0);
  49109. break;
  49110. case 'index':
  49111. a = stack.pop();
  49112. stack.index(a);
  49113. break;
  49114. case 'le':
  49115. b = stack.pop();
  49116. a = stack.pop();
  49117. stack.push(a <= b);
  49118. break;
  49119. case 'ln':
  49120. a = stack.pop();
  49121. stack.push(Math.log(a));
  49122. break;
  49123. case 'log':
  49124. a = stack.pop();
  49125. stack.push(Math.log(a) / Math.LN10);
  49126. break;
  49127. case 'lt':
  49128. b = stack.pop();
  49129. a = stack.pop();
  49130. stack.push(a < b);
  49131. break;
  49132. case 'mod':
  49133. b = stack.pop();
  49134. a = stack.pop();
  49135. stack.push(a % b);
  49136. break;
  49137. case 'mul':
  49138. b = stack.pop();
  49139. a = stack.pop();
  49140. stack.push(a * b);
  49141. break;
  49142. case 'ne':
  49143. b = stack.pop();
  49144. a = stack.pop();
  49145. stack.push(a !== b);
  49146. break;
  49147. case 'neg':
  49148. a = stack.pop();
  49149. stack.push(-a);
  49150. break;
  49151. case 'not':
  49152. a = stack.pop();
  49153. if (isBool(a)) {
  49154. stack.push(!a);
  49155. } else {
  49156. stack.push(~a);
  49157. }
  49158. break;
  49159. case 'or':
  49160. b = stack.pop();
  49161. a = stack.pop();
  49162. if (isBool(a) && isBool(b)) {
  49163. stack.push(a || b);
  49164. } else {
  49165. stack.push(a | b);
  49166. }
  49167. break;
  49168. case 'pop':
  49169. stack.pop();
  49170. break;
  49171. case 'roll':
  49172. b = stack.pop();
  49173. a = stack.pop();
  49174. stack.roll(a, b);
  49175. break;
  49176. case 'round':
  49177. a = stack.pop();
  49178. stack.push(Math.round(a));
  49179. break;
  49180. case 'sin':
  49181. a = stack.pop();
  49182. stack.push(Math.sin(a));
  49183. break;
  49184. case 'sqrt':
  49185. a = stack.pop();
  49186. stack.push(Math.sqrt(a));
  49187. break;
  49188. case 'sub':
  49189. b = stack.pop();
  49190. a = stack.pop();
  49191. stack.push(a - b);
  49192. break;
  49193. case 'true':
  49194. stack.push(true);
  49195. break;
  49196. case 'truncate':
  49197. a = stack.pop();
  49198. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  49199. stack.push(a);
  49200. break;
  49201. case 'xor':
  49202. b = stack.pop();
  49203. a = stack.pop();
  49204. if (isBool(a) && isBool(b)) {
  49205. stack.push(a !== b);
  49206. } else {
  49207. stack.push(a ^ b);
  49208. }
  49209. break;
  49210. default:
  49211. error('Unknown operator ' + operator);
  49212. break;
  49213. }
  49214. }
  49215. return stack.stack;
  49216. }
  49217. };
  49218. return PostScriptEvaluator;
  49219. }();
  49220. // Most of the PDFs functions consist of simple operations such as:
  49221. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  49222. //
  49223. // We can compile most of such programs, and at the same moment, we can
  49224. // optimize some expressions using basic math properties. Keeping track of
  49225. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  49226. var PostScriptCompiler = function PostScriptCompilerClosure() {
  49227. function AstNode(type) {
  49228. this.type = type;
  49229. }
  49230. AstNode.prototype.visit = function (visitor) {
  49231. throw new Error('abstract method');
  49232. };
  49233. function AstArgument(index, min, max) {
  49234. AstNode.call(this, 'args');
  49235. this.index = index;
  49236. this.min = min;
  49237. this.max = max;
  49238. }
  49239. AstArgument.prototype = Object.create(AstNode.prototype);
  49240. AstArgument.prototype.visit = function (visitor) {
  49241. visitor.visitArgument(this);
  49242. };
  49243. function AstLiteral(number) {
  49244. AstNode.call(this, 'literal');
  49245. this.number = number;
  49246. this.min = number;
  49247. this.max = number;
  49248. }
  49249. AstLiteral.prototype = Object.create(AstNode.prototype);
  49250. AstLiteral.prototype.visit = function (visitor) {
  49251. visitor.visitLiteral(this);
  49252. };
  49253. function AstBinaryOperation(op, arg1, arg2, min, max) {
  49254. AstNode.call(this, 'binary');
  49255. this.op = op;
  49256. this.arg1 = arg1;
  49257. this.arg2 = arg2;
  49258. this.min = min;
  49259. this.max = max;
  49260. }
  49261. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  49262. AstBinaryOperation.prototype.visit = function (visitor) {
  49263. visitor.visitBinaryOperation(this);
  49264. };
  49265. function AstMin(arg, max) {
  49266. AstNode.call(this, 'max');
  49267. this.arg = arg;
  49268. this.min = arg.min;
  49269. this.max = max;
  49270. }
  49271. AstMin.prototype = Object.create(AstNode.prototype);
  49272. AstMin.prototype.visit = function (visitor) {
  49273. visitor.visitMin(this);
  49274. };
  49275. function AstVariable(index, min, max) {
  49276. AstNode.call(this, 'var');
  49277. this.index = index;
  49278. this.min = min;
  49279. this.max = max;
  49280. }
  49281. AstVariable.prototype = Object.create(AstNode.prototype);
  49282. AstVariable.prototype.visit = function (visitor) {
  49283. visitor.visitVariable(this);
  49284. };
  49285. function AstVariableDefinition(variable, arg) {
  49286. AstNode.call(this, 'definition');
  49287. this.variable = variable;
  49288. this.arg = arg;
  49289. }
  49290. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  49291. AstVariableDefinition.prototype.visit = function (visitor) {
  49292. visitor.visitVariableDefinition(this);
  49293. };
  49294. function ExpressionBuilderVisitor() {
  49295. this.parts = [];
  49296. }
  49297. ExpressionBuilderVisitor.prototype = {
  49298. visitArgument: function (arg) {
  49299. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  49300. },
  49301. visitVariable: function (variable) {
  49302. this.parts.push('v', variable.index);
  49303. },
  49304. visitLiteral: function (literal) {
  49305. this.parts.push(literal.number);
  49306. },
  49307. visitBinaryOperation: function (operation) {
  49308. this.parts.push('(');
  49309. operation.arg1.visit(this);
  49310. this.parts.push(' ', operation.op, ' ');
  49311. operation.arg2.visit(this);
  49312. this.parts.push(')');
  49313. },
  49314. visitVariableDefinition: function (definition) {
  49315. this.parts.push('var ');
  49316. definition.variable.visit(this);
  49317. this.parts.push(' = ');
  49318. definition.arg.visit(this);
  49319. this.parts.push(';');
  49320. },
  49321. visitMin: function (max) {
  49322. this.parts.push('Math.min(');
  49323. max.arg.visit(this);
  49324. this.parts.push(', ', max.max, ')');
  49325. },
  49326. toString: function () {
  49327. return this.parts.join('');
  49328. }
  49329. };
  49330. function buildAddOperation(num1, num2) {
  49331. if (num2.type === 'literal' && num2.number === 0) {
  49332. // optimization: second operand is 0
  49333. return num1;
  49334. }
  49335. if (num1.type === 'literal' && num1.number === 0) {
  49336. // optimization: first operand is 0
  49337. return num2;
  49338. }
  49339. if (num2.type === 'literal' && num1.type === 'literal') {
  49340. // optimization: operands operand are literals
  49341. return new AstLiteral(num1.number + num2.number);
  49342. }
  49343. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  49344. }
  49345. function buildMulOperation(num1, num2) {
  49346. if (num2.type === 'literal') {
  49347. // optimization: second operands is a literal...
  49348. if (num2.number === 0) {
  49349. return new AstLiteral(0);
  49350. } else // and it's 0
  49351. if (num2.number === 1) {
  49352. return num1;
  49353. } else // and it's 1
  49354. if (num1.type === 'literal') {
  49355. // ... and first operands is a literal too
  49356. return new AstLiteral(num1.number * num2.number);
  49357. }
  49358. }
  49359. if (num1.type === 'literal') {
  49360. // optimization: first operands is a literal...
  49361. if (num1.number === 0) {
  49362. return new AstLiteral(0);
  49363. } else // and it's 0
  49364. if (num1.number === 1) {
  49365. return num2;
  49366. }
  49367. }
  49368. // and it's 1
  49369. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  49370. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  49371. return new AstBinaryOperation('*', num1, num2, min, max);
  49372. }
  49373. function buildSubOperation(num1, num2) {
  49374. if (num2.type === 'literal') {
  49375. // optimization: second operands is a literal...
  49376. if (num2.number === 0) {
  49377. return num1;
  49378. } else // ... and it's 0
  49379. if (num1.type === 'literal') {
  49380. // ... and first operands is a literal too
  49381. return new AstLiteral(num1.number - num2.number);
  49382. }
  49383. }
  49384. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  49385. // optimization for case: 1 - (1 - x)
  49386. return num2.arg2;
  49387. }
  49388. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  49389. }
  49390. function buildMinOperation(num1, max) {
  49391. if (num1.min >= max) {
  49392. // optimization: num1 min value is not less than required max
  49393. return new AstLiteral(max);
  49394. } else // just returning max
  49395. if (num1.max <= max) {
  49396. // optimization: num1 max value is not greater than required max
  49397. return num1;
  49398. }
  49399. // just returning an argument
  49400. return new AstMin(num1, max);
  49401. }
  49402. function PostScriptCompiler() {
  49403. }
  49404. PostScriptCompiler.prototype = {
  49405. compile: function PostScriptCompiler_compile(code, domain, range) {
  49406. var stack = [];
  49407. var i, ii;
  49408. var instructions = [];
  49409. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  49410. var lastRegister = 0;
  49411. var n, j;
  49412. var num1, num2, ast1, ast2, tmpVar, item;
  49413. for (i = 0; i < inputSize; i++) {
  49414. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  49415. }
  49416. for (i = 0, ii = code.length; i < ii; i++) {
  49417. item = code[i];
  49418. if (typeof item === 'number') {
  49419. stack.push(new AstLiteral(item));
  49420. continue;
  49421. }
  49422. switch (item) {
  49423. case 'add':
  49424. if (stack.length < 2) {
  49425. return null;
  49426. }
  49427. num2 = stack.pop();
  49428. num1 = stack.pop();
  49429. stack.push(buildAddOperation(num1, num2));
  49430. break;
  49431. case 'cvr':
  49432. if (stack.length < 1) {
  49433. return null;
  49434. }
  49435. break;
  49436. case 'mul':
  49437. if (stack.length < 2) {
  49438. return null;
  49439. }
  49440. num2 = stack.pop();
  49441. num1 = stack.pop();
  49442. stack.push(buildMulOperation(num1, num2));
  49443. break;
  49444. case 'sub':
  49445. if (stack.length < 2) {
  49446. return null;
  49447. }
  49448. num2 = stack.pop();
  49449. num1 = stack.pop();
  49450. stack.push(buildSubOperation(num1, num2));
  49451. break;
  49452. case 'exch':
  49453. if (stack.length < 2) {
  49454. return null;
  49455. }
  49456. ast1 = stack.pop();
  49457. ast2 = stack.pop();
  49458. stack.push(ast1, ast2);
  49459. break;
  49460. case 'pop':
  49461. if (stack.length < 1) {
  49462. return null;
  49463. }
  49464. stack.pop();
  49465. break;
  49466. case 'index':
  49467. if (stack.length < 1) {
  49468. return null;
  49469. }
  49470. num1 = stack.pop();
  49471. if (num1.type !== 'literal') {
  49472. return null;
  49473. }
  49474. n = num1.number;
  49475. if (n < 0 || (n | 0) !== n || stack.length < n) {
  49476. return null;
  49477. }
  49478. ast1 = stack[stack.length - n - 1];
  49479. if (ast1.type === 'literal' || ast1.type === 'var') {
  49480. stack.push(ast1);
  49481. break;
  49482. }
  49483. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  49484. stack[stack.length - n - 1] = tmpVar;
  49485. stack.push(tmpVar);
  49486. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  49487. break;
  49488. case 'dup':
  49489. if (stack.length < 1) {
  49490. return null;
  49491. }
  49492. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' && code[i + 3] === i + 7 && code[i + 4] === 'jz' && code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  49493. // special case of the commands sequence for the min operation
  49494. num1 = stack.pop();
  49495. stack.push(buildMinOperation(num1, code[i + 1]));
  49496. i += 6;
  49497. break;
  49498. }
  49499. ast1 = stack[stack.length - 1];
  49500. if (ast1.type === 'literal' || ast1.type === 'var') {
  49501. // we don't have to save into intermediate variable a literal or
  49502. // variable.
  49503. stack.push(ast1);
  49504. break;
  49505. }
  49506. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  49507. stack[stack.length - 1] = tmpVar;
  49508. stack.push(tmpVar);
  49509. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  49510. break;
  49511. case 'roll':
  49512. if (stack.length < 2) {
  49513. return null;
  49514. }
  49515. num2 = stack.pop();
  49516. num1 = stack.pop();
  49517. if (num2.type !== 'literal' || num1.type !== 'literal') {
  49518. // both roll operands must be numbers
  49519. return null;
  49520. }
  49521. j = num2.number;
  49522. n = num1.number;
  49523. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  49524. // ... and integers
  49525. return null;
  49526. }
  49527. j = (j % n + n) % n;
  49528. if (j === 0) {
  49529. break;
  49530. }
  49531. // just skipping -- there are nothing to rotate
  49532. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  49533. break;
  49534. default:
  49535. return null;
  49536. }
  49537. }
  49538. // unsupported operator
  49539. if (stack.length !== outputSize) {
  49540. return null;
  49541. }
  49542. var result = [];
  49543. instructions.forEach(function (instruction) {
  49544. var statementBuilder = new ExpressionBuilderVisitor();
  49545. instruction.visit(statementBuilder);
  49546. result.push(statementBuilder.toString());
  49547. });
  49548. stack.forEach(function (expr, i) {
  49549. var statementBuilder = new ExpressionBuilderVisitor();
  49550. expr.visit(statementBuilder);
  49551. var min = range[i * 2], max = range[i * 2 + 1];
  49552. var out = [statementBuilder.toString()];
  49553. if (min > expr.min) {
  49554. out.unshift('Math.max(', min, ', ');
  49555. out.push(')');
  49556. }
  49557. if (max < expr.max) {
  49558. out.unshift('Math.min(', max, ', ');
  49559. out.push(')');
  49560. }
  49561. out.unshift('dest[destOffset + ', i, '] = ');
  49562. out.push(';');
  49563. result.push(out.join(''));
  49564. });
  49565. return result.join('\n');
  49566. }
  49567. };
  49568. return PostScriptCompiler;
  49569. }();
  49570. exports.isPDFFunction = isPDFFunction;
  49571. exports.PDFFunction = PDFFunction;
  49572. exports.PostScriptEvaluator = PostScriptEvaluator;
  49573. exports.PostScriptCompiler = PostScriptCompiler;
  49574. }));
  49575. (function (root, factory) {
  49576. factory(root.pdfjsDisplayAPI = {}, root.pdfjsSharedUtil, root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas, root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  49577. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas, displayMetadata, displayDOMUtils, amdRequire) {
  49578. var InvalidPDFException = sharedUtil.InvalidPDFException;
  49579. var MessageHandler = sharedUtil.MessageHandler;
  49580. var MissingPDFException = sharedUtil.MissingPDFException;
  49581. var PageViewport = sharedUtil.PageViewport;
  49582. var PasswordResponses = sharedUtil.PasswordResponses;
  49583. var PasswordException = sharedUtil.PasswordException;
  49584. var StatTimer = sharedUtil.StatTimer;
  49585. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  49586. var UnknownErrorException = sharedUtil.UnknownErrorException;
  49587. var Util = sharedUtil.Util;
  49588. var createPromiseCapability = sharedUtil.createPromiseCapability;
  49589. var error = sharedUtil.error;
  49590. var deprecated = sharedUtil.deprecated;
  49591. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  49592. var info = sharedUtil.info;
  49593. var isInt = sharedUtil.isInt;
  49594. var isArray = sharedUtil.isArray;
  49595. var isArrayBuffer = sharedUtil.isArrayBuffer;
  49596. var isSameOrigin = sharedUtil.isSameOrigin;
  49597. var loadJpegStream = sharedUtil.loadJpegStream;
  49598. var stringToBytes = sharedUtil.stringToBytes;
  49599. var globalScope = sharedUtil.globalScope;
  49600. var warn = sharedUtil.warn;
  49601. var FontFaceObject = displayFontLoader.FontFaceObject;
  49602. var FontLoader = displayFontLoader.FontLoader;
  49603. var CanvasGraphics = displayCanvas.CanvasGraphics;
  49604. var createScratchCanvas = displayCanvas.createScratchCanvas;
  49605. var Metadata = displayMetadata.Metadata;
  49606. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  49607. var DEFAULT_RANGE_CHUNK_SIZE = 65536;
  49608. // 2^16 = 65536
  49609. var isWorkerDisabled = false;
  49610. var workerSrc;
  49611. var isPostMessageTransfersDisabled = false;
  49612. var fakeWorkerFilesLoader = null;
  49613. var useRequireEnsure = false;
  49614. /**
  49615. * Document initialization / loading parameters object.
  49616. *
  49617. * @typedef {Object} DocumentInitParameters
  49618. * @property {string} url - The URL of the PDF.
  49619. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  49620. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  49621. * use atob() to convert it to a binary string first.
  49622. * @property {Object} httpHeaders - Basic authentication headers.
  49623. * @property {boolean} withCredentials - Indicates whether or not cross-site
  49624. * Access-Control requests should be made using credentials such as cookies
  49625. * or authorization headers. The default is false.
  49626. * @property {string} password - For decrypting password-protected PDFs.
  49627. * @property {TypedArray} initialData - A typed array with the first portion or
  49628. * all of the pdf data. Used by the extension since some data is already
  49629. * loaded before the switch to range requests.
  49630. * @property {number} length - The PDF file length. It's used for progress
  49631. * reports and range requests operations.
  49632. * @property {PDFDataRangeTransport} range
  49633. * @property {number} rangeChunkSize - Optional parameter to specify
  49634. * maximum number of bytes fetched per range request. The default value is
  49635. * 2^16 = 65536.
  49636. * @property {PDFWorker} worker - The worker that will be used for the loading
  49637. * and parsing of the PDF data.
  49638. * @property {string} docBaseUrl - (optional) The base URL of the document,
  49639. * used when attempting to recover valid absolute URLs for annotations, and
  49640. * outline items, that (incorrectly) only specify relative URLs.
  49641. */
  49642. /**
  49643. * @typedef {Object} PDFDocumentStats
  49644. * @property {Array} streamTypes - Used stream types in the document (an item
  49645. * is set to true if specific stream ID was used in the document).
  49646. * @property {Array} fontTypes - Used font type in the document (an item is set
  49647. * to true if specific font ID was used in the document).
  49648. */
  49649. /**
  49650. * This is the main entry point for loading a PDF and interacting with it.
  49651. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  49652. * is used, which means it must follow the same origin rules that any XHR does
  49653. * e.g. No cross domain requests without CORS.
  49654. *
  49655. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  49656. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  49657. * already populated with data or parameter object.
  49658. *
  49659. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  49660. * if you want to manually serve range requests for data in the PDF.
  49661. *
  49662. * @param {function} passwordCallback (deprecated) It is used to request a
  49663. * password if wrong or no password was provided. The callback receives two
  49664. * parameters: function that needs to be called with new password and reason
  49665. * (see {PasswordResponses}).
  49666. *
  49667. * @param {function} progressCallback (deprecated) It is used to be able to
  49668. * monitor the loading progress of the PDF file (necessary to implement e.g.
  49669. * a loading bar). The callback receives an {Object} with the properties:
  49670. * {number} loaded and {number} total.
  49671. *
  49672. * @return {PDFDocumentLoadingTask}
  49673. */
  49674. function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallback) {
  49675. var task = new PDFDocumentLoadingTask();
  49676. // Support of the obsolete arguments (for compatibility with API v1.0)
  49677. if (arguments.length > 1) {
  49678. deprecated('getDocument is called with pdfDataRangeTransport, ' + 'passwordCallback or progressCallback argument');
  49679. }
  49680. if (pdfDataRangeTransport) {
  49681. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  49682. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  49683. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  49684. pdfDataRangeTransport.length = src.length;
  49685. pdfDataRangeTransport.initialData = src.initialData;
  49686. if (!pdfDataRangeTransport.abort) {
  49687. pdfDataRangeTransport.abort = function () {
  49688. };
  49689. }
  49690. }
  49691. src = Object.create(src);
  49692. src.range = pdfDataRangeTransport;
  49693. }
  49694. task.onPassword = passwordCallback || null;
  49695. task.onProgress = progressCallback || null;
  49696. var source;
  49697. if (typeof src === 'string') {
  49698. source = { url: src };
  49699. } else if (isArrayBuffer(src)) {
  49700. source = { data: src };
  49701. } else if (src instanceof PDFDataRangeTransport) {
  49702. source = { range: src };
  49703. } else {
  49704. if (typeof src !== 'object') {
  49705. error('Invalid parameter in getDocument, need either Uint8Array, ' + 'string or a parameter object');
  49706. }
  49707. if (!src.url && !src.data && !src.range) {
  49708. error('Invalid parameter object: need either .data, .range or .url');
  49709. }
  49710. source = src;
  49711. }
  49712. var params = {};
  49713. var rangeTransport = null;
  49714. var worker = null;
  49715. for (var key in source) {
  49716. if (key === 'url' && typeof window !== 'undefined') {
  49717. // The full path is required in the 'url' field.
  49718. params[key] = new URL(source[key], window.location).href;
  49719. continue;
  49720. } else if (key === 'range') {
  49721. rangeTransport = source[key];
  49722. continue;
  49723. } else if (key === 'worker') {
  49724. worker = source[key];
  49725. continue;
  49726. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  49727. // Converting string or array-like data to Uint8Array.
  49728. var pdfBytes = source[key];
  49729. if (typeof pdfBytes === 'string') {
  49730. params[key] = stringToBytes(pdfBytes);
  49731. } else if (typeof pdfBytes === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  49732. params[key] = new Uint8Array(pdfBytes);
  49733. } else if (isArrayBuffer(pdfBytes)) {
  49734. params[key] = new Uint8Array(pdfBytes);
  49735. } else {
  49736. error('Invalid PDF binary data: either typed array, string or ' + 'array-like object is expected in the data property.');
  49737. }
  49738. continue;
  49739. }
  49740. params[key] = source[key];
  49741. }
  49742. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  49743. if (!worker) {
  49744. // Worker was not provided -- creating and owning our own.
  49745. worker = new PDFWorker();
  49746. task._worker = worker;
  49747. }
  49748. var docId = task.docId;
  49749. worker.promise.then(function () {
  49750. if (task.destroyed) {
  49751. throw new Error('Loading aborted');
  49752. }
  49753. return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) {
  49754. if (task.destroyed) {
  49755. throw new Error('Loading aborted');
  49756. }
  49757. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  49758. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  49759. task._transport = transport;
  49760. messageHandler.send('Ready', null);
  49761. });
  49762. }).catch(task._capability.reject);
  49763. return task;
  49764. }
  49765. /**
  49766. * Starts fetching of specified PDF document/data.
  49767. * @param {PDFWorker} worker
  49768. * @param {Object} source
  49769. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  49770. * @param {string} docId Unique document id, used as MessageHandler id.
  49771. * @returns {Promise} The promise, which is resolved when worker id of
  49772. * MessageHandler is known.
  49773. * @private
  49774. */
  49775. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  49776. if (worker.destroyed) {
  49777. return Promise.reject(new Error('Worker was destroyed'));
  49778. }
  49779. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  49780. source.disableStream = getDefaultSetting('disableStream');
  49781. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  49782. if (pdfDataRangeTransport) {
  49783. source.length = pdfDataRangeTransport.length;
  49784. source.initialData = pdfDataRangeTransport.initialData;
  49785. }
  49786. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  49787. docId: docId,
  49788. source: source,
  49789. disableRange: getDefaultSetting('disableRange'),
  49790. maxImageSize: getDefaultSetting('maxImageSize'),
  49791. cMapUrl: getDefaultSetting('cMapUrl'),
  49792. cMapPacked: getDefaultSetting('cMapPacked'),
  49793. disableFontFace: getDefaultSetting('disableFontFace'),
  49794. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  49795. postMessageTransfers: getDefaultSetting('postMessageTransfers') && !isPostMessageTransfersDisabled,
  49796. docBaseUrl: source.docBaseUrl
  49797. }).then(function (workerId) {
  49798. if (worker.destroyed) {
  49799. throw new Error('Worker was destroyed');
  49800. }
  49801. return workerId;
  49802. });
  49803. }
  49804. /**
  49805. * PDF document loading operation.
  49806. * @class
  49807. * @alias PDFDocumentLoadingTask
  49808. */
  49809. var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  49810. var nextDocumentId = 0;
  49811. /** @constructs PDFDocumentLoadingTask */
  49812. function PDFDocumentLoadingTask() {
  49813. this._capability = createPromiseCapability();
  49814. this._transport = null;
  49815. this._worker = null;
  49816. /**
  49817. * Unique document loading task id -- used in MessageHandlers.
  49818. * @type {string}
  49819. */
  49820. this.docId = 'd' + nextDocumentId++;
  49821. /**
  49822. * Shows if loading task is destroyed.
  49823. * @type {boolean}
  49824. */
  49825. this.destroyed = false;
  49826. /**
  49827. * Callback to request a password if wrong or no password was provided.
  49828. * The callback receives two parameters: function that needs to be called
  49829. * with new password and reason (see {PasswordResponses}).
  49830. */
  49831. this.onPassword = null;
  49832. /**
  49833. * Callback to be able to monitor the loading progress of the PDF file
  49834. * (necessary to implement e.g. a loading bar). The callback receives
  49835. * an {Object} with the properties: {number} loaded and {number} total.
  49836. */
  49837. this.onProgress = null;
  49838. /**
  49839. * Callback to when unsupported feature is used. The callback receives
  49840. * an {UNSUPPORTED_FEATURES} argument.
  49841. */
  49842. this.onUnsupportedFeature = null;
  49843. }
  49844. PDFDocumentLoadingTask.prototype = /** @lends PDFDocumentLoadingTask.prototype */
  49845. {
  49846. /**
  49847. * @return {Promise}
  49848. */
  49849. get promise() {
  49850. return this._capability.promise;
  49851. },
  49852. /**
  49853. * Aborts all network requests and destroys worker.
  49854. * @return {Promise} A promise that is resolved after destruction activity
  49855. * is completed.
  49856. */
  49857. destroy: function () {
  49858. this.destroyed = true;
  49859. var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  49860. return transportDestroyed.then(function () {
  49861. this._transport = null;
  49862. if (this._worker) {
  49863. this._worker.destroy();
  49864. this._worker = null;
  49865. }
  49866. }.bind(this));
  49867. },
  49868. /**
  49869. * Registers callbacks to indicate the document loading completion.
  49870. *
  49871. * @param {function} onFulfilled The callback for the loading completion.
  49872. * @param {function} onRejected The callback for the loading failure.
  49873. * @return {Promise} A promise that is resolved after the onFulfilled or
  49874. * onRejected callback.
  49875. */
  49876. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  49877. return this.promise.then.apply(this.promise, arguments);
  49878. }
  49879. };
  49880. return PDFDocumentLoadingTask;
  49881. }();
  49882. /**
  49883. * Abstract class to support range requests file loading.
  49884. * @class
  49885. * @alias PDFDataRangeTransport
  49886. * @param {number} length
  49887. * @param {Uint8Array} initialData
  49888. */
  49889. var PDFDataRangeTransport = function pdfDataRangeTransportClosure() {
  49890. function PDFDataRangeTransport(length, initialData) {
  49891. this.length = length;
  49892. this.initialData = initialData;
  49893. this._rangeListeners = [];
  49894. this._progressListeners = [];
  49895. this._progressiveReadListeners = [];
  49896. this._readyCapability = createPromiseCapability();
  49897. }
  49898. PDFDataRangeTransport.prototype = /** @lends PDFDataRangeTransport.prototype */
  49899. {
  49900. addRangeListener: function PDFDataRangeTransport_addRangeListener(listener) {
  49901. this._rangeListeners.push(listener);
  49902. },
  49903. addProgressListener: function PDFDataRangeTransport_addProgressListener(listener) {
  49904. this._progressListeners.push(listener);
  49905. },
  49906. addProgressiveReadListener: function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  49907. this._progressiveReadListeners.push(listener);
  49908. },
  49909. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  49910. var listeners = this._rangeListeners;
  49911. for (var i = 0, n = listeners.length; i < n; ++i) {
  49912. listeners[i](begin, chunk);
  49913. }
  49914. },
  49915. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  49916. this._readyCapability.promise.then(function () {
  49917. var listeners = this._progressListeners;
  49918. for (var i = 0, n = listeners.length; i < n; ++i) {
  49919. listeners[i](loaded);
  49920. }
  49921. }.bind(this));
  49922. },
  49923. onDataProgressiveRead: function PDFDataRangeTransport_onDataProgress(chunk) {
  49924. this._readyCapability.promise.then(function () {
  49925. var listeners = this._progressiveReadListeners;
  49926. for (var i = 0, n = listeners.length; i < n; ++i) {
  49927. listeners[i](chunk);
  49928. }
  49929. }.bind(this));
  49930. },
  49931. transportReady: function PDFDataRangeTransport_transportReady() {
  49932. this._readyCapability.resolve();
  49933. },
  49934. requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) {
  49935. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  49936. },
  49937. abort: function PDFDataRangeTransport_abort() {
  49938. }
  49939. };
  49940. return PDFDataRangeTransport;
  49941. }();
  49942. /**
  49943. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  49944. * properties that can be read synchronously.
  49945. * @class
  49946. * @alias PDFDocumentProxy
  49947. */
  49948. var PDFDocumentProxy = function PDFDocumentProxyClosure() {
  49949. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  49950. this.pdfInfo = pdfInfo;
  49951. this.transport = transport;
  49952. this.loadingTask = loadingTask;
  49953. }
  49954. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */
  49955. {
  49956. /**
  49957. * @return {number} Total number of pages the PDF contains.
  49958. */
  49959. get numPages() {
  49960. return this.pdfInfo.numPages;
  49961. },
  49962. /**
  49963. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  49964. * unique.
  49965. */
  49966. get fingerprint() {
  49967. return this.pdfInfo.fingerprint;
  49968. },
  49969. /**
  49970. * @param {number} pageNumber The page number to get. The first page is 1.
  49971. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  49972. * object.
  49973. */
  49974. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  49975. return this.transport.getPage(pageNumber);
  49976. },
  49977. /**
  49978. * @param {{num: number, gen: number}} ref The page reference. Must have
  49979. * the 'num' and 'gen' properties.
  49980. * @return {Promise} A promise that is resolved with the page index that is
  49981. * associated with the reference.
  49982. */
  49983. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  49984. return this.transport.getPageIndex(ref);
  49985. },
  49986. /**
  49987. * @return {Promise} A promise that is resolved with a lookup table for
  49988. * mapping named destinations to reference numbers.
  49989. *
  49990. * This can be slow for large documents: use getDestination instead
  49991. */
  49992. getDestinations: function PDFDocumentProxy_getDestinations() {
  49993. return this.transport.getDestinations();
  49994. },
  49995. /**
  49996. * @param {string} id The named destination to get.
  49997. * @return {Promise} A promise that is resolved with all information
  49998. * of the given named destination.
  49999. */
  50000. getDestination: function PDFDocumentProxy_getDestination(id) {
  50001. return this.transport.getDestination(id);
  50002. },
  50003. /**
  50004. * @return {Promise} A promise that is resolved with:
  50005. * an Array containing the pageLabels that correspond to the pageIndexes,
  50006. * or `null` when no pageLabels are present in the PDF file.
  50007. */
  50008. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  50009. return this.transport.getPageLabels();
  50010. },
  50011. /**
  50012. * @return {Promise} A promise that is resolved with a lookup table for
  50013. * mapping named attachments to their content.
  50014. */
  50015. getAttachments: function PDFDocumentProxy_getAttachments() {
  50016. return this.transport.getAttachments();
  50017. },
  50018. /**
  50019. * @return {Promise} A promise that is resolved with an array of all the
  50020. * JavaScript strings in the name tree.
  50021. */
  50022. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  50023. return this.transport.getJavaScript();
  50024. },
  50025. /**
  50026. * @return {Promise} A promise that is resolved with an {Array} that is a
  50027. * tree outline (if it has one) of the PDF. The tree is in the format of:
  50028. * [
  50029. * {
  50030. * title: string,
  50031. * bold: boolean,
  50032. * italic: boolean,
  50033. * color: rgb Uint8Array,
  50034. * dest: dest obj,
  50035. * url: string,
  50036. * items: array of more items like this
  50037. * },
  50038. * ...
  50039. * ].
  50040. */
  50041. getOutline: function PDFDocumentProxy_getOutline() {
  50042. return this.transport.getOutline();
  50043. },
  50044. /**
  50045. * @return {Promise} A promise that is resolved with an {Object} that has
  50046. * info and metadata properties. Info is an {Object} filled with anything
  50047. * available in the information dictionary and similarly metadata is a
  50048. * {Metadata} object with information from the metadata section of the PDF.
  50049. */
  50050. getMetadata: function PDFDocumentProxy_getMetadata() {
  50051. return this.transport.getMetadata();
  50052. },
  50053. /**
  50054. * @return {Promise} A promise that is resolved with a TypedArray that has
  50055. * the raw data from the PDF.
  50056. */
  50057. getData: function PDFDocumentProxy_getData() {
  50058. return this.transport.getData();
  50059. },
  50060. /**
  50061. * @return {Promise} A promise that is resolved when the document's data
  50062. * is loaded. It is resolved with an {Object} that contains the length
  50063. * property that indicates size of the PDF data in bytes.
  50064. */
  50065. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  50066. return this.transport.downloadInfoCapability.promise;
  50067. },
  50068. /**
  50069. * @return {Promise} A promise this is resolved with current stats about
  50070. * document structures (see {@link PDFDocumentStats}).
  50071. */
  50072. getStats: function PDFDocumentProxy_getStats() {
  50073. return this.transport.getStats();
  50074. },
  50075. /**
  50076. * Cleans up resources allocated by the document, e.g. created @font-face.
  50077. */
  50078. cleanup: function PDFDocumentProxy_cleanup() {
  50079. this.transport.startCleanup();
  50080. },
  50081. /**
  50082. * Destroys current document instance and terminates worker.
  50083. */
  50084. destroy: function PDFDocumentProxy_destroy() {
  50085. return this.loadingTask.destroy();
  50086. }
  50087. };
  50088. return PDFDocumentProxy;
  50089. }();
  50090. /**
  50091. * Page getTextContent parameters.
  50092. *
  50093. * @typedef {Object} getTextContentParameters
  50094. * @property {boolean} normalizeWhitespace - replaces all occurrences of
  50095. * whitespace with standard spaces (0x20). The default value is `false`.
  50096. * @property {boolean} disableCombineTextItems - do not attempt to combine
  50097. * same line {@link TextItem}'s. The default value is `false`.
  50098. */
  50099. /**
  50100. * Page text content.
  50101. *
  50102. * @typedef {Object} TextContent
  50103. * @property {array} items - array of {@link TextItem}
  50104. * @property {Object} styles - {@link TextStyles} objects, indexed by font name.
  50105. */
  50106. /**
  50107. * Page text content part.
  50108. *
  50109. * @typedef {Object} TextItem
  50110. * @property {string} str - text content.
  50111. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  50112. * @property {array} transform - transformation matrix.
  50113. * @property {number} width - width in device space.
  50114. * @property {number} height - height in device space.
  50115. * @property {string} fontName - font name used by pdf.js for converted font.
  50116. */
  50117. /**
  50118. * Text style.
  50119. *
  50120. * @typedef {Object} TextStyle
  50121. * @property {number} ascent - font ascent.
  50122. * @property {number} descent - font descent.
  50123. * @property {boolean} vertical - text is in vertical mode.
  50124. * @property {string} fontFamily - possible font family
  50125. */
  50126. /**
  50127. * Page annotation parameters.
  50128. *
  50129. * @typedef {Object} GetAnnotationsParameters
  50130. * @property {string} intent - Determines the annotations that will be fetched,
  50131. * can be either 'display' (viewable annotations) or 'print'
  50132. * (printable annotations).
  50133. * If the parameter is omitted, all annotations are fetched.
  50134. */
  50135. /**
  50136. * Page render parameters.
  50137. *
  50138. * @typedef {Object} RenderParameters
  50139. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  50140. * @property {PageViewport} viewport - Rendering viewport obtained by
  50141. * calling of PDFPage.getViewport method.
  50142. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  50143. * (default value is 'display').
  50144. * @property {boolean} renderInteractiveForms - (optional) Whether or not
  50145. * interactive form elements are rendered in the display
  50146. * layer. If so, we do not render them on canvas as well.
  50147. * @property {Array} transform - (optional) Additional transform, applied
  50148. * just before viewport transform.
  50149. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  50150. * endLayout and appendImage functions.
  50151. * @property {function} continueCallback - (deprecated) A function that will be
  50152. * called each time the rendering is paused. To continue
  50153. * rendering call the function that is the first argument
  50154. * to the callback.
  50155. */
  50156. /**
  50157. * PDF page operator list.
  50158. *
  50159. * @typedef {Object} PDFOperatorList
  50160. * @property {Array} fnArray - Array containing the operator functions.
  50161. * @property {Array} argsArray - Array containing the arguments of the
  50162. * functions.
  50163. */
  50164. /**
  50165. * Proxy to a PDFPage in the worker thread.
  50166. * @class
  50167. * @alias PDFPageProxy
  50168. */
  50169. var PDFPageProxy = function PDFPageProxyClosure() {
  50170. function PDFPageProxy(pageIndex, pageInfo, transport) {
  50171. this.pageIndex = pageIndex;
  50172. this.pageInfo = pageInfo;
  50173. this.transport = transport;
  50174. this.stats = new StatTimer();
  50175. this.stats.enabled = getDefaultSetting('enableStats');
  50176. this.commonObjs = transport.commonObjs;
  50177. this.objs = new PDFObjects();
  50178. this.cleanupAfterRender = false;
  50179. this.pendingCleanup = false;
  50180. this.intentStates = Object.create(null);
  50181. this.destroyed = false;
  50182. }
  50183. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */
  50184. {
  50185. /**
  50186. * @return {number} Page number of the page. First page is 1.
  50187. */
  50188. get pageNumber() {
  50189. return this.pageIndex + 1;
  50190. },
  50191. /**
  50192. * @return {number} The number of degrees the page is rotated clockwise.
  50193. */
  50194. get rotate() {
  50195. return this.pageInfo.rotate;
  50196. },
  50197. /**
  50198. * @return {Object} The reference that points to this page. It has 'num' and
  50199. * 'gen' properties.
  50200. */
  50201. get ref() {
  50202. return this.pageInfo.ref;
  50203. },
  50204. /**
  50205. * @return {Array} An array of the visible portion of the PDF page in the
  50206. * user space units - [x1, y1, x2, y2].
  50207. */
  50208. get view() {
  50209. return this.pageInfo.view;
  50210. },
  50211. /**
  50212. * @param {number} scale The desired scale of the viewport.
  50213. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  50214. * defaults to the page rotation.
  50215. * @return {PageViewport} Contains 'width' and 'height' properties
  50216. * along with transforms required for rendering.
  50217. */
  50218. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  50219. if (arguments.length < 2) {
  50220. rotate = this.rotate;
  50221. }
  50222. return new PageViewport(this.view, scale, rotate, 0, 0);
  50223. },
  50224. /**
  50225. * @param {GetAnnotationsParameters} params - Annotation parameters.
  50226. * @return {Promise} A promise that is resolved with an {Array} of the
  50227. * annotation objects.
  50228. */
  50229. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  50230. var intent = params && params.intent || null;
  50231. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  50232. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent);
  50233. this.annotationsIntent = intent;
  50234. }
  50235. return this.annotationsPromise;
  50236. },
  50237. /**
  50238. * Begins the process of rendering a page to the desired context.
  50239. * @param {RenderParameters} params Page render parameters.
  50240. * @return {RenderTask} An object that contains the promise, which
  50241. * is resolved when the page finishes rendering.
  50242. */
  50243. render: function PDFPageProxy_render(params) {
  50244. var stats = this.stats;
  50245. stats.time('Overall');
  50246. // If there was a pending destroy cancel it so no cleanup happens during
  50247. // this call to render.
  50248. this.pendingCleanup = false;
  50249. var renderingIntent = params.intent === 'print' ? 'print' : 'display';
  50250. var renderInteractiveForms = params.renderInteractiveForms === true ? true : /* Default */
  50251. false;
  50252. if (!this.intentStates[renderingIntent]) {
  50253. this.intentStates[renderingIntent] = Object.create(null);
  50254. }
  50255. var intentState = this.intentStates[renderingIntent];
  50256. // If there's no displayReadyCapability yet, then the operatorList
  50257. // was never requested before. Make the request and create the promise.
  50258. if (!intentState.displayReadyCapability) {
  50259. intentState.receivingOperatorList = true;
  50260. intentState.displayReadyCapability = createPromiseCapability();
  50261. intentState.operatorList = {
  50262. fnArray: [],
  50263. argsArray: [],
  50264. lastChunk: false
  50265. };
  50266. this.stats.time('Page Request');
  50267. this.transport.messageHandler.send('RenderPageRequest', {
  50268. pageIndex: this.pageNumber - 1,
  50269. intent: renderingIntent,
  50270. renderInteractiveForms: renderInteractiveForms
  50271. });
  50272. }
  50273. var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber);
  50274. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  50275. if (!intentState.renderTasks) {
  50276. intentState.renderTasks = [];
  50277. }
  50278. intentState.renderTasks.push(internalRenderTask);
  50279. var renderTask = internalRenderTask.task;
  50280. // Obsolete parameter support
  50281. if (params.continueCallback) {
  50282. deprecated('render is used with continueCallback parameter');
  50283. renderTask.onContinue = params.continueCallback;
  50284. }
  50285. var self = this;
  50286. intentState.displayReadyCapability.promise.then(function pageDisplayReadyPromise(transparency) {
  50287. if (self.pendingCleanup) {
  50288. complete();
  50289. return;
  50290. }
  50291. stats.time('Rendering');
  50292. internalRenderTask.initializeGraphics(transparency);
  50293. internalRenderTask.operatorListChanged();
  50294. }, function pageDisplayReadPromiseError(reason) {
  50295. complete(reason);
  50296. });
  50297. function complete(error) {
  50298. var i = intentState.renderTasks.indexOf(internalRenderTask);
  50299. if (i >= 0) {
  50300. intentState.renderTasks.splice(i, 1);
  50301. }
  50302. if (self.cleanupAfterRender) {
  50303. self.pendingCleanup = true;
  50304. }
  50305. self._tryCleanup();
  50306. if (error) {
  50307. internalRenderTask.capability.reject(error);
  50308. } else {
  50309. internalRenderTask.capability.resolve();
  50310. }
  50311. stats.timeEnd('Rendering');
  50312. stats.timeEnd('Overall');
  50313. }
  50314. return renderTask;
  50315. },
  50316. /**
  50317. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  50318. * object that represents page's operator list.
  50319. */
  50320. getOperatorList: function PDFPageProxy_getOperatorList() {
  50321. function operatorListChanged() {
  50322. if (intentState.operatorList.lastChunk) {
  50323. intentState.opListReadCapability.resolve(intentState.operatorList);
  50324. var i = intentState.renderTasks.indexOf(opListTask);
  50325. if (i >= 0) {
  50326. intentState.renderTasks.splice(i, 1);
  50327. }
  50328. }
  50329. }
  50330. var renderingIntent = 'oplist';
  50331. if (!this.intentStates[renderingIntent]) {
  50332. this.intentStates[renderingIntent] = Object.create(null);
  50333. }
  50334. var intentState = this.intentStates[renderingIntent];
  50335. var opListTask;
  50336. if (!intentState.opListReadCapability) {
  50337. opListTask = {};
  50338. opListTask.operatorListChanged = operatorListChanged;
  50339. intentState.receivingOperatorList = true;
  50340. intentState.opListReadCapability = createPromiseCapability();
  50341. intentState.renderTasks = [];
  50342. intentState.renderTasks.push(opListTask);
  50343. intentState.operatorList = {
  50344. fnArray: [],
  50345. argsArray: [],
  50346. lastChunk: false
  50347. };
  50348. this.transport.messageHandler.send('RenderPageRequest', {
  50349. pageIndex: this.pageIndex,
  50350. intent: renderingIntent
  50351. });
  50352. }
  50353. return intentState.opListReadCapability.promise;
  50354. },
  50355. /**
  50356. * @param {getTextContentParameters} params - getTextContent parameters.
  50357. * @return {Promise} That is resolved a {@link TextContent}
  50358. * object that represent the page text content.
  50359. */
  50360. getTextContent: function PDFPageProxy_getTextContent(params) {
  50361. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  50362. pageIndex: this.pageNumber - 1,
  50363. normalizeWhitespace: params && params.normalizeWhitespace === true ? true : /* Default */
  50364. false,
  50365. combineTextItems: params && params.disableCombineTextItems === true ? false : /* Default */
  50366. true
  50367. });
  50368. },
  50369. /**
  50370. * Destroys page object.
  50371. */
  50372. _destroy: function PDFPageProxy_destroy() {
  50373. this.destroyed = true;
  50374. this.transport.pageCache[this.pageIndex] = null;
  50375. var waitOn = [];
  50376. Object.keys(this.intentStates).forEach(function (intent) {
  50377. if (intent === 'oplist') {
  50378. // Avoid errors below, since the renderTasks are just stubs.
  50379. return;
  50380. }
  50381. var intentState = this.intentStates[intent];
  50382. intentState.renderTasks.forEach(function (renderTask) {
  50383. var renderCompleted = renderTask.capability.promise.catch(function () {
  50384. });
  50385. // ignoring failures
  50386. waitOn.push(renderCompleted);
  50387. renderTask.cancel();
  50388. });
  50389. }, this);
  50390. this.objs.clear();
  50391. this.annotationsPromise = null;
  50392. this.pendingCleanup = false;
  50393. return Promise.all(waitOn);
  50394. },
  50395. /**
  50396. * Cleans up resources allocated by the page. (deprecated)
  50397. */
  50398. destroy: function () {
  50399. deprecated('page destroy method, use cleanup() instead');
  50400. this.cleanup();
  50401. },
  50402. /**
  50403. * Cleans up resources allocated by the page.
  50404. */
  50405. cleanup: function PDFPageProxy_cleanup() {
  50406. this.pendingCleanup = true;
  50407. this._tryCleanup();
  50408. },
  50409. /**
  50410. * For internal use only. Attempts to clean up if rendering is in a state
  50411. * where that's possible.
  50412. * @ignore
  50413. */
  50414. _tryCleanup: function PDFPageProxy_tryCleanup() {
  50415. if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) {
  50416. var intentState = this.intentStates[intent];
  50417. return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList;
  50418. }, this)) {
  50419. return;
  50420. }
  50421. Object.keys(this.intentStates).forEach(function (intent) {
  50422. delete this.intentStates[intent];
  50423. }, this);
  50424. this.objs.clear();
  50425. this.annotationsPromise = null;
  50426. this.pendingCleanup = false;
  50427. },
  50428. /**
  50429. * For internal use only.
  50430. * @ignore
  50431. */
  50432. _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) {
  50433. var intentState = this.intentStates[intent];
  50434. // TODO Refactor RenderPageRequest to separate rendering
  50435. // and operator list logic
  50436. if (intentState.displayReadyCapability) {
  50437. intentState.displayReadyCapability.resolve(transparency);
  50438. }
  50439. },
  50440. /**
  50441. * For internal use only.
  50442. * @ignore
  50443. */
  50444. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) {
  50445. var intentState = this.intentStates[intent];
  50446. var i, ii;
  50447. // Add the new chunk to the current operator list.
  50448. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  50449. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  50450. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  50451. }
  50452. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  50453. // Notify all the rendering tasks there are more operators to be consumed.
  50454. for (i = 0; i < intentState.renderTasks.length; i++) {
  50455. intentState.renderTasks[i].operatorListChanged();
  50456. }
  50457. if (operatorListChunk.lastChunk) {
  50458. intentState.receivingOperatorList = false;
  50459. this._tryCleanup();
  50460. }
  50461. }
  50462. };
  50463. return PDFPageProxy;
  50464. }();
  50465. /**
  50466. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  50467. * WorkerTransport for them. If creation of a web worker is not possible,
  50468. * a "fake" worker will be used instead.
  50469. * @class
  50470. */
  50471. var PDFWorker = function PDFWorkerClosure() {
  50472. var nextFakeWorkerId = 0;
  50473. function getWorkerSrc() {
  50474. if (typeof workerSrc !== 'undefined') {
  50475. return workerSrc;
  50476. }
  50477. if (getDefaultSetting('workerSrc')) {
  50478. return getDefaultSetting('workerSrc');
  50479. }
  50480. if (pdfjsFilePath) {
  50481. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  50482. }
  50483. error('No PDFJS.workerSrc specified');
  50484. }
  50485. var fakeWorkerFilesLoadedCapability;
  50486. // Loads worker code into main thread.
  50487. function setupFakeWorkerGlobal() {
  50488. var WorkerMessageHandler;
  50489. if (fakeWorkerFilesLoadedCapability) {
  50490. return fakeWorkerFilesLoadedCapability.promise;
  50491. }
  50492. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  50493. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  50494. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  50495. return fakeWorkerFilesLoadedCapability.promise;
  50496. }
  50497. function FakeWorkerPort(defer) {
  50498. this._listeners = [];
  50499. this._defer = defer;
  50500. this._deferred = Promise.resolve(undefined);
  50501. }
  50502. FakeWorkerPort.prototype = {
  50503. postMessage: function (obj, transfers) {
  50504. function cloneValue(value) {
  50505. // Trying to perform a structured clone close to the spec, including
  50506. // transfers.
  50507. if (typeof value !== 'object' || value === null) {
  50508. return value;
  50509. }
  50510. if (cloned.has(value)) {
  50511. // already cloned the object
  50512. return cloned.get(value);
  50513. }
  50514. var result;
  50515. var buffer;
  50516. if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
  50517. // We found object with ArrayBuffer (typed array).
  50518. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  50519. if (value === buffer) {
  50520. // Special case when we are faking typed arrays in compatibility.js.
  50521. result = value;
  50522. } else if (transferable) {
  50523. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  50524. } else {
  50525. result = new value.constructor(value);
  50526. }
  50527. cloned.set(value, result);
  50528. return result;
  50529. }
  50530. result = isArray(value) ? [] : {};
  50531. cloned.set(value, result);
  50532. // adding to cache now for cyclic references
  50533. // Cloning all value and object properties, however ignoring properties
  50534. // defined via getter.
  50535. for (var i in value) {
  50536. var desc, p = value;
  50537. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  50538. p = Object.getPrototypeOf(p);
  50539. }
  50540. if (typeof desc.value === 'undefined' || typeof desc.value === 'function') {
  50541. continue;
  50542. }
  50543. result[i] = cloneValue(desc.value);
  50544. }
  50545. return result;
  50546. }
  50547. if (!this._defer) {
  50548. this._listeners.forEach(function (listener) {
  50549. listener.call(this, { data: obj });
  50550. }, this);
  50551. return;
  50552. }
  50553. var cloned = new WeakMap();
  50554. var e = { data: cloneValue(obj) };
  50555. this._deferred.then(function () {
  50556. this._listeners.forEach(function (listener) {
  50557. listener.call(this, e);
  50558. }, this);
  50559. }.bind(this));
  50560. },
  50561. addEventListener: function (name, listener) {
  50562. this._listeners.push(listener);
  50563. },
  50564. removeEventListener: function (name, listener) {
  50565. var i = this._listeners.indexOf(listener);
  50566. this._listeners.splice(i, 1);
  50567. },
  50568. terminate: function () {
  50569. this._listeners = [];
  50570. }
  50571. };
  50572. function createCDNWrapper(url) {
  50573. // We will rely on blob URL's property to specify origin.
  50574. // We want this function to fail in case if createObjectURL or Blob do not
  50575. // exist or fail for some reason -- our Worker creation will fail anyway.
  50576. var wrapper = 'importScripts(\'' + url + '\');';
  50577. return URL.createObjectURL(new Blob([wrapper]));
  50578. }
  50579. function PDFWorker(name) {
  50580. this.name = name;
  50581. this.destroyed = false;
  50582. this._readyCapability = createPromiseCapability();
  50583. this._port = null;
  50584. this._webWorker = null;
  50585. this._messageHandler = null;
  50586. this._initialize();
  50587. }
  50588. PDFWorker.prototype = /** @lends PDFWorker.prototype */
  50589. {
  50590. get promise() {
  50591. return this._readyCapability.promise;
  50592. },
  50593. get port() {
  50594. return this._port;
  50595. },
  50596. get messageHandler() {
  50597. return this._messageHandler;
  50598. },
  50599. _initialize: function PDFWorker_initialize() {
  50600. // Either workers are disabled, not supported or have thrown an exception.
  50601. // Thus, we fallback to a faked worker.
  50602. this._setupFakeWorker();
  50603. },
  50604. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  50605. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  50606. warn('Setting up fake worker.');
  50607. isWorkerDisabled = true;
  50608. }
  50609. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  50610. if (this.destroyed) {
  50611. this._readyCapability.reject(new Error('Worker was destroyed'));
  50612. return;
  50613. }
  50614. // We cannot turn on proper fake port simulation (this includes
  50615. // structured cloning) when typed arrays are not supported. Relying
  50616. // on a chance that messages will be sent in proper order.
  50617. var isTypedArraysPresent = Uint8Array !== Float32Array;
  50618. var port = new FakeWorkerPort(isTypedArraysPresent);
  50619. this._port = port;
  50620. // All fake workers use the same port, making id unique.
  50621. var id = 'fake' + nextFakeWorkerId++;
  50622. // If the main thread is our worker, setup the handling for the
  50623. // messages -- the main thread sends to it self.
  50624. var workerHandler = new MessageHandler(id + '_worker', id, port);
  50625. WorkerMessageHandler.setup(workerHandler, port);
  50626. var messageHandler = new MessageHandler(id, id + '_worker', port);
  50627. this._messageHandler = messageHandler;
  50628. this._readyCapability.resolve();
  50629. }.bind(this));
  50630. },
  50631. /**
  50632. * Destroys the worker instance.
  50633. */
  50634. destroy: function PDFWorker_destroy() {
  50635. this.destroyed = true;
  50636. if (this._webWorker) {
  50637. // We need to terminate only web worker created resource.
  50638. this._webWorker.terminate();
  50639. this._webWorker = null;
  50640. }
  50641. this._port = null;
  50642. if (this._messageHandler) {
  50643. this._messageHandler.destroy();
  50644. this._messageHandler = null;
  50645. }
  50646. }
  50647. };
  50648. return PDFWorker;
  50649. }();
  50650. /**
  50651. * For internal use only.
  50652. * @ignore
  50653. */
  50654. var WorkerTransport = function WorkerTransportClosure() {
  50655. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  50656. this.messageHandler = messageHandler;
  50657. this.loadingTask = loadingTask;
  50658. this.pdfDataRangeTransport = pdfDataRangeTransport;
  50659. this.commonObjs = new PDFObjects();
  50660. this.fontLoader = new FontLoader(loadingTask.docId);
  50661. this.destroyed = false;
  50662. this.destroyCapability = null;
  50663. this.pageCache = [];
  50664. this.pagePromises = [];
  50665. this.downloadInfoCapability = createPromiseCapability();
  50666. this.setupMessageHandler();
  50667. }
  50668. WorkerTransport.prototype = {
  50669. destroy: function WorkerTransport_destroy() {
  50670. if (this.destroyCapability) {
  50671. return this.destroyCapability.promise;
  50672. }
  50673. this.destroyed = true;
  50674. this.destroyCapability = createPromiseCapability();
  50675. var waitOn = [];
  50676. // We need to wait for all renderings to be completed, e.g.
  50677. // timeout/rAF can take a long time.
  50678. this.pageCache.forEach(function (page) {
  50679. if (page) {
  50680. waitOn.push(page._destroy());
  50681. }
  50682. });
  50683. this.pageCache = [];
  50684. this.pagePromises = [];
  50685. var self = this;
  50686. // We also need to wait for the worker to finish its long running tasks.
  50687. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  50688. waitOn.push(terminated);
  50689. Promise.all(waitOn).then(function () {
  50690. self.fontLoader.clear();
  50691. if (self.pdfDataRangeTransport) {
  50692. self.pdfDataRangeTransport.abort();
  50693. self.pdfDataRangeTransport = null;
  50694. }
  50695. if (self.messageHandler) {
  50696. self.messageHandler.destroy();
  50697. self.messageHandler = null;
  50698. }
  50699. self.destroyCapability.resolve();
  50700. }, this.destroyCapability.reject);
  50701. return this.destroyCapability.promise;
  50702. },
  50703. setupMessageHandler: function WorkerTransport_setupMessageHandler() {
  50704. var messageHandler = this.messageHandler;
  50705. function updatePassword(password) {
  50706. messageHandler.send('UpdatePassword', password);
  50707. }
  50708. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  50709. if (pdfDataRangeTransport) {
  50710. pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
  50711. messageHandler.send('OnDataRange', {
  50712. begin: begin,
  50713. chunk: chunk
  50714. });
  50715. });
  50716. pdfDataRangeTransport.addProgressListener(function (loaded) {
  50717. messageHandler.send('OnDataProgress', { loaded: loaded });
  50718. });
  50719. pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
  50720. messageHandler.send('OnDataRange', { chunk: chunk });
  50721. });
  50722. messageHandler.on('RequestDataRange', function transportDataRange(data) {
  50723. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  50724. }, this);
  50725. }
  50726. messageHandler.on('GetDoc', function transportDoc(data) {
  50727. var pdfInfo = data.pdfInfo;
  50728. this.numPages = data.pdfInfo.numPages;
  50729. var loadingTask = this.loadingTask;
  50730. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  50731. this.pdfDocument = pdfDocument;
  50732. loadingTask._capability.resolve(pdfDocument);
  50733. }, this);
  50734. messageHandler.on('NeedPassword', function transportNeedPassword(exception) {
  50735. var loadingTask = this.loadingTask;
  50736. if (loadingTask.onPassword) {
  50737. return loadingTask.onPassword(updatePassword, PasswordResponses.NEED_PASSWORD);
  50738. }
  50739. loadingTask._capability.reject(new PasswordException(exception.message, exception.code));
  50740. }, this);
  50741. messageHandler.on('IncorrectPassword', function transportIncorrectPassword(exception) {
  50742. var loadingTask = this.loadingTask;
  50743. if (loadingTask.onPassword) {
  50744. return loadingTask.onPassword(updatePassword, PasswordResponses.INCORRECT_PASSWORD);
  50745. }
  50746. loadingTask._capability.reject(new PasswordException(exception.message, exception.code));
  50747. }, this);
  50748. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  50749. this.loadingTask._capability.reject(new InvalidPDFException(exception.message));
  50750. }, this);
  50751. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  50752. this.loadingTask._capability.reject(new MissingPDFException(exception.message));
  50753. }, this);
  50754. messageHandler.on('UnexpectedResponse', function transportUnexpectedResponse(exception) {
  50755. this.loadingTask._capability.reject(new UnexpectedResponseException(exception.message, exception.status));
  50756. }, this);
  50757. messageHandler.on('UnknownError', function transportUnknownError(exception) {
  50758. this.loadingTask._capability.reject(new UnknownErrorException(exception.message, exception.details));
  50759. }, this);
  50760. messageHandler.on('DataLoaded', function transportPage(data) {
  50761. this.downloadInfoCapability.resolve(data);
  50762. }, this);
  50763. messageHandler.on('PDFManagerReady', function transportPage(data) {
  50764. if (this.pdfDataRangeTransport) {
  50765. this.pdfDataRangeTransport.transportReady();
  50766. }
  50767. }, this);
  50768. messageHandler.on('StartRenderPage', function transportRender(data) {
  50769. if (this.destroyed) {
  50770. return;
  50771. }
  50772. // Ignore any pending requests if the worker was terminated.
  50773. var page = this.pageCache[data.pageIndex];
  50774. page.stats.timeEnd('Page Request');
  50775. page._startRenderPage(data.transparency, data.intent);
  50776. }, this);
  50777. messageHandler.on('RenderPageChunk', function transportRender(data) {
  50778. if (this.destroyed) {
  50779. return;
  50780. }
  50781. // Ignore any pending requests if the worker was terminated.
  50782. var page = this.pageCache[data.pageIndex];
  50783. page._renderPageChunk(data.operatorList, data.intent);
  50784. }, this);
  50785. messageHandler.on('commonobj', function transportObj(data) {
  50786. if (this.destroyed) {
  50787. return;
  50788. }
  50789. // Ignore any pending requests if the worker was terminated.
  50790. var id = data[0];
  50791. var type = data[1];
  50792. if (this.commonObjs.hasData(id)) {
  50793. return;
  50794. }
  50795. switch (type) {
  50796. case 'Font':
  50797. var exportedData = data[2];
  50798. if ('error' in exportedData) {
  50799. var exportedError = exportedData.error;
  50800. warn('Error during font loading: ' + exportedError);
  50801. this.commonObjs.resolve(id, exportedError);
  50802. break;
  50803. }
  50804. var fontRegistry = null;
  50805. if (getDefaultSetting('pdfBug') && globalScope.FontInspector && globalScope['FontInspector'].enabled) {
  50806. fontRegistry = {
  50807. registerFont: function (font, url) {
  50808. globalScope['FontInspector'].fontAdded(font, url);
  50809. }
  50810. };
  50811. }
  50812. var font = new FontFaceObject(exportedData, {
  50813. isEvalSuported: getDefaultSetting('isEvalSupported'),
  50814. disableFontFace: getDefaultSetting('disableFontFace'),
  50815. fontRegistry: fontRegistry
  50816. });
  50817. this.fontLoader.bind([font], function fontReady(fontObjs) {
  50818. this.commonObjs.resolve(id, font);
  50819. }.bind(this));
  50820. break;
  50821. case 'FontPath':
  50822. this.commonObjs.resolve(id, data[2]);
  50823. break;
  50824. default:
  50825. error('Got unknown common object type ' + type);
  50826. }
  50827. }, this);
  50828. messageHandler.on('obj', function transportObj(data) {
  50829. if (this.destroyed) {
  50830. return;
  50831. }
  50832. // Ignore any pending requests if the worker was terminated.
  50833. var id = data[0];
  50834. var pageIndex = data[1];
  50835. var type = data[2];
  50836. var pageProxy = this.pageCache[pageIndex];
  50837. var imageData;
  50838. if (pageProxy.objs.hasData(id)) {
  50839. return;
  50840. }
  50841. switch (type) {
  50842. case 'JpegStream':
  50843. imageData = data[3];
  50844. loadJpegStream(id, imageData, pageProxy.objs);
  50845. break;
  50846. case 'Image':
  50847. imageData = data[3];
  50848. pageProxy.objs.resolve(id, imageData);
  50849. // heuristics that will allow not to store large data
  50850. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  50851. if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  50852. pageProxy.cleanupAfterRender = true;
  50853. }
  50854. break;
  50855. default:
  50856. error('Got unknown object type ' + type);
  50857. }
  50858. }, this);
  50859. messageHandler.on('DocProgress', function transportDocProgress(data) {
  50860. if (this.destroyed) {
  50861. return;
  50862. }
  50863. // Ignore any pending requests if the worker was terminated.
  50864. var loadingTask = this.loadingTask;
  50865. if (loadingTask.onProgress) {
  50866. loadingTask.onProgress({
  50867. loaded: data.loaded,
  50868. total: data.total
  50869. });
  50870. }
  50871. }, this);
  50872. messageHandler.on('PageError', function transportError(data) {
  50873. if (this.destroyed) {
  50874. return;
  50875. }
  50876. // Ignore any pending requests if the worker was terminated.
  50877. var page = this.pageCache[data.pageNum - 1];
  50878. var intentState = page.intentStates[data.intent];
  50879. if (intentState.displayReadyCapability) {
  50880. intentState.displayReadyCapability.reject(data.error);
  50881. } else {
  50882. error(data.error);
  50883. }
  50884. if (intentState.operatorList) {
  50885. // Mark operator list as complete.
  50886. intentState.operatorList.lastChunk = true;
  50887. for (var i = 0; i < intentState.renderTasks.length; i++) {
  50888. intentState.renderTasks[i].operatorListChanged();
  50889. }
  50890. }
  50891. }, this);
  50892. messageHandler.on('UnsupportedFeature', function transportUnsupportedFeature(data) {
  50893. if (this.destroyed) {
  50894. return;
  50895. }
  50896. // Ignore any pending requests if the worker was terminated.
  50897. var featureId = data.featureId;
  50898. var loadingTask = this.loadingTask;
  50899. if (loadingTask.onUnsupportedFeature) {
  50900. loadingTask.onUnsupportedFeature(featureId);
  50901. }
  50902. _UnsupportedManager.notify(featureId);
  50903. }, this);
  50904. messageHandler.on('JpegDecode', function (data) {
  50905. if (this.destroyed) {
  50906. return Promise.reject(new Error('Worker was destroyed'));
  50907. }
  50908. var imageUrl = data[0];
  50909. var components = data[1];
  50910. if (components !== 3 && components !== 1) {
  50911. return Promise.reject(new Error('Only 3 components or 1 component can be returned'));
  50912. }
  50913. return new Promise(function (resolve, reject) {
  50914. var img = new Image();
  50915. img.onload = function () {
  50916. var width = img.width;
  50917. var height = img.height;
  50918. var size = width * height;
  50919. var rgbaLength = size * 4;
  50920. var buf = new Uint8Array(size * components);
  50921. var tmpCanvas = createScratchCanvas(width, height);
  50922. var tmpCtx = tmpCanvas.getContext('2d');
  50923. tmpCtx.drawImage(img, 0, 0);
  50924. var data = tmpCtx.getImageData(0, 0, width, height).data;
  50925. var i, j;
  50926. if (components === 3) {
  50927. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  50928. buf[j] = data[i];
  50929. buf[j + 1] = data[i + 1];
  50930. buf[j + 2] = data[i + 2];
  50931. }
  50932. } else if (components === 1) {
  50933. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  50934. buf[j] = data[i];
  50935. }
  50936. }
  50937. resolve({
  50938. data: buf,
  50939. width: width,
  50940. height: height
  50941. });
  50942. };
  50943. img.onerror = function () {
  50944. reject(new Error('JpegDecode failed to load image'));
  50945. };
  50946. img.src = imageUrl;
  50947. });
  50948. }, this);
  50949. },
  50950. getData: function WorkerTransport_getData() {
  50951. return this.messageHandler.sendWithPromise('GetData', null);
  50952. },
  50953. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  50954. if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  50955. return Promise.reject(new Error('Invalid page request'));
  50956. }
  50957. var pageIndex = pageNumber - 1;
  50958. if (pageIndex in this.pagePromises) {
  50959. return this.pagePromises[pageIndex];
  50960. }
  50961. var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) {
  50962. if (this.destroyed) {
  50963. throw new Error('Transport destroyed');
  50964. }
  50965. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  50966. this.pageCache[pageIndex] = page;
  50967. return page;
  50968. }.bind(this));
  50969. this.pagePromises[pageIndex] = promise;
  50970. return promise;
  50971. },
  50972. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  50973. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) {
  50974. return Promise.reject(new Error(reason));
  50975. });
  50976. },
  50977. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  50978. return this.messageHandler.sendWithPromise('GetAnnotations', {
  50979. pageIndex: pageIndex,
  50980. intent: intent
  50981. });
  50982. },
  50983. getDestinations: function WorkerTransport_getDestinations() {
  50984. return this.messageHandler.sendWithPromise('GetDestinations', null);
  50985. },
  50986. getDestination: function WorkerTransport_getDestination(id) {
  50987. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  50988. },
  50989. getPageLabels: function WorkerTransport_getPageLabels() {
  50990. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  50991. },
  50992. getAttachments: function WorkerTransport_getAttachments() {
  50993. return this.messageHandler.sendWithPromise('GetAttachments', null);
  50994. },
  50995. getJavaScript: function WorkerTransport_getJavaScript() {
  50996. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  50997. },
  50998. getOutline: function WorkerTransport_getOutline() {
  50999. return this.messageHandler.sendWithPromise('GetOutline', null);
  51000. },
  51001. getMetadata: function WorkerTransport_getMetadata() {
  51002. return this.messageHandler.sendWithPromise('GetMetadata', null).then(function transportMetadata(results) {
  51003. return {
  51004. info: results[0],
  51005. metadata: results[1] ? new Metadata(results[1]) : null
  51006. };
  51007. });
  51008. },
  51009. getStats: function WorkerTransport_getStats() {
  51010. return this.messageHandler.sendWithPromise('GetStats', null);
  51011. },
  51012. startCleanup: function WorkerTransport_startCleanup() {
  51013. this.messageHandler.sendWithPromise('Cleanup', null).then(function endCleanup() {
  51014. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  51015. var page = this.pageCache[i];
  51016. if (page) {
  51017. page.cleanup();
  51018. }
  51019. }
  51020. this.commonObjs.clear();
  51021. this.fontLoader.clear();
  51022. }.bind(this));
  51023. }
  51024. };
  51025. return WorkerTransport;
  51026. }();
  51027. /**
  51028. * A PDF document and page is built of many objects. E.g. there are objects
  51029. * for fonts, images, rendering code and such. These objects might get processed
  51030. * inside of a worker. The `PDFObjects` implements some basic functions to
  51031. * manage these objects.
  51032. * @ignore
  51033. */
  51034. var PDFObjects = function PDFObjectsClosure() {
  51035. function PDFObjects() {
  51036. this.objs = Object.create(null);
  51037. }
  51038. PDFObjects.prototype = {
  51039. /**
  51040. * Internal function.
  51041. * Ensures there is an object defined for `objId`.
  51042. */
  51043. ensureObj: function PDFObjects_ensureObj(objId) {
  51044. if (this.objs[objId]) {
  51045. return this.objs[objId];
  51046. }
  51047. var obj = {
  51048. capability: createPromiseCapability(),
  51049. data: null,
  51050. resolved: false
  51051. };
  51052. this.objs[objId] = obj;
  51053. return obj;
  51054. },
  51055. /**
  51056. * If called *without* callback, this returns the data of `objId` but the
  51057. * object needs to be resolved. If it isn't, this function throws.
  51058. *
  51059. * If called *with* a callback, the callback is called with the data of the
  51060. * object once the object is resolved. That means, if you call this
  51061. * function and the object is already resolved, the callback gets called
  51062. * right away.
  51063. */
  51064. get: function PDFObjects_get(objId, callback) {
  51065. // If there is a callback, then the get can be async and the object is
  51066. // not required to be resolved right now
  51067. if (callback) {
  51068. this.ensureObj(objId).capability.promise.then(callback);
  51069. return null;
  51070. }
  51071. // If there isn't a callback, the user expects to get the resolved data
  51072. // directly.
  51073. var obj = this.objs[objId];
  51074. // If there isn't an object yet or the object isn't resolved, then the
  51075. // data isn't ready yet!
  51076. if (!obj || !obj.resolved) {
  51077. error('Requesting object that isn\'t resolved yet ' + objId);
  51078. }
  51079. return obj.data;
  51080. },
  51081. /**
  51082. * Resolves the object `objId` with optional `data`.
  51083. */
  51084. resolve: function PDFObjects_resolve(objId, data) {
  51085. var obj = this.ensureObj(objId);
  51086. obj.resolved = true;
  51087. obj.data = data;
  51088. obj.capability.resolve(data);
  51089. },
  51090. isResolved: function PDFObjects_isResolved(objId) {
  51091. var objs = this.objs;
  51092. if (!objs[objId]) {
  51093. return false;
  51094. } else {
  51095. return objs[objId].resolved;
  51096. }
  51097. },
  51098. hasData: function PDFObjects_hasData(objId) {
  51099. return this.isResolved(objId);
  51100. },
  51101. /**
  51102. * Returns the data of `objId` if object exists, null otherwise.
  51103. */
  51104. getData: function PDFObjects_getData(objId) {
  51105. var objs = this.objs;
  51106. if (!objs[objId] || !objs[objId].resolved) {
  51107. return null;
  51108. } else {
  51109. return objs[objId].data;
  51110. }
  51111. },
  51112. clear: function PDFObjects_clear() {
  51113. this.objs = Object.create(null);
  51114. }
  51115. };
  51116. return PDFObjects;
  51117. }();
  51118. /**
  51119. * Allows controlling of the rendering tasks.
  51120. * @class
  51121. * @alias RenderTask
  51122. */
  51123. var RenderTask = function RenderTaskClosure() {
  51124. function RenderTask(internalRenderTask) {
  51125. this._internalRenderTask = internalRenderTask;
  51126. /**
  51127. * Callback for incremental rendering -- a function that will be called
  51128. * each time the rendering is paused. To continue rendering call the
  51129. * function that is the first argument to the callback.
  51130. * @type {function}
  51131. */
  51132. this.onContinue = null;
  51133. }
  51134. RenderTask.prototype = /** @lends RenderTask.prototype */
  51135. {
  51136. /**
  51137. * Promise for rendering task completion.
  51138. * @return {Promise}
  51139. */
  51140. get promise() {
  51141. return this._internalRenderTask.capability.promise;
  51142. },
  51143. /**
  51144. * Cancels the rendering task. If the task is currently rendering it will
  51145. * not be cancelled until graphics pauses with a timeout. The promise that
  51146. * this object extends will resolved when cancelled.
  51147. */
  51148. cancel: function RenderTask_cancel() {
  51149. this._internalRenderTask.cancel();
  51150. },
  51151. /**
  51152. * Registers callbacks to indicate the rendering task completion.
  51153. *
  51154. * @param {function} onFulfilled The callback for the rendering completion.
  51155. * @param {function} onRejected The callback for the rendering failure.
  51156. * @return {Promise} A promise that is resolved after the onFulfilled or
  51157. * onRejected callback.
  51158. */
  51159. then: function RenderTask_then(onFulfilled, onRejected) {
  51160. return this.promise.then.apply(this.promise, arguments);
  51161. }
  51162. };
  51163. return RenderTask;
  51164. }();
  51165. /**
  51166. * For internal use only.
  51167. * @ignore
  51168. */
  51169. var InternalRenderTask = function InternalRenderTaskClosure() {
  51170. function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber) {
  51171. this.callback = callback;
  51172. this.params = params;
  51173. this.objs = objs;
  51174. this.commonObjs = commonObjs;
  51175. this.operatorListIdx = null;
  51176. this.operatorList = operatorList;
  51177. this.pageNumber = pageNumber;
  51178. this.running = false;
  51179. this.graphicsReadyCallback = null;
  51180. this.graphicsReady = false;
  51181. this.useRequestAnimationFrame = false;
  51182. this.cancelled = false;
  51183. this.capability = createPromiseCapability();
  51184. this.task = new RenderTask(this);
  51185. // caching this-bound methods
  51186. this._continueBound = this._continue.bind(this);
  51187. this._scheduleNextBound = this._scheduleNext.bind(this);
  51188. this._nextBound = this._next.bind(this);
  51189. }
  51190. InternalRenderTask.prototype = {
  51191. initializeGraphics: function InternalRenderTask_initializeGraphics(transparency) {
  51192. if (this.cancelled) {
  51193. return;
  51194. }
  51195. if (getDefaultSetting('pdfBug') && globalScope.StepperManager && globalScope.StepperManager.enabled) {
  51196. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  51197. this.stepper.init(this.operatorList);
  51198. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  51199. }
  51200. var params = this.params;
  51201. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, params.imageLayer);
  51202. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  51203. this.operatorListIdx = 0;
  51204. this.graphicsReady = true;
  51205. if (this.graphicsReadyCallback) {
  51206. this.graphicsReadyCallback();
  51207. }
  51208. },
  51209. cancel: function InternalRenderTask_cancel() {
  51210. this.running = false;
  51211. this.cancelled = true;
  51212. this.callback('cancelled');
  51213. },
  51214. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  51215. if (!this.graphicsReady) {
  51216. if (!this.graphicsReadyCallback) {
  51217. this.graphicsReadyCallback = this._continueBound;
  51218. }
  51219. return;
  51220. }
  51221. if (this.stepper) {
  51222. this.stepper.updateOperatorList(this.operatorList);
  51223. }
  51224. if (this.running) {
  51225. return;
  51226. }
  51227. this._continue();
  51228. },
  51229. _continue: function InternalRenderTask__continue() {
  51230. this.running = true;
  51231. if (this.cancelled) {
  51232. return;
  51233. }
  51234. if (this.task.onContinue) {
  51235. this.task.onContinue.call(this.task, this._scheduleNextBound);
  51236. } else {
  51237. this._scheduleNext();
  51238. }
  51239. },
  51240. _scheduleNext: function InternalRenderTask__scheduleNext() {
  51241. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  51242. window.requestAnimationFrame(this._nextBound);
  51243. } else {
  51244. Promise.resolve(undefined).then(this._nextBound);
  51245. }
  51246. },
  51247. _next: function InternalRenderTask__next() {
  51248. if (this.cancelled) {
  51249. return;
  51250. }
  51251. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  51252. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  51253. this.running = false;
  51254. if (this.operatorList.lastChunk) {
  51255. this.gfx.endDrawing();
  51256. this.callback();
  51257. }
  51258. }
  51259. }
  51260. };
  51261. return InternalRenderTask;
  51262. }();
  51263. /**
  51264. * (Deprecated) Global observer of unsupported feature usages. Use
  51265. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  51266. */
  51267. var _UnsupportedManager = function UnsupportedManagerClosure() {
  51268. var listeners = [];
  51269. return {
  51270. listen: function (cb) {
  51271. deprecated('Global UnsupportedManager.listen is used: ' + ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  51272. listeners.push(cb);
  51273. },
  51274. notify: function (featureId) {
  51275. for (var i = 0, ii = listeners.length; i < ii; i++) {
  51276. listeners[i](featureId);
  51277. }
  51278. }
  51279. };
  51280. }();
  51281. if (typeof pdfjsVersion !== 'undefined') {
  51282. exports.version = pdfjsVersion;
  51283. }
  51284. if (typeof pdfjsBuild !== 'undefined') {
  51285. exports.build = pdfjsBuild;
  51286. }
  51287. exports.getDocument = getDocument;
  51288. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  51289. exports.PDFWorker = PDFWorker;
  51290. exports.PDFDocumentProxy = PDFDocumentProxy;
  51291. exports.PDFPageProxy = PDFPageProxy;
  51292. exports._UnsupportedManager = _UnsupportedManager;
  51293. }));
  51294. (function (root, factory) {
  51295. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  51296. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  51297. var error = sharedUtil.error;
  51298. var info = sharedUtil.info;
  51299. var isArray = sharedUtil.isArray;
  51300. var isString = sharedUtil.isString;
  51301. var shadow = sharedUtil.shadow;
  51302. var warn = sharedUtil.warn;
  51303. var isDict = corePrimitives.isDict;
  51304. var isName = corePrimitives.isName;
  51305. var isStream = corePrimitives.isStream;
  51306. var PDFFunction = coreFunction.PDFFunction;
  51307. var ColorSpace = function ColorSpaceClosure() {
  51308. /**
  51309. * Resizes an RGB image with 3 components.
  51310. * @param {TypedArray} src - The source buffer.
  51311. * @param {Number} bpc - Number of bits per component.
  51312. * @param {Number} w1 - Original width.
  51313. * @param {Number} h1 - Original height.
  51314. * @param {Number} w2 - New width.
  51315. * @param {Number} h2 - New height.
  51316. * @param {Number} alpha01 - Size reserved for the alpha channel.
  51317. * @param {TypedArray} dest - The destination buffer.
  51318. */
  51319. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  51320. var COMPONENTS = 3;
  51321. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  51322. var xRatio = w1 / w2;
  51323. var yRatio = h1 / h2;
  51324. var i, j, py, newIndex = 0, oldIndex;
  51325. var xScaled = new Uint16Array(w2);
  51326. var w1Scanline = w1 * COMPONENTS;
  51327. for (i = 0; i < w2; i++) {
  51328. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  51329. }
  51330. for (i = 0; i < h2; i++) {
  51331. py = Math.floor(i * yRatio) * w1Scanline;
  51332. for (j = 0; j < w2; j++) {
  51333. oldIndex = py + xScaled[j];
  51334. dest[newIndex++] = src[oldIndex++];
  51335. dest[newIndex++] = src[oldIndex++];
  51336. dest[newIndex++] = src[oldIndex++];
  51337. newIndex += alpha01;
  51338. }
  51339. }
  51340. }
  51341. // Constructor should define this.numComps, this.defaultColor, this.name
  51342. function ColorSpace() {
  51343. error('should not call ColorSpace constructor');
  51344. }
  51345. ColorSpace.prototype = {
  51346. /**
  51347. * Converts the color value to the RGB color. The color components are
  51348. * located in the src array starting from the srcOffset. Returns the array
  51349. * of the rgb components, each value ranging from [0,255].
  51350. */
  51351. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  51352. var rgb = new Uint8Array(3);
  51353. this.getRgbItem(src, srcOffset, rgb, 0);
  51354. return rgb;
  51355. },
  51356. /**
  51357. * Converts the color value to the RGB color, similar to the getRgb method.
  51358. * The result placed into the dest array starting from the destOffset.
  51359. */
  51360. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  51361. error('Should not call ColorSpace.getRgbItem');
  51362. },
  51363. /**
  51364. * Converts the specified number of the color values to the RGB colors.
  51365. * The colors are located in the src array starting from the srcOffset.
  51366. * The result is placed into the dest array starting from the destOffset.
  51367. * The src array items shall be in [0,2^bits) range, the dest array items
  51368. * will be in [0,255] range. alpha01 indicates how many alpha components
  51369. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  51370. * array).
  51371. */
  51372. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51373. error('Should not call ColorSpace.getRgbBuffer');
  51374. },
  51375. /**
  51376. * Determines the number of bytes required to store the result of the
  51377. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  51378. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  51379. */
  51380. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  51381. error('Should not call ColorSpace.getOutputLength');
  51382. },
  51383. /**
  51384. * Returns true if source data will be equal the result/output data.
  51385. */
  51386. isPassthrough: function ColorSpace_isPassthrough(bits) {
  51387. return false;
  51388. },
  51389. /**
  51390. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  51391. * how many alpha components there are in the dest array; it will be either
  51392. * 0 (RGB array) or 1 (RGBA array).
  51393. */
  51394. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  51395. var count = originalWidth * originalHeight;
  51396. var rgbBuf = null;
  51397. var numComponentColors = 1 << bpc;
  51398. var needsResizing = originalHeight !== height || originalWidth !== width;
  51399. var i, ii;
  51400. if (this.isPassthrough(bpc)) {
  51401. rgbBuf = comps;
  51402. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  51403. // Optimization: create a color map when there is just one component and
  51404. // we are converting more colors than the size of the color map. We
  51405. // don't build the map if the colorspace is gray or rgb since those
  51406. // methods are faster than building a map. This mainly offers big speed
  51407. // ups for indexed and alternate colorspaces.
  51408. //
  51409. // TODO it may be worth while to cache the color map. While running
  51410. // testing I never hit a cache so I will leave that out for now (perhaps
  51411. // we are reparsing colorspaces too much?).
  51412. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  51413. var key;
  51414. for (i = 0; i < numComponentColors; i++) {
  51415. allColors[i] = i;
  51416. }
  51417. var colorMap = new Uint8Array(numComponentColors * 3);
  51418. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  51419. 0);
  51420. var destPos, rgbPos;
  51421. if (!needsResizing) {
  51422. // Fill in the RGB values directly into |dest|.
  51423. destPos = 0;
  51424. for (i = 0; i < count; ++i) {
  51425. key = comps[i] * 3;
  51426. dest[destPos++] = colorMap[key];
  51427. dest[destPos++] = colorMap[key + 1];
  51428. dest[destPos++] = colorMap[key + 2];
  51429. destPos += alpha01;
  51430. }
  51431. } else {
  51432. rgbBuf = new Uint8Array(count * 3);
  51433. rgbPos = 0;
  51434. for (i = 0; i < count; ++i) {
  51435. key = comps[i] * 3;
  51436. rgbBuf[rgbPos++] = colorMap[key];
  51437. rgbBuf[rgbPos++] = colorMap[key + 1];
  51438. rgbBuf[rgbPos++] = colorMap[key + 2];
  51439. }
  51440. }
  51441. } else {
  51442. if (!needsResizing) {
  51443. // Fill in the RGB values directly into |dest|.
  51444. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  51445. } else {
  51446. rgbBuf = new Uint8Array(count * 3);
  51447. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  51448. 0);
  51449. }
  51450. }
  51451. if (rgbBuf) {
  51452. if (needsResizing) {
  51453. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  51454. } else {
  51455. rgbPos = 0;
  51456. destPos = 0;
  51457. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  51458. dest[destPos++] = rgbBuf[rgbPos++];
  51459. dest[destPos++] = rgbBuf[rgbPos++];
  51460. dest[destPos++] = rgbBuf[rgbPos++];
  51461. destPos += alpha01;
  51462. }
  51463. }
  51464. }
  51465. },
  51466. /**
  51467. * True if the colorspace has components in the default range of [0, 1].
  51468. * This should be true for all colorspaces except for lab color spaces
  51469. * which are [0,100], [-128, 127], [-128, 127].
  51470. */
  51471. usesZeroToOneRange: true
  51472. };
  51473. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  51474. var IR = ColorSpace.parseToIR(cs, xref, res);
  51475. if (IR instanceof AlternateCS) {
  51476. return IR;
  51477. }
  51478. return ColorSpace.fromIR(IR);
  51479. };
  51480. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  51481. var name = isArray(IR) ? IR[0] : IR;
  51482. var whitePoint, blackPoint, gamma;
  51483. switch (name) {
  51484. case 'DeviceGrayCS':
  51485. return this.singletons.gray;
  51486. case 'DeviceRgbCS':
  51487. return this.singletons.rgb;
  51488. case 'DeviceCmykCS':
  51489. return this.singletons.cmyk;
  51490. case 'CalGrayCS':
  51491. whitePoint = IR[1];
  51492. blackPoint = IR[2];
  51493. gamma = IR[3];
  51494. return new CalGrayCS(whitePoint, blackPoint, gamma);
  51495. case 'CalRGBCS':
  51496. whitePoint = IR[1];
  51497. blackPoint = IR[2];
  51498. gamma = IR[3];
  51499. var matrix = IR[4];
  51500. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  51501. case 'PatternCS':
  51502. var basePatternCS = IR[1];
  51503. if (basePatternCS) {
  51504. basePatternCS = ColorSpace.fromIR(basePatternCS);
  51505. }
  51506. return new PatternCS(basePatternCS);
  51507. case 'IndexedCS':
  51508. var baseIndexedCS = IR[1];
  51509. var hiVal = IR[2];
  51510. var lookup = IR[3];
  51511. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  51512. case 'AlternateCS':
  51513. var numComps = IR[1];
  51514. var alt = IR[2];
  51515. var tintFnIR = IR[3];
  51516. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  51517. case 'LabCS':
  51518. whitePoint = IR[1];
  51519. blackPoint = IR[2];
  51520. var range = IR[3];
  51521. return new LabCS(whitePoint, blackPoint, range);
  51522. default:
  51523. error('Unknown name ' + name);
  51524. }
  51525. return null;
  51526. };
  51527. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  51528. if (isName(cs)) {
  51529. var colorSpaces = res.get('ColorSpace');
  51530. if (isDict(colorSpaces)) {
  51531. var refcs = colorSpaces.get(cs.name);
  51532. if (refcs) {
  51533. cs = refcs;
  51534. }
  51535. }
  51536. }
  51537. cs = xref.fetchIfRef(cs);
  51538. var mode;
  51539. if (isName(cs)) {
  51540. mode = cs.name;
  51541. this.mode = mode;
  51542. switch (mode) {
  51543. case 'DeviceGray':
  51544. case 'G':
  51545. return 'DeviceGrayCS';
  51546. case 'DeviceRGB':
  51547. case 'RGB':
  51548. return 'DeviceRgbCS';
  51549. case 'DeviceCMYK':
  51550. case 'CMYK':
  51551. return 'DeviceCmykCS';
  51552. case 'Pattern':
  51553. return [
  51554. 'PatternCS',
  51555. null
  51556. ];
  51557. default:
  51558. error('unrecognized colorspace ' + mode);
  51559. }
  51560. } else if (isArray(cs)) {
  51561. mode = xref.fetchIfRef(cs[0]).name;
  51562. this.mode = mode;
  51563. var numComps, params, alt, whitePoint, blackPoint, gamma;
  51564. switch (mode) {
  51565. case 'DeviceGray':
  51566. case 'G':
  51567. return 'DeviceGrayCS';
  51568. case 'DeviceRGB':
  51569. case 'RGB':
  51570. return 'DeviceRgbCS';
  51571. case 'DeviceCMYK':
  51572. case 'CMYK':
  51573. return 'DeviceCmykCS';
  51574. case 'CalGray':
  51575. params = xref.fetchIfRef(cs[1]);
  51576. whitePoint = params.getArray('WhitePoint');
  51577. blackPoint = params.getArray('BlackPoint');
  51578. gamma = params.get('Gamma');
  51579. return [
  51580. 'CalGrayCS',
  51581. whitePoint,
  51582. blackPoint,
  51583. gamma
  51584. ];
  51585. case 'CalRGB':
  51586. params = xref.fetchIfRef(cs[1]);
  51587. whitePoint = params.getArray('WhitePoint');
  51588. blackPoint = params.getArray('BlackPoint');
  51589. gamma = params.getArray('Gamma');
  51590. var matrix = params.getArray('Matrix');
  51591. return [
  51592. 'CalRGBCS',
  51593. whitePoint,
  51594. blackPoint,
  51595. gamma,
  51596. matrix
  51597. ];
  51598. case 'ICCBased':
  51599. var stream = xref.fetchIfRef(cs[1]);
  51600. var dict = stream.dict;
  51601. numComps = dict.get('N');
  51602. alt = dict.get('Alternate');
  51603. if (alt) {
  51604. var altIR = ColorSpace.parseToIR(alt, xref, res);
  51605. // Parse the /Alternate CS to ensure that the number of components
  51606. // are correct, and also (indirectly) that it is not a PatternCS.
  51607. var altCS = ColorSpace.fromIR(altIR);
  51608. if (altCS.numComps === numComps) {
  51609. return altIR;
  51610. }
  51611. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  51612. }
  51613. if (numComps === 1) {
  51614. return 'DeviceGrayCS';
  51615. } else if (numComps === 3) {
  51616. return 'DeviceRgbCS';
  51617. } else if (numComps === 4) {
  51618. return 'DeviceCmykCS';
  51619. }
  51620. break;
  51621. case 'Pattern':
  51622. var basePatternCS = cs[1] || null;
  51623. if (basePatternCS) {
  51624. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  51625. }
  51626. return [
  51627. 'PatternCS',
  51628. basePatternCS
  51629. ];
  51630. case 'Indexed':
  51631. case 'I':
  51632. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  51633. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  51634. var lookup = xref.fetchIfRef(cs[3]);
  51635. if (isStream(lookup)) {
  51636. lookup = lookup.getBytes();
  51637. }
  51638. return [
  51639. 'IndexedCS',
  51640. baseIndexedCS,
  51641. hiVal,
  51642. lookup
  51643. ];
  51644. case 'Separation':
  51645. case 'DeviceN':
  51646. var name = xref.fetchIfRef(cs[1]);
  51647. numComps = 1;
  51648. if (isName(name)) {
  51649. numComps = 1;
  51650. } else if (isArray(name)) {
  51651. numComps = name.length;
  51652. }
  51653. alt = ColorSpace.parseToIR(cs[2], xref, res);
  51654. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  51655. return [
  51656. 'AlternateCS',
  51657. numComps,
  51658. alt,
  51659. tintFnIR
  51660. ];
  51661. case 'Lab':
  51662. params = xref.fetchIfRef(cs[1]);
  51663. whitePoint = params.getArray('WhitePoint');
  51664. blackPoint = params.getArray('BlackPoint');
  51665. var range = params.getArray('Range');
  51666. return [
  51667. 'LabCS',
  51668. whitePoint,
  51669. blackPoint,
  51670. range
  51671. ];
  51672. default:
  51673. error('unimplemented color space object "' + mode + '"');
  51674. }
  51675. } else {
  51676. error('unrecognized color space object: "' + cs + '"');
  51677. }
  51678. return null;
  51679. };
  51680. /**
  51681. * Checks if a decode map matches the default decode map for a color space.
  51682. * This handles the general decode maps where there are two values per
  51683. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  51684. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  51685. * slightly different.
  51686. * @param {Array} decode Decode map (usually from an image).
  51687. * @param {Number} n Number of components the color space has.
  51688. */
  51689. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  51690. if (!isArray(decode)) {
  51691. return true;
  51692. }
  51693. if (n * 2 !== decode.length) {
  51694. warn('The decode map is not the correct length');
  51695. return true;
  51696. }
  51697. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  51698. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  51699. return false;
  51700. }
  51701. }
  51702. return true;
  51703. };
  51704. ColorSpace.singletons = {
  51705. get gray() {
  51706. return shadow(this, 'gray', new DeviceGrayCS());
  51707. },
  51708. get rgb() {
  51709. return shadow(this, 'rgb', new DeviceRgbCS());
  51710. },
  51711. get cmyk() {
  51712. return shadow(this, 'cmyk', new DeviceCmykCS());
  51713. }
  51714. };
  51715. return ColorSpace;
  51716. }();
  51717. /**
  51718. * Alternate color space handles both Separation and DeviceN color spaces. A
  51719. * Separation color space is actually just a DeviceN with one color component.
  51720. * Both color spaces use a tinting function to convert colors to a base color
  51721. * space.
  51722. */
  51723. var AlternateCS = function AlternateCSClosure() {
  51724. function AlternateCS(numComps, base, tintFn) {
  51725. this.name = 'Alternate';
  51726. this.numComps = numComps;
  51727. this.defaultColor = new Float32Array(numComps);
  51728. for (var i = 0; i < numComps; ++i) {
  51729. this.defaultColor[i] = 1;
  51730. }
  51731. this.base = base;
  51732. this.tintFn = tintFn;
  51733. this.tmpBuf = new Float32Array(base.numComps);
  51734. }
  51735. AlternateCS.prototype = {
  51736. getRgb: ColorSpace.prototype.getRgb,
  51737. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51738. var tmpBuf = this.tmpBuf;
  51739. this.tintFn(src, srcOffset, tmpBuf, 0);
  51740. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  51741. },
  51742. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51743. var tintFn = this.tintFn;
  51744. var base = this.base;
  51745. var scale = 1 / ((1 << bits) - 1);
  51746. var baseNumComps = base.numComps;
  51747. var usesZeroToOneRange = base.usesZeroToOneRange;
  51748. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  51749. var pos = isPassthrough ? destOffset : 0;
  51750. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  51751. var numComps = this.numComps;
  51752. var scaled = new Float32Array(numComps);
  51753. var tinted = new Float32Array(baseNumComps);
  51754. var i, j;
  51755. if (usesZeroToOneRange) {
  51756. for (i = 0; i < count; i++) {
  51757. for (j = 0; j < numComps; j++) {
  51758. scaled[j] = src[srcOffset++] * scale;
  51759. }
  51760. tintFn(scaled, 0, tinted, 0);
  51761. for (j = 0; j < baseNumComps; j++) {
  51762. baseBuf[pos++] = tinted[j] * 255;
  51763. }
  51764. }
  51765. } else {
  51766. for (i = 0; i < count; i++) {
  51767. for (j = 0; j < numComps; j++) {
  51768. scaled[j] = src[srcOffset++] * scale;
  51769. }
  51770. tintFn(scaled, 0, tinted, 0);
  51771. base.getRgbItem(tinted, 0, baseBuf, pos);
  51772. pos += baseNumComps;
  51773. }
  51774. }
  51775. if (!isPassthrough) {
  51776. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  51777. }
  51778. },
  51779. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  51780. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  51781. },
  51782. isPassthrough: ColorSpace.prototype.isPassthrough,
  51783. fillRgb: ColorSpace.prototype.fillRgb,
  51784. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  51785. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51786. },
  51787. usesZeroToOneRange: true
  51788. };
  51789. return AlternateCS;
  51790. }();
  51791. var PatternCS = function PatternCSClosure() {
  51792. function PatternCS(baseCS) {
  51793. this.name = 'Pattern';
  51794. this.base = baseCS;
  51795. }
  51796. PatternCS.prototype = {};
  51797. return PatternCS;
  51798. }();
  51799. var IndexedCS = function IndexedCSClosure() {
  51800. function IndexedCS(base, highVal, lookup) {
  51801. this.name = 'Indexed';
  51802. this.numComps = 1;
  51803. this.defaultColor = new Uint8Array([0]);
  51804. this.base = base;
  51805. this.highVal = highVal;
  51806. var baseNumComps = base.numComps;
  51807. var length = baseNumComps * highVal;
  51808. var lookupArray;
  51809. if (isStream(lookup)) {
  51810. lookupArray = new Uint8Array(length);
  51811. var bytes = lookup.getBytes(length);
  51812. lookupArray.set(bytes);
  51813. } else if (isString(lookup)) {
  51814. lookupArray = new Uint8Array(length);
  51815. for (var i = 0; i < length; ++i) {
  51816. lookupArray[i] = lookup.charCodeAt(i);
  51817. }
  51818. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  51819. lookupArray = lookup;
  51820. } else {
  51821. error('Unrecognized lookup table: ' + lookup);
  51822. }
  51823. this.lookup = lookupArray;
  51824. }
  51825. IndexedCS.prototype = {
  51826. getRgb: ColorSpace.prototype.getRgb,
  51827. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51828. var numComps = this.base.numComps;
  51829. var start = src[srcOffset] * numComps;
  51830. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  51831. },
  51832. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51833. var base = this.base;
  51834. var numComps = base.numComps;
  51835. var outputDelta = base.getOutputLength(numComps, alpha01);
  51836. var lookup = this.lookup;
  51837. for (var i = 0; i < count; ++i) {
  51838. var lookupPos = src[srcOffset++] * numComps;
  51839. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  51840. destOffset += outputDelta;
  51841. }
  51842. },
  51843. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  51844. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  51845. },
  51846. isPassthrough: ColorSpace.prototype.isPassthrough,
  51847. fillRgb: ColorSpace.prototype.fillRgb,
  51848. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  51849. // indexed color maps shouldn't be changed
  51850. return true;
  51851. },
  51852. usesZeroToOneRange: true
  51853. };
  51854. return IndexedCS;
  51855. }();
  51856. var DeviceGrayCS = function DeviceGrayCSClosure() {
  51857. function DeviceGrayCS() {
  51858. this.name = 'DeviceGray';
  51859. this.numComps = 1;
  51860. this.defaultColor = new Float32Array([0]);
  51861. }
  51862. DeviceGrayCS.prototype = {
  51863. getRgb: ColorSpace.prototype.getRgb,
  51864. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51865. var c = src[srcOffset] * 255 | 0;
  51866. c = c < 0 ? 0 : c > 255 ? 255 : c;
  51867. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  51868. },
  51869. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51870. var scale = 255 / ((1 << bits) - 1);
  51871. var j = srcOffset, q = destOffset;
  51872. for (var i = 0; i < count; ++i) {
  51873. var c = scale * src[j++] | 0;
  51874. dest[q++] = c;
  51875. dest[q++] = c;
  51876. dest[q++] = c;
  51877. q += alpha01;
  51878. }
  51879. },
  51880. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  51881. return inputLength * (3 + alpha01);
  51882. },
  51883. isPassthrough: ColorSpace.prototype.isPassthrough,
  51884. fillRgb: ColorSpace.prototype.fillRgb,
  51885. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  51886. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51887. },
  51888. usesZeroToOneRange: true
  51889. };
  51890. return DeviceGrayCS;
  51891. }();
  51892. var DeviceRgbCS = function DeviceRgbCSClosure() {
  51893. function DeviceRgbCS() {
  51894. this.name = 'DeviceRGB';
  51895. this.numComps = 3;
  51896. this.defaultColor = new Float32Array([
  51897. 0,
  51898. 0,
  51899. 0
  51900. ]);
  51901. }
  51902. DeviceRgbCS.prototype = {
  51903. getRgb: ColorSpace.prototype.getRgb,
  51904. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51905. var r = src[srcOffset] * 255 | 0;
  51906. var g = src[srcOffset + 1] * 255 | 0;
  51907. var b = src[srcOffset + 2] * 255 | 0;
  51908. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  51909. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  51910. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  51911. },
  51912. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51913. if (bits === 8 && alpha01 === 0) {
  51914. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  51915. return;
  51916. }
  51917. var scale = 255 / ((1 << bits) - 1);
  51918. var j = srcOffset, q = destOffset;
  51919. for (var i = 0; i < count; ++i) {
  51920. dest[q++] = scale * src[j++] | 0;
  51921. dest[q++] = scale * src[j++] | 0;
  51922. dest[q++] = scale * src[j++] | 0;
  51923. q += alpha01;
  51924. }
  51925. },
  51926. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  51927. return inputLength * (3 + alpha01) / 3 | 0;
  51928. },
  51929. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  51930. return bits === 8;
  51931. },
  51932. fillRgb: ColorSpace.prototype.fillRgb,
  51933. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  51934. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51935. },
  51936. usesZeroToOneRange: true
  51937. };
  51938. return DeviceRgbCS;
  51939. }();
  51940. var DeviceCmykCS = function DeviceCmykCSClosure() {
  51941. // The coefficients below was found using numerical analysis: the method of
  51942. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  51943. // where color_value is the tabular value from the table of sampled RGB colors
  51944. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  51945. // CMYK color conversion using the estimation below:
  51946. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  51947. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  51948. var c = src[srcOffset + 0] * srcScale;
  51949. var m = src[srcOffset + 1] * srcScale;
  51950. var y = src[srcOffset + 2] * srcScale;
  51951. var k = src[srcOffset + 3] * srcScale;
  51952. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747) + 255 | 0;
  51953. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578) + 255 | 0;
  51954. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367) + 255 | 0;
  51955. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  51956. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  51957. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  51958. }
  51959. function DeviceCmykCS() {
  51960. this.name = 'DeviceCMYK';
  51961. this.numComps = 4;
  51962. this.defaultColor = new Float32Array([
  51963. 0,
  51964. 0,
  51965. 0,
  51966. 1
  51967. ]);
  51968. }
  51969. DeviceCmykCS.prototype = {
  51970. getRgb: ColorSpace.prototype.getRgb,
  51971. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51972. convertToRgb(src, srcOffset, 1, dest, destOffset);
  51973. },
  51974. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51975. var scale = 1 / ((1 << bits) - 1);
  51976. for (var i = 0; i < count; i++) {
  51977. convertToRgb(src, srcOffset, scale, dest, destOffset);
  51978. srcOffset += 4;
  51979. destOffset += 3 + alpha01;
  51980. }
  51981. },
  51982. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  51983. return inputLength / 4 * (3 + alpha01) | 0;
  51984. },
  51985. isPassthrough: ColorSpace.prototype.isPassthrough,
  51986. fillRgb: ColorSpace.prototype.fillRgb,
  51987. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  51988. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51989. },
  51990. usesZeroToOneRange: true
  51991. };
  51992. return DeviceCmykCS;
  51993. }();
  51994. //
  51995. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  51996. //
  51997. var CalGrayCS = function CalGrayCSClosure() {
  51998. function CalGrayCS(whitePoint, blackPoint, gamma) {
  51999. this.name = 'CalGray';
  52000. this.numComps = 1;
  52001. this.defaultColor = new Float32Array([0]);
  52002. if (!whitePoint) {
  52003. error('WhitePoint missing - required for color space CalGray');
  52004. }
  52005. blackPoint = blackPoint || [
  52006. 0,
  52007. 0,
  52008. 0
  52009. ];
  52010. gamma = gamma || 1;
  52011. // Translate arguments to spec variables.
  52012. this.XW = whitePoint[0];
  52013. this.YW = whitePoint[1];
  52014. this.ZW = whitePoint[2];
  52015. this.XB = blackPoint[0];
  52016. this.YB = blackPoint[1];
  52017. this.ZB = blackPoint[2];
  52018. this.G = gamma;
  52019. // Validate variables as per spec.
  52020. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  52021. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  52022. }
  52023. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  52024. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  52025. this.XB = this.YB = this.ZB = 0;
  52026. }
  52027. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  52028. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  52029. }
  52030. if (this.G < 1) {
  52031. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  52032. this.G = 1;
  52033. }
  52034. }
  52035. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  52036. // A represents a gray component of a calibrated gray space.
  52037. // A <---> AG in the spec
  52038. var A = src[srcOffset] * scale;
  52039. var AG = Math.pow(A, cs.G);
  52040. // Computes L as per spec. ( = cs.YW * AG )
  52041. // Except if other than default BlackPoint values are used.
  52042. var L = cs.YW * AG;
  52043. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  52044. // Convert values to rgb range [0, 255].
  52045. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  52046. dest[destOffset] = val;
  52047. dest[destOffset + 1] = val;
  52048. dest[destOffset + 2] = val;
  52049. }
  52050. CalGrayCS.prototype = {
  52051. getRgb: ColorSpace.prototype.getRgb,
  52052. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52053. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  52054. },
  52055. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52056. var scale = 1 / ((1 << bits) - 1);
  52057. for (var i = 0; i < count; ++i) {
  52058. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  52059. srcOffset += 1;
  52060. destOffset += 3 + alpha01;
  52061. }
  52062. },
  52063. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  52064. return inputLength * (3 + alpha01);
  52065. },
  52066. isPassthrough: ColorSpace.prototype.isPassthrough,
  52067. fillRgb: ColorSpace.prototype.fillRgb,
  52068. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  52069. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  52070. },
  52071. usesZeroToOneRange: true
  52072. };
  52073. return CalGrayCS;
  52074. }();
  52075. //
  52076. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  52077. //
  52078. var CalRGBCS = function CalRGBCSClosure() {
  52079. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  52080. // matrices.
  52081. var BRADFORD_SCALE_MATRIX = new Float32Array([
  52082. 0.8951,
  52083. 0.2664,
  52084. -0.1614,
  52085. -0.7502,
  52086. 1.7135,
  52087. 0.0367,
  52088. 0.0389,
  52089. -0.0685,
  52090. 1.0296
  52091. ]);
  52092. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  52093. 0.9869929,
  52094. -0.1470543,
  52095. 0.1599627,
  52096. 0.4323053,
  52097. 0.5183603,
  52098. 0.0492912,
  52099. -0.0085287,
  52100. 0.0400428,
  52101. 0.9684867
  52102. ]);
  52103. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  52104. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  52105. 3.2404542,
  52106. -1.5371385,
  52107. -0.4985314,
  52108. -0.9692660,
  52109. 1.8760108,
  52110. 0.0415560,
  52111. 0.0556434,
  52112. -0.2040259,
  52113. 1.0572252
  52114. ]);
  52115. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  52116. 1,
  52117. 1,
  52118. 1
  52119. ]);
  52120. var tempNormalizeMatrix = new Float32Array(3);
  52121. var tempConvertMatrix1 = new Float32Array(3);
  52122. var tempConvertMatrix2 = new Float32Array(3);
  52123. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  52124. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  52125. this.name = 'CalRGB';
  52126. this.numComps = 3;
  52127. this.defaultColor = new Float32Array(3);
  52128. if (!whitePoint) {
  52129. error('WhitePoint missing - required for color space CalRGB');
  52130. }
  52131. blackPoint = blackPoint || new Float32Array(3);
  52132. gamma = gamma || new Float32Array([
  52133. 1,
  52134. 1,
  52135. 1
  52136. ]);
  52137. matrix = matrix || new Float32Array([
  52138. 1,
  52139. 0,
  52140. 0,
  52141. 0,
  52142. 1,
  52143. 0,
  52144. 0,
  52145. 0,
  52146. 1
  52147. ]);
  52148. // Translate arguments to spec variables.
  52149. var XW = whitePoint[0];
  52150. var YW = whitePoint[1];
  52151. var ZW = whitePoint[2];
  52152. this.whitePoint = whitePoint;
  52153. var XB = blackPoint[0];
  52154. var YB = blackPoint[1];
  52155. var ZB = blackPoint[2];
  52156. this.blackPoint = blackPoint;
  52157. this.GR = gamma[0];
  52158. this.GG = gamma[1];
  52159. this.GB = gamma[2];
  52160. this.MXA = matrix[0];
  52161. this.MYA = matrix[1];
  52162. this.MZA = matrix[2];
  52163. this.MXB = matrix[3];
  52164. this.MYB = matrix[4];
  52165. this.MZB = matrix[5];
  52166. this.MXC = matrix[6];
  52167. this.MYC = matrix[7];
  52168. this.MZC = matrix[8];
  52169. // Validate variables as per spec.
  52170. if (XW < 0 || ZW < 0 || YW !== 1) {
  52171. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  52172. }
  52173. if (XB < 0 || YB < 0 || ZB < 0) {
  52174. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  52175. this.blackPoint = new Float32Array(3);
  52176. }
  52177. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  52178. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  52179. this.GR = this.GG = this.GB = 1;
  52180. }
  52181. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 || this.MXB < 0 || this.MYB < 0 || this.MZB < 0 || this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  52182. info('Invalid Matrix for ' + this.name + ' [' + this.MXA + ', ' + this.MYA + ', ' + this.MZA + this.MXB + ', ' + this.MYB + ', ' + this.MZB + this.MXC + ', ' + this.MYC + ', ' + this.MZC + '], falling back to default');
  52183. this.MXA = this.MYB = this.MZC = 1;
  52184. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  52185. }
  52186. }
  52187. function matrixProduct(a, b, result) {
  52188. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  52189. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  52190. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  52191. }
  52192. function convertToFlat(sourceWhitePoint, LMS, result) {
  52193. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  52194. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  52195. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  52196. }
  52197. function convertToD65(sourceWhitePoint, LMS, result) {
  52198. var D65X = 0.95047;
  52199. var D65Y = 1;
  52200. var D65Z = 1.08883;
  52201. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  52202. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  52203. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  52204. }
  52205. function sRGBTransferFunction(color) {
  52206. // See http://en.wikipedia.org/wiki/SRGB.
  52207. if (color <= 0.0031308) {
  52208. return adjustToRange(0, 1, 12.92 * color);
  52209. }
  52210. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  52211. }
  52212. function adjustToRange(min, max, value) {
  52213. return Math.max(min, Math.min(max, value));
  52214. }
  52215. function decodeL(L) {
  52216. if (L < 0) {
  52217. return -decodeL(-L);
  52218. }
  52219. if (L > 8.0) {
  52220. return Math.pow((L + 16) / 116, 3);
  52221. }
  52222. return L * DECODE_L_CONSTANT;
  52223. }
  52224. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  52225. // In case the blackPoint is already the default blackPoint then there is
  52226. // no need to do compensation.
  52227. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  52228. result[0] = XYZ_Flat[0];
  52229. result[1] = XYZ_Flat[1];
  52230. result[2] = XYZ_Flat[2];
  52231. return;
  52232. }
  52233. // For the blackPoint calculation details, please see
  52234. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  52235. // AdobeBPC.pdf.
  52236. // The destination blackPoint is the default blackPoint [0, 0, 0].
  52237. var zeroDecodeL = decodeL(0);
  52238. var X_DST = zeroDecodeL;
  52239. var X_SRC = decodeL(sourceBlackPoint[0]);
  52240. var Y_DST = zeroDecodeL;
  52241. var Y_SRC = decodeL(sourceBlackPoint[1]);
  52242. var Z_DST = zeroDecodeL;
  52243. var Z_SRC = decodeL(sourceBlackPoint[2]);
  52244. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  52245. var X_Offset = 1 - X_Scale;
  52246. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  52247. var Y_Offset = 1 - Y_Scale;
  52248. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  52249. var Z_Offset = 1 - Z_Scale;
  52250. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  52251. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  52252. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  52253. }
  52254. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  52255. // In case the whitePoint is already flat then there is no need to do
  52256. // normalization.
  52257. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  52258. result[0] = XYZ_In[0];
  52259. result[1] = XYZ_In[1];
  52260. result[2] = XYZ_In[2];
  52261. return;
  52262. }
  52263. var LMS = result;
  52264. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  52265. var LMS_Flat = tempNormalizeMatrix;
  52266. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  52267. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  52268. }
  52269. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  52270. var LMS = result;
  52271. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  52272. var LMS_D65 = tempNormalizeMatrix;
  52273. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  52274. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  52275. }
  52276. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  52277. // A, B and C represent a red, green and blue components of a calibrated
  52278. // rgb space.
  52279. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  52280. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  52281. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  52282. // A <---> AGR in the spec
  52283. // B <---> BGG in the spec
  52284. // C <---> CGB in the spec
  52285. var AGR = Math.pow(A, cs.GR);
  52286. var BGG = Math.pow(B, cs.GG);
  52287. var CGB = Math.pow(C, cs.GB);
  52288. // Computes intermediate variables L, M, N as per spec.
  52289. // To decode X, Y, Z values map L, M, N directly to them.
  52290. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  52291. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  52292. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  52293. // The following calculations are based on this document:
  52294. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  52295. // AdobeBPC.pdf.
  52296. var XYZ = tempConvertMatrix1;
  52297. XYZ[0] = X;
  52298. XYZ[1] = Y;
  52299. XYZ[2] = Z;
  52300. var XYZ_Flat = tempConvertMatrix2;
  52301. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  52302. var XYZ_Black = tempConvertMatrix1;
  52303. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  52304. var XYZ_D65 = tempConvertMatrix2;
  52305. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  52306. var SRGB = tempConvertMatrix1;
  52307. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  52308. var sR = sRGBTransferFunction(SRGB[0]);
  52309. var sG = sRGBTransferFunction(SRGB[1]);
  52310. var sB = sRGBTransferFunction(SRGB[2]);
  52311. // Convert the values to rgb range [0, 255].
  52312. dest[destOffset] = Math.round(sR * 255);
  52313. dest[destOffset + 1] = Math.round(sG * 255);
  52314. dest[destOffset + 2] = Math.round(sB * 255);
  52315. }
  52316. CalRGBCS.prototype = {
  52317. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  52318. var rgb = new Uint8Array(3);
  52319. this.getRgbItem(src, srcOffset, rgb, 0);
  52320. return rgb;
  52321. },
  52322. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52323. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  52324. },
  52325. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52326. var scale = 1 / ((1 << bits) - 1);
  52327. for (var i = 0; i < count; ++i) {
  52328. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  52329. srcOffset += 3;
  52330. destOffset += 3 + alpha01;
  52331. }
  52332. },
  52333. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  52334. return inputLength * (3 + alpha01) / 3 | 0;
  52335. },
  52336. isPassthrough: ColorSpace.prototype.isPassthrough,
  52337. fillRgb: ColorSpace.prototype.fillRgb,
  52338. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  52339. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  52340. },
  52341. usesZeroToOneRange: true
  52342. };
  52343. return CalRGBCS;
  52344. }();
  52345. //
  52346. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  52347. //
  52348. var LabCS = function LabCSClosure() {
  52349. function LabCS(whitePoint, blackPoint, range) {
  52350. this.name = 'Lab';
  52351. this.numComps = 3;
  52352. this.defaultColor = new Float32Array([
  52353. 0,
  52354. 0,
  52355. 0
  52356. ]);
  52357. if (!whitePoint) {
  52358. error('WhitePoint missing - required for color space Lab');
  52359. }
  52360. blackPoint = blackPoint || [
  52361. 0,
  52362. 0,
  52363. 0
  52364. ];
  52365. range = range || [
  52366. -100,
  52367. 100,
  52368. -100,
  52369. 100
  52370. ];
  52371. // Translate args to spec variables
  52372. this.XW = whitePoint[0];
  52373. this.YW = whitePoint[1];
  52374. this.ZW = whitePoint[2];
  52375. this.amin = range[0];
  52376. this.amax = range[1];
  52377. this.bmin = range[2];
  52378. this.bmax = range[3];
  52379. // These are here just for completeness - the spec doesn't offer any
  52380. // formulas that use BlackPoint in Lab
  52381. this.XB = blackPoint[0];
  52382. this.YB = blackPoint[1];
  52383. this.ZB = blackPoint[2];
  52384. // Validate vars as per spec
  52385. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  52386. error('Invalid WhitePoint components, no fallback available');
  52387. }
  52388. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  52389. info('Invalid BlackPoint, falling back to default');
  52390. this.XB = this.YB = this.ZB = 0;
  52391. }
  52392. if (this.amin > this.amax || this.bmin > this.bmax) {
  52393. info('Invalid Range, falling back to defaults');
  52394. this.amin = -100;
  52395. this.amax = 100;
  52396. this.bmin = -100;
  52397. this.bmax = 100;
  52398. }
  52399. }
  52400. // Function g(x) from spec
  52401. function fn_g(x) {
  52402. if (x >= 6 / 29) {
  52403. return x * x * x;
  52404. } else {
  52405. return 108 / 841 * (x - 4 / 29);
  52406. }
  52407. }
  52408. function decode(value, high1, low2, high2) {
  52409. return low2 + value * (high2 - low2) / high1;
  52410. }
  52411. // If decoding is needed maxVal should be 2^bits per component - 1.
  52412. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  52413. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  52414. // not the usual [0, 1]. If a command like setFillColor is used the src
  52415. // values will already be within the correct range. However, if we are
  52416. // converting an image we have to map the values to the correct range given
  52417. // above.
  52418. // Ls,as,bs <---> L*,a*,b* in the spec
  52419. var Ls = src[srcOffset];
  52420. var as = src[srcOffset + 1];
  52421. var bs = src[srcOffset + 2];
  52422. if (maxVal !== false) {
  52423. Ls = decode(Ls, maxVal, 0, 100);
  52424. as = decode(as, maxVal, cs.amin, cs.amax);
  52425. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  52426. }
  52427. // Adjust limits of 'as' and 'bs'
  52428. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  52429. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  52430. // Computes intermediate variables X,Y,Z as per spec
  52431. var M = (Ls + 16) / 116;
  52432. var L = M + as / 500;
  52433. var N = M - bs / 200;
  52434. var X = cs.XW * fn_g(L);
  52435. var Y = cs.YW * fn_g(M);
  52436. var Z = cs.ZW * fn_g(N);
  52437. var r, g, b;
  52438. // Using different conversions for D50 and D65 white points,
  52439. // per http://www.color.org/srgb.pdf
  52440. if (cs.ZW < 1) {
  52441. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  52442. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  52443. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  52444. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  52445. } else {
  52446. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  52447. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  52448. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  52449. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  52450. }
  52451. // clamp color values to [0,1] range then convert to [0,255] range.
  52452. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  52453. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  52454. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  52455. }
  52456. LabCS.prototype = {
  52457. getRgb: ColorSpace.prototype.getRgb,
  52458. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52459. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  52460. },
  52461. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52462. var maxVal = (1 << bits) - 1;
  52463. for (var i = 0; i < count; i++) {
  52464. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  52465. srcOffset += 3;
  52466. destOffset += 3 + alpha01;
  52467. }
  52468. },
  52469. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  52470. return inputLength * (3 + alpha01) / 3 | 0;
  52471. },
  52472. isPassthrough: ColorSpace.prototype.isPassthrough,
  52473. fillRgb: ColorSpace.prototype.fillRgb,
  52474. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  52475. // XXX: Decoding is handled with the lab conversion because of the strange
  52476. // ranges that are used.
  52477. return true;
  52478. },
  52479. usesZeroToOneRange: false
  52480. };
  52481. return LabCS;
  52482. }();
  52483. exports.ColorSpace = ColorSpace;
  52484. }));
  52485. (function (root, factory) {
  52486. factory(root.pdfjsDisplayGlobal = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI, root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer, root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  52487. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI, displayAnnotationLayer, displayTextLayer, displayMetadata, displaySVG) {
  52488. var globalScope = sharedUtil.globalScope;
  52489. var deprecated = sharedUtil.deprecated;
  52490. var warn = sharedUtil.warn;
  52491. var LinkTarget = displayDOMUtils.LinkTarget;
  52492. var isWorker = typeof window === 'undefined';
  52493. // The global PDFJS object is now deprecated and will not be supported in
  52494. // the future. The members below are maintained for backward compatibility
  52495. // and shall not be extended or modified. If the global.js is included as
  52496. // a module, we will create a global PDFJS object instance or use existing.
  52497. if (!globalScope.PDFJS) {
  52498. globalScope.PDFJS = {};
  52499. }
  52500. var PDFJS = globalScope.PDFJS;
  52501. if (typeof pdfjsVersion !== 'undefined') {
  52502. PDFJS.version = pdfjsVersion;
  52503. }
  52504. if (typeof pdfjsBuild !== 'undefined') {
  52505. PDFJS.build = pdfjsBuild;
  52506. }
  52507. PDFJS.pdfBug = false;
  52508. if (PDFJS.verbosity !== undefined) {
  52509. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  52510. }
  52511. delete PDFJS.verbosity;
  52512. Object.defineProperty(PDFJS, 'verbosity', {
  52513. get: function () {
  52514. return sharedUtil.getVerbosityLevel();
  52515. },
  52516. set: function (level) {
  52517. sharedUtil.setVerbosityLevel(level);
  52518. },
  52519. enumerable: true,
  52520. configurable: true
  52521. });
  52522. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  52523. PDFJS.OPS = sharedUtil.OPS;
  52524. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52525. PDFJS.isValidUrl = displayDOMUtils.isValidUrl;
  52526. PDFJS.shadow = sharedUtil.shadow;
  52527. PDFJS.createBlob = sharedUtil.createBlob;
  52528. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  52529. return sharedUtil.createObjectURL(data, contentType, PDFJS.disableCreateObjectURL);
  52530. };
  52531. Object.defineProperty(PDFJS, 'isLittleEndian', {
  52532. configurable: true,
  52533. get: function PDFJS_isLittleEndian() {
  52534. var value = sharedUtil.isLittleEndian();
  52535. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  52536. }
  52537. });
  52538. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  52539. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  52540. PDFJS.PasswordException = sharedUtil.PasswordException;
  52541. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  52542. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  52543. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  52544. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52545. PDFJS.Util = sharedUtil.Util;
  52546. PDFJS.PageViewport = sharedUtil.PageViewport;
  52547. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  52548. /**
  52549. * The maximum allowed image size in total pixels e.g. width * height. Images
  52550. * above this value will not be drawn. Use -1 for no limit.
  52551. * @var {number}
  52552. */
  52553. PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize;
  52554. /**
  52555. * The url of where the predefined Adobe CMaps are located. Include trailing
  52556. * slash.
  52557. * @var {string}
  52558. */
  52559. PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl;
  52560. /**
  52561. * Specifies if CMaps are binary packed.
  52562. * @var {boolean}
  52563. */
  52564. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  52565. /**
  52566. * By default fonts are converted to OpenType fonts and loaded via font face
  52567. * rules. If disabled, the font will be rendered using a built in font
  52568. * renderer that constructs the glyphs with primitive path commands.
  52569. * @var {boolean}
  52570. */
  52571. PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace;
  52572. /**
  52573. * Path for image resources, mainly for annotation icons. Include trailing
  52574. * slash.
  52575. * @var {string}
  52576. */
  52577. PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? '' : PDFJS.imageResourcesPath;
  52578. /**
  52579. * Disable the web worker and run all code on the main thread. This will
  52580. * happen automatically if the browser doesn't support workers or sending
  52581. * typed arrays to workers.
  52582. * @var {boolean}
  52583. */
  52584. PDFJS.disableWorker = PDFJS.disableWorker === undefined ? false : PDFJS.disableWorker;
  52585. /**
  52586. * Path and filename of the worker file. Required when the worker is enabled
  52587. * in development mode. If unspecified in the production build, the worker
  52588. * will be loaded based on the location of the pdf.js file. It is recommended
  52589. * that the workerSrc is set in a custom application to prevent issues caused
  52590. * by third-party frameworks and libraries.
  52591. * @var {string}
  52592. */
  52593. PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc;
  52594. /**
  52595. * Disable range request loading of PDF files. When enabled and if the server
  52596. * supports partial content requests then the PDF will be fetched in chunks.
  52597. * Enabled (false) by default.
  52598. * @var {boolean}
  52599. */
  52600. PDFJS.disableRange = PDFJS.disableRange === undefined ? false : PDFJS.disableRange;
  52601. /**
  52602. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  52603. * in chunks. This default behavior can be disabled.
  52604. * @var {boolean}
  52605. */
  52606. PDFJS.disableStream = PDFJS.disableStream === undefined ? false : PDFJS.disableStream;
  52607. /**
  52608. * Disable pre-fetching of PDF file data. When range requests are enabled
  52609. * PDF.js will automatically keep fetching more data even if it isn't needed
  52610. * to display the current page. This default behavior can be disabled.
  52611. *
  52612. * NOTE: It is also necessary to disable streaming, see above,
  52613. * in order for disabling of pre-fetching to work correctly.
  52614. * @var {boolean}
  52615. */
  52616. PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? false : PDFJS.disableAutoFetch;
  52617. /**
  52618. * Enables special hooks for debugging PDF.js.
  52619. * @var {boolean}
  52620. */
  52621. PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug;
  52622. /**
  52623. * Enables transfer usage in postMessage for ArrayBuffers.
  52624. * @var {boolean}
  52625. */
  52626. PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers;
  52627. /**
  52628. * Disables URL.createObjectURL usage.
  52629. * @var {boolean}
  52630. */
  52631. PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL;
  52632. /**
  52633. * Disables WebGL usage.
  52634. * @var {boolean}
  52635. */
  52636. PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL;
  52637. /**
  52638. * Specifies the |target| attribute for external links.
  52639. * The constants from PDFJS.LinkTarget should be used:
  52640. * - NONE [default]
  52641. * - SELF
  52642. * - BLANK
  52643. * - PARENT
  52644. * - TOP
  52645. * @var {number}
  52646. */
  52647. PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? LinkTarget.NONE : PDFJS.externalLinkTarget;
  52648. /**
  52649. * Specifies the |rel| attribute for external links. Defaults to stripping
  52650. * the referrer.
  52651. * @var {string}
  52652. */
  52653. PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? 'noreferrer' : PDFJS.externalLinkRel;
  52654. /**
  52655. * Determines if we can eval strings as JS. Primarily used to improve
  52656. * performance for font rendering.
  52657. * @var {boolean}
  52658. */
  52659. PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported;
  52660. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  52661. delete PDFJS.openExternalLinksInNewWindow;
  52662. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  52663. get: function () {
  52664. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  52665. },
  52666. set: function (value) {
  52667. if (value) {
  52668. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' + '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  52669. }
  52670. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  52671. warn('PDFJS.externalLinkTarget is already initialized');
  52672. return;
  52673. }
  52674. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  52675. },
  52676. enumerable: true,
  52677. configurable: true
  52678. });
  52679. if (savedOpenExternalLinksInNewWindow) {
  52680. /**
  52681. * (Deprecated) Opens external links in a new window if enabled.
  52682. * The default behavior opens external links in the PDF.js window.
  52683. *
  52684. * NOTE: This property has been deprecated, please use
  52685. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  52686. * @var {boolean}
  52687. */
  52688. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  52689. }
  52690. PDFJS.getDocument = displayAPI.getDocument;
  52691. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  52692. PDFJS.PDFWorker = displayAPI.PDFWorker;
  52693. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  52694. configurable: true,
  52695. get: function PDFJS_hasCanvasTypedArrays() {
  52696. var value = displayDOMUtils.hasCanvasTypedArrays();
  52697. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  52698. }
  52699. });
  52700. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  52701. PDFJS.LinkTarget = LinkTarget;
  52702. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  52703. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  52704. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  52705. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  52706. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  52707. PDFJS.Metadata = displayMetadata.Metadata;
  52708. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  52709. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  52710. exports.globalScope = globalScope;
  52711. exports.isWorker = isWorker;
  52712. exports.PDFJS = globalScope.PDFJS;
  52713. }));
  52714. (function (root, factory) {
  52715. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  52716. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  52717. var ImageKind = sharedUtil.ImageKind;
  52718. var assert = sharedUtil.assert;
  52719. var error = sharedUtil.error;
  52720. var info = sharedUtil.info;
  52721. var isArray = sharedUtil.isArray;
  52722. var warn = sharedUtil.warn;
  52723. var Name = corePrimitives.Name;
  52724. var isStream = corePrimitives.isStream;
  52725. var ColorSpace = coreColorSpace.ColorSpace;
  52726. var DecodeStream = coreStream.DecodeStream;
  52727. var JpegStream = coreStream.JpegStream;
  52728. var JpxImage = coreJpx.JpxImage;
  52729. var PDFImage = function PDFImageClosure() {
  52730. /**
  52731. * Decodes the image using native decoder if possible. Resolves the promise
  52732. * when the image data is ready.
  52733. */
  52734. function handleImageData(image, nativeDecoder) {
  52735. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  52736. return nativeDecoder.decode(image);
  52737. } else {
  52738. return Promise.resolve(image);
  52739. }
  52740. }
  52741. /**
  52742. * Decode and clamp a value. The formula is different from the spec because we
  52743. * don't decode to float range [0,1], we decode it in the [0,max] range.
  52744. */
  52745. function decodeAndClamp(value, addend, coefficient, max) {
  52746. value = addend + value * coefficient;
  52747. // Clamp the value to the range
  52748. return value < 0 ? 0 : value > max ? max : value;
  52749. }
  52750. /**
  52751. * Resizes an image mask with 1 component.
  52752. * @param {TypedArray} src - The source buffer.
  52753. * @param {Number} bpc - Number of bits per component.
  52754. * @param {Number} w1 - Original width.
  52755. * @param {Number} h1 - Original height.
  52756. * @param {Number} w2 - New width.
  52757. * @param {Number} h2 - New height.
  52758. * @returns {TypedArray} The resized image mask buffer.
  52759. */
  52760. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  52761. var length = w2 * h2;
  52762. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  52763. var xRatio = w1 / w2;
  52764. var yRatio = h1 / h2;
  52765. var i, j, py, newIndex = 0, oldIndex;
  52766. var xScaled = new Uint16Array(w2);
  52767. var w1Scanline = w1;
  52768. for (i = 0; i < w2; i++) {
  52769. xScaled[i] = Math.floor(i * xRatio);
  52770. }
  52771. for (i = 0; i < h2; i++) {
  52772. py = Math.floor(i * yRatio) * w1Scanline;
  52773. for (j = 0; j < w2; j++) {
  52774. oldIndex = py + xScaled[j];
  52775. dest[newIndex++] = src[oldIndex];
  52776. }
  52777. }
  52778. return dest;
  52779. }
  52780. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  52781. this.image = image;
  52782. var dict = image.dict;
  52783. if (dict.has('Filter')) {
  52784. var filter = dict.get('Filter').name;
  52785. if (filter === 'JPXDecode') {
  52786. var jpxImage = new JpxImage();
  52787. jpxImage.parseImageProperties(image.stream);
  52788. image.stream.reset();
  52789. image.bitsPerComponent = jpxImage.bitsPerComponent;
  52790. image.numComps = jpxImage.componentsCount;
  52791. } else if (filter === 'JBIG2Decode') {
  52792. image.bitsPerComponent = 1;
  52793. image.numComps = 1;
  52794. }
  52795. }
  52796. // TODO cache rendered images?
  52797. this.width = dict.get('Width', 'W');
  52798. this.height = dict.get('Height', 'H');
  52799. if (this.width < 1 || this.height < 1) {
  52800. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  52801. }
  52802. this.interpolate = dict.get('Interpolate', 'I') || false;
  52803. this.imageMask = dict.get('ImageMask', 'IM') || false;
  52804. this.matte = dict.get('Matte') || false;
  52805. var bitsPerComponent = image.bitsPerComponent;
  52806. if (!bitsPerComponent) {
  52807. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  52808. if (!bitsPerComponent) {
  52809. if (this.imageMask) {
  52810. bitsPerComponent = 1;
  52811. } else {
  52812. error('Bits per component missing in image: ' + this.imageMask);
  52813. }
  52814. }
  52815. }
  52816. this.bpc = bitsPerComponent;
  52817. if (!this.imageMask) {
  52818. var colorSpace = dict.get('ColorSpace', 'CS');
  52819. if (!colorSpace) {
  52820. info('JPX images (which do not require color spaces)');
  52821. switch (image.numComps) {
  52822. case 1:
  52823. colorSpace = Name.get('DeviceGray');
  52824. break;
  52825. case 3:
  52826. colorSpace = Name.get('DeviceRGB');
  52827. break;
  52828. case 4:
  52829. colorSpace = Name.get('DeviceCMYK');
  52830. break;
  52831. default:
  52832. error('JPX images with ' + this.numComps + ' color components not supported.');
  52833. }
  52834. }
  52835. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  52836. this.numComps = this.colorSpace.numComps;
  52837. }
  52838. this.decode = dict.getArray('Decode', 'D');
  52839. this.needsDecode = false;
  52840. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  52841. this.needsDecode = true;
  52842. // Do some preprocessing to avoid more math.
  52843. var max = (1 << bitsPerComponent) - 1;
  52844. this.decodeCoefficients = [];
  52845. this.decodeAddends = [];
  52846. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  52847. var dmin = this.decode[i];
  52848. var dmax = this.decode[i + 1];
  52849. this.decodeCoefficients[j] = dmax - dmin;
  52850. this.decodeAddends[j] = max * dmin;
  52851. }
  52852. }
  52853. if (smask) {
  52854. this.smask = new PDFImage(xref, res, smask, false);
  52855. } else if (mask) {
  52856. if (isStream(mask)) {
  52857. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  52858. if (!imageMask) {
  52859. warn('Ignoring /Mask in image without /ImageMask.');
  52860. } else {
  52861. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  52862. }
  52863. } else {
  52864. // Color key mask (just an array).
  52865. this.mask = mask;
  52866. }
  52867. }
  52868. }
  52869. /**
  52870. * Handles processing of image data and returns the Promise that is resolved
  52871. * with a PDFImage when the image is ready to be used.
  52872. */
  52873. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  52874. var imagePromise = handleImageData(image, nativeDecoder);
  52875. var smaskPromise;
  52876. var maskPromise;
  52877. var smask = image.dict.get('SMask');
  52878. var mask = image.dict.get('Mask');
  52879. if (smask) {
  52880. smaskPromise = handleImageData(smask, nativeDecoder);
  52881. maskPromise = Promise.resolve(null);
  52882. } else {
  52883. smaskPromise = Promise.resolve(null);
  52884. if (mask) {
  52885. if (isStream(mask)) {
  52886. maskPromise = handleImageData(mask, nativeDecoder);
  52887. } else if (isArray(mask)) {
  52888. maskPromise = Promise.resolve(mask);
  52889. } else {
  52890. warn('Unsupported mask format.');
  52891. maskPromise = Promise.resolve(null);
  52892. }
  52893. } else {
  52894. maskPromise = Promise.resolve(null);
  52895. }
  52896. }
  52897. return Promise.all([
  52898. imagePromise,
  52899. smaskPromise,
  52900. maskPromise
  52901. ]).then(function (results) {
  52902. var imageData = results[0];
  52903. var smaskData = results[1];
  52904. var maskData = results[2];
  52905. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  52906. });
  52907. };
  52908. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  52909. // |imgArray| might not contain full data for every pixel of the mask, so
  52910. // we need to distinguish between |computedLength| and |actualLength|.
  52911. // In particular, if inverseDecode is true, then the array we return must
  52912. // have a length of |computedLength|.
  52913. var computedLength = (width + 7 >> 3) * height;
  52914. var actualLength = imgArray.byteLength;
  52915. var haveFullData = computedLength === actualLength;
  52916. var data, i;
  52917. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  52918. // imgArray came from a DecodeStream and its data is in an appropriate
  52919. // form, so we can just transfer it.
  52920. data = imgArray;
  52921. } else if (!inverseDecode) {
  52922. data = new Uint8Array(actualLength);
  52923. data.set(imgArray);
  52924. } else {
  52925. data = new Uint8Array(computedLength);
  52926. data.set(imgArray);
  52927. for (i = actualLength; i < computedLength; i++) {
  52928. data[i] = 0xff;
  52929. }
  52930. }
  52931. // If necessary, invert the original mask data (but not any extra we might
  52932. // have added above). It's safe to modify the array -- whether it's the
  52933. // original or a copy, we're about to transfer it anyway, so nothing else
  52934. // in this thread can be relying on its contents.
  52935. if (inverseDecode) {
  52936. for (i = 0; i < actualLength; i++) {
  52937. data[i] = ~data[i];
  52938. }
  52939. }
  52940. return {
  52941. data: data,
  52942. width: width,
  52943. height: height
  52944. };
  52945. };
  52946. PDFImage.prototype = {
  52947. get drawWidth() {
  52948. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  52949. },
  52950. get drawHeight() {
  52951. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  52952. },
  52953. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  52954. var bpc = this.bpc;
  52955. var numComps = this.numComps;
  52956. var decodeAddends = this.decodeAddends;
  52957. var decodeCoefficients = this.decodeCoefficients;
  52958. var max = (1 << bpc) - 1;
  52959. var i, ii;
  52960. if (bpc === 1) {
  52961. // If the buffer needed decode that means it just needs to be inverted.
  52962. for (i = 0, ii = buffer.length; i < ii; i++) {
  52963. buffer[i] = +!buffer[i];
  52964. }
  52965. return;
  52966. }
  52967. var index = 0;
  52968. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  52969. for (var j = 0; j < numComps; j++) {
  52970. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  52971. index++;
  52972. }
  52973. }
  52974. },
  52975. getComponents: function PDFImage_getComponents(buffer) {
  52976. var bpc = this.bpc;
  52977. // This image doesn't require any extra work.
  52978. if (bpc === 8) {
  52979. return buffer;
  52980. }
  52981. var width = this.width;
  52982. var height = this.height;
  52983. var numComps = this.numComps;
  52984. var length = width * height * numComps;
  52985. var bufferPos = 0;
  52986. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  52987. var rowComps = width * numComps;
  52988. var max = (1 << bpc) - 1;
  52989. var i = 0, ii, buf;
  52990. if (bpc === 1) {
  52991. // Optimization for reading 1 bpc images.
  52992. var mask, loop1End, loop2End;
  52993. for (var j = 0; j < height; j++) {
  52994. loop1End = i + (rowComps & ~7);
  52995. loop2End = i + rowComps;
  52996. // unroll loop for all full bytes
  52997. while (i < loop1End) {
  52998. buf = buffer[bufferPos++];
  52999. output[i] = buf >> 7 & 1;
  53000. output[i + 1] = buf >> 6 & 1;
  53001. output[i + 2] = buf >> 5 & 1;
  53002. output[i + 3] = buf >> 4 & 1;
  53003. output[i + 4] = buf >> 3 & 1;
  53004. output[i + 5] = buf >> 2 & 1;
  53005. output[i + 6] = buf >> 1 & 1;
  53006. output[i + 7] = buf & 1;
  53007. i += 8;
  53008. }
  53009. // handle remaining bits
  53010. if (i < loop2End) {
  53011. buf = buffer[bufferPos++];
  53012. mask = 128;
  53013. while (i < loop2End) {
  53014. output[i++] = +!!(buf & mask);
  53015. mask >>= 1;
  53016. }
  53017. }
  53018. }
  53019. } else {
  53020. // The general case that handles all other bpc values.
  53021. var bits = 0;
  53022. buf = 0;
  53023. for (i = 0, ii = length; i < ii; ++i) {
  53024. if (i % rowComps === 0) {
  53025. buf = 0;
  53026. bits = 0;
  53027. }
  53028. while (bits < bpc) {
  53029. buf = buf << 8 | buffer[bufferPos++];
  53030. bits += 8;
  53031. }
  53032. var remainingBits = bits - bpc;
  53033. var value = buf >> remainingBits;
  53034. output[i] = value < 0 ? 0 : value > max ? max : value;
  53035. buf = buf & (1 << remainingBits) - 1;
  53036. bits = remainingBits;
  53037. }
  53038. }
  53039. return output;
  53040. },
  53041. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  53042. var smask = this.smask;
  53043. var mask = this.mask;
  53044. var alphaBuf, sw, sh, i, ii, j;
  53045. if (smask) {
  53046. sw = smask.width;
  53047. sh = smask.height;
  53048. alphaBuf = new Uint8Array(sw * sh);
  53049. smask.fillGrayBuffer(alphaBuf);
  53050. if (sw !== width || sh !== height) {
  53051. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  53052. }
  53053. } else if (mask) {
  53054. if (mask instanceof PDFImage) {
  53055. sw = mask.width;
  53056. sh = mask.height;
  53057. alphaBuf = new Uint8Array(sw * sh);
  53058. mask.numComps = 1;
  53059. mask.fillGrayBuffer(alphaBuf);
  53060. // Need to invert values in rgbaBuf
  53061. for (i = 0, ii = sw * sh; i < ii; ++i) {
  53062. alphaBuf[i] = 255 - alphaBuf[i];
  53063. }
  53064. if (sw !== width || sh !== height) {
  53065. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  53066. }
  53067. } else if (isArray(mask)) {
  53068. // Color key mask: if any of the components are outside the range
  53069. // then they should be painted.
  53070. alphaBuf = new Uint8Array(width * height);
  53071. var numComps = this.numComps;
  53072. for (i = 0, ii = width * height; i < ii; ++i) {
  53073. var opacity = 0;
  53074. var imageOffset = i * numComps;
  53075. for (j = 0; j < numComps; ++j) {
  53076. var color = image[imageOffset + j];
  53077. var maskOffset = j * 2;
  53078. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  53079. opacity = 255;
  53080. break;
  53081. }
  53082. }
  53083. alphaBuf[i] = opacity;
  53084. }
  53085. } else {
  53086. error('Unknown mask format.');
  53087. }
  53088. }
  53089. if (alphaBuf) {
  53090. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  53091. rgbaBuf[j] = alphaBuf[i];
  53092. }
  53093. } else {
  53094. // No mask.
  53095. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  53096. rgbaBuf[j] = 255;
  53097. }
  53098. }
  53099. },
  53100. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  53101. var matte = this.smask && this.smask.matte;
  53102. if (!matte) {
  53103. return;
  53104. }
  53105. var matteRgb = this.colorSpace.getRgb(matte, 0);
  53106. var matteR = matteRgb[0];
  53107. var matteG = matteRgb[1];
  53108. var matteB = matteRgb[2];
  53109. var length = width * height * 4;
  53110. var r, g, b;
  53111. for (var i = 0; i < length; i += 4) {
  53112. var alpha = buffer[i + 3];
  53113. if (alpha === 0) {
  53114. // according formula we have to get Infinity in all components
  53115. // making it white (typical paper color) should be okay
  53116. buffer[i] = 255;
  53117. buffer[i + 1] = 255;
  53118. buffer[i + 2] = 255;
  53119. continue;
  53120. }
  53121. var k = 255 / alpha;
  53122. r = (buffer[i] - matteR) * k + matteR;
  53123. g = (buffer[i + 1] - matteG) * k + matteG;
  53124. b = (buffer[i + 2] - matteB) * k + matteB;
  53125. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  53126. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  53127. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  53128. }
  53129. },
  53130. createImageData: function PDFImage_createImageData(forceRGBA) {
  53131. var drawWidth = this.drawWidth;
  53132. var drawHeight = this.drawHeight;
  53133. var imgData = {
  53134. // other fields are filled in below
  53135. width: drawWidth,
  53136. height: drawHeight
  53137. };
  53138. var numComps = this.numComps;
  53139. var originalWidth = this.width;
  53140. var originalHeight = this.height;
  53141. var bpc = this.bpc;
  53142. // Rows start at byte boundary.
  53143. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  53144. var imgArray;
  53145. if (!forceRGBA) {
  53146. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  53147. // without any complications, we pass a same-sized copy to the main
  53148. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  53149. // of memory for many scanned documents. It's also much faster.
  53150. //
  53151. // Similarly, if it is a 24-bit-per pixel RGB image without any
  53152. // complications, we avoid expanding by 1.333x to RGBA form.
  53153. var kind;
  53154. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  53155. kind = ImageKind.GRAYSCALE_1BPP;
  53156. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  53157. kind = ImageKind.RGB_24BPP;
  53158. }
  53159. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  53160. imgData.kind = kind;
  53161. imgArray = this.getImageBytes(originalHeight * rowBytes);
  53162. // If imgArray came from a DecodeStream, we're safe to transfer it
  53163. // (and thus detach its underlying buffer) because it will constitute
  53164. // the entire DecodeStream's data. But if it came from a Stream, we
  53165. // need to copy it because it'll only be a portion of the Stream's
  53166. // data, and the rest will be read later on.
  53167. if (this.image instanceof DecodeStream) {
  53168. imgData.data = imgArray;
  53169. } else {
  53170. var newArray = new Uint8Array(imgArray.length);
  53171. newArray.set(imgArray);
  53172. imgData.data = newArray;
  53173. }
  53174. if (this.needsDecode) {
  53175. // Invert the buffer (which must be grayscale if we reached here).
  53176. assert(kind === ImageKind.GRAYSCALE_1BPP);
  53177. var buffer = imgData.data;
  53178. for (var i = 0, ii = buffer.length; i < ii; i++) {
  53179. buffer[i] ^= 0xff;
  53180. }
  53181. }
  53182. return imgData;
  53183. }
  53184. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  53185. imgData.kind = ImageKind.RGB_24BPP;
  53186. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  53187. return imgData;
  53188. }
  53189. }
  53190. imgArray = this.getImageBytes(originalHeight * rowBytes);
  53191. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  53192. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  53193. var comps = this.getComponents(imgArray);
  53194. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  53195. // more compact RGB_24BPP form if allowable.
  53196. var alpha01, maybeUndoPreblend;
  53197. if (!forceRGBA && !this.smask && !this.mask) {
  53198. imgData.kind = ImageKind.RGB_24BPP;
  53199. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  53200. alpha01 = 0;
  53201. maybeUndoPreblend = false;
  53202. } else {
  53203. imgData.kind = ImageKind.RGBA_32BPP;
  53204. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  53205. alpha01 = 1;
  53206. maybeUndoPreblend = true;
  53207. // Color key masking (opacity) must be performed before decoding.
  53208. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  53209. }
  53210. if (this.needsDecode) {
  53211. this.decodeBuffer(comps);
  53212. }
  53213. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  53214. if (maybeUndoPreblend) {
  53215. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  53216. }
  53217. return imgData;
  53218. },
  53219. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  53220. var numComps = this.numComps;
  53221. if (numComps !== 1) {
  53222. error('Reading gray scale from a color image: ' + numComps);
  53223. }
  53224. var width = this.width;
  53225. var height = this.height;
  53226. var bpc = this.bpc;
  53227. // rows start at byte boundary
  53228. var rowBytes = width * numComps * bpc + 7 >> 3;
  53229. var imgArray = this.getImageBytes(height * rowBytes);
  53230. var comps = this.getComponents(imgArray);
  53231. var i, length;
  53232. if (bpc === 1) {
  53233. // inline decoding (= inversion) for 1 bpc images
  53234. length = width * height;
  53235. if (this.needsDecode) {
  53236. // invert and scale to {0, 255}
  53237. for (i = 0; i < length; ++i) {
  53238. buffer[i] = comps[i] - 1 & 255;
  53239. }
  53240. } else {
  53241. // scale to {0, 255}
  53242. for (i = 0; i < length; ++i) {
  53243. buffer[i] = -comps[i] & 255;
  53244. }
  53245. }
  53246. return;
  53247. }
  53248. if (this.needsDecode) {
  53249. this.decodeBuffer(comps);
  53250. }
  53251. length = width * height;
  53252. // we aren't using a colorspace so we need to scale the value
  53253. var scale = 255 / ((1 << bpc) - 1);
  53254. for (i = 0; i < length; ++i) {
  53255. buffer[i] = scale * comps[i] | 0;
  53256. }
  53257. },
  53258. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  53259. this.image.reset();
  53260. this.image.drawWidth = drawWidth || this.width;
  53261. this.image.drawHeight = drawHeight || this.height;
  53262. this.image.forceRGB = !!forceRGB;
  53263. return this.image.getBytes(length);
  53264. }
  53265. };
  53266. return PDFImage;
  53267. }();
  53268. exports.PDFImage = PDFImage;
  53269. }));
  53270. (function (root, factory) {
  53271. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  53272. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  53273. var InvalidPDFException = sharedUtil.InvalidPDFException;
  53274. var MissingDataException = sharedUtil.MissingDataException;
  53275. var XRefParseException = sharedUtil.XRefParseException;
  53276. var assert = sharedUtil.assert;
  53277. var bytesToString = sharedUtil.bytesToString;
  53278. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53279. var error = sharedUtil.error;
  53280. var info = sharedUtil.info;
  53281. var isArray = sharedUtil.isArray;
  53282. var isBool = sharedUtil.isBool;
  53283. var isInt = sharedUtil.isInt;
  53284. var isString = sharedUtil.isString;
  53285. var shadow = sharedUtil.shadow;
  53286. var stringToPDFString = sharedUtil.stringToPDFString;
  53287. var stringToUTF8String = sharedUtil.stringToUTF8String;
  53288. var warn = sharedUtil.warn;
  53289. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  53290. var Util = sharedUtil.Util;
  53291. var Ref = corePrimitives.Ref;
  53292. var RefSet = corePrimitives.RefSet;
  53293. var RefSetCache = corePrimitives.RefSetCache;
  53294. var isName = corePrimitives.isName;
  53295. var isCmd = corePrimitives.isCmd;
  53296. var isDict = corePrimitives.isDict;
  53297. var isRef = corePrimitives.isRef;
  53298. var isRefsEqual = corePrimitives.isRefsEqual;
  53299. var isStream = corePrimitives.isStream;
  53300. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  53301. var Lexer = coreParser.Lexer;
  53302. var Parser = coreParser.Parser;
  53303. var ChunkedStream = coreChunkedStream.ChunkedStream;
  53304. var ColorSpace = coreColorSpace.ColorSpace;
  53305. var Catalog = function CatalogClosure() {
  53306. function Catalog(pdfManager, xref, pageFactory) {
  53307. this.pdfManager = pdfManager;
  53308. this.xref = xref;
  53309. this.catDict = xref.getCatalogObj();
  53310. this.fontCache = new RefSetCache();
  53311. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  53312. // TODO refactor to move getPage() to the PDFDocument.
  53313. this.pageFactory = pageFactory;
  53314. this.pagePromises = [];
  53315. }
  53316. Catalog.prototype = {
  53317. get metadata() {
  53318. var streamRef = this.catDict.getRaw('Metadata');
  53319. if (!isRef(streamRef)) {
  53320. return shadow(this, 'metadata', null);
  53321. }
  53322. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  53323. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  53324. var metadata;
  53325. if (stream && isDict(stream.dict)) {
  53326. var type = stream.dict.get('Type');
  53327. var subtype = stream.dict.get('Subtype');
  53328. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  53329. // XXX: This should examine the charset the XML document defines,
  53330. // however since there are currently no real means to decode
  53331. // arbitrary charsets, let's just hope that the author of the PDF
  53332. // was reasonable enough to stick with the XML default charset,
  53333. // which is UTF-8.
  53334. try {
  53335. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  53336. } catch (e) {
  53337. info('Skipping invalid metadata.');
  53338. }
  53339. }
  53340. }
  53341. return shadow(this, 'metadata', metadata);
  53342. },
  53343. get toplevelPagesDict() {
  53344. var pagesObj = this.catDict.get('Pages');
  53345. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  53346. // shadow the prototype getter
  53347. return shadow(this, 'toplevelPagesDict', pagesObj);
  53348. },
  53349. get documentOutline() {
  53350. var obj = null;
  53351. try {
  53352. obj = this.readDocumentOutline();
  53353. } catch (ex) {
  53354. if (ex instanceof MissingDataException) {
  53355. throw ex;
  53356. }
  53357. warn('Unable to read document outline');
  53358. }
  53359. return shadow(this, 'documentOutline', obj);
  53360. },
  53361. readDocumentOutline: function Catalog_readDocumentOutline() {
  53362. var obj = this.catDict.get('Outlines');
  53363. if (!isDict(obj)) {
  53364. return null;
  53365. }
  53366. obj = obj.getRaw('First');
  53367. if (!isRef(obj)) {
  53368. return null;
  53369. }
  53370. var root = { items: [] };
  53371. var queue = [{
  53372. obj: obj,
  53373. parent: root
  53374. }];
  53375. // To avoid recursion, keep track of the already processed items.
  53376. var processed = new RefSet();
  53377. processed.put(obj);
  53378. var xref = this.xref, blackColor = new Uint8Array(3);
  53379. while (queue.length > 0) {
  53380. var i = queue.shift();
  53381. var outlineDict = xref.fetchIfRef(i.obj);
  53382. if (outlineDict === null) {
  53383. continue;
  53384. }
  53385. assert(outlineDict.has('Title'), 'Invalid outline item');
  53386. var data = {
  53387. url: null,
  53388. dest: null
  53389. };
  53390. Catalog.parseDestDictionary({
  53391. destDict: outlineDict,
  53392. resultObj: data,
  53393. docBaseUrl: this.pdfManager.docBaseUrl
  53394. });
  53395. var title = outlineDict.get('Title');
  53396. var flags = outlineDict.get('F') || 0;
  53397. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  53398. // We only need to parse the color when it's valid, and non-default.
  53399. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  53400. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  53401. }
  53402. var outlineItem = {
  53403. dest: data.dest,
  53404. url: data.url,
  53405. newWindow: data.newWindow,
  53406. title: stringToPDFString(title),
  53407. color: rgbColor,
  53408. count: outlineDict.get('Count'),
  53409. bold: !!(flags & 2),
  53410. italic: !!(flags & 1),
  53411. items: []
  53412. };
  53413. i.parent.items.push(outlineItem);
  53414. obj = outlineDict.getRaw('First');
  53415. if (isRef(obj) && !processed.has(obj)) {
  53416. queue.push({
  53417. obj: obj,
  53418. parent: outlineItem
  53419. });
  53420. processed.put(obj);
  53421. }
  53422. obj = outlineDict.getRaw('Next');
  53423. if (isRef(obj) && !processed.has(obj)) {
  53424. queue.push({
  53425. obj: obj,
  53426. parent: i.parent
  53427. });
  53428. processed.put(obj);
  53429. }
  53430. }
  53431. return root.items.length > 0 ? root.items : null;
  53432. },
  53433. get numPages() {
  53434. var obj = this.toplevelPagesDict.get('Count');
  53435. assert(isInt(obj), 'page count in top level pages object is not an integer');
  53436. // shadow the prototype getter
  53437. return shadow(this, 'num', obj);
  53438. },
  53439. get destinations() {
  53440. function fetchDestination(dest) {
  53441. return isDict(dest) ? dest.get('D') : dest;
  53442. }
  53443. var xref = this.xref;
  53444. var dests = {}, nameTreeRef, nameDictionaryRef;
  53445. var obj = this.catDict.get('Names');
  53446. if (obj && obj.has('Dests')) {
  53447. nameTreeRef = obj.getRaw('Dests');
  53448. } else if (this.catDict.has('Dests')) {
  53449. nameDictionaryRef = this.catDict.get('Dests');
  53450. }
  53451. if (nameDictionaryRef) {
  53452. // reading simple destination dictionary
  53453. obj = nameDictionaryRef;
  53454. obj.forEach(function catalogForEach(key, value) {
  53455. if (!value) {
  53456. return;
  53457. }
  53458. dests[key] = fetchDestination(value);
  53459. });
  53460. }
  53461. if (nameTreeRef) {
  53462. var nameTree = new NameTree(nameTreeRef, xref);
  53463. var names = nameTree.getAll();
  53464. for (var name in names) {
  53465. dests[name] = fetchDestination(names[name]);
  53466. }
  53467. }
  53468. return shadow(this, 'destinations', dests);
  53469. },
  53470. getDestination: function Catalog_getDestination(destinationId) {
  53471. function fetchDestination(dest) {
  53472. return isDict(dest) ? dest.get('D') : dest;
  53473. }
  53474. var xref = this.xref;
  53475. var dest = null, nameTreeRef, nameDictionaryRef;
  53476. var obj = this.catDict.get('Names');
  53477. if (obj && obj.has('Dests')) {
  53478. nameTreeRef = obj.getRaw('Dests');
  53479. } else if (this.catDict.has('Dests')) {
  53480. nameDictionaryRef = this.catDict.get('Dests');
  53481. }
  53482. if (nameDictionaryRef) {
  53483. // Simple destination dictionary.
  53484. var value = nameDictionaryRef.get(destinationId);
  53485. if (value) {
  53486. dest = fetchDestination(value);
  53487. }
  53488. }
  53489. if (nameTreeRef) {
  53490. var nameTree = new NameTree(nameTreeRef, xref);
  53491. dest = fetchDestination(nameTree.get(destinationId));
  53492. }
  53493. return dest;
  53494. },
  53495. get pageLabels() {
  53496. var obj = null;
  53497. try {
  53498. obj = this.readPageLabels();
  53499. } catch (ex) {
  53500. if (ex instanceof MissingDataException) {
  53501. throw ex;
  53502. }
  53503. warn('Unable to read page labels.');
  53504. }
  53505. return shadow(this, 'pageLabels', obj);
  53506. },
  53507. readPageLabels: function Catalog_readPageLabels() {
  53508. var obj = this.catDict.getRaw('PageLabels');
  53509. if (!obj) {
  53510. return null;
  53511. }
  53512. var pageLabels = new Array(this.numPages);
  53513. var style = null;
  53514. var prefix = '';
  53515. var start = 1;
  53516. var numberTree = new NumberTree(obj, this.xref);
  53517. var nums = numberTree.getAll();
  53518. var currentLabel = '', currentIndex = 1;
  53519. for (var i = 0, ii = this.numPages; i < ii; i++) {
  53520. if (i in nums) {
  53521. var labelDict = nums[i];
  53522. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  53523. var type = labelDict.get('Type');
  53524. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  53525. var s = labelDict.get('S');
  53526. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  53527. style = s ? s.name : null;
  53528. prefix = labelDict.get('P') || '';
  53529. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  53530. start = labelDict.get('St') || 1;
  53531. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  53532. currentIndex = start;
  53533. }
  53534. switch (style) {
  53535. case 'D':
  53536. currentLabel = currentIndex;
  53537. break;
  53538. case 'R':
  53539. case 'r':
  53540. currentLabel = Util.toRoman(currentIndex, style === 'r');
  53541. break;
  53542. case 'A':
  53543. case 'a':
  53544. var LIMIT = 26;
  53545. // Use only the characters A--Z, or a--z.
  53546. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  53547. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  53548. var letterIndex = currentIndex - 1;
  53549. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  53550. var charBuf = [];
  53551. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  53552. charBuf.push(character);
  53553. }
  53554. currentLabel = charBuf.join('');
  53555. break;
  53556. default:
  53557. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  53558. }
  53559. pageLabels[i] = prefix + currentLabel;
  53560. currentLabel = '';
  53561. currentIndex++;
  53562. }
  53563. return pageLabels;
  53564. },
  53565. get attachments() {
  53566. var xref = this.xref;
  53567. var attachments = null, nameTreeRef;
  53568. var obj = this.catDict.get('Names');
  53569. if (obj) {
  53570. nameTreeRef = obj.getRaw('EmbeddedFiles');
  53571. }
  53572. if (nameTreeRef) {
  53573. var nameTree = new NameTree(nameTreeRef, xref);
  53574. var names = nameTree.getAll();
  53575. for (var name in names) {
  53576. var fs = new FileSpec(names[name], xref);
  53577. if (!attachments) {
  53578. attachments = Object.create(null);
  53579. }
  53580. attachments[stringToPDFString(name)] = fs.serializable;
  53581. }
  53582. }
  53583. return shadow(this, 'attachments', attachments);
  53584. },
  53585. get javaScript() {
  53586. var xref = this.xref;
  53587. var obj = this.catDict.get('Names');
  53588. var javaScript = [];
  53589. function appendIfJavaScriptDict(jsDict) {
  53590. var type = jsDict.get('S');
  53591. if (!isName(type, 'JavaScript')) {
  53592. return;
  53593. }
  53594. var js = jsDict.get('JS');
  53595. if (isStream(js)) {
  53596. js = bytesToString(js.getBytes());
  53597. } else if (!isString(js)) {
  53598. return;
  53599. }
  53600. javaScript.push(stringToPDFString(js));
  53601. }
  53602. if (obj && obj.has('JavaScript')) {
  53603. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  53604. var names = nameTree.getAll();
  53605. for (var name in names) {
  53606. // We don't really use the JavaScript right now. This code is
  53607. // defensive so we don't cause errors on document load.
  53608. var jsDict = names[name];
  53609. if (isDict(jsDict)) {
  53610. appendIfJavaScriptDict(jsDict);
  53611. }
  53612. }
  53613. }
  53614. // Append OpenAction actions to javaScript array
  53615. var openactionDict = this.catDict.get('OpenAction');
  53616. if (isDict(openactionDict, 'Action')) {
  53617. var actionType = openactionDict.get('S');
  53618. if (isName(actionType, 'Named')) {
  53619. // The named Print action is not a part of the PDF 1.7 specification,
  53620. // but is supported by many PDF readers/writers (including Adobe's).
  53621. var action = openactionDict.get('N');
  53622. if (isName(action, 'Print')) {
  53623. javaScript.push('print({});');
  53624. }
  53625. } else {
  53626. appendIfJavaScriptDict(openactionDict);
  53627. }
  53628. }
  53629. return shadow(this, 'javaScript', javaScript);
  53630. },
  53631. cleanup: function Catalog_cleanup() {
  53632. var promises = [];
  53633. this.fontCache.forEach(function (promise) {
  53634. promises.push(promise);
  53635. });
  53636. return Promise.all(promises).then(function (translatedFonts) {
  53637. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  53638. var font = translatedFonts[i].dict;
  53639. delete font.translated;
  53640. }
  53641. this.fontCache.clear();
  53642. }.bind(this));
  53643. },
  53644. getPage: function Catalog_getPage(pageIndex) {
  53645. if (!(pageIndex in this.pagePromises)) {
  53646. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  53647. var dict = a[0];
  53648. var ref = a[1];
  53649. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  53650. }.bind(this));
  53651. }
  53652. return this.pagePromises[pageIndex];
  53653. },
  53654. getPageDict: function Catalog_getPageDict(pageIndex) {
  53655. var capability = createPromiseCapability();
  53656. var nodesToVisit = [this.catDict.getRaw('Pages')];
  53657. var currentPageIndex = 0;
  53658. var xref = this.xref;
  53659. var checkAllKids = false;
  53660. function next() {
  53661. while (nodesToVisit.length) {
  53662. var currentNode = nodesToVisit.pop();
  53663. if (isRef(currentNode)) {
  53664. xref.fetchAsync(currentNode).then(function (obj) {
  53665. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  53666. if (pageIndex === currentPageIndex) {
  53667. capability.resolve([
  53668. obj,
  53669. currentNode
  53670. ]);
  53671. } else {
  53672. currentPageIndex++;
  53673. next();
  53674. }
  53675. return;
  53676. }
  53677. nodesToVisit.push(obj);
  53678. next();
  53679. }, capability.reject);
  53680. return;
  53681. }
  53682. // Must be a child page dictionary.
  53683. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  53684. var count = currentNode.get('Count');
  53685. // If the current node doesn't have any children, avoid getting stuck
  53686. // in an empty node further down in the tree (see issue5644.pdf).
  53687. if (count === 0) {
  53688. checkAllKids = true;
  53689. }
  53690. // Skip nodes where the page can't be.
  53691. if (currentPageIndex + count <= pageIndex) {
  53692. currentPageIndex += count;
  53693. continue;
  53694. }
  53695. var kids = currentNode.get('Kids');
  53696. assert(isArray(kids), 'page dictionary kids object is not an array');
  53697. if (!checkAllKids && count === kids.length) {
  53698. // Nodes that don't have the page have been skipped and this is the
  53699. // bottom of the tree which means the page requested must be a
  53700. // descendant of this pages node. Ideally we would just resolve the
  53701. // promise with the page ref here, but there is the case where more
  53702. // pages nodes could link to single a page (see issue 3666 pdf). To
  53703. // handle this push it back on the queue so if it is a pages node it
  53704. // will be descended into.
  53705. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  53706. currentPageIndex = pageIndex;
  53707. continue;
  53708. } else {
  53709. for (var last = kids.length - 1; last >= 0; last--) {
  53710. nodesToVisit.push(kids[last]);
  53711. }
  53712. }
  53713. }
  53714. capability.reject('Page index ' + pageIndex + ' not found.');
  53715. }
  53716. next();
  53717. return capability.promise;
  53718. },
  53719. getPageIndex: function Catalog_getPageIndex(pageRef) {
  53720. // The page tree nodes have the count of all the leaves below them. To get
  53721. // how many pages are before we just have to walk up the tree and keep
  53722. // adding the count of siblings to the left of the node.
  53723. var xref = this.xref;
  53724. function pagesBeforeRef(kidRef) {
  53725. var total = 0;
  53726. var parentRef;
  53727. return xref.fetchAsync(kidRef).then(function (node) {
  53728. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  53729. throw new Error('The reference does not point to a /Page Dict.');
  53730. }
  53731. if (!node) {
  53732. return null;
  53733. }
  53734. assert(isDict(node), 'node must be a Dict.');
  53735. parentRef = node.getRaw('Parent');
  53736. return node.getAsync('Parent');
  53737. }).then(function (parent) {
  53738. if (!parent) {
  53739. return null;
  53740. }
  53741. assert(isDict(parent), 'parent must be a Dict.');
  53742. return parent.getAsync('Kids');
  53743. }).then(function (kids) {
  53744. if (!kids) {
  53745. return null;
  53746. }
  53747. var kidPromises = [];
  53748. var found = false;
  53749. for (var i = 0; i < kids.length; i++) {
  53750. var kid = kids[i];
  53751. assert(isRef(kid), 'kid must be a Ref.');
  53752. if (kid.num === kidRef.num) {
  53753. found = true;
  53754. break;
  53755. }
  53756. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  53757. if (kid.has('Count')) {
  53758. var count = kid.get('Count');
  53759. total += count;
  53760. } else {
  53761. // page leaf node
  53762. total++;
  53763. }
  53764. }));
  53765. }
  53766. if (!found) {
  53767. error('kid ref not found in parents kids');
  53768. }
  53769. return Promise.all(kidPromises).then(function () {
  53770. return [
  53771. total,
  53772. parentRef
  53773. ];
  53774. });
  53775. });
  53776. }
  53777. var total = 0;
  53778. function next(ref) {
  53779. return pagesBeforeRef(ref).then(function (args) {
  53780. if (!args) {
  53781. return total;
  53782. }
  53783. var count = args[0];
  53784. var parentRef = args[1];
  53785. total += count;
  53786. return next(parentRef);
  53787. });
  53788. }
  53789. return next(pageRef);
  53790. }
  53791. };
  53792. /**
  53793. * Helper function used to parse the contents of destination dictionaries.
  53794. * @param {Dict} destDict - The dictionary containing the destination.
  53795. * @param {Object} resultObj - The object where the parsed destination
  53796. * properties will be placed.
  53797. * @param {string} docBaseUrl - (optional) The document base URL that is used
  53798. * when attempting to recover valid absolute URLs from relative ones.
  53799. */
  53800. Catalog.parseDestDictionary = function Catalog_parseDestDictionary(params) {
  53801. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  53802. function addDefaultProtocolToUrl(url) {
  53803. if (url.indexOf('www.') === 0) {
  53804. return 'http://' + url;
  53805. }
  53806. return url;
  53807. }
  53808. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  53809. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  53810. function tryConvertUrlEncoding(url) {
  53811. try {
  53812. return stringToUTF8String(url);
  53813. } catch (e) {
  53814. return url;
  53815. }
  53816. }
  53817. var destDict = params.destDict;
  53818. if (!isDict(destDict)) {
  53819. warn('Catalog_parseDestDictionary: "destDict" must be a dictionary.');
  53820. return;
  53821. }
  53822. var resultObj = params.resultObj;
  53823. if (typeof resultObj !== 'object') {
  53824. warn('Catalog_parseDestDictionary: "resultObj" must be an object.');
  53825. return;
  53826. }
  53827. var docBaseUrl = params.docBaseUrl || null;
  53828. var action = destDict.get('A'), url, dest;
  53829. if (isDict(action)) {
  53830. var linkType = action.get('S').name;
  53831. switch (linkType) {
  53832. case 'URI':
  53833. url = action.get('URI');
  53834. if (isName(url)) {
  53835. // Some bad PDFs do not put parentheses around relative URLs.
  53836. url = '/' + url.name;
  53837. } else if (isString(url)) {
  53838. url = addDefaultProtocolToUrl(url);
  53839. }
  53840. // TODO: pdf spec mentions urls can be relative to a Base
  53841. // entry in the dictionary.
  53842. break;
  53843. case 'GoTo':
  53844. dest = action.get('D');
  53845. break;
  53846. case 'GoToR':
  53847. var urlDict = action.get('F');
  53848. if (isDict(urlDict)) {
  53849. // We assume that we found a FileSpec dictionary
  53850. // and fetch the URL without checking any further.
  53851. url = urlDict.get('F') || null;
  53852. } else if (isString(urlDict)) {
  53853. url = urlDict;
  53854. }
  53855. // NOTE: the destination is relative to the *remote* document.
  53856. var remoteDest = action.get('D');
  53857. if (remoteDest) {
  53858. if (isName(remoteDest)) {
  53859. remoteDest = remoteDest.name;
  53860. }
  53861. if (isString(url)) {
  53862. var baseUrl = url.split('#')[0];
  53863. if (isString(remoteDest)) {
  53864. // In practice, a named destination may contain only a number.
  53865. // If that happens, use the '#nameddest=' form to avoid the link
  53866. // redirecting to a page, instead of the correct destination.
  53867. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  53868. } else if (isArray(remoteDest)) {
  53869. url = baseUrl + '#' + JSON.stringify(remoteDest);
  53870. }
  53871. }
  53872. }
  53873. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  53874. var newWindow = action.get('NewWindow');
  53875. if (isBool(newWindow)) {
  53876. resultObj.newWindow = newWindow;
  53877. }
  53878. break;
  53879. case 'Named':
  53880. var namedAction = action.get('N');
  53881. if (isName(namedAction)) {
  53882. resultObj.action = namedAction.name;
  53883. }
  53884. break;
  53885. default:
  53886. warn('Catalog_parseDestDictionary: Unrecognized link type "' + linkType + '".');
  53887. break;
  53888. }
  53889. } else if (destDict.has('Dest')) {
  53890. // Simple destination link.
  53891. dest = destDict.get('Dest');
  53892. }
  53893. if (isString(url)) {
  53894. url = tryConvertUrlEncoding(url);
  53895. var absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl);
  53896. if (absoluteUrl) {
  53897. resultObj.url = absoluteUrl.href;
  53898. }
  53899. resultObj.unsafeUrl = url;
  53900. }
  53901. if (dest) {
  53902. if (isName(dest)) {
  53903. dest = dest.name;
  53904. }
  53905. if (isString(dest) || isArray(dest)) {
  53906. resultObj.dest = dest;
  53907. }
  53908. }
  53909. };
  53910. return Catalog;
  53911. }();
  53912. var XRef = function XRefClosure() {
  53913. function XRef(stream, password) {
  53914. this.stream = stream;
  53915. this.entries = [];
  53916. this.xrefstms = Object.create(null);
  53917. // prepare the XRef cache
  53918. this.cache = [];
  53919. this.password = password;
  53920. this.stats = {
  53921. streamTypes: [],
  53922. fontTypes: []
  53923. };
  53924. }
  53925. XRef.prototype = {
  53926. setStartXRef: function XRef_setStartXRef(startXRef) {
  53927. // Store the starting positions of xref tables as we process them
  53928. // so we can recover from missing data errors
  53929. this.startXRefQueue = [startXRef];
  53930. },
  53931. parse: function XRef_parse(recoveryMode) {
  53932. var trailerDict;
  53933. if (!recoveryMode) {
  53934. trailerDict = this.readXRef();
  53935. } else {
  53936. warn('Indexing all PDF objects');
  53937. trailerDict = this.indexObjects();
  53938. }
  53939. trailerDict.assignXref(this);
  53940. this.trailer = trailerDict;
  53941. var encrypt = trailerDict.get('Encrypt');
  53942. if (encrypt) {
  53943. var ids = trailerDict.get('ID');
  53944. var fileId = ids && ids.length ? ids[0] : '';
  53945. // The 'Encrypt' dictionary itself should not be encrypted, and by
  53946. // setting `suppressEncryption` we can prevent an infinite loop inside
  53947. // of `XRef_fetchUncompressed` if the dictionary contains indirect
  53948. // objects (fixes issue7665.pdf).
  53949. encrypt.suppressEncryption = true;
  53950. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  53951. }
  53952. // get the root dictionary (catalog) object
  53953. if (!(this.root = trailerDict.get('Root'))) {
  53954. error('Invalid root reference');
  53955. }
  53956. },
  53957. processXRefTable: function XRef_processXRefTable(parser) {
  53958. if (!('tableState' in this)) {
  53959. // Stores state of the table as we process it so we can resume
  53960. // from middle of table in case of missing data error
  53961. this.tableState = {
  53962. entryNum: 0,
  53963. streamPos: parser.lexer.stream.pos,
  53964. parserBuf1: parser.buf1,
  53965. parserBuf2: parser.buf2
  53966. };
  53967. }
  53968. var obj = this.readXRefTable(parser);
  53969. // Sanity check
  53970. if (!isCmd(obj, 'trailer')) {
  53971. error('Invalid XRef table: could not find trailer dictionary');
  53972. }
  53973. // Read trailer dictionary, e.g.
  53974. // trailer
  53975. // << /Size 22
  53976. // /Root 20R
  53977. // /Info 10R
  53978. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  53979. // >>
  53980. // The parser goes through the entire stream << ... >> and provides
  53981. // a getter interface for the key-value table
  53982. var dict = parser.getObj();
  53983. // The pdflib PDF generator can generate a nested trailer dictionary
  53984. if (!isDict(dict) && dict.dict) {
  53985. dict = dict.dict;
  53986. }
  53987. if (!isDict(dict)) {
  53988. error('Invalid XRef table: could not parse trailer dictionary');
  53989. }
  53990. delete this.tableState;
  53991. return dict;
  53992. },
  53993. readXRefTable: function XRef_readXRefTable(parser) {
  53994. // Example of cross-reference table:
  53995. // xref
  53996. // 0 1 <-- subsection header (first obj #, obj count)
  53997. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  53998. // 23 2 <-- subsection header ... and so on ...
  53999. // 0000025518 00002 n
  54000. // 0000025635 00000 n
  54001. // trailer
  54002. // ...
  54003. var stream = parser.lexer.stream;
  54004. var tableState = this.tableState;
  54005. stream.pos = tableState.streamPos;
  54006. parser.buf1 = tableState.parserBuf1;
  54007. parser.buf2 = tableState.parserBuf2;
  54008. // Outer loop is over subsection headers
  54009. var obj;
  54010. while (true) {
  54011. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  54012. if (isCmd(obj = parser.getObj(), 'trailer')) {
  54013. break;
  54014. }
  54015. tableState.firstEntryNum = obj;
  54016. tableState.entryCount = parser.getObj();
  54017. }
  54018. var first = tableState.firstEntryNum;
  54019. var count = tableState.entryCount;
  54020. if (!isInt(first) || !isInt(count)) {
  54021. error('Invalid XRef table: wrong types in subsection header');
  54022. }
  54023. // Inner loop is over objects themselves
  54024. for (var i = tableState.entryNum; i < count; i++) {
  54025. tableState.streamPos = stream.pos;
  54026. tableState.entryNum = i;
  54027. tableState.parserBuf1 = parser.buf1;
  54028. tableState.parserBuf2 = parser.buf2;
  54029. var entry = {};
  54030. entry.offset = parser.getObj();
  54031. entry.gen = parser.getObj();
  54032. var type = parser.getObj();
  54033. if (isCmd(type, 'f')) {
  54034. entry.free = true;
  54035. } else if (isCmd(type, 'n')) {
  54036. entry.uncompressed = true;
  54037. }
  54038. // Validate entry obj
  54039. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  54040. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  54041. }
  54042. // The first xref table entry, i.e. obj 0, should be free. Attempting
  54043. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  54044. if (i === 0 && entry.free && first === 1) {
  54045. first = 0;
  54046. }
  54047. if (!this.entries[i + first]) {
  54048. this.entries[i + first] = entry;
  54049. }
  54050. }
  54051. tableState.entryNum = 0;
  54052. tableState.streamPos = stream.pos;
  54053. tableState.parserBuf1 = parser.buf1;
  54054. tableState.parserBuf2 = parser.buf2;
  54055. delete tableState.firstEntryNum;
  54056. delete tableState.entryCount;
  54057. }
  54058. // Sanity check: as per spec, first object must be free
  54059. if (this.entries[0] && !this.entries[0].free) {
  54060. error('Invalid XRef table: unexpected first object');
  54061. }
  54062. return obj;
  54063. },
  54064. processXRefStream: function XRef_processXRefStream(stream) {
  54065. if (!('streamState' in this)) {
  54066. // Stores state of the stream as we process it so we can resume
  54067. // from middle of stream in case of missing data error
  54068. var streamParameters = stream.dict;
  54069. var byteWidths = streamParameters.get('W');
  54070. var range = streamParameters.get('Index');
  54071. if (!range) {
  54072. range = [
  54073. 0,
  54074. streamParameters.get('Size')
  54075. ];
  54076. }
  54077. this.streamState = {
  54078. entryRanges: range,
  54079. byteWidths: byteWidths,
  54080. entryNum: 0,
  54081. streamPos: stream.pos
  54082. };
  54083. }
  54084. this.readXRefStream(stream);
  54085. delete this.streamState;
  54086. return stream.dict;
  54087. },
  54088. readXRefStream: function XRef_readXRefStream(stream) {
  54089. var i, j;
  54090. var streamState = this.streamState;
  54091. stream.pos = streamState.streamPos;
  54092. var byteWidths = streamState.byteWidths;
  54093. var typeFieldWidth = byteWidths[0];
  54094. var offsetFieldWidth = byteWidths[1];
  54095. var generationFieldWidth = byteWidths[2];
  54096. var entryRanges = streamState.entryRanges;
  54097. while (entryRanges.length > 0) {
  54098. var first = entryRanges[0];
  54099. var n = entryRanges[1];
  54100. if (!isInt(first) || !isInt(n)) {
  54101. error('Invalid XRef range fields: ' + first + ', ' + n);
  54102. }
  54103. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  54104. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  54105. }
  54106. for (i = streamState.entryNum; i < n; ++i) {
  54107. streamState.entryNum = i;
  54108. streamState.streamPos = stream.pos;
  54109. var type = 0, offset = 0, generation = 0;
  54110. for (j = 0; j < typeFieldWidth; ++j) {
  54111. type = type << 8 | stream.getByte();
  54112. }
  54113. // if type field is absent, its default value is 1
  54114. if (typeFieldWidth === 0) {
  54115. type = 1;
  54116. }
  54117. for (j = 0; j < offsetFieldWidth; ++j) {
  54118. offset = offset << 8 | stream.getByte();
  54119. }
  54120. for (j = 0; j < generationFieldWidth; ++j) {
  54121. generation = generation << 8 | stream.getByte();
  54122. }
  54123. var entry = {};
  54124. entry.offset = offset;
  54125. entry.gen = generation;
  54126. switch (type) {
  54127. case 0:
  54128. entry.free = true;
  54129. break;
  54130. case 1:
  54131. entry.uncompressed = true;
  54132. break;
  54133. case 2:
  54134. break;
  54135. default:
  54136. error('Invalid XRef entry type: ' + type);
  54137. }
  54138. if (!this.entries[first + i]) {
  54139. this.entries[first + i] = entry;
  54140. }
  54141. }
  54142. streamState.entryNum = 0;
  54143. streamState.streamPos = stream.pos;
  54144. entryRanges.splice(0, 2);
  54145. }
  54146. },
  54147. indexObjects: function XRef_indexObjects() {
  54148. // Simple scan through the PDF content to find objects,
  54149. // trailers and XRef streams.
  54150. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  54151. var PERCENT = 0x25, LT = 0x3C;
  54152. function readToken(data, offset) {
  54153. var token = '', ch = data[offset];
  54154. while (ch !== LF && ch !== CR && ch !== LT) {
  54155. if (++offset >= data.length) {
  54156. break;
  54157. }
  54158. token += String.fromCharCode(ch);
  54159. ch = data[offset];
  54160. }
  54161. return token;
  54162. }
  54163. function skipUntil(data, offset, what) {
  54164. var length = what.length, dataLength = data.length;
  54165. var skipped = 0;
  54166. // finding byte sequence
  54167. while (offset < dataLength) {
  54168. var i = 0;
  54169. while (i < length && data[offset + i] === what[i]) {
  54170. ++i;
  54171. }
  54172. if (i >= length) {
  54173. break;
  54174. }
  54175. // sequence found
  54176. offset++;
  54177. skipped++;
  54178. }
  54179. return skipped;
  54180. }
  54181. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  54182. var trailerBytes = new Uint8Array([
  54183. 116,
  54184. 114,
  54185. 97,
  54186. 105,
  54187. 108,
  54188. 101,
  54189. 114
  54190. ]);
  54191. var startxrefBytes = new Uint8Array([
  54192. 115,
  54193. 116,
  54194. 97,
  54195. 114,
  54196. 116,
  54197. 120,
  54198. 114,
  54199. 101,
  54200. 102
  54201. ]);
  54202. var endobjBytes = new Uint8Array([
  54203. 101,
  54204. 110,
  54205. 100,
  54206. 111,
  54207. 98,
  54208. 106
  54209. ]);
  54210. var xrefBytes = new Uint8Array([
  54211. 47,
  54212. 88,
  54213. 82,
  54214. 101,
  54215. 102
  54216. ]);
  54217. // Clear out any existing entries, since they may be bogus.
  54218. this.entries.length = 0;
  54219. var stream = this.stream;
  54220. stream.pos = 0;
  54221. var buffer = stream.getBytes();
  54222. var position = stream.start, length = buffer.length;
  54223. var trailers = [], xrefStms = [];
  54224. while (position < length) {
  54225. var ch = buffer[position];
  54226. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  54227. ++position;
  54228. continue;
  54229. }
  54230. if (ch === PERCENT) {
  54231. // %-comment
  54232. do {
  54233. ++position;
  54234. if (position >= length) {
  54235. break;
  54236. }
  54237. ch = buffer[position];
  54238. } while (ch !== LF && ch !== CR);
  54239. continue;
  54240. }
  54241. var token = readToken(buffer, position);
  54242. var m;
  54243. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  54244. position += skipUntil(buffer, position, trailerBytes);
  54245. trailers.push(position);
  54246. position += skipUntil(buffer, position, startxrefBytes);
  54247. } else if (m = objRegExp.exec(token)) {
  54248. if (typeof this.entries[m[1]] === 'undefined') {
  54249. this.entries[m[1]] = {
  54250. offset: position - stream.start,
  54251. gen: m[2] | 0,
  54252. uncompressed: true
  54253. };
  54254. }
  54255. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  54256. var content = buffer.subarray(position, position + contentLength);
  54257. // checking XRef stream suspect
  54258. // (it shall have '/XRef' and next char is not a letter)
  54259. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  54260. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  54261. xrefStms.push(position - stream.start);
  54262. this.xrefstms[position - stream.start] = 1;
  54263. }
  54264. // Avoid recursion
  54265. position += contentLength;
  54266. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  54267. trailers.push(position);
  54268. position += skipUntil(buffer, position, startxrefBytes);
  54269. } else {
  54270. position += token.length + 1;
  54271. }
  54272. }
  54273. // reading XRef streams
  54274. var i, ii;
  54275. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  54276. this.startXRefQueue.push(xrefStms[i]);
  54277. this.readXRef(/* recoveryMode */
  54278. true);
  54279. }
  54280. // finding main trailer
  54281. var dict;
  54282. for (i = 0, ii = trailers.length; i < ii; ++i) {
  54283. stream.pos = trailers[i];
  54284. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  54285. true, /* xref = */
  54286. this, /* recoveryMode = */
  54287. true);
  54288. var obj = parser.getObj();
  54289. if (!isCmd(obj, 'trailer')) {
  54290. continue;
  54291. }
  54292. // read the trailer dictionary
  54293. dict = parser.getObj();
  54294. if (!isDict(dict)) {
  54295. continue;
  54296. }
  54297. // taking the first one with 'ID'
  54298. if (dict.has('ID')) {
  54299. return dict;
  54300. }
  54301. }
  54302. // no tailer with 'ID', taking last one (if exists)
  54303. if (dict) {
  54304. return dict;
  54305. }
  54306. // nothing helps
  54307. // calling error() would reject worker with an UnknownErrorException.
  54308. throw new InvalidPDFException('Invalid PDF structure');
  54309. },
  54310. readXRef: function XRef_readXRef(recoveryMode) {
  54311. var stream = this.stream;
  54312. try {
  54313. while (this.startXRefQueue.length) {
  54314. var startXRef = this.startXRefQueue[0];
  54315. stream.pos = startXRef + stream.start;
  54316. var parser = new Parser(new Lexer(stream), true, this);
  54317. var obj = parser.getObj();
  54318. var dict;
  54319. // Get dictionary
  54320. if (isCmd(obj, 'xref')) {
  54321. // Parse end-of-file XRef
  54322. dict = this.processXRefTable(parser);
  54323. if (!this.topDict) {
  54324. this.topDict = dict;
  54325. }
  54326. // Recursively get other XRefs 'XRefStm', if any
  54327. obj = dict.get('XRefStm');
  54328. if (isInt(obj)) {
  54329. var pos = obj;
  54330. // ignore previously loaded xref streams
  54331. // (possible infinite recursion)
  54332. if (!(pos in this.xrefstms)) {
  54333. this.xrefstms[pos] = 1;
  54334. this.startXRefQueue.push(pos);
  54335. }
  54336. }
  54337. } else if (isInt(obj)) {
  54338. // Parse in-stream XRef
  54339. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  54340. error('Invalid XRef stream');
  54341. }
  54342. dict = this.processXRefStream(obj);
  54343. if (!this.topDict) {
  54344. this.topDict = dict;
  54345. }
  54346. if (!dict) {
  54347. error('Failed to read XRef stream');
  54348. }
  54349. } else {
  54350. error('Invalid XRef stream header');
  54351. }
  54352. // Recursively get previous dictionary, if any
  54353. obj = dict.get('Prev');
  54354. if (isInt(obj)) {
  54355. this.startXRefQueue.push(obj);
  54356. } else if (isRef(obj)) {
  54357. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  54358. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  54359. this.startXRefQueue.push(obj.num);
  54360. }
  54361. this.startXRefQueue.shift();
  54362. }
  54363. return this.topDict;
  54364. } catch (e) {
  54365. if (e instanceof MissingDataException) {
  54366. throw e;
  54367. }
  54368. info('(while reading XRef): ' + e);
  54369. }
  54370. if (recoveryMode) {
  54371. return;
  54372. }
  54373. throw new XRefParseException();
  54374. },
  54375. getEntry: function XRef_getEntry(i) {
  54376. var xrefEntry = this.entries[i];
  54377. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  54378. return xrefEntry;
  54379. }
  54380. return null;
  54381. },
  54382. fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
  54383. if (!isRef(obj)) {
  54384. return obj;
  54385. }
  54386. return this.fetch(obj, suppressEncryption);
  54387. },
  54388. fetch: function XRef_fetch(ref, suppressEncryption) {
  54389. assert(isRef(ref), 'ref object is not a reference');
  54390. var num = ref.num;
  54391. if (num in this.cache) {
  54392. var cacheEntry = this.cache[num];
  54393. return cacheEntry;
  54394. }
  54395. var xrefEntry = this.getEntry(num);
  54396. // the referenced entry can be free
  54397. if (xrefEntry === null) {
  54398. return this.cache[num] = null;
  54399. }
  54400. if (xrefEntry.uncompressed) {
  54401. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  54402. } else {
  54403. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  54404. }
  54405. if (isDict(xrefEntry)) {
  54406. xrefEntry.objId = ref.toString();
  54407. } else if (isStream(xrefEntry)) {
  54408. xrefEntry.dict.objId = ref.toString();
  54409. }
  54410. return xrefEntry;
  54411. },
  54412. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  54413. var gen = ref.gen;
  54414. var num = ref.num;
  54415. if (xrefEntry.gen !== gen) {
  54416. error('inconsistent generation in XRef');
  54417. }
  54418. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  54419. var parser = new Parser(new Lexer(stream), true, this);
  54420. var obj1 = parser.getObj();
  54421. var obj2 = parser.getObj();
  54422. var obj3 = parser.getObj();
  54423. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  54424. error('bad XRef entry');
  54425. }
  54426. if (!isCmd(obj3, 'obj')) {
  54427. // some bad PDFs use "obj1234" and really mean 1234
  54428. if (obj3.cmd.indexOf('obj') === 0) {
  54429. num = parseInt(obj3.cmd.substring(3), 10);
  54430. if (!isNaN(num)) {
  54431. return num;
  54432. }
  54433. }
  54434. error('bad XRef entry');
  54435. }
  54436. if (this.encrypt && !suppressEncryption) {
  54437. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  54438. } else {
  54439. xrefEntry = parser.getObj();
  54440. }
  54441. if (!isStream(xrefEntry)) {
  54442. this.cache[num] = xrefEntry;
  54443. }
  54444. return xrefEntry;
  54445. },
  54446. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  54447. var tableOffset = xrefEntry.offset;
  54448. var stream = this.fetch(new Ref(tableOffset, 0));
  54449. if (!isStream(stream)) {
  54450. error('bad ObjStm stream');
  54451. }
  54452. var first = stream.dict.get('First');
  54453. var n = stream.dict.get('N');
  54454. if (!isInt(first) || !isInt(n)) {
  54455. error('invalid first and n parameters for ObjStm stream');
  54456. }
  54457. var parser = new Parser(new Lexer(stream), false, this);
  54458. parser.allowStreams = true;
  54459. var i, entries = [], num, nums = [];
  54460. // read the object numbers to populate cache
  54461. for (i = 0; i < n; ++i) {
  54462. num = parser.getObj();
  54463. if (!isInt(num)) {
  54464. error('invalid object number in the ObjStm stream: ' + num);
  54465. }
  54466. nums.push(num);
  54467. var offset = parser.getObj();
  54468. if (!isInt(offset)) {
  54469. error('invalid object offset in the ObjStm stream: ' + offset);
  54470. }
  54471. }
  54472. // read stream objects for cache
  54473. for (i = 0; i < n; ++i) {
  54474. entries.push(parser.getObj());
  54475. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  54476. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  54477. if (isCmd(parser.buf1, 'endobj')) {
  54478. parser.shift();
  54479. }
  54480. num = nums[i];
  54481. var entry = this.entries[num];
  54482. if (entry && entry.offset === tableOffset && entry.gen === i) {
  54483. this.cache[num] = entries[i];
  54484. }
  54485. }
  54486. xrefEntry = entries[xrefEntry.gen];
  54487. if (xrefEntry === undefined) {
  54488. error('bad XRef entry for compressed object');
  54489. }
  54490. return xrefEntry;
  54491. },
  54492. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj, suppressEncryption) {
  54493. if (!isRef(obj)) {
  54494. return Promise.resolve(obj);
  54495. }
  54496. return this.fetchAsync(obj, suppressEncryption);
  54497. },
  54498. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  54499. var streamManager = this.stream.manager;
  54500. var xref = this;
  54501. return new Promise(function tryFetch(resolve, reject) {
  54502. try {
  54503. resolve(xref.fetch(ref, suppressEncryption));
  54504. } catch (e) {
  54505. if (e instanceof MissingDataException) {
  54506. streamManager.requestRange(e.begin, e.end).then(function () {
  54507. tryFetch(resolve, reject);
  54508. }, reject);
  54509. return;
  54510. }
  54511. reject(e);
  54512. }
  54513. });
  54514. },
  54515. getCatalogObj: function XRef_getCatalogObj() {
  54516. return this.root;
  54517. }
  54518. };
  54519. return XRef;
  54520. }();
  54521. /**
  54522. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  54523. * see the specification (7.9.6 and 7.9.7) for additional details.
  54524. * TODO: implement all the Dict functions and make this more efficient.
  54525. */
  54526. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  54527. function NameOrNumberTree(root, xref) {
  54528. throw new Error('Cannot initialize NameOrNumberTree.');
  54529. }
  54530. NameOrNumberTree.prototype = {
  54531. getAll: function NameOrNumberTree_getAll() {
  54532. var dict = Object.create(null);
  54533. if (!this.root) {
  54534. return dict;
  54535. }
  54536. var xref = this.xref;
  54537. // Reading Name/Number tree.
  54538. var processed = new RefSet();
  54539. processed.put(this.root);
  54540. var queue = [this.root];
  54541. while (queue.length > 0) {
  54542. var i, n;
  54543. var obj = xref.fetchIfRef(queue.shift());
  54544. if (!isDict(obj)) {
  54545. continue;
  54546. }
  54547. if (obj.has('Kids')) {
  54548. var kids = obj.get('Kids');
  54549. for (i = 0, n = kids.length; i < n; i++) {
  54550. var kid = kids[i];
  54551. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  54552. queue.push(kid);
  54553. processed.put(kid);
  54554. }
  54555. continue;
  54556. }
  54557. var entries = obj.get(this._type);
  54558. if (isArray(entries)) {
  54559. for (i = 0, n = entries.length; i < n; i += 2) {
  54560. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  54561. }
  54562. }
  54563. }
  54564. return dict;
  54565. },
  54566. get: function NameOrNumberTree_get(key) {
  54567. if (!this.root) {
  54568. return null;
  54569. }
  54570. var xref = this.xref;
  54571. var kidsOrEntries = xref.fetchIfRef(this.root);
  54572. var loopCount = 0;
  54573. var MAX_LEVELS = 10;
  54574. var l, r, m;
  54575. // Perform a binary search to quickly find the entry that
  54576. // contains the key we are looking for.
  54577. while (kidsOrEntries.has('Kids')) {
  54578. if (++loopCount > MAX_LEVELS) {
  54579. warn('Search depth limit reached for "' + this._type + '" tree.');
  54580. return null;
  54581. }
  54582. var kids = kidsOrEntries.get('Kids');
  54583. if (!isArray(kids)) {
  54584. return null;
  54585. }
  54586. l = 0;
  54587. r = kids.length - 1;
  54588. while (l <= r) {
  54589. m = l + r >> 1;
  54590. var kid = xref.fetchIfRef(kids[m]);
  54591. var limits = kid.get('Limits');
  54592. if (key < xref.fetchIfRef(limits[0])) {
  54593. r = m - 1;
  54594. } else if (key > xref.fetchIfRef(limits[1])) {
  54595. l = m + 1;
  54596. } else {
  54597. kidsOrEntries = xref.fetchIfRef(kids[m]);
  54598. break;
  54599. }
  54600. }
  54601. if (l > r) {
  54602. return null;
  54603. }
  54604. }
  54605. // If we get here, then we have found the right entry. Now go through the
  54606. // entries in the dictionary until we find the key we're looking for.
  54607. var entries = kidsOrEntries.get(this._type);
  54608. if (isArray(entries)) {
  54609. // Perform a binary search to reduce the lookup time.
  54610. l = 0;
  54611. r = entries.length - 2;
  54612. while (l <= r) {
  54613. // Check only even indices (0, 2, 4, ...) because the
  54614. // odd indices contain the actual data.
  54615. m = l + r & ~1;
  54616. var currentKey = xref.fetchIfRef(entries[m]);
  54617. if (key < currentKey) {
  54618. r = m - 2;
  54619. } else if (key > currentKey) {
  54620. l = m + 2;
  54621. } else {
  54622. return xref.fetchIfRef(entries[m + 1]);
  54623. }
  54624. }
  54625. }
  54626. return null;
  54627. }
  54628. };
  54629. return NameOrNumberTree;
  54630. }();
  54631. var NameTree = function NameTreeClosure() {
  54632. function NameTree(root, xref) {
  54633. this.root = root;
  54634. this.xref = xref;
  54635. this._type = 'Names';
  54636. }
  54637. Util.inherit(NameTree, NameOrNumberTree, {});
  54638. return NameTree;
  54639. }();
  54640. var NumberTree = function NumberTreeClosure() {
  54641. function NumberTree(root, xref) {
  54642. this.root = root;
  54643. this.xref = xref;
  54644. this._type = 'Nums';
  54645. }
  54646. Util.inherit(NumberTree, NameOrNumberTree, {});
  54647. return NumberTree;
  54648. }();
  54649. /**
  54650. * "A PDF file can refer to the contents of another file by using a File
  54651. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  54652. * NOTE: Only embedded files are supported (as part of the attachments support)
  54653. * TODO: support the 'URL' file system (with caching if !/V), portable
  54654. * collections attributes and related files (/RF)
  54655. */
  54656. var FileSpec = function FileSpecClosure() {
  54657. function FileSpec(root, xref) {
  54658. if (!root || !isDict(root)) {
  54659. return;
  54660. }
  54661. this.xref = xref;
  54662. this.root = root;
  54663. if (root.has('FS')) {
  54664. this.fs = root.get('FS');
  54665. }
  54666. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  54667. if (root.has('RF')) {
  54668. warn('Related file specifications are not supported');
  54669. }
  54670. this.contentAvailable = true;
  54671. if (!root.has('EF')) {
  54672. this.contentAvailable = false;
  54673. warn('Non-embedded file specifications are not supported');
  54674. }
  54675. }
  54676. function pickPlatformItem(dict) {
  54677. // Look for the filename in this order:
  54678. // UF, F, Unix, Mac, DOS
  54679. if (dict.has('UF')) {
  54680. return dict.get('UF');
  54681. } else if (dict.has('F')) {
  54682. return dict.get('F');
  54683. } else if (dict.has('Unix')) {
  54684. return dict.get('Unix');
  54685. } else if (dict.has('Mac')) {
  54686. return dict.get('Mac');
  54687. } else if (dict.has('DOS')) {
  54688. return dict.get('DOS');
  54689. } else {
  54690. return null;
  54691. }
  54692. }
  54693. FileSpec.prototype = {
  54694. get filename() {
  54695. if (!this._filename && this.root) {
  54696. var filename = pickPlatformItem(this.root) || 'unnamed';
  54697. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  54698. }
  54699. return this._filename;
  54700. },
  54701. get content() {
  54702. if (!this.contentAvailable) {
  54703. return null;
  54704. }
  54705. if (!this.contentRef && this.root) {
  54706. this.contentRef = pickPlatformItem(this.root.get('EF'));
  54707. }
  54708. var content = null;
  54709. if (this.contentRef) {
  54710. var xref = this.xref;
  54711. var fileObj = xref.fetchIfRef(this.contentRef);
  54712. if (fileObj && isStream(fileObj)) {
  54713. content = fileObj.getBytes();
  54714. } else {
  54715. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  54716. }
  54717. } else {
  54718. warn('Embedded file specification does not have a content');
  54719. }
  54720. return content;
  54721. },
  54722. get serializable() {
  54723. return {
  54724. filename: this.filename,
  54725. content: this.content
  54726. };
  54727. }
  54728. };
  54729. return FileSpec;
  54730. }();
  54731. /**
  54732. * A helper for loading missing data in object graphs. It traverses the graph
  54733. * depth first and queues up any objects that have missing data. Once it has
  54734. * has traversed as many objects that are available it attempts to bundle the
  54735. * missing data requests and then resume from the nodes that weren't ready.
  54736. *
  54737. * NOTE: It provides protection from circular references by keeping track of
  54738. * of loaded references. However, you must be careful not to load any graphs
  54739. * that have references to the catalog or other pages since that will cause the
  54740. * entire PDF document object graph to be traversed.
  54741. */
  54742. var ObjectLoader = function () {
  54743. function mayHaveChildren(value) {
  54744. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  54745. }
  54746. function addChildren(node, nodesToVisit) {
  54747. var value;
  54748. if (isDict(node) || isStream(node)) {
  54749. var map;
  54750. if (isDict(node)) {
  54751. map = node.map;
  54752. } else {
  54753. map = node.dict.map;
  54754. }
  54755. for (var key in map) {
  54756. value = map[key];
  54757. if (mayHaveChildren(value)) {
  54758. nodesToVisit.push(value);
  54759. }
  54760. }
  54761. } else if (isArray(node)) {
  54762. for (var i = 0, ii = node.length; i < ii; i++) {
  54763. value = node[i];
  54764. if (mayHaveChildren(value)) {
  54765. nodesToVisit.push(value);
  54766. }
  54767. }
  54768. }
  54769. }
  54770. function ObjectLoader(obj, keys, xref) {
  54771. this.obj = obj;
  54772. this.keys = keys;
  54773. this.xref = xref;
  54774. this.refSet = null;
  54775. this.capability = null;
  54776. }
  54777. ObjectLoader.prototype = {
  54778. load: function ObjectLoader_load() {
  54779. var keys = this.keys;
  54780. this.capability = createPromiseCapability();
  54781. // Don't walk the graph if all the data is already loaded.
  54782. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  54783. this.capability.resolve();
  54784. return this.capability.promise;
  54785. }
  54786. this.refSet = new RefSet();
  54787. // Setup the initial nodes to visit.
  54788. var nodesToVisit = [];
  54789. for (var i = 0; i < keys.length; i++) {
  54790. nodesToVisit.push(this.obj[keys[i]]);
  54791. }
  54792. this._walk(nodesToVisit);
  54793. return this.capability.promise;
  54794. },
  54795. _walk: function ObjectLoader_walk(nodesToVisit) {
  54796. var nodesToRevisit = [];
  54797. var pendingRequests = [];
  54798. // DFS walk of the object graph.
  54799. while (nodesToVisit.length) {
  54800. var currentNode = nodesToVisit.pop();
  54801. // Only references or chunked streams can cause missing data exceptions.
  54802. if (isRef(currentNode)) {
  54803. // Skip nodes that have already been visited.
  54804. if (this.refSet.has(currentNode)) {
  54805. continue;
  54806. }
  54807. try {
  54808. var ref = currentNode;
  54809. this.refSet.put(ref);
  54810. currentNode = this.xref.fetch(currentNode);
  54811. } catch (e) {
  54812. if (!(e instanceof MissingDataException)) {
  54813. throw e;
  54814. }
  54815. nodesToRevisit.push(currentNode);
  54816. pendingRequests.push({
  54817. begin: e.begin,
  54818. end: e.end
  54819. });
  54820. }
  54821. }
  54822. if (currentNode && currentNode.getBaseStreams) {
  54823. var baseStreams = currentNode.getBaseStreams();
  54824. var foundMissingData = false;
  54825. for (var i = 0; i < baseStreams.length; i++) {
  54826. var stream = baseStreams[i];
  54827. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  54828. foundMissingData = true;
  54829. pendingRequests.push({
  54830. begin: stream.start,
  54831. end: stream.end
  54832. });
  54833. }
  54834. }
  54835. if (foundMissingData) {
  54836. nodesToRevisit.push(currentNode);
  54837. }
  54838. }
  54839. addChildren(currentNode, nodesToVisit);
  54840. }
  54841. if (pendingRequests.length) {
  54842. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  54843. nodesToVisit = nodesToRevisit;
  54844. for (var i = 0; i < nodesToRevisit.length; i++) {
  54845. var node = nodesToRevisit[i];
  54846. // Remove any reference nodes from the currrent refset so they
  54847. // aren't skipped when we revist them.
  54848. if (isRef(node)) {
  54849. this.refSet.remove(node);
  54850. }
  54851. }
  54852. this._walk(nodesToVisit);
  54853. }.bind(this), this.capability.reject);
  54854. return;
  54855. }
  54856. // Everything is loaded.
  54857. this.refSet = null;
  54858. this.capability.resolve();
  54859. }
  54860. };
  54861. return ObjectLoader;
  54862. }();
  54863. exports.Catalog = Catalog;
  54864. exports.ObjectLoader = ObjectLoader;
  54865. exports.XRef = XRef;
  54866. exports.FileSpec = FileSpec;
  54867. }));
  54868. (function (root, factory) {
  54869. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  54870. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  54871. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  54872. var MissingDataException = sharedUtil.MissingDataException;
  54873. var Util = sharedUtil.Util;
  54874. var assert = sharedUtil.assert;
  54875. var error = sharedUtil.error;
  54876. var info = sharedUtil.info;
  54877. var warn = sharedUtil.warn;
  54878. var isStream = corePrimitives.isStream;
  54879. var PDFFunction = coreFunction.PDFFunction;
  54880. var ColorSpace = coreColorSpace.ColorSpace;
  54881. var ShadingType = {
  54882. FUNCTION_BASED: 1,
  54883. AXIAL: 2,
  54884. RADIAL: 3,
  54885. FREE_FORM_MESH: 4,
  54886. LATTICE_FORM_MESH: 5,
  54887. COONS_PATCH_MESH: 6,
  54888. TENSOR_PATCH_MESH: 7
  54889. };
  54890. var Pattern = function PatternClosure() {
  54891. // Constructor should define this.getPattern
  54892. function Pattern() {
  54893. error('should not call Pattern constructor');
  54894. }
  54895. Pattern.prototype = {
  54896. // Input: current Canvas context
  54897. // Output: the appropriate fillStyle or strokeStyle
  54898. getPattern: function Pattern_getPattern(ctx) {
  54899. error('Should not call Pattern.getStyle: ' + ctx);
  54900. }
  54901. };
  54902. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  54903. var dict = isStream(shading) ? shading.dict : shading;
  54904. var type = dict.get('ShadingType');
  54905. try {
  54906. switch (type) {
  54907. case ShadingType.AXIAL:
  54908. case ShadingType.RADIAL:
  54909. // Both radial and axial shadings are handled by RadialAxial shading.
  54910. return new Shadings.RadialAxial(dict, matrix, xref, res);
  54911. case ShadingType.FREE_FORM_MESH:
  54912. case ShadingType.LATTICE_FORM_MESH:
  54913. case ShadingType.COONS_PATCH_MESH:
  54914. case ShadingType.TENSOR_PATCH_MESH:
  54915. return new Shadings.Mesh(shading, matrix, xref, res);
  54916. default:
  54917. throw new Error('Unsupported ShadingType: ' + type);
  54918. }
  54919. } catch (ex) {
  54920. if (ex instanceof MissingDataException) {
  54921. throw ex;
  54922. }
  54923. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  54924. warn(ex);
  54925. return new Shadings.Dummy();
  54926. }
  54927. };
  54928. return Pattern;
  54929. }();
  54930. var Shadings = {};
  54931. // A small number to offset the first/last color stops so we can insert ones to
  54932. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  54933. Shadings.SMALL_NUMBER = 1e-6;
  54934. // Radial and axial shading have very similar implementations
  54935. // If needed, the implementations can be broken into two classes
  54936. Shadings.RadialAxial = function RadialAxialClosure() {
  54937. function RadialAxial(dict, matrix, xref, res) {
  54938. this.matrix = matrix;
  54939. this.coordsArr = dict.getArray('Coords');
  54940. this.shadingType = dict.get('ShadingType');
  54941. this.type = 'Pattern';
  54942. var cs = dict.get('ColorSpace', 'CS');
  54943. cs = ColorSpace.parse(cs, xref, res);
  54944. this.cs = cs;
  54945. var t0 = 0.0, t1 = 1.0;
  54946. if (dict.has('Domain')) {
  54947. var domainArr = dict.getArray('Domain');
  54948. t0 = domainArr[0];
  54949. t1 = domainArr[1];
  54950. }
  54951. var extendStart = false, extendEnd = false;
  54952. if (dict.has('Extend')) {
  54953. var extendArr = dict.getArray('Extend');
  54954. extendStart = extendArr[0];
  54955. extendEnd = extendArr[1];
  54956. }
  54957. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  54958. // Radial gradient only currently works if either circle is fully within
  54959. // the other circle.
  54960. var x1 = this.coordsArr[0];
  54961. var y1 = this.coordsArr[1];
  54962. var r1 = this.coordsArr[2];
  54963. var x2 = this.coordsArr[3];
  54964. var y2 = this.coordsArr[4];
  54965. var r2 = this.coordsArr[5];
  54966. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  54967. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  54968. warn('Unsupported radial gradient.');
  54969. }
  54970. }
  54971. this.extendStart = extendStart;
  54972. this.extendEnd = extendEnd;
  54973. var fnObj = dict.get('Function');
  54974. var fn = PDFFunction.parseArray(xref, fnObj);
  54975. // 10 samples seems good enough for now, but probably won't work
  54976. // if there are sharp color changes. Ideally, we would implement
  54977. // the spec faithfully and add lossless optimizations.
  54978. var diff = t1 - t0;
  54979. var step = diff / 10;
  54980. var colorStops = this.colorStops = [];
  54981. // Protect against bad domains so we don't end up in an infinte loop below.
  54982. if (t0 >= t1 || step <= 0) {
  54983. // Acrobat doesn't seem to handle these cases so we'll ignore for
  54984. // now.
  54985. info('Bad shading domain.');
  54986. return;
  54987. }
  54988. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  54989. var rgbColor;
  54990. for (var i = t0; i <= t1; i += step) {
  54991. ratio[0] = i;
  54992. fn(ratio, 0, color, 0);
  54993. rgbColor = cs.getRgb(color, 0);
  54994. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  54995. colorStops.push([
  54996. (i - t0) / diff,
  54997. cssColor
  54998. ]);
  54999. }
  55000. var background = 'transparent';
  55001. if (dict.has('Background')) {
  55002. rgbColor = cs.getRgb(dict.get('Background'), 0);
  55003. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  55004. }
  55005. if (!extendStart) {
  55006. // Insert a color stop at the front and offset the first real color stop
  55007. // so it doesn't conflict with the one we insert.
  55008. colorStops.unshift([
  55009. 0,
  55010. background
  55011. ]);
  55012. colorStops[1][0] += Shadings.SMALL_NUMBER;
  55013. }
  55014. if (!extendEnd) {
  55015. // Same idea as above in extendStart but for the end.
  55016. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  55017. colorStops.push([
  55018. 1,
  55019. background
  55020. ]);
  55021. }
  55022. this.colorStops = colorStops;
  55023. }
  55024. RadialAxial.prototype = {
  55025. getIR: function RadialAxial_getIR() {
  55026. var coordsArr = this.coordsArr;
  55027. var shadingType = this.shadingType;
  55028. var type, p0, p1, r0, r1;
  55029. if (shadingType === ShadingType.AXIAL) {
  55030. p0 = [
  55031. coordsArr[0],
  55032. coordsArr[1]
  55033. ];
  55034. p1 = [
  55035. coordsArr[2],
  55036. coordsArr[3]
  55037. ];
  55038. r0 = null;
  55039. r1 = null;
  55040. type = 'axial';
  55041. } else if (shadingType === ShadingType.RADIAL) {
  55042. p0 = [
  55043. coordsArr[0],
  55044. coordsArr[1]
  55045. ];
  55046. p1 = [
  55047. coordsArr[3],
  55048. coordsArr[4]
  55049. ];
  55050. r0 = coordsArr[2];
  55051. r1 = coordsArr[5];
  55052. type = 'radial';
  55053. } else {
  55054. error('getPattern type unknown: ' + shadingType);
  55055. }
  55056. var matrix = this.matrix;
  55057. if (matrix) {
  55058. p0 = Util.applyTransform(p0, matrix);
  55059. p1 = Util.applyTransform(p1, matrix);
  55060. if (shadingType === ShadingType.RADIAL) {
  55061. var scale = Util.singularValueDecompose2dScale(matrix);
  55062. r0 *= scale[0];
  55063. r1 *= scale[1];
  55064. }
  55065. }
  55066. return [
  55067. 'RadialAxial',
  55068. type,
  55069. this.colorStops,
  55070. p0,
  55071. p1,
  55072. r0,
  55073. r1
  55074. ];
  55075. }
  55076. };
  55077. return RadialAxial;
  55078. }();
  55079. // All mesh shading. For now, they will be presented as set of the triangles
  55080. // to be drawn on the canvas and rgb color for each vertex.
  55081. Shadings.Mesh = function MeshClosure() {
  55082. function MeshStreamReader(stream, context) {
  55083. this.stream = stream;
  55084. this.context = context;
  55085. this.buffer = 0;
  55086. this.bufferLength = 0;
  55087. var numComps = context.numComps;
  55088. this.tmpCompsBuf = new Float32Array(numComps);
  55089. var csNumComps = context.colorSpace.numComps;
  55090. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  55091. }
  55092. MeshStreamReader.prototype = {
  55093. get hasData() {
  55094. if (this.stream.end) {
  55095. return this.stream.pos < this.stream.end;
  55096. }
  55097. if (this.bufferLength > 0) {
  55098. return true;
  55099. }
  55100. var nextByte = this.stream.getByte();
  55101. if (nextByte < 0) {
  55102. return false;
  55103. }
  55104. this.buffer = nextByte;
  55105. this.bufferLength = 8;
  55106. return true;
  55107. },
  55108. readBits: function MeshStreamReader_readBits(n) {
  55109. var buffer = this.buffer;
  55110. var bufferLength = this.bufferLength;
  55111. if (n === 32) {
  55112. if (bufferLength === 0) {
  55113. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  55114. }
  55115. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  55116. var nextByte = this.stream.getByte();
  55117. this.buffer = nextByte & (1 << bufferLength) - 1;
  55118. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  55119. }
  55120. if (n === 8 && bufferLength === 0) {
  55121. return this.stream.getByte();
  55122. }
  55123. while (bufferLength < n) {
  55124. buffer = buffer << 8 | this.stream.getByte();
  55125. bufferLength += 8;
  55126. }
  55127. bufferLength -= n;
  55128. this.bufferLength = bufferLength;
  55129. this.buffer = buffer & (1 << bufferLength) - 1;
  55130. return buffer >> bufferLength;
  55131. },
  55132. align: function MeshStreamReader_align() {
  55133. this.buffer = 0;
  55134. this.bufferLength = 0;
  55135. },
  55136. readFlag: function MeshStreamReader_readFlag() {
  55137. return this.readBits(this.context.bitsPerFlag);
  55138. },
  55139. readCoordinate: function MeshStreamReader_readCoordinate() {
  55140. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  55141. var xi = this.readBits(bitsPerCoordinate);
  55142. var yi = this.readBits(bitsPerCoordinate);
  55143. var decode = this.context.decode;
  55144. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  55145. // 2 ^ -32
  55146. return [
  55147. xi * scale * (decode[1] - decode[0]) + decode[0],
  55148. yi * scale * (decode[3] - decode[2]) + decode[2]
  55149. ];
  55150. },
  55151. readComponents: function MeshStreamReader_readComponents() {
  55152. var numComps = this.context.numComps;
  55153. var bitsPerComponent = this.context.bitsPerComponent;
  55154. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  55155. // 2 ^ -32
  55156. var decode = this.context.decode;
  55157. var components = this.tmpCompsBuf;
  55158. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  55159. var ci = this.readBits(bitsPerComponent);
  55160. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  55161. }
  55162. var color = this.tmpCsCompsBuf;
  55163. if (this.context.colorFn) {
  55164. this.context.colorFn(components, 0, color, 0);
  55165. }
  55166. return this.context.colorSpace.getRgb(color, 0);
  55167. }
  55168. };
  55169. function decodeType4Shading(mesh, reader) {
  55170. var coords = mesh.coords;
  55171. var colors = mesh.colors;
  55172. var operators = [];
  55173. var ps = [];
  55174. // not maintaining cs since that will match ps
  55175. var verticesLeft = 0;
  55176. // assuming we have all data to start a new triangle
  55177. while (reader.hasData) {
  55178. var f = reader.readFlag();
  55179. var coord = reader.readCoordinate();
  55180. var color = reader.readComponents();
  55181. if (verticesLeft === 0) {
  55182. // ignoring flags if we started a triangle
  55183. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  55184. switch (f) {
  55185. case 0:
  55186. verticesLeft = 3;
  55187. break;
  55188. case 1:
  55189. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  55190. verticesLeft = 1;
  55191. break;
  55192. case 2:
  55193. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  55194. verticesLeft = 1;
  55195. break;
  55196. }
  55197. operators.push(f);
  55198. }
  55199. ps.push(coords.length);
  55200. coords.push(coord);
  55201. colors.push(color);
  55202. verticesLeft--;
  55203. reader.align();
  55204. }
  55205. mesh.figures.push({
  55206. type: 'triangles',
  55207. coords: new Int32Array(ps),
  55208. colors: new Int32Array(ps)
  55209. });
  55210. }
  55211. function decodeType5Shading(mesh, reader, verticesPerRow) {
  55212. var coords = mesh.coords;
  55213. var colors = mesh.colors;
  55214. var ps = [];
  55215. // not maintaining cs since that will match ps
  55216. while (reader.hasData) {
  55217. var coord = reader.readCoordinate();
  55218. var color = reader.readComponents();
  55219. ps.push(coords.length);
  55220. coords.push(coord);
  55221. colors.push(color);
  55222. }
  55223. mesh.figures.push({
  55224. type: 'lattice',
  55225. coords: new Int32Array(ps),
  55226. colors: new Int32Array(ps),
  55227. verticesPerRow: verticesPerRow
  55228. });
  55229. }
  55230. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  55231. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  55232. var TRIANGLE_DENSITY = 20;
  55233. // count of triangles per entire mesh bounds
  55234. var getB = function getBClosure() {
  55235. function buildB(count) {
  55236. var lut = [];
  55237. for (var i = 0; i <= count; i++) {
  55238. var t = i / count, t_ = 1 - t;
  55239. lut.push(new Float32Array([
  55240. t_ * t_ * t_,
  55241. 3 * t * t_ * t_,
  55242. 3 * t * t * t_,
  55243. t * t * t
  55244. ]));
  55245. }
  55246. return lut;
  55247. }
  55248. var cache = [];
  55249. return function getB(count) {
  55250. if (!cache[count]) {
  55251. cache[count] = buildB(count);
  55252. }
  55253. return cache[count];
  55254. };
  55255. }();
  55256. function buildFigureFromPatch(mesh, index) {
  55257. var figure = mesh.figures[index];
  55258. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  55259. var coords = mesh.coords, colors = mesh.colors;
  55260. var pi = figure.coords;
  55261. var ci = figure.colors;
  55262. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  55263. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  55264. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  55265. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  55266. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  55267. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  55268. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  55269. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  55270. var verticesPerRow = splitXBy + 1;
  55271. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  55272. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  55273. var k = 0;
  55274. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  55275. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  55276. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  55277. for (var row = 0; row <= splitYBy; row++) {
  55278. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  55279. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  55280. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  55281. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  55282. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  55283. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  55284. for (var col = 0; col <= splitXBy; col++, k++) {
  55285. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  55286. continue;
  55287. }
  55288. var x = 0, y = 0;
  55289. var q = 0;
  55290. for (var i = 0; i <= 3; i++) {
  55291. for (var j = 0; j <= 3; j++, q++) {
  55292. var m = bRow[row][i] * bCol[col][j];
  55293. x += coords[pi[q]][0] * m;
  55294. y += coords[pi[q]][1] * m;
  55295. }
  55296. }
  55297. figureCoords[k] = coords.length;
  55298. coords.push([
  55299. x,
  55300. y
  55301. ]);
  55302. figureColors[k] = colors.length;
  55303. var newColor = new Uint8Array(3);
  55304. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  55305. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  55306. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  55307. colors.push(newColor);
  55308. }
  55309. }
  55310. figureCoords[0] = pi[0];
  55311. figureColors[0] = ci[0];
  55312. figureCoords[splitXBy] = pi[3];
  55313. figureColors[splitXBy] = ci[1];
  55314. figureCoords[verticesPerRow * splitYBy] = pi[12];
  55315. figureColors[verticesPerRow * splitYBy] = ci[2];
  55316. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  55317. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  55318. mesh.figures[index] = {
  55319. type: 'lattice',
  55320. coords: figureCoords,
  55321. colors: figureColors,
  55322. verticesPerRow: verticesPerRow
  55323. };
  55324. }
  55325. function decodeType6Shading(mesh, reader) {
  55326. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  55327. var coords = mesh.coords;
  55328. var colors = mesh.colors;
  55329. var ps = new Int32Array(16);
  55330. // p00, p10, ..., p30, p01, ..., p33
  55331. var cs = new Int32Array(4);
  55332. // c00, c30, c03, c33
  55333. while (reader.hasData) {
  55334. var f = reader.readFlag();
  55335. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  55336. var i, ii;
  55337. var pi = coords.length;
  55338. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  55339. coords.push(reader.readCoordinate());
  55340. }
  55341. var ci = colors.length;
  55342. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  55343. colors.push(reader.readComponents());
  55344. }
  55345. var tmp1, tmp2, tmp3, tmp4;
  55346. switch (f) {
  55347. case 0:
  55348. ps[12] = pi + 3;
  55349. ps[13] = pi + 4;
  55350. ps[14] = pi + 5;
  55351. ps[15] = pi + 6;
  55352. ps[8] = pi + 2;
  55353. /* values for 5, 6, 9, 10 are */
  55354. ps[11] = pi + 7;
  55355. ps[4] = pi + 1;
  55356. /* calculated below */
  55357. ps[7] = pi + 8;
  55358. ps[0] = pi;
  55359. ps[1] = pi + 11;
  55360. ps[2] = pi + 10;
  55361. ps[3] = pi + 9;
  55362. cs[2] = ci + 1;
  55363. cs[3] = ci + 2;
  55364. cs[0] = ci;
  55365. cs[1] = ci + 3;
  55366. break;
  55367. case 1:
  55368. tmp1 = ps[12];
  55369. tmp2 = ps[13];
  55370. tmp3 = ps[14];
  55371. tmp4 = ps[15];
  55372. ps[12] = tmp4;
  55373. ps[13] = pi + 0;
  55374. ps[14] = pi + 1;
  55375. ps[15] = pi + 2;
  55376. ps[8] = tmp3;
  55377. /* values for 5, 6, 9, 10 are */
  55378. ps[11] = pi + 3;
  55379. ps[4] = tmp2;
  55380. /* calculated below */
  55381. ps[7] = pi + 4;
  55382. ps[0] = tmp1;
  55383. ps[1] = pi + 7;
  55384. ps[2] = pi + 6;
  55385. ps[3] = pi + 5;
  55386. tmp1 = cs[2];
  55387. tmp2 = cs[3];
  55388. cs[2] = tmp2;
  55389. cs[3] = ci;
  55390. cs[0] = tmp1;
  55391. cs[1] = ci + 1;
  55392. break;
  55393. case 2:
  55394. tmp1 = ps[15];
  55395. tmp2 = ps[11];
  55396. ps[12] = ps[3];
  55397. ps[13] = pi + 0;
  55398. ps[14] = pi + 1;
  55399. ps[15] = pi + 2;
  55400. ps[8] = ps[7];
  55401. /* values for 5, 6, 9, 10 are */
  55402. ps[11] = pi + 3;
  55403. ps[4] = tmp2;
  55404. /* calculated below */
  55405. ps[7] = pi + 4;
  55406. ps[0] = tmp1;
  55407. ps[1] = pi + 7;
  55408. ps[2] = pi + 6;
  55409. ps[3] = pi + 5;
  55410. tmp1 = cs[3];
  55411. cs[2] = cs[1];
  55412. cs[3] = ci;
  55413. cs[0] = tmp1;
  55414. cs[1] = ci + 1;
  55415. break;
  55416. case 3:
  55417. ps[12] = ps[0];
  55418. ps[13] = pi + 0;
  55419. ps[14] = pi + 1;
  55420. ps[15] = pi + 2;
  55421. ps[8] = ps[1];
  55422. /* values for 5, 6, 9, 10 are */
  55423. ps[11] = pi + 3;
  55424. ps[4] = ps[2];
  55425. /* calculated below */
  55426. ps[7] = pi + 4;
  55427. ps[0] = ps[3];
  55428. ps[1] = pi + 7;
  55429. ps[2] = pi + 6;
  55430. ps[3] = pi + 5;
  55431. cs[2] = cs[0];
  55432. cs[3] = ci;
  55433. cs[0] = cs[1];
  55434. cs[1] = ci + 1;
  55435. break;
  55436. }
  55437. // set p11, p12, p21, p22
  55438. ps[5] = coords.length;
  55439. coords.push([
  55440. (-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  55441. (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  55442. ]);
  55443. ps[6] = coords.length;
  55444. coords.push([
  55445. (-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  55446. (-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  55447. ]);
  55448. ps[9] = coords.length;
  55449. coords.push([
  55450. (-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  55451. (-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  55452. ]);
  55453. ps[10] = coords.length;
  55454. coords.push([
  55455. (-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  55456. (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  55457. ]);
  55458. mesh.figures.push({
  55459. type: 'patch',
  55460. coords: new Int32Array(ps),
  55461. // making copies of ps and cs
  55462. colors: new Int32Array(cs)
  55463. });
  55464. }
  55465. }
  55466. function decodeType7Shading(mesh, reader) {
  55467. var coords = mesh.coords;
  55468. var colors = mesh.colors;
  55469. var ps = new Int32Array(16);
  55470. // p00, p10, ..., p30, p01, ..., p33
  55471. var cs = new Int32Array(4);
  55472. // c00, c30, c03, c33
  55473. while (reader.hasData) {
  55474. var f = reader.readFlag();
  55475. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  55476. var i, ii;
  55477. var pi = coords.length;
  55478. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  55479. coords.push(reader.readCoordinate());
  55480. }
  55481. var ci = colors.length;
  55482. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  55483. colors.push(reader.readComponents());
  55484. }
  55485. var tmp1, tmp2, tmp3, tmp4;
  55486. switch (f) {
  55487. case 0:
  55488. ps[12] = pi + 3;
  55489. ps[13] = pi + 4;
  55490. ps[14] = pi + 5;
  55491. ps[15] = pi + 6;
  55492. ps[8] = pi + 2;
  55493. ps[9] = pi + 13;
  55494. ps[10] = pi + 14;
  55495. ps[11] = pi + 7;
  55496. ps[4] = pi + 1;
  55497. ps[5] = pi + 12;
  55498. ps[6] = pi + 15;
  55499. ps[7] = pi + 8;
  55500. ps[0] = pi;
  55501. ps[1] = pi + 11;
  55502. ps[2] = pi + 10;
  55503. ps[3] = pi + 9;
  55504. cs[2] = ci + 1;
  55505. cs[3] = ci + 2;
  55506. cs[0] = ci;
  55507. cs[1] = ci + 3;
  55508. break;
  55509. case 1:
  55510. tmp1 = ps[12];
  55511. tmp2 = ps[13];
  55512. tmp3 = ps[14];
  55513. tmp4 = ps[15];
  55514. ps[12] = tmp4;
  55515. ps[13] = pi + 0;
  55516. ps[14] = pi + 1;
  55517. ps[15] = pi + 2;
  55518. ps[8] = tmp3;
  55519. ps[9] = pi + 9;
  55520. ps[10] = pi + 10;
  55521. ps[11] = pi + 3;
  55522. ps[4] = tmp2;
  55523. ps[5] = pi + 8;
  55524. ps[6] = pi + 11;
  55525. ps[7] = pi + 4;
  55526. ps[0] = tmp1;
  55527. ps[1] = pi + 7;
  55528. ps[2] = pi + 6;
  55529. ps[3] = pi + 5;
  55530. tmp1 = cs[2];
  55531. tmp2 = cs[3];
  55532. cs[2] = tmp2;
  55533. cs[3] = ci;
  55534. cs[0] = tmp1;
  55535. cs[1] = ci + 1;
  55536. break;
  55537. case 2:
  55538. tmp1 = ps[15];
  55539. tmp2 = ps[11];
  55540. ps[12] = ps[3];
  55541. ps[13] = pi + 0;
  55542. ps[14] = pi + 1;
  55543. ps[15] = pi + 2;
  55544. ps[8] = ps[7];
  55545. ps[9] = pi + 9;
  55546. ps[10] = pi + 10;
  55547. ps[11] = pi + 3;
  55548. ps[4] = tmp2;
  55549. ps[5] = pi + 8;
  55550. ps[6] = pi + 11;
  55551. ps[7] = pi + 4;
  55552. ps[0] = tmp1;
  55553. ps[1] = pi + 7;
  55554. ps[2] = pi + 6;
  55555. ps[3] = pi + 5;
  55556. tmp1 = cs[3];
  55557. cs[2] = cs[1];
  55558. cs[3] = ci;
  55559. cs[0] = tmp1;
  55560. cs[1] = ci + 1;
  55561. break;
  55562. case 3:
  55563. ps[12] = ps[0];
  55564. ps[13] = pi + 0;
  55565. ps[14] = pi + 1;
  55566. ps[15] = pi + 2;
  55567. ps[8] = ps[1];
  55568. ps[9] = pi + 9;
  55569. ps[10] = pi + 10;
  55570. ps[11] = pi + 3;
  55571. ps[4] = ps[2];
  55572. ps[5] = pi + 8;
  55573. ps[6] = pi + 11;
  55574. ps[7] = pi + 4;
  55575. ps[0] = ps[3];
  55576. ps[1] = pi + 7;
  55577. ps[2] = pi + 6;
  55578. ps[3] = pi + 5;
  55579. cs[2] = cs[0];
  55580. cs[3] = ci;
  55581. cs[0] = cs[1];
  55582. cs[1] = ci + 1;
  55583. break;
  55584. }
  55585. mesh.figures.push({
  55586. type: 'patch',
  55587. coords: new Int32Array(ps),
  55588. // making copies of ps and cs
  55589. colors: new Int32Array(cs)
  55590. });
  55591. }
  55592. }
  55593. function updateBounds(mesh) {
  55594. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  55595. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  55596. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  55597. minX = minX > x ? x : minX;
  55598. minY = minY > y ? y : minY;
  55599. maxX = maxX < x ? x : maxX;
  55600. maxY = maxY < y ? y : maxY;
  55601. }
  55602. mesh.bounds = [
  55603. minX,
  55604. minY,
  55605. maxX,
  55606. maxY
  55607. ];
  55608. }
  55609. function packData(mesh) {
  55610. var i, ii, j, jj;
  55611. var coords = mesh.coords;
  55612. var coordsPacked = new Float32Array(coords.length * 2);
  55613. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  55614. var xy = coords[i];
  55615. coordsPacked[j++] = xy[0];
  55616. coordsPacked[j++] = xy[1];
  55617. }
  55618. mesh.coords = coordsPacked;
  55619. var colors = mesh.colors;
  55620. var colorsPacked = new Uint8Array(colors.length * 3);
  55621. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  55622. var c = colors[i];
  55623. colorsPacked[j++] = c[0];
  55624. colorsPacked[j++] = c[1];
  55625. colorsPacked[j++] = c[2];
  55626. }
  55627. mesh.colors = colorsPacked;
  55628. var figures = mesh.figures;
  55629. for (i = 0, ii = figures.length; i < ii; i++) {
  55630. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  55631. for (j = 0, jj = ps.length; j < jj; j++) {
  55632. ps[j] *= 2;
  55633. cs[j] *= 3;
  55634. }
  55635. }
  55636. }
  55637. function Mesh(stream, matrix, xref, res) {
  55638. assert(isStream(stream), 'Mesh data is not a stream');
  55639. var dict = stream.dict;
  55640. this.matrix = matrix;
  55641. this.shadingType = dict.get('ShadingType');
  55642. this.type = 'Pattern';
  55643. this.bbox = dict.getArray('BBox');
  55644. var cs = dict.get('ColorSpace', 'CS');
  55645. cs = ColorSpace.parse(cs, xref, res);
  55646. this.cs = cs;
  55647. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  55648. var fnObj = dict.get('Function');
  55649. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  55650. this.coords = [];
  55651. this.colors = [];
  55652. this.figures = [];
  55653. var decodeContext = {
  55654. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  55655. bitsPerComponent: dict.get('BitsPerComponent'),
  55656. bitsPerFlag: dict.get('BitsPerFlag'),
  55657. decode: dict.getArray('Decode'),
  55658. colorFn: fn,
  55659. colorSpace: cs,
  55660. numComps: fn ? 1 : cs.numComps
  55661. };
  55662. var reader = new MeshStreamReader(stream, decodeContext);
  55663. var patchMesh = false;
  55664. switch (this.shadingType) {
  55665. case ShadingType.FREE_FORM_MESH:
  55666. decodeType4Shading(this, reader);
  55667. break;
  55668. case ShadingType.LATTICE_FORM_MESH:
  55669. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  55670. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  55671. decodeType5Shading(this, reader, verticesPerRow);
  55672. break;
  55673. case ShadingType.COONS_PATCH_MESH:
  55674. decodeType6Shading(this, reader);
  55675. patchMesh = true;
  55676. break;
  55677. case ShadingType.TENSOR_PATCH_MESH:
  55678. decodeType7Shading(this, reader);
  55679. patchMesh = true;
  55680. break;
  55681. default:
  55682. error('Unsupported mesh type.');
  55683. break;
  55684. }
  55685. if (patchMesh) {
  55686. // dirty bounds calculation for determining, how dense shall be triangles
  55687. updateBounds(this);
  55688. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  55689. buildFigureFromPatch(this, i);
  55690. }
  55691. }
  55692. // calculate bounds
  55693. updateBounds(this);
  55694. packData(this);
  55695. }
  55696. Mesh.prototype = {
  55697. getIR: function Mesh_getIR() {
  55698. return [
  55699. 'Mesh',
  55700. this.shadingType,
  55701. this.coords,
  55702. this.colors,
  55703. this.figures,
  55704. this.bounds,
  55705. this.matrix,
  55706. this.bbox,
  55707. this.background
  55708. ];
  55709. }
  55710. };
  55711. return Mesh;
  55712. }();
  55713. Shadings.Dummy = function DummyClosure() {
  55714. function Dummy() {
  55715. this.type = 'Pattern';
  55716. }
  55717. Dummy.prototype = {
  55718. getIR: function Dummy_getIR() {
  55719. return ['Dummy'];
  55720. }
  55721. };
  55722. return Dummy;
  55723. }();
  55724. function getTilingPatternIR(operatorList, dict, args) {
  55725. var matrix = dict.getArray('Matrix');
  55726. var bbox = dict.getArray('BBox');
  55727. var xstep = dict.get('XStep');
  55728. var ystep = dict.get('YStep');
  55729. var paintType = dict.get('PaintType');
  55730. var tilingType = dict.get('TilingType');
  55731. return [
  55732. 'TilingPattern',
  55733. args,
  55734. operatorList,
  55735. matrix,
  55736. bbox,
  55737. xstep,
  55738. ystep,
  55739. paintType,
  55740. tilingType
  55741. ];
  55742. }
  55743. exports.Pattern = Pattern;
  55744. exports.getTilingPatternIR = getTilingPatternIR;
  55745. }));
  55746. (function (root, factory) {
  55747. factory(root.pdfjsCoreEvaluator = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser, root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3, root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern, root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  55748. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  55749. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  55750. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  55751. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  55752. var ImageKind = sharedUtil.ImageKind;
  55753. var OPS = sharedUtil.OPS;
  55754. var TextRenderingMode = sharedUtil.TextRenderingMode;
  55755. var Util = sharedUtil.Util;
  55756. var assert = sharedUtil.assert;
  55757. var createPromiseCapability = sharedUtil.createPromiseCapability;
  55758. var error = sharedUtil.error;
  55759. var info = sharedUtil.info;
  55760. var isArray = sharedUtil.isArray;
  55761. var isNum = sharedUtil.isNum;
  55762. var isString = sharedUtil.isString;
  55763. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  55764. var warn = sharedUtil.warn;
  55765. var Dict = corePrimitives.Dict;
  55766. var Name = corePrimitives.Name;
  55767. var isCmd = corePrimitives.isCmd;
  55768. var isDict = corePrimitives.isDict;
  55769. var isName = corePrimitives.isName;
  55770. var isRef = corePrimitives.isRef;
  55771. var isStream = corePrimitives.isStream;
  55772. var DecodeStream = coreStream.DecodeStream;
  55773. var JpegStream = coreStream.JpegStream;
  55774. var Stream = coreStream.Stream;
  55775. var Lexer = coreParser.Lexer;
  55776. var Parser = coreParser.Parser;
  55777. var isEOF = coreParser.isEOF;
  55778. var PDFImage = coreImage.PDFImage;
  55779. var ColorSpace = coreColorSpace.ColorSpace;
  55780. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  55781. var ErrorFont = coreFonts.ErrorFont;
  55782. var FontFlags = coreFonts.FontFlags;
  55783. var Font = coreFonts.Font;
  55784. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  55785. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  55786. var getFontType = coreFonts.getFontType;
  55787. var isPDFFunction = coreFunction.isPDFFunction;
  55788. var PDFFunction = coreFunction.PDFFunction;
  55789. var Pattern = corePattern.Pattern;
  55790. var getTilingPatternIR = corePattern.getTilingPatternIR;
  55791. var CMapFactory = coreCMap.CMapFactory;
  55792. var IdentityCMap = coreCMap.IdentityCMap;
  55793. var getMetrics = coreMetrics.getMetrics;
  55794. var bidi = coreBidi.bidi;
  55795. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  55796. var StandardEncoding = coreEncodings.StandardEncoding;
  55797. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  55798. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  55799. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  55800. var getEncoding = coreEncodings.getEncoding;
  55801. var getStdFontMap = coreStandardFonts.getStdFontMap;
  55802. var getSerifFonts = coreStandardFonts.getSerifFonts;
  55803. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  55804. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  55805. var reverseIfRtl = coreUnicode.reverseIfRtl;
  55806. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  55807. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  55808. var PartialEvaluator = function PartialEvaluatorClosure() {
  55809. var DefaultPartialEvaluatorOptions = {
  55810. forceDataSchema: false,
  55811. maxImageSize: -1,
  55812. disableFontFace: false,
  55813. cMapOptions: {
  55814. url: null,
  55815. packed: false
  55816. }
  55817. };
  55818. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  55819. this.xref = xref;
  55820. this.resources = resources;
  55821. this.handler = handler;
  55822. this.forceDataSchema = forceDataSchema;
  55823. }
  55824. NativeImageDecoder.prototype = {
  55825. canDecode: function (image) {
  55826. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  55827. },
  55828. decode: function (image) {
  55829. // For natively supported JPEGs send them to the main thread for decoding.
  55830. var dict = image.dict;
  55831. var colorSpace = dict.get('ColorSpace', 'CS');
  55832. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  55833. var numComps = colorSpace.numComps;
  55834. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  55835. image.getIR(this.forceDataSchema),
  55836. numComps
  55837. ]);
  55838. return decodePromise.then(function (message) {
  55839. var data = message.data;
  55840. return new Stream(data, 0, data.length, image.dict);
  55841. });
  55842. }
  55843. };
  55844. /**
  55845. * Checks if the image can be decoded and displayed by the browser without any
  55846. * further processing such as color space conversions.
  55847. */
  55848. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  55849. var dict = image.dict;
  55850. if (dict.has('DecodeParms') || dict.has('DP')) {
  55851. return false;
  55852. }
  55853. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  55854. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  55855. };
  55856. /**
  55857. * Checks if the image can be decoded by the browser.
  55858. */
  55859. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  55860. var dict = image.dict;
  55861. if (dict.has('DecodeParms') || dict.has('DP')) {
  55862. return false;
  55863. }
  55864. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  55865. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  55866. };
  55867. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  55868. this.pdfManager = pdfManager;
  55869. this.xref = xref;
  55870. this.handler = handler;
  55871. this.pageIndex = pageIndex;
  55872. this.uniquePrefix = uniquePrefix;
  55873. this.idCounters = idCounters;
  55874. this.fontCache = fontCache;
  55875. this.options = options || DefaultPartialEvaluatorOptions;
  55876. }
  55877. // Trying to minimize Date.now() usage and check every 100 time
  55878. var TIME_SLOT_DURATION_MS = 20;
  55879. var CHECK_TIME_EVERY = 100;
  55880. function TimeSlotManager() {
  55881. this.reset();
  55882. }
  55883. TimeSlotManager.prototype = {
  55884. check: function TimeSlotManager_check() {
  55885. if (++this.checked < CHECK_TIME_EVERY) {
  55886. return false;
  55887. }
  55888. this.checked = 0;
  55889. return this.endTime <= Date.now();
  55890. },
  55891. reset: function TimeSlotManager_reset() {
  55892. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  55893. this.checked = 0;
  55894. }
  55895. };
  55896. var deferred = Promise.resolve();
  55897. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  55898. PartialEvaluator.prototype = {
  55899. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  55900. if (!isDict(resources)) {
  55901. return false;
  55902. }
  55903. var processed = Object.create(null);
  55904. if (resources.objId) {
  55905. processed[resources.objId] = true;
  55906. }
  55907. var nodes = [resources], xref = this.xref;
  55908. while (nodes.length) {
  55909. var key, i, ii;
  55910. var node = nodes.shift();
  55911. // First check the current resources for blend modes.
  55912. var graphicStates = node.get('ExtGState');
  55913. if (isDict(graphicStates)) {
  55914. var graphicStatesKeys = graphicStates.getKeys();
  55915. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  55916. key = graphicStatesKeys[i];
  55917. var graphicState = graphicStates.get(key);
  55918. var bm = graphicState.get('BM');
  55919. if (isName(bm) && bm.name !== 'Normal') {
  55920. return true;
  55921. }
  55922. }
  55923. }
  55924. // Descend into the XObjects to look for more resources and blend modes.
  55925. var xObjects = node.get('XObject');
  55926. if (!isDict(xObjects)) {
  55927. continue;
  55928. }
  55929. var xObjectsKeys = xObjects.getKeys();
  55930. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  55931. key = xObjectsKeys[i];
  55932. var xObject = xObjects.getRaw(key);
  55933. if (isRef(xObject)) {
  55934. if (processed[xObject.toString()]) {
  55935. // The XObject has already been processed, and by avoiding a
  55936. // redundant `xref.fetch` we can *significantly* reduce the load
  55937. // time for badly generated PDF files (fixes issue6961.pdf).
  55938. continue;
  55939. }
  55940. xObject = xref.fetch(xObject);
  55941. }
  55942. if (!isStream(xObject)) {
  55943. continue;
  55944. }
  55945. if (xObject.dict.objId) {
  55946. if (processed[xObject.dict.objId]) {
  55947. // stream has objId and is processed already
  55948. continue;
  55949. }
  55950. processed[xObject.dict.objId] = true;
  55951. }
  55952. var xResources = xObject.dict.get('Resources');
  55953. // Checking objId to detect an infinite loop.
  55954. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  55955. nodes.push(xResources);
  55956. if (xResources.objId) {
  55957. processed[xResources.objId] = true;
  55958. }
  55959. }
  55960. }
  55961. }
  55962. return false;
  55963. },
  55964. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  55965. var matrix = xobj.dict.getArray('Matrix');
  55966. var bbox = xobj.dict.getArray('BBox');
  55967. var group = xobj.dict.get('Group');
  55968. if (group) {
  55969. var groupOptions = {
  55970. matrix: matrix,
  55971. bbox: bbox,
  55972. smask: smask,
  55973. isolated: false,
  55974. knockout: false
  55975. };
  55976. var groupSubtype = group.get('S');
  55977. var colorSpace;
  55978. if (isName(groupSubtype, 'Transparency')) {
  55979. groupOptions.isolated = group.get('I') || false;
  55980. groupOptions.knockout = group.get('K') || false;
  55981. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  55982. }
  55983. if (smask && smask.backdrop) {
  55984. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  55985. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  55986. }
  55987. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  55988. }
  55989. operatorList.addOp(OPS.paintFormXObjectBegin, [
  55990. matrix,
  55991. bbox
  55992. ]);
  55993. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  55994. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  55995. if (group) {
  55996. operatorList.addOp(OPS.endGroup, [groupOptions]);
  55997. }
  55998. });
  55999. },
  56000. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  56001. var self = this;
  56002. var dict = image.dict;
  56003. var w = dict.get('Width', 'W');
  56004. var h = dict.get('Height', 'H');
  56005. if (!(w && isNum(w)) || !(h && isNum(h))) {
  56006. warn('Image dimensions are missing, or not numbers.');
  56007. return;
  56008. }
  56009. var maxImageSize = this.options.maxImageSize;
  56010. if (maxImageSize !== -1 && w * h > maxImageSize) {
  56011. warn('Image exceeded maximum allowed size and was removed.');
  56012. return;
  56013. }
  56014. var imageMask = dict.get('ImageMask', 'IM') || false;
  56015. var imgData, args;
  56016. if (imageMask) {
  56017. // This depends on a tmpCanvas being filled with the
  56018. // current fillStyle, such that processing the pixel
  56019. // data can't be done here. Instead of creating a
  56020. // complete PDFImage, only read the information needed
  56021. // for later.
  56022. var width = dict.get('Width', 'W');
  56023. var height = dict.get('Height', 'H');
  56024. var bitStrideLength = width + 7 >> 3;
  56025. var imgArray = image.getBytes(bitStrideLength * height);
  56026. var decode = dict.getArray('Decode', 'D');
  56027. var inverseDecode = !!decode && decode[0] > 0;
  56028. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  56029. imgData.cached = true;
  56030. args = [imgData];
  56031. operatorList.addOp(OPS.paintImageMaskXObject, args);
  56032. if (cacheKey) {
  56033. imageCache[cacheKey] = {
  56034. fn: OPS.paintImageMaskXObject,
  56035. args: args
  56036. };
  56037. }
  56038. return;
  56039. }
  56040. var softMask = dict.get('SMask', 'SM') || false;
  56041. var mask = dict.get('Mask') || false;
  56042. var SMALL_IMAGE_DIMENSIONS = 200;
  56043. // Inlining small images into the queue as RGB data
  56044. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  56045. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  56046. // We force the use of RGBA_32BPP images here, because we can't handle
  56047. // any other kind.
  56048. imgData = imageObj.createImageData(/* forceRGBA = */
  56049. true);
  56050. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  56051. return;
  56052. }
  56053. // If there is no imageMask, create the PDFImage and a lot
  56054. // of image processing can be done here.
  56055. var uniquePrefix = this.uniquePrefix || '';
  56056. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  56057. operatorList.addDependency(objId);
  56058. args = [
  56059. objId,
  56060. w,
  56061. h
  56062. ];
  56063. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  56064. // These JPEGs don't need any more processing so we can just send it.
  56065. operatorList.addOp(OPS.paintJpegXObject, args);
  56066. this.handler.send('obj', [
  56067. objId,
  56068. this.pageIndex,
  56069. 'JpegStream',
  56070. image.getIR(this.options.forceDataSchema)
  56071. ]);
  56072. return;
  56073. }
  56074. // Creates native image decoder only if a JPEG image or mask is present.
  56075. var nativeImageDecoder = null;
  56076. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  56077. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  56078. }
  56079. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  56080. var imgData = imageObj.createImageData(/* forceRGBA = */
  56081. false);
  56082. self.handler.send('obj', [
  56083. objId,
  56084. self.pageIndex,
  56085. 'Image',
  56086. imgData
  56087. ], [imgData.data.buffer]);
  56088. }).then(undefined, function (reason) {
  56089. warn('Unable to decode image: ' + reason);
  56090. self.handler.send('obj', [
  56091. objId,
  56092. self.pageIndex,
  56093. 'Image',
  56094. null
  56095. ]);
  56096. });
  56097. operatorList.addOp(OPS.paintImageXObject, args);
  56098. if (cacheKey) {
  56099. imageCache[cacheKey] = {
  56100. fn: OPS.paintImageXObject,
  56101. args: args
  56102. };
  56103. }
  56104. },
  56105. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  56106. var smaskContent = smask.get('G');
  56107. var smaskOptions = {
  56108. subtype: smask.get('S').name,
  56109. backdrop: smask.get('BC')
  56110. };
  56111. // The SMask might have a alpha/luminosity value transfer function --
  56112. // we will build a map of integer values in range 0..255 to be fast.
  56113. var transferObj = smask.get('TR');
  56114. if (isPDFFunction(transferObj)) {
  56115. var transferFn = PDFFunction.parse(this.xref, transferObj);
  56116. var transferMap = new Uint8Array(256);
  56117. var tmp = new Float32Array(1);
  56118. for (var i = 0; i < 256; i++) {
  56119. tmp[0] = i / 255;
  56120. transferFn(tmp, 0, tmp, 0);
  56121. transferMap[i] = tmp[0] * 255 | 0;
  56122. }
  56123. smaskOptions.transferMap = transferMap;
  56124. }
  56125. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  56126. },
  56127. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  56128. // Create an IR of the pattern code.
  56129. var tilingOpList = new OperatorList();
  56130. // Merge the available resources, to prevent issues when the patternDict
  56131. // is missing some /Resources entries (fixes issue6541.pdf).
  56132. var resourcesArray = [
  56133. patternDict.get('Resources'),
  56134. resources
  56135. ];
  56136. var patternResources = Dict.merge(this.xref, resourcesArray);
  56137. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  56138. // Add the dependencies to the parent operator list so they are
  56139. // resolved before sub operator list is executed synchronously.
  56140. operatorList.addDependencies(tilingOpList.dependencies);
  56141. operatorList.addOp(fn, getTilingPatternIR({
  56142. fnArray: tilingOpList.fnArray,
  56143. argsArray: tilingOpList.argsArray
  56144. }, patternDict, args));
  56145. });
  56146. },
  56147. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  56148. // TODO(mack): Not needed?
  56149. var fontName;
  56150. if (fontArgs) {
  56151. fontArgs = fontArgs.slice();
  56152. fontName = fontArgs[0].name;
  56153. }
  56154. var self = this;
  56155. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  56156. if (!translated.font.isType3Font) {
  56157. return translated;
  56158. }
  56159. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  56160. return translated;
  56161. }, function (reason) {
  56162. // Error in the font data -- sending unsupported feature notification.
  56163. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  56164. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  56165. });
  56166. }).then(function (translated) {
  56167. state.font = translated.font;
  56168. translated.send(self.handler);
  56169. return translated.loadedName;
  56170. });
  56171. },
  56172. handleText: function PartialEvaluator_handleText(chars, state) {
  56173. var font = state.font;
  56174. var glyphs = font.charsToGlyphs(chars);
  56175. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  56176. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  56177. var buildPath = function (fontChar) {
  56178. if (!font.renderer.hasBuiltPath(fontChar)) {
  56179. var path = font.renderer.getPathJs(fontChar);
  56180. this.handler.send('commonobj', [
  56181. font.loadedName + '_path_' + fontChar,
  56182. 'FontPath',
  56183. path
  56184. ]);
  56185. }
  56186. }.bind(this);
  56187. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  56188. var glyph = glyphs[i];
  56189. buildPath(glyph.fontChar);
  56190. // If the glyph has an accent we need to build a path for its
  56191. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  56192. var accent = glyph.accent;
  56193. if (accent && accent.fontChar) {
  56194. buildPath(accent.fontChar);
  56195. }
  56196. }
  56197. }
  56198. return glyphs;
  56199. },
  56200. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  56201. // This array holds the converted/processed state data.
  56202. var gStateObj = [];
  56203. var gStateKeys = gState.getKeys();
  56204. var self = this;
  56205. var promise = Promise.resolve();
  56206. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  56207. var key = gStateKeys[i];
  56208. var value = gState.get(key);
  56209. switch (key) {
  56210. case 'Type':
  56211. break;
  56212. case 'LW':
  56213. case 'LC':
  56214. case 'LJ':
  56215. case 'ML':
  56216. case 'D':
  56217. case 'RI':
  56218. case 'FL':
  56219. case 'CA':
  56220. case 'ca':
  56221. gStateObj.push([
  56222. key,
  56223. value
  56224. ]);
  56225. break;
  56226. case 'Font':
  56227. promise = promise.then(function () {
  56228. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  56229. operatorList.addDependency(loadedName);
  56230. gStateObj.push([
  56231. key,
  56232. [
  56233. loadedName,
  56234. value[1]
  56235. ]
  56236. ]);
  56237. });
  56238. });
  56239. break;
  56240. case 'BM':
  56241. gStateObj.push([
  56242. key,
  56243. value
  56244. ]);
  56245. break;
  56246. case 'SMask':
  56247. if (isName(value, 'None')) {
  56248. gStateObj.push([
  56249. key,
  56250. false
  56251. ]);
  56252. break;
  56253. }
  56254. if (isDict(value)) {
  56255. promise = promise.then(function (dict) {
  56256. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  56257. }.bind(this, value));
  56258. gStateObj.push([
  56259. key,
  56260. true
  56261. ]);
  56262. } else {
  56263. warn('Unsupported SMask type');
  56264. }
  56265. break;
  56266. // Only generate info log messages for the following since
  56267. // they are unlikely to have a big impact on the rendering.
  56268. case 'OP':
  56269. case 'op':
  56270. case 'OPM':
  56271. case 'BG':
  56272. case 'BG2':
  56273. case 'UCR':
  56274. case 'UCR2':
  56275. case 'TR':
  56276. case 'TR2':
  56277. case 'HT':
  56278. case 'SM':
  56279. case 'SA':
  56280. case 'AIS':
  56281. case 'TK':
  56282. // TODO implement these operators.
  56283. info('graphic state operator ' + key);
  56284. break;
  56285. default:
  56286. info('Unknown graphic state operator ' + key);
  56287. break;
  56288. }
  56289. }
  56290. return promise.then(function () {
  56291. if (gStateObj.length > 0) {
  56292. operatorList.addOp(OPS.setGState, [gStateObj]);
  56293. }
  56294. });
  56295. },
  56296. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  56297. function errorFont() {
  56298. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  56299. }
  56300. var fontRef;
  56301. if (font) {
  56302. // Loading by ref.
  56303. assert(isRef(font));
  56304. fontRef = font;
  56305. } else {
  56306. // Loading by name.
  56307. var fontRes = resources.get('Font');
  56308. if (fontRes) {
  56309. fontRef = fontRes.getRaw(fontName);
  56310. } else {
  56311. warn('fontRes not available');
  56312. return errorFont();
  56313. }
  56314. }
  56315. if (!fontRef) {
  56316. warn('fontRef not available');
  56317. return errorFont();
  56318. }
  56319. if (this.fontCache.has(fontRef)) {
  56320. return this.fontCache.get(fontRef);
  56321. }
  56322. font = xref.fetchIfRef(fontRef);
  56323. if (!isDict(font)) {
  56324. return errorFont();
  56325. }
  56326. // We are holding `font.translated` references just for `fontRef`s that
  56327. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  56328. if (font.translated) {
  56329. return font.translated;
  56330. }
  56331. var fontCapability = createPromiseCapability();
  56332. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  56333. var descriptor = preEvaluatedFont.descriptor;
  56334. var fontRefIsRef = isRef(fontRef), fontID;
  56335. if (fontRefIsRef) {
  56336. fontID = fontRef.toString();
  56337. }
  56338. if (isDict(descriptor)) {
  56339. if (!descriptor.fontAliases) {
  56340. descriptor.fontAliases = Object.create(null);
  56341. }
  56342. var fontAliases = descriptor.fontAliases;
  56343. var hash = preEvaluatedFont.hash;
  56344. if (fontAliases[hash]) {
  56345. var aliasFontRef = fontAliases[hash].aliasRef;
  56346. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  56347. this.fontCache.putAlias(fontRef, aliasFontRef);
  56348. return this.fontCache.get(fontRef);
  56349. }
  56350. } else {
  56351. fontAliases[hash] = { fontID: Font.getFontID() };
  56352. }
  56353. if (fontRefIsRef) {
  56354. fontAliases[hash].aliasRef = fontRef;
  56355. }
  56356. fontID = fontAliases[hash].fontID;
  56357. }
  56358. // Workaround for bad PDF generators that reference fonts incorrectly,
  56359. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  56360. // In this case we should not put the font into `this.fontCache` (which is
  56361. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  56362. //
  56363. // However, if we don't cache the font it's not possible to remove it
  56364. // when `cleanup` is triggered from the API, which causes issues on
  56365. // subsequent rendering operations (see issue7403.pdf).
  56366. // A simple workaround would be to just not hold `font.translated`
  56367. // references in this case, but this would force us to unnecessarily load
  56368. // the same fonts over and over.
  56369. //
  56370. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  56371. // key in `this.fontCache`, to allow the font to be cached.
  56372. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  56373. // keys. Also, since `fontRef` is used when getting cached fonts,
  56374. // we'll not accidentally match fonts cached with the `fontID`.
  56375. if (fontRefIsRef) {
  56376. this.fontCache.put(fontRef, fontCapability.promise);
  56377. } else {
  56378. if (!fontID) {
  56379. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  56380. }
  56381. this.fontCache.put('id_' + fontID, fontCapability.promise);
  56382. }
  56383. assert(fontID, 'The "fontID" must be defined.');
  56384. // Keep track of each font we translated so the caller can
  56385. // load them asynchronously before calling display on a page.
  56386. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  56387. font.translated = fontCapability.promise;
  56388. // TODO move promises into translate font
  56389. var translatedPromise;
  56390. try {
  56391. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  56392. } catch (e) {
  56393. translatedPromise = Promise.reject(e);
  56394. }
  56395. var self = this;
  56396. translatedPromise.then(function (translatedFont) {
  56397. if (translatedFont.fontType !== undefined) {
  56398. var xrefFontStats = xref.stats.fontTypes;
  56399. xrefFontStats[translatedFont.fontType] = true;
  56400. }
  56401. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  56402. }, function (reason) {
  56403. // TODO fontCapability.reject?
  56404. // Error in the font data -- sending unsupported feature notification.
  56405. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  56406. try {
  56407. // error, but it's still nice to have font type reported
  56408. var descriptor = preEvaluatedFont.descriptor;
  56409. var fontFile3 = descriptor && descriptor.get('FontFile3');
  56410. var subtype = fontFile3 && fontFile3.get('Subtype');
  56411. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  56412. var xrefFontStats = xref.stats.fontTypes;
  56413. xrefFontStats[fontType] = true;
  56414. } catch (ex) {
  56415. }
  56416. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  56417. });
  56418. return fontCapability.promise;
  56419. },
  56420. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  56421. var lastIndex = operatorList.length - 1;
  56422. if (!args) {
  56423. args = [];
  56424. }
  56425. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  56426. operatorList.addOp(OPS.constructPath, [
  56427. [fn],
  56428. args
  56429. ]);
  56430. } else {
  56431. var opArgs = operatorList.argsArray[lastIndex];
  56432. opArgs[0].push(fn);
  56433. Array.prototype.push.apply(opArgs[1], args);
  56434. }
  56435. },
  56436. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  56437. // compile tiling patterns
  56438. var patternName = args[args.length - 1];
  56439. // SCN/scn applies patterns along with normal colors
  56440. var pattern;
  56441. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  56442. var dict = isStream(pattern) ? pattern.dict : pattern;
  56443. var typeNum = dict.get('PatternType');
  56444. if (typeNum === TILING_PATTERN) {
  56445. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  56446. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  56447. } else if (typeNum === SHADING_PATTERN) {
  56448. var shading = dict.get('Shading');
  56449. var matrix = dict.getArray('Matrix');
  56450. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  56451. operatorList.addOp(fn, pattern.getIR());
  56452. return Promise.resolve();
  56453. } else {
  56454. return Promise.reject('Unknown PatternType: ' + typeNum);
  56455. }
  56456. }
  56457. // TODO shall we fail here?
  56458. operatorList.addOp(fn, args);
  56459. return Promise.resolve();
  56460. },
  56461. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  56462. var self = this;
  56463. var xref = this.xref;
  56464. var imageCache = Object.create(null);
  56465. assert(operatorList);
  56466. resources = resources || Dict.empty;
  56467. var xobjs = resources.get('XObject') || Dict.empty;
  56468. var patterns = resources.get('Pattern') || Dict.empty;
  56469. var stateManager = new StateManager(initialState || new EvalState());
  56470. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  56471. var timeSlotManager = new TimeSlotManager();
  56472. return new Promise(function promiseBody(resolve, reject) {
  56473. var next = function (promise) {
  56474. promise.then(function () {
  56475. try {
  56476. promiseBody(resolve, reject);
  56477. } catch (ex) {
  56478. reject(ex);
  56479. }
  56480. }, reject);
  56481. };
  56482. task.ensureNotTerminated();
  56483. timeSlotManager.reset();
  56484. var stop, operation = {}, i, ii, cs;
  56485. while (!(stop = timeSlotManager.check())) {
  56486. // The arguments parsed by read() are used beyond this loop, so we
  56487. // cannot reuse the same array on each iteration. Therefore we pass
  56488. // in |null| as the initial value (see the comment on
  56489. // EvaluatorPreprocessor_read() for why).
  56490. operation.args = null;
  56491. if (!preprocessor.read(operation)) {
  56492. break;
  56493. }
  56494. var args = operation.args;
  56495. var fn = operation.fn;
  56496. switch (fn | 0) {
  56497. case OPS.paintXObject:
  56498. if (args[0].code) {
  56499. break;
  56500. }
  56501. // eagerly compile XForm objects
  56502. var name = args[0].name;
  56503. if (!name) {
  56504. warn('XObject must be referred to by name.');
  56505. continue;
  56506. }
  56507. if (imageCache[name] !== undefined) {
  56508. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  56509. args = null;
  56510. continue;
  56511. }
  56512. var xobj = xobjs.get(name);
  56513. if (xobj) {
  56514. assert(isStream(xobj), 'XObject should be a stream');
  56515. var type = xobj.dict.get('Subtype');
  56516. assert(isName(type), 'XObject should have a Name subtype');
  56517. if (type.name === 'Form') {
  56518. stateManager.save();
  56519. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  56520. stateManager.restore();
  56521. }));
  56522. return;
  56523. } else if (type.name === 'Image') {
  56524. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  56525. args = null;
  56526. continue;
  56527. } else if (type.name === 'PS') {
  56528. // PostScript XObjects are unused when viewing documents.
  56529. // See section 4.7.1 of Adobe's PDF reference.
  56530. info('Ignored XObject subtype PS');
  56531. continue;
  56532. } else {
  56533. error('Unhandled XObject subtype ' + type.name);
  56534. }
  56535. }
  56536. break;
  56537. case OPS.setFont:
  56538. var fontSize = args[1];
  56539. // eagerly collect all fonts
  56540. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  56541. operatorList.addDependency(loadedName);
  56542. operatorList.addOp(OPS.setFont, [
  56543. loadedName,
  56544. fontSize
  56545. ]);
  56546. }));
  56547. return;
  56548. case OPS.endInlineImage:
  56549. var cacheKey = args[0].cacheKey;
  56550. if (cacheKey) {
  56551. var cacheEntry = imageCache[cacheKey];
  56552. if (cacheEntry !== undefined) {
  56553. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  56554. args = null;
  56555. continue;
  56556. }
  56557. }
  56558. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  56559. args = null;
  56560. continue;
  56561. case OPS.showText:
  56562. args[0] = self.handleText(args[0], stateManager.state);
  56563. break;
  56564. case OPS.showSpacedText:
  56565. var arr = args[0];
  56566. var combinedGlyphs = [];
  56567. var arrLength = arr.length;
  56568. var state = stateManager.state;
  56569. for (i = 0; i < arrLength; ++i) {
  56570. var arrItem = arr[i];
  56571. if (isString(arrItem)) {
  56572. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  56573. } else if (isNum(arrItem)) {
  56574. combinedGlyphs.push(arrItem);
  56575. }
  56576. }
  56577. args[0] = combinedGlyphs;
  56578. fn = OPS.showText;
  56579. break;
  56580. case OPS.nextLineShowText:
  56581. operatorList.addOp(OPS.nextLine);
  56582. args[0] = self.handleText(args[0], stateManager.state);
  56583. fn = OPS.showText;
  56584. break;
  56585. case OPS.nextLineSetSpacingShowText:
  56586. operatorList.addOp(OPS.nextLine);
  56587. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  56588. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  56589. args[0] = self.handleText(args[0], stateManager.state);
  56590. fn = OPS.showText;
  56591. break;
  56592. case OPS.setTextRenderingMode:
  56593. stateManager.state.textRenderingMode = args[0];
  56594. break;
  56595. case OPS.setFillColorSpace:
  56596. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  56597. continue;
  56598. case OPS.setStrokeColorSpace:
  56599. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  56600. continue;
  56601. case OPS.setFillColor:
  56602. cs = stateManager.state.fillColorSpace;
  56603. args = cs.getRgb(args, 0);
  56604. fn = OPS.setFillRGBColor;
  56605. break;
  56606. case OPS.setStrokeColor:
  56607. cs = stateManager.state.strokeColorSpace;
  56608. args = cs.getRgb(args, 0);
  56609. fn = OPS.setStrokeRGBColor;
  56610. break;
  56611. case OPS.setFillGray:
  56612. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  56613. args = ColorSpace.singletons.gray.getRgb(args, 0);
  56614. fn = OPS.setFillRGBColor;
  56615. break;
  56616. case OPS.setStrokeGray:
  56617. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  56618. args = ColorSpace.singletons.gray.getRgb(args, 0);
  56619. fn = OPS.setStrokeRGBColor;
  56620. break;
  56621. case OPS.setFillCMYKColor:
  56622. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  56623. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  56624. fn = OPS.setFillRGBColor;
  56625. break;
  56626. case OPS.setStrokeCMYKColor:
  56627. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  56628. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  56629. fn = OPS.setStrokeRGBColor;
  56630. break;
  56631. case OPS.setFillRGBColor:
  56632. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  56633. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  56634. break;
  56635. case OPS.setStrokeRGBColor:
  56636. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  56637. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  56638. break;
  56639. case OPS.setFillColorN:
  56640. cs = stateManager.state.fillColorSpace;
  56641. if (cs.name === 'Pattern') {
  56642. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  56643. return;
  56644. }
  56645. args = cs.getRgb(args, 0);
  56646. fn = OPS.setFillRGBColor;
  56647. break;
  56648. case OPS.setStrokeColorN:
  56649. cs = stateManager.state.strokeColorSpace;
  56650. if (cs.name === 'Pattern') {
  56651. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  56652. return;
  56653. }
  56654. args = cs.getRgb(args, 0);
  56655. fn = OPS.setStrokeRGBColor;
  56656. break;
  56657. case OPS.shadingFill:
  56658. var shadingRes = resources.get('Shading');
  56659. if (!shadingRes) {
  56660. error('No shading resource found');
  56661. }
  56662. var shading = shadingRes.get(args[0].name);
  56663. if (!shading) {
  56664. error('No shading object found');
  56665. }
  56666. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  56667. var patternIR = shadingFill.getIR();
  56668. args = [patternIR];
  56669. fn = OPS.shadingFill;
  56670. break;
  56671. case OPS.setGState:
  56672. var dictName = args[0];
  56673. var extGState = resources.get('ExtGState');
  56674. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  56675. break;
  56676. }
  56677. var gState = extGState.get(dictName.name);
  56678. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  56679. return;
  56680. case OPS.moveTo:
  56681. case OPS.lineTo:
  56682. case OPS.curveTo:
  56683. case OPS.curveTo2:
  56684. case OPS.curveTo3:
  56685. case OPS.closePath:
  56686. self.buildPath(operatorList, fn, args);
  56687. continue;
  56688. case OPS.rectangle:
  56689. self.buildPath(operatorList, fn, args);
  56690. continue;
  56691. case OPS.markPoint:
  56692. case OPS.markPointProps:
  56693. case OPS.beginMarkedContent:
  56694. case OPS.beginMarkedContentProps:
  56695. case OPS.endMarkedContent:
  56696. case OPS.beginCompat:
  56697. case OPS.endCompat:
  56698. // Ignore operators where the corresponding handlers are known to
  56699. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  56700. // serialization errors and is also a bit more efficient.
  56701. // We could also try to serialize all objects in a general way,
  56702. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  56703. // but doing so is meaningless without knowing the semantics.
  56704. continue;
  56705. default:
  56706. // Note: Ignore the operator if it has `Dict` arguments, since
  56707. // those are non-serializable, otherwise postMessage will throw
  56708. // "An object could not be cloned.".
  56709. if (args !== null) {
  56710. for (i = 0, ii = args.length; i < ii; i++) {
  56711. if (args[i] instanceof Dict) {
  56712. break;
  56713. }
  56714. }
  56715. if (i < ii) {
  56716. warn('getOperatorList - ignoring operator: ' + fn);
  56717. continue;
  56718. }
  56719. }
  56720. }
  56721. operatorList.addOp(fn, args);
  56722. }
  56723. if (stop) {
  56724. next(deferred);
  56725. return;
  56726. }
  56727. // Some PDFs don't close all restores inside object/form.
  56728. // Closing those for them.
  56729. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  56730. operatorList.addOp(OPS.restore, []);
  56731. }
  56732. resolve();
  56733. });
  56734. },
  56735. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  56736. stateManager = stateManager || new StateManager(new TextState());
  56737. var WhitespaceRegexp = /\s/g;
  56738. var textContent = {
  56739. items: [],
  56740. styles: Object.create(null)
  56741. };
  56742. var textContentItem = {
  56743. initialized: false,
  56744. str: [],
  56745. width: 0,
  56746. height: 0,
  56747. vertical: false,
  56748. lastAdvanceWidth: 0,
  56749. lastAdvanceHeight: 0,
  56750. textAdvanceScale: 0,
  56751. spaceWidth: 0,
  56752. fakeSpaceMin: Infinity,
  56753. fakeMultiSpaceMin: Infinity,
  56754. fakeMultiSpaceMax: -0,
  56755. textRunBreakAllowed: false,
  56756. transform: null,
  56757. fontName: null
  56758. };
  56759. var SPACE_FACTOR = 0.3;
  56760. var MULTI_SPACE_FACTOR = 1.5;
  56761. var MULTI_SPACE_FACTOR_MAX = 4;
  56762. var self = this;
  56763. var xref = this.xref;
  56764. resources = xref.fetchIfRef(resources) || Dict.empty;
  56765. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  56766. var xobjs = null;
  56767. var xobjsCache = Object.create(null);
  56768. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  56769. var textState;
  56770. function ensureTextContentItem() {
  56771. if (textContentItem.initialized) {
  56772. return textContentItem;
  56773. }
  56774. var font = textState.font;
  56775. if (!(font.loadedName in textContent.styles)) {
  56776. textContent.styles[font.loadedName] = {
  56777. fontFamily: font.fallbackName,
  56778. ascent: font.ascent,
  56779. descent: font.descent,
  56780. vertical: font.vertical
  56781. };
  56782. }
  56783. textContentItem.fontName = font.loadedName;
  56784. // 9.4.4 Text Space Details
  56785. var tsm = [
  56786. textState.fontSize * textState.textHScale,
  56787. 0,
  56788. 0,
  56789. textState.fontSize,
  56790. 0,
  56791. textState.textRise
  56792. ];
  56793. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  56794. var glyphHeight = font.bbox[3] - font.bbox[1];
  56795. if (glyphHeight > 0) {
  56796. glyphHeight = glyphHeight * textState.fontMatrix[3];
  56797. tsm[3] *= glyphHeight;
  56798. }
  56799. }
  56800. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  56801. textContentItem.transform = trm;
  56802. if (!font.vertical) {
  56803. textContentItem.width = 0;
  56804. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  56805. textContentItem.vertical = false;
  56806. } else {
  56807. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  56808. textContentItem.height = 0;
  56809. textContentItem.vertical = true;
  56810. }
  56811. var a = textState.textLineMatrix[0];
  56812. var b = textState.textLineMatrix[1];
  56813. var scaleLineX = Math.sqrt(a * a + b * b);
  56814. a = textState.ctm[0];
  56815. b = textState.ctm[1];
  56816. var scaleCtmX = Math.sqrt(a * a + b * b);
  56817. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  56818. textContentItem.lastAdvanceWidth = 0;
  56819. textContentItem.lastAdvanceHeight = 0;
  56820. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  56821. if (spaceWidth) {
  56822. textContentItem.spaceWidth = spaceWidth;
  56823. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  56824. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  56825. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  56826. // It's okay for monospace fonts to fake as much space as needed.
  56827. textContentItem.textRunBreakAllowed = !font.isMonospace;
  56828. } else {
  56829. textContentItem.spaceWidth = 0;
  56830. textContentItem.fakeSpaceMin = Infinity;
  56831. textContentItem.fakeMultiSpaceMin = Infinity;
  56832. textContentItem.fakeMultiSpaceMax = 0;
  56833. textContentItem.textRunBreakAllowed = false;
  56834. }
  56835. textContentItem.initialized = true;
  56836. return textContentItem;
  56837. }
  56838. function replaceWhitespace(str) {
  56839. // Replaces all whitespaces with standard spaces (0x20), to avoid
  56840. // alignment issues between the textLayer and the canvas if the text
  56841. // contains e.g. tabs (fixes issue6612.pdf).
  56842. var i = 0, ii = str.length, code;
  56843. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  56844. i++;
  56845. }
  56846. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  56847. }
  56848. function runBidiTransform(textChunk) {
  56849. var str = textChunk.str.join('');
  56850. var bidiResult = bidi(str, -1, textChunk.vertical);
  56851. return {
  56852. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  56853. dir: bidiResult.dir,
  56854. width: textChunk.width,
  56855. height: textChunk.height,
  56856. transform: textChunk.transform,
  56857. fontName: textChunk.fontName
  56858. };
  56859. }
  56860. function handleSetFont(fontName, fontRef) {
  56861. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  56862. textState.font = translated.font;
  56863. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  56864. });
  56865. }
  56866. function buildTextContentItem(chars) {
  56867. var font = textState.font;
  56868. var textChunk = ensureTextContentItem();
  56869. var width = 0;
  56870. var height = 0;
  56871. var glyphs = font.charsToGlyphs(chars);
  56872. var defaultVMetrics = font.defaultVMetrics;
  56873. for (var i = 0; i < glyphs.length; i++) {
  56874. var glyph = glyphs[i];
  56875. var vMetricX = null;
  56876. var vMetricY = null;
  56877. var glyphWidth = null;
  56878. if (font.vertical) {
  56879. if (glyph.vmetric) {
  56880. glyphWidth = glyph.vmetric[0];
  56881. vMetricX = glyph.vmetric[1];
  56882. vMetricY = glyph.vmetric[2];
  56883. } else {
  56884. glyphWidth = glyph.width;
  56885. vMetricX = glyph.width * 0.5;
  56886. vMetricY = defaultVMetrics[2];
  56887. }
  56888. } else {
  56889. glyphWidth = glyph.width;
  56890. }
  56891. var glyphUnicode = glyph.unicode;
  56892. var NormalizedUnicodes = getNormalizedUnicodes();
  56893. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  56894. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  56895. }
  56896. glyphUnicode = reverseIfRtl(glyphUnicode);
  56897. // The following will calculate the x and y of the individual glyphs.
  56898. // if (font.vertical) {
  56899. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  56900. // textState.fontMatrix[0];
  56901. // tsm[5] -= vMetricY * textState.fontSize *
  56902. // textState.fontMatrix[0];
  56903. // }
  56904. // var trm = Util.transform(textState.textMatrix, tsm);
  56905. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  56906. // var x = pt[0];
  56907. // var y = pt[1];
  56908. var charSpacing = textState.charSpacing;
  56909. if (glyph.isSpace) {
  56910. var wordSpacing = textState.wordSpacing;
  56911. charSpacing += wordSpacing;
  56912. if (wordSpacing > 0) {
  56913. addFakeSpaces(wordSpacing, textChunk.str);
  56914. }
  56915. }
  56916. var tx = 0;
  56917. var ty = 0;
  56918. if (!font.vertical) {
  56919. var w0 = glyphWidth * textState.fontMatrix[0];
  56920. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  56921. width += tx;
  56922. } else {
  56923. var w1 = glyphWidth * textState.fontMatrix[0];
  56924. ty = w1 * textState.fontSize + charSpacing;
  56925. height += ty;
  56926. }
  56927. textState.translateTextMatrix(tx, ty);
  56928. textChunk.str.push(glyphUnicode);
  56929. }
  56930. if (!font.vertical) {
  56931. textChunk.lastAdvanceWidth = width;
  56932. textChunk.width += width * textChunk.textAdvanceScale;
  56933. } else {
  56934. textChunk.lastAdvanceHeight = height;
  56935. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  56936. }
  56937. return textChunk;
  56938. }
  56939. function addFakeSpaces(width, strBuf) {
  56940. if (width < textContentItem.fakeSpaceMin) {
  56941. return;
  56942. }
  56943. if (width < textContentItem.fakeMultiSpaceMin) {
  56944. strBuf.push(' ');
  56945. return;
  56946. }
  56947. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  56948. while (fakeSpaces-- > 0) {
  56949. strBuf.push(' ');
  56950. }
  56951. }
  56952. function flushTextContentItem() {
  56953. if (!textContentItem.initialized) {
  56954. return;
  56955. }
  56956. textContent.items.push(runBidiTransform(textContentItem));
  56957. textContentItem.initialized = false;
  56958. textContentItem.str.length = 0;
  56959. }
  56960. var timeSlotManager = new TimeSlotManager();
  56961. return new Promise(function promiseBody(resolve, reject) {
  56962. var next = function (promise) {
  56963. promise.then(function () {
  56964. try {
  56965. promiseBody(resolve, reject);
  56966. } catch (ex) {
  56967. reject(ex);
  56968. }
  56969. }, reject);
  56970. };
  56971. task.ensureNotTerminated();
  56972. timeSlotManager.reset();
  56973. var stop, operation = {}, args = [];
  56974. while (!(stop = timeSlotManager.check())) {
  56975. // The arguments parsed by read() are not used beyond this loop, so
  56976. // we can reuse the same array on every iteration, thus avoiding
  56977. // unnecessary allocations.
  56978. args.length = 0;
  56979. operation.args = args;
  56980. if (!preprocessor.read(operation)) {
  56981. break;
  56982. }
  56983. textState = stateManager.state;
  56984. var fn = operation.fn;
  56985. args = operation.args;
  56986. var advance, diff;
  56987. switch (fn | 0) {
  56988. case OPS.setFont:
  56989. // Optimization to ignore multiple identical Tf commands.
  56990. var fontNameArg = args[0].name, fontSizeArg = args[1];
  56991. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  56992. break;
  56993. }
  56994. flushTextContentItem();
  56995. textState.fontName = fontNameArg;
  56996. textState.fontSize = fontSizeArg;
  56997. next(handleSetFont(fontNameArg, null));
  56998. return;
  56999. case OPS.setTextRise:
  57000. flushTextContentItem();
  57001. textState.textRise = args[0];
  57002. break;
  57003. case OPS.setHScale:
  57004. flushTextContentItem();
  57005. textState.textHScale = args[0] / 100;
  57006. break;
  57007. case OPS.setLeading:
  57008. flushTextContentItem();
  57009. textState.leading = args[0];
  57010. break;
  57011. case OPS.moveText:
  57012. // Optimization to treat same line movement as advance
  57013. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  57014. advance = args[0] - args[1];
  57015. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  57016. textState.translateTextLineMatrix(args[0], args[1]);
  57017. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  57018. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  57019. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  57020. addFakeSpaces(diff, textContentItem.str);
  57021. break;
  57022. }
  57023. flushTextContentItem();
  57024. textState.translateTextLineMatrix(args[0], args[1]);
  57025. textState.textMatrix = textState.textLineMatrix.slice();
  57026. break;
  57027. case OPS.setLeadingMoveText:
  57028. flushTextContentItem();
  57029. textState.leading = -args[1];
  57030. textState.translateTextLineMatrix(args[0], args[1]);
  57031. textState.textMatrix = textState.textLineMatrix.slice();
  57032. break;
  57033. case OPS.nextLine:
  57034. flushTextContentItem();
  57035. textState.carriageReturn();
  57036. break;
  57037. case OPS.setTextMatrix:
  57038. // Optimization to treat same line movement as advance.
  57039. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  57040. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  57041. textState.translateTextLineMatrix(advance.width, advance.height);
  57042. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  57043. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  57044. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  57045. addFakeSpaces(diff, textContentItem.str);
  57046. break;
  57047. }
  57048. flushTextContentItem();
  57049. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  57050. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  57051. break;
  57052. case OPS.setCharSpacing:
  57053. textState.charSpacing = args[0];
  57054. break;
  57055. case OPS.setWordSpacing:
  57056. textState.wordSpacing = args[0];
  57057. break;
  57058. case OPS.beginText:
  57059. flushTextContentItem();
  57060. textState.textMatrix = IDENTITY_MATRIX.slice();
  57061. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  57062. break;
  57063. case OPS.showSpacedText:
  57064. var items = args[0];
  57065. var offset;
  57066. for (var j = 0, jj = items.length; j < jj; j++) {
  57067. if (typeof items[j] === 'string') {
  57068. buildTextContentItem(items[j]);
  57069. } else if (isNum(items[j])) {
  57070. ensureTextContentItem();
  57071. // PDF Specification 5.3.2 states:
  57072. // The number is expressed in thousandths of a unit of text
  57073. // space.
  57074. // This amount is subtracted from the current horizontal or
  57075. // vertical coordinate, depending on the writing mode.
  57076. // In the default coordinate system, a positive adjustment
  57077. // has the effect of moving the next glyph painted either to
  57078. // the left or down by the given amount.
  57079. advance = items[j] * textState.fontSize / 1000;
  57080. var breakTextRun = false;
  57081. if (textState.font.vertical) {
  57082. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  57083. textState.translateTextMatrix(0, advance);
  57084. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  57085. if (!breakTextRun) {
  57086. // Value needs to be added to height to paint down.
  57087. textContentItem.height += offset;
  57088. }
  57089. } else {
  57090. advance = -advance;
  57091. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  57092. textState.translateTextMatrix(advance, 0);
  57093. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  57094. if (!breakTextRun) {
  57095. // Value needs to be subtracted from width to paint left.
  57096. textContentItem.width += offset;
  57097. }
  57098. }
  57099. if (breakTextRun) {
  57100. flushTextContentItem();
  57101. } else if (advance > 0) {
  57102. addFakeSpaces(advance, textContentItem.str);
  57103. }
  57104. }
  57105. }
  57106. break;
  57107. case OPS.showText:
  57108. buildTextContentItem(args[0]);
  57109. break;
  57110. case OPS.nextLineShowText:
  57111. flushTextContentItem();
  57112. textState.carriageReturn();
  57113. buildTextContentItem(args[0]);
  57114. break;
  57115. case OPS.nextLineSetSpacingShowText:
  57116. flushTextContentItem();
  57117. textState.wordSpacing = args[0];
  57118. textState.charSpacing = args[1];
  57119. textState.carriageReturn();
  57120. buildTextContentItem(args[2]);
  57121. break;
  57122. case OPS.paintXObject:
  57123. flushTextContentItem();
  57124. if (args[0].code) {
  57125. break;
  57126. }
  57127. if (!xobjs) {
  57128. xobjs = resources.get('XObject') || Dict.empty;
  57129. }
  57130. var name = args[0].name;
  57131. if (xobjsCache.key === name) {
  57132. if (xobjsCache.texts) {
  57133. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  57134. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  57135. }
  57136. break;
  57137. }
  57138. var xobj = xobjs.get(name);
  57139. if (!xobj) {
  57140. break;
  57141. }
  57142. assert(isStream(xobj), 'XObject should be a stream');
  57143. var type = xobj.dict.get('Subtype');
  57144. assert(isName(type), 'XObject should have a Name subtype');
  57145. if ('Form' !== type.name) {
  57146. xobjsCache.key = name;
  57147. xobjsCache.texts = null;
  57148. break;
  57149. }
  57150. stateManager.save();
  57151. var matrix = xobj.dict.getArray('Matrix');
  57152. if (isArray(matrix) && matrix.length === 6) {
  57153. stateManager.transform(matrix);
  57154. }
  57155. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  57156. Util.appendToArray(textContent.items, formTextContent.items);
  57157. Util.extendObj(textContent.styles, formTextContent.styles);
  57158. stateManager.restore();
  57159. xobjsCache.key = name;
  57160. xobjsCache.texts = formTextContent;
  57161. }));
  57162. return;
  57163. case OPS.setGState:
  57164. flushTextContentItem();
  57165. var dictName = args[0];
  57166. var extGState = resources.get('ExtGState');
  57167. if (!isDict(extGState) || !isName(dictName)) {
  57168. break;
  57169. }
  57170. var gState = extGState.get(dictName.name);
  57171. if (!isDict(gState)) {
  57172. break;
  57173. }
  57174. var gStateFont = gState.get('Font');
  57175. if (gStateFont) {
  57176. textState.fontName = null;
  57177. textState.fontSize = gStateFont[1];
  57178. next(handleSetFont(null, gStateFont[0]));
  57179. return;
  57180. }
  57181. break;
  57182. }
  57183. }
  57184. // switch
  57185. // while
  57186. if (stop) {
  57187. next(deferred);
  57188. return;
  57189. }
  57190. flushTextContentItem();
  57191. resolve(textContent);
  57192. });
  57193. },
  57194. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  57195. // 9.10.2
  57196. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  57197. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  57198. if (properties.composite) {
  57199. // CIDSystemInfo helps to match CID to glyphs
  57200. var cidSystemInfo = dict.get('CIDSystemInfo');
  57201. if (isDict(cidSystemInfo)) {
  57202. properties.cidSystemInfo = {
  57203. registry: cidSystemInfo.get('Registry'),
  57204. ordering: cidSystemInfo.get('Ordering'),
  57205. supplement: cidSystemInfo.get('Supplement')
  57206. };
  57207. }
  57208. var cidToGidMap = dict.get('CIDToGIDMap');
  57209. if (isStream(cidToGidMap)) {
  57210. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  57211. }
  57212. }
  57213. // Based on 9.6.6 of the spec the encoding can come from multiple places
  57214. // and depends on the font type. The base encoding and differences are
  57215. // read here, but the encoding that is actually used is chosen during
  57216. // glyph mapping in the font.
  57217. // TODO: Loading the built in encoding in the font would allow the
  57218. // differences to be merged in here not require us to hold on to it.
  57219. var differences = [];
  57220. var baseEncodingName = null;
  57221. var encoding;
  57222. if (dict.has('Encoding')) {
  57223. encoding = dict.get('Encoding');
  57224. if (isDict(encoding)) {
  57225. baseEncodingName = encoding.get('BaseEncoding');
  57226. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  57227. // Load the differences between the base and original
  57228. if (encoding.has('Differences')) {
  57229. var diffEncoding = encoding.get('Differences');
  57230. var index = 0;
  57231. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  57232. var data = xref.fetchIfRef(diffEncoding[j]);
  57233. if (isNum(data)) {
  57234. index = data;
  57235. } else if (isName(data)) {
  57236. differences[index++] = data.name;
  57237. } else {
  57238. error('Invalid entry in \'Differences\' array: ' + data);
  57239. }
  57240. }
  57241. }
  57242. } else if (isName(encoding)) {
  57243. baseEncodingName = encoding.name;
  57244. } else {
  57245. error('Encoding is not a Name nor a Dict');
  57246. }
  57247. // According to table 114 if the encoding is a named encoding it must be
  57248. // one of these predefined encodings.
  57249. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  57250. baseEncodingName = null;
  57251. }
  57252. }
  57253. if (baseEncodingName) {
  57254. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  57255. } else {
  57256. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  57257. // The Symbolic attribute can be misused for regular fonts
  57258. // Heuristic: we have to check if the font is a standard one also
  57259. if (!!(properties.flags & FontFlags.Symbolic)) {
  57260. encoding = MacRomanEncoding;
  57261. if (!properties.file) {
  57262. if (/Symbol/i.test(properties.name)) {
  57263. encoding = SymbolSetEncoding;
  57264. } else if (/Dingbats/i.test(properties.name)) {
  57265. encoding = ZapfDingbatsEncoding;
  57266. }
  57267. }
  57268. }
  57269. properties.defaultEncoding = encoding;
  57270. }
  57271. properties.differences = differences;
  57272. properties.baseEncodingName = baseEncodingName;
  57273. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  57274. properties.dict = dict;
  57275. return toUnicodePromise.then(function (toUnicode) {
  57276. properties.toUnicode = toUnicode;
  57277. return this.buildToUnicode(properties);
  57278. }.bind(this)).then(function (toUnicode) {
  57279. properties.toUnicode = toUnicode;
  57280. return properties;
  57281. });
  57282. },
  57283. /**
  57284. * Builds a char code to unicode map based on section 9.10 of the spec.
  57285. * @param {Object} properties Font properties object.
  57286. * @return {Promise} A Promise that is resolved with a
  57287. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  57288. */
  57289. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  57290. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  57291. // Section 9.10.2 Mapping Character Codes to Unicode Values
  57292. if (properties.hasIncludedToUnicodeMap) {
  57293. return Promise.resolve(properties.toUnicode);
  57294. }
  57295. // According to the spec if the font is a simple font we should only map
  57296. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  57297. // the differences array only contains adobe standard or symbol set names,
  57298. // in pratice it seems better to always try to create a toUnicode
  57299. // map based of the default encoding.
  57300. var toUnicode, charcode, glyphName;
  57301. if (!properties.composite)
  57302. /* is simple font */
  57303. {
  57304. toUnicode = [];
  57305. var encoding = properties.defaultEncoding.slice();
  57306. var baseEncodingName = properties.baseEncodingName;
  57307. // Merge in the differences array.
  57308. var differences = properties.differences;
  57309. for (charcode in differences) {
  57310. glyphName = differences[charcode];
  57311. if (glyphName === '.notdef') {
  57312. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  57313. // where there should be spaces (fixes issue5256.pdf).
  57314. continue;
  57315. }
  57316. encoding[charcode] = glyphName;
  57317. }
  57318. var glyphsUnicodeMap = getGlyphsUnicode();
  57319. for (charcode in encoding) {
  57320. // a) Map the character code to a character name.
  57321. glyphName = encoding[charcode];
  57322. // b) Look up the character name in the Adobe Glyph List (see the
  57323. // Bibliography) to obtain the corresponding Unicode value.
  57324. if (glyphName === '') {
  57325. continue;
  57326. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  57327. // (undocumented) c) Few heuristics to recognize unknown glyphs
  57328. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  57329. var code = 0;
  57330. switch (glyphName[0]) {
  57331. case 'G':
  57332. // Gxx glyph
  57333. if (glyphName.length === 3) {
  57334. code = parseInt(glyphName.substr(1), 16);
  57335. }
  57336. break;
  57337. case 'g':
  57338. // g00xx glyph
  57339. if (glyphName.length === 5) {
  57340. code = parseInt(glyphName.substr(1), 16);
  57341. }
  57342. break;
  57343. case 'C':
  57344. // Cddd glyph
  57345. case 'c':
  57346. // cddd glyph
  57347. if (glyphName.length >= 3) {
  57348. code = +glyphName.substr(1);
  57349. }
  57350. break;
  57351. default:
  57352. // 'uniXXXX'/'uXXXX{XX}' glyphs
  57353. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  57354. if (unicode !== -1) {
  57355. code = unicode;
  57356. }
  57357. }
  57358. if (code) {
  57359. // If |baseEncodingName| is one the predefined encodings,
  57360. // and |code| equals |charcode|, using the glyph defined in the
  57361. // baseEncoding seems to yield a better |toUnicode| mapping
  57362. // (fixes issue 5070).
  57363. if (baseEncodingName && code === +charcode) {
  57364. var baseEncoding = getEncoding(baseEncodingName);
  57365. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  57366. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  57367. continue;
  57368. }
  57369. }
  57370. toUnicode[charcode] = String.fromCharCode(code);
  57371. }
  57372. continue;
  57373. }
  57374. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  57375. }
  57376. return Promise.resolve(new ToUnicodeMap(toUnicode));
  57377. }
  57378. // If the font is a composite font that uses one of the predefined CMaps
  57379. // listed in Table 118 (except Identity–H and Identity–V) or whose
  57380. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  57381. // Adobe-Korea1 character collection:
  57382. if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof IdentityCMap) || properties.cidSystemInfo.registry === 'Adobe' && (properties.cidSystemInfo.ordering === 'GB1' || properties.cidSystemInfo.ordering === 'CNS1' || properties.cidSystemInfo.ordering === 'Japan1' || properties.cidSystemInfo.ordering === 'Korea1'))) {
  57383. // Then:
  57384. // a) Map the character code to a character identifier (CID) according
  57385. // to the font’s CMap.
  57386. // b) Obtain the registry and ordering of the character collection used
  57387. // by the font’s CMap (for example, Adobe and Japan1) from its
  57388. // CIDSystemInfo dictionary.
  57389. var registry = properties.cidSystemInfo.registry;
  57390. var ordering = properties.cidSystemInfo.ordering;
  57391. // c) Construct a second CMap name by concatenating the registry and
  57392. // ordering obtained in step (b) in the format registry–ordering–UCS2
  57393. // (for example, Adobe–Japan1–UCS2).
  57394. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  57395. // d) Obtain the CMap with the name constructed in step (c) (available
  57396. // from the ASN Web site; see the Bibliography).
  57397. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  57398. var cMap = properties.cMap;
  57399. toUnicode = [];
  57400. cMap.forEach(function (charcode, cid) {
  57401. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  57402. // e) Map the CID obtained in step (a) according to the CMap
  57403. // obtained in step (d), producing a Unicode value.
  57404. var ucs2 = ucs2CMap.lookup(cid);
  57405. if (ucs2) {
  57406. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  57407. }
  57408. });
  57409. return new ToUnicodeMap(toUnicode);
  57410. });
  57411. }
  57412. // The viewer's choice, just use an identity map.
  57413. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  57414. },
  57415. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  57416. var cmapObj = toUnicode;
  57417. if (isName(cmapObj)) {
  57418. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  57419. if (cmap instanceof IdentityCMap) {
  57420. return new IdentityToUnicodeMap(0, 0xFFFF);
  57421. }
  57422. return new ToUnicodeMap(cmap.getMap());
  57423. });
  57424. } else if (isStream(cmapObj)) {
  57425. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  57426. if (cmap instanceof IdentityCMap) {
  57427. return new IdentityToUnicodeMap(0, 0xFFFF);
  57428. }
  57429. var map = new Array(cmap.length);
  57430. // Convert UTF-16BE
  57431. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  57432. // to iterate over all keys.
  57433. cmap.forEach(function (charCode, token) {
  57434. var str = [];
  57435. for (var k = 0; k < token.length; k += 2) {
  57436. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  57437. if ((w1 & 0xF800) !== 0xD800) {
  57438. // w1 < 0xD800 || w1 > 0xDFFF
  57439. str.push(w1);
  57440. continue;
  57441. }
  57442. k += 2;
  57443. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  57444. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  57445. }
  57446. map[charCode] = String.fromCharCode.apply(String, str);
  57447. });
  57448. return new ToUnicodeMap(map);
  57449. });
  57450. }
  57451. return Promise.resolve(null);
  57452. },
  57453. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  57454. // Extract the encoding from the CIDToGIDMap
  57455. var glyphsData = cidToGidStream.getBytes();
  57456. // Set encoding 0 to later verify the font has an encoding
  57457. var result = [];
  57458. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  57459. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  57460. if (glyphID === 0) {
  57461. continue;
  57462. }
  57463. var code = j >> 1;
  57464. result[code] = glyphID;
  57465. }
  57466. return result;
  57467. },
  57468. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  57469. var glyphsWidths = [];
  57470. var defaultWidth = 0;
  57471. var glyphsVMetrics = [];
  57472. var defaultVMetrics;
  57473. var i, ii, j, jj, start, code, widths;
  57474. if (properties.composite) {
  57475. defaultWidth = dict.get('DW') || 1000;
  57476. widths = dict.get('W');
  57477. if (widths) {
  57478. for (i = 0, ii = widths.length; i < ii; i++) {
  57479. start = widths[i++];
  57480. code = xref.fetchIfRef(widths[i]);
  57481. if (isArray(code)) {
  57482. for (j = 0, jj = code.length; j < jj; j++) {
  57483. glyphsWidths[start++] = code[j];
  57484. }
  57485. } else {
  57486. var width = widths[++i];
  57487. for (j = start; j <= code; j++) {
  57488. glyphsWidths[j] = width;
  57489. }
  57490. }
  57491. }
  57492. }
  57493. if (properties.vertical) {
  57494. var vmetrics = dict.get('DW2') || [
  57495. 880,
  57496. -1000
  57497. ];
  57498. defaultVMetrics = [
  57499. vmetrics[1],
  57500. defaultWidth * 0.5,
  57501. vmetrics[0]
  57502. ];
  57503. vmetrics = dict.get('W2');
  57504. if (vmetrics) {
  57505. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  57506. start = vmetrics[i++];
  57507. code = xref.fetchIfRef(vmetrics[i]);
  57508. if (isArray(code)) {
  57509. for (j = 0, jj = code.length; j < jj; j++) {
  57510. glyphsVMetrics[start++] = [
  57511. code[j++],
  57512. code[j++],
  57513. code[j]
  57514. ];
  57515. }
  57516. } else {
  57517. var vmetric = [
  57518. vmetrics[++i],
  57519. vmetrics[++i],
  57520. vmetrics[++i]
  57521. ];
  57522. for (j = start; j <= code; j++) {
  57523. glyphsVMetrics[j] = vmetric;
  57524. }
  57525. }
  57526. }
  57527. }
  57528. }
  57529. } else {
  57530. var firstChar = properties.firstChar;
  57531. widths = dict.get('Widths');
  57532. if (widths) {
  57533. j = firstChar;
  57534. for (i = 0, ii = widths.length; i < ii; i++) {
  57535. glyphsWidths[j++] = widths[i];
  57536. }
  57537. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  57538. } else {
  57539. // Trying get the BaseFont metrics (see comment above).
  57540. var baseFontName = dict.get('BaseFont');
  57541. if (isName(baseFontName)) {
  57542. var metrics = this.getBaseFontMetrics(baseFontName.name);
  57543. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  57544. defaultWidth = metrics.defaultWidth;
  57545. }
  57546. }
  57547. }
  57548. // Heuristic: detection of monospace font by checking all non-zero widths
  57549. var isMonospace = true;
  57550. var firstWidth = defaultWidth;
  57551. for (var glyph in glyphsWidths) {
  57552. var glyphWidth = glyphsWidths[glyph];
  57553. if (!glyphWidth) {
  57554. continue;
  57555. }
  57556. if (!firstWidth) {
  57557. firstWidth = glyphWidth;
  57558. continue;
  57559. }
  57560. if (firstWidth !== glyphWidth) {
  57561. isMonospace = false;
  57562. break;
  57563. }
  57564. }
  57565. if (isMonospace) {
  57566. properties.flags |= FontFlags.FixedPitch;
  57567. }
  57568. properties.defaultWidth = defaultWidth;
  57569. properties.widths = glyphsWidths;
  57570. properties.defaultVMetrics = defaultVMetrics;
  57571. properties.vmetrics = glyphsVMetrics;
  57572. },
  57573. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  57574. // Simulating descriptor flags attribute
  57575. var fontNameWoStyle = baseFontName.split('-')[0];
  57576. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  57577. },
  57578. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  57579. var defaultWidth = 0;
  57580. var widths = [];
  57581. var monospace = false;
  57582. var stdFontMap = getStdFontMap();
  57583. var lookupName = stdFontMap[name] || name;
  57584. var Metrics = getMetrics();
  57585. if (!(lookupName in Metrics)) {
  57586. // Use default fonts for looking up font metrics if the passed
  57587. // font is not a base font
  57588. if (this.isSerifFont(name)) {
  57589. lookupName = 'Times-Roman';
  57590. } else {
  57591. lookupName = 'Helvetica';
  57592. }
  57593. }
  57594. var glyphWidths = Metrics[lookupName];
  57595. if (isNum(glyphWidths)) {
  57596. defaultWidth = glyphWidths;
  57597. monospace = true;
  57598. } else {
  57599. widths = glyphWidths();
  57600. }
  57601. // expand lazy widths array
  57602. return {
  57603. defaultWidth: defaultWidth,
  57604. monospace: monospace,
  57605. widths: widths
  57606. };
  57607. },
  57608. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  57609. var widths = Object.create(null);
  57610. var differences = properties.differences;
  57611. var encoding = properties.defaultEncoding;
  57612. for (var charCode = 0; charCode < 256; charCode++) {
  57613. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  57614. widths[charCode] = widthsByGlyphName[differences[charCode]];
  57615. continue;
  57616. }
  57617. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  57618. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  57619. continue;
  57620. }
  57621. }
  57622. return widths;
  57623. },
  57624. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  57625. var baseDict = dict;
  57626. var type = dict.get('Subtype');
  57627. assert(isName(type), 'invalid font Subtype');
  57628. var composite = false;
  57629. var uint8array;
  57630. if (type.name === 'Type0') {
  57631. // If font is a composite
  57632. // - get the descendant font
  57633. // - set the type according to the descendant font
  57634. // - get the FontDescriptor from the descendant font
  57635. var df = dict.get('DescendantFonts');
  57636. if (!df) {
  57637. error('Descendant fonts are not specified');
  57638. }
  57639. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  57640. type = dict.get('Subtype');
  57641. assert(isName(type), 'invalid font Subtype');
  57642. composite = true;
  57643. }
  57644. var descriptor = dict.get('FontDescriptor');
  57645. if (descriptor) {
  57646. var hash = new MurmurHash3_64();
  57647. var encoding = baseDict.getRaw('Encoding');
  57648. if (isName(encoding)) {
  57649. hash.update(encoding.name);
  57650. } else if (isRef(encoding)) {
  57651. hash.update(encoding.toString());
  57652. } else if (isDict(encoding)) {
  57653. var keys = encoding.getKeys();
  57654. for (var i = 0, ii = keys.length; i < ii; i++) {
  57655. var entry = encoding.getRaw(keys[i]);
  57656. if (isName(entry)) {
  57657. hash.update(entry.name);
  57658. } else if (isRef(entry)) {
  57659. hash.update(entry.toString());
  57660. } else if (isArray(entry)) {
  57661. // 'Differences' entry.
  57662. // Ideally we should check the contents of the array, but to avoid
  57663. // parsing it here and then again in |extractDataStructures|,
  57664. // we only use the array length for now (fixes bug1157493.pdf).
  57665. hash.update(entry.length.toString());
  57666. }
  57667. }
  57668. }
  57669. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  57670. if (isStream(toUnicode)) {
  57671. var stream = toUnicode.str || toUnicode;
  57672. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  57673. hash.update(uint8array);
  57674. } else if (isName(toUnicode)) {
  57675. hash.update(toUnicode.name);
  57676. }
  57677. var widths = dict.get('Widths') || baseDict.get('Widths');
  57678. if (widths) {
  57679. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  57680. hash.update(uint8array);
  57681. }
  57682. }
  57683. return {
  57684. descriptor: descriptor,
  57685. dict: dict,
  57686. baseDict: baseDict,
  57687. composite: composite,
  57688. type: type.name,
  57689. hash: hash ? hash.hexdigest() : ''
  57690. };
  57691. },
  57692. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  57693. var baseDict = preEvaluatedFont.baseDict;
  57694. var dict = preEvaluatedFont.dict;
  57695. var composite = preEvaluatedFont.composite;
  57696. var descriptor = preEvaluatedFont.descriptor;
  57697. var type = preEvaluatedFont.type;
  57698. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  57699. var cMapOptions = this.options.cMapOptions;
  57700. var properties;
  57701. if (!descriptor) {
  57702. if (type === 'Type3') {
  57703. // FontDescriptor is only required for Type3 fonts when the document
  57704. // is a tagged pdf. Create a barbebones one to get by.
  57705. descriptor = new Dict(null);
  57706. descriptor.set('FontName', Name.get(type));
  57707. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  57708. } else {
  57709. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  57710. // FontDescriptor was not required.
  57711. // This case is here for compatibility.
  57712. var baseFontName = dict.get('BaseFont');
  57713. if (!isName(baseFontName)) {
  57714. error('Base font is not specified');
  57715. }
  57716. // Using base font name as a font name.
  57717. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  57718. var metrics = this.getBaseFontMetrics(baseFontName);
  57719. // Simulating descriptor flags attribute
  57720. var fontNameWoStyle = baseFontName.split('-')[0];
  57721. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  57722. properties = {
  57723. type: type,
  57724. name: baseFontName,
  57725. widths: metrics.widths,
  57726. defaultWidth: metrics.defaultWidth,
  57727. flags: flags,
  57728. firstChar: 0,
  57729. lastChar: maxCharIndex
  57730. };
  57731. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  57732. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  57733. return new Font(baseFontName, null, properties);
  57734. }.bind(this));
  57735. }
  57736. }
  57737. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  57738. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  57739. // to ignore this rule when a variant of a standard font is used.
  57740. // TODO Fill the width array depending on which of the base font this is
  57741. // a variant.
  57742. var firstChar = dict.get('FirstChar') || 0;
  57743. var lastChar = dict.get('LastChar') || maxCharIndex;
  57744. var fontName = descriptor.get('FontName');
  57745. var baseFont = dict.get('BaseFont');
  57746. // Some bad PDFs have a string as the font name.
  57747. if (isString(fontName)) {
  57748. fontName = Name.get(fontName);
  57749. }
  57750. if (isString(baseFont)) {
  57751. baseFont = Name.get(baseFont);
  57752. }
  57753. if (type !== 'Type3') {
  57754. var fontNameStr = fontName && fontName.name;
  57755. var baseFontStr = baseFont && baseFont.name;
  57756. if (fontNameStr !== baseFontStr) {
  57757. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  57758. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  57759. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  57760. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  57761. fontName = baseFont;
  57762. }
  57763. }
  57764. }
  57765. fontName = fontName || baseFont;
  57766. assert(isName(fontName), 'invalid font name');
  57767. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  57768. if (fontFile) {
  57769. if (fontFile.dict) {
  57770. var subtype = fontFile.dict.get('Subtype');
  57771. if (subtype) {
  57772. subtype = subtype.name;
  57773. }
  57774. var length1 = fontFile.dict.get('Length1');
  57775. var length2 = fontFile.dict.get('Length2');
  57776. var length3 = fontFile.dict.get('Length3');
  57777. }
  57778. }
  57779. properties = {
  57780. type: type,
  57781. name: fontName.name,
  57782. subtype: subtype,
  57783. file: fontFile,
  57784. length1: length1,
  57785. length2: length2,
  57786. length3: length3,
  57787. loadedName: baseDict.loadedName,
  57788. composite: composite,
  57789. wideChars: composite,
  57790. fixedPitch: false,
  57791. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  57792. firstChar: firstChar || 0,
  57793. lastChar: lastChar || maxCharIndex,
  57794. bbox: descriptor.getArray('FontBBox'),
  57795. ascent: descriptor.get('Ascent'),
  57796. descent: descriptor.get('Descent'),
  57797. xHeight: descriptor.get('XHeight'),
  57798. capHeight: descriptor.get('CapHeight'),
  57799. flags: descriptor.get('Flags'),
  57800. italicAngle: descriptor.get('ItalicAngle'),
  57801. coded: false
  57802. };
  57803. var cMapPromise;
  57804. if (composite) {
  57805. var cidEncoding = baseDict.get('Encoding');
  57806. if (isName(cidEncoding)) {
  57807. properties.cidEncoding = cidEncoding.name;
  57808. }
  57809. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  57810. properties.cMap = cMap;
  57811. properties.vertical = properties.cMap.vertical;
  57812. });
  57813. } else {
  57814. cMapPromise = Promise.resolve(undefined);
  57815. }
  57816. return cMapPromise.then(function () {
  57817. return this.extractDataStructures(dict, baseDict, xref, properties);
  57818. }.bind(this)).then(function (properties) {
  57819. this.extractWidths(dict, xref, descriptor, properties);
  57820. if (type === 'Type3') {
  57821. properties.isType3Font = true;
  57822. }
  57823. return new Font(fontName.name, fontFile, properties);
  57824. }.bind(this));
  57825. }
  57826. };
  57827. return PartialEvaluator;
  57828. }();
  57829. var TranslatedFont = function TranslatedFontClosure() {
  57830. function TranslatedFont(loadedName, font, dict) {
  57831. this.loadedName = loadedName;
  57832. this.font = font;
  57833. this.dict = dict;
  57834. this.type3Loaded = null;
  57835. this.sent = false;
  57836. }
  57837. TranslatedFont.prototype = {
  57838. send: function (handler) {
  57839. if (this.sent) {
  57840. return;
  57841. }
  57842. var fontData = this.font.exportData();
  57843. handler.send('commonobj', [
  57844. this.loadedName,
  57845. 'Font',
  57846. fontData
  57847. ]);
  57848. this.sent = true;
  57849. },
  57850. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  57851. assert(this.font.isType3Font);
  57852. if (this.type3Loaded) {
  57853. return this.type3Loaded;
  57854. }
  57855. var translatedFont = this.font;
  57856. var loadCharProcsPromise = Promise.resolve();
  57857. var charProcs = this.dict.get('CharProcs');
  57858. var fontResources = this.dict.get('Resources') || resources;
  57859. var charProcKeys = charProcs.getKeys();
  57860. var charProcOperatorList = Object.create(null);
  57861. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  57862. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  57863. var glyphStream = charProcs.get(key);
  57864. var operatorList = new OperatorList();
  57865. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  57866. charProcOperatorList[key] = operatorList.getIR();
  57867. // Add the dependencies to the parent operator list so they are
  57868. // resolved before sub operator list is executed synchronously.
  57869. parentOperatorList.addDependencies(operatorList.dependencies);
  57870. }, function (reason) {
  57871. warn('Type3 font resource \"' + key + '\" is not available');
  57872. var operatorList = new OperatorList();
  57873. charProcOperatorList[key] = operatorList.getIR();
  57874. });
  57875. }.bind(this, charProcKeys[i]));
  57876. }
  57877. this.type3Loaded = loadCharProcsPromise.then(function () {
  57878. translatedFont.charProcOperatorList = charProcOperatorList;
  57879. });
  57880. return this.type3Loaded;
  57881. }
  57882. };
  57883. return TranslatedFont;
  57884. }();
  57885. var OperatorList = function OperatorListClosure() {
  57886. var CHUNK_SIZE = 1000;
  57887. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  57888. // close to chunk size
  57889. function getTransfers(queue) {
  57890. var transfers = [];
  57891. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  57892. for (var i = 0, ii = queue.length; i < ii; i++) {
  57893. switch (fnArray[i]) {
  57894. case OPS.paintInlineImageXObject:
  57895. case OPS.paintInlineImageXObjectGroup:
  57896. case OPS.paintImageMaskXObject:
  57897. var arg = argsArray[i][0];
  57898. // first param in imgData
  57899. if (!arg.cached) {
  57900. transfers.push(arg.data.buffer);
  57901. }
  57902. break;
  57903. }
  57904. }
  57905. return transfers;
  57906. }
  57907. function OperatorList(intent, messageHandler, pageIndex) {
  57908. this.messageHandler = messageHandler;
  57909. this.fnArray = [];
  57910. this.argsArray = [];
  57911. this.dependencies = Object.create(null);
  57912. this._totalLength = 0;
  57913. this.pageIndex = pageIndex;
  57914. this.intent = intent;
  57915. }
  57916. OperatorList.prototype = {
  57917. get length() {
  57918. return this.argsArray.length;
  57919. },
  57920. /**
  57921. * @returns {number} The total length of the entire operator list,
  57922. * since `this.length === 0` after flushing.
  57923. */
  57924. get totalLength() {
  57925. return this._totalLength + this.length;
  57926. },
  57927. addOp: function (fn, args) {
  57928. this.fnArray.push(fn);
  57929. this.argsArray.push(args);
  57930. if (this.messageHandler) {
  57931. if (this.fnArray.length >= CHUNK_SIZE) {
  57932. this.flush();
  57933. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  57934. // heuristic to flush on boundary of restore or endText
  57935. this.flush();
  57936. }
  57937. }
  57938. },
  57939. addDependency: function (dependency) {
  57940. if (dependency in this.dependencies) {
  57941. return;
  57942. }
  57943. this.dependencies[dependency] = true;
  57944. this.addOp(OPS.dependency, [dependency]);
  57945. },
  57946. addDependencies: function (dependencies) {
  57947. for (var key in dependencies) {
  57948. this.addDependency(key);
  57949. }
  57950. },
  57951. addOpList: function (opList) {
  57952. Util.extendObj(this.dependencies, opList.dependencies);
  57953. for (var i = 0, ii = opList.length; i < ii; i++) {
  57954. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  57955. }
  57956. },
  57957. getIR: function () {
  57958. return {
  57959. fnArray: this.fnArray,
  57960. argsArray: this.argsArray,
  57961. length: this.length
  57962. };
  57963. },
  57964. flush: function (lastChunk) {
  57965. if (this.intent !== 'oplist') {
  57966. new QueueOptimizer().optimize(this);
  57967. }
  57968. var transfers = getTransfers(this);
  57969. var length = this.length;
  57970. this._totalLength += length;
  57971. this.messageHandler.send('RenderPageChunk', {
  57972. operatorList: {
  57973. fnArray: this.fnArray,
  57974. argsArray: this.argsArray,
  57975. lastChunk: lastChunk,
  57976. length: length
  57977. },
  57978. pageIndex: this.pageIndex,
  57979. intent: this.intent
  57980. }, transfers);
  57981. this.dependencies = Object.create(null);
  57982. this.fnArray.length = 0;
  57983. this.argsArray.length = 0;
  57984. }
  57985. };
  57986. return OperatorList;
  57987. }();
  57988. var StateManager = function StateManagerClosure() {
  57989. function StateManager(initialState) {
  57990. this.state = initialState;
  57991. this.stateStack = [];
  57992. }
  57993. StateManager.prototype = {
  57994. save: function () {
  57995. var old = this.state;
  57996. this.stateStack.push(this.state);
  57997. this.state = old.clone();
  57998. },
  57999. restore: function () {
  58000. var prev = this.stateStack.pop();
  58001. if (prev) {
  58002. this.state = prev;
  58003. }
  58004. },
  58005. transform: function (args) {
  58006. this.state.ctm = Util.transform(this.state.ctm, args);
  58007. }
  58008. };
  58009. return StateManager;
  58010. }();
  58011. var TextState = function TextStateClosure() {
  58012. function TextState() {
  58013. this.ctm = new Float32Array(IDENTITY_MATRIX);
  58014. this.fontName = null;
  58015. this.fontSize = 0;
  58016. this.font = null;
  58017. this.fontMatrix = FONT_IDENTITY_MATRIX;
  58018. this.textMatrix = IDENTITY_MATRIX.slice();
  58019. this.textLineMatrix = IDENTITY_MATRIX.slice();
  58020. this.charSpacing = 0;
  58021. this.wordSpacing = 0;
  58022. this.leading = 0;
  58023. this.textHScale = 1;
  58024. this.textRise = 0;
  58025. }
  58026. TextState.prototype = {
  58027. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  58028. var m = this.textMatrix;
  58029. m[0] = a;
  58030. m[1] = b;
  58031. m[2] = c;
  58032. m[3] = d;
  58033. m[4] = e;
  58034. m[5] = f;
  58035. },
  58036. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  58037. var m = this.textLineMatrix;
  58038. m[0] = a;
  58039. m[1] = b;
  58040. m[2] = c;
  58041. m[3] = d;
  58042. m[4] = e;
  58043. m[5] = f;
  58044. },
  58045. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  58046. var m = this.textMatrix;
  58047. m[4] = m[0] * x + m[2] * y + m[4];
  58048. m[5] = m[1] * x + m[3] * y + m[5];
  58049. },
  58050. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  58051. var m = this.textLineMatrix;
  58052. m[4] = m[0] * x + m[2] * y + m[4];
  58053. m[5] = m[1] * x + m[3] * y + m[5];
  58054. },
  58055. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  58056. var font = this.font;
  58057. if (!font) {
  58058. return null;
  58059. }
  58060. var m = this.textLineMatrix;
  58061. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  58062. return null;
  58063. }
  58064. var txDiff = e - m[4], tyDiff = f - m[5];
  58065. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  58066. return null;
  58067. }
  58068. var tx, ty, denominator = a * d - b * c;
  58069. if (font.vertical) {
  58070. tx = -tyDiff * c / denominator;
  58071. ty = tyDiff * a / denominator;
  58072. } else {
  58073. tx = txDiff * d / denominator;
  58074. ty = -txDiff * b / denominator;
  58075. }
  58076. return {
  58077. width: tx,
  58078. height: ty,
  58079. value: font.vertical ? ty : tx
  58080. };
  58081. },
  58082. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  58083. // 9.4.4 Text Space Details
  58084. var tsm = [
  58085. this.fontSize * this.textHScale,
  58086. 0,
  58087. 0,
  58088. this.fontSize,
  58089. 0,
  58090. this.textRise
  58091. ];
  58092. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  58093. },
  58094. carriageReturn: function TextState_carriageReturn() {
  58095. this.translateTextLineMatrix(0, -this.leading);
  58096. this.textMatrix = this.textLineMatrix.slice();
  58097. },
  58098. clone: function TextState_clone() {
  58099. var clone = Object.create(this);
  58100. clone.textMatrix = this.textMatrix.slice();
  58101. clone.textLineMatrix = this.textLineMatrix.slice();
  58102. clone.fontMatrix = this.fontMatrix.slice();
  58103. return clone;
  58104. }
  58105. };
  58106. return TextState;
  58107. }();
  58108. var EvalState = function EvalStateClosure() {
  58109. function EvalState() {
  58110. this.ctm = new Float32Array(IDENTITY_MATRIX);
  58111. this.font = null;
  58112. this.textRenderingMode = TextRenderingMode.FILL;
  58113. this.fillColorSpace = ColorSpace.singletons.gray;
  58114. this.strokeColorSpace = ColorSpace.singletons.gray;
  58115. }
  58116. EvalState.prototype = {
  58117. clone: function CanvasExtraState_clone() {
  58118. return Object.create(this);
  58119. }
  58120. };
  58121. return EvalState;
  58122. }();
  58123. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  58124. // Specifies properties for each command
  58125. //
  58126. // If variableArgs === true: [0, `numArgs`] expected
  58127. // If variableArgs === false: exactly `numArgs` expected
  58128. var getOPMap = getLookupTableFactory(function (t) {
  58129. // Graphic state
  58130. t['w'] = {
  58131. id: OPS.setLineWidth,
  58132. numArgs: 1,
  58133. variableArgs: false
  58134. };
  58135. t['J'] = {
  58136. id: OPS.setLineCap,
  58137. numArgs: 1,
  58138. variableArgs: false
  58139. };
  58140. t['j'] = {
  58141. id: OPS.setLineJoin,
  58142. numArgs: 1,
  58143. variableArgs: false
  58144. };
  58145. t['M'] = {
  58146. id: OPS.setMiterLimit,
  58147. numArgs: 1,
  58148. variableArgs: false
  58149. };
  58150. t['d'] = {
  58151. id: OPS.setDash,
  58152. numArgs: 2,
  58153. variableArgs: false
  58154. };
  58155. t['ri'] = {
  58156. id: OPS.setRenderingIntent,
  58157. numArgs: 1,
  58158. variableArgs: false
  58159. };
  58160. t['i'] = {
  58161. id: OPS.setFlatness,
  58162. numArgs: 1,
  58163. variableArgs: false
  58164. };
  58165. t['gs'] = {
  58166. id: OPS.setGState,
  58167. numArgs: 1,
  58168. variableArgs: false
  58169. };
  58170. t['q'] = {
  58171. id: OPS.save,
  58172. numArgs: 0,
  58173. variableArgs: false
  58174. };
  58175. t['Q'] = {
  58176. id: OPS.restore,
  58177. numArgs: 0,
  58178. variableArgs: false
  58179. };
  58180. t['cm'] = {
  58181. id: OPS.transform,
  58182. numArgs: 6,
  58183. variableArgs: false
  58184. };
  58185. // Path
  58186. t['m'] = {
  58187. id: OPS.moveTo,
  58188. numArgs: 2,
  58189. variableArgs: false
  58190. };
  58191. t['l'] = {
  58192. id: OPS.lineTo,
  58193. numArgs: 2,
  58194. variableArgs: false
  58195. };
  58196. t['c'] = {
  58197. id: OPS.curveTo,
  58198. numArgs: 6,
  58199. variableArgs: false
  58200. };
  58201. t['v'] = {
  58202. id: OPS.curveTo2,
  58203. numArgs: 4,
  58204. variableArgs: false
  58205. };
  58206. t['y'] = {
  58207. id: OPS.curveTo3,
  58208. numArgs: 4,
  58209. variableArgs: false
  58210. };
  58211. t['h'] = {
  58212. id: OPS.closePath,
  58213. numArgs: 0,
  58214. variableArgs: false
  58215. };
  58216. t['re'] = {
  58217. id: OPS.rectangle,
  58218. numArgs: 4,
  58219. variableArgs: false
  58220. };
  58221. t['S'] = {
  58222. id: OPS.stroke,
  58223. numArgs: 0,
  58224. variableArgs: false
  58225. };
  58226. t['s'] = {
  58227. id: OPS.closeStroke,
  58228. numArgs: 0,
  58229. variableArgs: false
  58230. };
  58231. t['f'] = {
  58232. id: OPS.fill,
  58233. numArgs: 0,
  58234. variableArgs: false
  58235. };
  58236. t['F'] = {
  58237. id: OPS.fill,
  58238. numArgs: 0,
  58239. variableArgs: false
  58240. };
  58241. t['f*'] = {
  58242. id: OPS.eoFill,
  58243. numArgs: 0,
  58244. variableArgs: false
  58245. };
  58246. t['B'] = {
  58247. id: OPS.fillStroke,
  58248. numArgs: 0,
  58249. variableArgs: false
  58250. };
  58251. t['B*'] = {
  58252. id: OPS.eoFillStroke,
  58253. numArgs: 0,
  58254. variableArgs: false
  58255. };
  58256. t['b'] = {
  58257. id: OPS.closeFillStroke,
  58258. numArgs: 0,
  58259. variableArgs: false
  58260. };
  58261. t['b*'] = {
  58262. id: OPS.closeEOFillStroke,
  58263. numArgs: 0,
  58264. variableArgs: false
  58265. };
  58266. t['n'] = {
  58267. id: OPS.endPath,
  58268. numArgs: 0,
  58269. variableArgs: false
  58270. };
  58271. // Clipping
  58272. t['W'] = {
  58273. id: OPS.clip,
  58274. numArgs: 0,
  58275. variableArgs: false
  58276. };
  58277. t['W*'] = {
  58278. id: OPS.eoClip,
  58279. numArgs: 0,
  58280. variableArgs: false
  58281. };
  58282. // Text
  58283. t['BT'] = {
  58284. id: OPS.beginText,
  58285. numArgs: 0,
  58286. variableArgs: false
  58287. };
  58288. t['ET'] = {
  58289. id: OPS.endText,
  58290. numArgs: 0,
  58291. variableArgs: false
  58292. };
  58293. t['Tc'] = {
  58294. id: OPS.setCharSpacing,
  58295. numArgs: 1,
  58296. variableArgs: false
  58297. };
  58298. t['Tw'] = {
  58299. id: OPS.setWordSpacing,
  58300. numArgs: 1,
  58301. variableArgs: false
  58302. };
  58303. t['Tz'] = {
  58304. id: OPS.setHScale,
  58305. numArgs: 1,
  58306. variableArgs: false
  58307. };
  58308. t['TL'] = {
  58309. id: OPS.setLeading,
  58310. numArgs: 1,
  58311. variableArgs: false
  58312. };
  58313. t['Tf'] = {
  58314. id: OPS.setFont,
  58315. numArgs: 2,
  58316. variableArgs: false
  58317. };
  58318. t['Tr'] = {
  58319. id: OPS.setTextRenderingMode,
  58320. numArgs: 1,
  58321. variableArgs: false
  58322. };
  58323. t['Ts'] = {
  58324. id: OPS.setTextRise,
  58325. numArgs: 1,
  58326. variableArgs: false
  58327. };
  58328. t['Td'] = {
  58329. id: OPS.moveText,
  58330. numArgs: 2,
  58331. variableArgs: false
  58332. };
  58333. t['TD'] = {
  58334. id: OPS.setLeadingMoveText,
  58335. numArgs: 2,
  58336. variableArgs: false
  58337. };
  58338. t['Tm'] = {
  58339. id: OPS.setTextMatrix,
  58340. numArgs: 6,
  58341. variableArgs: false
  58342. };
  58343. t['T*'] = {
  58344. id: OPS.nextLine,
  58345. numArgs: 0,
  58346. variableArgs: false
  58347. };
  58348. t['Tj'] = {
  58349. id: OPS.showText,
  58350. numArgs: 1,
  58351. variableArgs: false
  58352. };
  58353. t['TJ'] = {
  58354. id: OPS.showSpacedText,
  58355. numArgs: 1,
  58356. variableArgs: false
  58357. };
  58358. t['\''] = {
  58359. id: OPS.nextLineShowText,
  58360. numArgs: 1,
  58361. variableArgs: false
  58362. };
  58363. t['"'] = {
  58364. id: OPS.nextLineSetSpacingShowText,
  58365. numArgs: 3,
  58366. variableArgs: false
  58367. };
  58368. // Type3 fonts
  58369. t['d0'] = {
  58370. id: OPS.setCharWidth,
  58371. numArgs: 2,
  58372. variableArgs: false
  58373. };
  58374. t['d1'] = {
  58375. id: OPS.setCharWidthAndBounds,
  58376. numArgs: 6,
  58377. variableArgs: false
  58378. };
  58379. // Color
  58380. t['CS'] = {
  58381. id: OPS.setStrokeColorSpace,
  58382. numArgs: 1,
  58383. variableArgs: false
  58384. };
  58385. t['cs'] = {
  58386. id: OPS.setFillColorSpace,
  58387. numArgs: 1,
  58388. variableArgs: false
  58389. };
  58390. t['SC'] = {
  58391. id: OPS.setStrokeColor,
  58392. numArgs: 4,
  58393. variableArgs: true
  58394. };
  58395. t['SCN'] = {
  58396. id: OPS.setStrokeColorN,
  58397. numArgs: 33,
  58398. variableArgs: true
  58399. };
  58400. t['sc'] = {
  58401. id: OPS.setFillColor,
  58402. numArgs: 4,
  58403. variableArgs: true
  58404. };
  58405. t['scn'] = {
  58406. id: OPS.setFillColorN,
  58407. numArgs: 33,
  58408. variableArgs: true
  58409. };
  58410. t['G'] = {
  58411. id: OPS.setStrokeGray,
  58412. numArgs: 1,
  58413. variableArgs: false
  58414. };
  58415. t['g'] = {
  58416. id: OPS.setFillGray,
  58417. numArgs: 1,
  58418. variableArgs: false
  58419. };
  58420. t['RG'] = {
  58421. id: OPS.setStrokeRGBColor,
  58422. numArgs: 3,
  58423. variableArgs: false
  58424. };
  58425. t['rg'] = {
  58426. id: OPS.setFillRGBColor,
  58427. numArgs: 3,
  58428. variableArgs: false
  58429. };
  58430. t['K'] = {
  58431. id: OPS.setStrokeCMYKColor,
  58432. numArgs: 4,
  58433. variableArgs: false
  58434. };
  58435. t['k'] = {
  58436. id: OPS.setFillCMYKColor,
  58437. numArgs: 4,
  58438. variableArgs: false
  58439. };
  58440. // Shading
  58441. t['sh'] = {
  58442. id: OPS.shadingFill,
  58443. numArgs: 1,
  58444. variableArgs: false
  58445. };
  58446. // Images
  58447. t['BI'] = {
  58448. id: OPS.beginInlineImage,
  58449. numArgs: 0,
  58450. variableArgs: false
  58451. };
  58452. t['ID'] = {
  58453. id: OPS.beginImageData,
  58454. numArgs: 0,
  58455. variableArgs: false
  58456. };
  58457. t['EI'] = {
  58458. id: OPS.endInlineImage,
  58459. numArgs: 1,
  58460. variableArgs: false
  58461. };
  58462. // XObjects
  58463. t['Do'] = {
  58464. id: OPS.paintXObject,
  58465. numArgs: 1,
  58466. variableArgs: false
  58467. };
  58468. t['MP'] = {
  58469. id: OPS.markPoint,
  58470. numArgs: 1,
  58471. variableArgs: false
  58472. };
  58473. t['DP'] = {
  58474. id: OPS.markPointProps,
  58475. numArgs: 2,
  58476. variableArgs: false
  58477. };
  58478. t['BMC'] = {
  58479. id: OPS.beginMarkedContent,
  58480. numArgs: 1,
  58481. variableArgs: false
  58482. };
  58483. t['BDC'] = {
  58484. id: OPS.beginMarkedContentProps,
  58485. numArgs: 2,
  58486. variableArgs: false
  58487. };
  58488. t['EMC'] = {
  58489. id: OPS.endMarkedContent,
  58490. numArgs: 0,
  58491. variableArgs: false
  58492. };
  58493. // Compatibility
  58494. t['BX'] = {
  58495. id: OPS.beginCompat,
  58496. numArgs: 0,
  58497. variableArgs: false
  58498. };
  58499. t['EX'] = {
  58500. id: OPS.endCompat,
  58501. numArgs: 0,
  58502. variableArgs: false
  58503. };
  58504. // (reserved partial commands for the lexer)
  58505. t['BM'] = null;
  58506. t['BD'] = null;
  58507. t['true'] = null;
  58508. t['fa'] = null;
  58509. t['fal'] = null;
  58510. t['fals'] = null;
  58511. t['false'] = null;
  58512. t['nu'] = null;
  58513. t['nul'] = null;
  58514. t['null'] = null;
  58515. });
  58516. function EvaluatorPreprocessor(stream, xref, stateManager) {
  58517. this.opMap = getOPMap();
  58518. // TODO(mduan): pass array of knownCommands rather than this.opMap
  58519. // dictionary
  58520. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  58521. this.stateManager = stateManager;
  58522. this.nonProcessedArgs = [];
  58523. }
  58524. EvaluatorPreprocessor.prototype = {
  58525. get savedStatesDepth() {
  58526. return this.stateManager.stateStack.length;
  58527. },
  58528. // |operation| is an object with two fields:
  58529. //
  58530. // - |fn| is an out param.
  58531. //
  58532. // - |args| is an inout param. On entry, it should have one of two values.
  58533. //
  58534. // - An empty array. This indicates that the caller is providing the
  58535. // array in which the args will be stored in. The caller should use
  58536. // this value if it can reuse a single array for each call to read().
  58537. //
  58538. // - |null|. This indicates that the caller needs this function to create
  58539. // the array in which any args are stored in. If there are zero args,
  58540. // this function will leave |operation.args| as |null| (thus avoiding
  58541. // allocations that would occur if we used an empty array to represent
  58542. // zero arguments). Otherwise, it will replace |null| with a new array
  58543. // containing the arguments. The caller should use this value if it
  58544. // cannot reuse an array for each call to read().
  58545. //
  58546. // These two modes are present because this function is very hot and so
  58547. // avoiding allocations where possible is worthwhile.
  58548. //
  58549. read: function EvaluatorPreprocessor_read(operation) {
  58550. var args = operation.args;
  58551. while (true) {
  58552. var obj = this.parser.getObj();
  58553. if (isCmd(obj)) {
  58554. var cmd = obj.cmd;
  58555. // Check that the command is valid
  58556. var opSpec = this.opMap[cmd];
  58557. if (!opSpec) {
  58558. warn('Unknown command "' + cmd + '"');
  58559. continue;
  58560. }
  58561. var fn = opSpec.id;
  58562. var numArgs = opSpec.numArgs;
  58563. var argsLength = args !== null ? args.length : 0;
  58564. if (!opSpec.variableArgs) {
  58565. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  58566. if (argsLength !== numArgs) {
  58567. var nonProcessedArgs = this.nonProcessedArgs;
  58568. while (argsLength > numArgs) {
  58569. nonProcessedArgs.push(args.shift());
  58570. argsLength--;
  58571. }
  58572. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  58573. if (!args) {
  58574. args = [];
  58575. }
  58576. args.unshift(nonProcessedArgs.pop());
  58577. argsLength++;
  58578. }
  58579. }
  58580. if (argsLength < numArgs) {
  58581. // If we receive too few args, it's not possible to possible
  58582. // to execute the command, so skip the command
  58583. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  58584. args = null;
  58585. continue;
  58586. }
  58587. } else if (argsLength > numArgs) {
  58588. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  58589. }
  58590. // TODO figure out how to type-check vararg functions
  58591. this.preprocessCommand(fn, args);
  58592. operation.fn = fn;
  58593. operation.args = args;
  58594. return true;
  58595. } else {
  58596. if (isEOF(obj)) {
  58597. return false;
  58598. }
  58599. // no more commands
  58600. // argument
  58601. if (obj !== null) {
  58602. if (!args) {
  58603. args = [];
  58604. }
  58605. args.push(obj);
  58606. assert(args.length <= 33, 'Too many arguments');
  58607. }
  58608. }
  58609. }
  58610. },
  58611. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  58612. switch (fn | 0) {
  58613. case OPS.save:
  58614. this.stateManager.save();
  58615. break;
  58616. case OPS.restore:
  58617. this.stateManager.restore();
  58618. break;
  58619. case OPS.transform:
  58620. this.stateManager.transform(args);
  58621. break;
  58622. }
  58623. }
  58624. };
  58625. return EvaluatorPreprocessor;
  58626. }();
  58627. var QueueOptimizer = function QueueOptimizerClosure() {
  58628. function addState(parentState, pattern, fn) {
  58629. var state = parentState;
  58630. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  58631. var item = pattern[i];
  58632. state = state[item] || (state[item] = []);
  58633. }
  58634. state[pattern[pattern.length - 1]] = fn;
  58635. }
  58636. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  58637. // Handles special case of mainly LaTeX documents which use image masks to
  58638. // draw lines with the current fill style.
  58639. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  58640. // have been found at iFirstSave.
  58641. var iFirstPIMXO = iFirstSave + 2;
  58642. for (var i = 0; i < count; i++) {
  58643. var arg = argsArray[iFirstPIMXO + 4 * i];
  58644. var imageMask = arg.length === 1 && arg[0];
  58645. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  58646. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  58647. continue;
  58648. }
  58649. break;
  58650. }
  58651. return count - i;
  58652. }
  58653. var InitialState = [];
  58654. // This replaces (save, transform, paintInlineImageXObject, restore)+
  58655. // sequences with one |paintInlineImageXObjectGroup| operation.
  58656. addState(InitialState, [
  58657. OPS.save,
  58658. OPS.transform,
  58659. OPS.paintInlineImageXObject,
  58660. OPS.restore
  58661. ], function foundInlineImageGroup(context) {
  58662. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  58663. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  58664. var MAX_WIDTH = 1000;
  58665. var IMAGE_PADDING = 1;
  58666. var fnArray = context.fnArray, argsArray = context.argsArray;
  58667. var curr = context.iCurr;
  58668. var iFirstSave = curr - 3;
  58669. var iFirstTransform = curr - 2;
  58670. var iFirstPIIXO = curr - 1;
  58671. // Look for the quartets.
  58672. var i = iFirstSave + 4;
  58673. var ii = fnArray.length;
  58674. while (i + 3 < ii) {
  58675. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  58676. break;
  58677. }
  58678. // ops don't match
  58679. i += 4;
  58680. }
  58681. // At this point, i is the index of the first op past the last valid
  58682. // quartet.
  58683. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  58684. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  58685. return i;
  58686. }
  58687. // assuming that heights of those image is too small (~1 pixel)
  58688. // packing as much as possible by lines
  58689. var maxX = 0;
  58690. var map = [], maxLineHeight = 0;
  58691. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  58692. var q;
  58693. for (q = 0; q < count; q++) {
  58694. var transform = argsArray[iFirstTransform + (q << 2)];
  58695. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  58696. if (currentX + img.width > MAX_WIDTH) {
  58697. // starting new line
  58698. maxX = Math.max(maxX, currentX);
  58699. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  58700. currentX = 0;
  58701. maxLineHeight = 0;
  58702. }
  58703. map.push({
  58704. transform: transform,
  58705. x: currentX,
  58706. y: currentY,
  58707. w: img.width,
  58708. h: img.height
  58709. });
  58710. currentX += img.width + 2 * IMAGE_PADDING;
  58711. maxLineHeight = Math.max(maxLineHeight, img.height);
  58712. }
  58713. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  58714. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  58715. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  58716. var imgRowSize = imgWidth << 2;
  58717. for (q = 0; q < count; q++) {
  58718. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  58719. // Copy image by lines and extends pixels into padding.
  58720. var rowSize = map[q].w << 2;
  58721. var dataOffset = 0;
  58722. var offset = map[q].x + map[q].y * imgWidth << 2;
  58723. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  58724. for (var k = 0, kk = map[q].h; k < kk; k++) {
  58725. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  58726. dataOffset += rowSize;
  58727. offset += imgRowSize;
  58728. }
  58729. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  58730. while (offset >= 0) {
  58731. data[offset - 4] = data[offset];
  58732. data[offset - 3] = data[offset + 1];
  58733. data[offset - 2] = data[offset + 2];
  58734. data[offset - 1] = data[offset + 3];
  58735. data[offset + rowSize] = data[offset + rowSize - 4];
  58736. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  58737. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  58738. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  58739. offset -= imgRowSize;
  58740. }
  58741. }
  58742. // Replace queue items.
  58743. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  58744. argsArray.splice(iFirstSave, count * 4, [
  58745. {
  58746. width: imgWidth,
  58747. height: imgHeight,
  58748. kind: ImageKind.RGBA_32BPP,
  58749. data: imgData
  58750. },
  58751. map
  58752. ]);
  58753. return iFirstSave + 1;
  58754. });
  58755. // This replaces (save, transform, paintImageMaskXObject, restore)+
  58756. // sequences with one |paintImageMaskXObjectGroup| or one
  58757. // |paintImageMaskXObjectRepeat| operation.
  58758. addState(InitialState, [
  58759. OPS.save,
  58760. OPS.transform,
  58761. OPS.paintImageMaskXObject,
  58762. OPS.restore
  58763. ], function foundImageMaskGroup(context) {
  58764. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  58765. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  58766. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  58767. var fnArray = context.fnArray, argsArray = context.argsArray;
  58768. var curr = context.iCurr;
  58769. var iFirstSave = curr - 3;
  58770. var iFirstTransform = curr - 2;
  58771. var iFirstPIMXO = curr - 1;
  58772. // Look for the quartets.
  58773. var i = iFirstSave + 4;
  58774. var ii = fnArray.length;
  58775. while (i + 3 < ii) {
  58776. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  58777. break;
  58778. }
  58779. // ops don't match
  58780. i += 4;
  58781. }
  58782. // At this point, i is the index of the first op past the last valid
  58783. // quartet.
  58784. var count = (i - iFirstSave) / 4;
  58785. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  58786. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  58787. return i;
  58788. }
  58789. var q;
  58790. var isSameImage = false;
  58791. var iTransform, transformArgs;
  58792. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  58793. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  58794. isSameImage = true;
  58795. var firstTransformArg0 = argsArray[iFirstTransform][0];
  58796. var firstTransformArg3 = argsArray[iFirstTransform][3];
  58797. iTransform = iFirstTransform + 4;
  58798. var iPIMXO = iFirstPIMXO + 4;
  58799. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  58800. transformArgs = argsArray[iTransform];
  58801. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  58802. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  58803. isSameImage = false;
  58804. } else {
  58805. count = q;
  58806. }
  58807. break;
  58808. }
  58809. }
  58810. }
  58811. // different image or transform
  58812. if (isSameImage) {
  58813. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  58814. var positions = new Float32Array(count * 2);
  58815. iTransform = iFirstTransform;
  58816. for (q = 0; q < count; q++, iTransform += 4) {
  58817. transformArgs = argsArray[iTransform];
  58818. positions[q << 1] = transformArgs[4];
  58819. positions[(q << 1) + 1] = transformArgs[5];
  58820. }
  58821. // Replace queue items.
  58822. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  58823. argsArray.splice(iFirstSave, count * 4, [
  58824. firstPIMXOArg0,
  58825. firstTransformArg0,
  58826. firstTransformArg3,
  58827. positions
  58828. ]);
  58829. } else {
  58830. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  58831. var images = [];
  58832. for (q = 0; q < count; q++) {
  58833. transformArgs = argsArray[iFirstTransform + (q << 2)];
  58834. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  58835. images.push({
  58836. data: maskParams.data,
  58837. width: maskParams.width,
  58838. height: maskParams.height,
  58839. transform: transformArgs
  58840. });
  58841. }
  58842. // Replace queue items.
  58843. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  58844. argsArray.splice(iFirstSave, count * 4, [images]);
  58845. }
  58846. return iFirstSave + 1;
  58847. });
  58848. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  58849. // with one paintImageXObjectRepeat operation, if the |transform| and
  58850. // |paintImageXObjectRepeat| ops are appropriate.
  58851. addState(InitialState, [
  58852. OPS.save,
  58853. OPS.transform,
  58854. OPS.paintImageXObject,
  58855. OPS.restore
  58856. ], function (context) {
  58857. var MIN_IMAGES_IN_BLOCK = 3;
  58858. var MAX_IMAGES_IN_BLOCK = 1000;
  58859. var fnArray = context.fnArray, argsArray = context.argsArray;
  58860. var curr = context.iCurr;
  58861. var iFirstSave = curr - 3;
  58862. var iFirstTransform = curr - 2;
  58863. var iFirstPIXO = curr - 1;
  58864. var iFirstRestore = curr;
  58865. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  58866. return iFirstRestore + 1;
  58867. }
  58868. // transform has the wrong form
  58869. // Look for the quartets.
  58870. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  58871. var firstTransformArg0 = argsArray[iFirstTransform][0];
  58872. var firstTransformArg3 = argsArray[iFirstTransform][3];
  58873. var i = iFirstSave + 4;
  58874. var ii = fnArray.length;
  58875. while (i + 3 < ii) {
  58876. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  58877. break;
  58878. }
  58879. // ops don't match
  58880. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  58881. break;
  58882. }
  58883. // transforms don't match
  58884. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  58885. break;
  58886. }
  58887. // images don't match
  58888. i += 4;
  58889. }
  58890. // At this point, i is the index of the first op past the last valid
  58891. // quartet.
  58892. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  58893. if (count < MIN_IMAGES_IN_BLOCK) {
  58894. return i;
  58895. }
  58896. // Extract the (x,y) positions from all of the matching transforms.
  58897. var positions = new Float32Array(count * 2);
  58898. var iTransform = iFirstTransform;
  58899. for (var q = 0; q < count; q++, iTransform += 4) {
  58900. var transformArgs = argsArray[iTransform];
  58901. positions[q << 1] = transformArgs[4];
  58902. positions[(q << 1) + 1] = transformArgs[5];
  58903. }
  58904. // Replace queue items.
  58905. var args = [
  58906. firstPIXOArg0,
  58907. firstTransformArg0,
  58908. firstTransformArg3,
  58909. positions
  58910. ];
  58911. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  58912. argsArray.splice(iFirstSave, count * 4, args);
  58913. return iFirstSave + 1;
  58914. });
  58915. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  58916. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  58917. // sequences, if the font for each one is the same.
  58918. addState(InitialState, [
  58919. OPS.beginText,
  58920. OPS.setFont,
  58921. OPS.setTextMatrix,
  58922. OPS.showText,
  58923. OPS.endText
  58924. ], function (context) {
  58925. var MIN_CHARS_IN_BLOCK = 3;
  58926. var MAX_CHARS_IN_BLOCK = 1000;
  58927. var fnArray = context.fnArray, argsArray = context.argsArray;
  58928. var curr = context.iCurr;
  58929. var iFirstBeginText = curr - 4;
  58930. var iFirstSetFont = curr - 3;
  58931. var iFirstSetTextMatrix = curr - 2;
  58932. var iFirstShowText = curr - 1;
  58933. var iFirstEndText = curr;
  58934. // Look for the quintets.
  58935. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  58936. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  58937. var i = iFirstBeginText + 5;
  58938. var ii = fnArray.length;
  58939. while (i + 4 < ii) {
  58940. if (fnArray[i] !== OPS.beginText || fnArray[i + 1] !== OPS.setFont || fnArray[i + 2] !== OPS.setTextMatrix || fnArray[i + 3] !== OPS.showText || fnArray[i + 4] !== OPS.endText) {
  58941. break;
  58942. }
  58943. // ops don't match
  58944. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  58945. break;
  58946. }
  58947. // fonts don't match
  58948. i += 5;
  58949. }
  58950. // At this point, i is the index of the first op past the last valid
  58951. // quintet.
  58952. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  58953. if (count < MIN_CHARS_IN_BLOCK) {
  58954. return i;
  58955. }
  58956. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  58957. // showText, endText), include that as well. (E.g. <something> might be
  58958. // |dependency|.)
  58959. var iFirst = iFirstBeginText;
  58960. if (iFirstBeginText >= 4 && fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] && fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] && fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] && fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] && argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 && argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  58961. count++;
  58962. iFirst -= 5;
  58963. }
  58964. // Remove (endText, beginText, setFont) trios.
  58965. var iEndText = iFirst + 4;
  58966. for (var q = 1; q < count; q++) {
  58967. fnArray.splice(iEndText, 3);
  58968. argsArray.splice(iEndText, 3);
  58969. iEndText += 2;
  58970. }
  58971. return iEndText + 1;
  58972. });
  58973. function QueueOptimizer() {
  58974. }
  58975. QueueOptimizer.prototype = {
  58976. optimize: function QueueOptimizer_optimize(queue) {
  58977. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  58978. var context = {
  58979. iCurr: 0,
  58980. fnArray: fnArray,
  58981. argsArray: argsArray
  58982. };
  58983. var state;
  58984. var i = 0, ii = fnArray.length;
  58985. while (i < ii) {
  58986. state = (state || InitialState)[fnArray[i]];
  58987. if (typeof state === 'function') {
  58988. // we found some handler
  58989. context.iCurr = i;
  58990. // state() returns the index of the first non-matching op (if we
  58991. // didn't match) or the first op past the modified ops (if we did
  58992. // match and replace).
  58993. i = state(context);
  58994. state = undefined;
  58995. // reset the state machine
  58996. ii = context.fnArray.length;
  58997. } else {
  58998. i++;
  58999. }
  59000. }
  59001. }
  59002. };
  59003. return QueueOptimizer;
  59004. }();
  59005. exports.OperatorList = OperatorList;
  59006. exports.PartialEvaluator = PartialEvaluator;
  59007. }));
  59008. (function (root, factory) {
  59009. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  59010. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  59011. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  59012. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  59013. var AnnotationFlag = sharedUtil.AnnotationFlag;
  59014. var AnnotationType = sharedUtil.AnnotationType;
  59015. var OPS = sharedUtil.OPS;
  59016. var Util = sharedUtil.Util;
  59017. var isString = sharedUtil.isString;
  59018. var isArray = sharedUtil.isArray;
  59019. var isInt = sharedUtil.isInt;
  59020. var stringToBytes = sharedUtil.stringToBytes;
  59021. var stringToPDFString = sharedUtil.stringToPDFString;
  59022. var warn = sharedUtil.warn;
  59023. var Dict = corePrimitives.Dict;
  59024. var isDict = corePrimitives.isDict;
  59025. var isName = corePrimitives.isName;
  59026. var isRef = corePrimitives.isRef;
  59027. var Stream = coreStream.Stream;
  59028. var ColorSpace = coreColorSpace.ColorSpace;
  59029. var Catalog = coreObj.Catalog;
  59030. var ObjectLoader = coreObj.ObjectLoader;
  59031. var FileSpec = coreObj.FileSpec;
  59032. var OperatorList = coreEvaluator.OperatorList;
  59033. /**
  59034. * @class
  59035. * @alias AnnotationFactory
  59036. */
  59037. function AnnotationFactory() {
  59038. }
  59039. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  59040. {
  59041. /**
  59042. * @param {XRef} xref
  59043. * @param {Object} ref
  59044. * @param {PDFManager} pdfManager
  59045. * @param {string} uniquePrefix
  59046. * @param {Object} idCounters
  59047. * @returns {Annotation}
  59048. */
  59049. create: function AnnotationFactory_create(xref, ref, pdfManager, uniquePrefix, idCounters) {
  59050. var dict = xref.fetchIfRef(ref);
  59051. if (!isDict(dict)) {
  59052. return;
  59053. }
  59054. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  59055. // Determine the annotation's subtype.
  59056. var subtype = dict.get('Subtype');
  59057. subtype = isName(subtype) ? subtype.name : null;
  59058. // Return the right annotation object based on the subtype and field type.
  59059. var parameters = {
  59060. xref: xref,
  59061. dict: dict,
  59062. ref: isRef(ref) ? ref : null,
  59063. subtype: subtype,
  59064. id: id,
  59065. pdfManager: pdfManager
  59066. };
  59067. switch (subtype) {
  59068. case 'Link':
  59069. return new LinkAnnotation(parameters);
  59070. case 'Text':
  59071. return new TextAnnotation(parameters);
  59072. case 'Widget':
  59073. var fieldType = Util.getInheritableProperty(dict, 'FT');
  59074. fieldType = isName(fieldType) ? fieldType.name : null;
  59075. switch (fieldType) {
  59076. case 'Tx':
  59077. return new TextWidgetAnnotation(parameters);
  59078. case 'Ch':
  59079. return new ChoiceWidgetAnnotation(parameters);
  59080. }
  59081. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  59082. return new WidgetAnnotation(parameters);
  59083. case 'Popup':
  59084. return new PopupAnnotation(parameters);
  59085. case 'Highlight':
  59086. return new HighlightAnnotation(parameters);
  59087. case 'Underline':
  59088. return new UnderlineAnnotation(parameters);
  59089. case 'Squiggly':
  59090. return new SquigglyAnnotation(parameters);
  59091. case 'StrikeOut':
  59092. return new StrikeOutAnnotation(parameters);
  59093. case 'FileAttachment':
  59094. return new FileAttachmentAnnotation(parameters);
  59095. default:
  59096. if (!subtype) {
  59097. warn('Annotation is missing the required /Subtype.');
  59098. } else {
  59099. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  59100. }
  59101. return new Annotation(parameters);
  59102. }
  59103. }
  59104. };
  59105. var Annotation = function AnnotationClosure() {
  59106. // 12.5.5: Algorithm: Appearance streams
  59107. function getTransformMatrix(rect, bbox, matrix) {
  59108. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  59109. var minX = bounds[0];
  59110. var minY = bounds[1];
  59111. var maxX = bounds[2];
  59112. var maxY = bounds[3];
  59113. if (minX === maxX || minY === maxY) {
  59114. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  59115. // just apply the transform for rect
  59116. return [
  59117. 1,
  59118. 0,
  59119. 0,
  59120. 1,
  59121. rect[0],
  59122. rect[1]
  59123. ];
  59124. }
  59125. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  59126. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  59127. return [
  59128. xRatio,
  59129. 0,
  59130. 0,
  59131. yRatio,
  59132. rect[0] - minX * xRatio,
  59133. rect[1] - minY * yRatio
  59134. ];
  59135. }
  59136. function getDefaultAppearance(dict) {
  59137. var appearanceState = dict.get('AP');
  59138. if (!isDict(appearanceState)) {
  59139. return;
  59140. }
  59141. var appearance;
  59142. var appearances = appearanceState.get('N');
  59143. if (isDict(appearances)) {
  59144. var as = dict.get('AS');
  59145. if (as && appearances.has(as.name)) {
  59146. appearance = appearances.get(as.name);
  59147. }
  59148. } else {
  59149. appearance = appearances;
  59150. }
  59151. return appearance;
  59152. }
  59153. function Annotation(params) {
  59154. var dict = params.dict;
  59155. this.setFlags(dict.get('F'));
  59156. this.setRectangle(dict.getArray('Rect'));
  59157. this.setColor(dict.getArray('C'));
  59158. this.setBorderStyle(dict);
  59159. this.appearance = getDefaultAppearance(dict);
  59160. // Expose public properties using a data object.
  59161. this.data = {};
  59162. this.data.id = params.id;
  59163. this.data.subtype = params.subtype;
  59164. this.data.annotationFlags = this.flags;
  59165. this.data.rect = this.rectangle;
  59166. this.data.color = this.color;
  59167. this.data.borderStyle = this.borderStyle;
  59168. this.data.hasAppearance = !!this.appearance;
  59169. }
  59170. Annotation.prototype = {
  59171. /**
  59172. * @private
  59173. */
  59174. _hasFlag: function Annotation_hasFlag(flags, flag) {
  59175. return !!(flags & flag);
  59176. },
  59177. /**
  59178. * @private
  59179. */
  59180. _isViewable: function Annotation_isViewable(flags) {
  59181. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  59182. },
  59183. /**
  59184. * @private
  59185. */
  59186. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  59187. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  59188. },
  59189. /**
  59190. * @return {boolean}
  59191. */
  59192. get viewable() {
  59193. if (this.flags === 0) {
  59194. return true;
  59195. }
  59196. return this._isViewable(this.flags);
  59197. },
  59198. /**
  59199. * @return {boolean}
  59200. */
  59201. get printable() {
  59202. if (this.flags === 0) {
  59203. return false;
  59204. }
  59205. return this._isPrintable(this.flags);
  59206. },
  59207. /**
  59208. * Set the flags.
  59209. *
  59210. * @public
  59211. * @memberof Annotation
  59212. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  59213. * characteristics
  59214. * @see {@link shared/util.js}
  59215. */
  59216. setFlags: function Annotation_setFlags(flags) {
  59217. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  59218. },
  59219. /**
  59220. * Check if a provided flag is set.
  59221. *
  59222. * @public
  59223. * @memberof Annotation
  59224. * @param {number} flag - Hexadecimal representation for an annotation
  59225. * characteristic
  59226. * @return {boolean}
  59227. * @see {@link shared/util.js}
  59228. */
  59229. hasFlag: function Annotation_hasFlag(flag) {
  59230. return this._hasFlag(this.flags, flag);
  59231. },
  59232. /**
  59233. * Set the rectangle.
  59234. *
  59235. * @public
  59236. * @memberof Annotation
  59237. * @param {Array} rectangle - The rectangle array with exactly four entries
  59238. */
  59239. setRectangle: function Annotation_setRectangle(rectangle) {
  59240. if (isArray(rectangle) && rectangle.length === 4) {
  59241. this.rectangle = Util.normalizeRect(rectangle);
  59242. } else {
  59243. this.rectangle = [
  59244. 0,
  59245. 0,
  59246. 0,
  59247. 0
  59248. ];
  59249. }
  59250. },
  59251. /**
  59252. * Set the color and take care of color space conversion.
  59253. *
  59254. * @public
  59255. * @memberof Annotation
  59256. * @param {Array} color - The color array containing either 0
  59257. * (transparent), 1 (grayscale), 3 (RGB) or
  59258. * 4 (CMYK) elements
  59259. */
  59260. setColor: function Annotation_setColor(color) {
  59261. var rgbColor = new Uint8Array(3);
  59262. // Black in RGB color space (default)
  59263. if (!isArray(color)) {
  59264. this.color = rgbColor;
  59265. return;
  59266. }
  59267. switch (color.length) {
  59268. case 0:
  59269. // Transparent, which we indicate with a null value
  59270. this.color = null;
  59271. break;
  59272. case 1:
  59273. // Convert grayscale to RGB
  59274. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  59275. this.color = rgbColor;
  59276. break;
  59277. case 3:
  59278. // Convert RGB percentages to RGB
  59279. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  59280. this.color = rgbColor;
  59281. break;
  59282. case 4:
  59283. // Convert CMYK to RGB
  59284. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  59285. this.color = rgbColor;
  59286. break;
  59287. default:
  59288. this.color = rgbColor;
  59289. break;
  59290. }
  59291. },
  59292. /**
  59293. * Set the border style (as AnnotationBorderStyle object).
  59294. *
  59295. * @public
  59296. * @memberof Annotation
  59297. * @param {Dict} borderStyle - The border style dictionary
  59298. */
  59299. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  59300. this.borderStyle = new AnnotationBorderStyle();
  59301. if (!isDict(borderStyle)) {
  59302. return;
  59303. }
  59304. if (borderStyle.has('BS')) {
  59305. var dict = borderStyle.get('BS');
  59306. var dictType = dict.get('Type');
  59307. if (!dictType || isName(dictType, 'Border')) {
  59308. this.borderStyle.setWidth(dict.get('W'));
  59309. this.borderStyle.setStyle(dict.get('S'));
  59310. this.borderStyle.setDashArray(dict.getArray('D'));
  59311. }
  59312. } else if (borderStyle.has('Border')) {
  59313. var array = borderStyle.getArray('Border');
  59314. if (isArray(array) && array.length >= 3) {
  59315. this.borderStyle.setHorizontalCornerRadius(array[0]);
  59316. this.borderStyle.setVerticalCornerRadius(array[1]);
  59317. this.borderStyle.setWidth(array[2]);
  59318. if (array.length === 4) {
  59319. // Dash array available
  59320. this.borderStyle.setDashArray(array[3]);
  59321. }
  59322. }
  59323. } else {
  59324. // There are no border entries in the dictionary. According to the
  59325. // specification, we should draw a solid border of width 1 in that
  59326. // case, but Adobe Reader did not implement that part of the
  59327. // specification and instead draws no border at all, so we do the same.
  59328. // See also https://github.com/mozilla/pdf.js/issues/6179.
  59329. this.borderStyle.setWidth(0);
  59330. }
  59331. },
  59332. /**
  59333. * Prepare the annotation for working with a popup in the display layer.
  59334. *
  59335. * @private
  59336. * @memberof Annotation
  59337. * @param {Dict} dict - The annotation's data dictionary
  59338. */
  59339. _preparePopup: function Annotation_preparePopup(dict) {
  59340. if (!dict.has('C')) {
  59341. // Fall back to the default background color.
  59342. this.data.color = null;
  59343. }
  59344. this.data.hasPopup = dict.has('Popup');
  59345. this.data.title = stringToPDFString(dict.get('T') || '');
  59346. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  59347. },
  59348. loadResources: function Annotation_loadResources(keys) {
  59349. return new Promise(function (resolve, reject) {
  59350. this.appearance.dict.getAsync('Resources').then(function (resources) {
  59351. if (!resources) {
  59352. resolve();
  59353. return;
  59354. }
  59355. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  59356. objectLoader.load().then(function () {
  59357. resolve(resources);
  59358. }, reject);
  59359. }, reject);
  59360. }.bind(this));
  59361. },
  59362. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  59363. if (!this.appearance) {
  59364. return Promise.resolve(new OperatorList());
  59365. }
  59366. var data = this.data;
  59367. var appearanceDict = this.appearance.dict;
  59368. var resourcesPromise = this.loadResources([
  59369. 'ExtGState',
  59370. 'ColorSpace',
  59371. 'Pattern',
  59372. 'Shading',
  59373. 'XObject',
  59374. 'Font'
  59375. ]);
  59376. // ProcSet
  59377. // Properties
  59378. var bbox = appearanceDict.getArray('BBox') || [
  59379. 0,
  59380. 0,
  59381. 1,
  59382. 1
  59383. ];
  59384. var matrix = appearanceDict.getArray('Matrix') || [
  59385. 1,
  59386. 0,
  59387. 0,
  59388. 1,
  59389. 0,
  59390. 0
  59391. ];
  59392. var transform = getTransformMatrix(data.rect, bbox, matrix);
  59393. var self = this;
  59394. return resourcesPromise.then(function (resources) {
  59395. var opList = new OperatorList();
  59396. opList.addOp(OPS.beginAnnotation, [
  59397. data.rect,
  59398. transform,
  59399. matrix
  59400. ]);
  59401. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  59402. opList.addOp(OPS.endAnnotation, []);
  59403. self.appearance.reset();
  59404. return opList;
  59405. });
  59406. });
  59407. }
  59408. };
  59409. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  59410. var annotationPromises = [];
  59411. for (var i = 0, n = annotations.length; i < n; ++i) {
  59412. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  59413. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  59414. }
  59415. }
  59416. return Promise.all(annotationPromises).then(function (operatorLists) {
  59417. opList.addOp(OPS.beginAnnotations, []);
  59418. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  59419. opList.addOpList(operatorLists[i]);
  59420. }
  59421. opList.addOp(OPS.endAnnotations, []);
  59422. });
  59423. };
  59424. return Annotation;
  59425. }();
  59426. /**
  59427. * Contains all data regarding an annotation's border style.
  59428. *
  59429. * @class
  59430. */
  59431. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  59432. /**
  59433. * @constructor
  59434. * @private
  59435. */
  59436. function AnnotationBorderStyle() {
  59437. this.width = 1;
  59438. this.style = AnnotationBorderStyleType.SOLID;
  59439. this.dashArray = [3];
  59440. this.horizontalCornerRadius = 0;
  59441. this.verticalCornerRadius = 0;
  59442. }
  59443. AnnotationBorderStyle.prototype = {
  59444. /**
  59445. * Set the width.
  59446. *
  59447. * @public
  59448. * @memberof AnnotationBorderStyle
  59449. * @param {integer} width - The width
  59450. */
  59451. setWidth: function AnnotationBorderStyle_setWidth(width) {
  59452. if (width === (width | 0)) {
  59453. this.width = width;
  59454. }
  59455. },
  59456. /**
  59457. * Set the style.
  59458. *
  59459. * @public
  59460. * @memberof AnnotationBorderStyle
  59461. * @param {Object} style - The style object
  59462. * @see {@link shared/util.js}
  59463. */
  59464. setStyle: function AnnotationBorderStyle_setStyle(style) {
  59465. if (!style) {
  59466. return;
  59467. }
  59468. switch (style.name) {
  59469. case 'S':
  59470. this.style = AnnotationBorderStyleType.SOLID;
  59471. break;
  59472. case 'D':
  59473. this.style = AnnotationBorderStyleType.DASHED;
  59474. break;
  59475. case 'B':
  59476. this.style = AnnotationBorderStyleType.BEVELED;
  59477. break;
  59478. case 'I':
  59479. this.style = AnnotationBorderStyleType.INSET;
  59480. break;
  59481. case 'U':
  59482. this.style = AnnotationBorderStyleType.UNDERLINE;
  59483. break;
  59484. default:
  59485. break;
  59486. }
  59487. },
  59488. /**
  59489. * Set the dash array.
  59490. *
  59491. * @public
  59492. * @memberof AnnotationBorderStyle
  59493. * @param {Array} dashArray - The dash array with at least one element
  59494. */
  59495. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  59496. // We validate the dash array, but we do not use it because CSS does not
  59497. // allow us to change spacing of dashes. For more information, visit
  59498. // http://www.w3.org/TR/css3-background/#the-border-style.
  59499. if (isArray(dashArray) && dashArray.length > 0) {
  59500. // According to the PDF specification: the elements in a dashArray
  59501. // shall be numbers that are nonnegative and not all equal to zero.
  59502. var isValid = true;
  59503. var allZeros = true;
  59504. for (var i = 0, len = dashArray.length; i < len; i++) {
  59505. var element = dashArray[i];
  59506. var validNumber = +element >= 0;
  59507. if (!validNumber) {
  59508. isValid = false;
  59509. break;
  59510. } else if (element > 0) {
  59511. allZeros = false;
  59512. }
  59513. }
  59514. if (isValid && !allZeros) {
  59515. this.dashArray = dashArray;
  59516. } else {
  59517. this.width = 0;
  59518. }
  59519. } else // Adobe behavior when the array is invalid.
  59520. if (dashArray) {
  59521. this.width = 0;
  59522. }
  59523. },
  59524. // Adobe behavior when the array is invalid.
  59525. /**
  59526. * Set the horizontal corner radius (from a Border dictionary).
  59527. *
  59528. * @public
  59529. * @memberof AnnotationBorderStyle
  59530. * @param {integer} radius - The horizontal corner radius
  59531. */
  59532. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  59533. if (radius === (radius | 0)) {
  59534. this.horizontalCornerRadius = radius;
  59535. }
  59536. },
  59537. /**
  59538. * Set the vertical corner radius (from a Border dictionary).
  59539. *
  59540. * @public
  59541. * @memberof AnnotationBorderStyle
  59542. * @param {integer} radius - The vertical corner radius
  59543. */
  59544. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  59545. if (radius === (radius | 0)) {
  59546. this.verticalCornerRadius = radius;
  59547. }
  59548. }
  59549. };
  59550. return AnnotationBorderStyle;
  59551. }();
  59552. var WidgetAnnotation = function WidgetAnnotationClosure() {
  59553. function WidgetAnnotation(params) {
  59554. Annotation.call(this, params);
  59555. var dict = params.dict;
  59556. var data = this.data;
  59557. data.annotationType = AnnotationType.WIDGET;
  59558. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  59559. true);
  59560. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  59561. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  59562. var fieldType = Util.getInheritableProperty(dict, 'FT');
  59563. data.fieldType = isName(fieldType) ? fieldType.name : null;
  59564. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  59565. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  59566. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  59567. data.fieldFlags = 0;
  59568. }
  59569. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  59570. // Hide signatures because we cannot validate them.
  59571. if (data.fieldType === 'Sig') {
  59572. this.setFlags(AnnotationFlag.HIDDEN);
  59573. }
  59574. // Building the full field name by collecting the field and
  59575. // its ancestors 'T' data and joining them using '.'.
  59576. var fieldName = [];
  59577. var namedItem = dict;
  59578. var ref = params.ref;
  59579. while (namedItem) {
  59580. var parent = namedItem.get('Parent');
  59581. var parentRef = namedItem.getRaw('Parent');
  59582. var name = namedItem.get('T');
  59583. if (name) {
  59584. fieldName.unshift(stringToPDFString(name));
  59585. } else if (parent && ref) {
  59586. // The field name is absent, that means more than one field
  59587. // with the same name may exist. Replacing the empty name
  59588. // with the '`' plus index in the parent's 'Kids' array.
  59589. // This is not in the PDF spec but necessary to id the
  59590. // the input controls.
  59591. var kids = parent.get('Kids');
  59592. var j, jj;
  59593. for (j = 0, jj = kids.length; j < jj; j++) {
  59594. var kidRef = kids[j];
  59595. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  59596. break;
  59597. }
  59598. }
  59599. fieldName.unshift('`' + j);
  59600. }
  59601. namedItem = parent;
  59602. ref = parentRef;
  59603. }
  59604. data.fullName = fieldName.join('.');
  59605. }
  59606. Util.inherit(WidgetAnnotation, Annotation, {
  59607. /**
  59608. * Check if a provided field flag is set.
  59609. *
  59610. * @public
  59611. * @memberof WidgetAnnotation
  59612. * @param {number} flag - Hexadecimal representation for an annotation
  59613. * field characteristic
  59614. * @return {boolean}
  59615. * @see {@link shared/util.js}
  59616. */
  59617. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  59618. return !!(this.data.fieldFlags & flag);
  59619. }
  59620. });
  59621. return WidgetAnnotation;
  59622. }();
  59623. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  59624. function TextWidgetAnnotation(params) {
  59625. WidgetAnnotation.call(this, params);
  59626. // The field value is always a string.
  59627. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  59628. // Determine the alignment of text in the field.
  59629. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  59630. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  59631. alignment = null;
  59632. }
  59633. this.data.textAlignment = alignment;
  59634. // Determine the maximum length of text in the field.
  59635. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  59636. if (!isInt(maximumLength) || maximumLength < 0) {
  59637. maximumLength = null;
  59638. }
  59639. this.data.maxLen = maximumLength;
  59640. // Process field flags for the display layer.
  59641. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  59642. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  59643. }
  59644. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  59645. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  59646. var operatorList = new OperatorList();
  59647. // Do not render form elements on the canvas when interactive forms are
  59648. // enabled. The display layer is responsible for rendering them instead.
  59649. if (renderForms) {
  59650. return Promise.resolve(operatorList);
  59651. }
  59652. if (this.appearance) {
  59653. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  59654. }
  59655. // Even if there is an appearance stream, ignore it. This is the
  59656. // behaviour used by Adobe Reader.
  59657. if (!this.data.defaultAppearance) {
  59658. return Promise.resolve(operatorList);
  59659. }
  59660. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  59661. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  59662. return operatorList;
  59663. });
  59664. }
  59665. });
  59666. return TextWidgetAnnotation;
  59667. }();
  59668. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  59669. function ChoiceWidgetAnnotation(params) {
  59670. WidgetAnnotation.call(this, params);
  59671. // Determine the options. The options array may consist of strings or
  59672. // arrays. If the array consists of arrays, then the first element of
  59673. // each array is the export value and the second element of each array is
  59674. // the display value. If the array consists of strings, then these
  59675. // represent both the export and display value. In this case, we convert
  59676. // it to an array of arrays as well for convenience in the display layer.
  59677. this.data.options = [];
  59678. var options = params.dict.getArray('Opt');
  59679. if (isArray(options)) {
  59680. for (var i = 0, ii = options.length; i < ii; i++) {
  59681. var option = options[i];
  59682. this.data.options[i] = {
  59683. exportValue: isArray(option) ? option[0] : option,
  59684. displayValue: isArray(option) ? option[1] : option
  59685. };
  59686. }
  59687. }
  59688. // Determine the field value. In this case, it may be a string or an
  59689. // array of strings. For convenience in the display layer, convert the
  59690. // string to an array of one string as well.
  59691. if (!isArray(this.data.fieldValue)) {
  59692. this.data.fieldValue = [this.data.fieldValue];
  59693. }
  59694. // Process field flags for the display layer.
  59695. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  59696. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  59697. }
  59698. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  59699. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  59700. var operatorList = new OperatorList();
  59701. // Do not render form elements on the canvas when interactive forms are
  59702. // enabled. The display layer is responsible for rendering them instead.
  59703. if (renderForms) {
  59704. return Promise.resolve(operatorList);
  59705. }
  59706. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  59707. }
  59708. });
  59709. return ChoiceWidgetAnnotation;
  59710. }();
  59711. var TextAnnotation = function TextAnnotationClosure() {
  59712. var DEFAULT_ICON_SIZE = 22;
  59713. // px
  59714. function TextAnnotation(parameters) {
  59715. Annotation.call(this, parameters);
  59716. this.data.annotationType = AnnotationType.TEXT;
  59717. if (this.data.hasAppearance) {
  59718. this.data.name = 'NoIcon';
  59719. } else {
  59720. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  59721. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  59722. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  59723. }
  59724. this._preparePopup(parameters.dict);
  59725. }
  59726. Util.inherit(TextAnnotation, Annotation, {});
  59727. return TextAnnotation;
  59728. }();
  59729. var LinkAnnotation = function LinkAnnotationClosure() {
  59730. function LinkAnnotation(params) {
  59731. Annotation.call(this, params);
  59732. var data = this.data;
  59733. data.annotationType = AnnotationType.LINK;
  59734. Catalog.parseDestDictionary({
  59735. destDict: params.dict,
  59736. resultObj: data,
  59737. docBaseUrl: params.pdfManager.docBaseUrl
  59738. });
  59739. }
  59740. Util.inherit(LinkAnnotation, Annotation, {});
  59741. return LinkAnnotation;
  59742. }();
  59743. var PopupAnnotation = function PopupAnnotationClosure() {
  59744. function PopupAnnotation(parameters) {
  59745. Annotation.call(this, parameters);
  59746. this.data.annotationType = AnnotationType.POPUP;
  59747. var dict = parameters.dict;
  59748. var parentItem = dict.get('Parent');
  59749. if (!parentItem) {
  59750. warn('Popup annotation has a missing or invalid parent annotation.');
  59751. return;
  59752. }
  59753. this.data.parentId = dict.getRaw('Parent').toString();
  59754. this.data.title = stringToPDFString(parentItem.get('T') || '');
  59755. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  59756. if (!parentItem.has('C')) {
  59757. // Fall back to the default background color.
  59758. this.data.color = null;
  59759. } else {
  59760. this.setColor(parentItem.getArray('C'));
  59761. this.data.color = this.color;
  59762. }
  59763. // If the Popup annotation is not viewable, but the parent annotation is,
  59764. // that is most likely a bug. Fallback to inherit the flags from the parent
  59765. // annotation (this is consistent with the behaviour in Adobe Reader).
  59766. if (!this.viewable) {
  59767. var parentFlags = parentItem.get('F');
  59768. if (this._isViewable(parentFlags)) {
  59769. this.setFlags(parentFlags);
  59770. }
  59771. }
  59772. }
  59773. Util.inherit(PopupAnnotation, Annotation, {});
  59774. return PopupAnnotation;
  59775. }();
  59776. var HighlightAnnotation = function HighlightAnnotationClosure() {
  59777. function HighlightAnnotation(parameters) {
  59778. Annotation.call(this, parameters);
  59779. this.data.annotationType = AnnotationType.HIGHLIGHT;
  59780. this._preparePopup(parameters.dict);
  59781. // PDF viewers completely ignore any border styles.
  59782. this.data.borderStyle.setWidth(0);
  59783. }
  59784. Util.inherit(HighlightAnnotation, Annotation, {});
  59785. return HighlightAnnotation;
  59786. }();
  59787. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  59788. function UnderlineAnnotation(parameters) {
  59789. Annotation.call(this, parameters);
  59790. this.data.annotationType = AnnotationType.UNDERLINE;
  59791. this._preparePopup(parameters.dict);
  59792. // PDF viewers completely ignore any border styles.
  59793. this.data.borderStyle.setWidth(0);
  59794. }
  59795. Util.inherit(UnderlineAnnotation, Annotation, {});
  59796. return UnderlineAnnotation;
  59797. }();
  59798. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  59799. function SquigglyAnnotation(parameters) {
  59800. Annotation.call(this, parameters);
  59801. this.data.annotationType = AnnotationType.SQUIGGLY;
  59802. this._preparePopup(parameters.dict);
  59803. // PDF viewers completely ignore any border styles.
  59804. this.data.borderStyle.setWidth(0);
  59805. }
  59806. Util.inherit(SquigglyAnnotation, Annotation, {});
  59807. return SquigglyAnnotation;
  59808. }();
  59809. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  59810. function StrikeOutAnnotation(parameters) {
  59811. Annotation.call(this, parameters);
  59812. this.data.annotationType = AnnotationType.STRIKEOUT;
  59813. this._preparePopup(parameters.dict);
  59814. // PDF viewers completely ignore any border styles.
  59815. this.data.borderStyle.setWidth(0);
  59816. }
  59817. Util.inherit(StrikeOutAnnotation, Annotation, {});
  59818. return StrikeOutAnnotation;
  59819. }();
  59820. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  59821. function FileAttachmentAnnotation(parameters) {
  59822. Annotation.call(this, parameters);
  59823. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  59824. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  59825. this.data.file = file.serializable;
  59826. this._preparePopup(parameters.dict);
  59827. }
  59828. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  59829. return FileAttachmentAnnotation;
  59830. }();
  59831. exports.Annotation = Annotation;
  59832. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  59833. exports.AnnotationFactory = AnnotationFactory;
  59834. }));
  59835. (function (root, factory) {
  59836. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  59837. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  59838. var MissingDataException = sharedUtil.MissingDataException;
  59839. var Util = sharedUtil.Util;
  59840. var assert = sharedUtil.assert;
  59841. var error = sharedUtil.error;
  59842. var info = sharedUtil.info;
  59843. var isArray = sharedUtil.isArray;
  59844. var isArrayBuffer = sharedUtil.isArrayBuffer;
  59845. var isString = sharedUtil.isString;
  59846. var shadow = sharedUtil.shadow;
  59847. var stringToBytes = sharedUtil.stringToBytes;
  59848. var stringToPDFString = sharedUtil.stringToPDFString;
  59849. var warn = sharedUtil.warn;
  59850. var isSpace = sharedUtil.isSpace;
  59851. var Dict = corePrimitives.Dict;
  59852. var isDict = corePrimitives.isDict;
  59853. var isName = corePrimitives.isName;
  59854. var isStream = corePrimitives.isStream;
  59855. var NullStream = coreStream.NullStream;
  59856. var Stream = coreStream.Stream;
  59857. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  59858. var Catalog = coreObj.Catalog;
  59859. var ObjectLoader = coreObj.ObjectLoader;
  59860. var XRef = coreObj.XRef;
  59861. var Linearization = coreParser.Linearization;
  59862. var calculateMD5 = coreCrypto.calculateMD5;
  59863. var OperatorList = coreEvaluator.OperatorList;
  59864. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  59865. var Annotation = coreAnnotation.Annotation;
  59866. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  59867. var Page = function PageClosure() {
  59868. var LETTER_SIZE_MEDIABOX = [
  59869. 0,
  59870. 0,
  59871. 612,
  59872. 792
  59873. ];
  59874. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  59875. this.pdfManager = pdfManager;
  59876. this.pageIndex = pageIndex;
  59877. this.pageDict = pageDict;
  59878. this.xref = xref;
  59879. this.ref = ref;
  59880. this.fontCache = fontCache;
  59881. this.uniquePrefix = 'p' + this.pageIndex + '_';
  59882. this.idCounters = { obj: 0 };
  59883. this.evaluatorOptions = pdfManager.evaluatorOptions;
  59884. this.resourcesPromise = null;
  59885. }
  59886. Page.prototype = {
  59887. getPageProp: function Page_getPageProp(key) {
  59888. return this.pageDict.get(key);
  59889. },
  59890. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  59891. var dict = this.pageDict, valueArray = null, loopCount = 0;
  59892. var MAX_LOOP_COUNT = 100;
  59893. // Always walk up the entire parent chain, to be able to find
  59894. // e.g. \Resources placed on multiple levels of the tree.
  59895. while (dict) {
  59896. var value = dict.get(key);
  59897. if (value) {
  59898. if (!valueArray) {
  59899. valueArray = [];
  59900. }
  59901. valueArray.push(value);
  59902. }
  59903. if (++loopCount > MAX_LOOP_COUNT) {
  59904. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  59905. break;
  59906. }
  59907. dict = dict.get('Parent');
  59908. }
  59909. if (!valueArray) {
  59910. return Dict.empty;
  59911. }
  59912. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  59913. return valueArray[0];
  59914. }
  59915. return Dict.merge(this.xref, valueArray);
  59916. },
  59917. get content() {
  59918. return this.getPageProp('Contents');
  59919. },
  59920. get resources() {
  59921. // For robustness: The spec states that a \Resources entry has to be
  59922. // present, but can be empty. Some document omit it still, in this case
  59923. // we return an empty dictionary.
  59924. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  59925. },
  59926. get mediaBox() {
  59927. var obj = this.getInheritedPageProp('MediaBox');
  59928. // Reset invalid media box to letter size.
  59929. if (!isArray(obj) || obj.length !== 4) {
  59930. obj = LETTER_SIZE_MEDIABOX;
  59931. }
  59932. return shadow(this, 'mediaBox', obj);
  59933. },
  59934. get view() {
  59935. var mediaBox = this.mediaBox;
  59936. var cropBox = this.getInheritedPageProp('CropBox');
  59937. if (!isArray(cropBox) || cropBox.length !== 4) {
  59938. return shadow(this, 'view', mediaBox);
  59939. }
  59940. // From the spec, 6th ed., p.963:
  59941. // "The crop, bleed, trim, and art boxes should not ordinarily
  59942. // extend beyond the boundaries of the media box. If they do, they are
  59943. // effectively reduced to their intersection with the media box."
  59944. cropBox = Util.intersect(cropBox, mediaBox);
  59945. if (!cropBox) {
  59946. return shadow(this, 'view', mediaBox);
  59947. }
  59948. return shadow(this, 'view', cropBox);
  59949. },
  59950. get rotate() {
  59951. var rotate = this.getInheritedPageProp('Rotate') || 0;
  59952. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  59953. if (rotate % 90 !== 0) {
  59954. rotate = 0;
  59955. } else if (rotate >= 360) {
  59956. rotate = rotate % 360;
  59957. } else if (rotate < 0) {
  59958. // The spec doesn't cover negatives, assume its counterclockwise
  59959. // rotation. The following is the other implementation of modulo.
  59960. rotate = (rotate % 360 + 360) % 360;
  59961. }
  59962. return shadow(this, 'rotate', rotate);
  59963. },
  59964. getContentStream: function Page_getContentStream() {
  59965. var content = this.content;
  59966. var stream;
  59967. if (isArray(content)) {
  59968. // fetching items
  59969. var xref = this.xref;
  59970. var i, n = content.length;
  59971. var streams = [];
  59972. for (i = 0; i < n; ++i) {
  59973. streams.push(xref.fetchIfRef(content[i]));
  59974. }
  59975. stream = new StreamsSequenceStream(streams);
  59976. } else if (isStream(content)) {
  59977. stream = content;
  59978. } else {
  59979. // replacing non-existent page content with empty one
  59980. stream = new NullStream();
  59981. }
  59982. return stream;
  59983. },
  59984. loadResources: function Page_loadResources(keys) {
  59985. if (!this.resourcesPromise) {
  59986. // TODO: add async getInheritedPageProp and remove this.
  59987. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  59988. }
  59989. return this.resourcesPromise.then(function resourceSuccess() {
  59990. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  59991. return objectLoader.load();
  59992. }.bind(this));
  59993. },
  59994. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  59995. var self = this;
  59996. var pdfManager = this.pdfManager;
  59997. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  59998. var resourcesPromise = this.loadResources([
  59999. 'ExtGState',
  60000. 'ColorSpace',
  60001. 'Pattern',
  60002. 'Shading',
  60003. 'XObject',
  60004. 'Font'
  60005. ]);
  60006. // ProcSet
  60007. // Properties
  60008. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  60009. var dataPromises = Promise.all([
  60010. contentStreamPromise,
  60011. resourcesPromise
  60012. ]);
  60013. var pageListPromise = dataPromises.then(function (data) {
  60014. var contentStream = data[0];
  60015. var opList = new OperatorList(intent, handler, self.pageIndex);
  60016. handler.send('StartRenderPage', {
  60017. transparency: partialEvaluator.hasBlendModes(self.resources),
  60018. pageIndex: self.pageIndex,
  60019. intent: intent
  60020. });
  60021. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  60022. return opList;
  60023. });
  60024. });
  60025. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  60026. return Promise.all([
  60027. pageListPromise,
  60028. annotationsPromise
  60029. ]).then(function (datas) {
  60030. var pageOpList = datas[0];
  60031. var annotations = datas[1];
  60032. if (annotations.length === 0) {
  60033. pageOpList.flush(true);
  60034. return pageOpList;
  60035. }
  60036. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  60037. return annotationsReadyPromise.then(function () {
  60038. pageOpList.flush(true);
  60039. return pageOpList;
  60040. });
  60041. });
  60042. },
  60043. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  60044. var handler = {
  60045. on: function nullHandlerOn() {
  60046. },
  60047. send: function nullHandlerSend() {
  60048. }
  60049. };
  60050. var self = this;
  60051. var pdfManager = this.pdfManager;
  60052. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  60053. var resourcesPromise = this.loadResources([
  60054. 'ExtGState',
  60055. 'XObject',
  60056. 'Font'
  60057. ]);
  60058. var dataPromises = Promise.all([
  60059. contentStreamPromise,
  60060. resourcesPromise
  60061. ]);
  60062. return dataPromises.then(function (data) {
  60063. var contentStream = data[0];
  60064. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  60065. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  60066. null, normalizeWhitespace, combineTextItems);
  60067. });
  60068. },
  60069. getAnnotationsData: function Page_getAnnotationsData(intent) {
  60070. var annotations = this.annotations;
  60071. var annotationsData = [];
  60072. for (var i = 0, n = annotations.length; i < n; ++i) {
  60073. if (intent) {
  60074. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  60075. continue;
  60076. }
  60077. }
  60078. annotationsData.push(annotations[i].data);
  60079. }
  60080. return annotationsData;
  60081. },
  60082. get annotations() {
  60083. var annotations = [];
  60084. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  60085. var annotationFactory = new AnnotationFactory();
  60086. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  60087. var annotationRef = annotationRefs[i];
  60088. var annotation = annotationFactory.create(this.xref, annotationRef, this.pdfManager, this.uniquePrefix, this.idCounters);
  60089. if (annotation) {
  60090. annotations.push(annotation);
  60091. }
  60092. }
  60093. return shadow(this, 'annotations', annotations);
  60094. }
  60095. };
  60096. return Page;
  60097. }();
  60098. /**
  60099. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  60100. * `PDFDoc`, this one doesn't have any job management code.
  60101. * Right now there exists one PDFDocument on the main thread + one object
  60102. * for each worker. If there is no worker support enabled, there are two
  60103. * `PDFDocument` objects on the main thread created.
  60104. */
  60105. var PDFDocument = function PDFDocumentClosure() {
  60106. var FINGERPRINT_FIRST_BYTES = 1024;
  60107. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  60108. function PDFDocument(pdfManager, arg, password) {
  60109. if (isStream(arg)) {
  60110. init.call(this, pdfManager, arg, password);
  60111. } else if (isArrayBuffer(arg)) {
  60112. init.call(this, pdfManager, new Stream(arg), password);
  60113. } else {
  60114. error('PDFDocument: Unknown argument type');
  60115. }
  60116. }
  60117. function init(pdfManager, stream, password) {
  60118. assert(stream.length > 0, 'stream must have data');
  60119. this.pdfManager = pdfManager;
  60120. this.stream = stream;
  60121. var xref = new XRef(this.stream, password, pdfManager);
  60122. this.xref = xref;
  60123. }
  60124. function find(stream, needle, limit, backwards) {
  60125. var pos = stream.pos;
  60126. var end = stream.end;
  60127. var strBuf = [];
  60128. if (pos + limit > end) {
  60129. limit = end - pos;
  60130. }
  60131. for (var n = 0; n < limit; ++n) {
  60132. strBuf.push(String.fromCharCode(stream.getByte()));
  60133. }
  60134. var str = strBuf.join('');
  60135. stream.pos = pos;
  60136. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  60137. if (index === -1) {
  60138. return false;
  60139. }
  60140. /* not found */
  60141. stream.pos += index;
  60142. return true;
  60143. }
  60144. /* found */
  60145. var DocumentInfoValidators = {
  60146. get entries() {
  60147. // Lazily build this since all the validation functions below are not
  60148. // defined until after this file loads.
  60149. return shadow(this, 'entries', {
  60150. Title: isString,
  60151. Author: isString,
  60152. Subject: isString,
  60153. Keywords: isString,
  60154. Creator: isString,
  60155. Producer: isString,
  60156. CreationDate: isString,
  60157. ModDate: isString,
  60158. Trapped: isName
  60159. });
  60160. }
  60161. };
  60162. PDFDocument.prototype = {
  60163. parse: function PDFDocument_parse(recoveryMode) {
  60164. this.setup(recoveryMode);
  60165. var version = this.catalog.catDict.get('Version');
  60166. if (isName(version)) {
  60167. this.pdfFormatVersion = version.name;
  60168. }
  60169. try {
  60170. // checking if AcroForm is present
  60171. this.acroForm = this.catalog.catDict.get('AcroForm');
  60172. if (this.acroForm) {
  60173. this.xfa = this.acroForm.get('XFA');
  60174. var fields = this.acroForm.get('Fields');
  60175. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  60176. // no fields and no XFA -- not a form (?)
  60177. this.acroForm = null;
  60178. }
  60179. }
  60180. } catch (ex) {
  60181. info('Something wrong with AcroForm entry');
  60182. this.acroForm = null;
  60183. }
  60184. },
  60185. get linearization() {
  60186. var linearization = null;
  60187. if (this.stream.length) {
  60188. try {
  60189. linearization = Linearization.create(this.stream);
  60190. } catch (err) {
  60191. if (err instanceof MissingDataException) {
  60192. throw err;
  60193. }
  60194. info(err);
  60195. }
  60196. }
  60197. // shadow the prototype getter with a data property
  60198. return shadow(this, 'linearization', linearization);
  60199. },
  60200. get startXRef() {
  60201. var stream = this.stream;
  60202. var startXRef = 0;
  60203. var linearization = this.linearization;
  60204. if (linearization) {
  60205. // Find end of first obj.
  60206. stream.reset();
  60207. if (find(stream, 'endobj', 1024)) {
  60208. startXRef = stream.pos + 6;
  60209. }
  60210. } else {
  60211. // Find startxref by jumping backward from the end of the file.
  60212. var step = 1024;
  60213. var found = false, pos = stream.end;
  60214. while (!found && pos > 0) {
  60215. pos -= step - 'startxref'.length;
  60216. if (pos < 0) {
  60217. pos = 0;
  60218. }
  60219. stream.pos = pos;
  60220. found = find(stream, 'startxref', step, true);
  60221. }
  60222. if (found) {
  60223. stream.skip(9);
  60224. var ch;
  60225. do {
  60226. ch = stream.getByte();
  60227. } while (isSpace(ch));
  60228. var str = '';
  60229. while (ch >= 0x20 && ch <= 0x39) {
  60230. // < '9'
  60231. str += String.fromCharCode(ch);
  60232. ch = stream.getByte();
  60233. }
  60234. startXRef = parseInt(str, 10);
  60235. if (isNaN(startXRef)) {
  60236. startXRef = 0;
  60237. }
  60238. }
  60239. }
  60240. // shadow the prototype getter with a data property
  60241. return shadow(this, 'startXRef', startXRef);
  60242. },
  60243. get mainXRefEntriesOffset() {
  60244. var mainXRefEntriesOffset = 0;
  60245. var linearization = this.linearization;
  60246. if (linearization) {
  60247. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  60248. }
  60249. // shadow the prototype getter with a data property
  60250. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  60251. },
  60252. // Find the header, remove leading garbage and setup the stream
  60253. // starting from the header.
  60254. checkHeader: function PDFDocument_checkHeader() {
  60255. var stream = this.stream;
  60256. stream.reset();
  60257. if (find(stream, '%PDF-', 1024)) {
  60258. // Found the header, trim off any garbage before it.
  60259. stream.moveStart();
  60260. // Reading file format version
  60261. var MAX_VERSION_LENGTH = 12;
  60262. var version = '', ch;
  60263. while ((ch = stream.getByte()) > 0x20) {
  60264. // SPACE
  60265. if (version.length >= MAX_VERSION_LENGTH) {
  60266. break;
  60267. }
  60268. version += String.fromCharCode(ch);
  60269. }
  60270. if (!this.pdfFormatVersion) {
  60271. // removing "%PDF-"-prefix
  60272. this.pdfFormatVersion = version.substring(5);
  60273. }
  60274. return;
  60275. }
  60276. },
  60277. // May not be a PDF file, continue anyway.
  60278. parseStartXRef: function PDFDocument_parseStartXRef() {
  60279. var startXRef = this.startXRef;
  60280. this.xref.setStartXRef(startXRef);
  60281. },
  60282. setup: function PDFDocument_setup(recoveryMode) {
  60283. this.xref.parse(recoveryMode);
  60284. var self = this;
  60285. var pageFactory = {
  60286. createPage: function (pageIndex, dict, ref, fontCache) {
  60287. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  60288. }
  60289. };
  60290. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  60291. },
  60292. get numPages() {
  60293. var linearization = this.linearization;
  60294. var num = linearization ? linearization.numPages : this.catalog.numPages;
  60295. // shadow the prototype getter
  60296. return shadow(this, 'numPages', num);
  60297. },
  60298. get documentInfo() {
  60299. var docInfo = {
  60300. PDFFormatVersion: this.pdfFormatVersion,
  60301. IsAcroFormPresent: !!this.acroForm,
  60302. IsXFAPresent: !!this.xfa
  60303. };
  60304. var infoDict;
  60305. try {
  60306. infoDict = this.xref.trailer.get('Info');
  60307. } catch (err) {
  60308. info('The document information dictionary is invalid.');
  60309. }
  60310. if (infoDict) {
  60311. var validEntries = DocumentInfoValidators.entries;
  60312. // Only fill the document info with valid entries from the spec.
  60313. for (var key in validEntries) {
  60314. if (infoDict.has(key)) {
  60315. var value = infoDict.get(key);
  60316. // Make sure the value conforms to the spec.
  60317. if (validEntries[key](value)) {
  60318. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  60319. } else {
  60320. info('Bad value in document info for "' + key + '"');
  60321. }
  60322. }
  60323. }
  60324. }
  60325. return shadow(this, 'documentInfo', docInfo);
  60326. },
  60327. get fingerprint() {
  60328. var xref = this.xref, hash, fileID = '';
  60329. var idArray = xref.trailer.get('ID');
  60330. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  60331. hash = stringToBytes(idArray[0]);
  60332. } else {
  60333. if (this.stream.ensureRange) {
  60334. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  60335. }
  60336. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  60337. }
  60338. for (var i = 0, n = hash.length; i < n; i++) {
  60339. var hex = hash[i].toString(16);
  60340. fileID += hex.length === 1 ? '0' + hex : hex;
  60341. }
  60342. return shadow(this, 'fingerprint', fileID);
  60343. },
  60344. getPage: function PDFDocument_getPage(pageIndex) {
  60345. return this.catalog.getPage(pageIndex);
  60346. },
  60347. cleanup: function PDFDocument_cleanup() {
  60348. return this.catalog.cleanup();
  60349. }
  60350. };
  60351. return PDFDocument;
  60352. }();
  60353. exports.Page = Page;
  60354. exports.PDFDocument = PDFDocument;
  60355. }));
  60356. (function (root, factory) {
  60357. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  60358. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  60359. var warn = sharedUtil.warn;
  60360. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  60361. var shadow = sharedUtil.shadow;
  60362. var NotImplementedException = sharedUtil.NotImplementedException;
  60363. var MissingDataException = sharedUtil.MissingDataException;
  60364. var createPromiseCapability = sharedUtil.createPromiseCapability;
  60365. var Util = sharedUtil.Util;
  60366. var Stream = coreStream.Stream;
  60367. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  60368. var PDFDocument = coreDocument.PDFDocument;
  60369. var BasePdfManager = function BasePdfManagerClosure() {
  60370. function BasePdfManager() {
  60371. throw new Error('Cannot initialize BaseManagerManager');
  60372. }
  60373. BasePdfManager.prototype = {
  60374. get docId() {
  60375. return this._docId;
  60376. },
  60377. get docBaseUrl() {
  60378. var docBaseUrl = null;
  60379. if (this._docBaseUrl) {
  60380. var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
  60381. if (absoluteUrl) {
  60382. docBaseUrl = absoluteUrl.href;
  60383. } else {
  60384. warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
  60385. }
  60386. }
  60387. return shadow(this, 'docBaseUrl', docBaseUrl);
  60388. },
  60389. onLoadedStream: function BasePdfManager_onLoadedStream() {
  60390. throw new NotImplementedException();
  60391. },
  60392. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  60393. return this.ensure(this.pdfDocument, prop, args);
  60394. },
  60395. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  60396. return this.ensure(this.pdfDocument.xref, prop, args);
  60397. },
  60398. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  60399. return this.ensure(this.pdfDocument.catalog, prop, args);
  60400. },
  60401. getPage: function BasePdfManager_getPage(pageIndex) {
  60402. return this.pdfDocument.getPage(pageIndex);
  60403. },
  60404. cleanup: function BasePdfManager_cleanup() {
  60405. return this.pdfDocument.cleanup();
  60406. },
  60407. ensure: function BasePdfManager_ensure(obj, prop, args) {
  60408. return new NotImplementedException();
  60409. },
  60410. requestRange: function BasePdfManager_requestRange(begin, end) {
  60411. return new NotImplementedException();
  60412. },
  60413. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  60414. return new NotImplementedException();
  60415. },
  60416. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  60417. return new NotImplementedException();
  60418. },
  60419. updatePassword: function BasePdfManager_updatePassword(password) {
  60420. this.pdfDocument.xref.password = this.password = password;
  60421. if (this._passwordChangedCapability) {
  60422. this._passwordChangedCapability.resolve();
  60423. }
  60424. },
  60425. passwordChanged: function BasePdfManager_passwordChanged() {
  60426. this._passwordChangedCapability = createPromiseCapability();
  60427. return this._passwordChangedCapability.promise;
  60428. },
  60429. terminate: function BasePdfManager_terminate() {
  60430. return new NotImplementedException();
  60431. }
  60432. };
  60433. return BasePdfManager;
  60434. }();
  60435. var LocalPdfManager = function LocalPdfManagerClosure() {
  60436. function LocalPdfManager(docId, data, password, evaluatorOptions, docBaseUrl) {
  60437. this._docId = docId;
  60438. this._docBaseUrl = docBaseUrl;
  60439. this.evaluatorOptions = evaluatorOptions;
  60440. var stream = new Stream(data);
  60441. this.pdfDocument = new PDFDocument(this, stream, password);
  60442. this._loadedStreamCapability = createPromiseCapability();
  60443. this._loadedStreamCapability.resolve(stream);
  60444. }
  60445. Util.inherit(LocalPdfManager, BasePdfManager, {
  60446. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  60447. return new Promise(function (resolve, reject) {
  60448. try {
  60449. var value = obj[prop];
  60450. var result;
  60451. if (typeof value === 'function') {
  60452. result = value.apply(obj, args);
  60453. } else {
  60454. result = value;
  60455. }
  60456. resolve(result);
  60457. } catch (e) {
  60458. reject(e);
  60459. }
  60460. });
  60461. },
  60462. requestRange: function LocalPdfManager_requestRange(begin, end) {
  60463. return Promise.resolve();
  60464. },
  60465. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  60466. return;
  60467. },
  60468. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  60469. return this._loadedStreamCapability.promise;
  60470. },
  60471. terminate: function LocalPdfManager_terminate() {
  60472. return;
  60473. }
  60474. });
  60475. return LocalPdfManager;
  60476. }();
  60477. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  60478. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) {
  60479. this._docId = docId;
  60480. this._docBaseUrl = docBaseUrl;
  60481. this.msgHandler = args.msgHandler;
  60482. this.evaluatorOptions = evaluatorOptions;
  60483. var params = {
  60484. msgHandler: args.msgHandler,
  60485. url: args.url,
  60486. length: args.length,
  60487. disableAutoFetch: args.disableAutoFetch,
  60488. rangeChunkSize: args.rangeChunkSize
  60489. };
  60490. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  60491. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  60492. }
  60493. Util.inherit(NetworkPdfManager, BasePdfManager, {
  60494. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  60495. var pdfManager = this;
  60496. return new Promise(function (resolve, reject) {
  60497. function ensureHelper() {
  60498. try {
  60499. var result;
  60500. var value = obj[prop];
  60501. if (typeof value === 'function') {
  60502. result = value.apply(obj, args);
  60503. } else {
  60504. result = value;
  60505. }
  60506. resolve(result);
  60507. } catch (e) {
  60508. if (!(e instanceof MissingDataException)) {
  60509. reject(e);
  60510. return;
  60511. }
  60512. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  60513. }
  60514. }
  60515. ensureHelper();
  60516. });
  60517. },
  60518. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  60519. return this.streamManager.requestRange(begin, end);
  60520. },
  60521. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  60522. this.streamManager.requestAllChunks();
  60523. },
  60524. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  60525. this.streamManager.onReceiveData({ chunk: chunk });
  60526. },
  60527. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  60528. return this.streamManager.onLoadedStream();
  60529. },
  60530. terminate: function NetworkPdfManager_terminate() {
  60531. this.streamManager.abort();
  60532. }
  60533. });
  60534. return NetworkPdfManager;
  60535. }();
  60536. exports.LocalPdfManager = LocalPdfManager;
  60537. exports.NetworkPdfManager = NetworkPdfManager;
  60538. }));
  60539. (function (root, factory) {
  60540. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  60541. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  60542. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  60543. var InvalidPDFException = sharedUtil.InvalidPDFException;
  60544. var MessageHandler = sharedUtil.MessageHandler;
  60545. var MissingPDFException = sharedUtil.MissingPDFException;
  60546. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  60547. var PasswordException = sharedUtil.PasswordException;
  60548. var PasswordResponses = sharedUtil.PasswordResponses;
  60549. var UnknownErrorException = sharedUtil.UnknownErrorException;
  60550. var XRefParseException = sharedUtil.XRefParseException;
  60551. var arrayByteLength = sharedUtil.arrayByteLength;
  60552. var arraysToBytes = sharedUtil.arraysToBytes;
  60553. var assert = sharedUtil.assert;
  60554. var createPromiseCapability = sharedUtil.createPromiseCapability;
  60555. var error = sharedUtil.error;
  60556. var info = sharedUtil.info;
  60557. var warn = sharedUtil.warn;
  60558. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  60559. var Ref = corePrimitives.Ref;
  60560. var LocalPdfManager = corePdfManager.LocalPdfManager;
  60561. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  60562. var globalScope = sharedUtil.globalScope;
  60563. var WorkerTask = function WorkerTaskClosure() {
  60564. function WorkerTask(name) {
  60565. this.name = name;
  60566. this.terminated = false;
  60567. this._capability = createPromiseCapability();
  60568. }
  60569. WorkerTask.prototype = {
  60570. get finished() {
  60571. return this._capability.promise;
  60572. },
  60573. finish: function () {
  60574. this._capability.resolve();
  60575. },
  60576. terminate: function () {
  60577. this.terminated = true;
  60578. },
  60579. ensureNotTerminated: function () {
  60580. if (this.terminated) {
  60581. throw new Error('Worker task was terminated');
  60582. }
  60583. }
  60584. };
  60585. return WorkerTask;
  60586. }();
  60587. /** @implements {IPDFStream} */
  60588. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  60589. function PDFWorkerStream(params, msgHandler) {
  60590. this._queuedChunks = [];
  60591. var initialData = params.initialData;
  60592. if (initialData && initialData.length > 0) {
  60593. this._queuedChunks.push(initialData);
  60594. }
  60595. this._msgHandler = msgHandler;
  60596. this._isRangeSupported = !params.disableRange;
  60597. this._isStreamingSupported = !params.disableStream;
  60598. this._contentLength = params.length;
  60599. this._fullRequestReader = null;
  60600. this._rangeReaders = [];
  60601. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  60602. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  60603. }
  60604. PDFWorkerStream.prototype = {
  60605. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  60606. if (args.begin === undefined) {
  60607. if (this._fullRequestReader) {
  60608. this._fullRequestReader._enqueue(args.chunk);
  60609. } else {
  60610. this._queuedChunks.push(args.chunk);
  60611. }
  60612. } else {
  60613. var found = this._rangeReaders.some(function (rangeReader) {
  60614. if (rangeReader._begin !== args.begin) {
  60615. return false;
  60616. }
  60617. rangeReader._enqueue(args.chunk);
  60618. return true;
  60619. });
  60620. assert(found);
  60621. }
  60622. },
  60623. _onProgress: function PDFWorkerStream_onProgress(evt) {
  60624. if (this._rangeReaders.length > 0) {
  60625. // Reporting to first range reader.
  60626. var firstReader = this._rangeReaders[0];
  60627. if (firstReader.onProgress) {
  60628. firstReader.onProgress({ loaded: evt.loaded });
  60629. }
  60630. }
  60631. },
  60632. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  60633. var i = this._rangeReaders.indexOf(reader);
  60634. if (i >= 0) {
  60635. this._rangeReaders.splice(i, 1);
  60636. }
  60637. },
  60638. getFullReader: function PDFWorkerStream_getFullReader() {
  60639. assert(!this._fullRequestReader);
  60640. var queuedChunks = this._queuedChunks;
  60641. this._queuedChunks = null;
  60642. return new PDFWorkerStreamReader(this, queuedChunks);
  60643. },
  60644. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  60645. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  60646. this._msgHandler.send('RequestDataRange', {
  60647. begin: begin,
  60648. end: end
  60649. });
  60650. this._rangeReaders.push(reader);
  60651. return reader;
  60652. },
  60653. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  60654. if (this._fullRequestReader) {
  60655. this._fullRequestReader.cancel(reason);
  60656. }
  60657. var readers = this._rangeReaders.slice(0);
  60658. readers.forEach(function (rangeReader) {
  60659. rangeReader.cancel(reason);
  60660. });
  60661. }
  60662. };
  60663. /** @implements {IPDFStreamReader} */
  60664. function PDFWorkerStreamReader(stream, queuedChunks) {
  60665. this._stream = stream;
  60666. this._done = false;
  60667. this._queuedChunks = queuedChunks || [];
  60668. this._requests = [];
  60669. this._headersReady = Promise.resolve();
  60670. stream._fullRequestReader = this;
  60671. this.onProgress = null;
  60672. }
  60673. // not used
  60674. PDFWorkerStreamReader.prototype = {
  60675. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  60676. if (this._done) {
  60677. return;
  60678. }
  60679. // ignore new data
  60680. if (this._requests.length > 0) {
  60681. var requestCapability = this._requests.shift();
  60682. requestCapability.resolve({
  60683. value: chunk,
  60684. done: false
  60685. });
  60686. return;
  60687. }
  60688. this._queuedChunks.push(chunk);
  60689. },
  60690. get headersReady() {
  60691. return this._headersReady;
  60692. },
  60693. get isRangeSupported() {
  60694. return this._stream._isRangeSupported;
  60695. },
  60696. get isStreamingSupported() {
  60697. return this._stream._isStreamingSupported;
  60698. },
  60699. get contentLength() {
  60700. return this._stream._contentLength;
  60701. },
  60702. read: function PDFWorkerStreamReader_read() {
  60703. if (this._queuedChunks.length > 0) {
  60704. var chunk = this._queuedChunks.shift();
  60705. return Promise.resolve({
  60706. value: chunk,
  60707. done: false
  60708. });
  60709. }
  60710. if (this._done) {
  60711. return Promise.resolve({
  60712. value: undefined,
  60713. done: true
  60714. });
  60715. }
  60716. var requestCapability = createPromiseCapability();
  60717. this._requests.push(requestCapability);
  60718. return requestCapability.promise;
  60719. },
  60720. cancel: function PDFWorkerStreamReader_cancel(reason) {
  60721. this._done = true;
  60722. this._requests.forEach(function (requestCapability) {
  60723. requestCapability.resolve({
  60724. value: undefined,
  60725. done: true
  60726. });
  60727. });
  60728. this._requests = [];
  60729. }
  60730. };
  60731. /** @implements {IPDFStreamRangeReader} */
  60732. function PDFWorkerStreamRangeReader(stream, begin, end) {
  60733. this._stream = stream;
  60734. this._begin = begin;
  60735. this._end = end;
  60736. this._queuedChunk = null;
  60737. this._requests = [];
  60738. this._done = false;
  60739. this.onProgress = null;
  60740. }
  60741. PDFWorkerStreamRangeReader.prototype = {
  60742. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  60743. if (this._done) {
  60744. return;
  60745. }
  60746. // ignore new data
  60747. if (this._requests.length === 0) {
  60748. this._queuedChunk = chunk;
  60749. } else {
  60750. var requestsCapability = this._requests.shift();
  60751. requestsCapability.resolve({
  60752. value: chunk,
  60753. done: false
  60754. });
  60755. this._requests.forEach(function (requestCapability) {
  60756. requestCapability.resolve({
  60757. value: undefined,
  60758. done: true
  60759. });
  60760. });
  60761. this._requests = [];
  60762. }
  60763. this._done = true;
  60764. this._stream._removeRangeReader(this);
  60765. },
  60766. get isStreamingSupported() {
  60767. return false;
  60768. },
  60769. read: function PDFWorkerStreamRangeReader_read() {
  60770. if (this._queuedChunk) {
  60771. return Promise.resolve({
  60772. value: this._queuedChunk,
  60773. done: false
  60774. });
  60775. }
  60776. if (this._done) {
  60777. return Promise.resolve({
  60778. value: undefined,
  60779. done: true
  60780. });
  60781. }
  60782. var requestCapability = createPromiseCapability();
  60783. this._requests.push(requestCapability);
  60784. return requestCapability.promise;
  60785. },
  60786. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  60787. this._done = true;
  60788. this._requests.forEach(function (requestCapability) {
  60789. requestCapability.resolve({
  60790. value: undefined,
  60791. done: true
  60792. });
  60793. });
  60794. this._requests = [];
  60795. this._stream._removeRangeReader(this);
  60796. }
  60797. };
  60798. return PDFWorkerStream;
  60799. }();
  60800. /** @type IPDFStream */
  60801. var PDFNetworkStream;
  60802. /**
  60803. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  60804. * @param {IPDFStream} cls - the PDF data transport.
  60805. */
  60806. function setPDFNetworkStreamClass(cls) {
  60807. PDFNetworkStream = cls;
  60808. }
  60809. var WorkerMessageHandler = {
  60810. setup: function wphSetup(handler, port) {
  60811. var testMessageProcessed = false;
  60812. handler.on('test', function wphSetupTest(data) {
  60813. if (testMessageProcessed) {
  60814. return;
  60815. }
  60816. // we already processed 'test' message once
  60817. testMessageProcessed = true;
  60818. // check if Uint8Array can be sent to worker
  60819. if (!(data instanceof Uint8Array)) {
  60820. handler.send('test', 'main', false);
  60821. return;
  60822. }
  60823. // making sure postMessage transfers are working
  60824. var supportTransfers = data[0] === 255;
  60825. handler.postMessageTransfers = supportTransfers;
  60826. // check if the response property is supported by xhr
  60827. var xhr = new XMLHttpRequest();
  60828. var responseExists = 'response' in xhr;
  60829. // check if the property is actually implemented
  60830. try {
  60831. var dummy = xhr.responseType;
  60832. } catch (e) {
  60833. responseExists = false;
  60834. }
  60835. if (!responseExists) {
  60836. handler.send('test', false);
  60837. return;
  60838. }
  60839. handler.send('test', {
  60840. supportTypedArray: true,
  60841. supportTransfers: supportTransfers
  60842. });
  60843. });
  60844. handler.on('configure', function wphConfigure(data) {
  60845. setVerbosityLevel(data.verbosity);
  60846. });
  60847. handler.on('GetDocRequest', function wphSetupDoc(data) {
  60848. return WorkerMessageHandler.createDocumentHandler(data, port);
  60849. });
  60850. },
  60851. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  60852. // This context is actually holds references on pdfManager and handler,
  60853. // until the latter is destroyed.
  60854. var pdfManager;
  60855. var terminated = false;
  60856. var cancelXHRs = null;
  60857. var WorkerTasks = [];
  60858. var docId = docParams.docId;
  60859. var docBaseUrl = docParams.docBaseUrl;
  60860. var workerHandlerName = docParams.docId + '_worker';
  60861. var handler = new MessageHandler(workerHandlerName, docId, port);
  60862. // Ensure that postMessage transfers are correctly enabled/disabled,
  60863. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  60864. handler.postMessageTransfers = docParams.postMessageTransfers;
  60865. function ensureNotTerminated() {
  60866. if (terminated) {
  60867. throw new Error('Worker was terminated');
  60868. }
  60869. }
  60870. function startWorkerTask(task) {
  60871. WorkerTasks.push(task);
  60872. }
  60873. function finishWorkerTask(task) {
  60874. task.finish();
  60875. var i = WorkerTasks.indexOf(task);
  60876. WorkerTasks.splice(i, 1);
  60877. }
  60878. function loadDocument(recoveryMode) {
  60879. var loadDocumentCapability = createPromiseCapability();
  60880. var parseSuccess = function parseSuccess() {
  60881. var numPagesPromise = pdfManager.ensureDoc('numPages');
  60882. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  60883. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  60884. Promise.all([
  60885. numPagesPromise,
  60886. fingerprintPromise,
  60887. encryptedPromise
  60888. ]).then(function onDocReady(results) {
  60889. var doc = {
  60890. numPages: results[0],
  60891. fingerprint: results[1],
  60892. encrypted: !!results[2]
  60893. };
  60894. loadDocumentCapability.resolve(doc);
  60895. }, parseFailure);
  60896. };
  60897. var parseFailure = function parseFailure(e) {
  60898. loadDocumentCapability.reject(e);
  60899. };
  60900. pdfManager.ensureDoc('checkHeader', []).then(function () {
  60901. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  60902. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  60903. }, parseFailure);
  60904. }, parseFailure);
  60905. return loadDocumentCapability.promise;
  60906. }
  60907. function getPdfManager(data, evaluatorOptions) {
  60908. var pdfManagerCapability = createPromiseCapability();
  60909. var pdfManager;
  60910. var source = data.source;
  60911. if (source.data) {
  60912. try {
  60913. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions, docBaseUrl);
  60914. pdfManagerCapability.resolve(pdfManager);
  60915. } catch (ex) {
  60916. pdfManagerCapability.reject(ex);
  60917. }
  60918. return pdfManagerCapability.promise;
  60919. }
  60920. var pdfStream;
  60921. try {
  60922. if (source.chunkedViewerLoading) {
  60923. pdfStream = new PDFWorkerStream(source, handler);
  60924. } else {
  60925. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  60926. pdfStream = new PDFNetworkStream(data);
  60927. }
  60928. } catch (ex) {
  60929. pdfManagerCapability.reject(ex);
  60930. return pdfManagerCapability.promise;
  60931. }
  60932. var fullRequest = pdfStream.getFullReader();
  60933. fullRequest.headersReady.then(function () {
  60934. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  60935. // If stream or range are disabled, it's our only way to report
  60936. // loading progress.
  60937. fullRequest.onProgress = function (evt) {
  60938. handler.send('DocProgress', {
  60939. loaded: evt.loaded,
  60940. total: evt.total
  60941. });
  60942. };
  60943. }
  60944. if (!fullRequest.isRangeSupported) {
  60945. return;
  60946. }
  60947. // We don't need auto-fetch when streaming is enabled.
  60948. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  60949. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  60950. msgHandler: handler,
  60951. url: source.url,
  60952. password: source.password,
  60953. length: fullRequest.contentLength,
  60954. disableAutoFetch: disableAutoFetch,
  60955. rangeChunkSize: source.rangeChunkSize
  60956. }, evaluatorOptions, docBaseUrl);
  60957. pdfManagerCapability.resolve(pdfManager);
  60958. cancelXHRs = null;
  60959. }).catch(function (reason) {
  60960. pdfManagerCapability.reject(reason);
  60961. cancelXHRs = null;
  60962. });
  60963. var cachedChunks = [], loaded = 0;
  60964. var flushChunks = function () {
  60965. var pdfFile = arraysToBytes(cachedChunks);
  60966. if (source.length && pdfFile.length !== source.length) {
  60967. warn('reported HTTP length is different from actual');
  60968. }
  60969. // the data is array, instantiating directly from it
  60970. try {
  60971. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions, docBaseUrl);
  60972. pdfManagerCapability.resolve(pdfManager);
  60973. } catch (ex) {
  60974. pdfManagerCapability.reject(ex);
  60975. }
  60976. cachedChunks = [];
  60977. };
  60978. var readPromise = new Promise(function (resolve, reject) {
  60979. var readChunk = function (chunk) {
  60980. try {
  60981. ensureNotTerminated();
  60982. if (chunk.done) {
  60983. if (!pdfManager) {
  60984. flushChunks();
  60985. }
  60986. cancelXHRs = null;
  60987. return;
  60988. }
  60989. var data = chunk.value;
  60990. loaded += arrayByteLength(data);
  60991. if (!fullRequest.isStreamingSupported) {
  60992. handler.send('DocProgress', {
  60993. loaded: loaded,
  60994. total: Math.max(loaded, fullRequest.contentLength || 0)
  60995. });
  60996. }
  60997. if (pdfManager) {
  60998. pdfManager.sendProgressiveData(data);
  60999. } else {
  61000. cachedChunks.push(data);
  61001. }
  61002. fullRequest.read().then(readChunk, reject);
  61003. } catch (e) {
  61004. reject(e);
  61005. }
  61006. };
  61007. fullRequest.read().then(readChunk, reject);
  61008. });
  61009. readPromise.catch(function (e) {
  61010. pdfManagerCapability.reject(e);
  61011. cancelXHRs = null;
  61012. });
  61013. cancelXHRs = function () {
  61014. pdfStream.cancelAllRequests('abort');
  61015. };
  61016. return pdfManagerCapability.promise;
  61017. }
  61018. var setupDoc = function (data) {
  61019. var onSuccess = function (doc) {
  61020. ensureNotTerminated();
  61021. handler.send('GetDoc', { pdfInfo: doc });
  61022. };
  61023. var onFailure = function (e) {
  61024. if (e instanceof PasswordException) {
  61025. if (e.code === PasswordResponses.NEED_PASSWORD) {
  61026. handler.send('NeedPassword', e);
  61027. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  61028. handler.send('IncorrectPassword', e);
  61029. }
  61030. } else if (e instanceof InvalidPDFException) {
  61031. handler.send('InvalidPDF', e);
  61032. } else if (e instanceof MissingPDFException) {
  61033. handler.send('MissingPDF', e);
  61034. } else if (e instanceof UnexpectedResponseException) {
  61035. handler.send('UnexpectedResponse', e);
  61036. } else {
  61037. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  61038. }
  61039. };
  61040. ensureNotTerminated();
  61041. var cMapOptions = {
  61042. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  61043. packed: data.cMapPacked === true
  61044. };
  61045. var evaluatorOptions = {
  61046. forceDataSchema: data.disableCreateObjectURL,
  61047. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  61048. disableFontFace: data.disableFontFace,
  61049. cMapOptions: cMapOptions
  61050. };
  61051. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  61052. if (terminated) {
  61053. // We were in a process of setting up the manager, but it got
  61054. // terminated in the middle.
  61055. newPdfManager.terminate();
  61056. throw new Error('Worker was terminated');
  61057. }
  61058. pdfManager = newPdfManager;
  61059. handler.send('PDFManagerReady', null);
  61060. pdfManager.onLoadedStream().then(function (stream) {
  61061. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  61062. });
  61063. }).then(function pdfManagerReady() {
  61064. ensureNotTerminated();
  61065. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  61066. ensureNotTerminated();
  61067. // Try again with recoveryMode == true
  61068. if (!(ex instanceof XRefParseException)) {
  61069. if (ex instanceof PasswordException) {
  61070. // after password exception prepare to receive a new password
  61071. // to repeat loading
  61072. pdfManager.passwordChanged().then(pdfManagerReady);
  61073. }
  61074. onFailure(ex);
  61075. return;
  61076. }
  61077. pdfManager.requestLoadedStream();
  61078. pdfManager.onLoadedStream().then(function () {
  61079. ensureNotTerminated();
  61080. loadDocument(true).then(onSuccess, onFailure);
  61081. });
  61082. }, onFailure);
  61083. }, onFailure);
  61084. };
  61085. handler.on('GetPage', function wphSetupGetPage(data) {
  61086. return pdfManager.getPage(data.pageIndex).then(function (page) {
  61087. var rotatePromise = pdfManager.ensure(page, 'rotate');
  61088. var refPromise = pdfManager.ensure(page, 'ref');
  61089. var viewPromise = pdfManager.ensure(page, 'view');
  61090. return Promise.all([
  61091. rotatePromise,
  61092. refPromise,
  61093. viewPromise
  61094. ]).then(function (results) {
  61095. return {
  61096. rotate: results[0],
  61097. ref: results[1],
  61098. view: results[2]
  61099. };
  61100. });
  61101. });
  61102. });
  61103. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  61104. var ref = new Ref(data.ref.num, data.ref.gen);
  61105. var catalog = pdfManager.pdfDocument.catalog;
  61106. return catalog.getPageIndex(ref);
  61107. });
  61108. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  61109. return pdfManager.ensureCatalog('destinations');
  61110. });
  61111. handler.on('GetDestination', function wphSetupGetDestination(data) {
  61112. return pdfManager.ensureCatalog('getDestination', [data.id]);
  61113. });
  61114. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  61115. return pdfManager.ensureCatalog('pageLabels');
  61116. });
  61117. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  61118. return pdfManager.ensureCatalog('attachments');
  61119. });
  61120. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  61121. return pdfManager.ensureCatalog('javaScript');
  61122. });
  61123. handler.on('GetOutline', function wphSetupGetOutline(data) {
  61124. return pdfManager.ensureCatalog('documentOutline');
  61125. });
  61126. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  61127. return Promise.all([
  61128. pdfManager.ensureDoc('documentInfo'),
  61129. pdfManager.ensureCatalog('metadata')
  61130. ]);
  61131. });
  61132. handler.on('GetData', function wphSetupGetData(data) {
  61133. pdfManager.requestLoadedStream();
  61134. return pdfManager.onLoadedStream().then(function (stream) {
  61135. return stream.bytes;
  61136. });
  61137. });
  61138. handler.on('GetStats', function wphSetupGetStats(data) {
  61139. return pdfManager.pdfDocument.xref.stats;
  61140. });
  61141. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  61142. pdfManager.updatePassword(data);
  61143. });
  61144. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  61145. return pdfManager.getPage(data.pageIndex).then(function (page) {
  61146. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  61147. });
  61148. });
  61149. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  61150. var pageIndex = data.pageIndex;
  61151. pdfManager.getPage(pageIndex).then(function (page) {
  61152. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  61153. startWorkerTask(task);
  61154. var pageNum = pageIndex + 1;
  61155. var start = Date.now();
  61156. // Pre compile the pdf page and fetch the fonts/images.
  61157. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  61158. finishWorkerTask(task);
  61159. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  61160. }, function (e) {
  61161. finishWorkerTask(task);
  61162. if (task.terminated) {
  61163. return;
  61164. }
  61165. // ignoring errors from the terminated thread
  61166. // For compatibility with older behavior, generating unknown
  61167. // unsupported feature notification on errors.
  61168. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  61169. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  61170. var wrappedException;
  61171. // Turn the error into an obj that can be serialized
  61172. if (typeof e === 'string') {
  61173. wrappedException = {
  61174. message: e,
  61175. stack: minimumStackMessage
  61176. };
  61177. } else if (typeof e === 'object') {
  61178. wrappedException = {
  61179. message: e.message || e.toString(),
  61180. stack: e.stack || minimumStackMessage
  61181. };
  61182. } else {
  61183. wrappedException = {
  61184. message: 'Unknown exception type: ' + typeof e,
  61185. stack: minimumStackMessage
  61186. };
  61187. }
  61188. handler.send('PageError', {
  61189. pageNum: pageNum,
  61190. error: wrappedException,
  61191. intent: data.intent
  61192. });
  61193. });
  61194. });
  61195. }, this);
  61196. handler.on('GetTextContent', function wphExtractText(data) {
  61197. var pageIndex = data.pageIndex;
  61198. var normalizeWhitespace = data.normalizeWhitespace;
  61199. var combineTextItems = data.combineTextItems;
  61200. return pdfManager.getPage(pageIndex).then(function (page) {
  61201. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  61202. startWorkerTask(task);
  61203. var pageNum = pageIndex + 1;
  61204. var start = Date.now();
  61205. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  61206. finishWorkerTask(task);
  61207. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  61208. return textContent;
  61209. }, function (reason) {
  61210. finishWorkerTask(task);
  61211. if (task.terminated) {
  61212. return;
  61213. }
  61214. // ignoring errors from the terminated thread
  61215. throw reason;
  61216. });
  61217. });
  61218. });
  61219. handler.on('Cleanup', function wphCleanup(data) {
  61220. return pdfManager.cleanup();
  61221. });
  61222. handler.on('Terminate', function wphTerminate(data) {
  61223. terminated = true;
  61224. if (pdfManager) {
  61225. pdfManager.terminate();
  61226. pdfManager = null;
  61227. }
  61228. if (cancelXHRs) {
  61229. cancelXHRs();
  61230. }
  61231. var waitOn = [];
  61232. WorkerTasks.forEach(function (task) {
  61233. waitOn.push(task.finished);
  61234. task.terminate();
  61235. });
  61236. return Promise.all(waitOn).then(function () {
  61237. // Notice that even if we destroying handler, resolved response promise
  61238. // must be sent back.
  61239. handler.destroy();
  61240. handler = null;
  61241. });
  61242. });
  61243. handler.on('Ready', function wphReady(data) {
  61244. setupDoc(docParams);
  61245. docParams = null;
  61246. });
  61247. // we don't need docParams anymore -- saving memory.
  61248. return workerHandlerName;
  61249. }
  61250. };
  61251. function initializeWorker() {
  61252. if (!('console' in globalScope)) {
  61253. var consoleTimer = {};
  61254. var workerConsole = {
  61255. log: function log() {
  61256. var args = Array.prototype.slice.call(arguments);
  61257. globalScope.postMessage({
  61258. targetName: 'main',
  61259. action: 'console_log',
  61260. data: args
  61261. });
  61262. },
  61263. error: function error() {
  61264. var args = Array.prototype.slice.call(arguments);
  61265. globalScope.postMessage({
  61266. targetName: 'main',
  61267. action: 'console_error',
  61268. data: args
  61269. });
  61270. throw 'pdf.js execution error';
  61271. },
  61272. time: function time(name) {
  61273. consoleTimer[name] = Date.now();
  61274. },
  61275. timeEnd: function timeEnd(name) {
  61276. var time = consoleTimer[name];
  61277. if (!time) {
  61278. error('Unknown timer name ' + name);
  61279. }
  61280. this.log('Timer:', name, Date.now() - time);
  61281. }
  61282. };
  61283. globalScope.console = workerConsole;
  61284. }
  61285. var handler = new MessageHandler('worker', 'main', self);
  61286. WorkerMessageHandler.setup(handler, self);
  61287. handler.send('ready', null);
  61288. }
  61289. // Worker thread (and not node.js)?
  61290. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  61291. initializeWorker();
  61292. }
  61293. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  61294. exports.WorkerTask = WorkerTask;
  61295. exports.WorkerMessageHandler = WorkerMessageHandler;
  61296. }));
  61297. (function (root, factory) {
  61298. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  61299. }(this, function (exports, sharedUtil, coreWorker) {
  61300. var OK_RESPONSE = 200;
  61301. var PARTIAL_CONTENT_RESPONSE = 206;
  61302. function NetworkManager(url, args) {
  61303. this.url = url;
  61304. args = args || {};
  61305. this.isHttp = /^https?:/i.test(url);
  61306. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  61307. this.withCredentials = args.withCredentials || false;
  61308. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  61309. return new XMLHttpRequest();
  61310. };
  61311. this.currXhrId = 0;
  61312. this.pendingRequests = Object.create(null);
  61313. this.loadedRequests = Object.create(null);
  61314. }
  61315. function getArrayBuffer(xhr) {
  61316. var data = xhr.response;
  61317. if (typeof data !== 'string') {
  61318. return data;
  61319. }
  61320. var length = data.length;
  61321. var array = new Uint8Array(length);
  61322. for (var i = 0; i < length; i++) {
  61323. array[i] = data.charCodeAt(i) & 0xFF;
  61324. }
  61325. return array.buffer;
  61326. }
  61327. var supportsMozChunked = function supportsMozChunkedClosure() {
  61328. try {
  61329. var x = new XMLHttpRequest();
  61330. // Firefox 37- required .open() to be called before setting responseType.
  61331. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  61332. // Even though the URL is not visited, .open() could fail if the URL is
  61333. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  61334. // When this error occurs, this feature detection method will mistakenly
  61335. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  61336. x.open('GET', 'https://example.com');
  61337. x.responseType = 'moz-chunked-arraybuffer';
  61338. return x.responseType === 'moz-chunked-arraybuffer';
  61339. } catch (e) {
  61340. return false;
  61341. }
  61342. }();
  61343. NetworkManager.prototype = {
  61344. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  61345. var args = {
  61346. begin: begin,
  61347. end: end
  61348. };
  61349. for (var prop in listeners) {
  61350. args[prop] = listeners[prop];
  61351. }
  61352. return this.request(args);
  61353. },
  61354. requestFull: function NetworkManager_requestFull(listeners) {
  61355. return this.request(listeners);
  61356. },
  61357. request: function NetworkManager_request(args) {
  61358. var xhr = this.getXhr();
  61359. var xhrId = this.currXhrId++;
  61360. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  61361. xhr.open('GET', this.url);
  61362. xhr.withCredentials = this.withCredentials;
  61363. for (var property in this.httpHeaders) {
  61364. var value = this.httpHeaders[property];
  61365. if (typeof value === 'undefined') {
  61366. continue;
  61367. }
  61368. xhr.setRequestHeader(property, value);
  61369. }
  61370. if (this.isHttp && 'begin' in args && 'end' in args) {
  61371. var rangeStr = args.begin + '-' + (args.end - 1);
  61372. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  61373. pendingRequest.expectedStatus = 206;
  61374. } else {
  61375. pendingRequest.expectedStatus = 200;
  61376. }
  61377. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  61378. if (useMozChunkedLoading) {
  61379. xhr.responseType = 'moz-chunked-arraybuffer';
  61380. pendingRequest.onProgressiveData = args.onProgressiveData;
  61381. pendingRequest.mozChunked = true;
  61382. } else {
  61383. xhr.responseType = 'arraybuffer';
  61384. }
  61385. if (args.onError) {
  61386. xhr.onerror = function (evt) {
  61387. args.onError(xhr.status);
  61388. };
  61389. }
  61390. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  61391. xhr.onprogress = this.onProgress.bind(this, xhrId);
  61392. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  61393. pendingRequest.onDone = args.onDone;
  61394. pendingRequest.onError = args.onError;
  61395. pendingRequest.onProgress = args.onProgress;
  61396. xhr.send(null);
  61397. return xhrId;
  61398. },
  61399. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  61400. var pendingRequest = this.pendingRequests[xhrId];
  61401. if (!pendingRequest) {
  61402. // Maybe abortRequest was called...
  61403. return;
  61404. }
  61405. if (pendingRequest.mozChunked) {
  61406. var chunk = getArrayBuffer(pendingRequest.xhr);
  61407. pendingRequest.onProgressiveData(chunk);
  61408. }
  61409. var onProgress = pendingRequest.onProgress;
  61410. if (onProgress) {
  61411. onProgress(evt);
  61412. }
  61413. },
  61414. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  61415. var pendingRequest = this.pendingRequests[xhrId];
  61416. if (!pendingRequest) {
  61417. // Maybe abortRequest was called...
  61418. return;
  61419. }
  61420. var xhr = pendingRequest.xhr;
  61421. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  61422. pendingRequest.onHeadersReceived();
  61423. delete pendingRequest.onHeadersReceived;
  61424. }
  61425. if (xhr.readyState !== 4) {
  61426. return;
  61427. }
  61428. if (!(xhrId in this.pendingRequests)) {
  61429. // The XHR request might have been aborted in onHeadersReceived()
  61430. // callback, in which case we should abort request
  61431. return;
  61432. }
  61433. delete this.pendingRequests[xhrId];
  61434. // success status == 0 can be on ftp, file and other protocols
  61435. if (xhr.status === 0 && this.isHttp) {
  61436. if (pendingRequest.onError) {
  61437. pendingRequest.onError(xhr.status);
  61438. }
  61439. return;
  61440. }
  61441. var xhrStatus = xhr.status || OK_RESPONSE;
  61442. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  61443. // "A server MAY ignore the Range header". This means it's possible to
  61444. // get a 200 rather than a 206 response from a range request.
  61445. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  61446. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  61447. if (pendingRequest.onError) {
  61448. pendingRequest.onError(xhr.status);
  61449. }
  61450. return;
  61451. }
  61452. this.loadedRequests[xhrId] = true;
  61453. var chunk = getArrayBuffer(xhr);
  61454. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  61455. var rangeHeader = xhr.getResponseHeader('Content-Range');
  61456. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  61457. var begin = parseInt(matches[1], 10);
  61458. pendingRequest.onDone({
  61459. begin: begin,
  61460. chunk: chunk
  61461. });
  61462. } else if (pendingRequest.onProgressiveData) {
  61463. pendingRequest.onDone(null);
  61464. } else if (chunk) {
  61465. pendingRequest.onDone({
  61466. begin: 0,
  61467. chunk: chunk
  61468. });
  61469. } else if (pendingRequest.onError) {
  61470. pendingRequest.onError(xhr.status);
  61471. }
  61472. },
  61473. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  61474. for (var xhrId in this.pendingRequests) {
  61475. return true;
  61476. }
  61477. return false;
  61478. },
  61479. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  61480. return this.pendingRequests[xhrId].xhr;
  61481. },
  61482. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  61483. return !!this.pendingRequests[xhrId].onProgressiveData;
  61484. },
  61485. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  61486. return xhrId in this.pendingRequests;
  61487. },
  61488. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  61489. return xhrId in this.loadedRequests;
  61490. },
  61491. abortAllRequests: function NetworkManager_abortAllRequests() {
  61492. for (var xhrId in this.pendingRequests) {
  61493. this.abortRequest(xhrId | 0);
  61494. }
  61495. },
  61496. abortRequest: function NetworkManager_abortRequest(xhrId) {
  61497. var xhr = this.pendingRequests[xhrId].xhr;
  61498. delete this.pendingRequests[xhrId];
  61499. xhr.abort();
  61500. }
  61501. };
  61502. var assert = sharedUtil.assert;
  61503. var createPromiseCapability = sharedUtil.createPromiseCapability;
  61504. var isInt = sharedUtil.isInt;
  61505. var MissingPDFException = sharedUtil.MissingPDFException;
  61506. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  61507. /** @implements {IPDFStream} */
  61508. function PDFNetworkStream(options) {
  61509. this._options = options;
  61510. var source = options.source;
  61511. this._manager = new NetworkManager(source.url, {
  61512. httpHeaders: source.httpHeaders,
  61513. withCredentials: source.withCredentials
  61514. });
  61515. this._rangeChunkSize = source.rangeChunkSize;
  61516. this._fullRequestReader = null;
  61517. this._rangeRequestReaders = [];
  61518. }
  61519. PDFNetworkStream.prototype = {
  61520. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  61521. var i = this._rangeRequestReaders.indexOf(reader);
  61522. if (i >= 0) {
  61523. this._rangeRequestReaders.splice(i, 1);
  61524. }
  61525. },
  61526. getFullReader: function PDFNetworkStream_getFullReader() {
  61527. assert(!this._fullRequestReader);
  61528. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  61529. return this._fullRequestReader;
  61530. },
  61531. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  61532. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  61533. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  61534. this._rangeRequestReaders.push(reader);
  61535. return reader;
  61536. },
  61537. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  61538. if (this._fullRequestReader) {
  61539. this._fullRequestReader.cancel(reason);
  61540. }
  61541. var readers = this._rangeRequestReaders.slice(0);
  61542. readers.forEach(function (reader) {
  61543. reader.cancel(reason);
  61544. });
  61545. }
  61546. };
  61547. /** @implements {IPDFStreamReader} */
  61548. function PDFNetworkStreamFullRequestReader(manager, options) {
  61549. this._manager = manager;
  61550. var source = options.source;
  61551. var args = {
  61552. onHeadersReceived: this._onHeadersReceived.bind(this),
  61553. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  61554. onDone: this._onDone.bind(this),
  61555. onError: this._onError.bind(this),
  61556. onProgress: this._onProgress.bind(this)
  61557. };
  61558. this._url = source.url;
  61559. this._fullRequestId = manager.requestFull(args);
  61560. this._headersReceivedCapability = createPromiseCapability();
  61561. this._disableRange = options.disableRange || false;
  61562. this._contentLength = source.length;
  61563. // optional
  61564. this._rangeChunkSize = source.rangeChunkSize;
  61565. if (!this._rangeChunkSize && !this._disableRange) {
  61566. this._disableRange = true;
  61567. }
  61568. this._isStreamingSupported = false;
  61569. this._isRangeSupported = false;
  61570. this._cachedChunks = [];
  61571. this._requests = [];
  61572. this._done = false;
  61573. this._storedError = undefined;
  61574. this.onProgress = null;
  61575. }
  61576. PDFNetworkStreamFullRequestReader.prototype = {
  61577. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  61578. if (this._disableRange) {
  61579. return false;
  61580. }
  61581. var networkManager = this._manager;
  61582. var fullRequestXhrId = this._fullRequestId;
  61583. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  61584. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  61585. return false;
  61586. }
  61587. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  61588. if (contentEncoding !== 'identity') {
  61589. return false;
  61590. }
  61591. var length = fullRequestXhr.getResponseHeader('Content-Length');
  61592. length = parseInt(length, 10);
  61593. if (!isInt(length)) {
  61594. return false;
  61595. }
  61596. this._contentLength = length;
  61597. // setting right content length
  61598. if (length <= 2 * this._rangeChunkSize) {
  61599. // The file size is smaller than the size of two chunks, so it does
  61600. // not make any sense to abort the request and retry with a range
  61601. // request.
  61602. return false;
  61603. }
  61604. return true;
  61605. },
  61606. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  61607. if (this._validateRangeRequestCapabilities()) {
  61608. this._isRangeSupported = true;
  61609. }
  61610. var networkManager = this._manager;
  61611. var fullRequestXhrId = this._fullRequestId;
  61612. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  61613. // We can continue fetching when progressive loading is enabled,
  61614. // and we don't need the autoFetch feature.
  61615. this._isStreamingSupported = true;
  61616. } else if (this._isRangeSupported) {
  61617. // NOTE: by cancelling the full request, and then issuing range
  61618. // requests, there will be an issue for sites where you can only
  61619. // request the pdf once. However, if this is the case, then the
  61620. // server should not be returning that it can support range
  61621. // requests.
  61622. networkManager.abortRequest(fullRequestXhrId);
  61623. }
  61624. this._headersReceivedCapability.resolve();
  61625. },
  61626. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  61627. if (this._requests.length > 0) {
  61628. var requestCapability = this._requests.shift();
  61629. requestCapability.resolve({
  61630. value: chunk,
  61631. done: false
  61632. });
  61633. } else {
  61634. this._cachedChunks.push(chunk);
  61635. }
  61636. },
  61637. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  61638. if (args) {
  61639. this._onProgressiveData(args.chunk);
  61640. }
  61641. this._done = true;
  61642. if (this._cachedChunks.length > 0) {
  61643. return;
  61644. }
  61645. this._requests.forEach(function (requestCapability) {
  61646. requestCapability.resolve({
  61647. value: undefined,
  61648. done: true
  61649. });
  61650. });
  61651. this._requests = [];
  61652. },
  61653. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  61654. var url = this._url;
  61655. var exception;
  61656. if (status === 404 || status === 0 && /^file:/.test(url)) {
  61657. exception = new MissingPDFException('Missing PDF "' + url + '".');
  61658. } else {
  61659. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  61660. }
  61661. this._storedError = exception;
  61662. this._headersReceivedCapability.reject(exception);
  61663. this._requests.forEach(function (requestCapability) {
  61664. requestCapability.reject(exception);
  61665. });
  61666. this._requests = [];
  61667. this._cachedChunks = [];
  61668. },
  61669. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  61670. if (this.onProgress) {
  61671. this.onProgress({
  61672. loaded: data.loaded,
  61673. total: data.lengthComputable ? data.total : this._contentLength
  61674. });
  61675. }
  61676. },
  61677. get isRangeSupported() {
  61678. return this._isRangeSupported;
  61679. },
  61680. get isStreamingSupported() {
  61681. return this._isStreamingSupported;
  61682. },
  61683. get contentLength() {
  61684. return this._contentLength;
  61685. },
  61686. get headersReady() {
  61687. return this._headersReceivedCapability.promise;
  61688. },
  61689. read: function PDFNetworkStreamFullRequestReader_read() {
  61690. if (this._storedError) {
  61691. return Promise.reject(this._storedError);
  61692. }
  61693. if (this._cachedChunks.length > 0) {
  61694. var chunk = this._cachedChunks.shift();
  61695. return Promise.resolve(chunk);
  61696. }
  61697. if (this._done) {
  61698. return Promise.resolve({
  61699. value: undefined,
  61700. done: true
  61701. });
  61702. }
  61703. var requestCapability = createPromiseCapability();
  61704. this._requests.push(requestCapability);
  61705. return requestCapability.promise;
  61706. },
  61707. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  61708. this._done = true;
  61709. this._headersReceivedCapability.reject(reason);
  61710. this._requests.forEach(function (requestCapability) {
  61711. requestCapability.resolve({
  61712. value: undefined,
  61713. done: true
  61714. });
  61715. });
  61716. this._requests = [];
  61717. if (this._manager.isPendingRequest(this._fullRequestId)) {
  61718. this._manager.abortRequest(this._fullRequestId);
  61719. }
  61720. this._fullRequestReader = null;
  61721. }
  61722. };
  61723. /** @implements {IPDFStreamRangeReader} */
  61724. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  61725. this._manager = manager;
  61726. var args = {
  61727. onDone: this._onDone.bind(this),
  61728. onProgress: this._onProgress.bind(this)
  61729. };
  61730. this._requestId = manager.requestRange(begin, end, args);
  61731. this._requests = [];
  61732. this._queuedChunk = null;
  61733. this._done = false;
  61734. this.onProgress = null;
  61735. this.onClosed = null;
  61736. }
  61737. PDFNetworkStreamRangeRequestReader.prototype = {
  61738. _close: function PDFNetworkStreamRangeRequestReader_close() {
  61739. if (this.onClosed) {
  61740. this.onClosed(this);
  61741. }
  61742. },
  61743. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  61744. var chunk = data.chunk;
  61745. if (this._requests.length > 0) {
  61746. var requestCapability = this._requests.shift();
  61747. requestCapability.resolve({
  61748. value: chunk,
  61749. done: false
  61750. });
  61751. } else {
  61752. this._queuedChunk = chunk;
  61753. }
  61754. this._done = true;
  61755. this._requests.forEach(function (requestCapability) {
  61756. requestCapability.resolve({
  61757. value: undefined,
  61758. done: true
  61759. });
  61760. });
  61761. this._requests = [];
  61762. this._close();
  61763. },
  61764. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  61765. if (!this.isStreamingSupported && this.onProgress) {
  61766. this.onProgress({ loaded: evt.loaded });
  61767. }
  61768. },
  61769. get isStreamingSupported() {
  61770. return false;
  61771. },
  61772. // TODO allow progressive range bytes loading
  61773. read: function PDFNetworkStreamRangeRequestReader_read() {
  61774. if (this._queuedChunk !== null) {
  61775. var chunk = this._queuedChunk;
  61776. this._queuedChunk = null;
  61777. return Promise.resolve({
  61778. value: chunk,
  61779. done: false
  61780. });
  61781. }
  61782. if (this._done) {
  61783. return Promise.resolve({
  61784. value: undefined,
  61785. done: true
  61786. });
  61787. }
  61788. var requestCapability = createPromiseCapability();
  61789. this._requests.push(requestCapability);
  61790. return requestCapability.promise;
  61791. },
  61792. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  61793. this._done = true;
  61794. this._requests.forEach(function (requestCapability) {
  61795. requestCapability.resolve({
  61796. value: undefined,
  61797. done: true
  61798. });
  61799. });
  61800. this._requests = [];
  61801. if (this._manager.isPendingRequest(this._requestId)) {
  61802. this._manager.abortRequest(this._requestId);
  61803. }
  61804. this._close();
  61805. }
  61806. };
  61807. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  61808. exports.PDFNetworkStream = PDFNetworkStream;
  61809. exports.NetworkManager = NetworkManager;
  61810. }));
  61811. }.call(pdfjsLibs));
  61812. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  61813. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  61814. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  61815. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  61816. exports.PDFDataRangeTransport = pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  61817. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  61818. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  61819. exports.AnnotationLayer = pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  61820. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  61821. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  61822. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  61823. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  61824. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  61825. exports.UnexpectedResponseException = pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  61826. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  61827. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  61828. exports.isValidUrl = pdfjsLibs.pdfjsDisplayDOMUtils.isValidUrl;
  61829. exports.createValidAbsoluteUrl = pdfjsLibs.pdfjsSharedUtil.createValidAbsoluteUrl;
  61830. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  61831. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  61832. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  61833. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  61834. exports.getFilenameFromUrl = pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  61835. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  61836. }));